/* styles.css — Butterfly Keys.
 *
 * A garden, drawn with CSS and SVG only. No web fonts (the CSP would block a
 * third-party one and vendoring a display face is not worth the bytes), so the
 * type is a system stack — but sized enormously, which matters far more to a
 * six-year-old than the typeface does.
 *
 * Three rules shape the whole sheet:
 *
 *   1. **The keyboard is the app.** It is sized from one unit, `--u`, derived
 *      from the width of its own container (with a viewport-height ceiling so a
 *      short laptop screen never needs scrolling). Every key is exactly `--u`
 *      square, so all thirty caps match no matter how many keys a row holds,
 *      and the board grows to fill a 1600px window instead of sitting in a
 *      1000px box. On a 1280x800 laptop a key lands around 88px.
 *   2. **Nothing red, nowhere.** The "nudge" state is a wiggle and the key's own
 *      hue. There is no cross, no stop colour and no failure styling anywhere.
 *   3. **Everything the child touches is huge.** No interactive target is under
 *      44px and most are two or three times that.
 */

:root {
  --bg: #f4fbf3;
  --bg2: #e6f5e4;
  --panel: #ffffff;
  --panel-soft: #fbfefa;
  --ink: #2c3a2a;
  --muted: #6b7d68;
  --line: #d6ead2;
  --accent: #7a5aa8;
  --accent-soft: #efe7fb;
  --ok: #2fae74;
  --warm: #f0913a;
  --star: #f5b93a;
  --grass: #b9e39a;
  --shadow: 0 2px 10px rgba(44, 58, 42, 0.09);
  --shadow-lift: 0 10px 26px rgba(44, 58, 42, 0.16);
  --radius: 18px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --garden-tint: #ffd166;

  /* the background scene, its own small palette */
  --sc-sky1: #cdeeff;
  --sc-sky2: #eefaf0;
  --sc-sun1: #ffe08a;
  --sc-sun2: rgba(255, 224, 138, 0.55);
  --sc-cloud: rgba(255, 255, 255, 0.86);
  --sc-hill1: #cdeeb4;
  --sc-hill2: #dcf3c9;
  --sc-grass: #b6e396;
  --sc-blade: #a4d886;
  --sc-tree1: #93cf74;
  --sc-tree2: #7cbe5e;
  --sc-trunk: #b98d5f;
  --sc-amber-body: #8a6fb0;
  --sc-amber-wing: rgba(190, 160, 232, 0.85);

  /* the hand diagrams */
  --hand-hi: #ffe9d4;
  --hand-lo: #f0cfae;

  /* key faces */
  --cap-hi: #ffffff;
  --cap-lo: #f1f7ef;
}

:root[data-theme="dark"] {
  --bg: #1b2320;
  --bg2: #223029;
  --panel: #26332c;
  --panel-soft: #2b3931;
  --ink: #eaf6e8;
  --muted: #9ab294;
  --line: #35473b;
  --accent: #c3a0e8;
  --accent-soft: #33294a;
  --ok: #58cf99;
  --warm: #f5ad63;
  --star: #ffc95c;
  --grass: #3c5c33;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  --shadow-lift: 0 12px 30px rgba(0, 0, 0, 0.45);

  --sc-sky1: #1d2f42;
  --sc-sky2: #1e2b25;
  --sc-sun1: #6f7fa8;
  --sc-sun2: rgba(111, 127, 168, 0.35);
  --sc-cloud: rgba(120, 140, 160, 0.24);
  --sc-hill1: #2c4430;
  --sc-hill2: #263a2c;
  --sc-grass: #2a4029;
  --sc-blade: #365234;
  --sc-tree1: #2f4a30;
  --sc-tree2: #263d28;
  --sc-trunk: #4b3a29;
  --sc-amber-body: #6b5a90;
  --sc-amber-wing: rgba(150, 130, 190, 0.6);

  --hand-hi: #4a4038;
  --hand-lo: #362f2a;

  --cap-hi: #33413a;
  --cap-lo: #2a3630;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.spacer { flex: 1; }

/* ---------- the background scene ---------- */

.scene-host {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.9;
}
:root[data-theme="dark"] .scene { opacity: 0.75; }

header, main, footer { position: relative; z-index: 1; }

/* The scene's colours live here, not in its SVG attributes. Each node carries a
 * literal light-theme colour as an attribute fallback and one of these classes;
 * a custom property inside an SVG presentation attribute is not something to
 * depend on, but `fill`/`stop-color` in a stylesheet resolves `var()` reliably
 * and lets the whole scene re-theme in one place. */
.sc-sky-a { stop-color: var(--sc-sky1); }
.sc-sky-b { stop-color: var(--sc-sky2); }
.sc-glow-a { stop-color: var(--sc-sun2); }
.sc-glow-b { stop-color: transparent; }
.sc-sun-fill { fill: var(--sc-sun1); }
.sc-cloud-fill { fill: var(--sc-cloud); }
.sc-hill1-fill { fill: var(--sc-hill1); }
.sc-hill2-fill { fill: var(--sc-hill2); }
.sc-tree1-fill { fill: var(--sc-tree1); }
.sc-tree2-fill { fill: var(--sc-tree2); }
.sc-trunk-fill { fill: var(--sc-trunk); }
.sc-grass-fill { fill: var(--sc-grass); }
.sc-blade { stroke: var(--sc-blade); }
.sc-amber-body-fill { fill: var(--sc-amber-body); }
.sc-amber-wing-fill { fill: var(--sc-amber-wing); }
.hand-stop-hi { stop-color: var(--hand-hi); }
.hand-stop-lo { stop-color: var(--hand-lo); }
.kb-pointer path { fill: var(--fc, currentColor); }

/* Slow ambient loops. Everything in the scene moves at a pace that reads as
 * "alive" in peripheral vision and never competes with the keyboard. */
.sc-rays { transform-origin: 1010px 108px; animation: scspin 120s linear infinite; }
@keyframes scspin { to { transform: rotate(360deg); } }
.sc-glow { animation: scbreathe 9s ease-in-out infinite; transform-origin: 1010px 108px; }
@keyframes scbreathe {
  0%, 100% { opacity: 0.75; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.06); }
}
.sc-cloud { animation: scdrift 90s linear infinite; }
.sc-cloud-b { animation-duration: 140s; animation-delay: -40s; }
.sc-cloud-c { animation-duration: 190s; animation-delay: -90s; }
@keyframes scdrift {
  0% { transform: translateX(-260px); }
  100% { transform: translateX(1460px); }
}
.sc-canopy { transform-origin: center bottom; animation: scsway 11s ease-in-out infinite; }
.sc-tree:nth-of-type(even) .sc-canopy { animation-duration: 14s; animation-delay: -3s; }
@keyframes scsway {
  0%, 100% { transform: rotate(-1.1deg); }
  50% { transform: rotate(1.1deg); }
}
.sc-blade { transform-origin: bottom center; animation: scblade 6s ease-in-out infinite; }
.sc-blade-1 { animation-duration: 7.5s; animation-delay: -1s; }
.sc-blade-2 { animation-duration: 5.4s; animation-delay: -2.5s; }
.sc-blade-3 { animation-duration: 8.6s; animation-delay: -3.5s; }
@keyframes scblade {
  0%, 100% { transform: skewX(-3deg); }
  50% { transform: skewX(3deg); }
}
.sc-amber { animation: scwander 46s linear infinite; }
@keyframes scwander {
  0% { transform: translate(-80px, 300px); }
  25% { transform: translate(340px, 232px); }
  50% { transform: translate(700px, 300px); }
  75% { transform: translate(1030px, 226px); }
  100% { transform: translate(1300px, 292px); }
}
.sc-amber-in { animation: scbob 3.4s ease-in-out infinite; }
@keyframes scbob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-14px); }
}
.sc-aw { transform-origin: center; animation: scflap 0.5s ease-in-out infinite; }
@keyframes scflap {
  0%, 100% { transform: scaleX(1); }
  50% { transform: scaleX(0.4); }
}

