:root {
  --sky: #d6ecff; --ink: #1f2a5c; --white: #ffffff; --green: #1fbf5b; --green-dark: #128a40;
  --top-bar: 72px;   /* rule 1, amended 15 Nov: at most 72 px */
  --side: 8px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  background: var(--sky); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  touch-action: none; -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
#app { position: fixed; inset: 0; }
#topbar {
  position: absolute; left: 0; right: 0; top: 0;
  height: calc(var(--top-bar) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) max(var(--side), env(safe-area-inset-right, 0px)) 0 max(var(--side), env(safe-area-inset-left, 0px));
  display: flex; align-items: center; justify-content: flex-end;
}
#stage {
  position: absolute;
  top: calc(var(--top-bar) + env(safe-area-inset-top, 0px));
  left: max(var(--side), env(safe-area-inset-left, 0px));
  right: max(var(--side), env(safe-area-inset-right, 0px));
  bottom: env(safe-area-inset-bottom, 0px);
  display: flex; align-items: center; justify-content: center;
}
#board { position: relative; flex: 0 0 auto; }
.board-layer { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* Loading: background colour only. Error: only the error screen. */
#app[data-state="loading"] #topbar, #app[data-state="loading"] #stage,
#app[data-state="error"] #topbar, #app[data-state="error"] #stage { visibility: hidden; }

.kid-btn {
  display: grid; place-items: center; padding: 0; margin: 0;
  min-width: 64px; min-height: 64px; border-radius: 50%;
  color: var(--ink); background: var(--white); border: 4px solid var(--ink);
  cursor: pointer; touch-action: manipulation; font: inherit;
}
.kid-btn:active { transform: translateY(2px); }
.kid-btn:focus-visible { outline: 4px solid var(--green-dark); outline-offset: 3px; }
.kid-btn.speaker { width: 64px; height: 64px; }

.screen {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px calc(16px + env(safe-area-inset-bottom, 0px));
}
.finish { background: rgba(31, 42, 92, 0.55); }
.finish .finish-art { width: min(70vw, 280px); height: auto; filter: drop-shadow(0 4px 0 rgba(0,0,0,.18)); }
.kid-btn.again { width: 112px; height: 112px; background: var(--green); color: var(--white); border-color: var(--white); box-shadow: 0 6px 0 var(--green-dark); }
.finish:not(.still) .hop { animation: hop 0.45s ease-out 3 both; transform-origin: 50% 100%; transform-box: fill-box; }
.finish:not(.still) .star { animation: twinkle 0.6s ease-out 2 both; transform-origin: center; transform-box: fill-box; }
.finish:not(.still) .s2 { animation-delay: 0.15s; }
.finish:not(.still) .s3 { animation-delay: 0.3s; }
.finish:not(.still) .again { animation: pop 0.35s ease-out 0.2s both; }
@keyframes hop { 0%, 100% { transform: translateY(0); } 45% { transform: translateY(-18px); } }
@keyframes twinkle { 0% { transform: scale(0.4); opacity: 0; } 70% { transform: scale(1.2); opacity: 1; } 100% { transform: scale(1); } }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .finish *, .finish { animation: none !important; } }

.error { background: var(--sky); text-align: center; -webkit-user-select: text; user-select: text; }
.error h1 { margin: 0; font-size: 22px; }
.error p { margin: 0; max-width: 32em; }
.kid-btn.retry { border-radius: 999px; width: auto; padding: 0 28px 0 18px; grid-auto-flow: column; gap: 8px; font-size: 20px; font-weight: 700; }
.kid-btn.retry svg { width: 36px; height: 36px; }
