/* ========================================
   MathéMagique - Fun Math for Kids!
   ======================================== */

:root {
    /* Brand palette — unchanged between themes */
    --purple-dark: #4C1D95;
    --purple: #6D28D9;
    --purple-light: #8B5CF6;
    --purple-lighter: #C4B5FD;
    --purple-lightest: #EDE9FE;
    --gold: #F59E0B;
    --gold-light: #FCD34D;
    --green: #10B981;
    --green-light: #6EE7B7;
    --red: #EF4444;
    --red-light: #FCA5A5;
    --pink: #EC4899;
    --blue: #3B82F6;
    --blue-light: #93C5FD;
    --orange: #F97316;
    --white: #FFFFFF;
    --gray-50: #F9FAFB;
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-600: #4B5563;
    --gray-800: #1F2937;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.15);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.2);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-lg: 24px;
    --font-display: 'Fredoka', sans-serif;
    --font-body: 'Nunito', sans-serif;

    /* === Theme surfaces ===
       Default theme = "couleur" (purple gradient). These are the surface
       and overlay tokens that change when [data-theme="clair"] is set. */
    --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --bg-overlay: linear-gradient(135deg, rgba(102, 126, 234, 0.7) 0%, rgba(118, 75, 162, 0.7) 100%);
    --bg-image: url('../assets/bg-hero.png');
    --splash-bg: linear-gradient(135deg, #4C1D95 0%, #6D28D9 40%, #8B5CF6 100%);
    --splash-hint-color: rgba(255,255,255,0.6);
    --surface-card: #ffffff;
    --surface-card-2: #f9fafb;
    --text-on-surface: var(--gray-800);
    --text-muted: var(--gray-600);
    --border-soft: rgba(196, 181, 253, 0.4);
    --bottom-bar-bg: rgba(255,255,255,0.95);
    --bottom-bar-text: var(--purple);
}

/* === Light "Clair" theme — for daytime, school, or parents who prefer
       lower-saturation surfaces. Brand accents stay vibrant; only the
       backgrounds and overlays change. */
[data-theme="clair"] {
    --bg-gradient: linear-gradient(135deg, #fef3e8 0%, #ffe8d6 60%, #fde7f3 100%);
    --bg-overlay: linear-gradient(135deg, rgba(255,245,235,0.55) 0%, rgba(253,230,243,0.45) 100%);
    --bg-image: none;
    --splash-bg: linear-gradient(135deg, #fef3e8 0%, #ffe8d6 50%, #ede9fe 100%);
    --splash-hint-color: var(--purple-dark);
    --border-soft: rgba(109, 40, 217, 0.18);
    --bottom-bar-bg: #ffffff;
}

/* Honor OS preference on first load when nothing is saved.
   JS still wins once the user toggles. */
@media (prefers-color-scheme: light) {
    :root:not([data-theme]) {
        --bg-gradient: linear-gradient(135deg, #fef3e8 0%, #ffe8d6 60%, #fde7f3 100%);
        --bg-overlay: linear-gradient(135deg, rgba(255,245,235,0.55) 0%, rgba(253,230,243,0.45) 100%);
        --bg-image: none;
        --splash-bg: linear-gradient(135deg, #fef3e8 0%, #ffe8d6 50%, #ede9fe 100%);
        --splash-hint-color: var(--purple-dark);
        --border-soft: rgba(109, 40, 217, 0.18);
    }
}

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

body {
    font-family: var(--font-body);
    background: var(--bg-gradient);
    background-image: var(--bg-image);
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    min-height: 100vh;
    overflow-x: hidden;
    color: var(--text-on-surface);
}

/* Overlay to keep text readable over the background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-overlay);
    z-index: -1;
}

/* ========== Splash Screen — Just Beedy ========== */
.splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    background: var(--splash-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
}

.splash-screen.hidden {
    display: none !important;
}

.splash-content {
    animation: splashFadeIn 0.8s ease;
}

@keyframes splashFadeIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

.splash-beedy {
    width: 260px;
    height: 260px;
    border-radius: 50%;
    object-fit: cover;
    border: 6px solid rgba(255,255,255,0.3);
    box-shadow: 0 0 60px rgba(245, 158, 11, 0.4), 0 10px 40px rgba(0,0,0,0.3);
    animation: splashBounce 1.8s ease-in-out infinite;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.splash-beedy:hover {
    transform: scale(1.1);
    box-shadow: 0 0 80px rgba(245, 158, 11, 0.6), 0 10px 40px rgba(0,0,0,0.3);
}

@keyframes splashBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

.splash-hint {
    color: var(--splash-hint-color);
    font-family: var(--font-display);
    font-size: 1.1rem;
    margin-top: 24px;
    animation: splashHintPulse 2s ease-in-out infinite;
}

@keyframes splashHintPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.8; }
}

@media (max-width: 768px) {
    .splash-beedy {
        width: 200px;
        height: 200px;
    }
}

/* ========== Stars Background ========== */
#stars-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.floating-star {
    position: absolute;
    font-size: 20px;
    opacity: 0.3;
    animation: floatStar linear infinite;
}

@keyframes floatStar {
    0% { transform: translateY(100vh) rotate(0deg); opacity: 0; }
    10% { opacity: 0.3; }
    90% { opacity: 0.3; }
    100% { transform: translateY(-10vh) rotate(360deg); opacity: 0; }
}

/* ========== Top Bar ========== */
.top-bar {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 5000;
    display: flex;
    gap: 8px;
    align-items: center;
}

#speech-toggle, #lang-toggle, #teacher-toggle {
    background: rgba(255,255,255,0.95);
    border: 2px solid var(--purple-light);
    border-radius: 25px;
    padding: 6px 16px;
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 700;
    color: var(--purple);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: var(--shadow-sm);
}

#lang-toggle:hover, #teacher-toggle:hover {
    background: var(--purple);
    color: white;
    transform: scale(1.05);
}

#teacher-toggle {
    font-size: 16px;
    padding: 6px 12px;
}

.flag { font-size: 18px; }

/* ========== Teacher Panel ========== */
.teacher-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: fadeIn 0.3s ease;
}

.teacher-overlay.hidden {
    display: none !important;
}

.teacher-panel {
    background: white;
    border-radius: var(--radius-lg);
    max-width: 520px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
}

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

.teacher-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 2px solid var(--gray-100);
    background: linear-gradient(135deg, var(--purple) 0%, var(--purple-light) 100%);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.teacher-header h2 {
    font-family: var(--font-display);
    color: white;
    font-size: 1.3rem;
    margin: 0;
}

