/* --- LOCAL FONTS SETUP (Variable Fonts) --- */
@font-face {
    font-family: 'Noto Sans Canadian Aboriginal';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('../assets/fonts/NotoSansCanadianAboriginal-VariableFont_wght.woff2') format('woff2');
}

@font-face {
    font-family: 'Nunito';
    font-style: normal;
    font-weight: 200 1000;
    font-display: swap;
    src: url('../assets/fonts/Nunito-VariableFont_wght.woff2') format('woff2');
}

/* --- SVG ICON SYSTEM --- */
.app-icon {
    width: 1.5rem;
    height: 1.5rem;
    fill: currentColor;
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
    transition: fill 0.2s;
}

.rotate-90 { transform: rotate(90deg); }
.rotate-neg-90 { transform: rotate(-90deg); }


/* --- VARIABLES --- */
:root {
    /* Palette */
    --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;

    /* Greys */
    --c-grey-50:  #F0F4F8;
    --c-grey-100: #D9E2EC;
    --c-grey-300: #BCCCDC;
    --c-grey-400: #9FB3C8;
    --c-grey-600: #627D98;
    --c-grey-900: #102A43;

    /* 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;
    
    /* Physics */
    --lift-rest: 0px;
    --lift-hover: -2px;
    --lift-active: 4px; 
    --shadow-rest: 4px;
    --shadow-hover: 6px;
    --shadow-active: 0px; 

    /* Typography */
    --font-syllabic: '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);
    
    --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; }

body {
    font-family: var(--font-english);
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    overflow: hidden; 
    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;
    padding-left: max(1.5rem, env(safe-area-inset-left));
    padding-right: max(1.5rem, env(safe-area-inset-right));
}

/* --- VIEW MODES --- */
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; }

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

/* --- HEADER --- */
.app-header {
    flex-shrink: 0; 
    padding-top: max(2rem, env(safe-area-inset-top));
    margin-bottom: var(--gap-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap; 
    gap: 1rem;
}

.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 { display: flex; align-items: center; gap: 1rem; flex-shrink: 0; }

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

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

.header-logo {
    height: 60px; width: 60px; 
    border-radius: 12px; 
    background-color: transparent;
    align-self: center; flex-shrink: 0; object-fit: cover;
}

.directory-icon {
    height: 48px; width: 48px;
    border-radius: 10px; flex-shrink: 0;
    object-fit: cover; background-color: transparent;
}

/* --- 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; }

/* --- 3D BUTTONS (Shared) --- */
.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;
    background-color: white;
    color: var(--text-main);
    border: var(--border-width) solid transparent;
    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;
    --btn-shadow-color: var(--c-grey-100);
}
.btn:focus { outline: none; }
@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; }

.btn--pill { border-radius: var(--radius-pill); padding: 0.75rem 2rem; }
.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; }

/* Button Skins */
.btn--solid-blue { background-color: var(--c-blue); color: white; border-color: var(--c-blue-dark); --btn-shadow-color: var(--c-blue-dark); }
.btn--solid-red { background-color: var(--c-red); color: white; border-color: var(--c-red-dark); --btn-shadow-color: var(--c-red-dark); }
.btn--surface { background-color: white; border-color: var(--border-subtle); color: var(--text-muted); --btn-shadow-color: var(--border-subtle); }

/* --- ROW BUTTON (Shared: Directory & Practice Sets) --- */
.btn-wrapper { position: relative; height: 85px; z-index: 1; }
.row-btn {
    appearance: none;
    width: 100%; height: 100%;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    border: var(--border-width) solid var(--border-subtle);
    box-shadow: 0 6px 0 var(--border-subtle);
    padding: 0 1.5rem;
    cursor: pointer;
    text-align: left;
    display: flex; align-items: center;
    position: relative;
    transform: translateZ(0); 
    will-change: transform;
    transition: transform 0.1s cubic-bezier(0.3, 0, 0.5, 1), box-shadow 0.1s cubic-bezier(0.3, 0, 0.5, 1), border-color 0.1s;
    overflow: hidden; 
}
@media (hover: hover) {
    .row-btn:hover { border-color: var(--c-blue); background-color: var(--c-grey-50); transform: translateY(-2px); box-shadow: 0 8px 0 var(--c-blue); }
}
.row-btn[aria-pressed="true"] { background-color: var(--c-blue); border-color: var(--c-blue-dark); color: white; transform: translateY(6px); box-shadow: 0 0 0 var(--c-blue-dark); }
.btn-text-group { display: flex; flex-direction: column; z-index: 2; position: relative; line-height: 1.1; }
.btn-label { font-family: var(--font-english); font-weight: 800; font-size: var(--fs-btn); color: var(--text-main); z-index: 2; position: relative; }
.btn-subtext { font-family: var(--font-english); font-size: var(--fs-sm); font-weight: 800; color: var(--text-muted); margin-top: 0.25rem; }
.row-btn[aria-pressed="true"] .btn-label { color: white; }
.row-btn[aria-pressed="true"] .btn-subtext { color: #D9E2EC; }

/* Ghost Syllabics inside row-btn */
.btn-syllabics {
    font-family: var(--font-syllabic);
    font-size: var(--fs-syl-row-bg);
    font-weight: 700;
    color: var(--text-main);
    line-height: normal;
    padding: 1rem 0;
    white-space: nowrap;
    position: absolute; right: 1rem; top: 50%; transform: translateY(-50%);
    pointer-events: none; transition: all 0.2s ease; opacity: 0.15; 
    mask-image: linear-gradient(to right, transparent 0%, black 80%);
    -webkit-mask-image: linear-gradient(to right, transparent 0%, black 80%);
}
.row-btn[aria-pressed="true"] .btn-syllabics { color: white; opacity: 0.3; mask-image: linear-gradient(to right, transparent 0%, white 90%); -webkit-mask-image: linear-gradient(to right, transparent 0%, white 90%); }

/* --- TOGGLE SWITCH --- */
.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); }

/* --- SLIDER --- */
.slider-group { margin-bottom: 2rem; width: 100%; }
.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);
}
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);
    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);
    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 */
.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 */
.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; }

/* 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; }
.splash-logo { width: 100px; height: 100px; border-radius: 20px; background-color: transparent; object-fit: cover; }
.splash-text { font-family: var(--font-english); font-weight: 800; font-size: 1.2rem; color: var(--text-muted); }