:root {
  --ink: #2a2118;
  --muted: #6e5b48;
  --paper: #fffaf2;
  --sun: #ffc857;
  --sun-dark: #e39b16;
  --good: #218a52;
  --bad: #e15d4a;
  --carry: #d4532b;
  --sky: #8fd4f5;
  --shadow: 0 14px 34px rgba(70, 42, 16, 0.12);
  font-family: "Fredoka", "Avenir Next", "Trebuchet MS", sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background: linear-gradient(#b7e7fb 0%, #e7f8cf 46%, #fff3d8 100%);
  overflow-x: hidden;
}

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

#app { min-height: 100dvh; }

.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 8px;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

h1 {
  margin: 0;
  font-size: clamp(1.7rem, 4vw, 2.4rem);
  line-height: 1.05;
}

.blurb {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.ghost {
  appearance: none;
  border: 0;
  background: rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(70, 42, 16, 0.08);
}

.ghost:active { transform: translateY(2px); }

.map-wrap {
  flex: 1;
  min-height: 0;
  padding: 6px 14px 0;
  display: grid;
  place-items: center;
}

.map-frame {
  width: min(100%, calc((100dvh - 196px) * 1.777));
  background: linear-gradient(#f8d98a, #e7b45c);
  border-radius: 28px;
  padding: 10px;
  box-shadow: var(--shadow);
}

.map-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 20px;
  overflow: hidden;
  background: #9ad7f6;
}

.map-stage svg {
  width: 100%;
  height: 100%;
  display: block;
}

.pin {
  position: absolute;
  transform: translate(-50%, 6px);
  background: rgba(255, 250, 242, 0.94);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: clamp(0.68rem, 1.5vw, 0.92rem);
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 3px 0 rgba(70, 42, 16, 0.12);
  pointer-events: none;
}

.pin.is-now {
  background: var(--sun);
  transform: translate(-50%, 6px) scale(1.06);
}

.pin.is-done { color: var(--good); }

.banner {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  background: #fffaf2;
  border-radius: 18px;
  padding: 10px 16px;
  font-weight: 700;
  box-shadow: var(--shadow);
  z-index: 2;
  text-align: center;
  max-width: min(90%, 420px);
}

.footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px calc(14px + env(safe-area-inset-bottom));
}

.btn {
  appearance: none;
  border: 0;
  background: var(--sun);
  color: var(--ink);
  font-weight: 700;
  font-size: 1.3rem;
  border-radius: 999px;
  padding: 14px 28px;
  min-height: 58px;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--sun-dark);
}

.btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--sun-dark);
}

.btn:disabled {
  cursor: default;
  transform: none;
}

.btn-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.linkish {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.95rem;
  padding: 8px;
}

.stage-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  padding: 8px 18px 12px;
  overflow: auto;
}

.play {
  display: grid;
  grid-template-columns: minmax(0, 520px) 220px;
  gap: 8px 8px;
  align-items: start;
  justify-content: center;
  width: min(860px, 100%);
  margin: 0 auto;
}

.card {
  background: var(--paper);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 22px 22px 18px;
  border: 4px solid transparent;
}

