:root {
    color-scheme: dark;
    /* Kid-friendly palette (bright, high-contrast) */
    --bg-deep: #070b14; --bg-main: #0f172a; --bg-card: #172554; --bg-obsidian: #0b1224;
    --accent-blue: #60a5fa; --accent-green: #34d399; --accent-red: #fb7185; --accent-yellow: #fbbf24;
    --accent-purple: #a78bfa; --accent-pink: #f472b6;
    --text-main: #f8fafc; --text-muted: #cbd5e1; --border: rgba(255, 255, 255, 0.14);
    --shadow-soft: 0 10px 30px rgba(0,0,0,0.35);
    --body-bg: #020617;
    /* Surfaces (swap in light theme) */
    --surface-1: rgba(255, 255, 255, 0.06);
    --surface-2: rgba(255, 255, 255, 0.10);
    --surface-3: rgba(255, 255, 255, 0.08);
    --surface-border: rgba(255, 255, 255, 0.12);
    --surface-border-soft: rgba(255, 255, 255, 0.08);
    --surface-border-mid: rgba(255, 255, 255, 0.16);
    --surface-border-strong: rgba(255, 255, 255, 0.18);
    --surface-divider: rgba(255, 255, 255, 0.10);
    --card-bg-a: rgba(255, 255, 255, 0.04);
    --card-bg-b: rgba(255, 255, 255, 0.02);
    --social-fg: #e2e8f0;
    --menu-label-color: #f8fafc;
    --abacus-muted: rgba(255, 255, 255, 0.55);
    --inset-shine: rgba(255, 255, 255, 0.06);
    --inset-shine-strong: rgba(255, 255, 255, 0.12);
    --puzzle-odd-border: rgba(255, 255, 255, 0.2);
    --memory-border: rgba(255, 255, 255, 0.15);
    --memory-bg: rgba(255, 255, 255, 0.08);
    --edu-card-bg: rgba(255, 255, 255, 0.045);
    --c4-slot-bg: rgba(0, 0, 0, 0.35);
    --nav-active-fg: #dbeafe;
    --chip-action-border: rgba(255, 255, 255, 0.10);
    --step-btn-border: rgba(255, 255, 255, 0.15);
    --paint-swatch-ring: rgba(255, 255, 255, 0.2);
}

