:root {
    /* --- Palette --- */
    /* Note: These are defaults. data.json config overrides them at runtime. */
    --c-yellow: #FFD200;
    --c-yellow-dark: #cca800;
    
    --c-blue: #0057B8;
    --c-blue-light: #3385D6; 
    --c-blue-dark: #003E85; 
    
    --c-green: #007A33;
    --c-green-dark: #004d20;
    
    --c-red: #E12D39; 
    --c-red-dark: #a81c25;

    /* --- Confetti Extras --- */
    --c-purple: #8E44AD;
    --c-pink: #E91E63;
    --c-orange: #F39C12;
    
    /* --- Cool Grey System --- */
    --c-grey-50:  #F0F4F8; /* Surface / Hover */
    --c-grey-100: #D9E2EC; /* Subtle Border / Card Shadow */
    --c-grey-300: #BCCCDC; /* Disabled Border / Strong Stroke */
    --c-grey-400: #9FB3C8; /* Disabled Text */
    --c-grey-600: #627D98; /* Muted Text */
    --c-grey-900: #102A43; /* Main Text */

    /* UI Aliases */
    --bg-body: #EFF2F5;       
    --bg-surface: #FFFFFF;    
    --text-main: var(--c-grey-900);     
    --text-muted: var(--c-grey-600);    
    --border-subtle: var(--c-grey-100);
    
    /* --- Tokens --- */
    --border-width: 3px;
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-pill: 50px;
    
    /* --- 3D Physics Tokens --- */
    --lift-rest: 0px;
    --lift-hover: -2px;
    --lift-active: 4px; /* How far down it goes when pressed */
    
    --shadow-rest: 4px;
    --shadow-hover: 6px; /* Rest + |Lift| */
    --shadow-active: 0px; 

    /* --- Typography --- */
    --font-syllabic: 'Radio Canada', 'Noto Sans Canadian Aboriginal', sans-serif;
    --font-english: 'Nunito', sans-serif;

    --fs-h1: clamp(1.8rem, 5vw, 2.2rem);
    --fs-h2: clamp(1.4rem, 4vw, 1.8rem);
    --fs-h3: clamp(1.2rem, 3.5vw, 1.4rem);
    
    --fs-body: 1rem;
    --fs-sm: 0.85rem;
    --fs-btn: 1.1rem;
    
    --fs-syl-mega: clamp(5rem, 15vh, 8rem);
    --fs-syl-hero: clamp(3.5rem, 10vh, 5rem);
    --fs-eng-hero: clamp(2.5rem, 8vh, 3.5rem);
    --fs-syl-display: clamp(2rem, 6vh, 3rem);
    --fs-eng-display: clamp(1.1rem, 3vh, 1.5rem);
    --fs-syl-grid: clamp(1.4rem, 2.5vw, 1.8rem);
    --fs-syl-row-bg: clamp(2rem, 4vw, 2.5rem);
    
    /* --- Spacing --- */
    --gap-sm: 0.5rem;
    --gap-md: 1rem;
    --gap-lg: 1.5rem;
    --gap-xl: 2.5rem;
}

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

/* --- GLOBAL SCROLL STRATEGY --- */
body {
    font-family: var(--font-english);
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    overflow: hidden; 
    
    /* PREVENT SELECTION & TAP HIGHLIGHT */
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
}

.main-wrapper {
    max-width: 850px;
    margin: 0 auto;
    width: 100%;
    height: 100dvh; 
    display: flex;
    flex-direction: column;
    overflow: hidden; 
    padding: 0 1.5rem;
    padding-bottom: 0;
    
    /* SAFE AREA PADDING */
    padding-left: max(1.5rem, env(safe-area-inset-left));
    padding-right: max(1.5rem, env(safe-area-inset-right));
}

