:root {
  --bg: #fff6e6;
  --card: #ffffff;
  --ink: #3a3350;
  --soft: #8a83a3;
  --accent: #6c8cff;
  --good: #59b97c;
  --hint: #ffd45c;
  --star: #f5b82e;
  --shadow: 0 6px 0 rgba(58, 51, 80, 0.12), 0 10px 24px rgba(58, 51, 80, 0.08);
  --radius: 28px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;          /* no pull-to-refresh */
  touch-action: manipulation;          /* no double-tap zoom */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.12s ease, opacity 0.3s ease, background 0.3s ease;
}
button:active { transform: translateY(3px) scale(0.98); }
button svg { width: 55%; height: 55%; }

.screen { flex: 1; display: flex; flex-direction: column; align-items: center; min-height: 0; }
.center { justify-content: center; gap: 28px; }

/* Start */
.big-play {
  width: min(56vw, 240px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--good);
  color: #fff;
  animation: breathe 2.4s ease-in-out infinite;
}
.big-play svg { margin-left: 8%; }

/* Ride picker */
.ride-picker { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 24px; width: 100%; }
.ride-picker h1 { margin: 0; font-size: 28px; }
.rides { display: grid; grid-template-columns: repeat(2, minmax(0, 150px)); gap: 16px; justify-content: center; }
.ride-choice { aspect-ratio: 1; padding: 14px; }
.ride-choice:last-child { grid-column: 1 / -1; width: 150px; justify-self: center; }
.ride-choice img { width: 100%; height: auto; }
.ride-choice.picked { background: var(--hint); animation: pop 0.45s ease; }