.sheet {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.card.is-wrong {
  border-color: var(--bad);
  background: #fff3f0;
  animation: shake 0.35s ease;
}

.card.is-right { border-color: var(--good); }

.prompt {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 1.05rem;
}

.task-line {
  margin: 0 0 12px;
  font-size: clamp(1.2rem, 3vw, 1.6rem);
  font-weight: 700;
}

.sum {
  display: grid;
  grid-template-columns: 1.15em repeat(var(--cols), 0.78em);
  justify-content: end;
  column-gap: 0.06em;
  font-size: clamp(2.1rem, 7vw, 3.5rem);
  font-weight: 700;
  line-height: 1.12;
  font-variant-numeric: tabular-nums;
  margin-left: auto;
  width: fit-content;
}

.sum .op { text-align: center; }

.sum .cell { text-align: center; min-height: 1.05em; }

.sum .line {
  grid-column: 1 / -1;
  height: 4px;
  border-radius: 4px;
  background: var(--ink);
  margin: 6px 0 8px;
}

.carry {
  color: var(--carry);
  font-size: 0.48em;
  line-height: 1;
  align-self: end;
}

.help .sum .cell[data-place] {
  border-radius: 8px;
  animation: colpop 0.7s ease both;
  animation-delay: calc(var(--i) * 0.55s);
}

.note {
  margin: 14px 0 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.note.bad { color: var(--bad); }
.note.good { color: var(--good); }

.help {
  margin-top: 16px;
  background: #fff7ea;
  border-radius: 18px;
  padding: 12px 14px 8px;
}

.help h2 {
  margin: 0 0 4px;
  font-size: 1.25rem;
}

.help p { margin: 0 0 10px; }

.help ol {
  margin: 8px 0 4px;
  padding-left: 1.2em;
}

.help li { margin: 0 0 6px; }

.quiz-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 12px;
}

.quiz-form input {
  width: min(100%, 220px);
  font-size: 2rem;
  font-weight: 700;
  text-align: right;
  border-radius: 16px;
  border: 3px solid #ecd9b8;
  background: white;
  padding: 8px 14px;
  font-variant-numeric: tabular-nums;
}

.quiz-form input:focus {
  outline: 3px solid var(--sun);
  border-color: var(--sun-dark);
}

.buddy {
  position: relative;
  height: auto;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  margin-top: 36px;
  pointer-events: none;
}

.buddy.is-leaving { animation: dog-leave 0.7s ease-in forwards; }
.buddy.is-entering { animation: dog-enter 0.72s ease-out; }

.dog-bob { animation: bob 2.4s ease-in-out infinite; }

.buddy.is-leaving .dog-bob,
.buddy.is-entering .dog-bob { animation: none; }

.pico { width: 210px; height: auto; display: block; }

.pico .leg,
.pico .tail,
.pico .wheel {
  transform-box: fill-box;
  transform-origin: center top;
}

.pico.is-run { animation: runbob 0.28s ease-in-out infinite; }

.pico.is-run .leg-a { animation: step 0.22s ease-in-out infinite; }
.pico.is-run .leg-b { animation: step 0.22s ease-in-out infinite reverse; }
.pico.is-run.on-board .leg { animation: none; }
.pico.is-run .wheel {
  transform-origin: center;
  animation: spin 0.28s linear infinite;
}

.pips {
  display: flex;
  gap: 6px;
  justify-content: center;
  padding: 4px 18px 0;
}

.pip {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: inset 0 0 0 2px rgba(42, 33, 24, 0.18);
}

.pip.is-now { background: var(--sun); box-shadow: none; transform: scale(1.25); }
.pip.is-done { background: var(--good); box-shadow: none; }
.pip.is-bad { background: var(--bad); box-shadow: none; }

.intro {
  width: min(560px, 100%);
  margin: 0 auto;
  text-align: center;
}

.intro .pico { width: 230px; margin: 0 auto; }

.cloud-drift { animation: drift 7s ease-in-out infinite alternate; }
.smoke { animation: smoke 2.8s ease-out infinite; transform-box: fill-box; transform-origin: center; }
.bobber { animation: bob 2.2s ease-in-out infinite; }
.wing { animation: wing 2.8s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }

.map-dog .tail { animation: wag 1.1s ease-in-out infinite; }
.map-dog.is-run .leg-a { animation: step 0.22s ease-in-out infinite; }
.map-dog.is-run .leg-b { animation: step 0.22s ease-in-out infinite reverse; }
.map-dog.is-run.on-board .leg { animation: none; }
.map-dog.is-run .wheel {
  transform-box: fill-box;
  transform-origin: center;
  animation: spin 0.28s linear infinite;
}

@keyframes dog-leave {
  to { transform: translateX(108vw); }
}

@keyframes dog-enter {
  from { transform: translateX(-70vw); }
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

@keyframes runbob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes wag {
  0%, 100% { transform: rotate(8deg); }
  50% { transform: rotate(-16deg); }
}

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

@keyframes colpop {
  0% { background: transparent; }
  35% { background: #ffe08a; }
  100% { background: transparent; }
}

@keyframes drift {
  from { transform: translateX(-8px); }
  to { transform: translateX(14px); }
}

@keyframes smoke {
  0% { opacity: 0.7; transform: translateY(0) scale(0.8); }
  100% { opacity: 0; transform: translateY(-16px) scale(1.3); }
}

@keyframes wing {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(12deg); }
}

@media (max-width: 760px) {
  .play { grid-template-columns: minmax(0, 1fr) 158px; }
  .pico { width: 150px; }
  .sheet { flex-wrap: wrap; }
  .footer { justify-content: center; }
}

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