/* --- VIEW MODE: LANDING --- */
body.view-landing { overflow-y: auto; }
body.view-landing .main-wrapper {
    height: auto;
    min-height: 100vh;
    padding-bottom: 3rem; 
    overflow: visible;
}
body.view-landing main {
    overflow: visible; 
    height: auto;
    flex-grow: 0; 
}

/* --- VIEW MODE: GAME --- */
body.view-game {
    overflow: hidden; 
    position: fixed; 
    width: 100%;
    height: 100%;
}
body.view-game .main-wrapper {
    height: 100dvh; 
    overflow: hidden; 
}

/* --- Flex Children --- */
.app-header {
    flex-shrink: 0; 
    /* SAFE AREA TOP + Original 2rem */
    padding-top: max(2rem, env(safe-area-inset-top));
    margin-bottom: var(--gap-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* Responsive Protection: Wrap if space is too tight */
    flex-wrap: wrap; 
    gap: 1rem;
}

/* Wrapper to keep Logo + Text together on the left */
.header-branding {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1 1 auto;
    min-width: 0;
}

.header-text {
    flex: 1 1 auto;
    min-width: 0;
}

/* --- Header Controls --- */
.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem; 
    flex-shrink: 0; /* Never let controls shrink */
}

main {
    flex-grow: 1; 
    min-height: 0; 
    display: flex;
    flex-direction: column;
    overflow: hidden; 
    padding-bottom: max(2rem, env(safe-area-inset-bottom)); 
}

/* --- Typography --- */
h1 {
    font-family: var(--font-syllabic);
    font-weight: 700;
    font-size: var(--fs-h1);
    color: var(--text-main);
    line-height: 1.1;
    display: flex; 
    align-items: center;
    gap: 0.75rem;
}

.subtitle {
    font-size: 0.95rem;
    color: var(--text-muted);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.25rem;
}

/* --- SPLASH SCREEN --- */
.app-splash {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background-color: var(--bg-body);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    transition: opacity 0.4s ease-out, visibility 0.4s;
}

.app-splash.fade-out {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.splash-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

/* UPDATED: Splash Logo (Flat) */
.splash-logo {
    width: 100px;
    height: 100px;
    
    /* Removed object-fit/position since icon is already square */
    border-radius: 20px; 
    background-color: transparent; 
}

.splash-text {
    font-family: var(--font-english);
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--text-muted);
}

/* --- HEADER LOGO --- */
.header-logo {
    /* Dimensions: Rounded Square matching text block height */
    height: 60px; 
    width: 60px; 
    
    /* Flat Style */
    border-radius: 12px; 
    background-color: transparent;

    /* Positioning */
    align-self: center;
    flex-shrink: 0; 
}

/* --- New Component: Progress Bar --- */
.pb-container {
    position: relative;
    width: 100%;
    height: 40px; 
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
    padding: 0 18px; 
}

.pb-track {
    width: 100%;
    height: 14px;
    background-color: white;
    border: var(--border-width) solid var(--border-subtle);
    border-radius: var(--radius-pill);
    position: relative;
    z-index: 1;
    overflow: hidden;
}

.pb-fill {
    height: 100%;
    width: 0%;
    background-color: var(--c-blue);
    border-right: 2px solid var(--c-grey-100);
    transition: width 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.pb-knob-guide {
    position: absolute;
    left: 18px; 
    right: 18px; 
    top: 0; bottom: 0;
    pointer-events: none;
}

.pb-knob {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.85rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transform: translate(-50%, -50%);
}

.pb-total {
    left: 100%; 
    background-color: white;
    border: var(--border-width) solid var(--border-subtle);
    color: var(--text-muted);
    z-index: 2; 
}

.pb-current {
    left: 0%; 
    background-color: var(--c-blue);
    color: white;
    z-index: 3;
    transition: left 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* --- Cards --- */
.card {
    background-color: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: var(--border-width) solid var(--border-subtle);
    box-shadow: 0 8px 0 var(--c-grey-100);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    margin-bottom: 2rem; 
}
.card:last-child { margin-bottom: 0; }

.card-header h3 {
    font-size: var(--fs-h3);
    color: var(--text-main);
    margin-bottom: var(--gap-sm);
    font-weight: 800;
}

.description-text {
    font-size: var(--fs-body);
    color: var(--text-main);
    margin-bottom: var(--gap-lg);
}

.instruction-label {
    font-size: var(--fs-sm);
    color: var(--text-muted);
    font-weight: 800;
    text-transform: uppercase;
    margin-bottom: var(--gap-md);
    display: block;
}

/* --- Buttons Grid --- */
.button-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--gap-md);
    margin-bottom: 2rem;
}

