/* ═══════════════════════════════════════════════════════════════
   PHONICS LAB - Orton-Gillingham inspired structured phonics game
   Design principles:
    • Lexend Deca - reduces visual crowding
    • Color-coded phonemes: vowels = red, consonants = blue, digraphs = green
   • Large touch targets (≥72px) for tablets
   • Warm cream background - reduces visual stress
   • Positive-only feedback design
═══════════════════════════════════════════════════════════════ */

:root {
    --bg:           #fffdf0;
    --text:         #1a1a2e;
    --text-light:   #5a5a7a;
    --card:         #ffffff;
    --border:       #e8e4d4;

    --vowel:        #dc2626;   /* red   - vowels                */
    --cons:         #1d4ed8;   /* blue  - consonants            */
    --digraph:      #16a34a;   /* green - digraph units          */

    --success:      #16a34a;
    --error:        #ef476f;
    --locked:       #c5c5d5;

    --ph-1: #2563eb;   /* CVC      - blue   */
    --ph-2: #16a34a;   /* CVCC     - green  */
    --ph-3: #ffbe0b;   /* CCVC     - yellow */
    --ph-4: #dc2626;   /* Digraph  - red    */
    --ph-5: #ea580c;   /* Mixed    - orange */

    --radius-sm: 10px;
    --radius-md: 18px;
    --radius-lg: 28px;
    --shadow:    0 4px 20px rgba(26,26,46,0.10);
    --shadow-lg: 0 8px 32px rgba(26,26,46,0.15);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }

body {
    font-family: 'Lexend Deca', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    letter-spacing: 0.03em;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

/* ─── Screen system ───────────────────────────────────────────── */
.screen { display: none; flex-direction: column; align-items: center; width: 100%; padding: 24px 16px 48px; }
.screen.active { display: flex; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ─── Home ────────────────────────────────────────────────────── */
.ph-home-header {
    text-align: center;
    padding: 8px 20px 4px;
    max-width: 640px;
    width: 100%;
}
.ph-home-header h1 {
    font-family: 'Fredoka One', cursive;
    font-size: clamp(2rem, 6vw, 2.8rem);
    color: #2563eb;
    text-shadow: 2px 2px 0 rgba(37,99,235,0.2);
    margin-bottom: 4px;
}
.ph-tagline { color: var(--text-light); font-size: 0.95rem; margin-bottom: 12px; }

.ph-stars-display {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #fef9c3;
    border: 2px solid #fcd34d;
    border-radius: var(--radius-lg);
    padding: 6px 18px;
    font-size: 1rem;
    font-weight: 700;
    color: #92400e;
    margin: 8px 0 16px;
}

/* ─── Pattern cards ───────────────────────────────────────────── */
.pattern-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
    width: 100%;
    max-width: 720px;
    margin-top: 8px;
}

.pattern-card {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--card);
    border: 2px solid var(--border);
    border-left: 5px solid var(--pat-color, #2563eb);
    border-radius: var(--radius-md);
    padding: 16px 18px;
    cursor: pointer;
    text-align: left;
    transition: transform 0.12s, box-shadow 0.12s;
    box-shadow: var(--shadow);
}
.pattern-card:hover, .pattern-card:focus-visible {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--pat-color, #2563eb);
}
.pat-icon  { font-size: 2.2rem; flex-shrink: 0; }
.pat-info  { flex: 1; }
.pat-info h3 { font-family: 'Fredoka One', cursive; font-size: 1.15rem; color: var(--text); margin-bottom: 2px; }
.pat-label { display: inline-block; background: var(--pat-color, #2563eb); color: #fff;
             font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em;
             padding: 2px 8px; border-radius: 100px; margin-bottom: 4px; }
.pat-info p { font-size: 0.82rem; color: var(--text-light); line-height: 1.4; }
.pat-stars  { font-size: 1.1rem; flex-shrink: 0; }

/* ─── Mode select ─────────────────────────────────────────────── */
.sel-header { text-align: center; margin-bottom: 16px; }
.sel-header h2 { font-family: 'Fredoka One', cursive; font-size: 1.6rem; }
.mode-select-grid { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 500px; }

.mode-sel-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--card);
    border: 2px solid var(--border);
    border-left: 5px solid var(--mode-color, #2563eb);
    border-radius: var(--radius-md);
    padding: 16px 18px;
    cursor: pointer;
    text-align: left;
    transition: transform 0.12s, box-shadow 0.12s;
    box-shadow: var(--shadow);
}
.mode-sel-btn:hover { transform: translateX(4px); box-shadow: var(--shadow-lg); }
.msel-icon { font-size: 1.8rem; flex-shrink: 0; }
.msel-info { flex: 1; display: flex; flex-direction: column; }
.msel-info strong { font-size: 1rem; color: var(--text); }
.msel-info span   { font-size: 0.82rem; color: var(--text-light); }
.msel-stars       { font-size: 0.95rem; flex-shrink: 0; }

/* ─── Game screen ─────────────────────────────────────────────── */
.ph-game-hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 560px;
    margin-bottom: 10px;
}
.ph-score-display { font-weight: 700; font-size: 1rem; color: var(--text-light); }
.ph-score-display span { color: var(--text); font-size: 1.1rem; }
.ph-qnum { font-size: 0.85rem; color: var(--text-light); }

