@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@1,9..144,400..900&family=DM+Sans:wght@400;500&display=swap');

@font-face {
    font-family: 'Geist';
    src: url('../assets/Geist-Regular.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Geist';
    src: url('../assets/Geist-Medium.woff2') format('woff2');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Geist';
    src: url('../assets/Geist-SemiBold.woff2') format('woff2');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

:root {
    --bg-primary: #FFF8F0;
    --bg-secondary: #f0ece6;
    --bg-tertiary: #e8e4de;
    --text-primary: #1A1A1A;
    --text-secondary: rgba(26,26,26,0.55);
    --text-muted: rgba(26,26,26,0.35);
    --accent: #5B9BD5;
    --accent-amber: #2f6fae;
    --border: rgba(26,26,26,0.1);
    --success: #2d7a50;
    --error: #c44040;
    --font: 'DM Sans', 'Geist', -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
    --font-display: 'Fraunces', Georgia, serif;
    --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 10px;
    --radius-pill: 999px;
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --card-bg: #fff;
    --card-border: rgba(0,0,0,0.1);
    --card-shadow: rgba(0, 0, 0, 0.04);
    --input-bg: #fff;
    --header-bg: #fafafa;
    --choice-selected-bg: #f0f0f0;
    --correct-bg: #f0faf4;
    --correct-border: #a3d4b0;
    --correct-text: #2d7a50;
    --incorrect-bg: #faf0f0;
    --incorrect-border: #d4a3a3;
    --subject-1: #f5f5f5;
    --subject-2: #f5f5f5;
    --subject-3: #f5f5f5;
    --subject-4: #f5f5f5;
    --subject-5: #f5f5f5;
    --icon-bg: #f0f0f0;
    --icon-border: rgba(0,0,0,0.06);
    color-scheme: light;
}

[data-theme="dark"] {
    --bg-primary: #111;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #222;
    --text-primary: #e8e8e8;
    --text-secondary: rgba(255,255,255,0.5);
    --text-muted: rgba(255,255,255,0.25);
    --accent: #7ab4e0;
    --accent-amber: #5B9BD5;
    --border: rgba(255,255,255,0.1);
    --success: #3d9e6a;
    --error: #c44040;
    --card-bg: #1a1a1a;
    --card-border: rgba(255,255,255,0.1);
    --card-shadow: rgba(0, 0, 0, 0.2);
    --input-bg: #111;
    --header-bg: #111;
    --choice-selected-bg: #222;
    --correct-bg: #122a18;
    --correct-border: #2a5a3a;
    --correct-text: #3d9e6a;
    --incorrect-bg: #2a1818;
    --incorrect-border: #5a2a2a;
    --subject-1: #1a1a1a;
    --subject-2: #1a1a1a;
    --subject-3: #1a1a1a;
    --subject-4: #1a1a1a;
    --subject-5: #1a1a1a;
    --icon-bg: #222;
    --icon-border: rgba(255,255,255,0.06);
    color-scheme: dark;
}

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

body {
    font-family: var(--font);
    font-weight: 400;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    padding: env(safe-area-inset-top, 0) 0 0 0;
}

.header-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 0.875rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: opacity 0.2s var(--ease);
}

.logo:hover {
    opacity: 0.8;
}

.logo i {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.stats {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 400;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-pill);
    border: 1px solid transparent;
    transition: all 0.2s var(--ease);
    letter-spacing: 0.01em;
}

.stat-item i {
    font-size: 0.75rem;
}

.stat-item .stat-val {
    font-variant-numeric: tabular-nums;
}

.stat-item:hover {
    background: var(--bg-secondary);
    border-color: var(--border);
    color: var(--text-primary);
}

.stat-streak i {
    color: var(--text-secondary);
}

.stat-xp i {
    color: var(--text-secondary);
}

.stat-hearts i {
    color: var(--text-secondary);
}

.container {
    flex: 1;
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
    padding: 2.5rem 1.5rem;
    padding-bottom: calc(2.5rem + env(safe-area-inset-bottom, 0));
}

.category-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    border-bottom: 2px solid var(--border);
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--text-muted) transparent;
}