/* ---------- header ---------- */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.45rem 1rem;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.brand .mark { width: 34px; height: 34px; color: var(--accent); flex: none; }
.brand h1 { margin: 0; font-size: 1.18rem; letter-spacing: -0.3px; }
.tagline { margin: 0; font-size: 0.8rem; color: var(--muted); }

.session { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.tally {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.28rem 0.62rem 0.28rem 0.45rem;
  font-size: 1rem;
  box-shadow: var(--shadow);
}
.tally svg { width: 20px; height: 20px; }
.tally b { font-variant-numeric: tabular-nums; }
.tally.is-pop { animation: tallypop 640ms cubic-bezier(.2, 1.5, .4, 1); }
@keyframes tallypop {
  0%, 100% { transform: scale(1); }
  30% { transform: scale(1.22) rotate(-4deg); }
  60% { transform: scale(1.08) rotate(2deg); }
}

button { font-family: inherit; cursor: pointer; }

.ghost {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.45rem 0.7rem;
  font-size: 0.92rem;
}
.ghost:hover { border-color: var(--accent); }

.theme-toggle { min-width: 2.4rem; font-size: 1.05rem; line-height: 1; }

.big-icon {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 14px;
  width: 3rem;
  height: 2.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}
.big-icon svg { width: 26px; height: 26px; }
.big-icon.is-off { color: var(--muted); background: transparent; }
/* Third state: notes plus the quiet accompaniment. Tinted rather than
   re-shaped, so the button stays the same size in every state. */
.big-icon.is-music { color: var(--accent); border-color: var(--accent); }
.big-icon:hover { border-color: var(--accent); }

.home-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.35rem 0.5rem;
}
.home-link svg { width: 14px; height: 14px; }
.home-link:hover { color: var(--ink); border-color: var(--line); }

/* ---------- layout ---------- */

main { flex: 1; padding: 0 0.8rem 0.3rem; display: flex; flex-direction: column; }
.view { flex: 1; display: flex; flex-direction: column; gap: 0.4rem; min-height: 0; }

