@import url("https://jaybulb.com/tokens.css");
@import url("neutral.css?v=20261004b");

@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:var(--bg);--bg-secondary:var(--bg2);--bg-tertiary:var(--color-code-bg);--text-primary:var(--text);--text-secondary:var(--text2);--text-muted:var(--text3);--accent-amber:var(--bulb-deep);--font:var(--font-body);--font-display:var(--font-body);--spring:var(--spring);--card-bg:var(--bg);--card-border:var(--border);--input-bg:var(--bg);--header-bg:var(--bg);--choice-selected-bg:var(--bg2);--subject-1:var(--bg2);--subject-2:var(--bg2);--subject-3:var(--bg2);--subject-4:var(--bg2);--subject-5:var(--bg2);--icon-bg:var(--bg2);--icon-border:var(--border2);
    --success: #5c6f1f;
    --error: #c44040;
    --card-shadow: rgba(0, 0, 0, 0.04);
    --correct-bg: #f5f5e6;
    --correct-border: #cdd59f;
    --correct-text: #5c6f1f;
    --incorrect-bg: #faf0f0;
    --incorrect-border: #d4a3a3;
}
[data-theme="dark"]{
    --success: #9bb04f;
    --error: #c44040;
    --card-shadow: rgba(0, 0, 0, 0.2);
    --correct-bg: #22250f;
    --correct-border: #4a5222;
    --correct-text: #9bb04f;
    --incorrect-bg: #2a1818;
    --incorrect-border: #5a2a2a;
}

* {
    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: rgba(255,255,255,0.85);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--border);
    padding: env(safe-area-inset-top, 0) 0 0 0;
}

[data-theme="dark"] .header {
    background: rgba(10,10,10,0.85);
}

.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.5rem;
    align-items: center;
}

/* Streak / XP / hearts read as one unit, not three competing pills */
.stat-group {
    display: flex;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--bg-secondary);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 400;
    padding: 0.3125rem 0.6875rem;
    letter-spacing: 0.01em;
}

.stat-group .stat-item + .stat-item {
    border-left: 1px solid var(--border);
}

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

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

.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;
    /* inset line instead of border-bottom so tabs can't overflow it vertically */
    box-shadow: inset 0 -2px 0 var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    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;
}

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

.category-tab.active {
    color: var(--link, var(--accent));
    border-bottom-color: var(--link, 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;
}

/* Fill the stretched .container instead of sitting at natural height, which
   left a large dead band under the question card on tall screens. */
.lesson-container.active {
    display: flex;
    flex-direction: column;
    min-height: 100%;
    animation: fadeUp 0.35s var(--ease);
}

.lesson-container.active .question-card {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Question grows, so the Skip/Check row settles at the bottom of the card. */
.lesson-container.active .question-container {
    flex: 1;
}

@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;
    display: flex;
    gap: 4px;
}

.progress-pip {
    flex: 1;
    background: var(--border);
    height: 8px;
    border-radius: 999px;
    overflow: hidden;
    transition: background 0.3s var(--ease);
}

.progress-pip.filled { background: var(--accent); }

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

.profile-quest {
    margin-bottom: 16px;
}

.profile-quest-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.profile-quest-bar {
    background: var(--border);
    height: 8px;
    border-radius: 999px;
    overflow: hidden;
}

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

.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(--link, 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(--link, 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;
    margin-top: 1rem;
    margin-top: 1rem;
}

.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;
}

.feedback-explain {
    margin: 0.5rem 0 0;
    font-weight: 400;
    opacity: 0.85;
}

.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;
    }

    /* Flex children default to min-width:auto, so .logo and .stats refused to
       shrink below their content width. The row overflowed, body's
       overflow-x:hidden clipped the login control, and the over-wide row
       dragged the page past the viewport so the subject grid's last column
       was cut off too. Let both children shrink; scroll the pills instead. */
    .header-inner {
        gap: 0.5rem;
    }

    .logo {
        min-width: 0;
    }

    .logo span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .stats {
        gap: 0.375rem;
        min-width: 0;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .stats::-webkit-scrollbar {
        display: none;
    }

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

    .profile-chip-name {
        max-width: 5.5rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .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(--link, var(--accent));
    outline: none;
}

.achievement-toast {
    position: fixed;
    bottom: -120px;
    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: bottom 0.3s var(--spring);
    max-width: 90vw;
}

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

.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;
}