.category-tabs::-webkit-scrollbar {
    height: 4px;
}

.category-tabs::-webkit-scrollbar-track {
    background: transparent;
}

.category-tabs::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 4px;
}

.category-tab {
    padding: 0.625rem 1rem;
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition: all 0.2s var(--ease);
    letter-spacing: 0.01em;
    margin-bottom: -2px;
}

.category-tab:hover {
    color: var(--text-secondary);
}

.category-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.section-title {
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

.subject-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
}

.subject-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    cursor: pointer;
    transition: opacity 0.4s ease-out, transform 0.2s var(--spring);
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    position: relative;
}

.subject-card:nth-child(5n + 1) {
    background: var(--subject-1);
}

.subject-card:nth-child(5n + 2) {
    background: var(--subject-2);
}

.subject-card:nth-child(5n + 3) {
    background: var(--subject-3);
}

.subject-card:nth-child(5n + 4) {
    background: var(--subject-4);
}

.subject-card:nth-child(5n + 5) {
    background: var(--subject-5);
}

.subject-card:hover {
    transform: translateY(-2px);
    border-color: var(--text-muted);
}

.subject-card.selected {
    border-color: var(--text-primary);
}

.subject-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--icon-bg);
    border: 1px solid var(--icon-border);
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.subject-name {
    font-weight: 500;
    font-size: 0.9375rem;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.subject-level {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
    letter-spacing: 0.01em;
}

.lesson-container {
    display: none;
}

.lesson-container.active {
    display: block;
    animation: fadeUp 0.35s var(--ease);
}

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

.progress-container {
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.progress-bar {
    flex: 1;
    background: var(--border);
    height: 8px;
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    background: var(--accent);
    height: 100%;
    border-radius: 999px;
    transition: width 0.4s var(--ease);
    width: 0%;
}

.progress-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    font-weight: 400;
}

.question-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2rem;
    margin-bottom: 1.5rem;
}

.question-container {
    animation: fadeIn 0.3s var(--ease);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.question-type {
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.question-text {
    font-size: 1.375rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 1.75rem;
    letter-spacing: -0.02em;
    line-height: 1.35;
}

.math-equation {
    font-size: 1.75rem;
    font-weight: 500;
    color: var(--text-primary);
    text-align: center;
    margin: 1.5rem 0 2rem;
    letter-spacing: -0.02em;
}

.math-input,
.translation-input {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 1rem;
    font-family: var(--font);
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.math-input {
    text-align: center;
}

.math-input::placeholder,
.translation-input::placeholder {
    color: var(--text-muted);
}

.math-input:focus,
.translation-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .math-input:focus,
[data-theme="dark"] .translation-input:focus {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.06);
}

.choices-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.choice-btn {
    background: var(--card-bg);
    border: 1px solid var(--border);
    padding: 1rem 1.25rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9375rem;
    font-family: var(--font);
    color: var(--text-primary);
    transition: opacity 0.4s ease-out, transform 0.2s var(--spring);
    text-align: left;
    font-weight: 500;
    line-height: 1.4;
}

.choice-btn:hover {
    transform: translateY(-2px);
    border-color: var(--text-muted);
}

.choice-btn:active {
    transform: translateY(1px);
}

.choice-btn.selected {
    border-color: var(--accent);
    background: var(--choice-selected-bg);
}

.choice-btn.correct {
    background: var(--correct-bg);
    border-color: var(--success);
    color: var(--correct-text);
}

.choice-btn.incorrect {
    background: var(--incorrect-bg);
    border-color: var(--error);
    color: var(--error);
}

.word-bank {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 1.25rem;
    background: var(--bg-secondary);
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
    min-height: 64px;
}

.word-chip {
    background: var(--card-bg);
    color: var(--text-primary);
    padding: 0.5rem 0.875rem;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: opacity 0.4s ease-out, transform 0.2s var(--spring);
    font-size: 0.875rem;
    font-weight: 400;
    border: 1px solid var(--border);
    user-select: none;
}

.word-chip:hover {
    border-color: var(--border);
    transform: translateY(-1px);
}

.word-chip.used {
    opacity: 0.35;
    cursor: default;
    transform: scale(0.95);
}

.answer-box {
    min-height: 56px;
    padding: 0.875rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--text-primary);
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.btn-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
}

.btn {
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.625rem 1.25rem;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.4s ease-out, transform 0.2s var(--spring);
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text-secondary);
    letter-spacing: 0;
}