/* Views cross-fade instead of snapping. */
.view.is-in { animation: viewin 260ms ease both; }
@keyframes viewin {
  0% { opacity: 0; transform: translateY(10px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ---------- play: top strip ---------- */

.playtop {
  display: grid;
  grid-template-columns: minmax(110px, 172px) 1fr minmax(66px, 104px);
  align-items: center;
  gap: 0.6rem;
}

.pipbox { display: flex; flex-direction: column; align-items: center; }
.pip-host { width: 100%; max-width: 172px; }
.pip { width: 100%; height: auto; display: block; }
.pip-say {
  margin: -0.2rem 0 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 0.1rem 0.7rem;
  min-height: 1.6rem;
  box-shadow: var(--shadow);
}

.stage { min-width: 0; text-align: center; }
.stage-head {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.stage-head .chip { flex: 0 0 auto; }
.stage-head h2 {
  flex: 1 1 8ch;
  min-width: 0;
  margin: 0;
  font-size: clamp(1rem, 2.6vw, 1.45rem);
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  min-height: 2.5rem;
  box-shadow: var(--shadow);
}
.chip svg { width: 20px; height: 20px; }
.chip:hover { border-color: var(--accent); }

/* The second word on the level chip. It is what makes the chip read as a way
 * out of the level rather than as a label: "Level 4 | Levels". Present the whole
 * time a level is being played, so leaving is never more than one tap away. */
.chip-sub {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--accent);
  border-left: 2px solid var(--line);
  padding-left: 0.42rem;
  margin-left: 0.1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.scorebox { text-align: center; }
.scorelabel { margin: 0.1rem 0 0; font-size: 0.72rem; color: var(--muted); }

/* ---------- the target ---------- */

.target { margin: 0.1rem 0 0; }

.word {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0.12em;
  min-height: 1.15em;
  font-size: clamp(3rem, 11vw, 6.4rem);
  line-height: 1;
}
.word.is-word { font-size: clamp(1.9rem, 8vw, 4.3rem); }

.cell {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  color: var(--muted);
  opacity: 0.42;
  transition: opacity 140ms ease, color 140ms ease, transform 160ms ease;
}
/* On a word level only, and only over the letter she is on: the capital of that
 * one letter, so "this letter" and "that key" are unmistakably the same thing.
 * Sized in em of the target, so it tracks the big glyph at every width. */
.cell-upper {
  font-size: 0.32em;
  font-weight: 800;
  letter-spacing: 0.02em;
  opacity: 0.9;
  line-height: 1;
  min-height: 0.36em;
}
.cell-glyph { font-weight: 800; letter-spacing: -0.01em; }

.cell.is-done { color: var(--ok); opacity: 1; }
.cell.is-live {
  color: var(--fc, var(--accent));
  opacity: 1;
  transform: scale(1.06);
  animation: livepulse 1.5s ease-in-out infinite;
  text-shadow: 0 6px 18px color-mix(in srgb, var(--fc, var(--accent)) 34%, transparent);
}
@keyframes livepulse {
  0%, 100% { transform: scale(1.04); }
  50% { transform: scale(1.12); }
}

.cell.is-space { min-width: 1.1em; }
.spacebar-mark {
  display: block;
  width: 1em;
  height: 0.24em;
  border: 0.055em solid currentColor;
  border-top: none;
  border-radius: 0 0 0.1em 0.1em;
  margin-bottom: 0.18em;
}

/* The nudge: a wiggle, in the finger's own colour. Not a cross, not red. */
.cell.nudge { animation: wiggle 420ms ease; }
@keyframes wiggle {
  0%, 100% { transform: translateX(0) scale(1.06); }
  20% { transform: translateX(-0.07em) scale(1.1); }
  45% { transform: translateX(0.07em) scale(1.1); }
  70% { transform: translateX(-0.04em) scale(1.08); }
}

.steps {
  display: flex;
  justify-content: center;
  gap: 0.32rem;
  margin-top: 0.25rem;
  min-height: 0.8rem;
}
.stepdot {
  width: 0.58rem;
  height: 0.58rem;
  border-radius: 999px;
  background: var(--line);
  transition: background 160ms ease, transform 160ms ease;
}
.stepdot.is-done { background: var(--ok); }
.stepdot.is-live { background: var(--accent); transform: scale(1.35); }

/* ---------- free play ----------------------------------------------------
 *
 * A mode of the play screen, not a fourth view: the keyboard, the hands and Pip
 * all stay exactly where they are, and only the curriculum furniture — the
 * target, the step dots, the star row, the meadow and the progress strip — gives
 * way to the ribbon of recently typed characters.
 *
 * The ribbon is the whole feedback loop of the mode, so it gets the space the
 * target had: newest character on the right at full size, older ones settling
 * back, each in the colour of the finger that pressed it.
 */

.typed,
.freetools { display: none; }

.view.is-free .target,
.view.is-free .pathstrip,
.view.is-free .meadow,
.view.is-free .scorebox { display: none; }

.view.is-free .typed {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 0.1em 0.06em;
  min-height: 2.1em;
  font-size: clamp(1.5rem, 5.2vw, 3.1rem);
  line-height: 1;
  padding: 0.25em 0.3em;
  border-radius: 1rem;
  border: 2px dashed var(--line);
  background: color-mix(in srgb, var(--panel) 70%, transparent);
  outline: none;
}
.view.is-free .typed.is-empty { border-style: dashed; }

.view.is-free .freetools {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}
.freehint { max-width: 26ch; text-align: left; }

.tchar {
  display: inline-flex;
  align-items: flex-end;
  justify-content: center;
  min-width: 0.62em;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--fc, var(--muted));
  transition: opacity 200ms ease;
}
.tchar.is-space { min-width: 0.9em; }
/* The space bar's mark, sized off the ribbon's type like the target's is. */
.tbar {
  display: block;
  width: 0.72em;
  height: 0.2em;
  border: 0.05em solid currentColor;
  border-top: none;
  border-radius: 0 0 0.1em 0.1em;
  margin-bottom: 0.2em;
}
/* The newest character lands. It is the only motion in the ribbon: everything
 * else just shifts along, so the eye goes to what was just pressed. */
.tchar.is-new {
  animation: tland 260ms cubic-bezier(0.22, 1.2, 0.36, 1) both;
  text-shadow: 0 5px 16px color-mix(in srgb, var(--fc, var(--accent)) 34%, transparent);
}
@keyframes tland {
  0% { transform: translateY(-0.22em) scale(1.5); opacity: 0.2; }
  60% { transform: translateY(0) scale(1.16); opacity: 1; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

/* The free-play chip, lit while the mode is on. */
.chip-free.is-on {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, var(--panel));
  color: var(--accent);
}

/* A finger lit by a free-play press: the same guide the levels give, held for a
 * moment after the key rather than before it. */
.hand.is-lit { opacity: 1; }
.hand .finger.is-lit { opacity: 1; animation: fingerdip 420ms ease both; }
@keyframes fingerdip {
  0% { transform: translateY(0); }
  40% { transform: translateY(7px); }
  100% { transform: translateY(0); }
}

/* ---------- full screen typing -------------------------------------------
 *
 * A page of its own that covers everything. The key just pressed fills the
 * middle; the keys before it run along the bottom. Escape is the only key that
 * ends it, which is why the instruction sits at the top in plain words and the
 * on-screen "Esc" button repeats it for a tablet with no Escape key.
 */

.fullwrap {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 1rem clamp(0.6rem, 3vw, 2rem) 1.2rem;
  background:
    radial-gradient(120% 90% at 50% 0%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 70%),
    var(--bg);
  overflow: hidden;
}

.full-head {
  position: absolute;
  top: 0.7rem;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  flex-wrap: wrap;
  padding: 0 0.8rem;
}
.full-head h2 { margin: 0; font-size: 1.05rem; letter-spacing: -0.2px; }
.full-note { margin: 0; font-size: 0.92rem; color: var(--muted); }
.full-note kbd {
  font: inherit;
  font-weight: 800;
  color: var(--accent);
  border: 2px solid var(--line);
  border-bottom-width: 3px;
  border-radius: 0.4rem;
  padding: 0.05rem 0.4rem;
  background: var(--panel);
}

/* The key just pressed. */
.full-big {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 1.1em;
  font-size: clamp(3.4rem, 19vh, 11rem);
  line-height: 1;
}
.bigkey {
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--fc, var(--accent));
  text-shadow: 0 12px 40px color-mix(in srgb, var(--fc, var(--accent)) 30%, transparent);
  animation: bigland 220ms cubic-bezier(0.22, 1.2, 0.36, 1) both;
}
.bigkey.is-named,
.bigkey.is-space {
  font-size: 0.3em;
  color: var(--muted);
  text-transform: lowercase;
  letter-spacing: 0.02em;
  border: 0.06em solid var(--line);
  border-radius: 0.3em;
  padding: 0.12em 0.34em;
  text-shadow: none;
}
@keyframes bigland {
  0% { transform: scale(0.55); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.full-keyname {
  margin: 0;
  min-height: 1.5rem;
  font-size: clamp(0.95rem, 2.4vw, 1.3rem);
  font-weight: 700;
  color: var(--fc, var(--muted));
}

/* Everything typed so far, newest last — up to a thousand keys.
 *
 * A thousand keys do not fit at full size on any screen, so the type shrinks to
 * suit: `--tscale` is set by JS, which steps it down and re-measures until the
 * content stops overflowing this box. Measuring rather than counting is what
 * makes it right — a thousand narrow letters and fifty `page down` pills need
 * very different sizes, and only the browser knows how the lines actually
 * broke. The transition means the shrink is a settle, not a jolt.
 *
 * The gap tightens as the type shrinks because it is expressed in em, so a full
 * ribbon packs rather than keeping the airy spacing of a nearly empty one. */
.full-typed {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  align-content: flex-end;
  justify-content: center;
  gap: 0.14em 0.08em;
  width: min(100%, 74rem);
  max-height: 52vh;
  overflow: hidden;
  font-size: calc(clamp(1.1rem, 3.4vw, 2.1rem) * var(--tscale, 1));
  transition: font-size 140ms ease;
  line-height: 1;
  padding: 0.4em 0.5em;
  border-radius: 1rem;
  border: 2px dashed var(--line);
  background: color-mix(in srgb, var(--panel) 70%, transparent);
  outline: none;
}

.full-tools {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  flex-wrap: wrap;
}

/* A named key in either ribbon: a small pill, so "enter" cannot be mistaken for
 * five letters that were typed. */
.tchar.is-named {
  font-size: 0.42em;
  font-weight: 700;
  color: var(--muted);
  border: 0.09em solid var(--line);
  border-radius: 0.35em;
  padding: 0.16em 0.34em;
  margin-bottom: 0.12em;
  letter-spacing: 0.01em;
}

/* Nothing behind the overlay should scroll while it is open. */
body.is-full { overflow: hidden; }

/* Screen-reader-only text: the running commentary of what was just typed. It
 * must stay in the accessibility tree, so it is clipped rather than hidden. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.hint {
  margin: 0.1rem 0 0;
  font-size: clamp(0.95rem, 2.4vw, 1.22rem);
  font-weight: 700;
  color: var(--fc, var(--muted));
  min-height: 1.4rem;
}

/* ---------- the progress path (play screen strip) ---------- */

.pathstrip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.28rem;
  min-height: 0.9rem;
  margin: 0.05rem 0 0;
}
.path-node {
  width: 0.62rem;
  height: 0.62rem;
  border-radius: 999px;
  background: var(--line);
  border: 2px solid transparent;
  flex: none;
  transition: transform 200ms ease, background 200ms ease;
}
.path-node.is-done { background: var(--pc, var(--ok)); border-color: color-mix(in srgb, var(--pc, var(--ok)) 60%, var(--ink)); }
.path-node.is-open { background: transparent; border-color: var(--line); }
.path-node.is-locked { background: transparent; border-color: var(--line); opacity: 0.5; }
.path-node.is-current {
  width: 1rem;
  height: 1rem;
  background: var(--accent);
  border-color: var(--panel);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 40%, transparent);
  animation: pathhere 1.8s ease-in-out infinite;
}
.path-node.is-wordstep { border-radius: 4px; }
@keyframes pathhere {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.18); }
}
.path-sep {
  width: 0.5rem;
  height: 2px;
  border-radius: 2px;
  background: var(--line);
  flex: none;
}

/* ---------- stars ---------- */

.star-row, .lv-stars, .win-stars { display: inline-flex; gap: 0.2rem; justify-content: center; }
.star {
  width: 1.7rem;
  height: 1.7rem;
  display: inline-block;
  background: var(--line);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
.star.is-on { background: var(--star); }
.star.sm { width: 1.05rem; height: 1.05rem; }
.star.big { width: 3rem; height: 3rem; }
.star.big.is-on { animation: starpop 520ms cubic-bezier(.2, 1.5, .4, 1) both; animation-delay: var(--sd, 0ms); }
@keyframes starpop {
  0% { transform: scale(0) rotate(-40deg); }
  100% { transform: scale(1) rotate(0); }
}

/* ---------- meadow (the progress display) ---------- */

.meadow {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0.05rem;
  flex-wrap: wrap;
  min-height: 54px;
  padding: 0 0.2rem;
  /* The ground line takes the colour of the garden she is currently in, so
   * moving to a new garden visibly changes the world she is planting in. */
  border-bottom: 6px solid color-mix(in srgb, var(--garden-tint) 40%, var(--grass));
  border-radius: 0 0 10px 10px;
  transition: border-color 500ms ease;
}
.flower {
  width: clamp(19px, 2.5vw, 30px);
  height: auto;
  transform: translateY(var(--jit, 0)) rotate(var(--tilt, 0deg));
  flex: none;
}
.flower.is-new { animation: bloom 440ms cubic-bezier(.2, 1.5, .4, 1) both; }
@keyframes bloom {
  0% { transform: translateY(var(--jit, 0)) scale(0) rotate(-25deg); }
  100% { transform: translateY(var(--jit, 0)) scale(1) rotate(var(--tilt, 0deg)); }
}
.flower-head { transform-origin: 30px 30px; }
.flower.is-flying {
  animation: flyoff 1.5s ease-in both;
  animation-delay: var(--fdelay, 0ms);
}
@keyframes flyoff {
  0% { transform: translateY(var(--jit, 0)) scale(1); opacity: 1; }
  100% { transform: translateY(-260px) translateX(24px) scale(0.5) rotate(22deg); opacity: 0; }
}

/* ---------- the keyboard ----------------------------------------------
 *
 * One unit drives everything. `--u` is the side of a key square: the width the
 * container can give ten of them, capped so the board never dwarfs the screen,
 * and capped again against viewport height so a 720px-tall laptop does not have
 * to scroll to see the space bar. The floor keeps a narrow phone usable, and
 * `.kb-host` scrolls horizontally rather than letting the page do it.
 */

.kb-host {
  display: flex;
  justify-content: center;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.1rem 0 0.2rem;
}

.kb {
  /* fallback for engines without container queries */
  --gap: clamp(4px, 0.6vw, 9px);
  --u: max(40px, min(8.4vw, 104px, 11.6vh));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap);
  flex: none;
}

@supports (container-type: inline-size) {
  .kb-host { container-type: inline-size; }
  .kb {
    --gap: clamp(4px, 0.6cqw, 9px);
    --u: max(40px, min(calc((100cqw - 9 * var(--gap)) / 10), 104px, 11.6vh));
  }
}

.kb-row { display: flex; gap: var(--gap); justify-content: center; }
/* The stagger a real keyboard has, in key-units so it holds at every size. */
.kb-row-1 { padding-left: calc(var(--u) * 0.34); }
.kb-row-2 { padding-left: calc(var(--u) * 0.86); }
.kb-row-space {
  align-items: flex-end;
  gap: calc(var(--gap) * 2);
  margin-top: calc(var(--gap) * 0.5);
}

.kb-key {
  width: var(--u);
  height: var(--u);
  flex: none;
  padding: 0;
  background: none;
  border: 0;
  position: relative;
  color: color-mix(in srgb, var(--fc) 72%, var(--ink));
  -webkit-tap-highlight-color: transparent;
}

/* The cap is what moves. Keeping it separate from the button means the hit
 * area never shifts under a small finger mid-press. */
.kb-cap {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.06em;
  border: 2px solid color-mix(in srgb, var(--fc) 42%, var(--line));
  border-radius: calc(var(--u) * 0.2);
  background:
    linear-gradient(180deg, var(--cap-hi) 0%, var(--cap-lo) 100%),
    color-mix(in srgb, var(--fc) 10%, var(--panel));
  box-shadow:
    0 calc(var(--u) * 0.06) 0 color-mix(in srgb, var(--fc) 30%, var(--line)),
    0 calc(var(--u) * 0.09) calc(var(--u) * 0.14) rgba(44, 58, 42, 0.12);
  transition:
    transform 90ms cubic-bezier(.2, 1.4, .4, 1),
    box-shadow 90ms ease,
    background 160ms ease,
    border-color 160ms ease;
}
.kb-key:hover .kb-cap { border-color: color-mix(in srgb, var(--fc) 70%, var(--line)); }

/* One capital per cap. Sized in key-units, so it scales with the board and
 * never depends on the viewport font size: at 0.46u the widest glyph in the set
 * (M, W) occupies about 0.42u of a 1u cap, which leaves room on both sides at
 * every window width and at every browser zoom level. It is deliberately larger
 * than the old 0.42u lowercase letter, because dropping the small secondary
 * letter freed the vertical space. */
.kb-glyph {
  font-size: calc(var(--u) * 0.46);
  font-weight: 800;
  line-height: 1;
  display: block;
  text-transform: uppercase;
  transition: transform 110ms cubic-bezier(.2, 1.6, .4, 1);
}

/* Home-row anchors. The eight home keys carry a ridge; f and j — the two keys
 * with a physical bump on a real keyboard — carry a wider double ridge and a
 * heavier outline, so "put your pointing fingers here" is visible at a glance
 * from across the room. */
.kb-key.is-home .kb-cap::after {
  content: "";
  position: absolute;
  bottom: calc(var(--u) * 0.09);
  width: 28%;
  height: calc(var(--u) * 0.045);
  min-height: 3px;
  border-radius: 99px;
  background: currentColor;
  opacity: 0.42;
}
.kb-key.is-home .kb-cap {
  background:
    linear-gradient(180deg, var(--cap-hi) 0%, var(--cap-lo) 100%),
    color-mix(in srgb, var(--fc) 18%, var(--panel));
}
.kb-key.is-anchor .kb-cap {
  border-width: 3px;
  border-color: color-mix(in srgb, var(--fc) 66%, var(--line));
}
.kb-key.is-anchor .kb-cap::after {
  width: 46%;
  height: calc(var(--u) * 0.075);
  border-radius: 99px;
  background:
    linear-gradient(to bottom,
      currentColor 0 38%,
      transparent 38% 62%,
      currentColor 62% 100%);
  opacity: 0.5;
}

.kb-space {
  width: calc(var(--u) * 5 + var(--gap) * 4);
  height: calc(var(--u) * 0.62);
}
.kb-space .kb-cap { border-radius: calc(var(--u) * 0.16); }
.kb-space .kb-glyph {
  font-size: calc(var(--u) * 0.2);
  letter-spacing: 0.1em;
  /* The space bar is the one cap whose label is a word, not a letter, and
   * "space" reads better than "SPACE" for a new reader. */
  text-transform: lowercase;
  font-weight: 700;
}

/* The next key. Full colour, lifted, glowing, pulsing, with a finger pointing
 * at it. Four signals for the same thing, because one is missable. */
.kb-key.is-next { z-index: 3; }
.kb-key.is-next .kb-cap {
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--fc) 78%, #ffffff) 0%,
    var(--fc) 100%);
  border-color: color-mix(in srgb, var(--fc) 70%, #ffffff);
  color: #ffffff;
  animation: keypulse 1.15s ease-in-out infinite;
}
.kb-key.is-next { color: #ffffff; }
@keyframes keypulse {
  0%, 100% {
    transform: translateY(0) scale(1);
    box-shadow:
      0 calc(var(--u) * 0.07) 0 color-mix(in srgb, var(--fc) 60%, #000000),
      0 0 0 0 color-mix(in srgb, var(--fc) 45%, transparent);
  }
  50% {
    transform: translateY(calc(var(--u) * -0.06)) scale(1.07);
    box-shadow:
      0 calc(var(--u) * 0.1) 0 color-mix(in srgb, var(--fc) 60%, #000000),
      0 0 calc(var(--u) * 0.34) calc(var(--u) * 0.1) color-mix(in srgb, var(--fc) 42%, transparent);
  }
}

.kb-pointer {
  position: absolute;
  left: 50%;
  bottom: calc(100% + var(--u) * 0.08);
  width: calc(var(--u) * 0.42);
  height: auto;
  margin-left: calc(var(--u) * -0.21);
  pointer-events: none;
  filter: drop-shadow(0 3px 6px rgba(44, 58, 42, 0.28));
  animation: pointbob 1.15s ease-in-out infinite;
}
@keyframes pointbob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(calc(var(--u) * 0.12)); }
}

/* The press. Physical, and identical whether it came from the real keyboard or
 * from a tap: the cap sinks into its own shadow and springs back. */
.kb-key.is-down .kb-cap {
  transform: translateY(calc(var(--u) * 0.055)) scale(0.97);
  box-shadow: 0 1px 0 color-mix(in srgb, var(--fc) 30%, var(--line));
}

/* A correct key: the letter pops and the cap flashes into its own hue. */
.kb-key.flash-hit .kb-cap { animation: hitcap 320ms cubic-bezier(.2, 1.5, .4, 1); }
.kb-key.flash-hit .kb-glyph { animation: hitletter 320ms cubic-bezier(.2, 1.9, .35, 1); }
@keyframes hitcap {
  0% { transform: translateY(calc(var(--u) * 0.06)) scale(0.95); }
  40% {
    transform: translateY(calc(var(--u) * -0.04)) scale(1.06);
    background: linear-gradient(180deg,
      color-mix(in srgb, var(--ok) 46%, #ffffff) 0%,
      color-mix(in srgb, var(--ok) 70%, #ffffff) 100%);
  }
  100% { transform: translateY(0) scale(1); }
}
@keyframes hitletter {
  0% { transform: scale(0.86); }
  45% { transform: scale(1.38); }
  100% { transform: scale(1); }
}

/* A wrong key: a soft wobble. No red, no cross, no shake hard enough to feel
 * like a buzzer. */
.kb-key.flash-miss .kb-cap { animation: misswobble 480ms ease; }
@keyframes misswobble {
  0%, 100% { transform: translateX(0) rotate(0); }
  18% { transform: translateX(-4px) rotate(-2.4deg); }
  42% { transform: translateX(4px) rotate(2.4deg); }
  66% { transform: translateX(-2.5px) rotate(-1.2deg); }
  86% { transform: translateX(1.5px) rotate(0.6deg); }
}

/* hands — they flank the space bar, so the finger guide sits with the keys */
.hand {
  width: calc(var(--u) * 1.35);
  max-width: 130px;
  height: auto;
  opacity: 0.55;
  transition: opacity 180ms ease;
  flex: none;
}
.hand.is-active { opacity: 1; }
.hand .palm { opacity: 0.9; }
.hand .finger { opacity: 0.32; transition: opacity 180ms ease, transform 180ms ease; }
.hand.is-active .finger { opacity: 0.5; }
.hand .finger.is-next { opacity: 1; animation: fingerpoke 1.15s ease-in-out infinite; }
@keyframes fingerpoke {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(6px); }
}

@media (max-width: 700px) {
  .hand { display: none; }
  .kb-space { width: calc(var(--u) * 6 + var(--gap) * 5); }
}

/* ---------- Pip ---------- */

.pip-body { transform-origin: 110px 140px; animation: pipbreathe 3.4s ease-in-out infinite; }
@keyframes pipbreathe {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-3px) scale(1.015); }
}
.pip-shadow { animation: pipshadow 3.4s ease-in-out infinite; transform-origin: 112px 160px; }
@keyframes pipshadow {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.94); opacity: 0.82; }
}
.pip-lid { transform-origin: center top; transform: scaleY(0); animation: pipblink 5.2s ease-in-out infinite; }
@keyframes pipblink {
  0%, 92%, 100% { transform: scaleY(0); }
  95%, 97% { transform: scaleY(1); }
}
.pip-ant-tip-l { animation: antbob 2.6s ease-in-out infinite; }
.pip-ant-tip-r { animation: antbob 2.6s ease-in-out infinite 0.4s; }
@keyframes antbob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}
.pip-sparks { opacity: 0; }
.pip-spark { transform-origin: center; }