.teacher-close {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    font-size: 1.5rem;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.teacher-close:hover {
    background: rgba(255,255,255,0.4);
}

/* PIN Gate */
.teacher-pin-gate {
    padding: 32px 24px;
    text-align: center;
}

.teacher-pin-gate p {
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 16px;
}

.pin-input-row {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 12px;
}

.pin-input {
    width: 100px;
    padding: 10px 16px;
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    border: 3px solid var(--purple-lighter);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    outline: none;
    letter-spacing: 6px;
}

.pin-input:focus {
    border-color: var(--purple);
    box-shadow: 0 0 0 4px rgba(109, 40, 217, 0.2);
}

.pin-error {
    color: var(--red);
    font-weight: 700;
    font-size: 0.9rem;
    animation: shake 0.5s ease;
}

.pin-hint {
    color: var(--gray-600);
    font-size: 0.8rem;
    margin-top: 8px;
    font-style: italic;
}

/* Teacher Controls */
.teacher-controls {
    padding: 0 24px 24px;
}

.teacher-section {
    padding: 20px 0;
    border-bottom: 1px solid var(--gray-100);
}

.teacher-section:last-child {
    border-bottom: none;
}

.teacher-section h3 {
    font-family: var(--font-display);
    color: var(--purple-dark);
    font-size: 1rem;
    margin-bottom: 14px;
}

/* Module Toggles */
.module-toggles, .difficulty-toggles {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.module-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s;
    position: relative;
    flex-wrap: wrap;
}

.module-toggle:hover {
    background: var(--gray-50);
}

.module-toggle input[type="checkbox"] {
    display: none;
}

/* Toggle Slider */
.toggle-slider {
    width: 44px;
    height: 24px;
    background: var(--gray-200);
    border-radius: 12px;
    position: relative;
    transition: background 0.3s;
    flex-shrink: 0;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.module-toggle input:checked + .toggle-slider {
    background: var(--green);
}

.module-toggle input:checked + .toggle-slider::after {
    transform: translateX(20px);
}

.toggle-icon {
    font-size: 1.3rem;
    flex-shrink: 0;
}

.module-toggle > span:not(.toggle-slider):not(.toggle-icon):not(.toggle-sub) {
    font-weight: 700;
    color: var(--gray-800);
    font-size: 0.95rem;
}

.toggle-sub {
    width: 100%;
    padding-left: 56px;
    font-size: 0.8rem;
    color: var(--gray-600);
    font-weight: 400;
    margin-top: -4px;
}

/* PIN change */
.pin-change-row {
    display: flex;
    gap: 12px;
    align-items: center;
}

.pin-change-row .pin-input {
    font-size: 1.1rem;
    letter-spacing: 4px;
}

.teacher-footer {
    text-align: center;
    padding-top: 16px;
}

/* ========== Pages ========== */
.page {
    display: none;
    min-height: 100vh;
    position: relative;
    z-index: 1;
    padding: 16px;
    padding-top: 60px;
    animation: fadeIn 0.4s ease;
}

.page.active {
    display: block;
}

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

/* ========== Page Header ========== */
.page-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.page-header h1 {
    font-family: var(--font-display);
    color: white;
    font-size: 1.8rem;
    flex: 1;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.back-btn {
    background: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.4);
    color: white;
    padding: 8px 16px;
    border-radius: 25px;
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    white-space: nowrap;
}

.back-btn:hover {
    background: rgba(255,255,255,0.3);
    transform: translateX(-4px);
}

.stars-display {
    background: rgba(255,255,255,0.2);
    padding: 8px 16px;
    border-radius: 25px;
    color: white;
    font-weight: 700;
    font-size: 1.1rem;
}

/* ========== HOME PAGE ========== */
.home-container {
    max-width: 900px;
    margin: 0 auto;
    text-align: center;
}

.logo-area {
    margin-bottom: 40px;
}

.wizard-hat {
    font-size: 80px;
    animation: bounce 2s ease-in-out infinite;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.2));
}

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

.app-title {
    font-family: var(--font-display);
    font-size: 3.5rem;
    margin: 10px 0;
    text-shadow: 3px 3px 6px rgba(0,0,0,0.2);
}

.title-math { color: var(--gold-light); }
.title-magic { color: white; }

.tagline {
    color: rgba(255,255,255,0.9);
    font-size: 1.3rem;
    font-weight: 600;
}

/* Grade Cards (Home Page) */
.grade-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 600px;
    margin: 0 auto 32px;
}

.grade-card {
    background: white;
    border-radius: var(--radius);
    padding: 18px 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
    border-left: 5px solid var(--grade-color, var(--purple));
    display: flex;
    align-items: center;
    gap: 16px;
    text-align: left;
}

.grade-card:hover {
    transform: translateX(8px);
    box-shadow: var(--shadow-md);
}

.grade-card:active { transform: translateX(4px); }

.grade-icon { font-size: 2.2rem; flex-shrink: 0; }

.grade-info { flex: 1; }
.grade-info h2 {
    font-family: var(--font-display);
    font-size: 1.3rem;
    color: var(--gray-800);
    margin-bottom: 2px;
}
.grade-module-count { font-size: 0.85rem; color: var(--gray-600); }

.grade-stars-badge {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--gold);
    white-space: nowrap;
}

/* Module Cards (Grade Page) */
.module-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
    max-width: 900px;
    margin: 0 auto;
    padding: 0 8px;
}

.module-card {
    background: white;
    border-radius: var(--radius);
    padding: 16px 18px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 14px;
    border-left: 4px solid var(--grade-color, var(--purple));
}

.module-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.module-icon { font-size: 1.8rem; flex-shrink: 0; }

.module-info { flex: 1; }
.module-info h3 {
    font-family: var(--font-display);
    font-size: 1rem;
    color: var(--gray-800);
    margin-bottom: 2px;
}
.module-info p { font-size: 0.8rem; color: var(--gray-600); margin: 0; }

.module-badge {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--gold);
    white-space: nowrap;
}

/* Module Tabs */
.module-tabs {
    display: flex;
    gap: 4px;
    max-width: 700px;
    margin: 0 auto 20px;
    background: rgba(255,255,255,0.15);
    border-radius: 30px;
    padding: 4px;
}

.tab-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.7);
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 0.95rem;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s;
}

.tab-btn.active {
    background: white;
    color: var(--purple-dark);
    box-shadow: var(--shadow-sm);
}

.tab-content { display: none; max-width: 700px; margin: 0 auto; }
.tab-content.active { display: block; animation: fadeIn 0.3s ease; }

/* Lesson Slides */
.lesson-content-area { margin-bottom: 16px; }

.lesson-slide-card {
    background: linear-gradient(180deg, #FFF9E6 0%, #FFF3CC 30%, #FFFDF5 100%);
    border-radius: var(--radius-lg);
    padding: 32px 28px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12), inset 0 0 60px rgba(245,158,11,0.05);
    text-align: center;
    min-height: 380px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border: 3px solid #F3DFA0;
    position: relative;
    overflow: hidden;
}

