/* ---------- Phonics Playground ---------- */
:root{
  --ink:#232a45;
  --ink-soft:#5c6480;
  --ink-faint:#6b7290;
  --paper:#f7f7fb;
  --surface:#fff;
  --line:rgba(35,42,69,.10);
  /* Every colour that carries text is dark enough to clear 4.5:1 on white, so the small
     print and the buttons stay readable; the lighter tints below are backgrounds only. */
  --pink:#cf3f6b;
  --orange:#c9681f;
  --yellow:#f0b429;
  --gold:#8a6010;
  --green:#1b7f4f;
  --teal:#1b8378;
  --blue:#2f66c4;
  --purple:#6f4cb8;

  --shadow-sm:0 1px 2px rgba(35,42,69,.06), 0 2px 6px rgba(35,42,69,.05);
  --shadow-md:0 2px 6px rgba(35,42,69,.07), 0 10px 24px rgba(35,42,69,.10);
  --shadow-lg:0 12px 34px rgba(35,42,69,.18);
  --radius:18px;

  /* Chrome and labels: the clean face the grown-ups read.                       */
  --font:"Segoe UI Variable Text","Segoe UI",system-ui,-apple-system,"Helvetica Neue",Arial,sans-serif;
  --font-display:"Segoe UI Variable Display","Segoe UI",system-ui,-apple-system,"Helvetica Neue",Arial,sans-serif;
  /* Letters and words the child reads. A geometric face keeps the single-storey
     "a" and "g" they are taught to write; the usual UI faces draw a two-storey
     "a", which is a different shape from the one on the page in front of them.  */
  --font-reading:"Century Gothic","Questrial","Futura","Avenir Next","Trebuchet MS",system-ui,sans-serif;
  --emoji:"Segoe UI Emoji","Apple Color Emoji","Noto Color Emoji",sans-serif;
}
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0; font-family:var(--font); color:var(--ink); font-size:16px; line-height:1.45;
  background:
    radial-gradient(ellipse 70% 50% at 15% 0%,rgba(255,214,168,.35),transparent 70%),
    radial-gradient(ellipse 60% 45% at 90% 8%,rgba(168,208,255,.32),transparent 70%),
    radial-gradient(ellipse 80% 40% at 50% 100%,rgba(255,196,219,.26),transparent 70%),
    var(--paper);
  -webkit-tap-highlight-color:transparent;
  overflow:hidden;
}
button{font-family:inherit;cursor:pointer;border:none;color:inherit}
.hidden{display:none !important}
.screen{position:absolute;inset:0;display:flex;flex-direction:column}

/* a visible ring for anyone driving this from the keyboard */
:focus-visible{outline:3px solid var(--blue);outline-offset:3px;border-radius:12px}

/* ---------- Menu ---------- */
#menu{align-items:center;padding:18px 20px 4px;overflow-y:auto}
.logo{
  margin:0; font-family:var(--font-display); font-weight:700;
  font-size:clamp(30px,5.2vw,50px); letter-spacing:-.5px; text-align:center; line-height:1.1;
}
.logo span{color:var(--ink)}
.logo em{color:var(--pink);font-style:normal}
.tagline{margin:5px 0 14px;font-size:clamp(14px,2vw,17px);color:var(--ink-soft)}

.agebar{
  display:flex;align-items:center;gap:14px;flex-wrap:wrap;justify-content:center;
  background:var(--surface);padding:10px 18px;border-radius:999px;
  border:1px solid var(--line);box-shadow:var(--shadow-sm);
}
.agebar-label{font-size:15px;color:var(--ink-soft);font-weight:500}
.ages{display:flex;gap:6px;flex-wrap:wrap;justify-content:center}
.age{
  width:46px;height:46px;border-radius:50%;font-size:19px;font-weight:600;color:var(--ink);
  font-family:var(--font-reading);
  background:var(--surface);border:1.5px solid var(--line);
  transition:transform .12s ease, box-shadow .12s ease, background .12s ease, color .12s ease;
}
.age:hover{transform:translateY(-2px);box-shadow:var(--shadow-sm);border-color:rgba(47,102,196,.4)}
.age:active{transform:translateY(0)}
.age[aria-pressed="true"]{
  background:var(--blue);border-color:var(--blue);color:#fff;
  box-shadow:0 4px 12px rgba(47,102,196,.35);
}
.level-note{margin:13px 0 2px;font-size:15px;color:var(--ink-soft);text-align:center}
.level-note b{color:var(--purple);font-weight:600}