.btn:hover {
    transform: translateY(-2px);
    border-color: var(--text-muted);
}

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

.btn-primary {
    background: var(--text-primary);
    color: var(--bg-primary);
    border: 1px solid var(--text-primary);
}

.btn-primary:hover {
    opacity: 0.85;
    color: var(--bg-primary);
}

.btn-primary:active {
    transform: translateY(1px);
}

.feedback {
    padding: 0.875rem 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    display: none;
    font-size: 0.875rem;
    font-weight: 500;
}

.feedback.correct {
    background: var(--correct-bg);
    color: var(--correct-text);
    border: 1px solid var(--correct-border);
}

.feedback.incorrect {
    background: var(--incorrect-bg);
    color: var(--error);
    border: 1px solid var(--incorrect-border);
}

.feedback.show {
    display: block;
}

.result-container {
    display: none;
    text-align: center;
}

.result-container.active {
    display: block;
    animation: fadeUp 0.35s var(--ease);
}

.result-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 3rem 2rem;
}

.result-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--correct-bg);
    border: 1px solid var(--correct-border);
    color: var(--success);
    font-size: 1.25rem;
}

.result-title {
    font-size: 1.25rem;
    font-weight: 500;
    margin-bottom: 0.375rem;
    letter-spacing: -0.01em;
}

.result-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-weight: 400;
}

.result-stats {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.result-stat {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.25rem 2rem;
    flex: 1;
}

.result-stat-value {
    font-size: 1.5rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}

.result-stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-weight: 500;
}

@media (max-width: 640px) {
    .header-inner {
        padding: 0.75rem 1rem;
    }

    .container {
        padding: 1.5rem 1rem;
    }

    .stats {
        gap: 0;
    }

    .stat-item {
        padding: 0.375rem 0.5rem;
        font-size: 0.75rem;
    }

    .question-text {
        font-size: 1.125rem;
    }

    .math-equation {
        font-size: 1.375rem;
    }

    .question-card {
        padding: 1.5rem;
    }

    .subject-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    .result-stats {
        flex-direction: column;
    }

    .result-stat {
        padding: 1rem;
    }
}

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

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

*:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.choice-btn:focus-visible,
.word-chip:focus-visible,
.subject-card:focus-visible {
    outline-offset: -2px;
}

.math-input:focus-visible,
.translation-input:focus-visible {
    border-color: var(--accent);
    outline: none;
}

.achievement-toast {
    position: fixed;
    top: -80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    background: var(--card-bg);
    border: 1px solid var(--correct-border);
    border-radius: var(--radius-lg);
    transition: top 0.3s var(--spring);
    max-width: 90vw;
}

.achievement-toast.show {
    top: calc(env(safe-area-inset-top, 0px) + 80px);
}

.achievement-toast-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--correct-bg);
    border: 1px solid var(--correct-border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--success);
    font-size: 1rem;
    flex-shrink: 0;
}

.achievement-toast-title {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--correct-text);
    font-weight: 500;
}

.achievement-toast-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.achievement-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 380px;
    max-width: 100vw;
    height: 100vh;
    background: var(--bg-primary);
    border-left: 1px solid var(--border);
    z-index: 200;
    transition: right 0.3s var(--ease);
    overflow-y: auto;
    padding: 1.5rem;
}

.achievement-panel.active {
    right: 0;
}

.achievement-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.achievement-panel-header h2 {
    font-size: 1.125rem;
    font-weight: 500;
    letter-spacing: -0.01em;
}

.achievement-close {
    border: none !important;
    padding: 0.5rem !important;
}