/* Storybook page curl effect */
.lesson-slide-card::before {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, transparent 50%, #F0D890 50%, #E8C860 100%);
    border-radius: 0 0 var(--radius-lg) 0;
    box-shadow: -2px -2px 5px rgba(0,0,0,0.05);
}

/* Decorative corner stars */
.lesson-slide-card::after {
    content: '✨';
    position: absolute;
    top: 12px;
    right: 16px;
    font-size: 1.2rem;
    opacity: 0.4;
}

.lesson-slide-num {
    font-size: 0.75rem;
    color: #C4A44A;
    margin-bottom: 8px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.lesson-slide-card h2 {
    font-family: var(--font-display);
    color: #5B3A8C;
    font-size: 1.7rem;
    margin-bottom: 16px;
    line-height: 1.3;
}

.lesson-visual-emoji { font-size: 4rem; margin-bottom: 20px; filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.lesson-visual-text { font-size: 1.4rem; margin-bottom: 16px; line-height: 1.8; }

.lesson-example {
    background: linear-gradient(135deg, #EDE9FE 0%, #DDD6FE 100%);
    border-radius: 16px;
    padding: 16px 28px;
    margin: 16px 0;
    display: inline-block;
    border: 2px solid var(--purple-lighter);
    box-shadow: 0 3px 10px rgba(109,40,217,0.1);
}

.lesson-example code {
    font-family: 'Courier New', monospace;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--purple-dark);
}

/* Beedy Teacher Layout */
.lesson-slide-title {
    font-family: var(--font-display);
    color: #5B3A8C;
    font-size: 1.7rem;
    margin-bottom: 12px;
    line-height: 1.3;
}

.beedy-teacher-row {
    display: flex;
    align-items: flex-end;
    gap: 0;
    margin-top: 16px;
    margin-bottom: 8px;
}

.beedy-teacher-avatar {
    flex-shrink: 0;
    position: relative;
    z-index: 2;
}

.beedy-teacher-vid {
    width: 130px;
    height: 130px;
    border-radius: 20px;
    object-fit: cover;
    border: 3px solid #E8C860;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    display: block;
}

.beedy-teacher-bubble {
    flex: 1;
    background: linear-gradient(135deg, #EDE9FE 0%, #F3EFFF 100%);
    border-radius: 20px;
    border-bottom-left-radius: 6px;
    padding: 18px 22px;
    margin-left: -12px;
    position: relative;
    border: 2px solid var(--purple-lighter);
    box-shadow: 0 3px 12px rgba(109,40,217,0.08);
    min-height: 80px;
    display: flex;
    align-items: center;
}

/* Speech pointer towards Beedy */
.beedy-teacher-bubble::before {
    content: '';
    position: absolute;
    left: -10px;
    bottom: 20px;
    width: 0;
    height: 0;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 12px solid var(--purple-lighter);
}

.beedy-teacher-bubble::after {
    content: '';
    position: absolute;
    left: -7px;
    bottom: 22px;
    width: 0;
    height: 0;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-right: 10px solid #EDE9FE;
}

.beedy-teacher-bubble .lesson-slide-text {
    text-align: left;
    margin: 0;
    font-size: 1.25rem;
}

.beedy-lesson-img {
    width: 130px;
    height: 130px;
    border-radius: 20px;
    object-fit: cover;
    border: 3px solid #E8C860;
    flex-shrink: 0;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

/* Animated Beedy in practice prompt */
.beedy-prompt-vid {
    width: 55px;
    height: 55px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--purple-lighter);
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

/* Animated Beedy in difficulty select / challenge */
.beedy-inline-vid {
    width: 55px;
    height: 55px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--purple-lighter);
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    flex-shrink: 0;
}

.beedy-section-vid {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--purple-lighter);
    box-shadow: 0 3px 12px rgba(0,0,0,0.15);
}

.btn-listen {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
    padding: 10px 22px;
    background: linear-gradient(135deg, #8B5CF6 0%, #6D28D9 100%);
    color: white;
    border: none;
    border-radius: 25px;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 3px 12px rgba(109,40,217,0.3);
}

.btn-listen:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 5px 18px rgba(109,40,217,0.4);
}

.btn-listen:active {
    transform: translateY(0) scale(0.98);
}

.lesson-visual-demo {
    margin: 16px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lesson-table-grid {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: center;
}

.lesson-table-col {
    background: var(--purple-lightest);
    border-radius: 10px;
    padding: 10px 14px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--purple-dark);
    line-height: 1.8;
}

.lesson-table-col strong {
    display: block;
    color: var(--purple);
    font-size: 1.1rem;
    margin-bottom: 4px;
    border-bottom: 2px solid var(--purple-lighter);
    padding-bottom: 4px;
}

.lesson-slide-text {
    font-family: var(--font-body);
    font-size: 1.35rem;
    color: #4A3660;
    line-height: 1.8;
    font-weight: 600;
    max-width: 500px;
    margin: 0 auto;
}

/* Lesson slide illustration image */
.lesson-slide-illustration {
    width: 100%;
    max-width: 280px;
    border-radius: 16px;
    margin: 16px auto;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    border: 3px solid rgba(255,255,255,0.8);
}

.lesson-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 16px;
}

.lesson-nav .btn-primary,
.lesson-nav .btn-secondary {
    font-size: 1.05rem;
    padding: 12px 24px;
}

/* Beedy inline */
.beedy-inline {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    justify-content: center;
}

.beedy-speech-inline {
    background: white;
    border-radius: var(--radius);
    padding: 10px 18px;
    border: 2px solid var(--purple-lighter);
    position: relative;
}

.beedy-speech-inline::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 0; height: 0;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-right: 8px solid var(--purple-lighter);
}

.beedy-speech-inline p {
    font-weight: 600;
    color: var(--purple-dark);
    font-size: 1rem;
    margin: 0;
}

/* Engine visual area */
.engine-area { text-align: center; margin-bottom: 16px; }
.engine-visual { display: inline-block; margin: 12px 0; }

/* Footer */
.home-footer {
    color: rgba(255,255,255,0.7);
    font-size: 0.9rem;
}

.footer-credits {
    margin-top: 10px;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.6);
}

.footer-credits p {
    margin: 2px 0;
}

.footer-link {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    font-weight: 700;
    transition: color 0.2s;
}

.footer-link:hover {
    color: var(--gold-light);
}

.footer-stats {
    background: rgba(255,255,255,0.15);
    display: inline-block;
    padding: 8px 20px;
    border-radius: 25px;
    margin-bottom: 8px;
    font-weight: 700;
    color: white;
}

