:root {
  color-scheme: light;
  --ink: #30254d;
  --paper: #fffaf0;
  --plum: #7452b8;
  --plum-dark: #4b2f8f;
  --shadow: #39295e;
  --star: #ffd84d;
  --star-edge: #a86100;
  --wood: #e3ac6c;
  --wood-dark: #b07a3f;
  --red: #e8473b;
  --blue: #3f6fd0;
  --green: #5fb550;
  --button: 56px;
  --gap: 12px;
  --bounce: cubic-bezier(.2, .9, .25, 1.2);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  font-family: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", system-ui, sans-serif;
  font-weight: 850;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #7d5cc4;
  color: var(--ink);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

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

button,
#game-canvas {
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible {
  outline: 4px solid #fff;
  outline-offset: 3px;
  box-shadow: 0 0 0 7px var(--plum);
}

#game-shell {
  position: fixed;
  inset: 0;
  min-height: 100dvh;
  isolation: isolate;
  overflow: hidden;
}

#game-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  outline: none;
}

#game-canvas:focus-visible {
  outline: 5px solid var(--star);
  outline-offset: -9px;
}

#game-canvas.dragging { cursor: grabbing; }

.icon {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------------------------------------------------------------- chrome */

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

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

.icon-button {
  display: grid;
  place-items: center;
  width: var(--button);
  height: var(--button);
  min-height: 48px;
  padding: 0;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 0 5px 0 var(--shadow);
  cursor: pointer;
  transition: transform 180ms var(--bounce), box-shadow 120ms ease-out;
}

.icon-button:active,
.action-button:active,
.play-button:active,
.gate:active,
.float:active,
.sample-button:active {
  transform: scale(.94);
  transition-duration: 80ms;
}

.chrome-actions {
  position: absolute;
  top: calc(var(--safe-top) + var(--gap));
  right: calc(var(--safe-right) + var(--gap));
  display: grid;
  grid-auto-flow: column;
  gap: var(--gap);
}

#sound-button .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; }
#sound-button[aria-pressed="false"] { background: #e9e2f6; }

.task-panel {
  position: absolute;
  top: calc(var(--safe-top) + var(--gap));
  left: 0;
  right: 0;
  width: max-content;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 56px auto;
  align-items: center;
  gap: 10px;
  height: 64px;
  max-width: min(420px, calc(100vw - 2 * 148px));
  padding: 3px 16px 3px 3px;
  border: 3px solid var(--ink);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 5px 0 var(--shadow);
}

#game-shell[data-phase="start"] .task-panel { display: none; }

.sample-button {
  width: 56px;
  height: 52px;
  padding: 0;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
  transition: transform 180ms var(--bounce);
}

.sample-button canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.task-copy {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.task-text {
  margin: 0;
  overflow: hidden;
  font-size: 20px;
  font-weight: 900;
  line-height: 1.1;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.task-text.feedback { color: var(--plum-dark); }

/* In MIX the task panel names the level language with a small drawn letter tag. */
.lang-badge {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 20px;
  margin-left: auto;
  padding: 0 6px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--star);
  font-size: 16px;
  font-weight: 950;
  line-height: 1;
  letter-spacing: .02em;
}
.lang-badge[data-lang="en"] { background: #bfe3ff; }
.lang-badge[data-lang="et"] { background: #c9f0c0; }

.task-progress {
  display: flex;
  align-items: center;
  gap: 12px;
}

.piece-dots,
.world-dots {
  display: flex;
  gap: 5px;
}

.piece-dots i,
.world-dots i {
  width: 12px;
  height: 12px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: #fff;
  transition: transform 250ms var(--bounce), background 200ms ease-out;
}

.piece-dots i.on { background: var(--green); transform: scale(1.15); }
.world-dots { padding-left: 10px; border-left: 2px solid rgba(48, 37, 77, .25); }
.world-dots i { width: 10px; height: 10px; border-radius: 3px; }
.world-dots i.done { background: var(--star); }
.world-dots i.current { box-shadow: 0 0 0 2px var(--plum); }

.icon-steps { fill: var(--ink); stroke-width: 1.2; }

.show-place-button {
  position: absolute;
  z-index: 20;
  right: calc(var(--safe-right) + var(--gap));
  bottom: calc(var(--safe-bottom) + var(--gap));
  background: #fff1c2;
}

/* ---------------------------------------------------------------- guide */

.guide-layer {
  position: absolute;
  z-index: 15;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.guide-path {
  display: none;
  fill: none;
  stroke: var(--paper);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-dasharray: 0 19;
  filter: drop-shadow(0 2px 0 rgba(48, 37, 77, .55));
  animation: march 900ms linear infinite;
}

.guide-hand {
  display: none;
  scale: 1.5;
  fill: var(--paper);
  stroke: var(--ink);
  stroke-width: 2.5;
  stroke-linejoin: round;
}

.guide-path-on .guide-path,
.guide-hand-on .guide-hand { display: block; }

@keyframes march { to { stroke-dashoffset: -38; } }

/* ---------------------------------------------------------------- start screen */

.start-screen {
  position: absolute;
  z-index: 30;
  inset: 0;
  display: grid;
  justify-items: center;
  align-content: center;
  overflow-y: auto;
  padding:
    calc(var(--safe-top) + 84px)
    calc(var(--safe-right) + 14px)
    calc(var(--safe-bottom) + 18px)
    calc(var(--safe-left) + 14px);
}

.start-inner {
  width: min(760px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  gap: 14px;
  padding: 0 18px 22px;
  border: 3px solid var(--ink);
  border-radius: 28px;
  background: var(--paper);
  box-shadow: 0 8px 0 var(--shadow);
  text-align: center;
}

.bunting {
  justify-self: stretch;
  width: 100%;
  height: 58px;
  margin-bottom: -6px;
}

.bunting-string { fill: none; stroke: var(--ink); stroke-width: 3; }
.flag { stroke: var(--ink); stroke-width: 2.5; stroke-linejoin: round; }
.flag-red { fill: var(--red); }
.flag-yellow { fill: var(--star); }
.flag-blue { fill: #3f9de8; }
.flag-green { fill: var(--green); }

h1 {
  margin: 0;
  color: var(--plum-dark);
  font-size: 32px;
  font-weight: 950;
  line-height: 1.05;
}

.subtitle {
  margin: -4px 0 0;
  font-size: 18px;
  font-weight: 800;
}

.parade-ground {
  width: 100%;
  padding: 10px 0 6px;
  border-radius: 18px;
  background:
    linear-gradient(transparent 76%, rgba(48, 37, 77, .1) 76% 79%, transparent 79%),
    #f3dcae;
  border: 3px solid var(--ink);
}

.parade {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding: 4px 12px 6px;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  touch-action: pan-x;
}

.parade::-webkit-scrollbar { display: none; }

.float {
  flex: 0 0 auto;
  display: grid;
  justify-items: center;
  width: 92px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  scroll-snap-align: center;
  transition: transform 180ms var(--bounce);
  touch-action: manipulation;
}

.float-picture {
  display: grid;
  place-items: center;
  width: 84px;
  height: 70px;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: #fff;
}

.float-picture canvas { display: block; width: 100%; height: 100%; object-fit: contain; }

.float-cart {
  width: 92px;
  height: 31px;
  margin-top: -2px;
  overflow: visible;
}

.cart-bed { fill: var(--wood); stroke: var(--ink); stroke-width: 2.5; }
.cart-line { stroke: var(--wood-dark); stroke-width: 2; stroke-linecap: round; }
.wheel circle { fill: var(--ink); stroke: var(--ink); stroke-width: 2; }
.wheel path { stroke: #c8ced9; stroke-width: 2; stroke-linecap: round; }

.float.empty { cursor: default; opacity: .55; }
.float.empty .float-picture { border-style: dashed; background: rgba(255, 255, 255, .45); }
.float.empty .cart-bed { fill: #f6e7c8; stroke-dasharray: 5 4; }

.gates {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--gap);
  width: 100%;
}

.gate {
  display: grid;
  justify-items: center;
  gap: 4px;
  min-height: 104px;
  padding: 10px 6px;
  border: 3px solid var(--ink);
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 5px 0 var(--shadow);
  cursor: pointer;
  transition: transform 180ms var(--bounce);
}

.gate-meadow { background: #e4f5d6; }
.gate-town { background: #fbe1d6; }
.gate-sky { background: #dfe7fb; }

.gate-icon {
  width: 46px;
  height: 46px;
  fill: var(--paper);
  stroke: var(--ink);
  stroke-width: 1.6;
  stroke-linejoin: round;
}

.gate-meadow .gate-icon { fill: #9fd57a; }
.gate-town .gate-icon { fill: #f2a07f; }
.gate-sky .gate-icon { fill: #9db3ee; }

.gate-name { font-size: 18px; font-weight: 900; }

.gate-dots { display: flex; gap: 5px; }
.gate-dots i {
  width: 12px;
  height: 12px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: #fff;
}
.gate-dots i.on { background: var(--star); }

.gate.suggested { animation: gate-glow 1.8s ease-in-out infinite; }

@keyframes gate-glow {
  0%, 100% { transform: scale(1); box-shadow: 0 5px 0 var(--shadow); }
  50% { transform: scale(1.04); box-shadow: 0 5px 0 var(--shadow), 0 0 0 6px rgba(255, 216, 77, .75); }
}

.play-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 200px;
  min-height: 64px;
  padding: 0 28px;
  border: 3px solid var(--ink);
  border-radius: 20px;
  background: var(--star);
  box-shadow: 0 6px 0 var(--shadow);
  font-size: 24px;
  font-weight: 950;
  cursor: pointer;
  transition: transform 180ms var(--bounce);
}

/* ---------------------------------------------------------------- completion */

.celebration {
  position: absolute;
  z-index: 25;
  left: var(--party-x, 0);
  top: var(--party-y, 0);
  width: var(--party-w, 100%);
  height: var(--party-h, 100%);
  display: grid;
  place-items: center;
  pointer-events: none;
}

.celebration-card {
  display: grid;
  justify-items: center;
  gap: 8px;
  max-width: 100%;
  max-height: 100%;
  padding: 12px 14px 14px;
  border: 3px solid var(--ink);
  border-radius: 24px;
  background: var(--paper);
  box-shadow: 0 6px 0 var(--shadow);
  pointer-events: auto;
  animation: card-in 320ms var(--bounce) both;
}

.celebration-star {
  width: 64px;
  height: 64px;
  fill: #ffd84d;
  stroke: #a86100;
  stroke-width: 1.4;
  stroke-linejoin: round;
  animation: star-pop 520ms var(--bounce) both;
}

.celebration-text {
  margin: 0;
  font-size: 26px;
  font-weight: 950;
  text-align: center;
  line-height: 1.1;
}

.celebration-sub {
  margin: 0;
  font-size: 18px;
  font-weight: 900;
  text-align: center;
  line-height: 1.15;
  color: var(--plum-dark);
}

.celebration-actions {
  display: grid;
  grid-auto-flow: column;
  gap: var(--gap);
}

.stacked .celebration-actions { grid-auto-flow: row; width: 100%; }
.stacked .celebration-star { width: 72px; height: 72px; }
.compact .celebration-actions { gap: 10px; }
.compact .action-button {
  flex-direction: column;
  gap: 2px;
  min-width: 84px;
  padding: 4px 8px;
  font-size: 16px;
}
.compact .action-button .icon { width: 24px; height: 24px; }
.compact .celebration-star { width: 52px; height: 52px; }
.compact .celebration-text { font-size: 22px; }

.action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 64px;
  min-height: 64px;
  padding: 0 16px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 5px 0 var(--shadow);
  font-size: 18px;
  font-weight: 900;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 180ms var(--bounce);
}

.action-next { background: var(--star); }

@keyframes card-in { from { opacity: 0; transform: translateY(14px) scale(.96); } }
@keyframes star-pop { 0% { transform: scale(.2) rotate(-40deg); } 70% { transform: scale(1.12) rotate(6deg); } 100% { transform: scale(1); } }

.parade-stage {
  position: absolute;
  z-index: 18;
  left: var(--board-x);
  top: var(--board-y);
  width: var(--board-w);
  height: var(--board-h);
  display: grid;
  align-content: center;
}

.parade-stage .parade {
  justify-content: safe center;
  padding: 16px 14px 10px;
  border: 3px solid var(--ink);
  border-radius: 22px;
  background:
    linear-gradient(transparent 80%, rgba(48, 37, 77, .12) 80% 83%, transparent 83%),
    #f3dcae;
  box-shadow: 0 6px 0 var(--shadow);
}

.parade-stage .float { width: 112px; }
.parade-stage .float-picture { width: 104px; height: 86px; }
.parade-stage .float-cart { width: 112px; height: 38px; }

.float.arriving { opacity: 0; }
.float.rolled-in { animation: roll-in 420ms var(--bounce) both; }
.float.rolled-in .wheel { animation: wheel-spin 420ms linear 1; transform-box: fill-box; transform-origin: center; }

@keyframes roll-in { from { transform: translateX(-18px); } }
@keyframes wheel-spin { to { rotate: 360deg; } }

.parade.lap .float { animation: parade-hop 900ms ease-in-out 3 both; }
.parade.lap .float:nth-child(3n + 2) { animation-delay: 150ms; }
.parade.lap .float:nth-child(3n) { animation-delay: 300ms; }

@keyframes parade-hop {
  0%, 100% { transform: translate(0, 0); }
  30% { transform: translate(8px, -12px) rotate(-3deg); }
  60% { transform: translate(14px, 0) rotate(2deg); }
}

.flyer {
  position: fixed;
  z-index: 40;
  border: 4px solid var(--ink);
  border-radius: 14px;
  background: #fff;
  transform-origin: 0 0;
  transition: transform 780ms cubic-bezier(.45, .05, .25, 1);
  pointer-events: none;
}

/* ---------------------------------------------------------------- misc */

.error-card {
  position: absolute;
  z-index: 100;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  padding: 28px;
  border: 3px solid var(--ink);
  border-radius: 24px;
  background: var(--paper);
  font-size: 22px;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.insets-probe {
  position: fixed;
  visibility: hidden;
  pointer-events: none;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

@media (max-width: 639px) {
  /* Below the platform corner (home, stars, language): game-core.mjs layout() panelTopPx. */
  .task-panel {
    top: calc(max(10px, var(--safe-top)) + 112px);
    max-width: calc(100vw - 24px);
  }
  .start-screen { padding-top: calc(var(--safe-top) + 76px); }
  .start-inner { gap: 12px; padding: 0 12px 16px; }
  .gate { min-height: 96px; }
}

@media (max-width: 480px) {
  :root { --button: 48px; }
  .task-panel { top: calc(max(10px, var(--safe-top)) + 108px); }
  .icon-button { border-radius: 16px; }
  .icon { width: 26px; height: 26px; }
  .task-text { font-size: 18px; }
  .celebration-text { font-size: 22px; }
  .action-button { padding: 0 10px; font-size: 16px; gap: 6px; }
  .action-button .icon { width: 22px; height: 22px; }
  .celebration-card { gap: 6px; padding: 8px 10px 12px; }
  .celebration-star { width: 52px; height: 52px; }
  .play-button { min-width: 180px; }
}

@media (max-height: 560px) and (orientation: landscape) {
  .start-screen { align-content: start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .guide-path { animation: none; }
}