.achievement-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.achievement-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: all 0.2s var(--ease);
}

.achievement-item.locked {
    opacity: 0.45;
}

.achievement-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
    flex-shrink: 0;
}

.achievement-item.unlocked .achievement-icon {
    background: var(--correct-bg);
    border-color: var(--correct-border);
    color: var(--success);
}

.achievement-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.achievement-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.achievement-info {
    flex: 1;
}

.achievement-check {
    color: var(--success);
    font-size: 0.875rem;
}

.mic-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s var(--ease);
    margin-bottom: 1rem;
    font-size: 1rem;
}

.mic-btn:hover {
    border-color: var(--border);
    color: var(--text-primary);
}

.mic-btn.listening {
    background: var(--incorrect-bg);
    border-color: var(--incorrect-border);
    color: var(--error);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%,
    100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

.review-badge {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--correct-text);
    background: var(--correct-bg);
    border: 1px solid var(--correct-border);
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-pill);
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
}

.btn,
.choice-btn,
.subject-card,
.word-chip {
    position: relative;
    overflow: hidden;
}

.ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.08);
    width: 100px;
}

[data-theme="dark"] .ripple {
    background: rgba(255, 255, 255, 0.08);
    height: 100px;
    margin-left: -50px;
    margin-top: -50px;
    animation: rippleEffect 0.5s ease-out;
    pointer-events: none;
}