.subject-grade {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.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;
    }
}

.icon-btn,
.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;
    font-family: var(--font);
}

.icon-btn:hover,
.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(--bg-secondary);
    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-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(--link, 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-forgot {
    background: none;
    border: none;
    padding: 0.5rem;
    font-family: var(--font);
    font-size: 0.8125rem;
    color: var(--text-secondary);
    text-decoration: underline;
    cursor: pointer;
}

.auth-forgot:hover {
    color: var(--text-primary);
}

/* ── Auth feedback ── */

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

.auth-feedback.success {
    color: var(--link, 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: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--bg-tertiary);
    font-size: 2rem;
    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);
}

.profile-overview {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.profile-overview-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-primary);
}

.profile-overview-item i {
    color: var(--link, var(--accent));
}

@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(--link, 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: #9bb04f; 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(--link, 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: #9bb04f; }
.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: #9bb04f; }
.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(--link, 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; position: relative;
    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(--link, var(--accent)); }
.tree-node:not(:last-child)::after {
    content: ''; position: absolute; left: 1.63rem; top: 100%;
    width: 1px; height: 0.6rem; background: var(--card-border);
}
.tree-node.complete:not(:last-child)::after { background: var(--accent-amber); }
.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; }

.auth-oauth-row { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.auth-oauth { width: 100%; }

/* Match pairs: two columns, tap one side then the other. */
.match-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-top: 1rem;
}

