* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #b4a5d8;
    --primary-hover: #c4b5e8;
    --accent: #f4c5c0;
    --bg: #1a1625;
    --bg-card: #252031;
    --bg-hover: #2d2839;
    --text: #e8e4f0;
    --text-secondary: #b0a8c0;
    --border: #3a3447;
    --success: #a8dba8;
    --warning: #f5d491;
    --danger: #f4a0a0;
    --shadow: rgba(0, 0, 0, 0.2);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #1a1625 0%, #252031 100%);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.7;
    position: relative;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: -50%;
    right: -50%;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(180, 165, 216, 0.08) 0%, transparent 70%);
    pointer-events: none;
    z-index: -1;
}

body::after {
    content: '';
    position: fixed;
    bottom: -50%;
    left: -50%;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(244, 197, 192, 0.06) 0%, transparent 70%);
    pointer-events: none;
    z-index: -1;
}

/* Sparkles / Glowing dots */
.sparkles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.sparkles::before,
.sparkles::after {
    content: '';
    position: absolute;
    width: 3px;
    height: 3px;
    border-radius: 50%;
    animation: sparkle 4s ease-in-out infinite;
}

.sparkles::before {
    top: 8%;
    left: 20%;
    box-shadow:
        0 0 12px 3px rgba(180, 165, 216, 0.7),
        0 0 24px 5px rgba(180, 165, 216, 0.4),
        100px 20px 12px 3px rgba(244, 197, 192, 0.6),
        250px 10px 10px 2px rgba(180, 165, 216, 0.5),
        400px 30px 12px 3px rgba(244, 197, 192, 0.7),
        550px 15px 10px 2px rgba(180, 165, 216, 0.6),
        150px 50px 12px 3px rgba(244, 197, 192, 0.5),
        350px 60px 10px 2px rgba(180, 165, 216, 0.6),
        500px 70px 12px 3px rgba(244, 197, 192, 0.6),
        200px -20px 10px 2px rgba(180, 165, 216, 0.7),
        450px -10px 12px 3px rgba(244, 197, 192, 0.5),
        300px 80px 10px 2px rgba(180, 165, 216, 0.5),
        150px 200px 8px 2px rgba(244, 197, 192, 0.4),
        600px 250px 8px 2px rgba(180, 165, 216, 0.4),
        800px 150px 8px 2px rgba(244, 197, 192, 0.5),
        100px 400px 8px 2px rgba(180, 165, 216, 0.4);
    animation-delay: 0s;
}

.sparkles::after {
    top: 10%;
    left: 70%;
    box-shadow:
        0 0 10px 3px rgba(244, 197, 192, 0.6),
        0 0 20px 4px rgba(244, 197, 192, 0.4),
        -150px 15px 12px 3px rgba(180, 165, 216, 0.6),
        -300px 25px 10px 2px rgba(244, 197, 192, 0.7),
        -450px 5px 12px 3px rgba(180, 165, 216, 0.5),
        -200px 45px 10px 2px rgba(244, 197, 192, 0.6),
        -350px 55px 12px 3px rgba(180, 165, 216, 0.7),
        -500px -15px 10px 2px rgba(244, 197, 192, 0.5),
        -100px 65px 12px 3px rgba(180, 165, 216, 0.6),
        -250px -5px 10px 2px rgba(244, 197, 192, 0.7),
        -400px 35px 12px 3px rgba(180, 165, 216, 0.5),
        -150px 180px 8px 2px rgba(244, 197, 192, 0.4),
        -350px 200px 8px 2px rgba(180, 165, 216, 0.4),
        -200px 350px 8px 2px rgba(244, 197, 192, 0.4),
        -450px 150px 8px 2px rgba(180, 165, 216, 0.5);
    animation-delay: 2s;
}

@keyframes sparkle {
    0%, 100% {
        opacity: 0.3;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        transform: scale(1.2);
    }
}

.app {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
    padding-bottom: 48px;
    position: relative;
    z-index: 1;
}

