/* Zaika v doroge: a watercolour road atlas page with the shared Toddler Playroom chrome. */
:root {
  --ink: #30254d;
  --paper: #fffaf0;
  --plum: #7452b8;
  --shadow: #39295e;
  --star: #ffd84d;
  --tint: #fbf6e6;
  --muted-ink: #54476f;
  --tap-target: 64px;
  --hud-button: 56px;
  --dpad-ring: 196px;
  --dpad-button: 64px;
  --dpad-offset: 60px;
  --safe-top: max(10px, env(safe-area-inset-top));
  --safe-right: max(10px, env(safe-area-inset-right));
  --safe-bottom: max(14px, env(safe-area-inset-bottom));
  --safe-left: max(10px, env(safe-area-inset-left));
  --bounce: cubic-bezier(.2, .9, .25, 1.2);
  --rounded: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", system-ui, sans-serif;
  color-scheme: light;
}

#game-shell[data-chapter="clover-valley"] { --tint: #f4f6df; --accent: #6f9a4b; }
#game-shell[data-chapter="whispering-woods"] { --tint: #fbeedb; --accent: #c4672d; }
#game-shell[data-chapter="starlight-mountain"] { --tint: #edf1fb; --accent: #3e5ea8; }

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  background: #efe4cc;
  color: var(--ink);
  font-family: var(--rounded);
  -webkit-text-size-adjust: 100%;
}

#game-shell {
  position: fixed;
  inset: 0;
  min-height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

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

.icon {
  display: block;
  width: 26px;
  height: 26px;
}

/* ---------- HUD: task panel top-centre, sound then full screen top-right ---------- */

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

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

.task-panel {
  position: absolute;
  top: var(--safe-top);
  left: 50%;
  width: min(460px, calc(100vw - 300px));
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 8px 14px 9px 9px;
  border: 3px solid var(--ink);
  border-radius: 22px;
  background: var(--paper);
  box-shadow: 0 5px 0 var(--shadow), 0 10px 22px rgba(48, 37, 77, .18);
  transform: translateX(-50%);
}

.task-panel.is-placed { transform: none; }

.task-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--tint);
  color: var(--ink);
}

.task-icon .icon { width: 34px; height: 34px; }
.task-icon.is-fresh { animation: settle 280ms var(--bounce); }

.task-copy { min-width: 0; }

.task-title {
  margin: 0;
  font-size: 22px;
  font-weight: 950;
  line-height: 1.05;
  letter-spacing: .01em;
}

.task-chapter {
  margin: 2px 0 0;
  color: var(--muted-ink);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.15;
}

.task-line {
  margin: 4px 0 0;
  font-size: 20px;
  font-weight: 900;
  line-height: 1.15;
}

.task-short { display: none; }

.task-dots {
  display: flex;
  gap: 7px;
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
}

.task-dots li {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 2.5px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
}

.task-dots li.is-current { box-shadow: 0 0 0 3px var(--star); }
.task-dots li.is-done { background: var(--star); }
.task-dots .icon { width: 15px; height: 15px; stroke-width: 3; }

.hud-actions {
  position: absolute;
  top: var(--safe-top);
  right: var(--safe-right);
  display: flex;
  gap: 10px;
}

.hud-button,
.dpad-button,
.card-button,
.finale-chapter {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  font-family: var(--rounded);
  cursor: pointer;
  transition: transform 220ms cubic-bezier(.2, .9, .25, 1.6), background-color 150ms ease, opacity 150ms ease;
}

.hud-button {
  display: grid;
  place-items: center;
  width: var(--hud-button);
  height: var(--hud-button);
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--tint);
  color: var(--ink);
  box-shadow: 0 5px 0 var(--shadow);
}

.hud-button:active,
.card-button:active,
.finale-chapter:active {
  transform: scale(.94);
  transition-duration: 80ms;
}

.hud-button .sound-off,
.hud-button[aria-pressed="false"] .sound-on,
.hud-button .exit-full,
.hud-button.is-full .enter-full { display: none; }

.hud-button[aria-pressed="false"] .sound-off,
.hud-button.is-full .exit-full { display: block; }

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

/* ---------- Story panel: tipped-in illustration beside or below the map ---------- */

.story-panel {
  position: absolute;
  top: 140px;
  right: var(--safe-right);
  width: 236px;
  height: 260px;
  margin: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 22px;
  background: var(--paper);
  box-shadow: 0 5px 0 var(--shadow), 0 12px 26px rgba(48, 37, 77, .2);
  cursor: pointer;
  transition: opacity 260ms ease, transform 320ms var(--bounce), visibility 0s linear 0s;
}

.story-panel[data-open="false"] {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(14px) rotate(1deg);
  transition: opacity 220ms ease, transform 260ms ease, visibility 0s linear 260ms;
}

.story-panel[data-shape="band"] {
  grid-template-rows: none;
  grid-template-columns: minmax(96px, 34%) minmax(0, 1fr);
}

