/* Sopo: Ice Mosaic - ice workshop skin over the shared wondermaths.app tokens. */
:root {
  --world-ice-1: #eaf8ff;
  --world-ice-2: #bfe6f7;
  --world-ice-3: #8fd0ea;
  --world-warm-1: #ffe9c9;
  --world-warm-2: #f0cf9c;
  --world-deep: #17324d;
  --panel-pad: clamp(12px, 1.6vmin, 26px);
  --tile-gap: clamp(6px, 1.4vmin, 12px);
}

* { box-sizing: border-box; }

/* Author display rules must never beat the hidden attribute. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  /* Fallback behind the illustrated workshop: a cool ice wash, never a broad
     flat brown, if the world picture is missing or still arriving. */
  background: radial-gradient(120% 90% at 50% 16%, #e6f4fd, #9fd2ec 54%, #5f9cc4);
  color: var(--wm-ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }

.shell { position: fixed; inset: 0; overflow: hidden; display: block; }

.world, .world img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 42%;
}

.screen { position: absolute; inset: 0; }

.image-button {
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  display: block;
  touch-action: manipulation;
  filter: drop-shadow(0 3px 2px rgb(70 48 30 / 0.35));
}
.image-button img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.image-button:active { transform: translateY(2px) scale(0.96); }
.image-button:focus-visible,
.wood-button:focus-visible,
.card:focus-visible,
.socket:focus-visible,
.divider:focus-visible {
  outline: none;
  box-shadow: var(--wm-focus-ring);
}

/* ---------- intro ---------- */
.intro { display: grid; place-items: center; overflow: hidden; }
.intro-art, .intro-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.intro-copy {
  position: absolute;
  left: 50%;
  top: max(5vh, 18px);
  transform: translateX(-50%);
  text-align: center;
  padding: 10px 26px;
  border-radius: var(--wm-radius-panel);
  background: rgb(255 248 230 / 0.86);
  box-shadow: var(--wm-shadow-card);
  width: max-content;
  max-width: min(92vw, 640px);
}
.intro-brand { margin: 0; font-size: clamp(11px, 1.5vmin, 15px); letter-spacing: .16em; text-transform: lowercase; opacity: .78; }
.intro h1 { margin: .1em 0 0; font-size: clamp(26px, 5.2vmin, 58px); color: var(--world-deep); }
.play-button {
  position: absolute;
  left: 50%;
  bottom: max(4vh, 16px);
  transform: translateX(-50%);
  width: clamp(96px, 17vmin, 168px);
  height: clamp(96px, 17vmin, 168px);
}
.play-button:active { transform: translateX(-50%) translateY(3px) scale(.96); }
.intro-status {
  position: absolute;
  left: 50%;
  bottom: calc(max(4vh, 16px) + clamp(96px, 17vmin, 168px) + 12px);
  transform: translateX(-50%);
  margin: 0;
  padding: 8px 20px;
  max-width: min(92vw, 520px);
  border-radius: 999px;
  background: rgb(255 248 230 / .94);
  box-shadow: var(--wm-shadow-card);
  color: var(--world-deep);
  font-size: clamp(13px, 2vmin, 20px);
  font-weight: 700;
  text-align: center;
}
.intro-status:empty { display: none; }

/* ---------- gameplay shell ---------- */
.game { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: clamp(4px, 1vmin, 12px); padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }

.hud { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: clamp(6px, 1.4vmin, 18px); }
.controls { grid-column: 3; grid-row: 1; justify-self: end; display: flex; flex-flow: row nowrap; gap: clamp(4px, .9vmin, 10px); }
.control {
  position: relative;
  flex: 0 0 auto;
  width: clamp(56px, 6.4vmin, 68px);
  height: clamp(56px, 6.4vmin, 68px);
  min-width: 56px;
  min-height: 56px;
  border-radius: 50%;
}
/* The help control is a real carved wooden button in assets/ui/, exactly like
   pause and home: no CSS circle, no font glyph, same drop-shadow family. */
.help-control { display: block; }
/* Pause is meaningless on a reward or the finale; the rest of the header stays
   usable because those two overlays are non-modal (see game.js). Raising the
   header above them keeps Home, Sound, Restart and Help clickable. */
.control:disabled { opacity: .45; cursor: default; }
.control:disabled:active { transform: none; }
.shell[data-state="level-complete"] .hud,
.shell[data-state="game-complete"] .hud { position: relative; z-index: 310; }
/* Keep the reward/finale card clear of the still-live header. */
.shell[data-state="level-complete"] .overlay,
.shell[data-state="game-complete"] .overlay { padding-top: clamp(72px, 12vh, 120px); }

/* Progress and level path sit on the same honey-wood workshop plaque (one
   shared WebP), so no bare text and no grey glass floats over the busy scene. */