.ph-progress-track {
    width: 100%;
    max-width: 560px;
    height: 8px;
    background: var(--border);
    border-radius: 100px;
    overflow: hidden;
    margin-bottom: 18px;
}
.ph-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #e63946, #2563eb, #16a34a);
    border-radius: 100px;
    transition: width 0.35s ease;
    width: 0%;
}

#game-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 560px;
    gap: 14px;
}

/* ─── Color-coded word display ────────────────────────────────── */
.ph-word-display {
    font-family: 'Fredoka One', cursive;
    font-size: clamp(2.8rem, 10vw, 5rem);
    letter-spacing: 0.08em;
    line-height: 1;
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px 36px;
    box-shadow: var(--shadow);
    transition: filter 0.3s;
    user-select: none;
}
.ph-vowel   { color: var(--vowel);   }
.ph-cons    { color: var(--cons);    }
.ph-digraph { color: var(--digraph); text-decoration: underline; text-decoration-color: var(--digraph); text-underline-offset: 4px; }

/* ─── Timer bar ───────────────────────────────────────────────── */
.ph-timer-bar {
    width: 100%;
    max-width: 300px;
    height: 6px;
    background: var(--border);
    border-radius: 100px;
    overflow: hidden;
}
.ph-timer-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #ffbe0b, #2563eb);
    border-radius: 100px;
    transition: width 0.05s linear;
}

/* ─── Prompt ──────────────────────────────────────────────────── */
.ph-prompt { font-size: 1rem; color: var(--text-light); text-align: center; }