.story-art {
  position: relative;
  min-height: 0;
  background-color: var(--tint);
  background-repeat: no-repeat;
  background-size: 300%;
  border-bottom: 3px solid var(--ink);
}

.story-panel[data-shape="band"] .story-art {
  border-bottom: 0;
  border-right: 3px solid var(--ink);
}

.story-character {
  position: absolute;
  left: 50%;
  bottom: 2px;
  width: min(118px, 70%);
  transform: translateX(-50%);
}

.story-panel[data-shape="band"] .story-character { width: min(92px, 88%); }
.story-character .character { display: block; width: 100%; height: auto; }

.story-text {
  margin: 0;
  padding: 10px 14px 12px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 850;
  line-height: 1.3;
}

.story-panel[data-shape="band"] .story-text {
  align-self: center;
  padding: 8px 14px;
}

/* ---------- Steering pad: four round buttons inside a compass ring ---------- */

.dpad {
  position: absolute;
  right: calc(var(--safe-right) + 6px);
  bottom: var(--safe-bottom);
  width: var(--dpad-ring);
  height: var(--dpad-ring);
  border: 3px solid var(--ink);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, transparent 0 58%, rgba(48, 37, 77, .1) 58.5% 59.5%, transparent 60%),
    rgba(255, 250, 240, .86);
  box-shadow: 0 6px 0 rgba(57, 41, 94, .55), 0 12px 24px rgba(48, 37, 77, .18);
}

.dpad-button {
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  place-items: center;
  width: var(--dpad-button);
  height: var(--dpad-button);
  margin: calc(var(--dpad-button) / -2) 0 0 calc(var(--dpad-button) / -2);
  padding: 0;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--shadow);
  touch-action: none;
}

.dpad-up { transform: translateY(calc(var(--dpad-offset) * -1)); }
.dpad-down { transform: translateY(var(--dpad-offset)); }
.dpad-left { transform: translateX(calc(var(--dpad-offset) * -1)); }
.dpad-right { transform: translateX(var(--dpad-offset)); }

.dpad-up.pressed { transform: translateY(calc(var(--dpad-offset) * -1)) scale(.94); transition-duration: 80ms; }
.dpad-down.pressed { transform: translateY(var(--dpad-offset)) scale(.94); transition-duration: 80ms; }
.dpad-left.pressed { transform: translateX(calc(var(--dpad-offset) * -1)) scale(.94); transition-duration: 80ms; }
.dpad-right.pressed { transform: translateX(var(--dpad-offset)) scale(.94); transition-duration: 80ms; }