.hud-progress {
  grid-column: 1; grid-row: 1;
  display: flex; flex-direction: column; justify-content: center; align-items: flex-start;
  gap: 3px; min-width: 0;
  width: clamp(126px, 14.5vw, 190px); min-height: clamp(58px, 9vh, 76px);
  padding: 8px clamp(12px, 1.5vmin, 20px);
  background: url("assets/ui/hud-workshop-plaque.webp") center / 100% 100% no-repeat;
  filter: drop-shadow(0 4px 6px rgb(60 40 20 / .38));
}
.hud-label { margin: 0; max-width: 100%; font-size: clamp(12px, 1.65vmin, 17px); font-weight: 700; color: #fff8e6; text-shadow: 0 2px 3px rgb(52 30 12 / .85); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.round-track { display: flex; gap: clamp(3px, .7vmin, 7px); }
.round-star { width: clamp(24px, 3.8vmin, 30px); height: clamp(24px, 3.8vmin, 30px); background: center/contain no-repeat url("assets/ui/ui-reward-star-empty.webp"); filter: drop-shadow(0 1px 2px rgb(52 30 12 / .55)); }
.round-star.earned { background-image: url("assets/ui/ui-reward-star.webp"); }
.round-star.landing { animation: star-land 700ms ease-out; }
@keyframes star-land { from { transform: scale(.4) rotate(-25deg); } 60% { transform: scale(1.22); } to { transform: scale(1); } }

.level-path {
  grid-column: 2; grid-row: 1;
  display: flex; align-items: center; justify-content: center; gap: clamp(4px, .9vmin, 9px);
  width: clamp(200px, 20vw, 280px); min-height: clamp(54px, 8.5vh, 68px);
  padding: 6px clamp(10px, 1.3vmin, 16px);
  background: url("assets/ui/hud-workshop-plaque.webp") center / 100% 100% no-repeat;
  filter: drop-shadow(0 4px 6px rgb(60 40 20 / .38));
}
.level-token {
  width: clamp(32px, 4.6vmin, 44px);
  height: clamp(32px, 4.6vmin, 44px);
  min-width: 32px;
  border-radius: 50%;
  /* Warm honey wood with the real grain of the shared plaque - never grey glass. */
  border: 2px solid #e0b071;
  background-color: #b9793f;
  background-image: url("assets/ui/hud-workshop-plaque.webp");
  background-size: 260% 260%;
  background-position: center;
  color: #35200d;
  text-shadow: 0 1px 0 rgb(255 236 201 / .5);
  box-shadow: inset 0 0 0 2px rgb(255 236 201 / .30), inset 0 -3px 6px rgb(90 55 24 / .35), 0 2px 0 rgb(110 66 30 / .75);
  font-size: clamp(13px, 1.8vmin, 19px);
  font-weight: 700;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
}
.level-token[disabled] { opacity: .6; cursor: default; }
.level-token.complete { border-color: var(--wm-gold); background-color: #c98f5a; color: #4a2f14; box-shadow: inset 0 0 0 2px rgb(242 193 65 / .55), 0 2px 0 rgb(110 66 30 / .75); }
.level-token.active { border-color: #fff3d4; background-color: #e2ab68; color: #2a1808; transform: scale(1.12); box-shadow: inset 0 0 0 2px rgb(255 236 201 / .6), 0 0 0 3px rgb(242 193 65 / .85), 0 3px 7px rgb(60 40 20 / .5); }

/* ---------- stage ---------- */
.stage { display: grid; grid-template-columns: minmax(190px, 24%) minmax(0, 1fr) minmax(175px, 21%); align-items: stretch; gap: clamp(6px, 1.4vmin, 20px); min-height: 0; }

.guide { display: flex; flex-direction: column; justify-content: flex-end; gap: 6px; min-height: 0; }
/* Large enough to read as characters and to sit beside the tray instead of
   leaving a wide empty column (roughly 280-340px of visible art on desktop). */
.guide-art { width: clamp(200px, 36vmin, 340px); max-width: 100%; height: auto; align-self: flex-start; max-height: 80%; object-fit: contain; filter: drop-shadow(0 10px 12px rgb(23 50 77 / .4)); }
.char-loop { display: block; background: none; }
.speech {
  position: relative;
  margin: 0;
  padding: clamp(8px, 1.4vmin, 16px) clamp(10px, 1.6vmin, 18px);
  border-radius: 20px 22px 24px 8px;
  border: 3px solid rgb(255 255 255 / .8);
  background: linear-gradient(160deg, #fffdf6, var(--wm-cream-2));
  box-shadow: var(--wm-shadow-card);
  font-size: clamp(13px, 1.9vmin, 21px);
  font-weight: 700;
  color: var(--world-deep);
  max-width: 100%;
}
.speech::before {
  content: "";
  position: absolute;
  left: 12px;
  top: -14px;
  width: 26px;
  height: 20px;
  background: #fffdf6;
  clip-path: polygon(12% 100%, 88% 100%, 46% 0%);
}
.guide.talking .guide-art { animation: ori-nod 900ms ease-in-out; }
@keyframes ori-nod { 50% { transform: translateY(-6px) rotate(-2deg); } }

.board-area { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: clamp(4px, 1vmin, 10px); min-height: 0; min-width: 0; }
/* The right-hand padding is the grip column: the split handle lives there,
   outside the tiles, and layoutBoard() reserves the same width for it. */
.board-shell { position: relative; display: grid; place-items: center; flex: 1 1 auto; min-height: 0; min-width: 0; width: 100%; padding-right: 48px; }

.board {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  gap: var(--tile-gap);
  padding: clamp(6px, 1.2vmin, 16px);
  /* Opaque deep ice-blue tray. The snow scene behind it is bright and busy, so
     white snowballs only read if they sit on a calm dark ground. Same box,
     padding and gap as before: the visible edge is an inset ring, not a border,
     so no tile size or geometry moves. */
  border-radius: 28px;
  background: radial-gradient(ellipse at 50% 30%, #1d568c, #174a7e 58%, #123c68);
  /* Deep-ice tray with an honest warm wood rim and a frost highlight, plus a
     soft lift shadow. The rim is painted outside the tiles, so no cell moves. */
  box-shadow:
    inset 0 0 0 2px rgb(255 255 255 / .30),
    inset 0 0 44px rgb(5 26 50 / .55),
    0 0 0 6px rgb(138 85 44 / .82),
    0 0 0 8px rgb(255 240 214 / .30),
    0 10px 22px rgb(6 26 48 / .38);
}

.tile {
  position: relative;
  background: none;
  display: grid;
  place-items: center;
}
/* One soft snowball per cell: the .tile itself stays transparent, so no
   rectangular plate ever shows behind the ball. */
.tile::before {
  content: "";
  position: absolute;
  inset: 5%;                            /* the ball fills ~90% of the cell */
  border-radius: 50%;
  /* The URL is a variable so a recovered server can repaint the tiles with one
     fresh copy after a failed first request (see reattachCriticalImages). */
  background-image: var(--snowball-url, url("assets/snowball.webp"));
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  /* Subtle dark contact shadow keeps each ball a separate round object on the
     dark tray; the part halos stack after it so blue/gold still read. */
  filter: drop-shadow(0 3px 4px rgb(6 24 44 / .55));
}
/* Only a halo differs between the two parts; the white snow texture stays. */
.tile.part-a::before { filter: drop-shadow(0 3px 4px rgb(6 24 44 / .55)) drop-shadow(0 0 5px rgb(96 176 226 / .95)); }
.tile.part-b::before { filter: drop-shadow(0 3px 4px rgb(6 24 44 / .55)) drop-shadow(0 0 5px rgb(240 178 74 / .95)); }
.tile.counted::after {
  content: attr(data-count);
  position: relative;
  z-index: 1;
  font-size: clamp(10px, 1.5vmin, 17px);
  font-weight: 700;
  color: var(--world-deep);
  text-shadow: 0 1px 2px rgb(255 255 255 / .9);
}
.tile.lit { animation: tile-lit 520ms ease-out; }
@keyframes tile-lit { 40% { transform: scale(1.12); filter: drop-shadow(0 0 7px rgb(242 193 65 / .95)); } }

.divider {
  position: absolute;
  height: 56px;
  transform: translateY(-50%);
  border: 0;
  background: none;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 48px;   /* bar over the tiles, grip in the right column */
  align-items: center;
  cursor: grab;
  touch-action: none;
  z-index: 3;
}
.divider[hidden] { display: none; }
.divider-bar { grid-column: 1; justify-self: stretch; height: 10px; border-radius: 999px; background: linear-gradient(#ffe9c9, #e9bb7c 55%, #c98f5a); box-shadow: inset 0 2px 0 rgb(255 236 201 / .45), 0 0 0 2px rgb(90 55 24 / .92), 0 3px 6px rgb(3 18 34 / .55); }
/* Unsplitted: park the whole grip at the bottom-right (no bar at all) so
   nothing ever lies across the last row of tiles. */
.divider.parked .divider-bar { display: none; }
.divider-grip {
  grid-column: 2;
  justify-self: center;
  /* Real carved up/down grip from the shared honey-wood family: 44x54 inside
     the existing 48px column and 56px slider hit area. */
  width: 44px;
  height: 54px;
  border: 0;
  background: url("assets/ui/row-divider-grip.webp") center / contain no-repeat;
  filter: drop-shadow(0 3px 4px rgb(6 24 48 / .5));
  display: block;
}
.divider.dragging { cursor: grabbing; }
.divider.dragging .divider-grip { transform: scale(1.06); }
.divider.nudge { animation: divider-nudge 1400ms ease-in-out infinite; }
@keyframes divider-nudge { 50% { transform: translateY(-50%) scale(1.05); } }

.equation {
  margin: 0;
  padding: 4px clamp(10px, 1.6vmin, 20px);
  border-radius: 999px;
  background: rgb(255 248 230 / .92);
  box-shadow: var(--wm-shadow-card);
  font-size: clamp(14px, 2.2vmin, 26px);
  font-weight: 700;
  color: var(--world-deep);
  max-width: 100%;
  text-align: center;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.equation.solved { background: var(--wm-gold); }
.count-readout { margin: 0; min-height: 1em; font-size: clamp(13px, 1.9vmin, 22px); font-weight: 700; color: #fff8e6; text-shadow: 0 2px 3px rgb(20 40 60 / .7); }

.hero { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; min-height: 0; }
.hero-art { width: clamp(200px, 36vmin, 340px); max-width: 100%; height: auto; max-height: 76%; object-fit: contain; filter: drop-shadow(0 10px 12px rgb(23 50 77 / .4)); }
.hero.react-happy .hero-art { animation: hero-happy 900ms ease-out; }
.hero.react-soft .hero-art { animation: hero-soft 900ms ease-out; }
@keyframes hero-happy { 30% { transform: translateY(-10px) rotate(-4deg); } 65% { transform: translateY(0) rotate(3deg); } }
@keyframes hero-soft { 40% { transform: rotate(-5deg) translateY(4px); } }

.mosaic { display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px; width: min(100%, 190px); }
.mosaic-cell { aspect-ratio: 1; border-radius: 50%; background: rgb(23 50 77 / .28); box-shadow: inset 0 0 0 1px rgb(255 248 230 / .45); }
.mosaic-cell.joined { background: linear-gradient(160deg, var(--world-ice-1), var(--world-ice-3)); box-shadow: inset 0 0 0 1px #fff; }
.mosaic-cell.just-joined { animation: panel-join 800ms ease-out; }
@keyframes panel-join { from { transform: scale(.2); opacity: 0; } 60% { transform: scale(1.15); } }

/* ---------- answer bar ---------- */
.answer-bar {
  display: flex;
  flex-flow: row nowrap;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.6vmin, 22px);
  padding: clamp(5px, 1vmin, 12px) clamp(10px, 1.6vmin, 22px);
  border-radius: 30px;
  /* Frosted answer dock: the cards, the socket, OK and Count with me read as
     one tool instead of four boxes floating on the scene. */
  background: linear-gradient(rgb(255 248 230 / .22), rgb(23 50 77 / .30));
  box-shadow: inset 0 0 0 2px rgb(255 248 230 / .32), 0 8px 18px rgb(6 26 48 / .28);
}
.cards { display: flex; gap: clamp(6px, 1.2vmin, 16px); }
.card {
  width: clamp(58px, 8.4vmin, 96px);
  height: clamp(76px, 11vmin, 124px);
  border-radius: 18px;
  border: 4px solid var(--wm-wood-2);
  background: linear-gradient(#fffdf5, var(--wm-cream-2));
  box-shadow: var(--wm-shadow-card);
  font-size: clamp(26px, 4.4vmin, 52px);
  font-weight: 700;
  color: var(--world-deep);
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: none;
  user-select: none;
}
.card.selected { border-color: var(--wm-gold); box-shadow: 0 0 0 4px rgb(242 193 65 / .75), var(--wm-shadow-card); transform: translateY(-4px); }
.card.used { opacity: .38; }
.card.dragging { position: fixed; z-index: 260; pointer-events: none; transform: scale(1.06) rotate(-3deg); }
.demo-ghost { position: fixed; z-index: 255; pointer-events: none; transform: translate(-50%, -50%) scale(1.04); transition: left 700ms ease-in-out, top 700ms ease-in-out; }

.socket {
  width: clamp(66px, 9.6vmin, 112px);
  height: clamp(76px, 11vmin, 124px);
  border-radius: 18px;
  border: 4px dashed rgb(255 248 230 / .9);
  background: rgb(23 50 77 / .28);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.socket-hint { font-size: clamp(10px, 1.4vmin, 15px); font-weight: 700; color: #fff8e6; opacity: .9; text-align: center; }
.socket.filled { border-style: solid; border-color: var(--wm-gold); background: rgb(255 248 230 / .95); padding: 0; }
.socket.over { border-color: var(--wm-gold); background: rgb(242 193 65 / .35); }
.socket .card { border: 0; box-shadow: none; background: none; width: 100%; height: 100%; }

.wood-button {
  border: 3px solid var(--wm-wood-2);
  border-radius: 999px;
  background: linear-gradient(#f3ddb4, #d9b177);
  box-shadow: 0 4px 0 var(--wm-wood-2);
  color: #4a2f14;
  font-weight: 700;
  font-size: clamp(13px, 1.9vmin, 20px);
  padding: clamp(8px, 1.4vmin, 14px) clamp(12px, 2vmin, 22px);
  min-height: 48px;
  cursor: pointer;
  touch-action: manipulation;
}
.wood-button:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--wm-wood-2); }
.wood-button[aria-pressed="true"] { background: linear-gradient(#fff3d4, var(--wm-gold)); }
.ok-button { width: clamp(56px, 7.6vmin, 88px); height: clamp(56px, 7.6vmin, 88px); min-width: 56px; min-height: 56px; }

/* ---------- tutorial ---------- */
.tutorial-hand { position: fixed; z-index: 250; width: clamp(58px, 9vmin, 116px); height: auto; pointer-events: none; transform-origin: 18% 8%; transition: left 620ms ease-in-out, top 620ms ease-in-out, opacity 240ms; }
.tutorial-hand img { width: 100%; height: auto; display: block; transform: rotate(-16deg); }
.tutorial-hand[hidden] { display: none; }
.tutorial-steps { position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 250; margin: 0; padding: 8px 16px 8px 30px; border-radius: 18px; background: rgb(255 248 230 / .95); box-shadow: var(--wm-shadow-card); font-size: clamp(12px, 1.7vmin, 17px); font-weight: 700; color: var(--world-deep); pointer-events: none; }
.tutorial-steps[hidden] { display: none; }
.tutorial-steps span { display: inline-grid; place-items: center; width: 20px; height: 20px; margin-right: 6px; border-radius: 50%; background: var(--wm-gold); }

.rune { position: fixed; z-index: 400; left: max(6px, env(safe-area-inset-left)); bottom: max(6px, env(safe-area-inset-bottom)); width: clamp(44px, 7vmin, 92px); height: auto; opacity: .92; pointer-events: none; }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom)); background: rgb(20 44 66 / .55); }
.overlay[hidden] { display: none; }
.panel { position: relative; width: min(92vw, 560px); max-height: 92vh; overflow: auto; border-radius: var(--wm-radius-panel); border: 5px solid var(--wm-wood-2); background: linear-gradient(#fffdf6, var(--wm-cream-2)); box-shadow: 0 18px 40px rgb(15 30 45 / .5); padding: var(--panel-pad); text-align: center; }
.panel h2 { margin: 0 0 .3em; font-size: clamp(20px, 3.4vmin, 34px); color: var(--world-deep); }
.panel-note { margin: 0 0 .8em; font-size: clamp(13px, 1.9vmin, 19px); }
.panel-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 10px; }
.big-button { font-size: clamp(16px, 2.4vmin, 24px); padding: 14px 28px; }
.level-choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 12px; }
.level-choice { display: grid; gap: 2px; }
.level-choice small { font-weight: 400; font-size: 11px; opacity: .8; }
.reward-card { width: min(92vw, 620px); }
.reward-highfive { width: min(100%, 360px); height: auto; }
.finale-card { border-color: var(--wm-gold); }
.finale-mosaic { width: min(100%, 320px); margin: 0 auto 10px; }
.audio-note { margin: 0; min-height: 1.2em; font-size: 13px; font-weight: 700; color: #7a4a12; }

/* ---------- help ---------- */
.help { border: 0; padding: 0; background: none; max-width: min(94vw, 880px); max-height: 94vh; }
.help::backdrop { background: rgb(20 44 66 / .62); }
.help-card { border-radius: var(--wm-radius-panel); border: 5px solid var(--wm-wood-2); background: linear-gradient(#fffdf6, var(--wm-cream-2)); box-shadow: 0 18px 40px rgb(15 30 45 / .5); padding: var(--panel-pad); max-height: 92vh; overflow: auto; }
.help-card h2 { margin: 0 0 .4em; color: var(--world-deep); }
.help-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.help-steps li { display: grid; grid-template-columns: minmax(96px, 170px) minmax(0, 1fr); gap: 14px; align-items: center; }
.help-steps strong { display: block; font-size: clamp(14px, 2vmin, 20px); color: var(--world-deep); }
.help-steps p { margin: .2em 0 0; font-size: clamp(13px, 1.8vmin, 18px); }
.help-art { display: grid; place-items: center; }
.mini-board { display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(3, 1fr); gap: 6px; width: min(100%, 150px); padding: 8px; border-radius: 16px; background: radial-gradient(ellipse at 50% 32%, #1d568c, #174a7e 60%, #123c68); box-shadow: inset 0 0 0 3px rgb(255 255 255 / .26), inset 0 0 18px rgb(5 26 50 / .5); position: relative; }
.mini-board i { aspect-ratio: 1; background-image: var(--snowball-url, url("assets/snowball.webp")); background-size: contain; background-position: center; background-repeat: no-repeat; filter: drop-shadow(0 2px 2px rgb(6 24 44 / .5)); }
.mini-divider { position: absolute; left: 3%; right: 3%; top: 66.6%; height: 6px; border-radius: 4px; background: linear-gradient(#ffe9c9, #f0cf9c); box-shadow: 0 0 0 2px rgb(96 58 26 / .9), 0 2px 4px rgb(3 18 34 / .55); }
.mini-card { width: 74px; height: 96px; border-radius: 14px; border: 4px solid var(--wm-wood-2); background: linear-gradient(#fffdf5, var(--wm-cream-2)); display: grid; place-items: center; font-size: 40px; font-weight: 700; color: var(--world-deep); }
.mini-ok { width: 74px; height: 74px; }
.help-spoken { margin-top: 16px; padding-top: 12px; border-top: 2px dashed rgb(138 85 44 / .4); text-align: left; }
.help-spoken h3 { margin: 0 0 .3em; color: var(--world-deep); }
.help-spoken p { margin: .5em 0; font-size: clamp(12px, 1.7vmin, 17px); line-height: 1.5; }
.help-parent { margin-top: 16px; padding-top: 12px; border-top: 2px dashed rgb(138 85 44 / .4); text-align: left; }
.help-parent h3 { margin: 0 0 .3em; color: var(--world-deep); }
.help-parent p { margin: .5em 0; font-size: clamp(12px, 1.7vmin, 17px); line-height: 1.45; }
/* The audio controls sit right under the title, and Close stays pinned to the
   bottom of the scroll box so the instructions stay reachable on a phone. */
.help-audio { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 0 0 14px; }
.close-button { position: sticky; bottom: 0; z-index: 1; width: 100%; margin-top: 14px; }

/* ---------- portrait composition ---------- */
@media (orientation: portrait) {
  .hud { grid-template-columns: 1fr auto; grid-template-areas: "controls controls" "progress path"; }
  .controls { grid-column: 1 / -1; grid-area: controls; justify-self: center; }
  .hud-progress { grid-area: progress; width: 130px; min-height: 62px; padding: 7px 10px; }
  .level-path { grid-area: path; align-self: center; width: 195px; min-height: 58px; padding: 5px 10px; }
  .round-track { gap: 4px; }
  .round-star { width: 24px; height: 24px; }
  .level-token { width: 30px; height: 30px; min-width: 30px; font-size: 14px; }
  .divider-grip { width: 42px; height: 52px; }
  .control { width: 56px; height: 56px; min-width: 56px; min-height: 56px; }

  /* Guide across the top; below it a two-column stage: the tile board keeps
     the tall space a 9-row task needs, Sopo and the miniature mosaic sit in a
     narrow column at the bottom right. */
  /* A character column wide enough for a phone-sized Sopo instead of a sliver. */
  .stage { grid-template-columns: minmax(0, 1fr) clamp(110px, 30vmin, 132px); grid-template-rows: auto minmax(0, 1fr); gap: 6px; }
  .guide { grid-column: 1 / -1; grid-row: 1; flex-direction: row; align-items: center; gap: 8px; }
  .guide-art { width: clamp(72px, 20vmin, 108px); max-height: 100%; align-self: center; }
  .speech { flex: 1 1 auto; padding: 6px 10px; font-size: clamp(12px, 3.2vmin, 17px); }
  .speech::before { display: none; }
  .board-area { grid-column: 1; grid-row: 2; }
  .hero { grid-column: 2; grid-row: 2; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; }
  .hero-art { width: 100%; max-height: 46%; }
  .mosaic { width: min(100%, 96px); grid-template-columns: repeat(5, 1fr); }
  .tile.counted::after { font-size: clamp(12px, 3vmin, 18px); }

  .answer-bar { flex-wrap: wrap; gap: 6px; }
  .cards { order: 1; width: 100%; justify-content: center; gap: 6px; }
  .card { width: clamp(48px, 7.4vmin, 72px); height: clamp(56px, 8.6vmin, 84px); font-size: clamp(22px, 3.8vmin, 40px); }
  .socket { order: 2; width: clamp(56px, 8.6vmin, 84px); height: clamp(56px, 8.6vmin, 84px); }
  .ok-button { order: 3; width: 56px; height: 56px; min-width: 56px; min-height: 56px; }
  #countButton { order: 4; }
  .equation { font-size: clamp(12px, 3.4vmin, 20px); padding: 3px 12px; }
  .count-readout { font-size: clamp(12px, 3vmin, 18px); }
}

/* Tablet portrait has room for a wider character column. */
@media (orientation: portrait) and (min-width: 600px) {
  .stage { grid-template-columns: minmax(0, 1fr) 180px; }
  .guide-art { width: clamp(96px, 15vmin, 140px); }
  .hero-art { width: 100%; max-height: 60%; }
  .mosaic { width: min(100%, 170px); }
}

@media (orientation: landscape) and (max-height: 640px) {
  .guide-art, .hero-art { width: clamp(150px, 28vmin, 260px); max-height: 42%; }
}

/* Compact phones in landscape (844x390 and friends): keep the whole board,
   the answer bar and all five controls inside the viewport. */
@media (orientation: landscape) and (max-height: 520px) {
  .game { gap: 4px; padding: 4px max(6px, env(safe-area-inset-right)) 4px max(6px, env(safe-area-inset-left)); }
  .stage { grid-template-columns: minmax(78px, 15%) minmax(0, 1fr) minmax(66px, 13%); gap: 6px; }
  .guide-art { width: clamp(72px, 16vmin, 128px); max-height: 42%; }
  .hero-art { width: clamp(96px, 20vmin, 150px); max-height: 48%; }
  .speech { padding: 6px 10px; font-size: clamp(12px, 2.6vmin, 15px); border-radius: 14px 16px 18px 6px; }
  .speech::before { display: none; }
  .hud-label { font-size: clamp(11px, 2.2vmin, 14px); }
  .hud-progress { width: 150px; min-height: 52px; padding: 6px 12px; }
  .level-path { width: 205px; min-height: 50px; padding: 4px 10px; }
  .round-star { width: 22px; height: 22px; }
  .level-token { width: 28px; height: 28px; min-width: 28px; font-size: 12px; }
  .divider-grip { width: 40px; height: 50px; }
  .answer-bar { gap: 8px; padding: 3px 10px; }
  .cards { gap: 6px; }
  .card { width: clamp(48px, 7vmin, 62px); height: clamp(56px, 9vmin, 76px); font-size: clamp(22px, 3.6vmin, 34px); border-width: 3px; }
  .socket { width: clamp(54px, 8vmin, 70px); height: clamp(56px, 9vmin, 76px); border-width: 3px; }
  .equation { font-size: clamp(12px, 2.4vmin, 16px); }
  .count-readout { font-size: clamp(11px, 2.2vmin, 15px); }
  .wood-button { padding: 6px 12px; min-height: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  .tutorial-hand { transition: none; }
  .round-star.landing, .tile.lit, .hero.react-happy .hero-art, .hero.react-soft .hero-art,
  .mosaic-cell.just-joined, .guide.talking .guide-art, .divider.nudge { animation: none; }
}

/* ---------- juice layer (P1-P6) ---------- */

/* Every decorative effect lives in this one inert layer: fixed, transparent
   to touch, above the board and the characters but below the dragged card
   (260), the tutorial hand (250), the overlays (300), the help dialog (top
   layer) and the rune (400). Nothing here can cover the rune or modal text. */
#fx-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  overflow: hidden;
}
.fx-node { position: fixed; left: 0; top: 0; pointer-events: none; will-change: transform, opacity; }

/* P3 - tiny ice/gold sparkles at the panel target, never across the board. */
.fx-sparkle {
  width: var(--s, 7px); height: var(--s, 7px);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 34%, #fff, var(--c, var(--wm-gold)) 62%, rgb(255 255 255 / 0));
  animation: fx-sparkle var(--dur, 600ms) ease-out both;
}
@keyframes fx-sparkle {
  0% { transform: translate3d(var(--x), var(--y), 0) scale(1); opacity: 1; }
  100% { transform: translate3d(calc(var(--x) + var(--dx)), calc(var(--y) + var(--dy)), 0) scale(.35); opacity: 0; }
}

/* P2 - one finished panel: the whole rows x cols array of snowball copies
   flies together (never one snowball at a time, no cap on the copy count). */
.fx-panel {
  display: grid;
  grid-template-columns: repeat(var(--gc, 5), 1fr);
  grid-template-rows: repeat(var(--gr, 5), 1fr);
  gap: var(--g, 8px);
  padding: var(--p, 8px);
  width: var(--w, 320px);
  height: var(--h, 240px);
  border-radius: 28px;
  background: radial-gradient(ellipse at 50% 30%, #1d568c, #174a7e 58%, #123c68);
  box-shadow: inset 0 0 0 2px rgb(255 255 255 / .3), 0 10px 22px rgb(6 26 48 / .38);
}
.fx-panel-ball { background: var(--snowball-url, url("assets/snowball.webp")) center / contain no-repeat; filter: drop-shadow(0 3px 4px rgb(6 24 44 / .55)); }

/* P2 - three thought dots beside the seal's head (decoration, no new face). */
.fx-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--wm-cream, #fff8e6);
  box-shadow: 0 0 0 2px rgb(23 50 77 / .22);
  animation: fx-dot var(--dur, 1500ms) ease-in-out var(--d, 0ms) both;
}
@keyframes fx-dot {
  0% { transform: translate3d(var(--x), var(--y), 0) scale(.4); opacity: 0; }
  35% { transform: translate3d(var(--x), calc(var(--y) - 12px), 0) scale(1); opacity: .95; }
  70% { opacity: .95; }
  100% { transform: translate3d(var(--x), calc(var(--y) - 24px), 0) scale(.8); opacity: 0; }
}

/* P3 - finale: one slow, warm, low-opacity curtain of light. Never white. */
.fx-bloom {
  position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(closest-side at 50% 54%, rgb(255 231 180 / .55), rgb(255 231 180 / 0) 72%);
  opacity: 0;
  animation: fx-bloom 1500ms ease-in-out both;
}
@keyframes fx-bloom { 0% { opacity: 0; } 45% { opacity: .25; } 100% { opacity: 0; } }

/* P1 - tap acknowledgement. The standalone `scale` property is composed with
   the existing selected/used/pressed transforms, so nothing is overridden and
   the native drag position is untouched. */
.juice-pop { animation: juice-pop 240ms cubic-bezier(.22,.9,.3,1.2); }
@keyframes juice-pop { 0% { scale: 1; } 45% { scale: 1.15; } 100% { scale: 1; } }

/* P2 - one gentle 2.2 s wobble on the child's own trial; never a verdict,
   never points, never a repeated shake. */
.juice-wobble { animation: juice-wobble 2200ms ease-in-out; }
@keyframes juice-wobble { 0%, 100% { rotate: 0deg; } 30% { rotate: -1.6deg; } 68% { rotate: 1.2deg; } }

/* P2 - Sopo beats. Whole canonical hero only: no new face, limb, hat or finger.
   MA-07 small body sway, MA-15 polite tiny bow, both one gentle 2.2 s scene. */
.hero.beat-sway .hero-art { animation: hero-beat-sway 2200ms ease-in-out; }
@keyframes hero-beat-sway { 0%, 100% { transform: rotate(0deg); } 30% { transform: rotate(-2.4deg); } 70% { transform: rotate(1.8deg); } }
.hero.beat-bow .hero-art { animation: hero-beat-bow 2200ms ease-in-out; }
@keyframes hero-beat-bow { 0%, 100% { transform: translateY(0) rotate(0deg); } 40% { transform: translateY(8px) rotate(-1.6deg); } 76% { transform: translateY(2px) rotate(0.6deg); } }

/* P3 - the existing high-five picture gives one gentle cheer at level end. */
.reward-highfive.cheer { animation: reward-cheer 900ms ease-out; }
@keyframes reward-cheer { 25% { transform: translateY(-6px) rotate(-2deg); opacity: .92; } 60% { transform: translateY(0) rotate(1.4deg); opacity: 1; } }

/* P3 - the last empty task star breathes gently. Life, never a math hint. */
.round-star.breathe { animation: star-breathe 2200ms ease-in-out infinite; }
@keyframes star-breathe { 50% { scale: 1.12; opacity: .82; } }

/* P6 - one safe call to action breathes after a quiet spell. */
.juice-breathe { animation: juice-breathe 2000ms ease-in-out infinite; }
@keyframes juice-breathe { 50% { scale: 1.04; } }

/* P4 - three ice motes drifting only along the edges, 12-20 s per pass. */
.ambient-flake {
  position: fixed; top: 0; width: 10px; height: 10px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff, #cfeaf7 58%, rgb(207 234 247 / 0));
  opacity: 0; pointer-events: none;
  animation: flake-drift var(--dur, 14s) linear infinite;
  animation-delay: var(--delay, 0s);
  animation-play-state: paused;
}
.amb-0 { left: 3vw; --dur: 12s; --delay: -3s; }
.amb-1 { left: 94vw; --dur: 16s; --delay: -8s; }
.amb-2 { left: 7vw; --dur: 20s; --delay: -14s; }
#fx-layer.ambient-on .ambient-flake { animation-play-state: running; }
@keyframes flake-drift {
  0% { transform: translate3d(0, -6vh, 0); opacity: 0; }
  12% { opacity: .65; }
  88% { opacity: .65; }
  100% { transform: translate3d(5vw, 106vh, 0); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .fx-sparkle, .fx-dot, .fx-bloom, .juice-pop, .juice-wobble,
  .hero.beat-sway .hero-art, .hero.beat-bow .hero-art,
  .round-star.breathe, .juice-breathe, .reward-highfive.cheer { animation: none !important; }
  .ambient-flake { display: none !important; }
}