.pip.is-happy .pip-body { animation: piphop 400ms cubic-bezier(.2, 1.6, .4, 1); }
@keyframes piphop {
  0%, 100% { transform: translateY(0) scale(1); }
  40% { transform: translateY(-16px) scale(1.05); }
}
.pip.is-happy .pip-mouth { d: path("M145 111 q11 11 22 0"); }

.pip.is-oops .pip-head { animation: piptilt 660ms ease; transform-origin: 156px 118px; }
@keyframes piptilt {
  0%, 100% { transform: rotate(0); }
  30% { transform: rotate(-11deg); }
  65% { transform: rotate(5deg); }
}
.pip.is-oops .pip-lid { animation: none; transform: scaleY(0.42); }

.pip.is-cheer .pip-body { animation: pipcheer 2.3s ease-in-out; }
@keyframes pipcheer {
  0%, 100% { transform: translateY(0) rotate(0) scale(1); }
  12% { transform: translateY(-22px) rotate(-6deg) scale(1.07); }
  30% { transform: translateY(0) rotate(3deg) scale(1); }
  48% { transform: translateY(-20px) rotate(6deg) scale(1.07); }
  66% { transform: translateY(0) rotate(-3deg) scale(1); }
  82% { transform: translateY(-12px) scale(1.04); }
}
.pip.is-cheer .pip-cheek { opacity: 1; }
.pip.is-cheer .pip-sparks { animation: sparkshow 2.3s ease-in-out; }
@keyframes sparkshow {
  0%, 100% { opacity: 0; }
  20%, 80% { opacity: 1; }
}
.pip.is-cheer .pip-spark-0 { animation: sparkspin 1.1s ease-in-out infinite; }
.pip.is-cheer .pip-spark-1 { animation: sparkspin 1.4s ease-in-out infinite 0.2s; }
.pip.is-cheer .pip-spark-2 { animation: sparkspin 1.25s ease-in-out infinite 0.45s; }
@keyframes sparkspin {
  0%, 100% { transform: scale(0.6) rotate(0); }
  50% { transform: scale(1.15) rotate(90deg); }
}