/* Light theme: override tokens (toggle via data-theme on <html>) */
html[data-theme="light"] {
    color-scheme: light;
    --body-bg: #f1f5f9;
    --bg-deep: #e8edf3;
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --bg-obsidian: #eef2f7;
    --text-main: #0f172a;
    --text-muted: #475569;
    --border: rgba(15, 23, 42, 0.12);
    --shadow-soft: 0 10px 28px rgba(15, 23, 42, 0.08);
    --surface-1: rgba(15, 23, 42, 0.045);
    --surface-2: rgba(15, 23, 42, 0.08);
    --surface-3: rgba(15, 23, 42, 0.06);
    --surface-border: rgba(15, 23, 42, 0.12);
    --surface-border-soft: rgba(15, 23, 42, 0.08);
    --surface-border-mid: rgba(15, 23, 42, 0.16);
    --surface-border-strong: rgba(15, 23, 42, 0.22);
    --surface-divider: rgba(15, 23, 42, 0.1);
    --card-bg-a: rgba(255, 255, 255, 0.98);
    --card-bg-b: rgba(248, 250, 252, 0.99);
    --social-fg: #334155;
    --menu-label-color: #0f172a;
    --abacus-muted: rgba(15, 23, 42, 0.55);
    --inset-shine: rgba(255, 255, 255, 0.55);
    --inset-shine-strong: rgba(255, 255, 255, 0.85);
    --puzzle-odd-border: rgba(15, 23, 42, 0.2);
    --memory-border: rgba(15, 23, 42, 0.16);
    --memory-bg: rgba(15, 23, 42, 0.05);
    --edu-card-bg: rgba(255, 255, 255, 0.92);
    --c4-slot-bg: rgba(15, 23, 42, 0.12);
    --nav-active-fg: #1d4ed8;
    --chip-action-border: rgba(15, 23, 42, 0.12);
    --step-btn-border: rgba(15, 23, 42, 0.18);
    --paint-swatch-ring: rgba(15, 23, 42, 0.28);
}
html[data-theme="light"] .menu-label {
    background: linear-gradient(165deg, rgba(96, 165, 250, 0.22) 0%, #f8fafc 48%, rgba(226, 232, 240, 0.98) 100%);
    border-color: rgba(96, 165, 250, 0.4);
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.9);
    box-shadow:
        0 6px 20px rgba(15, 23, 42, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.95),
        0 0 0 1px rgba(167, 139, 250, 0.1);
}
html[data-theme="light"] .loys-modal-overlay { background: rgba(15, 23, 42, 0.4); }
html[data-theme="light"] .ttt-status--turn { color: #1e40af; }
html[data-theme="light"] .ttt-status--win { color: #047857; }
html[data-theme="light"] .ttt-status--loss { color: #9f1239; }
html[data-theme="light"] .ttt-status--draw { color: #b45309; }
html[data-theme="light"] .abacus-mode-btn--active,
html[data-theme="light"] .paint-brush-btn--active { color: #1e40af !important; }
html[data-theme="light"] .abacus-target-value { color: #047857; }
html[data-theme="light"] .abacus-digit-read { color: #92400e; }
html[data-theme="light"] .puzzle-feedback.ok .puzzle-feedback-link { color: #0369a1 !important; }
html[data-theme="light"] .puzzle-feedback.bad .puzzle-feedback-link { color: #0c4a6e !important; }
html[data-theme="light"] .edu-game-badge { color: #5b21b6; }
html[data-theme="light"] .edu-game-badge--yt { color: #b91c1c; }

* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--body-bg); font-family: 'Poppins', sans-serif; color: var(--text-main); min-height: 100vh; display: flex; align-items: center; justify-content: center; }

.app-shell { display: flex; flex-direction: column; width: 100%; height: 100vh; background: var(--bg-main); overflow: hidden; }

.sidebar-wrapper { background: var(--bg-deep); border-bottom: 1px solid var(--border); }
.about-sidebar { padding: 15px; display: flex; flex-wrap: wrap; align-items: center; gap: 15px; }
.about-sidebar .brand-info { min-width: 0; }
.logo { width: 45px; height: 45px; border-radius: 8px; border: 1px solid var(--accent-blue); }
.tagline { font-size: 11px; color: var(--accent-blue); }
.about-text { display: none; }
.social-block { flex: 1 1 100%; width: 100%; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--surface-divider); }
.social-label { font-size: 11px; color: var(--text-muted); font-weight: 700; margin-bottom: 8px; }
.social-row { display: flex; gap: 10px; }
.social-link { width: 36px; height: 36px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; background: var(--surface-1); border: 1px solid var(--surface-divider); color: var(--social-fg); transition: transform 120ms ease, background 120ms ease, border-color 120ms ease; text-decoration: none; }
.social-link:hover { transform: translateY(-1px); background: var(--surface-2); border-color: var(--surface-border-strong); }
.social-link:active { transform: translateY(0px) scale(0.99); }
.social-link:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }
.social-icon { width: 18px; height: 18px; }

.contact-email-link { color: #f97316; font-weight: 800; text-decoration: underline; text-underline-offset: 3px; }
.contact-email-link:hover { color: #fb923c; }
.contact-email-link:visited { color: #ea580c; }
.contact-email-link:focus-visible { outline: 2px solid #f97316; outline-offset: 2px; }

.nav-sidebar {
    padding: 14px 12px 16px;
    background: var(--bg-obsidian);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    box-sizing: border-box;
}

/* Section title: centered pill inside the nav frame */
.menu-label {
    margin: 0;
    padding: 12px 22px;
    width: fit-content;
    max-width: calc(100% - 8px);
    box-sizing: border-box;
    text-align: center;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.32em;
    text-transform: uppercase;
    color: var(--menu-label-color);
    line-height: 1.35;
    border-radius: 16px;
    background:
        linear-gradient(165deg, rgba(96, 165, 250, 0.22) 0%, rgba(15, 23, 42, 0.92) 45%, rgba(30, 27, 75, 0.55) 100%);
    border: 1px solid rgba(96, 165, 250, 0.38);
    box-shadow:
        0 6px 24px rgba(0, 0, 0, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        0 0 0 1px rgba(167, 139, 250, 0.12);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
    position: relative;
    overflow: hidden;
}
.menu-label::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.07) 50%, transparent 60%);
    pointer-events: none;
}
.menu-label::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    width: 48%;
    height: 2px;
    border-radius: 2px;
    background: linear-gradient(90deg, transparent, var(--accent-blue), var(--accent-purple), transparent);
    opacity: 0.85;
    pointer-events: none;
}

.nav-links {
    display: flex;
    align-self: stretch;
    width: 100%;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 4px;
}
.nav-btn { white-space: nowrap; background: var(--surface-1); border: 1px solid var(--surface-border-soft); color: var(--text-muted); padding: 10px 16px; border-radius: 12px; cursor: pointer; font-weight: 800; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; transition: transform 120ms ease, background 120ms ease, border-color 120ms ease; }
.nav-btn:hover { transform: translateY(-1px); background: var(--surface-2); border-color: var(--surface-border-mid); }
.nav-btn:active { transform: translateY(0px) scale(0.99); }
.nav-btn.active { background: rgba(96, 165, 250, 0.22); color: var(--nav-active-fg); border-color: rgba(96, 165, 250, 0.45); }
.nav-btn:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }

.content { flex: 1; padding: 15px; overflow-y: auto; }
.activity-section { display: none; }
.activity-section.active { display: block; }

.card { background: linear-gradient(180deg, var(--card-bg-a), var(--card-bg-b)); padding: 20px; border-radius: 22px; border: 1px solid var(--border); box-shadow: var(--shadow-soft); }
.section-header { display: flex; flex-direction: column; gap: 15px; margin-bottom: 20px; }

/* COLORFUL PROGRESS BAR */
.timer-wrapper { margin-top: 10px; position: relative; }
.progress-bg { background: var(--bg-obsidian); height: 12px; border-radius: 6px; border: 1px solid var(--border); overflow: hidden; }
.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #38bdf8, #10b981, #facc15, #fb7185);
    background-size: 200% 100%;
    width: 100%;
    transition: width 1s linear;
    animation: flow 3s linear infinite;
}
@keyframes flow { 0% { background-position: 0% 50%; } 100% { background-position: 200% 50%; } }
#timer-text { font-size: 12px; font-weight: 700; color: var(--accent-blue); display: block; margin-bottom: 4px; }

.controls-row { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; border-bottom: 1px solid var(--border); padding-bottom: 15px; }
.btn-group { display: flex; flex-wrap: wrap; gap: 6px; }
.btn-group button { padding: 10px 14px; font-size: 12px; border-radius: 999px; border: 1px solid var(--surface-border); background: var(--surface-1); color: var(--text-main); cursor: pointer; font-weight: 800; transition: transform 120ms ease, background 120ms ease, border-color 120ms ease; }
.btn-group button:hover { transform: translateY(-1px); background: var(--surface-2); border-color: var(--surface-border-strong); }
.btn-group button:active { transform: translateY(0px) scale(0.99); }
.btn-group button:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }
.math-tab.active { background: rgba(96, 165, 250, 0.22); border-color: rgba(96, 165, 250, 0.45); color: var(--nav-active-fg); }
.diff-easy.active { background: rgba(52, 211, 153, 0.22); border-color: rgba(52, 211, 153, 0.45); color: #d1fae5; }
.diff-med.active { background: rgba(251, 191, 36, 0.22); border-color: rgba(251, 191, 36, 0.45); color: #fef3c7; }
.diff-hard.active { background: rgba(251, 113, 133, 0.22); border-color: rgba(251, 113, 133, 0.45); color: #ffe4e6; }

.quiz-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.question-compact { background: var(--surface-1); padding: 16px; border-radius: 16px; display: flex; justify-content: space-between; align-items: center; border: 1px solid var(--surface-border); position: relative; }
.math-input-compact { width: 75px; height: 40px; border-radius: 8px; text-align: center; font-size: 18px; font-weight: 700; border: none; background: #fff; color: #000; }

.gk-options-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.gk-option { padding: 16px; background: var(--surface-1); border: 1px solid var(--surface-border); border-radius: 14px; color: var(--text-main); cursor: pointer; text-align: left; font-weight: 800; transition: transform 120ms ease, background 120ms ease, border-color 120ms ease; }
.gk-option:hover { transform: translateY(-1px); background: var(--surface-3); border-color: var(--surface-border-strong); }
.gk-option:active { transform: translateY(0px) scale(0.99); }
.gk-option:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }
.correct-flash { background: rgba(52, 211, 153, 0.90) !important; color: #052e1d !important; font-weight: 900; }
.wrong-flash { background: rgba(251, 113, 133, 0.90) !important; color: #3f0711 !important; font-weight: 900; }

.action-btn { padding: 12px 18px; border-radius: 14px; border: 1px solid var(--chip-action-border); font-weight: 900; cursor: pointer; transition: transform 120ms ease, filter 120ms ease; }
.action-btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.action-btn:active { transform: translateY(0px) scale(0.99); }
.primary { background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple)); color: #04121f; }
.secondary { background: linear-gradient(90deg, var(--accent-green), var(--accent-yellow)); color: #052e1d; }
.action-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* TOPBAR */
.loys-topbar { margin-bottom: 14px; }
.loys-topbar-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
.loys-chip { background: var(--surface-1); border: 1px solid var(--border); color: var(--text-main); padding: 8px 12px; border-radius: 999px; font-weight: 700; font-size: 12px; cursor: pointer; text-decoration: none; }
.loys-chip.muted { color: var(--text-muted); font-weight: 600; cursor: default; }
.loys-chip:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }
/* MODAL */
.loys-modal-overlay { position: fixed; inset: 0; background: rgba(2,6,23,0.75); display: none; align-items: center; justify-content: center; padding: 20px; z-index: 999; }
.loys-modal-overlay.open { display: flex; }
.loys-modal { width: min(520px, 100%); background: var(--bg-card); border: 1px solid var(--border); border-radius: 18px; padding: 18px; box-shadow: 0 20px 60px rgba(0,0,0,0.45); }
.loys-muted { color: var(--text-muted); font-size: 12px; margin-top: 6px; }
.loys-form { margin-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.loys-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.loys-label { display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: 12px; color: var(--text-main); }
.loys-input { height: 42px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-obsidian); color: var(--text-main); padding: 0 12px; font-weight: 700; }
.loys-input:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }
.loys-modal-actions { margin-top: 16px; display: flex; justify-content: flex-end; gap: 10px; }
.loys-inline-error { margin-right: auto; color: var(--text-muted); font-size: 11px; font-weight: 700; align-self: center; }

/* DASHBOARD */
.dashboard-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.dashboard-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.stat-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); color: var(--text-muted); font-weight: 700; }
.stat-row b { color: var(--text-main); }
.stat-block { margin-top: 8px; }
.badge-wrap { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.badge-pill { background: rgba(56, 189, 248, 0.12); border: 1px solid rgba(56, 189, 248, 0.25); color: var(--text-main); padding: 6px 10px; border-radius: 999px; font-size: 12px; font-weight: 800; text-transform: capitalize; }

.game-switcher { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.game-tab { padding: 8px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg-obsidian); color: var(--text-muted); font-weight: 700; cursor: pointer; font-size: 11px; }
@media (min-width: 1024px) {
    .game-tab { font-size: 12px; padding: 8px 14px; }
}
.game-tab.active { background: rgba(56, 189, 248, 0.18); color: var(--accent-blue); border-color: rgba(56, 189, 248, 0.35); }
.game-tab:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }
.game-panel { display: none; }
.game-panel.active { display: block; }

/* Puzzles page */
.puzzle-switcher { margin-bottom: 14px; }
.puzzle-stage { text-align: center; font-size: clamp(1.5rem, 5vw, 2.25rem); font-weight: 800; letter-spacing: 0.12em; margin: 18px 0; padding: 16px; border-radius: 16px; background: var(--surface-1); border: 1px solid var(--border); color: var(--text-main); }
.puzzle-stage--nums { letter-spacing: 0.06em; font-variant-numeric: tabular-nums; }
.puzzle-stage--count { letter-spacing: 0; line-height: 1.4; word-break: break-all; }
.puzzle-input-label { display: block; margin-top: 8px; margin-bottom: 6px; }
.puzzle-text-input { width: 100%; max-width: 280px; display: block; margin: 0 auto; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg-obsidian); color: var(--text-main); font-weight: 700; font-size: 16px; }
.puzzle-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.puzzle-feedback { text-align: center; min-height: 1.4em; margin-top: 12px; font-weight: 700; font-size: 14px; transition: color 0.15s ease; line-height: 1.45; }
.puzzle-feedback.ok { color: #4ade80; }
.puzzle-feedback.bad { color: #fb7185; }
/* Google link: don’t inherit parent red/green text color */
.puzzle-feedback .puzzle-feedback-link {
    display: block;
    margin-top: 12px;
    font-weight: 700;
    font-size: 15px;
    text-decoration: underline;
    text-underline-offset: 4px;
    cursor: pointer;
}
.puzzle-feedback.ok .puzzle-feedback-link {
    color: #e0f2fe !important;
}
.puzzle-feedback.ok .puzzle-feedback-link:hover { color: #ffffff !important; }
.puzzle-feedback.ok .puzzle-feedback-link:focus-visible {
    outline: 2px solid #e0f2fe;
    outline-offset: 3px;
    border-radius: 4px;
}
.puzzle-feedback.bad .puzzle-feedback-link {
    color: #7dd3fc !important;
}
.puzzle-feedback.bad .puzzle-feedback-link:hover { color: #bae6fd !important; }
.puzzle-feedback.bad .puzzle-feedback-link:focus-visible {
    outline: 2px solid #7dd3fc;
    outline-offset: 3px;
    border-radius: 4px;
}
.puzzle-feedback .puzzle-feedback-answer {
    color: #4ade80;
    font-weight: 800;
    text-shadow: 0 0 12px rgba(74, 222, 128, 0.35);
}
@keyframes puzzle-feedback-pop {
    0% { opacity: 0; transform: translateY(6px) scale(0.98); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}
.puzzle-feedback.puzzle-feedback-pop { animation: puzzle-feedback-pop 0.32s ease-out; }
.puzzle-text-input.puzzle-input-flash-ok {
    border-color: rgba(34, 197, 94, 0.85) !important;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.25);
}
.puzzle-text-input.puzzle-input-flash-bad {
    border-color: rgba(251, 113, 133, 0.9) !important;
    box-shadow: 0 0 0 3px rgba(251, 113, 133, 0.25);
}
.puzzle-odd-btn.puzzle-pick-ok:disabled,
.puzzle-opt-btn.puzzle-pick-ok:disabled {
    opacity: 1;
    background: rgba(34, 197, 94, 0.2) !important;
    border-color: rgba(34, 197, 94, 0.65) !important;
    box-shadow: inset 0 0 0 2px rgba(34, 197, 94, 0.5);
}
.puzzle-odd-btn.puzzle-pick-bad:disabled,
.puzzle-opt-btn.puzzle-pick-bad:disabled {
    opacity: 1;
    background: rgba(251, 113, 133, 0.15) !important;
    border-color: rgba(251, 113, 133, 0.55) !important;
    box-shadow: inset 0 0 0 2px rgba(251, 113, 133, 0.45);
}
.puzzle-odd-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; max-width: 280px; margin: 16px auto; }
@media (min-width: 480px) {
    .puzzle-odd-grid { grid-template-columns: repeat(4, 1fr); max-width: 420px; }
}
.puzzle-odd-btn { aspect-ratio: 1; border-radius: 16px; border: 2px solid var(--puzzle-odd-border); background: rgba(96, 165, 250, 0.12); font-size: clamp(2rem, 8vw, 3rem); cursor: pointer; transition: transform 100ms ease, background 100ms ease; touch-action: manipulation; }
.puzzle-odd-btn:hover:not(:disabled) { background: rgba(96, 165, 250, 0.22); transform: scale(1.03); }
.puzzle-odd-btn:disabled { opacity: 0.5; cursor: default; }
.puzzle-analogy-stem { text-align: center; font-size: 1.05rem; font-weight: 700; margin: 16px 0 12px; line-height: 1.45; color: var(--text-main); }
.puzzle-option-grid { display: flex; flex-direction: column; gap: 8px; max-width: 360px; margin: 0 auto; }
.puzzle-opt-btn { padding: 12px 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-1); color: var(--text-main); font-weight: 700; cursor: pointer; text-align: left; transition: background 100ms ease; touch-action: manipulation; }
.puzzle-opt-btn:hover:not(:disabled) { background: rgba(56, 189, 248, 0.15); }
.puzzle-opt-btn:disabled { opacity: 0.55; cursor: default; }

.ttt-grid { display: grid; grid-template-columns: repeat(3, 80px); gap: 10px; margin: 20px auto; width: fit-content; }
.cell { width: 80px; height: 80px; background: var(--bg-obsidian); border: 1px solid var(--border); border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 28px; cursor: pointer; }

/* Tic-Tac-Toe: centered outcome banner with color cues */
.ttt-status-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin: 12px 0 8px;
    padding: 0 8px;
    box-sizing: border-box;
}
.ttt-status {
    margin: 0;
    padding: 14px 22px;
    border-radius: 16px;
    font-size: clamp(1rem, 2.8vw, 1.2rem);
    font-weight: 800;
    text-align: center;
    line-height: 1.35;
    border: 2px solid transparent;
    max-width: min(100%, 420px);
    box-sizing: border-box;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.ttt-status--turn {
    background: rgba(96, 165, 250, 0.18);
    border-color: rgba(96, 165, 250, 0.45);
    color: var(--nav-active-fg);
}
.ttt-status--thinking {
    background: rgba(148, 163, 184, 0.12);
    border-color: rgba(148, 163, 184, 0.35);
    color: var(--text-muted);
}
.ttt-status--win {
    background: rgba(52, 211, 153, 0.22);
    border-color: rgba(52, 211, 153, 0.55);
    color: #d1fae5;
    box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.15);
}
.ttt-status--loss {
    background: rgba(251, 113, 133, 0.2);
    border-color: rgba(251, 113, 133, 0.5);
    color: #ffe4e6;
    box-shadow: 0 0 0 1px rgba(251, 113, 133, 0.12);
}
.ttt-status--draw {
    background: rgba(251, 191, 36, 0.2);
    border-color: rgba(251, 191, 36, 0.5);
    color: #fef3c7;
    box-shadow: 0 0 0 1px rgba(251, 191, 36, 0.12);
}

.game-status-box { width: 100%; text-align: center; }
.game-status-box h3 { margin-left: auto; margin-right: auto; }
.stone-count { margin-top: 10px; text-align: center; font-weight: 700; color: var(--text-main); }
.stone-track { margin: 12px auto; width: fit-content; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 420px; }
.stone-chip { width: 22px; height: 22px; border-radius: 999px; background: var(--accent-yellow); border: 1px solid rgba(0,0,0,0.2); box-shadow: inset 0 -2px 0 rgba(0,0,0,0.2); }
.stone-controls { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.stone-controls .action-btn { min-width: 92px; }

/* Memory Match */
.memory-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 320px; margin: 16px auto; }
@media (min-width: 480px) {
    .memory-grid { grid-template-columns: repeat(4, 1fr); max-width: 400px; }
}
.memory-card { aspect-ratio: 1; border-radius: 14px; border: 2px solid var(--memory-border); background: var(--memory-bg); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: clamp(1.5rem, 6vw, 2rem); font-weight: 800; transition: transform 120ms ease, background 120ms ease; user-select: none; }
.memory-card:hover:not(.memory-matched) { transform: scale(1.03); }
.memory-card.memory-flipped { background: rgba(96, 165, 250, 0.2); border-color: rgba(96, 165, 250, 0.5); }
.memory-card.memory-matched { background: rgba(52, 211, 153, 0.25); border-color: rgba(52, 211, 153, 0.5); cursor: default; opacity: 0.95; }
.memory-card.memory-back { color: transparent; }
.memory-card.memory-back::after { content: '★'; color: var(--accent-yellow); font-size: 1.75rem; }

/* Connect Four */
.c4-board { display: flex; gap: 6px; justify-content: center; margin: 16px auto; flex-wrap: nowrap; }
.c4-col { display: flex; flex-direction: column-reverse; gap: 5px; cursor: pointer; padding: 4px 2px; border-radius: 12px; transition: background 120ms ease; }
.c4-col:hover { background: var(--surface-1); }
.c4-slot { width: 38px; height: 38px; border-radius: 50%; background: var(--c4-slot-bg); border: 2px solid var(--surface-border); flex-shrink: 0; }
@media (min-width: 1024px) {
    .c4-slot { width: 44px; height: 44px; }
}
.c4-slot.c4-human { background: linear-gradient(145deg, #fbbf24, #f59e0b); border-color: rgba(251, 191, 36, 0.6); }
.c4-slot.c4-ai { background: linear-gradient(145deg, #fb7185, #e11d48); border-color: rgba(251, 113, 133, 0.5); }

/* Rock Paper Scissors */
.rps-scoreboard { display: flex; justify-content: center; align-items: center; gap: 10px; flex-wrap: wrap; margin: 12px 0 4px; font-weight: 700; color: var(--text-main); }
.rps-score-sep { color: var(--text-muted); font-weight: 600; }
.rps-reveal { text-align: center; min-height: 1.5em; margin: 8px 0 4px; font-size: 14px; }
.rps-choices { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.rps-btn { min-width: 108px; padding: 14px 16px; border-radius: 14px; border: 2px solid var(--surface-border-strong); background: rgba(96, 165, 250, 0.15); color: var(--text-main); font-weight: 800; font-size: 14px; cursor: pointer; transition: transform 100ms ease, background 100ms ease; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.rps-btn:hover:not(:disabled) { background: rgba(96, 165, 250, 0.28); transform: scale(1.02); }
.rps-btn:active:not(:disabled) { transform: scale(0.98); }
.rps-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.rps-btn:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }

/* Abacus */
.abacus-intro { margin-bottom: 12px; text-align: center; max-width: 560px; margin-left: auto; margin-right: auto; }
.abacus-mode-row { justify-content: center; flex-wrap: wrap; margin: 16px 0; }
.abacus-mode-btn--active {
    background: rgba(96, 165, 250, 0.22) !important;
    border-color: rgba(96, 165, 250, 0.45) !important;
    color: var(--nav-active-fg) !important;
}
.abacus-game-panel { margin: 16px 0; text-align: center; }
.abacus-target-banner {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 16px 24px;
    border-radius: 16px;
    background: rgba(52, 211, 153, 0.15);
    border: 2px solid rgba(52, 211, 153, 0.45);
    margin: 0 auto 8px;
    max-width: 100%;
    box-sizing: border-box;
}
.abacus-target-label { font-size: 12px; font-weight: 700; color: var(--text-muted); }
.abacus-target-value { font-size: clamp(1.75rem, 8vw, 2.5rem); font-weight: 800; color: #d1fae5; line-height: 1.1; }
.abacus-score-line { font-size: 13px; color: var(--text-muted); margin: 8px 0 0; }
.abacus-frame {
    background: linear-gradient(165deg, #4a3428 0%, #2d1f18 45%, #1a120e 100%);
    border-radius: 22px;
    padding: 18px 10px 14px;
    border: 3px solid rgba(92, 64, 51, 0.9);
    max-width: min(100%, 720px);
    margin: 20px auto;
    box-shadow: var(--shadow-soft), inset 0 1px 0 var(--inset-shine);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.abacus-rods {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: clamp(4px, 1.8vw, 16px);
    min-width: min-content;
    padding-bottom: 4px;
}
.abacus-rod { display: flex; flex-direction: column; align-items: center; flex: 0 0 auto; width: clamp(44px, 14vw, 60px); }
.abacus-heaven { height: 48px; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 2px; width: 100%; }
.abacus-beam {
    width: 100%;
    height: 9px;
    background: linear-gradient(180deg, #a16207, #713f12);
    border-radius: 3px;
    margin: 2px 0 6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45), inset 0 1px 0 var(--inset-shine-strong);
}
.abacus-earth {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding-top: 4px;
    min-height: 148px;
    width: 100%;
}
.abacus-bead {
    width: clamp(36px, 12vw, 46px);
    height: clamp(24px, 8vw, 30px);
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, 0.25);
    cursor: pointer;
    background: radial-gradient(ellipse 70% 60% at 35% 30%, #fecaca, #b91c1c 55%, #7f1d1d);
    box-shadow: inset 0 -3px 4px rgba(0, 0, 0, 0.35), 0 4px 6px rgba(0, 0, 0, 0.35);
    transition: transform 0.18s ease;
    padding: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.abacus-bead:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 3px; }
.abacus-heaven-bead { transform: translateY(-10px); }
.abacus-heaven-bead.abacus-bead--active { transform: translateY(12px); }
.abacus-earth-bead { transform: translateY(10px); }
.abacus-earth-bead.abacus-bead--active { transform: translateY(-12px); }
.abacus-place-label { font-size: 8px; font-weight: 800; color: var(--abacus-muted); text-transform: uppercase; letter-spacing: 0.02em; margin-top: 10px; line-height: 1.2; text-align: center; max-width: 100%; }
@media (min-width: 520px) {
    .abacus-place-label { font-size: 9px; letter-spacing: 0.03em; }
}
.abacus-rod-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 8px;
}
.abacus-step-btn {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    border: 1px solid var(--step-btn-border);
    background: var(--memory-bg);
    color: var(--text-main);
    font-weight: 800;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    touch-action: manipulation;
}
.abacus-step-btn:hover { background: var(--surface-2); }
.abacus-step-btn:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }
.abacus-digit-read { min-width: 22px; text-align: center; font-weight: 800; font-size: 15px; color: #fef3c7; }
.abacus-readout { text-align: center; font-size: 1.05rem; margin: 18px 0 8px; color: var(--text-main); }
.abacus-readout strong { color: var(--accent-yellow); font-size: 1.15em; }
.abacus-feedback { min-height: 1.5em; text-align: center; font-weight: 700; font-size: 14px; margin: 12px 0; padding: 0 8px; }
.abacus-feedback--ok { color: var(--accent-green); }
.abacus-feedback--bad { color: var(--accent-red); }
.abacus-actions { justify-content: center; flex-wrap: wrap; margin-top: 8px; }

/* Painting studio */
.paint-intro { margin-bottom: 16px; text-align: center; max-width: 520px; margin-left: auto; margin-right: auto; }
.paint-layout { display: flex; flex-direction: column; gap: 20px; align-items: center; margin: 20px 0; }
.paint-sample-block { text-align: center; }
.paint-sample-label, .paint-canvas-label, .paint-toolbar-label { font-size: 11px; font-weight: 800; color: var(--accent-purple); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
.paint-sample-block canvas { border-radius: 14px; border: 2px solid rgba(167, 139, 250, 0.45); box-shadow: var(--shadow-soft); display: block; margin: 0 auto; max-width: 100%; height: auto; }
.paint-workspace { width: 100%; max-width: min(100%, 520px); }
.paint-canvas-stack {
    position: relative;
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    aspect-ratio: 520 / 360;
    border-radius: 16px;
    overflow: hidden;
    border: 2px solid rgba(96, 165, 250, 0.4);
    box-shadow: var(--shadow-soft);
    background: #fefce8;
}
.paint-canvas-stack canvas {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: crosshair;
}
.paint-canvas-stack #paintOutline { z-index: 0; cursor: default; pointer-events: none; }
.paint-canvas-stack #paintLayer { z-index: 1; }
.paint-nav-row { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 8px; }
.paint-nav-buttons { flex-wrap: wrap; justify-content: center; }
.paint-picture-label { font-size: 14px; font-weight: 800; color: var(--text-main); text-align: center; margin: 0; max-width: 100%; }
.paint-swatch-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-bottom: 8px; }
.paint-swatch { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--paint-swatch-ring); cursor: pointer; padding: 0; transition: transform 120ms ease, box-shadow 120ms ease; }
.paint-swatch:hover { transform: scale(1.08); }
.paint-swatch:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 3px; }
.paint-swatch--active { box-shadow: 0 0 0 3px var(--accent-yellow), 0 4px 12px rgba(0,0,0,0.35); transform: scale(1.05); }
.paint-brush-btn--active { background: rgba(96, 165, 250, 0.22) !important; border-color: rgba(96, 165, 250, 0.45) !important; color: var(--nav-active-fg) !important; }
.paint-tool-active { background: rgba(251, 191, 36, 0.22) !important; border-color: rgba(251, 191, 36, 0.5) !important; color: #fef3c7 !important; }
.paint-actions { justify-content: center; flex-wrap: wrap; }

/* Educational video games hub */
.edu-vg-lead { max-width: 640px; margin-left: auto; margin-right: auto; text-align: center; }
.edu-vg-section-title { font-size: 1.2rem; margin-bottom: 8px; color: var(--text-main); }
.edu-games-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    margin-top: 18px;
}
.edu-game-card {
    background: var(--edu-card-bg);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.edu-game-card:hover {
    border-color: rgba(96, 165, 250, 0.32);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
    transform: translateY(-1px);
}
.edu-game-card h3 { font-size: 1.05rem; margin: 0; color: var(--text-main); }
.edu-game-card p { margin: 0; flex: 1; font-size: 13px; line-height: 1.5; color: var(--text-muted); }
.edu-game-card .action-btn { align-self: flex-start; margin-top: 4px; }
.edu-game-badge {
    display: inline-block;
    width: fit-content;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 5px 11px;
    border-radius: 999px;
    background: rgba(167, 139, 250, 0.18);
    color: #ede9fe;
    border: 1px solid rgba(167, 139, 250, 0.38);
}
.edu-game-badge--yt {
    background: rgba(239, 68, 68, 0.14);
    color: #fecaca;
    border-color: rgba(248, 113, 113, 0.38);
}
.edu-game-card--video { border-color: rgba(248, 113, 113, 0.1); }
.edu-vg-note { border-style: dashed; border-color: rgba(148, 163, 184, 0.35); }
.edu-vg-note a { color: var(--accent-blue); font-weight: 700; text-decoration: underline; text-underline-offset: 2px; }

/* Map explorer (Google Maps embed) */
.map-explore-section .section-header { margin-bottom: 8px; }
.map-explore-tabs { margin-bottom: 16px; }
.map-explore-panel { display: none; }
.map-explore-panel.active { display: block; }
.map-explore-lead { margin-bottom: 16px; line-height: 1.5; color: var(--text-muted); max-width: 640px; font-size: 14px; }
.map-explore-bar { display: flex; flex-direction: column; align-items: stretch; gap: 10px; margin-bottom: 4px; max-width: 480px; }
.map-explore-bar--directions { max-width: 520px; }
.map-explore-label { font-weight: 800; font-size: 12px; color: var(--text-main); }
.map-explore-input { max-width: 100% !important; margin: 0 !important; display: block; width: 100%; }
.map-autocomplete-wrap { position: relative; width: 100%; }
.map-autocomplete-dropdown {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    z-index: 80;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    max-height: 240px;
    overflow-y: auto;
    box-shadow: var(--shadow-soft);
    list-style: none;
    padding: 6px 0;
    margin: 0;
}
.map-autocomplete-dropdown li {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.35;
    color: var(--text-main);
}
.map-autocomplete-dropdown li:hover,
.map-autocomplete-dropdown li:focus { background: var(--surface-2); outline: none; }
.map-explore-hint { min-height: 1.35em; margin-top: 6px; font-size: 12px; }
.map-travel-times { margin-top: 4px; }
.map-travel-times-note { font-size: 12px; line-height: 1.5; max-width: 640px; margin: 0; }
.map-travel-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.map-travel-table th,
.map-travel-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.map-travel-table th { color: var(--text-muted); font-weight: 800; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.map-explore-below { display: none; flex-direction: column; gap: 10px; margin-top: 12px; }
.map-explore-below.active { display: flex; }
.map-dir-links-intro { font-size: 12px; margin: 0; max-width: 640px; line-height: 1.45; }
.map-dir-chips { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.map-explore-frame-wrap {
    margin-top: 14px;
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--surface-1);
    min-height: 260px;
    aspect-ratio: 16 / 10;
    max-width: 100%;
}
.map-explore-embed { width: 100%; height: 100%; min-height: 260px; border: 0; display: block; }
.map-explore-footnote { margin-top: 14px; font-size: 11px; line-height: 1.45; max-width: 560px; }
@media (min-width: 520px) {
    .map-explore-bar--place { flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
    .map-explore-bar--place .map-explore-label { flex: 1 1 100%; }
    .map-explore-bar--place .map-explore-input-wrap { flex: 1 1 200px; min-width: 0; }
    .map-explore-bar--place .action-btn { flex: 0 0 auto; }
}
@media (min-width: 560px) {
    .edu-games-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
    .edu-games-grid:not(.edu-games-grid--videos) { grid-template-columns: repeat(3, 1fr); }
    .edu-games-grid--videos { grid-template-columns: repeat(2, 1fr); }
}

/* Storybook */
.storybook-lead { margin-bottom: 18px; line-height: 1.55; color: var(--text-muted); max-width: 640px; font-size: 14px; }
.storybook-lead strong { color: var(--text-main); font-weight: 800; }
.storybook-library-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    margin-top: 8px;
}
.storybook-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    text-align: left;
    padding: 18px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: var(--edu-card-bg);
    cursor: pointer;
    font: inherit;
    color: var(--text-main);
    transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.storybook-card:hover {
    border-color: rgba(96, 165, 250, 0.35);
    transform: translateY(-1px);
    box-shadow: var(--shadow-soft);
}
.storybook-card:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 3px; }
.storybook-card-art { font-size: 2.5rem; line-height: 1; }
.storybook-card-title { font-size: 1.1rem; font-weight: 800; }
.storybook-card-blurb { font-size: 13px; color: var(--text-muted); line-height: 1.45; font-weight: 600; }
.storybook-reader-card .storybook-reader-top { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.storybook-reader-title { font-size: 1.25rem; font-weight: 800; margin: 0; flex: 1 1 auto; min-width: 0; }
.storybook-reader-art {
    font-size: clamp(3rem, 12vw, 4.5rem);
    line-height: 1;
    text-align: center;
    margin: 8px 0 20px;
    user-select: none;
}
.storybook-reader-text {
    font-size: clamp(1.05rem, 2.8vw, 1.2rem);
    line-height: 1.65;
    max-width: 38em;
    margin: 0 auto 16px;
    font-weight: 600;
    color: var(--text-main);
}
.storybook-reader-progress { text-align: center; font-size: 12px; font-weight: 700; margin-bottom: 12px; }
.storybook-dots { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 18px; }
.storybook-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    border: 1px solid var(--surface-border-strong);
    background: var(--surface-1);
    padding: 0;
    cursor: pointer;
    transition: transform 0.12s ease, background 0.12s ease;
}
.storybook-dot:hover { transform: scale(1.15); background: var(--surface-2); }
.storybook-dot--active { background: var(--accent-blue); border-color: rgba(96, 165, 250, 0.55); transform: scale(1.2); }
.storybook-dot:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }
.storybook-reader-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
@media (min-width: 520px) {
    .storybook-library-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 900px) {
    .storybook-library-grid { grid-template-columns: repeat(3, 1fr); }
}

.app-footer { background: var(--bg-deep); padding: 10px; text-align: center; font-size: 10px; color: var(--text-muted); }

@media (min-width: 1024px) {
    .app-shell { display: grid; grid-template-columns: 280px 240px 1fr; grid-template-rows: 1fr auto; height: 90vh; width: 95%; border-radius: 30px; }
    .sidebar-wrapper { display: contents; }
    .about-sidebar { grid-column: 1; grid-row: 1; border-right: 1px solid var(--border); flex-direction: column; flex-wrap: nowrap; align-items: flex-start; align-self: stretch; height: 100%; min-height: 0; padding: 40px; }
    .about-sidebar .brand-info { width: 100%; }
    .social-block { flex: 0 0 auto; width: 100%; margin-top: auto; padding-top: 16px; }
    .about-text { display: block; margin-top: 20px; font-size: 0.9rem; color: var(--text-muted); }
    .logo { width: 100px; height: 100px; }
    .nav-sidebar { grid-column: 2; border-right: 1px solid var(--border); padding: 36px 18px 40px; gap: 18px; }
    .menu-label {
        padding: 14px 20px;
        font-size: 10px;
        letter-spacing: 0.28em;
        max-width: 100%;
        border-radius: 18px;
    }
    .nav-links { flex-direction: column; overflow: visible; align-items: stretch; gap: 10px; }
    .nav-links .nav-btn { width: 100%; justify-content: flex-start; }
    .content { padding: 40px; }
    .section-header { flex-direction: row; justify-content: space-between; }
    .controls-row { flex-direction: row; justify-content: space-between; }
    .quiz-grid, .gk-options-grid { grid-template-columns: 1fr 1fr; }
    .app-footer { grid-column: 1 / -1; }
    .dashboard-grid { grid-template-columns: 1fr 1fr; }
    .paint-layout { flex-direction: row; align-items: flex-start; justify-content: center; gap: 32px; }
    .paint-sample-block { flex: 0 0 auto; }
    .paint-workspace { flex: 1 1 auto; max-width: 520px; }
}