/* Journey: the road with one stop per round */
.journey {
  position: relative;
  height: min(calc(100dvh - 80px), 170vw);
  aspect-ratio: 360 / 640;
  max-width: 100%;
  margin: 48px auto 0;
}
.road { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.road path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.road-edge { stroke: #e3d3b5; stroke-width: 44; }
.road-top { stroke: #f1e6cf; stroke-width: 34; }
.road-line { stroke: #ffffff; stroke-width: 4; stroke-dasharray: 10 12; }
.stop {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 27%;
  aspect-ratio: 1;
  border-radius: 50%;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 5px solid #fff;
}
/* Keep the centring while pressed: the shared button:active rule would replace
   translate(-50%, -50%), the stop would jump from under the finger and the tap be lost. */
.stop:active { transform: translate(-50%, -50%) scale(0.96); }
.stop.started { border-color: var(--accent); }
.stop.done { border-color: var(--star); }
.stop-pic { width: 54%; aspect-ratio: 1; display: grid; place-items: center; }
.stop-pic img { width: 100%; height: auto; }
.stop .mini-stars { position: absolute; bottom: -22px; background: var(--card); border-radius: 999px; padding: 2px 6px; box-shadow: var(--shadow); }
/* On the road while driving; parked just above its stop so the picture shows. */
.ride {
  position: absolute;
  transform: translate(-50%, -70%);
  transition: transform 0.3s ease;
  width: 22%;
  padding: 0;
  background: none;
  box-shadow: none;
  z-index: 2;
  pointer-events: none;   /* its see-through edges must never catch taps meant for a stop */
}
.ride-chip {
  position: fixed;
  right: 12px;
  top: 12px;
  width: 64px;
  height: 52px;
  padding: 6px;
  border-radius: 999px;
}
.ride-chip img { width: 100%; height: 100%; object-fit: contain; }
.ride img { width: 100%; height: auto; display: block; filter: drop-shadow(0 4px 2px rgba(58, 51, 80, 0.2)); }
.ride.flip img { transform: scaleX(-1); }
.journey:not(.driving) .ride { transform: translate(-50%, -158%); }
.journey:not(.driving) .ride img { animation: idle 1.6s ease-in-out infinite; }
.journey.driving .stop { pointer-events: none; }
.mini-stars { display: flex; gap: 2px; color: var(--star); height: 20px; }
.mini-stars svg { width: 14px; height: 14px; }
.mini-stars .empty { color: #e7e2ef; }
@keyframes idle { 50% { transform: translateY(-4px); } }
.ride.flip img { animation: none; }

.parent {
  position: fixed;
  right: 10px;
  bottom: max(10px, env(safe-area-inset-bottom));
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--soft);
  background: transparent;
  box-shadow: none;
  opacity: 0.5;
}
.parent .ring { position: absolute; inset: 0; border-radius: 50%; }

/* Question */
.topbar {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
  flex-shrink: 0;
}
.topbar .home { width: 52px; height: 52px; border-radius: 18px; color: var(--soft); }
.dots { flex: 1; display: flex; justify-content: center; gap: 8px; }
.dot { width: 16px; height: 16px; border-radius: 50%; background: #e7e2ef; transition: background 0.3s; }
.dot.done { background: var(--star); }
.dot.now { background: var(--accent); }
/* Second-chance pictures: hollow rings after a small "again" arrow, added the
   moment a wrong letter is tapped, so it is clear why the round gets longer. */
.dots .again-mark { width: 18px; height: 18px; margin-left: 6px; color: var(--soft); display: grid; place-items: center; }
.dots .again-mark svg { width: 18px; height: 18px; }
.dot.repeat { background: transparent; box-shadow: inset 0 0 0 3px var(--soft); }
.dot.repeat.now { box-shadow: inset 0 0 0 3px var(--accent); background: transparent; }
.dot.repeat.done { box-shadow: none; background: var(--soft); }
.dot.tried { background: #c9c3d8; }
.dot.repeat.added { animation: pop 0.5s ease; }
.again-badge {
  position: absolute;
  left: -12px;
  top: -12px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--card);
  color: var(--accent);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
}
.again-badge svg { width: 30px; height: 30px; }

.stage {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
}
.picture-wrap { position: relative; }
.picture {
  width: min(70vw, 40dvh, 340px);
  aspect-ratio: 1;
  padding: 6%;
  background: var(--card);
  border-radius: 36px;
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
}
.picture img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.picture.pop { animation: pop 0.5s ease; }

.speaker {
  position: absolute;
  right: -14px;
  bottom: -14px;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
}
.speaker.playing { animation: pulse 1s ease-in-out infinite; }

.choices {
  width: 100%;
  max-width: 480px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.letter {
  height: clamp(96px, 15dvh, 130px);
  font-size: clamp(56px, 10dvh, 84px);
  font-weight: 600;
  line-height: 1;
  padding-bottom: 0.12em;
}
.letter.waiting { opacity: 0.55; pointer-events: none; }
.letter.gone { opacity: 0; pointer-events: none; transform: scale(0.8); }
.letter.correct { background: var(--good); color: #fff; }
.letter.hint { background: var(--hint); animation: pulse 1s ease-in-out infinite; }

.after {
  height: 96px;
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  flex-shrink: 0;
}
.replay-sound {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  color: var(--accent);
  font-size: 30px;
  font-weight: 600;
  grid-auto-flow: column;
  gap: 2px;
  padding: 0 8px;
}
.replay-sound svg { width: 26px; height: 26px; }
.next {
  width: 120px;
  height: 88px;
  background: var(--good);
  color: #fff;
  animation: breathe 2.4s ease-in-out infinite;
}
.hidden { visibility: hidden; }

.fly-star {
  position: fixed;
  width: 72px;
  height: 72px;
  color: var(--star);
  pointer-events: none;
  z-index: 10;
  transition: transform 0.8s cubic-bezier(.5,-0.3,.6,1), opacity 0.8s;
}

/* Round end */
.end-stars {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 360px;
  color: var(--star);
}
.end-stars svg { width: 64px; height: 64px; animation: pop 0.5s ease backwards; }
.end-buttons { display: flex; gap: 20px; }
.end-buttons button { width: 120px; height: 104px; }
.end-buttons .go { background: var(--good); color: #fff; }

/* Child's name: asked once after Play, changed from the badge on the rounds screen */
.name-screen {
  width: min(100%, 480px);
  margin: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.name-screen h1 { font-size: 26px; line-height: 1.25; margin: 0; }
.name-screen p { margin: 0; line-height: 1.45; color: var(--soft); }
.name-shown { color: var(--accent); }
.name-input {
  font: inherit;
  font-size: 30px;
  text-align: center;
  padding: 14px 16px;
  border: 3px solid #e7e2ef;
  border-radius: 20px;
  background: var(--card);
  color: var(--ink);
  user-select: text;
  -webkit-user-select: text;
  outline: none;
}
.name-input:focus { border-color: var(--accent); }
.name-msg { min-height: 1.4em; color: #c4453c !important; }
.name-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.name-actions .p-btn { display: flex; align-items: center; justify-content: center; gap: 8px; }
.name-actions .p-btn svg { width: 22px; height: 22px; }
.name-actions .n-save { background: var(--good); color: #fff; min-width: 140px; }
.name-actions .n-save:disabled { opacity: 0.7; }
.ways { display: flex; flex-direction: column; gap: 10px; }
.way { display: flex; gap: 10px; }
.way .way-play { flex: 1; display: flex; align-items: center; gap: 10px; justify-content: flex-start; font-size: 20px; }
.way .way-play svg { width: 22px; height: 22px; color: var(--accent); }
.way .way-use { min-width: 110px; }
.way .p-btn:disabled { opacity: 0.6; }
.way-own { display: flex; gap: 10px; }
.way-own .way-input { flex: 1; min-width: 0; font-size: 20px; padding: 10px 14px; }
.name-wifi { color: var(--soft); width: 72px; height: 72px; margin: 0 auto; }
.name-wifi svg { width: 100%; height: 100%; }
.name-badge {
  position: fixed;
  left: 12px;
  top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 10px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 600;
  color: var(--soft);
  max-width: 60vw;
}
.name-badge svg { width: 22px; height: 22px; flex: none; }
.name-badge span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Parent screen (behind the 3-second gear) */
.parent-panel {
  width: min(100%, 520px);
  padding: 20px 16px 32px;
  overflow-y: auto;
  user-select: text;
}
.parent-panel h1 { font-size: 26px; margin: 4px 0 16px; }
.parent-panel h2 { font-size: 19px; margin: 0 0 6px; }
.parent-panel p { margin: 0 0 12px; line-height: 1.45; }
.parent-panel section { background: var(--card); border-radius: 20px; padding: 16px; margin-bottom: 16px; }
.parent-row { display: flex; flex-wrap: wrap; gap: 10px; }
.p-btn { padding: 0 18px; min-height: 52px; border-radius: 16px; font-size: 17px; font-weight: 600; background: var(--bg); }
.p-back { width: 100%; background: var(--good); color: #fff; }
.p-note { color: var(--soft); font-size: 15px; }
.p-message:empty { display: none; }

@keyframes breathe { 50% { transform: scale(1.05); } }
@keyframes pulse { 50% { transform: scale(1.06); } }
@keyframes pop { 0% { transform: scale(0.6); opacity: 0; } 70% { transform: scale(1.08); } 100% { transform: scale(1); opacity: 1; } }

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