/* Progress Grade Cards */
.progress-grade-card {
    background: white;
    border-radius: var(--radius-sm);
    padding: 14px 18px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-left: 4px solid var(--purple);
    box-shadow: var(--shadow-sm);
}

.progress-grade-icon { font-size: 1.5rem; }
.progress-grade-name { flex: 1; font-weight: 700; color: var(--gray-800); }
.progress-grade-stats { font-size: 0.9rem; color: var(--gray-600); font-weight: 600; }

/* Branch headers in module list */
.branch-header {
    font-family: var(--font-display);
    color: white;
    font-size: 1.1rem;
    padding: 12px 8px 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.2);
    grid-column: 1 / -1;
}

.branch-icon { font-size: 1.3rem; }

.branch-img {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: cover;
}

.teacher-branch-label {
    font-size: 0.85rem;
    color: var(--gray-600);
    padding: 8px 0 4px 12px;
    border-top: 1px solid var(--gray-100);
    margin-top: 4px;
}

/* Teacher module toggle sub */
.module-toggle-sub { padding-left: 24px; }
.teacher-grade-header { margin-bottom: 4px; }
.teacher-module-list { padding-bottom: 8px; }

/* ========== BUTTONS ========== */
.btn {
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 1rem;
    padding: 10px 24px;
    border-radius: 25px;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--purple) 0%, var(--purple-light) 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(109, 40, 217, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(109, 40, 217, 0.4);
}

.btn-secondary {
    background: white;
    color: var(--purple);
    border: 2px solid var(--purple-lighter);
}

.btn-secondary:hover {
    background: var(--purple-lightest);
    transform: translateY(-2px);
}

.btn-hint {
    background: linear-gradient(135deg, var(--gold) 0%, var(--orange) 100%);
    color: white;
}

.btn-large {
    font-size: 1.2rem;
    padding: 14px 32px;
}

.pulse-btn {
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 4px 12px rgba(109, 40, 217, 0.3); }
    50% { box-shadow: 0 4px 24px rgba(109, 40, 217, 0.6); }
}

/* ========== LESSON PAGE ========== */
.lesson-container {
    max-width: 800px;
    margin: 0 auto;
}

.lesson-slide {
    display: none;
    animation: slideIn 0.5s ease;
}

.lesson-slide.active {
    display: block;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

.slide-content {
    background: white;
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-lg);
    min-height: 400px;
}

.slide-content h2 {
    font-family: var(--font-display);
    color: var(--purple-dark);
    font-size: 1.6rem;
    margin-bottom: 20px;
    text-align: center;
}

.slide-visual {
    margin: 24px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.slide-text {
    font-size: 1.1rem;
    line-height: 1.6;
    color: var(--gray-600);
    text-align: center;
    margin-top: 16px;
}

/* Lesson Intro Visual */
.thought-bubble {
    background: var(--purple-lightest);
    border-radius: var(--radius);
    padding: 16px 24px;
    margin-bottom: 16px;
    position: relative;
    border: 2px solid var(--purple-lighter);
}

.thought-bubble p {
    font-size: 1.1rem;
    color: var(--purple-dark);
    font-weight: 600;
}

.candy-row {
    font-size: 1.5rem;
    line-height: 2;
    text-align: center;
    letter-spacing: 4px;
}

/* Demo Division Display */
.demo-division {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    font-family: 'Courier New', monospace;
    font-size: 2rem;
    font-weight: 700;
    margin: 20px 0;
}

.demo-left {
    text-align: right;
    min-width: 100px;
    padding-right: 12px;
}

.demo-bracket {
    border-left: 3px solid var(--purple-dark);
    border-bottom: 0;
    min-height: 80px;
    width: 0;
    position: relative;
}

.demo-right {
    text-align: left;
    padding-left: 12px;
    min-width: 80px;
}

.demo-divisor {
    color: var(--blue);
    padding-bottom: 4px;
    border-bottom: 3px solid var(--purple-dark);
    margin-bottom: 8px;
}

.demo-quotient {
    color: var(--green);
}

.demo-row {
    display: flex;
    justify-content: flex-end;
    margin: 2px 0;
}

.demo-row.subtract {
    color: var(--red);
    font-size: 1.6rem;
}

.demo-separator {
    border-bottom: 2px solid var(--gray-200);
    margin: 4px 0;
    width: 100%;
}

.demo-digit {
    display: inline-block;
    width: 1.2em;
    text-align: center;
}

.demo-digit.placeholder {
    color: var(--gray-200);
}

.dividend-highlight .demo-digit { color: var(--orange); }
.divisor-highlight { color: var(--blue) !important; }

.label-arrows {
    display: flex;
    justify-content: space-around;
    width: 100%;
    margin-top: 16px;
    flex-wrap: wrap;
    gap: 8px;
}

.label-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    min-width: 120px;
}

.label-arrow {
    font-size: 1.5rem;
    color: var(--purple);
}

.label-text {
    font-size: 0.85rem;
    color: var(--gray-600);
    text-align: center;
    font-family: var(--font-body);
}

/* Step Explanation */
.step-explanation {
    background: var(--purple-lightest);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-top: 16px;
    text-align: center;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.step-explanation p {
    font-size: 1rem;
    color: var(--purple-dark);
    font-weight: 600;
}

.demo-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-top: 16px;
}

.step-counter {
    font-weight: 700;
    color: var(--purple);
    min-width: 60px;
    text-align: center;
}