@media (min-width: 768px) {
    .app {
        padding: 40px;
    }
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: 48px;
    padding: 24px 0;
}

.app-title {
    font-size: 32px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
    letter-spacing: -1px;
}

.app-subtitle {
    font-size: 16px;
    color: var(--text-secondary);
    font-weight: 400;
}

@media (min-width: 768px) {
    .app-title {
        font-size: 42px;
    }

    .app-subtitle {
        font-size: 18px;
    }
}

/* Navigation */
.nav {
    display: flex;
    gap: 12px;
    margin-bottom: 32px;
    overflow-x: auto;
    padding: 6px;
    background: var(--bg-card);
    border-radius: 20px;
    box-shadow: 0 4px 16px var(--shadow);
}

.nav-btn {
    flex: 1;
    min-width: fit-content;
    padding: 14px 24px;
    background: transparent;
    border: none;
    border-radius: 16px;
    color: var(--text-secondary);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.nav-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
    transform: translateY(-2px);
}

.nav-btn.active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: var(--text);
    box-shadow: 0 4px 12px rgba(180, 165, 216, 0.3);
}

/* Sections */
.section {
    display: none;
}

.section.active {
    display: block;
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 1024px) {
    #stability.active {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 32px;
        align-items: start;
    }

    #stability .calendar-nav {
        grid-column: 1 / -1;
    }

    #stability .stats-cards {
        grid-row: 2;
        grid-column: 2;
    }
}

/* Calendar */
.calendar-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.calendar-nav h2 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.5px;
}

.arrow-btn {
    width: 48px;
    height: 48px;
    background: var(--bg-card);
    border: none;
    border-radius: 14px;
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px var(--shadow);
}

.arrow-btn:hover {
    background: var(--primary);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(180, 165, 216, 0.3);
}

.arrow-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.calendar {
    background: var(--bg-card);
    border-radius: 24px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 4px 20px var(--shadow);
    position: relative;
    overflow: hidden;
}

.calendar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
    opacity: 0.6;
}

@media (min-width: 768px) {
    .calendar {
        padding: 32px;
    }
}

.calendar-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
    margin-bottom: 12px;
}

.calendar-header span {
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary);
    padding: 10px 0;
    font-weight: 500;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}

.calendar-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    border-radius: 12px;
    color: var(--text-secondary);
    transition: all 0.3s ease;
    cursor: default;
}

.calendar-day.current-month {
    color: var(--text);
}

.calendar-day.has-entry {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: var(--text);
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(180, 165, 216, 0.3);
    position: relative;
    animation: gentle-pulse 3s ease-in-out infinite;
}

@keyframes gentle-pulse {
    0%, 100% {
        box-shadow: 0 2px 8px rgba(180, 165, 216, 0.3);
    }
    50% {
        box-shadow: 0 2px 12px rgba(180, 165, 216, 0.5);
    }
}

.calendar-day.today {
    border: 2px solid var(--accent);
    box-shadow: 0 0 16px rgba(244, 197, 192, 0.4);
}

/* Stats Cards */
.stats-cards {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 16px var(--shadow);
    transition: all 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 6px 24px var(--shadow);
}

.stat-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.stat-icon {
    font-size: 24px;
    opacity: 0.8;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 15px;
}

.stat-value {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
}

@media (min-width: 768px) {
    .stats-cards {
        gap: 20px;
    }
}

/* State Section */
.state-tabs {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    padding: 6px;
    background: var(--bg-card);
    border-radius: 18px;
    box-shadow: 0 2px 12px var(--shadow);
}

.state-tab {
    flex: 1;
    padding: 12px 20px;
    background: transparent;
    border: none;
    border-radius: 14px;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.state-tab.active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: var(--text);
    box-shadow: 0 2px 8px rgba(180, 165, 216, 0.3);
}