@keyframes correctBounce {
    0% {
        transform: scale(1);
    }
    30% {
        transform: scale(1.05);
        box-shadow: 0 0 0 6px rgba(0, 0, 0, 0.06);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes incorrectShake {
    0% {
        transform: translateX(0);
    }
    20% {
        transform: translateX(-6px);
    }
    40% {
        transform: translateX(6px);
    }
    60% {
        transform: translateX(-4px);
    }
    80% {
        transform: translateX(4px);
    }
    100% {
        transform: translateX(0);
    }
}

.question-card.correct-anim {
    animation: correctBounce 0.5s var(--ease);
    border-color: var(--correct-border);
}

.question-card.incorrect-anim {
    animation: incorrectShake 0.5s var(--ease);
    border-color: var(--incorrect-border);
}

@keyframes xpFloat {
    0% {
        opacity: 1;
        transform: translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateY(-40px);
    }
}

.xp-float {
    position: absolute;
    top: -0.25rem;
    right: 0;
    font-size: 0.875rem;
    font-weight: 800;
    color: var(--text-primary);
    pointer-events: none;
    animation: xpFloat 1s var(--ease) forwards;
    z-index: 101;
}

@keyframes confettiFall {
    0% {
        transform: translateY(-10px) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

.confetti-piece {
    position: fixed;
    top: -10px;
    width: 8px;
    height: 8px;
    z-index: 1000;
    pointer-events: none;
    animation: confettiFall 2s var(--ease) forwards;
}

@keyframes rippleEffect {
    from {
        transform: scale(0);
        opacity: 1;
    }
    to {
        transform: scale(4);
        opacity: 0;
    }
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s var(--ease);
    font-size: 0.875rem;
    padding: 0;
}

.theme-toggle:hover {
    background: var(--bg-secondary);
    border-color: var(--border);
    color: var(--text-primary);
}

[data-theme="light"] .theme-toggle .fa-sun {
    display: none;
}

[data-theme="light"] .theme-toggle .fa-moon {
    display: inline;
}

[data-theme="dark"] .theme-toggle .fa-sun {
    display: inline;
}

[data-theme="dark"] .theme-toggle .fa-moon {
    display: none;
}

/* Dark theme already matches root -- editorial dark is the default */

.sr-only:focus {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: auto !important;
    height: auto !important;
    padding: 0.75rem 1.5rem !important;
    margin: 0 !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border: 2px solid var(--accent) !important;
    border-radius: var(--radius-md) !important;
    z-index: 10000 !important;
    font-size: 0.875rem;
    font-weight: 700;
}

/* ── Fade-up entrance animation ── */

.fade-up {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease-out, transform 0.8s ease-out;
}

.fade-up.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ── Noise texture overlay ── */

.noise-overlay {
    display: none;
}

/* ── Auth / Landing screen ── */

dialog.auth-shell {
    border: none;
    border-radius: 1.25rem;
    padding: 2rem;
    max-width: 480px;
    width: 90%;
    background: var(--surface);
    color: var(--text-primary);
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
    max-height: 90vh;
    overflow-y: auto;
}
dialog.auth-shell::backdrop {
    background: rgba(0, 0, 0, 0.5);
}
.auth-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
    padding: 0.25rem;
}
.auth-close:hover { color: var(--text-primary); }

.auth-card {
    max-width: 100%;
    width: 100%;
    position: relative;
}

.auth-copy {
    margin-bottom: 2.5rem;
}

.auth-section-label {
    font-family: var(--font);
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.auth-heading {
    font-family: var(--font-display);
    font-style: italic;
    font-size: clamp(2.5rem, 7vw, 4rem);
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1.1;
    margin-bottom: 1rem;
}

.auth-subtitle {
    font-family: var(--font);
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-secondary);
    max-width: 360px;
}

.auth-panel {
    width: 100%;
}

.auth-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.auth-tab {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.875rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.auth-tab.active {
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.auth-field {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.auth-field span {
    font-family: var(--font);
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
}

.auth-field input {
    font-family: var(--font);
    font-size: 1rem;
    padding: 0.875rem 1rem;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    transition: border-color 0.2s var(--ease);
    outline: none;
}

.auth-field input::placeholder {
    color: var(--text-muted);
}

.auth-field input:focus {
    border-color: var(--accent);
}

.auth-avatar-label {
    font-family: var(--font);
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    margin-bottom: -0.5rem;
}

/* ── Avatar picker (3x2 grid) ── */

.avatar-picker {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.avatar-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 0.5rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: transform 0.2s var(--spring), border-color 0.2s var(--ease);
    font-family: var(--font);
}

.avatar-option:hover {
    transform: translateY(-2px);
    border-color: var(--text-muted);
}

.avatar-option.selected {
    border-color: var(--text-primary);
    background: var(--choice-selected-bg);
}

.avatar-emoji {
    font-size: 1.5rem;
    line-height: 1;
}

.avatar-label {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* ── Auth CTA (pill button) ── */

.auth-submit {
    background: var(--text-primary);
    color: var(--bg-primary);
    border: 1px solid var(--text-primary);
    border-radius: 100px;
    padding: 0.875rem 2rem;
    font-family: var(--font);
    font-size: 0.9375rem;
    font-weight: 500;
    letter-spacing: 0;
    cursor: pointer;
    transition: opacity 0.4s ease-out, transform 0.2s var(--spring);
    margin-top: 0.5rem;
}

.auth-submit:hover {
    opacity: 0.85;
    transform: translateY(-2px);
}

/* ── Auth feedback ── */

.auth-feedback {
    font-family: var(--font);
    font-size: 0.875rem;
    color: var(--accent);
    margin-top: 1rem;
    min-height: 1.25rem;
}

.auth-feedback.success {
    color: var(--accent);
}

.auth-feedback.error {
    color: var(--error);
}

/* ── Profile chip (header) ── */

.profile-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.75rem 0.25rem 0.25rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: transform 0.2s var(--spring), border-color 0.2s var(--ease);
    font-family: var(--font);
}

.profile-chip:hover {
    transform: translateY(-2px);
    border-color: var(--text-muted);
}

.profile-chip-avatar {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--bg-tertiary);
    font-size: 0.875rem;
    line-height: 1;
}

.profile-chip-name {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-primary);
}

/* ── Profile panel (slide-out) ── */

.profile-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 380px;
    max-width: 100vw;
    height: 100vh;
    background: var(--bg-primary);
    border-left: 1px solid var(--border);
    z-index: 200;
    transition: right 0.3s var(--ease);
    overflow-y: auto;
    padding: 1.5rem;
}

.profile-panel.active {
    right: 0;
}

.profile-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.profile-panel-header h2 {
    font-family: var(--font);
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.profile-panel-kicker {
    font-size: 0.6875rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

.profile-summary {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
}

.profile-summary-avatar {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--bg-tertiary);
    font-size: 1.5rem;
    flex-shrink: 0;
}

.profile-summary-copy {
    flex: 1;
}

.profile-summary-name {
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.125rem;
}

.profile-summary-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

@media (max-width: 640px) {
    .auth-shell {
        min-height: auto;
        padding: 1rem 0;
    }

    .avatar-picker {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }

    .avatar-option {
        padding: 0.75rem 0.25rem;
    }

    .auth-heading {
        font-size: clamp(1.75rem, 5vw, 2.5rem);
    }

    .profile-panel {
        width: 100vw;
        right: -100vw;
    }
}

/* ============================================================
   GAMES
   ============================================================ */

.game-container {
    display: none;
}

.game-container.active {
    display: block;
    animation: fadeUp 0.35s var(--ease);
}

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.game-title {
    font-family: var(--font);
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--text-primary);
}

.game-back-btn,
.game-restart-btn {
    font-size: 0.8125rem;
    padding: 0.5rem 1rem;
}

.game-board {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.game-instructions {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 0.5rem;
}

.game-won {
    color: var(--accent);
    font-weight: 800;
}

/* Chess */

.chess-status {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-align: center;
}

.chess-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    width: min(360px, calc(100vw - 3rem));
    aspect-ratio: 1;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.chess-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s var(--ease);
    position: relative;
}

.chess-cell.light { background: #b7c0a8; }
.chess-cell.dark { background: #6b8f4e; }

[data-theme="light"] .chess-cell.light { background: #ecd8b0; }
[data-theme="light"] .chess-cell.dark { background: #b58863; }

.chess-cell.selected { background: #d4a843 !important; }
.chess-cell.valid-move::after {
    content: '';
    position: absolute;
    width: 30%;
    height: 30%;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.25);
}

.chess-piece {
    font-size: clamp(1.25rem, 4vw, 2.25rem);
    line-height: 1;
    user-select: none;
    pointer-events: none;
}

.chess-piece.white-piece { filter: drop-shadow(0 1px 1px rgba(0,0,0,0.3)); }
.chess-piece.black-piece { filter: drop-shadow(0 1px 1px rgba(0,0,0,0.2)); }

/* 2048 */

.game-2048-score {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-align: center;
}

.game-2048-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    width: min(320px, calc(100vw - 3rem));
    padding: 6px;
    background: var(--border);
    border-radius: var(--radius-md);
}

.tile-2048 {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.5rem;
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: all 0.1s var(--ease);
    font-variant-numeric: tabular-nums;
}

.tile-2048[data-value="2"] { background: #eee4da; color: #776e65; }
.tile-2048[data-value="4"] { background: #ede0c8; color: #776e65; }
.tile-2048[data-value="8"] { background: #f2b179; color: #f9f6f2; }
.tile-2048[data-value="16"] { background: #f59563; color: #f9f6f2; }
.tile-2048[data-value="32"] { background: #f67c5f; color: #f9f6f2; }
.tile-2048[data-value="64"] { background: #f65e3b; color: #f9f6f2; }
.tile-2048[data-value="128"] { background: #edcf72; color: #f9f6f2; font-size: 1.25rem; }
.tile-2048[data-value="256"] { background: #edcc61; color: #f9f6f2; font-size: 1.25rem; }
.tile-2048[data-value="512"] { background: #edc850; color: #f9f6f2; font-size: 1.25rem; }
.tile-2048[data-value="1024"] { background: #edc53f; color: #f9f6f2; font-size: 1rem; }
.tile-2048[data-value="2048"] { background: #3d9e6a; color: #f9f6f2; font-size: 1rem; }

/* Memory */

.memory-stats {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-align: center;
}

.memory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    width: min(320px, calc(100vw - 3rem));
}

.memory-card {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    background: var(--bg-tertiary);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: transform 0.2s var(--spring), background 0.2s var(--ease);
    user-select: none;
}

.memory-card:hover { transform: translateY(-2px); }
.memory-card.flipped { background: var(--bg-secondary); border-color: var(--accent); }
.memory-card.matched { background: var(--correct-bg); border-color: var(--correct-border); opacity: 0.7; }

/* Minesweeper */

.mine-status {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-align: center;
}

.mine-grid {
    display: grid;
    gap: 1px;
    width: min(320px, calc(100vw - 3rem));
    background: var(--border);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.mine-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
    font-weight: 800;
    background: var(--bg-tertiary);
    cursor: pointer;
    user-select: none;
    transition: background 0.1s var(--ease);
}

.mine-cell:hover { background: var(--bg-secondary); }
.mine-cell.revealed { background: var(--bg-primary); cursor: default; }
.mine-cell.mine { background: var(--incorrect-bg); }
.mine-cell[data-num="1"] { color: #4a90d9; }
.mine-cell[data-num="2"] { color: #3d9e6a; }
.mine-cell[data-num="3"] { color: #c44040; }
.mine-cell[data-num="4"] { color: #7b5ea7; }
.mine-cell[data-num="5"] { color: #d4a843; }
.mine-cell[data-num="6"] { color: #3d9e6a; }
.mine-cell[data-num="7"] { color: var(--text-primary); }
.mine-cell[data-num="8"] { color: var(--text-muted); }

/* Snake */

.snake-score {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-align: center;
}

.snake-canvas {
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    display: block;
    max-width: 100%;
}

.snake-controls {
    display: grid;
    grid-template-areas:
        '. up .'
        'left . right'
        '. down .';
    gap: 6px;
    width: 160px;
    margin-top: 0.5rem;
}

.snake-dir-btn {
    width: 48px;
    height: 48px;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: var(--radius-sm);
}

.snake-dir-up { grid-area: up; justify-self: center; }
.snake-dir-left { grid-area: left; justify-self: end; }
.snake-dir-right { grid-area: right; justify-self: start; }
.snake-dir-down { grid-area: down; justify-self: center; }

/* ---- Skill tree (Phase 2) ---- */
.skill-tree { display: none; max-width: 640px; margin: 0 auto; }
.skill-tree.active { display: block; animation: fadeUp 0.4s ease both; }
.tree-back {
    display: inline-flex; align-items: center; gap: 0.4rem;
    background: none; border: none; cursor: pointer; padding: 0.4rem 0;
    color: var(--text-muted); font-size: 0.8125rem; margin-bottom: 1rem;
    transition: color 0.2s;
}
.tree-back:hover { color: var(--text-secondary); }
.tree-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; }
.tree-icon {
    width: 56px; height: 56px; border-radius: 16px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    background: var(--card-bg); border: 1px solid var(--card-border);
    font-size: 1.5rem; color: var(--accent);
}
.tree-title { font-size: 1.5rem; margin: 0; }
.tree-sub { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.2rem; }
.tree-unit { margin-bottom: 1.75rem; }
.tree-unit-title {
    font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.12em;
    color: var(--text-muted); margin-bottom: 0.75rem;
}
.tree-node {
    display: flex; align-items: center; gap: 0.85rem; width: 100%;
    text-align: left; padding: 0.85rem 1rem; margin-bottom: 0.6rem;
    background: var(--card-bg); border: 1px solid var(--card-border);
    border-radius: 14px; cursor: pointer; color: var(--text-primary);
    font-size: 0.95rem; min-height: 44px;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), border-color 0.2s;
}
.tree-node:hover:not(.locked) { transform: translateY(-2px); border-color: var(--accent); }
.tree-node-dot {
    width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-tertiary); color: var(--text-secondary); font-size: 0.85rem;
}
.tree-node.complete .tree-node-dot { background: var(--accent-amber); color: var(--bg-primary); }
.tree-node.locked { opacity: 0.5; cursor: not-allowed; }
.tree-node-label { flex: 1; }
.tts-btn { margin-left: 0.75rem; padding: 0.35rem 0.85rem; font-size: 0.8125rem; }