/* ---------- level map (the big path) ---------- */

.subhead {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.2rem 0;
}
.subhead h2 { margin: 0; font-size: 1.35rem; }

.level-grid { display: flex; flex-direction: column; gap: 0.7rem; padding-bottom: 1rem; }
.garden-band {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 6px solid var(--pc, var(--line));
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem 0.8rem;
  box-shadow: var(--shadow);
}
.garden-band h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.band-dot {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 999px;
  background: var(--pc, var(--line));
  border: 2px solid color-mix(in srgb, var(--pc, var(--line)) 55%, var(--ink));
  flex: none;
}

/* The band row is the path: cards in order, joined by a dashed trail. */
.band-row {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
  position: relative;
  /* headroom for the "here" badge, which sits above the card's top edge */
  padding-top: 0.7rem;
}
.band-row::before {
  content: "";
  position: absolute;
  left: 1.4rem;
  right: 1.4rem;
  top: 2.3rem;
  border-top: 3px dashed color-mix(in srgb, var(--pc, var(--line)) 55%, transparent);
  z-index: 0;
}

.levelcard {
  flex: 1 1 8.5rem;
  min-width: 8.5rem;
  min-height: 7.4rem;
  background: var(--panel-soft);
  border: 2px solid var(--line);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  padding: 0.5rem;
  position: relative;
  z-index: 1;
  color: var(--ink);
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}
.levelcard:hover:not(:disabled) {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: var(--shadow-lift);
}
.levelcard.is-done {
  background: color-mix(in srgb, var(--ok) 10%, var(--panel-soft));
  border-color: color-mix(in srgb, var(--ok) 45%, var(--line));
}
.levelcard.is-current {
  border-color: var(--accent);
  border-width: 3px;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 26%, transparent), var(--shadow);
}
/* Both at once: a finished level she is replaying keeps its green "done" wash
 * and also wears the "you are here" ring. */
