/* Studio of coloured toys: a sunlit clay-and-lacquer toy workshop.
   Chrome follows the platform tokens; the scene (wall, bench, cabinet) is the workshop's own. */

:root {
  --ink: #30254d;
  --paper: #fffaf0;
  --plum: #7452b8;
  --star: #ffd84d;
  --shadow: #39295e;
  --chrome: 56px;
  --tool: 56px;
  --sw: 56px;
  --gap: 12px;
  --action-w: 136px;
  --ease: cubic-bezier(.2, .9, .25, 1.2);
  --font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", system-ui, sans-serif;
  --stage-top: 96px;
  --stage-bottom: 200px;
  --cabinet-top: 130px;
  --celebration-top: 80px;
  --celebration-bottom: 200px;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #f6e3bd;
  color: var(--ink);
  font-family: var(--font);
  font-weight: 900;
  -webkit-font-smoothing: antialiased;
}

button,
a { font: inherit; color: inherit; }

[hidden] { display: none !important; }

#game-shell {
  position: fixed;
  inset: 0;
  overflow: hidden;
  isolation: isolate;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- Workshop backdrop (scenery only, never a target) ---------- */

.backdrop,
.backdrop > span {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.backdrop {
  z-index: 0;
  background: linear-gradient(176deg, #fff6df 0%, #fbe6bd 52%, #f1cf94 100%);
  transition: background 400ms var(--ease);
}

.backdrop .sun {
  background:
    radial-gradient(ellipse 46% 38% at 16% 12%, rgba(255, 255, 255, .78), transparent 70%),
    linear-gradient(118deg, transparent 0 18%, rgba(255, 252, 236, .5) 18% 26%, transparent 26% 31%, rgba(255, 252, 236, .38) 31% 37%, transparent 37%);
}

.backdrop .pegboard {
  opacity: .32;
  background-image: radial-gradient(circle, rgba(126, 82, 34, .5) 1.6px, transparent 2.2px);
  background-size: 28px 28px;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 22%, #000 58%, transparent 80%);
  mask-image: linear-gradient(180deg, transparent 0, #000 22%, #000 58%, transparent 80%);
}

.backdrop .bench {
  top: auto;
  height: 34%;
  background:
    repeating-linear-gradient(178deg, rgba(120, 70, 20, .08) 0 3px, transparent 3px 19px),
    linear-gradient(180deg, #e7b56b 0, #d99a4a 12%, #c98638 100%);
  box-shadow: inset 0 6px 0 rgba(255, 238, 200, .7), inset 0 9px 0 rgba(120, 70, 20, .25);
}

#game-shell[data-shelf="1"] .backdrop { background: linear-gradient(176deg, #f1fff7 0%, #d6f4e4 50%, #b6e4cc 100%); }
#game-shell[data-shelf="1"] .backdrop .bench { background: repeating-linear-gradient(178deg, rgba(120, 70, 20, .08) 0 3px, transparent 3px 19px), linear-gradient(180deg, #ebc285 0, #d9a35a 12%, #c48a43 100%); }
#game-shell[data-shelf="2"] .backdrop { background: linear-gradient(176deg, #4a4890 0%, #33316e 55%, #23224f 100%); }
#game-shell[data-shelf="2"] .backdrop .sun { background: radial-gradient(circle at 82% 16%, rgba(255, 244, 196, .55) 0 22px, rgba(255, 244, 196, .12) 23px 60px, transparent 61px), radial-gradient(circle at 20% 22%, rgba(255, 255, 255, .7) 0 1.5px, transparent 2px), radial-gradient(circle at 42% 9%, rgba(255, 255, 255, .6) 0 1.5px, transparent 2px), radial-gradient(circle at 63% 27%, rgba(255, 255, 255, .5) 0 1.5px, transparent 2px); }
#game-shell[data-shelf="2"] .backdrop .pegboard { opacity: .18; }
#game-shell[data-shelf="2"] .backdrop .bench { background: repeating-linear-gradient(178deg, rgba(0, 0, 0, .1) 0 3px, transparent 3px 19px), linear-gradient(180deg, #a8743c 0, #8c5c2c 12%, #6e4722 100%); }

#game-canvas,
#fx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#game-canvas {
  z-index: 1;
  touch-action: none;
  cursor: grab;
  outline: none;
}

#game-canvas:active { cursor: grabbing; }
#game-canvas:focus-visible { outline: 4px solid var(--plum); outline-offset: -10px; border-radius: 24px; }
#fx-canvas { z-index: 2; pointer-events: none; }

/* ---------- Shared control feel ---------- */

.chrome-button,
.tool-button,
.action-button,
.swatch,
.sticker-button,
.place,
.big-button {
  position: relative;
  border: 3px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: scale 80ms ease-out, translate 220ms var(--ease), box-shadow 160ms ease-out, opacity 160ms ease-out;
}

.chrome-button:active,
.tool-button:active,
.action-button:active,
.swatch:active,
.sticker-button:active,
.place:active,
.big-button:active { scale: .94; }

.released { animation: release 260ms var(--ease); }

@keyframes release {
  0% { scale: .94; }
  60% { scale: 1.04; }
  100% { scale: 1; }
}

.chrome-button:focus-visible,
.tool-button:focus-visible,
.action-button:focus-visible,
.swatch:focus-visible,
.sticker-button:focus-visible,
.place:focus-visible,
.big-button:focus-visible {
  outline: 4px solid var(--plum);
  outline-offset: 4px;
}

.icon {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.hand-fill { fill: var(--paper); }

/* ---------- HUD: task panel and chrome ---------- */

.hud {
  position: absolute;
  z-index: 45;
  inset: 0 0 auto 0;
  height: 0;
  pointer-events: none;
}

.hud > * { pointer-events: auto; }

.task-panel {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  translate: -50% 0;
  display: grid;
  grid-template-columns: 40px auto auto;
  align-items: center;
  gap: 12px;
  height: 64px;
  max-width: calc(100vw - 2 * (var(--chrome) * 2 + var(--gap) + 22px));
  padding: 0 18px 0 12px;
  border: 3px solid var(--ink);
  border-radius: 22px;
  background: var(--paper);
  box-shadow: 0 5px 0 var(--shadow);
  font-size: 20px;
  line-height: 1.08;
  pointer-events: none;
}

.task-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 14px; background: #fde9b8; }
.task-icon .icon { width: 30px; height: 30px; stroke-width: 2; }

.task-text {
  min-width: 0;
  max-width: 20em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-weight: 950;
  text-wrap: balance;
}

.task-text.feedback { color: #5a2f8f; }

/* Mixed mode: the toy's language as a small lettered tag on the panel corner (no flags). */
.lang-badge {
  position: absolute;
  top: -12px;
  right: -8px;
  display: grid;
  place-items: center;
  min-width: 34px;
  height: 22px;
  padding: 0 6px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #7452b8;
  color: #fff;
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: .04em;
}
.lang-badge[hidden] { display: none; }
.lang-badge[data-lang="en"] { background: #2f7d6d; }
.lang-badge[data-lang="et"] { background: #3f6fc4; }
.task-panel.pop .task-text { animation: text-pop 300ms var(--ease); }

@keyframes text-pop {
  from { scale: .86; opacity: .3; }
  to { scale: 1; opacity: 1; }
}

.part-dots,
.step-track {
  display: flex;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.part-dots li {
  position: relative;
  width: 20px;
  height: 20px;
  border: 2.5px dashed rgba(48, 37, 77, .45);
  border-radius: 50%;
  background: #f4ead6;
  transition: scale 250ms var(--ease);
}

.part-dots li.filled {
  border: 2.5px solid var(--ink);
  background: var(--dot, #ccc);
}

.part-dots li.bump { animation: dot-bump 300ms var(--ease); }
@keyframes dot-bump { 0% { scale: 1; } 50% { scale: 1.35; } 100% { scale: 1; } }

.part-dots li .icon {
  position: absolute;
  inset: 1px;
  width: 13px;
  height: 13px;
  stroke: #fff;
  stroke-width: 4;
  filter: drop-shadow(0 0 1px var(--ink));
}

.step-track li {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 2.5px solid rgba(48, 37, 77, .4);
  border-radius: 50%;
  background: #f4ead6;
  color: rgba(48, 37, 77, .55);
}

.step-track li .icon { width: 20px; height: 20px; stroke-width: 2.2; }
.step-track li.done { border-color: var(--ink); background: #bfe7c8; color: var(--ink); }
.step-track li.current { border-color: var(--ink); background: var(--star); color: var(--ink); box-shadow: 0 0 0 3px #fff3c4; }

.chrome-actions {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  gap: var(--gap);
}

.chrome-button {
  display: grid;
  place-items: center;
  width: var(--chrome);
  height: var(--chrome);
  padding: 0;
  border-radius: 18px;
  box-shadow: 0 5px 0 var(--shadow);
}

.chrome-button .icon { width: 28px; height: 28px; }
.icon-sound-off { display: none; }
#sound-button[aria-pressed="false"] .icon-sound-on { display: none; }
#sound-button[aria-pressed="false"] .icon-sound-off { display: block; }

/* ---------- Dock: the workshop tool tray ---------- */

.dock {
  position: absolute;
  z-index: 21;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  translate: -50% 0;
  display: grid;
  grid-template-areas: "shelf main undo action";
  grid-template-columns: var(--tool) auto var(--tool) var(--action-w);
  align-items: center;
  gap: var(--gap);
  padding: 12px;
  border: 3px solid var(--ink);
  border-radius: 28px;
  background:
    repeating-linear-gradient(92deg, rgba(140, 90, 30, .07) 0 2px, transparent 2px 23px),
    linear-gradient(180deg, #fbe3b2, #efc985);
  box-shadow: 0 6px 0 var(--shadow), inset 0 3px 0 rgba(255, 255, 255, .6);
}

#game-shell:not([data-view="toy"]) .dock,
#game-shell:not([data-view="toy"]) .task-panel .part-dots { visibility: hidden; }
#game-shell[data-view="celebration"] .task-panel { visibility: hidden; }

.shelf-button { grid-area: shelf; }
.undo-button { grid-area: undo; }
.action-button { grid-area: action; }
.swatches,
.sticker-tray { grid-area: main; }

.tool-button {
  display: grid;
  place-items: center;
  width: var(--tool);
  height: var(--tool);
  padding: 0;
  border-radius: 18px;
  box-shadow: 0 4px 0 var(--shadow);
}

.tool-button .icon { width: 28px; height: 28px; }
.tool-button:disabled { opacity: .38; cursor: default; box-shadow: 0 2px 0 var(--shadow); }
.tool-button:disabled:active { scale: 1; }
.shelf-button.has-news::after {
  content: "";
  position: absolute;
  top: -6px;
  right: -6px;
  width: 16px;
  height: 16px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--star);
}

.action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: var(--action-w);
  min-width: 64px;
  height: 64px;
  padding: 0 14px;
  border-radius: 22px;
  background: var(--star);
  box-shadow: 0 5px 0 var(--shadow);
  font-size: 20px;
  font-weight: 950;
  white-space: nowrap;
}

.action-button .icon { width: 30px; height: 30px; }
.action-button[data-shown="false"] { visibility: hidden; }
.action-button[data-shown="true"] { animation: pop-in 320ms var(--ease); }
.action-button[data-mode="ready"] .icon-camera,
.action-button[data-mode="camera"] .icon-ready { display: none; }
.action-button[data-mode="camera"] { background: #ffcfe4; }

@keyframes pop-in {
  0% { scale: .4; opacity: 0; }
  70% { scale: 1.08; opacity: 1; }
  100% { scale: 1; }
}

.breathe { animation: breathe 1.3s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { scale: 1; } 50% { scale: 1.09; } }

.swatches {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--sw);
  grid-template-rows: var(--sw);
  align-content: center;
  justify-content: center;
  gap: var(--gap);
  min-height: 64px;
}

.swatch {
  width: var(--sw);
  height: var(--sw);
  padding: 0;
  border-radius: 50%;
  background: var(--fill, #ccc);
  box-shadow: 0 4px 0 var(--shadow), inset 0 -6px 0 rgba(0, 0, 0, .14), inset 5px 6px 0 -2px rgba(255, 255, 255, .45);
}

.swatch[data-kind="pattern"],
.swatch[data-kind="finish"] { border-radius: 18px; }
.swatch[data-kind="pattern"]:first-of-type,
.swatch.group-start { margin-left: 0; }
.swatch[aria-pressed="true"] {
  translate: 0 -7px;
  box-shadow: 0 0 0 4px var(--paper), 0 0 0 7px var(--ink), 0 9px 0 4px rgba(57, 41, 94, .35);
}

.swatch[data-kind="pattern"][data-id="stripes"] { background: repeating-linear-gradient(45deg, var(--c) 0 7px, #fff4dc 7px 14px); }
.swatch[data-kind="pattern"][data-id="dots"] { background: radial-gradient(circle, var(--c) 0 4.5px, transparent 5px) 0 0 / 15px 15px, radial-gradient(circle, var(--c) 0 4.5px, transparent 5px) 7.5px 7.5px / 15px 15px, #fff4dc; }
.swatch[data-kind="pattern"][data-id="zigzag"] { background: linear-gradient(135deg, var(--c) 25%, transparent 25%) -8px 0 / 16px 16px, linear-gradient(225deg, var(--c) 25%, transparent 25%) -8px 0 / 16px 16px, linear-gradient(315deg, var(--c) 25%, transparent 25%) 0 0 / 16px 16px, linear-gradient(45deg, var(--c) 25%, transparent 25%) 0 0 / 16px 16px, #fff4dc; }
.swatch[data-kind="finish"][data-id="gold"] { background: linear-gradient(135deg, #fff1b0 0%, #f2b632 38%, #a86d0c 62%, #ffe28a 100%); }
.swatch[data-kind="finish"][data-id="silver"] { background: linear-gradient(135deg, #ffffff 0%, #c9d0da 40%, #7c8594 62%, #eef2f7 100%); }
.swatch[data-kind="finish"][data-id="copper"] { background: linear-gradient(135deg, #ffd2b0 0%, #d27a4a 40%, #8a3f1a 62%, #f3b08a 100%); }
.swatch[data-kind="finish"][data-id="glow"] { background: radial-gradient(circle, #fff 0 5px, var(--c) 9px, color-mix(in srgb, var(--c) 40%, #1d1b44) 22px, #1d1b44 30px); box-shadow: 0 4px 0 var(--shadow), 0 0 16px 2px var(--c); }

.sticker-tray {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap);
  min-height: 64px;
}

.sticker-button {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  padding: 2px;
  border-color: transparent;
  border-radius: 18px;
  background: transparent;
}

.sticker-button .sticker-art { width: 56px; height: 56px; filter: drop-shadow(0 3px 0 rgba(57, 41, 94, .35)); }
.sticker-button[aria-pressed="true"] { translate: 0 -6px; border-color: var(--ink); background: var(--paper); box-shadow: 0 5px 0 var(--shadow); }
.sticker-button.fly-in { animation: sticker-in 360ms var(--ease) both; }
@keyframes sticker-in { from { translate: 0 40px; opacity: 0; } to { translate: 0 0; opacity: 1; } }

.ghost-sticker {
  position: absolute;
  z-index: 30;
  width: 56px;
  height: 56px;
  pointer-events: none;
}

/* ---------- Hints ---------- */

.rotate-hint,
.hand-hint {
  position: absolute;
  z-index: 19;
  width: 76px;
  height: 76px;
  pointer-events: none;
  color: var(--ink);
}

.rotate-hint .icon,
.hand-hint .icon { width: 100%; height: 100%; stroke-width: 1.6; filter: drop-shadow(0 3px 0 rgba(57, 41, 94, .35)); }
.rotate-hint { animation: sway 1.8s ease-in-out infinite; }
@keyframes sway { 0%, 100% { rotate: -9deg; } 50% { rotate: 9deg; } }
.hand-hint { transform-origin: 46% 14%; animation: grow 1.2s ease-in-out infinite; }
@keyframes grow { 0%, 100% { scale: 1; } 50% { scale: 1.25; } }

/* ---------- Cabinet: the persistent shelf of finished toys ---------- */

.cabinet {
  position: absolute;
  z-index: 30;
  inset: 0;
  background: rgba(255, 246, 223, .5);
}

#game-shell[data-shelf="2"] .cabinet { background: rgba(35, 34, 79, .35); }

.cabinet-frame {
  position: absolute;
  top: var(--cabinet-top);
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 50%;
  translate: -50% 0;
  width: min(860px, calc(100vw - 24px));
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
  padding: 10px 14px 16px;
  border: 4px solid var(--ink);
  border-radius: 26px;
  background:
    repeating-linear-gradient(91deg, rgba(110, 60, 15, .1) 0 2px, transparent 2px 17px, rgba(255, 230, 180, .12) 17px 19px, transparent 19px 31px),
    linear-gradient(180deg, #edbd70, #d4913f);
  box-shadow: 0 8px 0 var(--shadow), inset 0 4px 0 rgba(255, 236, 196, .7);
  animation: cabinet-in 300ms var(--ease);
}

@keyframes cabinet-in { from { translate: -50% 24px; opacity: 0; } to { translate: -50% 0; opacity: 1; } }

.cabinet-sign {
  justify-self: center;
  margin: 0;
  padding: 6px 22px 8px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: linear-gradient(180deg, #fff6e2, #f3dfb6);
  box-shadow: 0 4px 0 var(--shadow);
  font-size: clamp(20px, 3.4vw, 28px);
  font-weight: 950;
  line-height: 1.1;
  text-align: center;
}

.cabinet-shelves {
  display: grid;
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 12px;
  min-height: 0;
}

.cabinet-shelf {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  min-height: 0;
  padding: 26px 10px 14px;
  border-radius: 16px;
  background: linear-gradient(180deg, #8a5426, #a86a34 70%, #6b3e18);
  box-shadow: inset 0 6px 10px rgba(40, 20, 5, .45);
}

.cabinet-shelf::after {
  content: "";
  position: absolute;
  left: -6px;
  right: -6px;
  bottom: -6px;
  height: 14px;
  border: 3px solid var(--ink);
  border-radius: 7px;
  background: linear-gradient(180deg, #f2c278, #c98a3e);
}

.shelf-tag {
  position: absolute;
  z-index: 1;
  top: -4px;
  left: 14px;
  padding: 2px 12px 3px;
  border: 2.5px solid var(--ink);
  border-radius: 8px;
  background: #e9cf9e;
  font-size: 16px;
  font-weight: 950;
  rotate: -2deg;
}

.place {
  display: grid;
  place-items: center;
  min-width: 56px;
  min-height: 56px;
  padding: 6px;
  border-radius: 16px;
  background: #3b3954;
  color: #f4efe2;
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, .35), 0 4px 0 var(--shadow);
  overflow: hidden;
}

.place:not([data-state="done"]) { padding-bottom: 30px; }
.place .chalk { width: 100%; height: 100%; max-width: 140px; max-height: 100%; min-height: 0; stroke: #f4efe2; stroke-width: 1.4; }
.place[data-state="open"] .chalk { filter: drop-shadow(0 0 6px rgba(255, 244, 196, .8)); }
.place[data-state="open"] { background: radial-gradient(circle at 50% 40%, #59577a, #3b3954 70%); }
.place[data-state="locked"] .chalk { opacity: .42; stroke-dasharray: 2.2 2.2; }
.place .lock {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 26px;
  height: 26px;
  stroke: #f4efe2;
  opacity: .7;
}
.place .place-name {
  position: absolute;
  left: 12px;
  bottom: 6px;
  font-size: 16px;
  font-weight: 950;
  color: #f4efe2;
}
.place[data-state="locked"] .place-name { opacity: .5; }
.place.bob { animation: bob 360ms var(--ease); }
@keyframes bob { 0%, 100% { translate: 0 0; } 40% { translate: 0 -8px; } 70% { translate: 0 3px; } }

.place[data-state="done"] { background: #4a4766; }
.place .polaroid {
  position: absolute;
  top: 7px;
  bottom: 9px;
  left: 50%;
  translate: -50% 0;
  aspect-ratio: 5 / 6;
  max-width: calc(100% - 14px);
}
.place .polaroid img,
.place .polaroid .photo-fallback { width: 100%; height: auto; }
.place .polaroid .photo-fallback { display: grid; place-items: center; }
.place .polaroid .photo-fallback .chalk { width: 70%; height: 70%; stroke: var(--ink); stroke-width: 1.8; fill: rgba(255, 250, 240, .75); filter: none; }

.polaroid {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  margin: 0;
  padding: 7px 7px 4px;
  border-radius: 4px;
  background: #fffdf8;
  box-shadow: 0 6px 14px rgba(20, 10, 40, .35);
  rotate: var(--tilt, -2deg);
}

.polaroid img,
.polaroid .photo-fallback {
  display: block;
  width: auto;
  height: 100%;
  max-width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  min-height: 0;
  background: #f1e3c4;
}

.polaroid figcaption {
  padding-top: 3px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 950;
  text-align: center;
}

.place .polaroid.just-added { animation: polaroid-drop 520ms var(--ease); }
@keyframes polaroid-drop { from { translate: 0 -60px; rotate: 12deg; opacity: 0; } to { translate: 0 0; opacity: 1; } }

/* ---------- Celebration: platform grammar ---------- */

.celebration {
  position: absolute;
  z-index: 40;
  inset: 0;
  background: rgba(255, 248, 230, .62);
}

#game-shell[data-shelf="2"] .celebration { background: rgba(30, 29, 70, .45); }

.celebration-card {
  position: absolute;
  top: var(--celebration-top);
  bottom: var(--celebration-bottom);
  left: 50%;
  translate: -50% 0;
  width: min(520px, calc(100vw - 24px));
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  justify-items: center;
  align-content: center;
  gap: 12px;
}

.celebration-star {
  position: absolute;
  z-index: 2;
  top: -6px;
  left: 50%;
  width: clamp(72px, 13vh, 112px);
  height: clamp(72px, 13vh, 112px);
  translate: -50% -26%;
  fill: #ffd84d;
  stroke: #a86100;
  stroke-width: 1.3;
  stroke-linejoin: round;
  filter: drop-shadow(0 5px 0 rgba(168, 97, 0, .45));
  animation: star-pop 520ms var(--ease) both;
}

@keyframes star-pop {
  0% { scale: .2; rotate: -40deg; opacity: 0; }
  70% { scale: 1.12; rotate: 6deg; opacity: 1; }
  100% { scale: 1; rotate: 0deg; }
}

.celebration .polaroid {
  --tilt: -3deg;
  min-height: 0;
  height: 100%;
  max-height: 380px;
  padding: 12px 12px 6px;
  border: 3px solid var(--ink);
  animation: photo-print 480ms var(--ease) both;
}

.celebration .polaroid figcaption { font-size: 22px; padding: 6px 0 2px; }

@keyframes photo-print { from { translate: 0 30px; scale: .85; opacity: 0; } to { translate: 0 0; scale: 1; opacity: 1; } }

.celebration-text {
  margin: 0;
  padding: 8px 22px 10px;
  border: 3px solid var(--ink);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 5px 0 var(--shadow);
  font-size: clamp(24px, 4.2vw, 32px);
  font-weight: 950;
  line-height: 1.1;
}

.celebration-actions {
  position: absolute;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 50%;
  translate: -50% 0;
  display: flex;
  gap: var(--gap);
}

.big-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 64px;
  min-height: 64px;
  padding: 0 22px;
  border-radius: 22px;
  box-shadow: 0 5px 0 var(--shadow);
  font-size: 20px;
  font-weight: 950;
  text-decoration: none;
  white-space: nowrap;
}

.big-button .icon { width: 30px; height: 30px; }
.big-button-next { background: var(--star); }

.flash {
  position: absolute;
  z-index: 50;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

.flash.go { animation: flash 150ms ease-out; }
@keyframes flash { from { opacity: .95; } to { opacity: 0; } }

.error-card {
  position: absolute;
  z-index: 60;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  width: min(390px, calc(100vw - 32px));
  padding: 24px;
  border: 3px solid var(--ink);
  border-radius: 24px;
  background: var(--paper);
  box-shadow: 0 6px 0 var(--shadow);
  text-align: center;
}

.error-card strong,
.error-card span { display: block; }
.error-card strong { font-size: 24px; }
.error-card span { margin-top: 8px; font-size: 18px; }

/* Platform toast sits in the reserved slot just above the dock. */
body [data-tokenville-star-toast] {
  bottom: var(--toy-toast-bottom, max(24px, calc(env(safe-area-inset-bottom) + 14px))) !important;
  left: var(--toy-toast-left, 50%) !important;
}

/* ---------- Tablet portrait: two swatch rows ---------- */

@media (max-width: 999px) {
  .swatches {
    grid-auto-flow: row;
    grid-template-columns: repeat(5, var(--sw));
    grid-template-rows: none;
    grid-auto-rows: var(--sw);
    min-height: calc(var(--sw) * 2 + var(--gap));
  }
  .sticker-tray { min-height: calc(var(--sw) * 2 + var(--gap)); }
}

/* ---------- Phone ---------- */

@media (max-width: 560px) {
  :root {
    --chrome: 48px;
    --sw: clamp(46px, calc((100vw - 16px - 30px - 4 * 12px) / 5), 56px);
    --action-w: 124px;
  }
  .task-panel {
    top: calc(max(10px, env(safe-area-inset-top)) + 58px);
    left: calc(var(--tokenville-corner-right, 86px) + 8px);
    right: max(10px, env(safe-area-inset-right));
    translate: none;
    max-width: none;
    height: 82px;
    grid-template-columns: 34px minmax(0, 1fr);
    grid-template-rows: 1fr auto;
    gap: 4px 10px;
    padding: 6px 10px 8px;
    font-size: 18px;
  }
  .task-icon { grid-row: 1 / 3; width: 34px; height: 34px; }
  .task-icon .icon { width: 26px; height: 26px; }
  .task-text { align-self: center; max-width: none; }
  .part-dots { gap: 5px; }
  .part-dots li { width: 18px; height: 18px; }
  .step-track li { width: 28px; height: 28px; }
  .step-track li .icon { width: 17px; height: 17px; }
  .chrome-button .icon { width: 25px; height: 25px; }
  .dock {
    left: 8px;
    right: 8px;
    bottom: max(10px, env(safe-area-inset-bottom));
    translate: none;
    grid-template-areas: "shelf . undo action" "main main main main";
    grid-template-columns: var(--tool) minmax(0, 1fr) var(--tool) var(--action-w);
    padding: 10px 12px 12px;
    border-radius: 24px;
  }
  .swatches { justify-content: center; }
  .action-button { font-size: 18px; padding: 0 10px; }
  .celebration-actions { left: 8px; right: 8px; translate: none; justify-content: center; }
  .big-button { flex: 1 1 0; flex-direction: column; gap: 2px; min-height: 72px; padding: 6px 4px; font-size: 18px; }
  .shelf-tag { font-size: 16px; }
}

/* ---------- Short landscape phones: the tray moves to the right edge ---------- */

@media (max-height: 540px) and (orientation: landscape) {
  :root { --chrome: 48px; --sw: 46px; --tool: 46px; --gap: 10px; --action-w: 100%; }
  .dock {
    left: auto;
    right: max(10px, env(safe-area-inset-right));
    top: calc(max(10px, env(safe-area-inset-top)) + 58px);
    bottom: auto;
    translate: none;
    align-content: start;
    grid-template-areas: "shelf undo . ." "main main main main" "action action action action";
    grid-template-columns: repeat(4, var(--sw));
    padding: 8px;
  }
  .swatches { grid-auto-flow: row; grid-template-columns: repeat(4, var(--sw)); grid-template-rows: none; grid-auto-rows: var(--sw); min-height: 0; }
  .sticker-tray { flex-wrap: wrap; min-height: 0; }
  .sticker-button { width: 52px; height: 52px; }
  .sticker-button .sticker-art { width: 46px; height: 46px; }
  .action-button { height: 56px; font-size: 18px; }
  .task-panel { height: 52px; font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  .flash.go { opacity: 0 !important; }
}