/* ─── Choices grid ────────────────────────────────────────────── */
.ph-choices {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
    max-width: 400px;
    transition: opacity 0.3s;
}
.ph-choice-btn {
    font-family: 'Fredoka One', cursive;
    font-size: 1.5rem;
    padding: 16px 10px;
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: transform 0.1s, border-color 0.1s, background 0.15s;
    box-shadow: var(--shadow);
    color: var(--text);
}
.ph-choice-btn:hover:not(:disabled) { transform: scale(1.04); border-color: #2563eb; }
.ph-choice-btn.correct { background: #dcfce7; border-color: var(--success); color: #14532d; }
.ph-choice-btn.wrong   { background: #fee2e2; border-color: var(--error);   color: #7f1d1d; }

/* ─── Speak button ────────────────────────────────────────────── */
.ph-speak-btn {
    background: #fff8cc;
    border: 2px solid #ffbe0b;
    color: #7a5200;
    border-radius: var(--radius-md);
    padding: 10px 24px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s;
}
.ph-speak-btn:hover:not(:disabled) { background: #ffef99; }
.ph-speak-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Sort grid ───────────────────────────────────────────────── */
.ph-sort-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
    max-width: 420px;
}
.ph-sort-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 18px 12px;
    background: var(--card);
    border: 3px solid var(--sort-color, #2563eb);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: transform 0.1s, background 0.15s;
    box-shadow: var(--shadow);
}
.ph-sort-btn:hover:not(:disabled) { transform: scale(1.04); background: #f0f9ff; }
.ph-sort-btn.correct { background: #dcfce7; border-color: var(--success); }
.ph-sort-btn.wrong   { background: #fee2e2; border-color: var(--error);   }
.sort-label   { font-family: 'Fredoka One', cursive; font-size: 1.3rem; color: var(--sort-color, #2563eb); }
.sort-example { font-size: 0.78rem; color: var(--text-light); }

/* ─── Blend mode ──────────────────────────────────────────────── */
.ph-phoneme-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}
.ph-phoneme-box {
    font-family: 'Fredoka One', cursive;
    font-size: 2.2rem;
    min-width: 64px;
    padding: 14px 12px;
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    text-align: center;
    color: var(--cons);
    transition: background 0.2s, transform 0.15s, border-color 0.2s;
    box-shadow: var(--shadow);
}
.ph-phoneme-box.active-phoneme {
    background: #dbeafe;
    border-color: #2563eb;
    color: #1d4ed8;
    transform: scale(1.12);
}
.ph-sep { font-size: 1.5rem; color: var(--text-light); }

/* ─── Feedback flash ──────────────────────────────────────────── */
.ph-feedback {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--success);
    min-height: 1.4em;
    text-align: center;
    transition: opacity 0.2s;
}
.ph-feedback-wrong   { color: var(--error); }
.ph-feedback-hidden  { opacity: 0; }

/* ─── Results screen ──────────────────────────────────────────── */
.ph-results-card {
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px 32px;
    max-width: 440px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-lg);
}
.res-stars   { font-size: 2.2rem; letter-spacing: 4px; margin-bottom: 8px; display: block; }
.res-title   { font-family: 'Fredoka One', cursive; font-size: 1.7rem; margin-bottom: 6px; }
.res-msg     { font-size: 0.92rem; color: var(--text-light); margin-bottom: 18px; }
.res-stats   { display: flex; justify-content: center; gap: 28px; margin-bottom: 20px; }
.res-stat    { display: flex; flex-direction: column; align-items: center; }
.res-stat span:first-child { font-size: 1.6rem; font-weight: 800; color: var(--text); }
.res-stat span:last-child  { font-size: 0.78rem; color: var(--text-light); }
.res-btns    { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

/* ─── Buttons ─────────────────────────────────────────────────── */
.btn-primary {
    background: #e63946;
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    padding: 14px 28px;
    font-family: 'Fredoka One', cursive;
    font-size: 1.05rem;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    box-shadow: var(--shadow);
}
.btn-primary:hover { background: #c81d2a; transform: translateY(-2px); }

.btn-secondary {
    background: #2563eb;
    color: #fff;
    border: 2px solid #1d4ed8;
    border-radius: var(--radius-md);
    padding: 12px 22px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-secondary:hover { background: #1d4ed8; }

.btn-quit {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 4px 10px;
}
.btn-quit:hover { color: var(--error); }

.btn-reset {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-light);
    font-size: 0.8rem;
    border-radius: 8px;
    padding: 6px 14px;
    cursor: pointer;
    margin-top: 8px;
}
.btn-reset:hover { color: var(--error); border-color: var(--error); }

/* ─── Legend bar ──────────────────────────────────────────────── */
.ph-legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: center;
    font-size: 0.8rem;
    color: var(--text-light);
    margin-bottom: 10px;
}
.ph-legend-item { display: flex; align-items: center; gap: 4px; }
.ph-legend-dot  { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ─── More games footer ───────────────────────────────────────── */
.home-footer { margin-top: 24px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }

/* ─── Responsive ──────────────────────────────────────────────── */
@media (max-width: 480px) {
    .pattern-grid      { grid-template-columns: 1fr; }
    .ph-word-display   { font-size: 3rem; padding: 16px 24px; }
    .ph-choices        { grid-template-columns: 1fr 1fr; gap: 8px; }
    .ph-choice-btn     { font-size: 1.3rem; padding: 14px 8px; }
    .ph-sort-grid      { grid-template-columns: 1fr 1fr; gap: 8px; }
    .ph-phoneme-box    { font-size: 1.8rem; min-width: 52px; padding: 12px 10px; }
    .res-stats         { gap: 16px; }
}