/* --- Footer --- */
.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: var(--border-width) solid var(--border-subtle);
    padding-top: var(--gap-lg);
    gap: var(--gap-md);
    margin-top: auto;
    
    /* Allow wrapping naturally */
    flex-wrap: wrap;
}

.button-group-right { display: flex; gap: var(--gap-sm); align-items: center; }

/* --- Toggle --- */
.toggle-btn {
    appearance: none;
    background: none;
    border: none;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    padding: 4px;
}

.toggle-label-text {
    font-weight: 700;
    color: var(--text-main);
    font-size: 0.95rem;
}

.toggle-track {
    width: 52px;
    height: 30px;
    background-color: var(--bg-body);
    border: var(--border-width) solid var(--border-subtle);
    border-radius: var(--radius-pill);
    position: relative;
    transition: background-color 0.2s;
}

.toggle-thumb {
    width: 18px;
    height: 18px;
    background-color: var(--text-muted);
    border-radius: 50%;
    position: absolute;
    top: 3px;
    left: 4px;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toggle-btn[aria-checked="true"] .toggle-track { background-color: var(--c-yellow); border-color: var(--c-yellow); }
.toggle-btn[aria-checked="true"] .toggle-thumb { transform: translateX(22px); background-color: var(--text-main); }


/* ========================================= */
/*   STANDARDIZED 3D BUTTONS ARCHITECTURE    */
/* ========================================= */

/* 1. Base Class: Physics & Typography */
.btn {
    appearance: none;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    
    font-family: var(--font-english);
    font-weight: 800;
    font-size: var(--fs-btn);
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    
    /* Defaults to be overridden by skins */
    background-color: white;
    color: var(--text-main);
    border: var(--border-width) solid transparent;
    
    /* The Physics Engine */
    transform: translateY(var(--lift-rest));
    box-shadow: 0 var(--shadow-rest) 0 var(--btn-shadow-color);
    
    transition: transform 0.1s cubic-bezier(0.3, 0, 0.5, 1), 
                box-shadow 0.1s cubic-bezier(0.3, 0, 0.5, 1),
                background-color 0.1s,
                border-color 0.1s,
                color 0.1s;
    
    /* Variable Defaults */
    --btn-shadow-color: var(--c-grey-100);
}

.btn:focus { outline: none; }

/* 2. Interaction States (Physics) - MOBILE FIX APPLIED */
@media (hover: hover) {
    .btn:hover:not(:disabled) {
        transform: translateY(var(--lift-hover));
        box-shadow: 0 var(--shadow-hover) 0 var(--btn-shadow-color);
    }
}

.btn:active:not(:disabled) {
    transform: translateY(var(--lift-active));
    box-shadow: 0 var(--shadow-active) 0 var(--btn-shadow-color);
}

.btn:disabled {
    cursor: not-allowed;
    background-color: var(--c-grey-50);
    color: var(--c-grey-400);
    border-color: var(--c-grey-300);
    --btn-shadow-color: var(--c-grey-300);
    transform: translateY(var(--lift-rest));
    box-shadow: 0 var(--shadow-rest) 0 var(--btn-shadow-color);
    opacity: 0.8;
}

/* 3. Shape Modifiers */
.btn--pill {
    border-radius: var(--radius-pill);
    padding: 0.75rem 2rem;
}

/* Strict Circle Enforcement: 
   flex-shrink: 0 and min-width ensures they never get crushed by flex containers on mobile.
*/
.btn--circle {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    border-radius: 50%;
    padding: 0;
    flex-shrink: 0;
    aspect-ratio: 1 / 1;
}

.btn--block {
    width: 100%;
    border-radius: var(--radius-md);
    padding: 0.75rem;
}

/* 4. Skin Modifiers */

/* A. Solid Skins (Colored by default) */
.btn--solid-blue {
    background-color: var(--c-blue);
    color: white;
    border-color: var(--c-blue-dark);
    --btn-shadow-color: var(--c-blue-dark);
}

@media (hover: hover) {
    .btn--solid-blue:hover:not(:disabled) { background-color: var(--c-blue-light); }
}

.btn--solid-red {
    background-color: var(--c-red);
    color: white;
    border-color: var(--c-red-dark);
    --btn-shadow-color: var(--c-red-dark);
}

@media (hover: hover) {
    .btn--solid-red:hover:not(:disabled) { background-color: #ff4d5a; }
}


/* B. Surface Skins (Grey by default, colored on interaction) */
/* Base Surface Style */
.btn--surface {
    background-color: white;
    border-color: var(--border-subtle);
    color: var(--text-muted);
    --btn-shadow-color: var(--border-subtle);
}

/* Surface Variants (Color on Hover) */
/* Applied Mobile Hover Check here too */
@media (hover: hover) {
    .btn--surface-blue:hover:not(:disabled) {
        color: var(--c-blue);
        border-color: var(--c-blue);
        --btn-shadow-color: var(--c-blue);
    }
    .btn--surface-red:hover:not(:disabled) {
        color: var(--c-red);
        border-color: var(--c-red);
        --btn-shadow-color: var(--c-red);
    }
    .btn--surface-yellow:hover:not(:disabled) {
        color: var(--text-main);
        background-color: var(--c-yellow);
        border-color: var(--c-yellow-dark);
        --btn-shadow-color: var(--c-yellow-dark);
    }
    .btn--surface-green:hover:not(:disabled) {
        color: var(--c-green);
        border-color: var(--c-green);
        --btn-shadow-color: var(--c-green);
    }
}

.btn--surface-blue:active:not(:disabled) {
    color: var(--c-blue);
    border-color: var(--c-blue);
    --btn-shadow-color: var(--c-blue);
}
.btn--surface-red:active:not(:disabled) {
    color: var(--c-red);
    border-color: var(--c-red);
    --btn-shadow-color: var(--c-red);
}
.btn--surface-yellow:active:not(:disabled) {
    color: var(--text-main);
    background-color: var(--c-yellow);
    border-color: var(--c-yellow-dark);
    --btn-shadow-color: var(--c-yellow-dark);
}
.btn--surface-green:active:not(:disabled) {
    color: var(--c-green);
    border-color: var(--c-green);
    --btn-shadow-color: var(--c-green);
}

/* 5. Icon Size Fix */
.btn .material-icons-round { font-size: 1.5rem; }

/* Responsive Tweaks */
@media (max-width: 400px) {
    .btn--pill { width: 100%; }
    .header-controls .btn--pill { width: auto; }
}

/* --- Slider --- */
.slider-group { margin-bottom: 2rem; }

.slider-wrapper {
    position: relative;
    height: 40px; 
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
}

input[type=range] {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0; left: 0;
    margin: 0;
    opacity: 1; 
    background: transparent; 
    cursor: pointer;
    z-index: 2;
    -webkit-appearance: none;
}

input[type=range]:focus { outline: none; }

.slider-track-visual {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 100%;
    height: 14px;
    background-color: white;
    border: var(--border-width) solid var(--border-subtle);
    border-radius: var(--radius-pill);
    overflow: hidden;
    z-index: 1;
    pointer-events: none;
}

.track-fill {
    height: 100%;
    width: 50%; 
    background-color: var(--c-blue);
    border-right: 2px solid rgba(0,0,0,0.1);
    box-shadow: none;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 32px;
    width: 32px;
    border-radius: 50%;
    background-color: var(--c-blue);
    border: 4px solid white;
    box-shadow: 0 0 0 1px var(--border-subtle);
    background-image: none;
    margin-top: 4px; 
    cursor: grab;
    transition: transform 0.1s;
}

input[type=range]::-webkit-slider-thumb:active {
    cursor: grabbing;
    transform: scale(1.1);
    background-color: var(--c-yellow);
}

input[type=range]::-moz-range-thumb {
    height: 32px;
    width: 32px;
    border-radius: 50%;
    background-color: var(--c-blue);
    border: 4px solid white;
    box-shadow: 0 0 0 1px var(--border-subtle);
    background-image: none;
    cursor: grab;
}

.slider-ticks {
    display: flex;
    justify-content: space-between;
    font-size: var(--fs-sm);
    font-weight: 800;
    color: var(--text-muted);
}
.active-tick { color: var(--c-blue); }

/* --- Modal Overlay --- */
.modal-backdrop {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background-color: rgba(16, 42, 67, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 1.5rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.modal-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background-color: white;
    border-radius: var(--radius-lg);
    border: var(--border-width) solid var(--border-subtle);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    text-align: center;
    transform: scale(0.9);
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

.modal-backdrop.visible .modal-content {
    transform: scale(1);
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 2rem;
}

/* --- Stats Debug Overlay --- */
.stats-content {
    max-width: 600px; 
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

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

.stats-header h3 { margin: 0; }

.stats-debug-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 0.75rem;
    overflow-y: auto;
    flex-grow: 1;
    padding: 0.5rem;
}

.stat-card {
    background: var(--bg-body);
    border: 2px solid var(--border-subtle);
    border-radius: 12px;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.stat-char {
    font-family: var(--font-syllabic);
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-main);
}

.stat-char.font-english {
    font-family: var(--font-english);
    font-size: 1.2rem;
}

.stat-rate {
    font-size: 0.9rem;
    font-weight: 800;
}

.stat-rate.good { color: var(--c-green); }
.stat-rate.mid { color: var(--c-orange); }
.stat-rate.bad { color: var(--c-red); }
.stat-rate.neutral { color: var(--text-muted); opacity: 0.5; }


/* --- Results Screen (Shared) --- */
.results-card {
    text-align: center;
    padding: 2rem;
    flex-grow: 1;
    justify-content: center;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.score-display {
    font-size: 5rem;
    font-weight: 800;
    color: var(--c-blue);
    line-height: 1;
    margin: 1rem 0;
}

.score-label {
    font-size: 1.2rem;
    color: var(--text-muted);
    font-weight: 700;
}

.struggle-section {
    margin-top: 2rem;
    text-align: center;
    width: 100%;
    overflow-y: auto; 
    max-height: 40vh;
}

.struggle-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

.struggle-item {
    background: #FFF5F5;
    border: 2px solid #E12D39;
    color: #E12D39;
    border-radius: 8px;
    padding: 0.5rem;
    text-align: center;
    font-family: var(--font-syllabic);
    font-weight: 700;
    font-size: 1.5rem;
    min-width: 60px;
}

.game-footer {
    display: flex;
    justify-content: center;
    margin-top: 1rem;
    flex-shrink: 0;
}

@media (max-width: 600px) {
    .card-footer { 
        flex-direction: column; 
        align-items: stretch; 
        gap: 1.5rem;
    }
    .toggle-btn { justify-content: space-between; width: 100%; }
    .button-group-right { flex-direction: column; width: 100%; gap: 0.75rem; }
    
    /* FIX: Only stretch buttons that AREN'T circles. 
       This fixes the oval/touching bug in headers. */
    .btn:not(.btn--circle) { width: 100%; }
}