.dpad-button .icon { width: 30px; height: 30px; }
.dpad-button.is-wall { opacity: .42; box-shadow: 0 2px 0 var(--shadow); }
.dpad-button.is-glow { background: #ffe68a; box-shadow: 0 0 0 5px rgba(255, 216, 77, .6), 0 4px 0 var(--shadow); }

.dpad-center {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  transform: translate(-50%, -50%);
}

.dpad-center .pip-head { display: block; width: 100%; height: 100%; }

/* ---------- Celebration card and finale spread ---------- */

.celebration {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  align-items: start;
  justify-items: center;
  padding: max(9vh, calc(env(safe-area-inset-top) + 72px)) 12px 120px;
  background: rgba(48, 37, 77, .26);
}

.celebration[hidden] { display: none; }

.celebration-card {
  width: min(460px, 100%);
  padding: 14px 18px 20px;
  border: 3px solid var(--ink);
  border-radius: 28px;
  background: var(--paper);
  box-shadow: 0 8px 0 var(--shadow), 0 22px 44px rgba(31, 24, 51, .3);
  text-align: center;
  animation: card-in 340ms var(--bounce) both;
}

.celebration-star-wrap { display: grid; place-items: center; }
.celebration-star { width: 116px; height: 116px; animation: star-pop 420ms var(--bounce) both; }

.celebration-title {
  margin: 4px 0 14px;
  font-size: 30px;
  font-weight: 950;
  line-height: 1.1;
}

.finale-hint {
  margin: -6px 0 8px;
  color: var(--muted-ink);
  font-size: 16px;
  font-weight: 800;
}

.finale-chapters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.finale-chapter {
  position: relative;
  display: grid;
  gap: 6px;
  justify-items: center;
  min-height: 96px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
}

.finale-art {
  position: relative;
  width: 100%;
  max-width: 120px;
  aspect-ratio: 1;
  min-height: 96px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background-color: var(--tint);
  background-size: cover;
  background-position: center;
  box-shadow: 0 4px 0 var(--shadow);
}

.finale-art .stamp {
  position: absolute;
  top: -12px;
  right: -12px;
  width: 50px;
  height: 50px;
  transform: rotate(9deg);
}

.finale-label {
  font-size: 16px;
  font-weight: 850;
  line-height: 1.1;
}

.celebration-actions {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 12px;
}

.card-button {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 3px;
  min-height: var(--tap-target);
  padding: 7px 6px;
  border: 3px solid var(--ink);
  border-radius: 20px;
  background: var(--tint);
  color: var(--ink);
  box-shadow: 0 5px 0 var(--shadow);
  font-size: 17px;
  font-weight: 900;
  text-decoration: none;
}

.card-button-primary { background: var(--plum); color: #fffaf0; }
.card-button[hidden] { display: none; }
.card-icon .icon { width: 26px; height: 26px; }

.flyer {
  position: fixed;
  z-index: 70;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  color: #a86100;
  pointer-events: none;
  transition: transform 250ms cubic-bezier(.3, .7, .3, 1.25), opacity 120ms ease 210ms;
}

.flyer .icon { width: 44px; height: 44px; stroke-width: 2.8; }

/* ---------- Language: mixed-mode badge, animal name tag, naming word card ---------- */

.task-icon-wrap { position: relative; display: block; }

.language-badge {
  position: absolute;
  right: -7px;
  bottom: -5px;
  min-width: 28px;
  padding: 1px 5px;
  border: 2px solid var(--ink);
  border-radius: 9px;
  background: var(--star);
  color: var(--ink);
  font-size: 11px;
  font-weight: 950;
  line-height: 1.2;
  letter-spacing: .04em;
  text-align: center;
}

.language-badge[hidden] { display: none; }

.story-name {
  position: absolute;
  top: 7px;
  left: 7px;
  padding: 2px 9px;
  border: 2px solid var(--ink);
  border-radius: 11px;
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
  line-height: 1.2;
}

.word-card {
  position: fixed;
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 13px 5px 8px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 0 4px 0 var(--shadow);
  color: var(--ink);
  font-size: 22px;
  font-weight: 950;
  line-height: 1.1;
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, -100%);
  animation: word-pop 320ms var(--bounce);
  transition: opacity 300ms ease;
}

.word-card.is-leaving { opacity: 0; }
.word-card .word-icon { width: 28px; height: 28px; color: #a86100; }

.word-digit {
  display: grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--star);
  font-size: 20px;
}

@keyframes word-pop {
  0% { transform: translate(-50%, -60%) scale(.6); opacity: 0; }
  100% { transform: translate(-50%, -100%) scale(1); opacity: 1; }
}

@keyframes settle {
  0% { transform: scale(.8); }
  70% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

@keyframes star-pop {
  0% { transform: scale(.5) rotate(-12deg); opacity: 0; }
  70% { transform: scale(1.06) rotate(3deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(18px) scale(.96); }
  to { opacity: 1; transform: none; }
}

/* ---------- Portrait: steering pad bottom-centre ---------- */

@media (orientation: portrait) {
  .dpad {
    right: auto;
    left: 50%;
    transform: translateX(-50%);
  }
}

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

@media (max-width: 560px) {
  :root {
    --hud-button: 48px;
    --dpad-ring: 168px;
    --dpad-button: 56px;
    --dpad-offset: 51px;
    --tap-target: 60px;
  }

  .hud-actions { gap: 8px; }
  .icon { width: 24px; height: 24px; }

  .task-panel {
    top: max(6px, env(safe-area-inset-top));
    grid-template-columns: 32px minmax(0, 1fr);
    grid-template-rows: auto auto;
    column-gap: 7px;
    row-gap: 3px;
    min-height: 48px;
    max-height: 64px;
    padding: 4px 8px 4px 4px;
    border-width: 2.5px;
    border-radius: 16px;
  }

  .task-icon { width: 32px; height: 32px; border-width: 2.5px; }
  .task-icon .icon { width: 22px; height: 22px; }
  .task-copy { display: contents; }
  .task-title,
  .task-chapter,
  .task-full {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  .task-line { margin: 0; font-size: 16px; line-height: 1.05; }
  .task-short { display: inline; }
  .task-dots { grid-column: 1 / -1; gap: 5px; margin: 0 0 0 2px; }
  .task-dots li { width: 14px; height: 14px; border-width: 2px; }
  .task-dots .icon { width: 10px; height: 10px; }

  .story-text { font-size: 16px; padding: 6px 10px; }
  .story-name { top: 5px; left: 5px; padding: 1px 6px; font-size: 12px; }
  /* The phone panel is short: the badge sits at its right end instead of over the step dots. */
  .task-panel.is-second-row .task-icon-wrap { position: static; }
  .task-panel.is-second-row .language-badge { top: 50%; right: 9px; bottom: auto; transform: translateY(-50%); }
  .word-card { font-size: 18px; padding: 4px 10px 4px 6px; }
  .word-card .word-icon { width: 22px; height: 22px; }
  .word-digit { min-width: 24px; height: 24px; font-size: 16px; }
  .dpad-center { width: 38px; height: 38px; }
  .dpad-button .icon { width: 26px; height: 26px; }

  .celebration { padding-top: max(76px, calc(env(safe-area-inset-top) + 66px)); }
  .celebration-card { padding: 10px 12px 16px; }
  .celebration-star { width: 92px; height: 92px; }
  .celebration-title { font-size: 25px; }
  .finale-chapters { gap: 10px; }
  .card-button { font-size: 16px; border-radius: 18px; }
}

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