/* Remainder Example */
.remainder-example {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.highlight-rest {
    color: var(--orange) !important;
    font-weight: 900;
    font-size: 2.2rem !important;
}

.remainder-callout {
    background: var(--gold-light);
    border-radius: var(--radius);
    padding: 12px 24px;
    margin-top: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.callout-text {
    font-family: var(--font-display);
    font-size: 1.2rem;
    color: var(--gray-800);
}

.callout-emoji { font-size: 2rem; }

/* Ready Visual */
.ready-visual {
    padding: 24px 0;
}

.ready-stars {
    font-size: 3rem;
    margin-bottom: 16px;
    animation: bounce 1.5s ease-in-out infinite;
}

.ready-character {
    font-size: 5rem;
    margin-bottom: 16px;
}

.ready-text {
    font-size: 1.2rem;
    color: var(--purple-dark);
    font-weight: 600;
    margin-bottom: 24px;
}

.ready-buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Slide Navigation */
.slide-dots {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 20px 0;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(255,255,255,0.4);
    cursor: pointer;
    transition: all 0.3s;
}

.dot.active {
    background: var(--gold);
    transform: scale(1.3);
}

.slide-nav {
    display: flex;
    justify-content: center;
    gap: 16px;
}

/* ========== PRACTICE PAGE ========== */
.practice-container {
    max-width: 700px;
    margin: 0 auto;
}

.difficulty-panel {
    text-align: center;
}

.difficulty-panel h2 {
    font-family: var(--font-display);
    color: white;
    font-size: 1.6rem;
    margin-bottom: 24px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.difficulty-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
}

.diff-card {
    background: white;
    border-radius: var(--radius);
    padding: 24px 16px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: var(--shadow-md);
    border: 3px solid transparent;
}

.diff-card:hover { transform: translateY(-6px); box-shadow: var(--shadow-lg); }

.diff-easy:hover { border-color: var(--green); }
.diff-medium:hover { border-color: var(--blue); }
.diff-hard:hover { border-color: var(--orange); }
.diff-expert:hover { border-color: var(--red); }

.diff-icon { font-size: 2.5rem; margin-bottom: 8px; }

.diff-card h3 {
    font-family: var(--font-display);
    color: var(--purple-dark);
    margin-bottom: 8px;
}

.diff-card p {
    font-size: 0.85rem;
    color: var(--gray-600);
    margin-bottom: 4px;
}

.diff-example {
    font-family: 'Courier New', monospace;
    font-weight: 700;
    color: var(--purple);
    font-size: 1rem !important;
}

/* Practice Area */
.practice-area {
    animation: fadeIn 0.5s ease;
}

.practice-problem-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.problem-num {
    color: white;
    font-weight: 700;
    font-size: 1.1rem;
}

.difficulty-badge {
    background: rgba(255,255,255,0.2);
    color: white;
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
}

/* ========== DIVISION BOARD ========== */
.division-board {
    background: white;
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-lg);
    margin-bottom: 20px;
    overflow-x: auto;
}

.division-visual {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    font-family: 'Courier New', monospace;
    font-size: 1.8rem;
    font-weight: 700;
    gap: 0;
}

.division-left {
    text-align: right;
    padding-right: 12px;
    min-width: 120px;
}

.division-bracket-line {
    border-left: 3px solid var(--purple-dark);
    min-height: 60px;
    align-self: stretch;
}

.division-right {
    text-align: left;
    padding-left: 12px;
    min-width: 80px;
}

.division-divisor {
    color: var(--blue);
    border-bottom: 3px solid var(--purple-dark);
    padding-bottom: 6px;
    margin-bottom: 8px;
}

.division-quotient {
    color: var(--green);
    min-height: 1.8em;
}

.div-row {
    display: flex;
    justify-content: flex-end;
    margin: 2px 0;
    min-height: 1.8em;
}

.div-row.subtract-row {
    color: var(--red);
}

.div-row.separator-row {
    border-bottom: 2px solid var(--gray-200);
    margin: 4px 0;
    min-height: 0;
    height: 2px;
}

.div-row.remainder-row {
    color: var(--purple-dark);
}

.div-row.final-remainder {
    color: var(--orange);
    font-size: 2rem;
}

.div-cell {
    display: inline-block;
    width: 1.3em;
    text-align: center;
    transition: all 0.4s ease;
}

.div-cell.new {
    animation: popIn 0.4s ease;
}

@keyframes popIn {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.3); }
    100% { transform: scale(1); opacity: 1; }
}

.quotient-digit {
    display: inline-block;
    width: 1.3em;
    text-align: center;
    transition: all 0.4s ease;
}

.quotient-digit.new {
    animation: popIn 0.4s ease;
}

.div-cell.highlight, .quotient-digit.highlight {
    background: var(--gold-light);
    border-radius: 6px;
}

.div-cell.bringing-down {
    animation: bringDown 0.6s ease;
}

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

/* ========== Step Prompt ========== */
.step-prompt {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 16px;
}

.prompt-character {
    font-size: 2.5rem;
    flex-shrink: 0;
    animation: bounce 2s ease-in-out infinite;
}

.prompt-bubble {
    background: var(--purple-lightest);
    border-radius: var(--radius);
    border-top-left-radius: 4px;
    padding: 14px 20px;
    flex: 1;
    border: 2px solid var(--purple-lighter);
}

.prompt-bubble p {
    font-size: 1.05rem;
    color: var(--purple-dark);
    font-weight: 600;
    line-height: 1.4;
}

/* ========== Input Area ========== */
.input-area {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.step-input {
    width: 100px;
    padding: 12px 16px;
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    border: 3px solid var(--purple-lighter);
    border-radius: var(--radius-sm);
    font-family: 'Courier New', monospace;
    outline: none;
    transition: all 0.3s;
}

.step-input:focus {
    border-color: var(--purple);
    box-shadow: 0 0 0 4px rgba(109, 40, 217, 0.2);
}

.step-input.correct {
    border-color: var(--green);
    background: #ECFDF5;
}

.step-input.wrong {
    border-color: var(--red);
    background: #FEF2F2;
    animation: shake 0.5s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-8px); }
    40%, 80% { transform: translateX(8px); }
}

/* ========== Feedback ========== */
.feedback-area {
    text-align: center;
    margin: 12px 0;
    min-height: 40px;
}

.feedback-message {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 1.1rem;
    display: inline-block;
    animation: popIn 0.4s ease;
}

.feedback-message.correct {
    background: #ECFDF5;
    color: var(--green);
    border: 2px solid var(--green-light);
}

.feedback-message.wrong {
    background: #FEF2F2;
    color: var(--red);
    border: 2px solid var(--red-light);
}

.feedback-message.hint {
    background: #FFFBEB;
    color: var(--orange);
    border: 2px solid var(--gold-light);
}

/* ========== Problem Complete ========== */
.problem-complete {
    text-align: center;
    padding: 24px;
    animation: fadeIn 0.6s ease;
}

.complete-stars {
    font-size: 3rem;
    margin-bottom: 12px;
    animation: bounce 1s ease-in-out infinite;
}

.problem-complete h2 {
    font-family: var(--font-display);
    color: var(--green);
    font-size: 2rem;
    margin-bottom: 8px;
}

.problem-complete p {
    color: var(--gray-600);
    font-size: 1.1rem;
    margin-bottom: 20px;
}

.complete-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ========== CHALLENGE PAGE ========== */
.challenge-container {
    max-width: 600px;
    margin: 0 auto;
}

.challenge-setup {
    text-align: center;
    background: white;
    border-radius: var(--radius-lg);
    padding: 40px 32px;
    box-shadow: var(--shadow-lg);
}

.challenge-setup h2 {
    font-family: var(--font-display);
    color: var(--purple-dark);
    font-size: 1.4rem;
    margin-bottom: 24px;
}