.period-selector {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.period-btn {
    flex: 1;
    padding: 10px 16px;
    background: var(--bg-card);
    border: 2px solid transparent;
    border-radius: 12px;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.period-btn:hover {
    background: var(--bg-hover);
}

.period-btn.active {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(180, 165, 216, 0.1);
}

.offset-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
}

.offset-nav span {
    font-size: 15px;
    color: var(--text);
    font-weight: 500;
}

.state-display {
    background: var(--bg-card);
    border-radius: 24px;
    padding: 32px;
    display: flex;
    gap: 32px;
    align-items: center;
    box-shadow: 0 6px 24px var(--shadow);
    position: relative;
    overflow: hidden;
}

.state-display::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
    opacity: 0.5;
}

.state-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.score-circle {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: conic-gradient(
        var(--primary) calc(var(--score, 0) * 10%),
        rgba(180, 165, 216, 0.15) 0
    );
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    box-shadow: 0 4px 16px rgba(180, 165, 216, 0.2);
}

.score-circle::before {
    content: '';
    position: absolute;
    width: 94px;
    height: 94px;
    background: var(--bg-card);
    border-radius: 50%;
}

.score-circle span {
    position: relative;
    font-size: 36px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.score-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.state-info {
    flex: 1;
}

.state-summary {
    font-size: 15px;
    margin-bottom: 16px;
    line-height: 1.8;
    color: var(--text);
}

.state-trend {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    padding: 10px 16px;
    border-radius: 12px;
    width: fit-content;
    font-weight: 500;
    transition: all 0.3s ease;
}

.state-trend:hover {
    transform: scale(1.05);
}

.state-trend .trend-icon {
    font-size: 18px;
    animation: gentle-bounce 2s ease-in-out infinite;
}

@keyframes gentle-bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-3px);
    }
}

.state-trend.improving {
    color: var(--success);
    background: rgba(168, 219, 168, 0.15);
    box-shadow: 0 2px 8px rgba(168, 219, 168, 0.2);
}
.state-trend.stable {
    color: var(--warning);
    background: rgba(245, 212, 145, 0.15);
    box-shadow: 0 2px 8px rgba(245, 212, 145, 0.2);
}
.state-trend.declining {
    color: var(--danger);
    background: rgba(244, 160, 160, 0.15);
    box-shadow: 0 2px 8px rgba(244, 160, 160, 0.2);
}

@media (prefers-reduced-motion: reduce) {
    .state-trend .trend-icon {
        animation: none !important;
    }
}

@media (max-width: 640px) {
    .state-display {
        flex-direction: column;
        padding: 24px;
        gap: 24px;
    }

    .score-circle {
        width: 100px;
        height: 100px;
    }

    .score-circle::before {
        width: 78px;
        height: 78px;
    }

    .score-circle span {
        font-size: 30px;
    }
}

/* Keywords Section */
.keywords-content {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

@media (min-width: 768px) {
    .keywords-content {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 24px;
    }

    .keywords-card {
        grid-row: 1 / 3;
    }
}

.keywords-card {
    background: var(--bg-card);
    border-radius: 24px;
    padding: 28px;
    box-shadow: 0 4px 20px var(--shadow);
    position: relative;
    overflow: hidden;
}

.keywords-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent) 0%, var(--primary) 100%);
    opacity: 0.5;
}