.match-col {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

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

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

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

.match-btn.matched {
    background: var(--correct-bg);
    border-color: var(--success);
    color: var(--correct-text);
    opacity: 0.55;
    cursor: default;
    transform: none;
}

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

@media (prefers-reduced-motion: reduce) {
    .match-btn { transition: none; }
    .match-btn:hover { transform: none; }
}

/* Signed-out gate shown in place of the course grid. */
.auth-gate {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.75rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.auth-gate-text {
    margin: 0;
    max-width: 46ch;
    color: var(--text-muted);
    line-height: 1.5;
}

/* Demo mode (/app/?demo=1): one real lesson, no account. Hide the chrome that only
   means something to a signed-in player so the page reads as a lesson, not as a
   half-logged-in app. Hearts stay — they are part of the lesson itself. */
body.demo .stat-streak,
body.demo .stat-xp,
body.demo #achievementBtn,
body.demo #profileBtn,
body.demo .category-tabs,
body.demo #skipBtn {
    display: none;
}

/* The streak/xp pills are hidden, so the hearts pill must not keep their divider */
body.demo .stat-group .stat-item {
    border-left: 0;
}

body.demo .header-inner::after {
    content: 'Demo lesson';
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* "Before you start" card above a unit's lessons: grammar note plus real phrases. */
.unit-intro {
    margin: 0 0 1rem;
    padding: 1rem 1.125rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.unit-intro-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.unit-intro-tip {
    margin: 0 0 0.75rem;
    font-size: 0.875rem;
    line-height: 1.55;
    color: var(--text-secondary);
}

.unit-intro-phrases {
    margin: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.25rem 0.875rem;
    font-size: 0.875rem;
}

.unit-intro-phrases dt { font-weight: 600; color: var(--text-primary); }
.unit-intro-phrases dd { margin: 0; color: var(--text-muted); }

/* Course map: one Continue button, units folded to a line each. */
.tree-continue {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    width: 100%; text-align: left; padding: 1rem 1.1rem; margin-bottom: 1.5rem;
    background: var(--text-primary); color: var(--bg-primary); border: 0;
    border-radius: 14px; cursor: pointer; min-height: 44px;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.tree-continue:hover { transform: translateY(-2px); }
.tree-continue > span:first-child { display: flex; flex-direction: column; gap: 0.15rem; }
.tree-continue-kicker { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.12em; opacity: 0.7; }
.tree-continue-title { font-size: 1.05rem; font-weight: 600; }
.tree-continue-where { font-size: 0.8rem; opacity: 0.7; }
.tree-unit-head {
    display: flex; align-items: center; gap: 0.75rem; width: 100%; min-height: 44px;
    padding: 0.85rem 0; margin-bottom: 0.75rem; background: none; border: 0;
    border-bottom: 1px solid var(--border); cursor: pointer; font: inherit; text-align: left;
    color: var(--text-muted);
}
.tree-unit-head .tree-unit-title { margin: 0; flex: 1; }
.tree-unit-count { font-size: 0.75rem; color: var(--text-muted); }
.tree-unit-bar { width: 48px; height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; }
.tree-unit-bar > i { display: block; height: 100%; background: var(--accent); }
.tree-unit-head .fa-chevron-down { font-size: 0.7rem; transition: transform 0.2s; }
.tree-unit-head[aria-expanded="true"] .fa-chevron-down { transform: rotate(180deg); }
.tree-unit-body[hidden] { display: none; }

/* Math answer keypad. */
.math-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.4rem; margin-top: 0.6rem; }
.math-key {
    min-height: 44px; padding: 0 0.4rem; font: inherit; font-size: 0.95rem;
    color: var(--text-primary); background: var(--card-bg); border: 1px solid var(--card-border);
    border-radius: 10px; cursor: pointer; transition: transform 0.15s, border-color 0.15s;
}
.math-key:hover { border-color: var(--text-muted); }
.math-key:active { transform: scale(0.96); }
@media (prefers-reduced-motion: reduce) {
    .tree-continue, .math-key, .tree-unit-head .fa-chevron-down { transition: none; }
}

/* Teaching line under feedback: hear the answer, see what it means. */
.feedback-teach { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.6rem; color: var(--text-primary); font-weight: 400; }
.feedback-hear { flex: none; width: 2rem; height: 2rem; border-radius: 50%; border: 1px solid var(--card-border); background: var(--bg-primary); color: var(--text-primary); cursor: pointer; }
.feedback-hear:hover { border-color: var(--text-secondary); }

/* Phones: the stats pills need the room, the icon alone says Tonchi. */
@media (max-width: 480px) { .logo span { display: none; } }

/* Learn-first card: the lesson's answers before its quiz. */
.learn-card .unit-intro-phrases { grid-template-columns: 1fr; gap: 0.15rem; font-size: 0.9375rem; }
.learn-card dt { display: flex; align-items: center; gap: 0.5rem; }
.learn-card dd { margin: 0 0 0.75rem; color: var(--text-secondary); }

/* Phones: the tab row scrolls sideways, so fade the right edge to say there is more. */
@media (max-width: 600px) {
    .category-tabs { -webkit-mask-image: linear-gradient(to right, #000 85%, transparent); mask-image: linear-gradient(to right, #000 85%, transparent); padding-right: 1.5rem; }
}

/* Chess puzzle board. Sized to the column, square by aspect ratio. */
.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);   /* an empty rank would otherwise collapse */
    width: min(100%, 360px);
    aspect-ratio: 1;
    margin: 0 auto 1.5rem;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border, rgba(0,0,0,0.12));
}
.chess-square {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #eef2f7;
    font-size: clamp(1.25rem, 7vw, 2.1rem);
    line-height: 1;
    user-select: none;
}
.chess-square.dark { background: #9fb6cd; }
.chess-square.white-piece { color: #ffffff; text-shadow: -1px 0 #18181b, 1px 0 #18181b, 0 -1px #18181b, 0 1px #18181b; }
.chess-square.black-piece { color: #18181b; }
