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

/* Goal 38: Smooth cross-page transitions in browsers that support View Transitions
   (Chrome/Edge — covers most Chromebook users). Gracefully ignored elsewhere. */
@view-transition {
    navigation: auto;
}

/* Persistent UI elements morph smoothly across page loads instead of cross-fading */
.nav-bar { view-transition-name: nav-bar; }
.mascot-container { view-transition-name: mascot; }

/* Respect reduced-motion preference: skip transitions */
@media (prefers-reduced-motion: reduce) {
    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) {
        animation: none !important;
    }
}

/* Accessibility - visually hidden but screen reader accessible */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Skip link for keyboard navigation */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #1976D2;
    color: white;
    padding: 8px 16px;
    z-index: 10000;
    text-decoration: none;
    border-radius: 0 0 4px 0;
}

.skip-link:focus {
    top: 0;
}

/* Ensure focus is visible for all interactive elements */
:focus-visible {
    outline: 3px solid #1976D2;
    outline-offset: 2px;
}

:root {
    /* Goal 83: playful display font for titles/buttons/scores (Segoe stays for body) */
    --font-display: 'Fredoka', 'Segoe UI', Tahoma, sans-serif;
    /* Goal 83: WCAG AA accent tokens — deep in light theme, bright in dark */
    --accent-blue: #1976D2;
    --accent-orange: #EF6C00;
    --accent-green: #2E7D32;
    --accent-gold: #B8860B;
    /* Light theme (default) */
    --bg-primary: #FFF59D;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f8f9fa;
    --bg-accent: #fff9e6;
    --text-primary: #333333;
    --text-secondary: #555555;
    --text-tertiary: #545454;
    --border-color: #64B5F6;
    --shadow: rgba(0, 0, 0, 0.2);
    --shadow-light: rgba(0, 0, 0, 0.1);
    --card-bg: #ffffff;
    --input-bg: #ffffff;
    --progress-bg: #e0e0e0;
    --nav-bg: rgba(100, 181, 246, 0.9);
    --star-color: #ffffff;
    /* Instructions and hint box - light theme */
    --instructions-bg: #fff9e6;
    --instructions-text: #5d4e37;
    --hint-bg: #fff9e6;
    --hint-text: #5d4e37;
    --hint-border: #FF9800;
}

[data-theme="dark"] {
    /* Bright accent variants pass contrast on dark surfaces */
    --accent-blue: #64B5F6;
    --accent-orange: #FFB74D;
    --accent-green: #81C784;
    --accent-gold: #FFD700;
    /* Dark theme */
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-accent: #1f4068;
    --text-primary: #e8e8e8;
    --text-secondary: #cccccc;
    --text-tertiary: #b0b0b0;
    --border-color: #64B5F6;
    --shadow: rgba(0, 0, 0, 0.5);
    --shadow-light: rgba(0, 0, 0, 0.3);
    --card-bg: #16213e;
    --input-bg: #0f3460;
    --progress-bg: #2a2a3e;
    --nav-bg: rgba(15, 52, 96, 0.95);
    --star-color: #ffd700;
    /* Instructions and hint box - dark theme */
    --instructions-bg: #2a2a3e;
    --instructions-text: #f0e6d3;
    --hint-bg: #2a2a3e;
    --hint-text: #f0e6d3;
    --hint-border: #FFB74D;
}

/* ===== ERA-SPECIFIC THEMES ===== */
/* Each era has its own color palette for immersive experience */