/* 220px is the narrowest a card can be before the blurb starts stacking up into a tall
   column of two-word lines; the width below is what it takes to stand seven of them in a
   row. That puts the twenty games in three rows on a 1080p screen, which fits without
   scrolling, and still gives five columns at 1280. */
.cards{
  display:grid;gap:14px;width:min(1640px,100%);padding:12px 2px 14px;
  grid-template-columns:repeat(auto-fit,minmax(220px,1fr));
}
.card{
  --accent:var(--pink);
  position:relative;overflow:hidden;
  display:flex;flex-direction:column;align-items:flex-start;gap:6px;text-align:left;
  padding:18px;border-radius:var(--radius);background:var(--surface);
  border:1px solid var(--line);box-shadow:var(--shadow-sm);
  transition:transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
/* a quiet band of the card's colour, so the set still reads as colour-coded */
.card::before{
  content:"";position:absolute;left:0;right:0;top:0;height:3px;background:var(--accent);opacity:.85;
}
.card:hover{transform:translateY(-3px);box-shadow:var(--shadow-md);border-color:rgba(35,42,69,.16)}
.card:active{transform:translateY(0);box-shadow:var(--shadow-sm)}
.card .icon{
  font-size:28px;line-height:1;width:52px;height:52px;border-radius:14px;
  display:flex;align-items:center;justify-content:center;font-family:var(--emoji);
  background:var(--tint,#fdeaf0);
  margin-bottom:2px;transition:transform .25s ease;
}
.card:hover .icon{animation:hop .5s ease}
@keyframes hop{0%,100%{transform:translateY(0)}45%{transform:translateY(-5px) scale(1.06)}75%{transform:translateY(1px)}}
.card .name{font-family:var(--font-display);font-size:19px;font-weight:600;letter-spacing:-.2px}
.card .blurb{font-size:14px;color:var(--ink-soft);line-height:1.45}
/* long sound chains (c-a-t-s) must be allowed to break, but only where they have to:
   break-all splits ordinary words mid-letter and "carriage" came out as "carriag e" */
.card .train-line{font-family:var(--font-reading);font-size:14px;color:var(--blue);font-weight:600;overflow-wrap:anywhere;line-height:1.5}
.card.c0{--accent:var(--pink);--tint:#fdeaf0}
.card.c1{--accent:var(--blue);--tint:#e8f0fd}
.card.c2{--accent:var(--teal);--tint:#e2f6f4}
.card.c3{--accent:var(--yellow);--tint:#fdf2dc}
.card.c4{--accent:var(--purple);--tint:#efe9fa}
.card.c5{--accent:var(--green);--tint:#e5f6ed}

.grownups{display:flex;gap:10px;align-items:center;flex-wrap:wrap;justify-content:center;padding:2px 0 12px}
.mini{
  background:var(--surface);border:1px solid var(--line);border-radius:999px;
  padding:8px 16px;font-size:14px;color:var(--ink);box-shadow:var(--shadow-sm);
  transition:transform .12s ease, border-color .12s ease;
}
.mini:hover{border-color:rgba(35,42,69,.2)}
.mini:active{transform:translateY(1px)}
.hint{font-size:13px;color:var(--ink-faint)}

/* the voice picker: step back and forth, or open the list and choose one outright */
.voicebar{display:flex;align-items:center;gap:6px;padding:4px 8px}
.voicebar:active{transform:none}
.voice-ico{font-family:var(--emoji);font-size:14px;line-height:1}
.voice-step{
  background:none;border-radius:50%;width:24px;height:24px;font-size:11px;
  color:var(--ink-soft);display:flex;align-items:center;justify-content:center;
  transition:background .12s ease, color .12s ease;
}
.voice-step:hover{background:rgba(35,42,69,.07);color:var(--ink)}
.voice-step:disabled{opacity:.35;cursor:default;background:none}
#voice-select{
  font-family:inherit;font-size:14px;color:var(--ink);background:none;border:none;
  padding:4px 2px;max-width:190px;cursor:pointer;
}
#voice-select:focus{outline:none}
.visually-hidden{
  position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;
  clip:rect(0 0 0 0);white-space:nowrap;border:0;
}

/* ---------- HUD ---------- */
#hud{
  display:flex;align-items:center;gap:10px;padding:10px 14px;flex-wrap:wrap;
  background:rgba(255,255,255,.88);backdrop-filter:blur(10px);
  border-bottom:1px solid var(--line);
}
.hud-btn{
  background:var(--surface);border:1px solid var(--line);border-radius:999px;
  padding:9px 16px;font-size:15px;color:var(--ink);box-shadow:var(--shadow-sm);
  transition:transform .12s ease, border-color .12s ease;
}
.hud-btn:hover{border-color:rgba(35,42,69,.2)}
.hud-btn:active{transform:translateY(1px)}
.prompt{
  flex:1;display:flex;align-items:center;gap:10px;justify-content:center;
  background:var(--surface);border:1px solid var(--line);border-radius:999px;
  padding:7px 14px;min-width:240px;box-shadow:var(--shadow-sm);
}
#prompt-text{font-size:clamp(16px,2.4vw,22px);font-weight:600;text-align:center}
#prompt-text .target{font-family:var(--font-reading);color:var(--pink);text-transform:lowercase;font-weight:700;letter-spacing:.5px}
#prompt-text .pic{font-size:1.7em;line-height:1;vertical-align:-.18em;font-family:var(--emoji)}
.say,.peek{
  border-radius:50%;width:42px;height:42px;font-size:19px;flex:0 0 auto;color:#fff;
  background:var(--yellow);box-shadow:0 2px 8px rgba(240,180,41,.4);
  transition:transform .12s ease, box-shadow .12s ease;
}
.peek{background:var(--teal);box-shadow:0 2px 8px rgba(27,131,120,.4)}
.say:hover,.peek:hover{transform:translateY(-1px)}
.say:active,.peek:active{transform:translateY(1px);box-shadow:none}
.say{animation:pulse 2.8s ease-in-out infinite}
@keyframes pulse{0%,100%{transform:scale(1)}50%{transform:scale(1.05)}}
.hud-right{display:flex;gap:8px;align-items:center}
.progress,.starcount{
  background:var(--surface);border:1px solid var(--line);border-radius:999px;
  padding:8px 14px;font-size:14px;font-weight:600;color:var(--ink-soft);
}
.starcount{color:var(--gold)}
.progress:empty{display:none}   /* games against the clock have no round count */

/* ---------- Stage ---------- */
#stage{flex:1;position:relative;display:flex;align-items:center;justify-content:center;padding:14px;min-height:0}
#canvas{
  max-width:100%;max-height:100%;width:auto;height:auto;
  border-radius:16px;touch-action:none;display:block;background:#fff;
  box-shadow:0 0 0 1px var(--line), var(--shadow-lg);
}

.rotate-hint{display:none}
@media (orientation:portrait) and (max-width:760px){
  .rotate-hint{
    display:block;position:absolute;left:0;right:0;bottom:16px;margin:0;
    text-align:center;font-size:13px;color:var(--ink-soft);
  }
}

/* ---------- Results ---------- */
.results{
  position:absolute;inset:0;display:flex;align-items:center;justify-content:center;
  background:rgba(35,42,69,.45);backdrop-filter:blur(3px);
}
.results-card{
  position:relative;overflow:hidden;background:var(--surface);
  border-radius:24px;padding:32px 40px 28px;text-align:center;
  box-shadow:var(--shadow-lg);animation:pop .4s cubic-bezier(.2,1.3,.4,1);max-width:90vw;
}
/* a warm glow behind the stars: the moment should still feel like a reward. Rays were
   tried here and read as stray streaks once the rest of the card got quieter; the stars
   popping in carry it well enough on their own. */
.results-card::before{
  content:"";position:absolute;left:50%;top:78px;width:300px;height:170px;margin-left:-150px;
  background:radial-gradient(ellipse at center,rgba(240,180,41,.22),transparent 70%);
  pointer-events:none;
}
@keyframes pop{from{transform:scale(.8);opacity:0}to{transform:scale(1);opacity:1}}
.results-card > *{position:relative}
.results-card h2{
  margin:0 0 8px;font-family:var(--font-display);font-size:32px;font-weight:700;
  letter-spacing:-.4px;color:var(--ink);
}
.results-stars{font-size:42px;letter-spacing:4px;margin:6px 0;font-family:var(--emoji)}
.results-stars span{display:inline-block;opacity:0;animation:starpop .5s cubic-bezier(.2,1.6,.4,1) forwards}
.results-stars span.off{filter:grayscale(1);opacity:0;animation-name:starfade}
@keyframes starpop{from{transform:scale(0) rotate(-90deg);opacity:0}to{transform:scale(1) rotate(0);opacity:1}}
@keyframes starfade{from{opacity:0}to{opacity:.3}}
.results-card p{margin:6px 0 22px;color:var(--ink-soft);font-size:15px}
.results-btns{display:flex;gap:10px;justify-content:center;flex-wrap:wrap}
.big{
  background:var(--green);color:#fff;border-radius:999px;padding:13px 30px;
  font-size:17px;font-weight:600;box-shadow:0 3px 12px rgba(27,127,79,.35);
  transition:transform .12s ease, box-shadow .12s ease;
}
.big:hover{transform:translateY(-2px);box-shadow:0 6px 18px rgba(27,127,79,.4)}
.big:active{transform:translateY(1px);box-shadow:none}
.big.ghost{background:var(--surface);color:var(--ink);border:1px solid var(--line);box-shadow:var(--shadow-sm)}
.big.ghost:hover{box-shadow:var(--shadow-md)}

/* A 720p screen is wide enough for five columns but short on height, so the menu's
   header gives back what it can and the cards sit tighter. */
@media (min-width:900px) and (max-height:820px){
  #menu{padding:14px 20px 4px}
  .logo{font-size:clamp(26px,3.4vw,36px)}
  .tagline{margin:4px 0 12px;font-size:15px}
  .agebar{padding:7px 16px}
  .age{width:40px;height:40px;font-size:17px}
  .level-note{margin:12px 0 0}
  .cards{gap:12px;padding:12px 2px 14px}
  .card{padding:13px 14px;gap:3px}
  .card .icon{width:42px;height:42px;font-size:23px;border-radius:12px}
  .card .name{font-size:17px}
  /* two lines each, so one long blurb cannot make every card in its row tall */
  .card .blurb{
    font-size:13px;line-height:1.35;
    display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;
  }
  .grownups{padding:0 0 12px}
}

@media (max-width:560px){
  #menu{padding:18px 14px 8px}
  .prompt{order:3;width:100%;flex-basis:100%}
  /* the label takes its own line here, so the ages have the width to stay on one row */
  .agebar{border-radius:22px;padding:10px 12px;gap:8px;width:100%}
  .agebar-label{width:100%;text-align:center}
  .ages{gap:4px;width:100%;justify-content:space-between}
  .age{width:40px;height:40px;font-size:17px}
  .card{padding:15px}
  .card .icon{width:46px;height:46px;font-size:25px}
}
@media (prefers-reduced-motion:reduce){
  *,*::before,*::after{animation:none !important;transition:none !important}
  .results-stars span{opacity:1}
  .results-stars span.off{opacity:.3}
}