.levelcard.is-done.is-current {
  background: color-mix(in srgb, var(--ok) 10%, var(--panel-soft));
}
/* The strip node for the level she is on shows a finished level's colour in the
 * middle of the "you are here" ring, rather than hiding that it was completed. */
.path-node.is-current.is-finished { background: var(--ok); }
.levelcard.is-locked { opacity: 0.5; cursor: not-allowed; }
.lv-num { font-size: 1.5rem; font-weight: 800; color: var(--accent); line-height: 1; }
.lv-name { font-size: 0.92rem; font-weight: 600; text-align: center; }

/* A note above the grid, for the grown-up reading over her shoulder. */
.levels-note {
  margin: 0 0 0.8rem;
  max-width: 46rem;
  font-size: 0.92rem;
  color: var(--muted);
}

/* The per-card state, as an icon AND a word. Four distinguishable states, none
 * of them carried by colour alone: the icon shape and the text both change, so
 * the card still reads correctly in greyscale. */
.lv-state {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--muted);
  text-align: center;
}
.lv-icon { width: 0.95rem; height: 0.95rem; flex: none; }
.levelcard.state-open .lv-state { color: var(--accent); }
.levelcard.state-done .lv-state { color: var(--ok); }
.levelcard.state-full .lv-state { color: var(--star); }