/* Ancient Civilizations - Sandy gold, terracotta, papyrus */
[data-era="Ancient Civilizations"] {
    --bg-primary: #F5E6C8;
    --era-accent: #C4A35A;
    --era-secondary: #8B7355;
    --era-glow: rgba(196, 163, 90, 0.4);
}
[data-era="Ancient Civilizations"] .scenario-card {
    background: linear-gradient(135deg, #FFF8E7 0%, #F5E6C8 100%);
    border: 2px solid #C4A35A;
}
[data-era="Ancient Civilizations"] .scenario-title {
    color: #8B6914;
    border-bottom-color: #C4A35A;
}
[data-era="Ancient Civilizations"] .choice-btn {
    background: linear-gradient(135deg, #FFF8E7 0%, #EDE0C8 100%);
    border-color: #C4A35A;
}
[data-era="Ancient Civilizations"] .choice-btn:hover {
    background: linear-gradient(135deg, #C4A35A 0%, #8B6914 100%);
}

/* Medieval Period - Stone gray, burgundy, castle tones */
[data-era="Medieval Period"] {
    --bg-primary: #D4C4B0;
    --era-accent: #722F37;
    --era-secondary: #4A4A4A;
    --era-glow: rgba(114, 47, 55, 0.4);
}
[data-era="Medieval Period"] .scenario-card {
    background: linear-gradient(135deg, #E8DED3 0%, #D4C4B0 100%);
    border: 2px solid #722F37;
}
[data-era="Medieval Period"] .scenario-title {
    color: #722F37;
    border-bottom-color: #722F37;
}
[data-era="Medieval Period"] .choice-btn {
    background: linear-gradient(135deg, #E8DED3 0%, #D4C4B0 100%);
    border-color: #722F37;
}
[data-era="Medieval Period"] .choice-btn:hover {
    background: linear-gradient(135deg, #722F37 0%, #4A1C20 100%);
}

/* Prehistory - Earth tones, cave colors */
[data-era="Prehistory"] {
    --bg-primary: #C9B99A;
    --era-accent: #6B4423;
    --era-secondary: #8B7355;
    --era-glow: rgba(107, 68, 35, 0.4);
}
[data-era="Prehistory"] .scenario-card {
    background: linear-gradient(135deg, #E0D5C0 0%, #C9B99A 100%);
    border: 2px solid #6B4423;
}
[data-era="Prehistory"] .scenario-title {
    color: #6B4423;
    border-bottom-color: #8B7355;
}
[data-era="Prehistory"] .choice-btn {
    background: linear-gradient(135deg, #E0D5C0 0%, #C9B99A 100%);
    border-color: #6B4423;
}
[data-era="Prehistory"] .choice-btn:hover {
    background: linear-gradient(135deg, #6B4423 0%, #4A2F19 100%);
}

/* Renaissance - Rich purple, gold, ornate */
[data-era="Renaissance"] {
    --bg-primary: #E8E0F0;
    --era-accent: #6A0DAD;
    --era-secondary: #DAA520;
    --era-glow: rgba(106, 13, 173, 0.4);
}
[data-era="Renaissance"] .scenario-card {
    background: linear-gradient(135deg, #F5F0FA 0%, #E8E0F0 100%);
    border: 2px solid #6A0DAD;
}
[data-era="Renaissance"] .scenario-title {
    color: #6A0DAD;
    border-bottom-color: #DAA520;
}
[data-era="Renaissance"] .choice-btn {
    background: linear-gradient(135deg, #F5F0FA 0%, #E8E0F0 100%);
    border-color: #6A0DAD;
}
[data-era="Renaissance"] .choice-btn:hover {
    background: linear-gradient(135deg, #6A0DAD 0%, #DAA520 100%);
}

/* Age of Exploration - Ocean blue, compass gold */
[data-era="Age of Exploration"] {
    --bg-primary: #D6EAF8;
    --era-accent: #1E6091;
    --era-secondary: #D4AC0D;
    --era-glow: rgba(30, 96, 145, 0.4);
}
[data-era="Age of Exploration"] .scenario-card {
    background: linear-gradient(135deg, #EBF5FB 0%, #D6EAF8 100%);
    border: 2px solid #1E6091;
}
[data-era="Age of Exploration"] .scenario-title {
    color: #1E6091;
    border-bottom-color: #D4AC0D;
}
[data-era="Age of Exploration"] .choice-btn {
    background: linear-gradient(135deg, #EBF5FB 0%, #D6EAF8 100%);
    border-color: #1E6091;
}
[data-era="Age of Exploration"] .choice-btn:hover {
    background: linear-gradient(135deg, #1E6091 0%, #D4AC0D 100%);
}

/* Early Modern Period - Colonial browns, rich reds */
[data-era="Early Modern Period"] {
    --bg-primary: #E8DDD0;
    --era-accent: #8B4513;
    --era-secondary: #B22222;
    --era-glow: rgba(139, 69, 19, 0.4);
}
[data-era="Early Modern Period"] .scenario-card {
    background: linear-gradient(135deg, #F5EDE3 0%, #E8DDD0 100%);
    border: 2px solid #8B4513;
}
[data-era="Early Modern Period"] .scenario-title {
    color: #8B4513;
    border-bottom-color: #B22222;
}
[data-era="Early Modern Period"] .choice-btn {
    background: linear-gradient(135deg, #F5EDE3 0%, #E8DDD0 100%);
    border-color: #8B4513;
}
[data-era="Early Modern Period"] .choice-btn:hover {
    background: linear-gradient(135deg, #8B4513 0%, #B22222 100%);
}

/* Age of Revolutions - Patriotic red, blue, cream */
[data-era="Age of Revolutions"] {
    --bg-primary: #F8F4E8;
    --era-accent: #B22234;
    --era-secondary: #002868;
    --era-glow: rgba(178, 34, 52, 0.4);
}
[data-era="Age of Revolutions"] .scenario-card {
    background: linear-gradient(135deg, #FFFDF5 0%, #F8F4E8 100%);
    border: 2px solid #B22234;
}
[data-era="Age of Revolutions"] .scenario-title {
    color: #002868;
    border-bottom-color: #B22234;
}
[data-era="Age of Revolutions"] .choice-btn {
    background: linear-gradient(135deg, #FFFDF5 0%, #F8F4E8 100%);
    border-color: #002868;
}
[data-era="Age of Revolutions"] .choice-btn:hover {
    background: linear-gradient(135deg, #002868 0%, #B22234 100%);
}

/* Industrial Age - Steel gray, smoky, machinery */
[data-era="Industrial Age"] {
    --bg-primary: #D5D8DC;
    --era-accent: #566573;
    --era-secondary: #7B241C;
    --era-glow: rgba(86, 101, 115, 0.4);
}
[data-era="Industrial Age"] .scenario-card {
    background: linear-gradient(135deg, #EAECEE 0%, #D5D8DC 100%);
    border: 2px solid #566573;
}
[data-era="Industrial Age"] .scenario-title {
    color: #2C3E50;
    border-bottom-color: #566573;
}
[data-era="Industrial Age"] .choice-btn {
    background: linear-gradient(135deg, #EAECEE 0%, #D5D8DC 100%);
    border-color: #566573;
}
[data-era="Industrial Age"] .choice-btn:hover {
    background: linear-gradient(135deg, #566573 0%, #2C3E50 100%);
}

/* 19th Century America - Sepia, frontier rust */
[data-era="19th Century America"] {
    --bg-primary: #E8D4B8;
    --era-accent: #8B4726;
    --era-secondary: #A0522D;
    --era-glow: rgba(139, 71, 38, 0.4);
}
[data-era="19th Century America"] .scenario-card {
    background: linear-gradient(135deg, #F5EBD8 0%, #E8D4B8 100%);
    border: 2px solid #8B4726;
}
[data-era="19th Century America"] .scenario-title {
    color: #8B4726;
    border-bottom-color: #A0522D;
}
[data-era="19th Century America"] .choice-btn {
    background: linear-gradient(135deg, #F5EBD8 0%, #E8D4B8 100%);
    border-color: #8B4726;
}
[data-era="19th Century America"] .choice-btn:hover {
    background: linear-gradient(135deg, #8B4726 0%, #5D3019 100%);
}

/* 20th Century - Modern, mid-century colors */
[data-era="20th Century"] {
    --bg-primary: #E8F0F2;
    --era-accent: #2874A6;
    --era-secondary: #1ABC9C;
    --era-glow: rgba(40, 116, 166, 0.4);
}
[data-era="20th Century"] .scenario-card {
    background: linear-gradient(135deg, #F4F9FA 0%, #E8F0F2 100%);
    border: 2px solid #2874A6;
}
[data-era="20th Century"] .scenario-title {
    color: #2874A6;
    border-bottom-color: #1ABC9C;
}
[data-era="20th Century"] .choice-btn {
    background: linear-gradient(135deg, #F4F9FA 0%, #E8F0F2 100%);
    border-color: #2874A6;
}
[data-era="20th Century"] .choice-btn:hover {
    background: linear-gradient(135deg, #2874A6 0%, #1ABC9C 100%);
}

/* Pre-Columbian Americas - Jade green, clay red, maize (Goal 82: was unthemed) */
[data-era="Pre-Columbian Americas"] {
    --bg-primary: #EADEC9;
    --era-accent: #0E7C61;
    --era-secondary: #C0392B;
    --era-glow: rgba(14, 124, 97, 0.4);
}
[data-era="Pre-Columbian Americas"] .scenario-card {
    background: linear-gradient(135deg, #F4EBD9 0%, #EADEC9 100%);
    border: 2px solid #0E7C61;
}
[data-era="Pre-Columbian Americas"] .scenario-title {
    color: #0E7C61;
    border-bottom-color: #C0392B;
}
[data-era="Pre-Columbian Americas"] .choice-btn {
    background: linear-gradient(135deg, #F4EBD9 0%, #EADEC9 100%);
    border-color: #0E7C61;
}
[data-era="Pre-Columbian Americas"] .choice-btn:hover {
    background: linear-gradient(135deg, #0E7C61 0%, #C0392B 100%);
}

/* ===== Goal 82: DARK-MODE ERA VARIANTS =====
   Each era keeps its accent hue; card surfaces go to a dark tint of the same
   family so dark theme + era theming no longer produces a half-lit card. */
[data-theme="dark"] [data-era="Ancient Civilizations"] { --era-dark-1: #2e2718; --era-dark-2: #221c10; --era-title-dark: #E8C97D; }
[data-theme="dark"] [data-era="Medieval Period"]       { --era-dark-1: #2b1f21; --era-dark-2: #1f1517; --era-title-dark: #D89AA2; }
[data-theme="dark"] [data-era="Prehistory"]            { --era-dark-1: #2a2318; --era-dark-2: #1e1910; --era-title-dark: #D2B48C; }
[data-theme="dark"] [data-era="Renaissance"]           { --era-dark-1: #261d31; --era-dark-2: #1a1322; --era-title-dark: #CBA6E8; }
[data-theme="dark"] [data-era="Age of Exploration"]    { --era-dark-1: #16242f; --era-dark-2: #0f1a22; --era-title-dark: #85C1E9; }
[data-theme="dark"] [data-era="Early Modern Period"]   { --era-dark-1: #2b2018; --era-dark-2: #1f1610; --era-title-dark: #DEB887; }
[data-theme="dark"] [data-era="Age of Revolutions"]    { --era-dark-1: #26202a; --era-dark-2: #191521; --era-title-dark: #9FB6E8; }
[data-theme="dark"] [data-era="Industrial Age"]        { --era-dark-1: #23282d; --era-dark-2: #181c20; --era-title-dark: #AEB6BF; }
[data-theme="dark"] [data-era="19th Century America"]  { --era-dark-1: #2b2318; --era-dark-2: #1f1911; --era-title-dark: #D9B98C; }
[data-theme="dark"] [data-era="20th Century"]          { --era-dark-1: #17262e; --era-dark-2: #101b21; --era-title-dark: #7EC8E3; }
[data-theme="dark"] [data-era="Pre-Columbian Americas"] { --era-dark-1: #17281f; --era-dark-2: #101c16; --era-title-dark: #7DCEA0; }

[data-theme="dark"] [data-era] .scenario-card {
    background: linear-gradient(135deg, var(--era-dark-1, #1d2433) 0%, var(--era-dark-2, #141a26) 100%);
    border-color: var(--era-accent, #64B5F6);
}
[data-theme="dark"] [data-era] .scenario-title {
    color: var(--era-title-dark, #e8e8e8);
    border-bottom-color: var(--era-accent, #64B5F6);
}
[data-theme="dark"] [data-era] .choice-btn {
    background: linear-gradient(135deg, var(--era-dark-1, #232b3d) 0%, var(--era-dark-2, #1a2130) 100%);
    border-color: var(--era-accent, #64B5F6);
    color: var(--text-primary);
}
[data-theme="dark"] [data-era] .choice-btn:hover {
    background: linear-gradient(135deg, var(--era-accent, #64B5F6) 0%, var(--era-dark-2, #1a2130) 140%);
}

/* Goal 82: T/F buttons join the era theme instead of a bare gray fieldset */
[data-era] .tf-choices {
    border: none;
    padding: 0;
}
[data-era] .tf-btn {
    border: 2px solid var(--era-accent, #64B5F6);
}
[data-era] .tf-btn:hover {
    box-shadow: 0 4px 14px var(--era-glow, rgba(100, 181, 246, 0.4));
}

/* Goal 82: era continuity on the answer/feedback page */
[data-era] .result-card {
    border-top: 6px solid var(--era-accent, #64B5F6);
}
[data-era] .fact-box {
    border-left: 4px solid var(--era-accent, #64B5F6);
}

/* Era badge styling */
.era-badge {
    display: inline-block;
    font-size: 0.5em;
    background: var(--era-accent, #64B5F6);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    margin-left: 5px;
    font-weight: normal;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 8px var(--era-glow, rgba(100, 181, 246, 0.4));
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    min-height: 100vh;
    padding: 20px;
    color: var(--text-primary);
    overflow-x: hidden;
    position: relative;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    position: relative;
    z-index: 10;
}

/* ===== BACKGROUND ANIMATIONS ===== */
.stars-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.star {
    position: absolute;
    width: 2px;
    height: 2px;
    background: var(--star-color);
    border-radius: 50%;
    animation: twinkle 3s infinite;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

.shooting-star {
    position: absolute;
    width: 2px;
    height: 2px;
    background: var(--star-color);
    border-radius: 50%;
    box-shadow: 0 0 4px var(--star-color);
    animation: shoot 2s linear;
}

@keyframes shoot {
    from {
        transform: translate(0, 0);
        opacity: 1;
    }
    to {
        transform: translate(-300px, 300px);
        opacity: 0;
    }
}

.floating-emojis {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.floating-emoji {
    position: absolute;
    font-size: 2em;
    opacity: 0.3;
    animation: float-up 6s linear;
}

@keyframes float-up {
    from {
        transform: translateY(100vh) rotate(0deg);
        opacity: 0.3;
    }
    to {
        transform: translateY(-100px) rotate(360deg);
        opacity: 0;
    }
}

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

/* Goal 67: themed emoji shards. Animation is driven by Web Animations API
   inside animations.js — this rule just sets position + sizing. */
.confetti-shard {
    position: absolute;
    top: -8vh;
    user-select: none;
    will-change: transform, opacity;
    line-height: 1;
    pointer-events: none;
}

/* ===== INTERACTIVE ANIMATIONS ===== */
@keyframes wobble {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-2deg); }
    75% { transform: rotate(2deg); }
}

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

@keyframes glow {
    0%, 100% { text-shadow: 0 0 10px rgba(100, 181, 246, 0.5); }
    50% { text-shadow: 0 0 20px rgba(100, 181, 246, 1), 0 0 30px rgba(255, 152, 0, 0.8); }
}

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

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

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

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

.bounce {
    animation: bounce 1s ease-in-out;
}

@keyframes wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-5deg); }
    75% { transform: rotate(5deg); }
}

.wiggle {
    display: inline-block;
    animation: wiggle 0.5s ease-in-out;
}

@keyframes pop-in {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.pop-in {
    animation: pop-in 0.5s ease-out;
}

@keyframes fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.fade-in {
    animation: fade-in 0.8s ease-in;
}

@keyframes slide-up {
    from {
        transform: translateY(30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.slide-up {
    animation: slide-up 0.6s ease-out;
}

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

.slide-in {
    animation: slide-in 0.5s ease-out forwards;
    opacity: 0;
}

@keyframes glow-pulse {
    0%, 100% {
        box-shadow: 0 0 20px rgba(100, 181, 246, 0.3);
    }
    50% {
        box-shadow: 0 0 40px rgba(100, 181, 246, 0.8), 0 0 60px rgba(255, 152, 0, 0.6);
    }
}

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

@keyframes sparkle {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.3); }
}

.sparkle {
    animation: sparkle 1.5s ease-in-out infinite;
}

/* Hover effects */
.pulse-on-hover {
    transition: all 0.3s ease;
}

.pulse-on-hover:hover {
    animation: pulse 0.5s ease-in-out infinite;
}

.shake-on-hover:hover {
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Ripple effect */
.ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.6);
    transform: scale(0);
    animation: ripple-animation 0.6s ease-out;
    pointer-events: none;
}

@keyframes ripple-animation {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* ===== WELCOME SCREEN ===== */
.welcome-screen {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 20px 60px var(--shadow);
    animation: slideIn 0.6s ease-out;
}

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

.game-title {
    text-align: center;
    font-size: 3em;
    color: #64B5F6;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

.subtitle {
    text-align: center;
    color: #FF9800;
    font-size: 1.5em;
    margin-bottom: 30px;
}

.start-form {
    text-align: center;
    margin: 30px 0;
}

.start-form label {
    display: block;
    font-size: 1.2em;
    margin-bottom: 15px;
    color: var(--text-secondary);
    font-weight: bold;
}

/* Goal 68: screen-flash overlay (radial vignette, WAAPI-animated) */
#hq-screen-flash {
    --flash-color: transparent;
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(ellipse at center, transparent 50%, var(--flash-color) 100%);
    opacity: 0;
    z-index: 9999;
    /* Don't let the flash trigger reflow during animation */
    will-change: opacity;
}
@media (prefers-reduced-motion: reduce) {
    #hq-screen-flash { display: none; }
}

/* Goal 67: choice-tile morph into result card via View Transitions */
::view-transition-old(chosen-choice),
::view-transition-new(chosen-choice) {
    animation-duration: 0.45s;
    animation-timing-function: cubic-bezier(.2, .8, .2, 1);
}

/* Goal 67: animated number ticker (rolls up from --ticker-from to --ticker-to). */
@property --ticker-val {
    syntax: '<integer>';
    initial-value: 0;
    inherits: false;
}
.num-ticker {
    --ticker-val: var(--ticker-from, 0);
    counter-reset: ticker var(--ticker-val);
    animation: num-ticker-roll 1.1s 0.1s cubic-bezier(.2, .8, .2, 1) forwards;
    font-variant-numeric: tabular-nums;
}
.num-ticker::after {
    content: counter(ticker);
}
@keyframes num-ticker-roll {
    to { --ticker-val: var(--ticker-to, 0); }
}
@media (prefers-reduced-motion: reduce) {
    .num-ticker {
        animation: none;
        --ticker-val: var(--ticker-to, 0);
    }
}

.btn-start {
    background: linear-gradient(135deg, #64B5F6 0%, #FF9800 100%);
    color: white;
    border: none;
    padding: 18px 40px;
    font-size: 1.3em;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 5px 20px rgba(100, 181, 246, 0.4);
    font-weight: bold;
    position: relative;
    overflow: hidden;
}

.btn-start:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 30px rgba(100, 181, 246, 0.6);
    background: linear-gradient(135deg, #5aa8e8 0%, #e68900 100%);
}

.btn-start:focus {
    outline: none;
    box-shadow: 0 0 0 4px rgba(100, 181, 246, 0.5), 0 8px 30px rgba(100, 181, 246, 0.6);
}

.btn-start:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 2px 10px rgba(100, 181, 246, 0.4);
}

/* ===== GAME HEADER ===== */
.game-header {
    background: var(--card-bg);
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 5px 20px var(--shadow);
}

.player-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
    font-size: 1.2em;
    font-weight: bold;
}

.player-name {
    color: #64B5F6;
}

.score {
    color: #FF9800;
}

.progress-bar {
    background: var(--progress-bg);
    border-radius: 10px;
    height: 30px;
    position: relative;
    overflow: hidden;
}

.progress-fill {
    background: linear-gradient(90deg, #64B5F6 0%, #FF9800 100%);
    height: 100%;
    transition: width 0.5s ease;
    border-radius: 10px;
}

.progress-text {
    position: absolute;
    width: 100%;
    text-align: center;
    line-height: 30px;
    font-weight: bold;
    color: var(--text-primary);
    z-index: 1;
}

/* ===== SCENARIO CARD ===== */
.scenario-card {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 10px 40px var(--shadow);
    animation: fadeIn 0.5s ease-in;
    position: relative;
}

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

.scenario-icon {
    font-size: 5em;
    text-align: center;
    margin-bottom: 20px;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.2));
}

.scenario-title {
    color: #64B5F6;
    font-size: 2em;
    margin-bottom: 20px;
    text-align: center;
    border-bottom: 3px solid #FF9800;
    padding-bottom: 15px;
}

.scenario-question {
    background: var(--bg-tertiary);
    padding: 25px;
    border-radius: 15px;
    margin-bottom: 30px;
    font-size: 1.2em;
    line-height: 1.8;
    border-left: 5px solid var(--border-color);
}

.choices {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin-top: 10px;
    border: none;
    padding: 0;
}

.choice-btn {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border: 3px solid #64B5F6;
    border-radius: 15px;
    padding: 20px;
    font-size: 1.1em;
    cursor: pointer;
    transition: all 0.3s;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 15px;
    position: relative;
    overflow: hidden;
}

.choice-btn:hover {
    background: linear-gradient(135deg, #64B5F6 0%, #FF9800 100%);
    color: white;
    transform: translateX(10px) scale(1.02);
    box-shadow: 0 5px 20px rgba(100, 181, 246, 0.4);
}

.choice-btn:active {
    transform: translateX(10px) scale(0.98);
}

.choice-btn:focus {
    outline: none;
    box-shadow: 0 0 0 4px rgba(100, 181, 246, 0.5), 0 5px 20px rgba(100, 181, 246, 0.4);
}

.choice-btn:focus .choice-letter {
    background: #FF9800;
}

.choice-letter {
    background: #64B5F6;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2em;
    flex-shrink: 0;
    transition: all 0.3s;
}

.choice-btn:hover .choice-letter {
    background: white;
    color: #64B5F6;
    transform: rotate(360deg);
}

/* Dark mode choice buttons */
[data-theme="dark"] .choice-btn {
    background: linear-gradient(135deg, #2a3a4a 0%, #1a2a3a 100%);
    color: var(--text-primary);
    border-color: #64B5F6;
}

[data-theme="dark"] .choice-btn:hover {
    background: linear-gradient(135deg, #64B5F6 0%, #FF9800 100%);
    color: white;
}

.hint-box {
    background: var(--hint-bg);
    padding: 20px;
    border-radius: 15px;
    margin-top: 20px;
    text-align: center;
    font-size: 1.1em;
    border: 2px dashed var(--hint-border);
    transition: all 0.3s;
    color: var(--hint-text);
}

.hint-box:hover {
    transform: scale(1.02);
    box-shadow: 0 5px 15px rgba(255, 152, 0, 0.3);
}

/* ===== RESULT CARD ===== */
.result-card {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 10px 40px var(--shadow);
    animation: bounceIn 0.6s ease-out;
}

@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.result-header {
    text-align: center;
    margin-bottom: 25px;
}

.result-excellent {
    color: #4CAF50;
    font-size: 2.5em;
}

.result-good {
    color: #64B5F6;
    font-size: 2.5em;
}

.result-okay {
    color: #FF9800;
    font-size: 2.5em;
}

.result-incorrect {
    color: #e74c3c;
    font-size: 2.5em;
}

.outcome-box {
    background: var(--bg-tertiary);
    padding: 25px;
    border-radius: 15px;
    margin-bottom: 20px;
    font-size: 1.2em;
    line-height: 1.8;
    border-left: 5px solid var(--border-color);
}

.points-earned {
    text-align: center;
    margin: 20px 0;
}

.points-badge {
    display: inline-block;
    background: linear-gradient(135deg, #FF9800 0%, #e74c3c 100%);
    color: white;
    padding: 15px 30px;
    border-radius: 50px;
    font-size: 1.5em;
    font-weight: bold;
    box-shadow: 0 5px 20px rgba(255, 152, 0, 0.4);
}

.fact-box {
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
    padding: 25px;
    border-radius: 15px;
    margin: 20px 0;
    border-left: 5px solid #4CAF50;
}

.fact-box h3 {
    color: #4CAF50;
    margin-bottom: 15px;
    font-size: 1.3em;
}

.fact-box p {
    color: #2d5a30;
    font-size: 1.1em;
    line-height: 1.8;
}

/* Dark mode fact box */
[data-theme="dark"] .fact-box {
    background: linear-gradient(135deg, #1a3d1a 0%, #2d5a2d 100%);
    border-left-color: #66bb6a;
}

[data-theme="dark"] .fact-box h3 {
    color: #81c784;
}

[data-theme="dark"] .fact-box p {
    color: #e0e0e0;
}

[data-theme="dark"] .fact-box .teacher-note {
    border-top-color: rgba(255, 255, 255, 0.2);
    color: #c0c0c0;
}

/* Context note inside fact box */
.fact-box .fact-context {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px dashed rgba(0, 100, 0, 0.3);
    font-size: 0.9em;
    font-style: italic;
    background: transparent;
    padding-left: 0;
    padding-right: 0;
    padding-bottom: 0;
    border-left: none;
    border-radius: 0;
}

[data-theme="dark"] .fact-box .fact-context {
    border-top-color: rgba(255, 255, 255, 0.2);
}

.btn-continue {
    display: block;
    background: linear-gradient(135deg, #64B5F6 0%, #FF9800 100%);
    color: white;
    text-decoration: none;
    padding: 18px 40px;
    border-radius: 50px;
    text-align: center;
    font-size: 1.3em;
    font-weight: bold;
    margin: 30px auto 0;
    max-width: 400px;
    transition: all 0.3s ease;
    box-shadow: 0 5px 20px rgba(100, 181, 246, 0.4);
    position: relative;
    overflow: hidden;
}

.btn-continue:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 30px rgba(100, 181, 246, 0.6);
    background: linear-gradient(135deg, #5aa8e8 0%, #e68900 100%);
}

.btn-continue:focus {
    outline: none;
    box-shadow: 0 0 0 4px rgba(100, 181, 246, 0.5), 0 8px 30px rgba(100, 181, 246, 0.6);
}

.btn-continue:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 2px 10px rgba(100, 181, 246, 0.4);
}

.answer-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-top: 30px;
}

.answer-actions .btn-continue {
    margin: 0;
}

.btn-minigame-optional {
    display: inline-block;
    background: transparent;
    color: var(--text-secondary, #555);
    text-decoration: none;
    padding: 10px 24px;
    border-radius: 50px;
    text-align: center;
    font-size: 0.95em;
    font-weight: 600;
    border: 2px solid rgba(100, 181, 246, 0.4);
    transition: all 0.25s ease;
}

.btn-minigame-optional:hover {
    background: rgba(100, 181, 246, 0.1);
    border-color: rgba(100, 181, 246, 0.7);
    color: #1976D2;
    transform: translateY(-1px);
}

.btn-minigame-optional:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(100, 181, 246, 0.4);
}

/* ===== RESULTS SCREEN ===== */
.results-screen {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 20px 60px var(--shadow);
    animation: slideIn 0.6s ease-out;
}

.results-title {
    text-align: center;
    font-size: 2.5em;
    color: #64B5F6;
    margin-bottom: 30px;
}

.final-score-box {
    text-align: center;
    background: linear-gradient(135deg, #64B5F6 0%, #FF9800 100%);
    color: white;
    padding: 40px;
    border-radius: 20px;
    margin-bottom: 30px;
}

.rank-title {
    font-size: 3em;
    margin: 20px 0;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.rank-message {
    font-size: 1.3em;
    margin-top: 10px;
}

.score-breakdown {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

.score-item {
    background: var(--bg-tertiary);
    padding: 25px;
    border-radius: 15px;
    text-align: center;
    border: 3px solid var(--border-color);
    transition: all 0.3s;
}

.score-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(100, 181, 246, 0.3);
}

.score-label {
    display: block;
    font-size: 1.1em;
    color: var(--text-tertiary);
    margin-bottom: 10px;
}

.score-value {
    display: block;
    font-size: 2em;
    font-weight: bold;
    color: #64B5F6;
}

.facts-learned {
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
    padding: 30px;
    border-radius: 15px;
    margin-bottom: 30px;
}

.facts-learned h3 {
    color: #4CAF50;
    margin-bottom: 20px;
    font-size: 1.5em;
}

.facts-list {
    list-style: none;
    padding-left: 0;
}

.facts-list li {
    background: var(--bg-secondary);
    padding: 15px;
    margin-bottom: 10px;
    border-radius: 10px;
    border-left: 4px solid #4CAF50;
    font-size: 1.05em;
    line-height: 1.6;
    transition: all 0.3s;
    color: var(--text-primary);
}

.facts-list li:hover {
    transform: translateX(10px);
    box-shadow: 0 3px 10px rgba(76, 175, 80, 0.2);
}

/* Dark mode facts learned */
[data-theme="dark"] .facts-learned {
    background: linear-gradient(135deg, #1a3d1a 0%, #2d5a2d 100%);
}

[data-theme="dark"] .facts-learned h3 {
    color: #81c784;
}

[data-theme="dark"] .facts-list li {
    border-left-color: #66bb6a;
}

.achievements {
    background: #fff9e6;
    padding: 30px;
    border-radius: 15px;
    margin-bottom: 30px;
}

.achievements h3 {
    color: #FF9800;
    margin-bottom: 20px;
    font-size: 1.5em;
}

/* Dark mode achievements */
[data-theme="dark"] .achievements {
    background: linear-gradient(135deg, #3d2e1a 0%, #5a4a2d 100%);
}

[data-theme="dark"] .achievements h3 {
    color: #FFB74D;
}

.achievement-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
}

.badge {
    background: linear-gradient(135deg, #64B5F6 0%, #FF9800 100%);
    color: white;
    padding: 12px 20px;
    border-radius: 25px;
    font-weight: bold;
    box-shadow: 0 3px 10px rgba(0,0,0,0.2);
    transition: all 0.3s;
    cursor: default;
}

.badge:hover {
    transform: translateY(-5px) rotate(5deg);
    box-shadow: 0 8px 20px rgba(0,0,0,0.3);
}

.badge.gold {
    background: linear-gradient(135deg, #ffd700 0%, #FF9800 100%);
}

.badge.silver {
    background: linear-gradient(135deg, #c0c0c0 0%, #95a5a6 100%);
}

.badge.bronze {
    background: linear-gradient(135deg, #cd7f32 0%, #a0522d 100%);
}

.action-buttons {
    text-align: center;
    margin: 30px 0;
}

.btn-play-again {
    display: inline-block;
    background: linear-gradient(135deg, #4CAF50 0%, #229954 100%);
    color: white;
    text-decoration: none;
    padding: 18px 40px;
    border-radius: 50px;
    font-size: 1.3em;
    font-weight: bold;
    transition: all 0.3s;
    box-shadow: 0 5px 20px rgba(76, 175, 80, 0.4);
    position: relative;
    overflow: hidden;
}

.btn-play-again:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 30px rgba(76, 175, 80, 0.6);
}

.teacher-note {
    background: var(--bg-accent);
    padding: 20px;
    border-radius: 10px;
    border-left: 4px solid #3498db;
    font-style: italic;
    color: var(--text-secondary);
    margin-top: 30px;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .container {
        padding: 0 10px;
    }

    .game-title {
        font-size: 1.8em;
        word-wrap: break-word;
    }

    .subtitle {
        font-size: 1.1em;
    }

    .scenario-card,
    .result-card,
    .welcome-screen,
    .results-screen {
        padding: 20px 15px;
        border-radius: 15px;
    }

    .scenario-title {
        font-size: 1.4em;
        word-wrap: break-word;
    }

    .scenario-question {
        font-size: 1em;
        padding: 15px;
    }

    .choice-btn {
        font-size: 0.95em;
        padding: 15px 12px;
    }

    .choice-letter {
        width: 32px;
        height: 32px;
        font-size: 1em;
        flex-shrink: 0;
    }

    .choice-text {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .score-breakdown {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .rank-title {
        font-size: 1.8em;
    }

    .scenario-icon {
        font-size: 3em;
    }

    .btn-start,
    .btn-continue,
    .btn-play-again {
        padding: 15px 30px;
        font-size: 1.1em;
        width: 100%;
        max-width: 100%;
    }


    .fact-box {
        padding: 15px;
    }

    .fact-box h3 {
        font-size: 1.1em;
    }

    .fact-box p {
        font-size: 1em;
    }

    .points-badge {
        font-size: 1.2em;
        padding: 12px 24px;
    }

    .player-info {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }

    .final-score-box {
        padding: 25px 15px;
    }

    .facts-learned,
    .achievements {
        padding: 20px 15px;
    }

    .achievement-badges {
        gap: 10px;
    }

    .badge {
        padding: 10px 15px;
        font-size: 0.9em;
    }

    .facts-list li {
        padding: 12px;
        font-size: 0.95em;
    }
}

/* ===== MICRO-INTERACTIONS ===== */
/* Button press feedback */
.btn-start:active,
.btn-continue:active,
.btn-play-again:active {
    transform: scale(0.95) !important;
    transition: transform 0.1s;
}

.choice-btn:active {
    transform: scale(0.97) !important;
    transition: transform 0.1s;
}

/* Card entrance animation */
.score-item {
    animation: slideUp 0.4s ease-out backwards;
}
.score-item:nth-child(1) { animation-delay: 0.1s; }
.score-item:nth-child(2) { animation-delay: 0.2s; }
.score-item:nth-child(3) { animation-delay: 0.3s; }

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

/* Progress bar smooth fill animation */
.progress-fill {
    animation: fillProgress 0.8s ease-out;
}

@keyframes fillProgress {
    from { width: 0%; }
}

/* Animated score counter target */
.score-value[data-animate] {
    transition: all 0.3s;
}

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

    .star, .shooting-star, .floating-emoji, .confetti-shard {
        display: none !important;
    }

    .choice-btn:hover {
        transform: none;
    }

    .btn-start:hover,
    .btn-continue:hover,
    .btn-play-again:hover {
        transform: none;
    }

    .badge:hover {
        transform: none;
    }

    .score-item:hover {
        transform: none;
    }

    .facts-list li:hover {
        transform: none;
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    .game-title {
        font-size: 1.5em;
    }

    .scenario-title {
        font-size: 1.2em;
    }

    .choice-btn {
        flex-direction: column;
        text-align: center;
        gap: 10px;
    }

    .choice-letter {
        margin: 0 auto;
    }

    .rank-title {
        font-size: 1.5em;
    }
}

/* ===== Goal 83: BRAND & TYPOGRAPHY ===== */
/* One name everywhere: the text wordmark replaces the old "Time Twisters Trivia"
   PNG (which had a baked-in white rectangle). */
.wordmark {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 22px;
    color: #ffffff;
    letter-spacing: 0.5px;
    white-space: nowrap;
}
.wordmark-accent { color: #FFD54F; }
.wordmark-hero {
    font-size: 3.2rem;
    color: var(--accent-blue);
    margin: 10px 0 4px;
    text-shadow: 2px 2px 0 var(--shadow-light);
}
.wordmark-hero .wordmark-accent { color: var(--accent-orange); }

/* Display font on the moments that should feel like a game */
h1, h2, h3,
.btn-start, .btn-continue, .btn-play-again, .btn-minigame-optional,
.rank-title, .results-title, .score, .points-badge, .grade-btn,
.scenario-title, .choice-letter, .continue-btn, .era-badge {
    font-family: var(--font-display);
}

/* ===== Goal 76: FLASH MESSAGES ===== */
.flash-stack {
    max-width: 900px;
    margin: 0 auto 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
    z-index: 50;
}
.flash-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 12px;
    background: var(--card-bg);
    color: var(--text-primary);
    border: 2px solid var(--accent-blue);
    box-shadow: 0 4px 12px var(--shadow-light);
    font-weight: 600;
}
.flash-banner.flash-error { border-color: #C62828; }
.flash-banner.flash-success { border-color: var(--accent-green); }
.flash-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: inherit;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 6px;
}
.flash-close:hover { background: var(--shadow-light); }

/* ===== Goal 76: FRIENDLY ERROR PAGES ===== */
.error-screen {
    text-align: center;
    background: var(--card-bg);
    border-radius: 20px;
    padding: 60px 30px;
    margin-top: 40px;
    box-shadow: 0 8px 30px var(--shadow);
}
.error-emoji { font-size: 64px; margin-bottom: 10px; }
.error-code {
    font-family: var(--font-display);
    font-size: 72px;
    color: var(--accent-blue);
    line-height: 1;
}
.error-title { color: var(--text-primary); margin: 10px 0; }
.error-message { color: var(--text-secondary); margin-bottom: 25px; }
.error-screen .btn-start { display: inline-block; text-decoration: none; }