.challenge-difficulty {
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.challenge-difficulty label {
    font-weight: 700;
    color: var(--gray-600);
}

.challenge-difficulty select {
    padding: 8px 16px;
    font-size: 1rem;
    font-family: var(--font-body);
    font-weight: 700;
    border: 2px solid var(--purple-lighter);
    border-radius: var(--radius-sm);
    color: var(--purple-dark);
    cursor: pointer;
}

.challenge-best {
    margin-top: 20px;
    font-weight: 700;
    color: var(--gray-600);
}

/* Challenge Active */
.challenge-hud {
    display: flex;
    justify-content: space-around;
    margin-bottom: 24px;
    gap: 12px;
}

.hud-item {
    background: white;
    border-radius: var(--radius);
    padding: 12px 20px;
    font-weight: 700;
    font-size: 1.3rem;
    box-shadow: var(--shadow-sm);
    flex: 1;
    text-align: center;
}

.hud-timer { color: var(--red); }
.hud-score { color: var(--gold); }
.hud-streak { color: var(--orange); }

.hud-timer.urgent {
    animation: urgentPulse 0.5s ease infinite;
    background: #FEF2F2;
}

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

.challenge-problem {
    background: white;
    border-radius: var(--radius-lg);
    padding: 32px;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.challenge-question {
    font-family: 'Courier New', monospace;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--purple-dark);
    margin-bottom: 24px;
}

.challenge-input-row {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 16px;
}

.challenge-input {
    width: 140px;
    padding: 12px 16px;
    font-size: 2rem;
    font-weight: 700;
    text-align: center;
    border: 3px solid var(--purple-lighter);
    border-radius: var(--radius-sm);
    font-family: 'Courier New', monospace;
    outline: none;
    transition: all 0.3s;
}

.challenge-input:focus {
    border-color: var(--purple);
    box-shadow: 0 0 0 4px rgba(109, 40, 217, 0.2);
}

.challenge-feedback {
    font-weight: 700;
    font-size: 1.3rem;
    min-height: 40px;
    padding: 8px;
}

.challenge-feedback.correct { color: var(--green); }
.challenge-feedback.wrong { color: var(--red); }

/* Challenge Results */
.challenge-results {
    text-align: center;
    animation: fadeIn 0.6s ease;
}

.results-header h2 {
    font-family: var(--font-display);
    color: white;
    font-size: 2rem;
    margin-bottom: 24px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.results-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-md);
}

.stat-value {
    font-family: var(--font-display);
    font-size: 2.5rem;
    color: var(--purple);
}

.stat-label {
    color: var(--gray-600);
    font-size: 0.85rem;
    font-weight: 600;
}