/* "you are here", spelled out, so the ring around the current card is not the
 * only thing saying it. */
.lv-here {
  position: absolute;
  top: -0.6rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #ffffff;
  font-size: 0.64rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.1rem 0.42rem;
  border-radius: 999px;
  white-space: nowrap;
}
.lv-bfly { position: absolute; top: 4px; right: 5px; width: 2.1rem; height: auto; opacity: 0.95; }
.lv-bud {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 15px;
  height: 19px;
  border-radius: 50% 50% 45% 45% / 60% 60% 40% 40%;
  background: var(--grass);
}

/* ---------- garden (collection) ---------- */

.garden-line { margin: 0.1rem 0 0.5rem; font-size: 1rem; color: var(--muted); }
.garden-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(6.4rem, 1fr));
  gap: 0.6rem;
}
.gcell {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 0.5rem 0.3rem 0.35rem;
  text-align: center;
  min-height: 6.6rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: transform 200ms ease, box-shadow 200ms ease;
}
.gcell.is-empty { background: transparent; border-style: dashed; box-shadow: none; }
.gcell .bfly { width: 78%; max-width: 5.4rem; height: auto; }
.gname { margin: 0.15rem 0 0; font-size: 0.85rem; font-weight: 700; }
.gcell.is-arriving .bfly { opacity: 0; }
.gcell.is-landed {
  animation: landcell 900ms cubic-bezier(.2, 1.4, .4, 1);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--star) 45%, transparent), var(--shadow);
}
@keyframes landcell {
  0% { transform: scale(1); }
  35% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
.cocoon {
  width: 1.8rem;
  height: 2.6rem;
  border-radius: 50% 50% 45% 45% / 42% 42% 58% 58%;
  background: linear-gradient(160deg, var(--line), color-mix(in srgb, var(--grass) 60%, var(--line)));
  box-shadow: inset -3px -4px 8px rgba(0, 0, 0, 0.08);
}

.bfly .bw { transform-origin: 60px 55px; }
.bfly.is-resting .bw-l { animation: flapL 3.6s ease-in-out infinite; }
.bfly.is-resting .bw-r { animation: flapR 3.6s ease-in-out infinite; }
.bfly.is-hatching { animation: hatchin 1.5s cubic-bezier(.2, 1.3, .35, 1) both; }
.bfly.is-hatching .bw-l { animation: flapL 0.5s ease-in-out infinite; }
.bfly.is-hatching .bw-r { animation: flapR 0.5s ease-in-out infinite; }
.bfly.is-mini .bw-l { animation: flapL 4.4s ease-in-out infinite; }
.bfly.is-mini .bw-r { animation: flapR 4.4s ease-in-out infinite; }
@keyframes flapL {
  0%, 100% { transform: scaleX(1); }
  50% { transform: scaleX(0.66); }
}
@keyframes flapR {
  0%, 100% { transform: scaleX(1); }
  50% { transform: scaleX(0.66); }
}
@keyframes hatchin {
  0% { transform: scale(0.1) translateY(30px); opacity: 0; }
  60% { opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.grown-ups {
  margin-top: 1.2rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.8rem 1rem 1rem;
  box-shadow: var(--shadow);
}
.grown-ups h3 { margin: 0 0 0.3rem; font-size: 0.95rem; }
.grown-ups p { margin: 0 0 0.6rem; }
.nickrow { display: flex; align-items: center; gap: 0.55rem; flex-wrap: wrap; margin-top: 0.7rem; }
.klabel { font-size: 0.85rem; color: var(--muted); }
.nickrow input {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  max-width: 11rem;
}
.danger {
  background: var(--warm);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 0.5rem 0.8rem;
  font-size: 0.92rem;
}

/* ---------- the grown-ups panel ---------- */

.grownwrap { align-items: flex-start; overflow-y: auto; padding: 1.2rem 1rem 2rem; }
.growncard {
  position: relative;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 22px;
  padding: 1rem 1.2rem 1.2rem;
  max-width: 34rem;
  width: 100%;
  margin: auto;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  animation: cardin 300ms cubic-bezier(.2, 1.3, .4, 1) both;
}
.grown-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.growncard h2 { margin: 0; font-size: 1.3rem; color: var(--accent); }
.grown-sec { margin-top: 1.1rem; border-top: 1px solid var(--line); padding-top: 0.8rem; }
.grown-sec:first-of-type { border-top: 0; }
.grown-sec h3 { margin: 0 0 0.4rem; font-size: 1rem; }
.grown-sec p { margin: 0 0 0.6rem; line-height: 1.45; }
.sess-state { font-weight: 700; font-size: 1.02rem; }
.sess-state.is-user { color: var(--ok); }
.sess-state.is-guest { color: var(--accent); }
.sess-state.is-local, .sess-state.is-unknown { color: var(--muted); }
.confirm-box {
  margin-top: 0.7rem;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line));
  border-radius: 14px;
  padding: 0.7rem 0.8rem;
}
.confirm-box p { margin: 0; }

/* ---------- win card ---------- */

.winwrap {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--ink) 44%, transparent);
  padding: 1rem;
  backdrop-filter: blur(2px);
}
.petal-host { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.petal {
  position: absolute;
  top: -8%;
  left: var(--px, 50%);
  width: var(--pw, 14px);
  height: var(--pw, 14px);
  background: var(--pc, #ffd166);
  border-radius: 60% 40% 55% 45%;
  animation: petalfall var(--pt, 2200ms) linear var(--pd, 0ms) forwards;
  transform: rotate(var(--pr, 0deg));
}
@keyframes petalfall {
  0% { transform: translateY(0) rotate(var(--pr, 0deg)); opacity: 1; }
  100% { transform: translateY(112vh) rotate(calc(var(--pr, 0deg) + 540deg)); opacity: 0.9; }
}

/* Confetti bursts out of the middle of the card, which reads as a "pop"
 * rather than as weather. */
.confetti {
  position: absolute;
  left: 50%;
  top: 46%;
  width: 11px;
  height: 15px;
  background: var(--cc, #ffd166);
  border-radius: 2px;
  opacity: 0;
  animation: confpop 1500ms cubic-bezier(.15, .7, .3, 1) var(--cd, 0ms) forwards;
}
.confetti.is-round { border-radius: 999px; width: 10px; height: 10px; }
@keyframes confpop {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  /* the peak of the arc — up and out */
  45% {
    transform: translate(calc(var(--cx, 0px) * 0.8), var(--cy, 0px)) rotate(calc(var(--cr, 180deg) * 0.5));
    opacity: 1;
  }
  75% { opacity: 1; }
  /* then gravity takes it down past the bottom */
  100% {
    transform: translate(var(--cx, 0px), calc(var(--cy, 0px) + 46vh)) rotate(var(--cr, 180deg));
    opacity: 0;
  }
}

.wincard {
  position: relative;
  background: var(--panel);
  border: 3px solid var(--accent);
  border-radius: 26px;
  padding: 1.2rem 1.6rem 1.4rem;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
  max-width: 27rem;
  width: 100%;
  animation: cardin 380ms cubic-bezier(.2, 1.4, .4, 1) both;
}
@keyframes cardin {
  0% { transform: scale(0.82) translateY(20px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}
.wincard h2 { margin: 0 0 0.6rem; font-size: 1.7rem; color: var(--accent); }
.win-bfly { margin: 0.4rem 0 0; }
.win-bfly .bfly { width: 9.5rem; height: auto; }
.bfly-name { margin: 0.1rem 0 0; font-size: 1.15rem; font-weight: 800; }
.win-line { margin: 0.4rem 0 0.9rem; font-size: 1.05rem; color: var(--muted); }
.win-actions { display: flex; gap: 0.55rem; justify-content: center; flex-wrap: wrap; }

.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 0.6rem 1rem;
  font-size: 1rem;
  font-weight: 700;
}
.primary:hover { filter: brightness(1.08); }
.primary:disabled { opacity: 0.6; cursor: default; }
.big { min-height: 3.1rem; min-width: 5.5rem; font-size: 1.15rem; }

/* ---------- the collectible's flight ---------- */

.fly-layer { position: fixed; inset: 0; z-index: 60; pointer-events: none; }
.fly-box { position: fixed; }
.fly-box svg { width: 100%; height: 100%; display: block; }
.fly-box.is-flying {
  transition: transform 1050ms cubic-bezier(.32, .06, .3, 1), opacity 1050ms ease;
}

/* ---------- footer ---------- */

footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.55rem 1rem 0.9rem;
  font-size: 0.85rem;
  color: var(--muted);
}
footer a { color: var(--accent); }
.foot-sep { color: var(--line); }
.foot-btn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent);
  font-size: 0.82rem;
  padding: 0.2rem 0.7rem;
}
.foot-btn:hover { border-color: var(--accent); background: var(--panel); }

/* ---------- motion preference ----------------------------------------
 *
 * A calmer variant, not a dead one. The ambient scene stops, the confetti and
 * the flights are skipped in JS, and the long loops are switched off — but the
 * teaching signals stay: the next key is still unmistakable (a static ring and
 * full colour instead of a pulse), the press still depresses, and state changes
 * still fade so nothing snaps.
 */

@media (prefers-reduced-motion: reduce) {
  .sc-rays, .sc-glow, .sc-cloud, .sc-canopy, .sc-blade, .sc-amber, .sc-amber-in, .sc-aw,
  .pip-body, .pip-shadow, .pip-lid, .pip-ant-tip-l, .pip-ant-tip-r, .pip-sparks, .pip-spark,
  .bfly.is-resting .bw-l, .bfly.is-resting .bw-r,
  .bfly.is-mini .bw-l, .bfly.is-mini .bw-r,
  .bfly.is-hatching .bw-l, .bfly.is-hatching .bw-r,
  .path-node.is-current, .cell.is-live, .kb-pointer,
  .tchar.is-new, .hand .finger.is-lit, .bigkey,
  .hand .finger.is-next, .flower.is-new, .flower.is-flying,
  .star.big.is-on, .wincard, .growncard, .view.is-in, .tally.is-pop,
  .gcell.is-landed, .bfly.is-hatching {
    animation: none !important;
  }
  .pip-lid { transform: scaleY(0); }
  .cell.is-live { transform: scale(1.06); }

  /* The newest typed character must still be obvious without landing: it stays
   * bigger than its neighbours and carries a soft underline instead. */
  .tchar.is-new {
    transform: scale(1.14);
    border-bottom: 0.07em solid currentColor;
  }
  .hand .finger.is-lit { transform: translateY(4px); }
  /* The ribbon still shrinks to fit — it just does it instantly. */
  .full-typed { transition: none !important; }

  /* The next key must stay unmissable without pulsing: full colour, a thick
   * static ring, and the pointer held still above it. */
  .kb-key.is-next .kb-cap {
    animation: none !important;
    transform: translateY(calc(var(--u) * -0.04));
    box-shadow:
      0 0 0 4px color-mix(in srgb, var(--fc) 55%, transparent),
      0 calc(var(--u) * 0.08) 0 color-mix(in srgb, var(--fc) 60%, #000000);
  }
  .kb-pointer { transform: translateY(0); }

  .kb-key.flash-hit .kb-cap, .kb-key.flash-hit .kb-glyph,
  .kb-key.flash-miss .kb-cap, .cell.nudge {
    animation-duration: 200ms !important;
  }
  .view.is-in { animation: viewfade 200ms ease both !important; }
  @keyframes viewfade { from { opacity: 0; } to { opacity: 1; } }
}