.keywords-card h3 {
    font-size: 16px;
    color: var(--text);
    margin-bottom: 20px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.keywords-card h3::before {
    content: '✨';
    font-size: 18px;
}

.word-list {
    list-style: none;
}

.word-list li {
    display: flex;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid rgba(180, 165, 216, 0.1);
    transition: all 0.3s ease;
}

.word-list li:hover {
    padding-left: 8px;
    background: rgba(180, 165, 216, 0.05);
    border-radius: 8px;
    margin: 0 -8px;
    padding-left: 16px;
    padding-right: 8px;
}

.word-list li:last-child {
    border-bottom: none;
}

.word-list .word {
    font-weight: 600;
    font-size: 16px;
}

.word-list .count {
    color: var(--text-secondary);
    font-size: 15px;
    padding: 4px 12px;
    background: rgba(180, 165, 216, 0.1);
    border-radius: 8px;
}

.keywords-highlights {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

@media (min-width: 480px) {
    .keywords-highlights {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 768px) {
    .keywords-highlights {
        grid-template-columns: 1fr;
    }
}

.highlight-card {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 12px;
    box-shadow: 0 4px 16px var(--shadow);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.highlight-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(180, 165, 216, 0.05) 0%, rgba(244, 197, 192, 0.05) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.highlight-card:hover::before {
    opacity: 1;
}

.highlight-card:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 8px 28px var(--shadow);
}

.highlight-icon {
    font-size: 32px;
    position: relative;
    z-index: 1;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.highlight-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
    position: relative;
    z-index: 1;
}

.highlight-value {
    font-size: 16px;
    font-weight: 600;
    word-break: break-word;
    color: var(--text);
    position: relative;
    z-index: 1;
}

/* Loading & Error */
.loading, .error {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(26, 22, 37, 0.95);
    backdrop-filter: blur(10px);
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 20px;
    z-index: 100;
}

.loading.show, .error.show {
    display: flex;
    animation: fadeIn 0.3s ease;
}

.spinner {
    width: 56px;
    height: 56px;
    border: 4px solid rgba(180, 165, 216, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.error p {
    font-size: 16px;
    color: var(--text);
    margin-bottom: 8px;
}

.error button {
    padding: 14px 32px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    border: none;
    border-radius: 16px;
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 16px rgba(180, 165, 216, 0.3);
}

.error button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(180, 165, 216, 0.4);
}

/* Responsive Enhancements */
@media (max-width: 480px) {
    .app {
        padding: 16px;
    }

    .app-header {
        margin-bottom: 32px;
        padding: 16px 0;
    }

    .app-title {
        font-size: 28px;
    }

    .app-subtitle {
        font-size: 14px;
    }

    .nav {
        gap: 8px;
        padding: 4px;
    }

    .nav-btn {
        padding: 12px 16px;
        font-size: 14px;
    }

    .calendar {
        padding: 16px;
    }

    .calendar-nav h2 {
        font-size: 20px;
    }

    .arrow-btn {
        width: 44px;
        height: 44px;
    }

    .stats-cards {
        gap: 12px;
    }

    .stat-card {
        padding: 16px 20px;
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .stat-content {
        width: 100%;
    }

    .stat-value {
        font-size: 24px;
        align-self: flex-end;
    }

    .state-display {
        padding: 20px;
    }

    .keywords-card {
        padding: 20px;
    }
}

@media (min-width: 1200px) {
    #state.active {
        max-width: 900px;
        margin: 0 auto;
    }

    #keywords.active {
        max-width: 1100px;
        margin: 0 auto;
    }
}

/* Print styles */
@media print {
    body::before,
    body::after,
    .nav,
    .arrow-btn,
    .loading,
    .error {
        display: none !important;
    }

    .section {
        display: block !important;
        page-break-inside: avoid;
    }
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-hover);
}

/* Focus states */
button:focus-visible,
.nav-btn:focus-visible,
.arrow-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Transitions for all interactive elements */
button, .nav-btn, .period-btn, .state-tab, .arrow-btn, .stat-card, .highlight-card {
    -webkit-tap-highlight-color: transparent;
}

/* Empty states */
.word-list li:only-child {
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
    padding: 20px;
    border: none;
}

/* Subtle animations */
@keyframes float {
    0%, 100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-6px);
    }
}

/* Smooth gradient shift */
@keyframes gradient-shift {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

.calendar::before,
.state-display::before,
.keywords-card::before {
    background-size: 200% 200%;
    animation: gradient-shift 8s ease infinite;
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .calendar-day.has-entry,
    .sparkles::before,
    .sparkles::after {
        animation: none !important;
    }
}