.new-record {
    font-family: var(--font-display);
    font-size: 1.5rem;
    color: var(--gold);
    margin-bottom: 24px;
    animation: bounce 1s ease infinite;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.results-buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ========== TABLES PAGE ========== */
.tables-container {
    max-width: 700px;
    margin: 0 auto;
}

.tables-selector {
    text-align: center;
}

.tables-selector h2 {
    font-family: var(--font-display);
    color: white;
    font-size: 1.4rem;
    margin-bottom: 24px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.tables-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.table-btn {
    background: white;
    border: 3px solid transparent;
    border-radius: var(--radius);
    padding: 20px;
    font-family: var(--font-display);
    font-size: 1.5rem;
    color: var(--purple-dark);
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: var(--shadow-sm);
}

.table-btn:hover {
    border-color: var(--purple);
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.table-quiz-btn {
    background: linear-gradient(135deg, var(--gold) 0%, var(--orange) 100%);
    color: white;
    grid-column: span 2;
}

.table-display, .table-quiz {
    background: white;
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.table-display h3, .table-quiz h3 {
    font-family: var(--font-display);
    color: var(--purple-dark);
    font-size: 1.5rem;
    margin-bottom: 20px;
}

.table-content {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}

.table-row {
    font-family: 'Courier New', monospace;
    font-size: 1.2rem;
    font-weight: 700;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s;
}

.table-row:hover {
    background: var(--purple-lightest);
}

.quiz-score {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--gray-600);
    margin-bottom: 20px;
}

.quiz-question {
    font-family: 'Courier New', monospace;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--purple-dark);
    margin-bottom: 20px;
}

.quiz-input-row {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 16px;
}

.quiz-input {
    width: 100px;
    padding: 10px 16px;
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    border: 3px solid var(--purple-lighter);
    border-radius: var(--radius-sm);
    font-family: 'Courier New', monospace;
    outline: none;
}

.quiz-input:focus {
    border-color: var(--purple);
    box-shadow: 0 0 0 4px rgba(109, 40, 217, 0.2);
}

.quiz-feedback {
    font-weight: 700;
    font-size: 1.2rem;
    min-height: 30px;
}

.quiz-complete h3 {
    margin-top: 20px;
}

/* ========== PROGRESS PAGE ========== */
.progress-container {
    max-width: 700px;
    margin: 0 auto;
}

.progress-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.summary-card {
    background: white;
    border-radius: var(--radius);
    padding: 24px 16px;
    text-align: center;
    box-shadow: var(--shadow-md);
    transition: transform 0.3s;
}

.summary-card:hover {
    transform: translateY(-4px);
}

.total-stars-card {
    background: linear-gradient(135deg, var(--gold-light) 0%, var(--gold) 100%);
}

.total-stars-card .summary-value { color: white; }
.total-stars-card .summary-label { color: rgba(255,255,255,0.9); }

.summary-icon { font-size: 2rem; margin-bottom: 8px; }

.summary-value {
    font-family: var(--font-display);
    font-size: 2.5rem;
    color: var(--purple);
}

.summary-label {
    font-size: 0.85rem;
    color: var(--gray-600);
    font-weight: 600;
}

.progress-badges h2 {
    font-family: var(--font-display);
    color: white;
    font-size: 1.4rem;
    margin-bottom: 16px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.badges-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 32px;
}

.badge-card {
    background: white;
    border-radius: var(--radius);
    padding: 20px 12px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s;
}

.badge-card.locked {
    opacity: 0.5;
    filter: grayscale(1);
}

.badge-card.unlocked {
    border: 2px solid var(--gold);
}

.badge-icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
}

.badge-name {
    font-family: var(--font-display);
    font-size: 0.9rem;
    color: var(--purple-dark);
    margin-bottom: 4px;
}

.badge-desc {
    font-size: 0.75rem;
    color: var(--gray-600);
}

.progress-actions {
    text-align: center;
}

/* ========== CONFETTI ========== */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

/* ========== UTILITY ========== */
.hidden {
    display: none !important;
}

/* ========== ANIMATED DEMO (Lesson) ========== */
.animated-demo {
    min-height: 200px;
}

.animated-demo .demo-left {
    min-width: 140px;
}

.demo-step-highlight {
    background: var(--gold-light);
    border-radius: 4px;
    padding: 0 2px;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .page {
        padding: 12px;
        padding-top: 54px;
    }

    .top-bar {
        top: 8px;
        right: 8px;
        gap: 6px;
    }

    #speech-toggle, #music-toggle, #lang-toggle, #teacher-toggle {
        padding: 5px 10px;
        font-size: 12px;
    }

    .lesson-slide-card {
        padding: 20px 16px;
        min-height: 300px;
    }

    .lesson-slide-title {
        font-size: 1.3rem;
    }

    .beedy-teacher-row {
        flex-direction: column;
        align-items: center;
        gap: 12px;
    }

    .beedy-teacher-avatar {
        order: -1;
    }

    .beedy-teacher-vid, .beedy-lesson-img {
        width: 100px;
        height: 100px;
    }

    .beedy-teacher-bubble {
        margin-left: 0;
        border-bottom-left-radius: 20px;
        border-radius: 20px;
    }

    .beedy-teacher-bubble::before,
    .beedy-teacher-bubble::after {
        display: none;
    }

    .beedy-teacher-bubble .lesson-slide-text {
        text-align: center;
        font-size: 1.1rem;
    }

    .lesson-slide-illustration {
        max-width: 200px;
    }

    .lesson-example code {
        font-size: 1.3rem;
    }

    .teacher-panel {
        max-height: 90vh;
    }

    .toggle-sub {
        padding-left: 0;
        width: 100%;
    }

    .app-title {
        font-size: 2.2rem;
    }

    .beedy-img {
        width: 90px;
        height: 90px;
    }

    .beedy-small {
        width: 40px;
        height: 40px;
    }

    .beedy-speech p {
        font-size: 0.9rem;
    }

    .tagline {
        font-size: 1rem;
    }

    .home-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .home-card {
        padding: 20px 14px;
    }

    .card-icon {
        font-size: 36px;
    }

    .home-card h2 {
        font-size: 1.1rem;
    }

    .home-card p {
        font-size: 0.8rem;
    }

    .page-header h1 {
        font-size: 1.3rem;
    }

    .slide-content {
        padding: 20px;
        min-height: 300px;
    }

    .slide-content h2 {
        font-size: 1.3rem;
    }

    .demo-division {
        font-size: 1.4rem;
    }

    .division-visual {
        font-size: 1.4rem;
    }

    .division-board {
        padding: 20px 16px;
    }

    .step-input, .challenge-input {
        width: 80px;
        font-size: 1.3rem;
    }

    .challenge-question {
        font-size: 2rem;
    }

    .difficulty-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .results-stats {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .stat-value {
        font-size: 1.8rem;
    }

    .tables-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .table-btn {
        padding: 14px;
        font-size: 1.2rem;
    }

    .table-quiz-btn {
        grid-column: span 3;
    }

    .hud-item {
        padding: 8px 12px;
        font-size: 1.1rem;
    }

    .prompt-character {
        font-size: 2rem;
    }

    .prompt-bubble p {
        font-size: 0.95rem;
    }

    .candy-row {
        font-size: 1.1rem;
        letter-spacing: 2px;
    }

    .label-arrows {
        flex-direction: column;
        align-items: center;
    }
}

@media (max-width: 400px) {
    .home-cards {
        grid-template-columns: 1fr;
    }

    .app-title {
        font-size: 1.8rem;
    }

    .difficulty-cards {
        grid-template-columns: 1fr;
    }

    .tables-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .results-stats {
        grid-template-columns: 1fr;
    }
}

/* ========== BEEDY CHARACTER ========== */
.beedy-character {
    display: inline-block;
    margin-bottom: 8px;
}

.beedy-video {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    object-fit: cover;
    filter: drop-shadow(0 6px 20px rgba(0,0,0,0.3));
    border: 4px solid rgba(255,255,255,0.5);
}

.beedy-img {
    width: 120px;
    height: 120px;
    filter: drop-shadow(0 4px 12px rgba(0,0,0,0.2));
}

.beedy-small {
    width: 50px;
    height: 50px;
    filter: drop-shadow(0 2px 6px rgba(0,0,0,0.15));
}

.beedy-medium {
    width: 100px;
    height: 100px;
    filter: drop-shadow(0 3px 8px rgba(0,0,0,0.2));
}

/* Beedy talking animation */
.beedy-talking {
    animation: beedyTalk 0.3s ease-in-out infinite alternate !important;
}

@keyframes beedyTalk {
    0% { transform: scale(1) rotate(0deg); }
    50% { transform: scale(1.03) rotate(-1deg); }
    100% { transform: scale(1) rotate(1deg); }
}

.beedy-wave {
    animation: beedyBounce 2.5s ease-in-out infinite;
}

.beedy-celebrate {
    animation: beedyCelebrate 1s ease-in-out infinite;
}

.beedy-think {
    animation: beedyThink 3s ease-in-out infinite;
}

.beedy-happy {
    animation: beedyHappy 0.6s ease;
}

.beedy-sad {
    animation: beedySad 0.5s ease;
}

@keyframes beedyBounce {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-10px) rotate(-3deg); }
    50% { transform: translateY(0) rotate(0deg); }
    75% { transform: translateY(-10px) rotate(3deg); }
}

@keyframes beedyCelebrate {
    0%, 100% { transform: scale(1) rotate(0deg); }
    25% { transform: scale(1.1) rotate(-5deg); }
    50% { transform: scale(1) rotate(0deg); }
    75% { transform: scale(1.1) rotate(5deg); }
}

@keyframes beedyThink {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(5px); }
}

@keyframes beedyHappy {
    0% { transform: scale(1); }
    30% { transform: scale(1.2) rotate(5deg); }
    60% { transform: scale(1.1) rotate(-3deg); }
    100% { transform: scale(1) rotate(0deg); }
}

@keyframes beedySad {
    0% { transform: translateY(0); }
    30% { transform: translateY(5px) rotate(-3deg); }
    100% { transform: translateY(0) rotate(0deg); }
}

/* Beedy Speech Bubble */
.beedy-speech {
    background: white;
    border-radius: var(--radius);
    padding: 14px 24px;
    margin: 12px auto;
    max-width: 500px;
    position: relative;
    box-shadow: var(--shadow-sm);
    border: 2px solid var(--purple-lighter);
}

.beedy-speech::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-bottom: 10px solid var(--purple-lighter);
}

.beedy-speech::after {
    content: '';
    position: absolute;
    top: -7px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 8px solid white;
}

.beedy-speech p {
    font-size: 1.05rem;
    color: var(--purple-dark);
    font-weight: 600;
    line-height: 1.5;
    margin: 0;
}

.home-speech {
    animation: fadeIn 0.8s ease 0.5s both;
}

/* Beedy Reaction Overlay */
.beedy-reaction {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9998;
    text-align: center;
    pointer-events: none;
    animation: reactionPop 1.2s ease forwards;
}

.beedy-reaction .beedy-img {
    width: 150px;
    height: 150px;
}

.beedy-reaction-text {
    font-family: var(--font-display);
    font-size: 2rem;
    color: var(--purple-dark);
    background: white;
    padding: 8px 24px;
    border-radius: 25px;
    box-shadow: var(--shadow-lg);
    margin-top: 8px;
    display: inline-block;
}

@keyframes reactionPop {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3); }
    30% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
    50% { transform: translate(-50%, -50%) scale(1); }
    80% { opacity: 1; }
    100% { opacity: 0; transform: translate(-50%, -60%) scale(0.8); }
}

/* ========== PRINT ========== */
@media print {
    body { background: white; }
    .page { padding: 0; }
    #lang-toggle, .back-btn, .btn, #stars-bg, #confetti-canvas { display: none; }
}

/* ========== ACCESSIBILITY ==========
   Honor user OS preferences. Kids with vestibular sensitivity, school
   high-contrast modes, and keyboard-only users all need to be served. */

/* Visible focus ring on every interactive element (defaults to none on most
   browsers' button styling). Uses focus-visible so mouse users don't see it. */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible,
.tab-btn:focus-visible,
.module-card:focus-visible {
    outline: 3px solid var(--gold);
    outline-offset: 2px;
    border-radius: 8px;
}

/* Reduced-motion: turn off non-essential animation for users who set
   "Reduce Motion" in their OS. Keeps transitions short so the app
   still feels responsive but doesn't bounce or shake. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 80ms !important;
        scroll-behavior: auto !important;
    }
    .floating-star,
    .splash-beedy,
    .pulse-btn,
    .reaction-burst,
    .beedy-bounce {
        animation: none !important;
    }
    #confetti-canvas { display: none !important; }
}

/* Forced-colors: Windows High Contrast / Firefox color override. Keep
   the critical interactive surfaces visible — browsers swap colors to
   system tokens but we still need our buttons to look like buttons. */
@media (forced-colors: active) {
    .btn,
    .tab-btn,
    .back-btn,
    .pin-input,
    .step-input,
    .module-card {
        forced-color-adjust: none;
        border: 2px solid ButtonText;
        background: ButtonFace;
        color: ButtonText;
    }
    .btn-primary,
    .btn-large,
    .pulse-btn {
        background: Highlight;
        color: HighlightText;
        border-color: Highlight;
    }
    .feedback-message.correct { color: LinkText; }
    .feedback-message.wrong { color: Mark; }
}

/* Theme-toggle button — sits in the top bar with lang + teacher buttons */
#theme-toggle {
    background: rgba(255,255,255,0.95);
    border: 2px solid var(--purple-light);
    border-radius: 25px;
    padding: 6px 12px;
    font-family: var(--font-body);
    font-size: 16px;
    color: var(--purple);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    box-shadow: var(--shadow-sm);
}
#theme-toggle:hover {
    background: var(--purple);
    color: white;
    transform: scale(1.05);
}
[data-theme="clair"] #theme-toggle {
    background: #ffffff;
    border-color: var(--gold);
    color: var(--gold);
}
[data-theme="clair"] #theme-toggle:hover {
    background: var(--gold);
    color: white;
}

/* Skip-to-content link for screen readers / keyboard users */
.skip-link {
    position: absolute;
    top: -100px;
    left: 8px;
    background: var(--purple);
    color: white;
    padding: 10px 16px;
    border-radius: 6px;
    font-weight: 700;
    z-index: 99999;
    transition: top 0.2s;
}
.skip-link:focus {
    top: 8px;
}

/* ========== STUDENT CODE BADGE + MODAL ========== */
#student-code-btn {
    background: rgba(255,255,255,0.95);
    border: 2px solid var(--gold);
    border-radius: 25px;
    padding: 6px 14px;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 700;
    color: var(--purple-dark);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: var(--shadow-sm);
    letter-spacing: 1.2px;
}
#student-code-btn:hover {
    background: var(--gold);
    color: white;
    transform: scale(1.05);
}
[data-theme="clair"] #student-code-btn {
    background: #ffffff;
}

.student-code-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: fadeIn 0.25s ease;
}
.student-code-overlay.hidden { display: none !important; }

.student-code-panel {
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    max-width: 460px;
    width: 100%;
    padding: 28px 26px 24px;
    box-shadow: var(--shadow-lg);
    position: relative;
    animation: slideUp 0.3s ease;
    color: var(--text-on-surface);
}
.student-code-panel h2 {
    font-family: var(--font-display);
    color: var(--purple-dark);
    margin: 0 0 10px;
    font-size: 1.3rem;
}
.student-code-panel h3 {
    font-family: var(--font-display);
    color: var(--purple-dark);
    margin: 0 0 8px;
    font-size: 1rem;
}
.sc-help {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0 0 14px;
    line-height: 1.45;
}
.sc-current-code {
    font-family: 'Fredoka', monospace;
    font-size: 2.4rem;
    font-weight: 700;
    letter-spacing: 0.4em;
    color: var(--purple);
    text-align: center;
    padding: 14px 8px;
    background: var(--purple-lightest);
    border: 2px dashed var(--purple-light);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    user-select: all;
}
.sc-copy { margin-bottom: 0; display: block; margin: 0 auto; }
.sc-divider {
    height: 1px;
    background: var(--border-soft);
    margin: 22px 0 18px;
}
.sc-resume-row {
    display: flex;
    gap: 10px;
    align-items: stretch;
}
#sc-resume-input {
    flex: 1;
    padding: 12px 14px;
    font-family: 'Fredoka', monospace;
    font-size: 1.4rem;
    font-weight: 700;
    text-align: center;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    border: 2px solid var(--purple-lighter);
    border-radius: var(--radius-sm);
    outline: none;
    color: var(--purple-dark);
    background: var(--white);
}
#sc-resume-input:focus {
    border-color: var(--purple);
    box-shadow: 0 0 0 4px rgba(109, 40, 217, 0.15);
}
.sc-status {
    margin: 12px 0 0;
    font-weight: 700;
    text-align: center;
    min-height: 1.2em;
    font-size: 0.9rem;
}
.sc-status.sc-ok { color: var(--green); }
.sc-status.sc-err { color: var(--red); }
.sc-close {
    position: absolute;
    top: 10px;
    right: 12px;
    background: transparent;
    border: none;
    font-size: 1.6rem;
    color: var(--text-muted);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
}
.sc-close:hover { background: var(--gray-100); }

@media (max-width: 480px) {
    .sc-current-code { font-size: 1.8rem; letter-spacing: 0.3em; }
    #sc-resume-input { font-size: 1.1rem; letter-spacing: 0.3em; }
    .sc-resume-row { flex-direction: column; }
}

/* Screen-reader-only utility — keeps labels readable by assistive tech
   without affecting the visual layout. */
.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
