/* Shape colours: a deep tone for light backgrounds, a pale tone for dark ones. */
:root { --deep: #3F6E8C; --pale: #9FC3D9; }
[data-shape-color="green"] { --deep: #3F7358; --pale: #A5D0B4; }
[data-shape-color="plum"]  { --deep: #75507F; --pale: #CDB3D6; }
[data-shape-color="clay"]  { --deep: #A9503A; --pale: #E3B3A2; }
[data-shape-color="slate"] { --deep: #55606B; --pale: #BFC8D0; }
[data-shape-color="red"]    { --deep: #CF3F2E; --pale: #F2A79C; }
[data-shape-color="orange"] { --deep: #C95F0A; --pale: #F3BE8A; }
[data-shape-color="pink"]   { --deep: #CF3D86; --pale: #F0A8CB; }
[data-shape-color="teal"]   { --deep: #0A716C; --pale: #8FD6D0; }
[data-shape-color="purple"] { --deep: #7650C8; --pale: #C4B0F0; }
[data-shape-color="blue"]   { --deep: #3F6E8C; --pale: #9FC3D9; }

/* Palettes. Shape against background is at least 3:1, except "soft", which an adult chooses on purpose. */
:root, [data-palette="light"] {
  --bg: #EEF1EC; --shape: var(--deep); --on-shape: #F4F7F5;
  --ink: #2E3A40; --soft: #C9D2CD; --panel: #FFFFFF;
}
[data-palette="dark"] {
  --bg: #1E2530; --shape: var(--pale); --on-shape: #1E2530;
  --ink: #D8DEE4; --soft: #3A4656; --panel: #283140;
}
[data-palette="warm"] {
  --bg: #F4EADB; --shape: var(--deep); --on-shape: #FBF4EA;
  --ink: #3B2E28; --soft: #DCCDB8; --panel: #FFFAF2;
}
[data-palette="soft"] {
  --bg: #E6E9E5; --shape: #9AAFBB; --shape: color-mix(in srgb, var(--deep) 45%, #E6E9E5); --on-shape: #F1F3F0;
  --ink: #4A555A; --soft: #D3D9D4; --panel: #EEF0ED;
}
[data-palette="sky"] {
  --bg: #D9F0FF; --shape: var(--deep); --on-shape: #FFFFFF;
  --ink: #17324A; --soft: #A8D2EC; --panel: #FFFFFF;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 18px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#status { position: fixed; top: 0; left: 0; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
h1:focus, #gate:focus { outline: none; }
a { color: inherit; }

/* ---------- Child screen ---------- */
#child { height: 100vh; height: 100dvh; min-height: 340px; display: flex; flex-direction: column; gap: 8px; user-select: none; -webkit-user-select: none; touch-action: manipulation;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; }
.tool { width: 80px; height: 80px; flex: none; display: grid; place-items: center; background: var(--panel); border: 2px solid var(--soft); border-radius: 22px; }
.tool svg { width: 44px; height: 44px; fill: currentColor; }
.tool.small { height: 60px; width: auto; min-width: 60px; padding: 0 12px; display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 15px; border-radius: 16px; }
.tool.small svg { width: 32px; height: 32px; }
#sound .waves, #sound[aria-pressed="true"] .slash { display: none; }
#sound[aria-pressed="true"] .waves { display: inline; }
#sound.gone { visibility: hidden; }
[data-phase="running"] #adults span, [data-phase="paused"] #adults span, [data-phase="swap"] #adults span { display: none; }

#turns { display: flex; align-items: center; gap: 14px; }
#turns .who { width: 56px; height: 56px; padding: 5px; border-radius: 16px; border: 4px solid transparent; background: #fff; opacity: .5; color: var(--shape); }
#turns .who.now { opacity: 1; border-color: currentColor; }
#turns .who.b { color: var(--shape-b); }
#turns ol { list-style: none; display: flex; gap: 5px; margin: 0; padding: 0; }
#turns li { width: 12px; height: 12px; border-radius: 50%; background: var(--ink); }
#turns li.over { background: transparent; box-shadow: inset 0 0 0 2px var(--ink); opacity: .5; }

/* The shape gets the room. Beside it, smaller, what comes next. */
#stage { flex: 1; min-height: 120px; display: flex; align-items: center; justify-content: center; gap: clamp(12px, 4vw, 56px); }
#shape { height: 100%; max-height: 560px; aspect-ratio: 3 / 4; min-width: 0; max-width: 56vw; color: var(--shape); display: grid; place-items: center; }
#shape { position: relative; }
#shape > svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
#shape .line { fill: none; stroke: var(--shape); stroke-width: 3.5; stroke-linejoin: round; stroke-linecap: round; }
#shape .back { fill: var(--panel); }
#shape .left { fill: var(--shape); }
[data-turn="b"] :is(#shape, .go) { --shape: var(--shape-b); }
#arrow { width: clamp(28px, 6vw, 56px); flex: none; opacity: .6; }
#next { width: clamp(96px, 22vw, 220px); flex: none; text-align: center; color: var(--shape); }
#next-pic { padding: 8%; border: 5px solid var(--soft); border-radius: 24px; background: #fff; }
#next svg { display: block; width: 100%; }
#next p { margin: 6px 0 0; font-weight: 600; color: var(--ink); }
[data-warn] #next-pic { border-color: var(--shape); }
[data-warn][data-style="walk"] #shape rect { stroke-width: 6; }
[data-warn][data-style="reveal"] #shape .line { stroke-width: 7; }
[data-nonext] #arrow, [data-nonext] #next, [data-style="reveal"] #arrow, [data-style="reveal"] #next { display: none; }
/* The walk takes the whole stage: what comes next is at the end of the path. */
[data-style="walk"] #shape { width: 100%; max-width: 1000px; max-height: none; height: 100%; aspect-ratio: auto; }
[data-style="walk"]:not([data-phase="done"]) #arrow, [data-style="walk"]:not([data-phase="done"]) #next { display: none; }
.stone { fill: var(--shape); } .stone.used { fill: none; stroke: var(--shape); stroke-width: 1; opacity: .45; }
.joy { display: none; } .happy .joy { display: inline; } .happy .look { display: none; }
.breathe { transform-origin: 50% 80%; animation: breathe 6s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.05); } }
[data-motion="steps"] .breathe, [data-phase="ready"] .breathe { animation: none; }
#cheer { display: none; align-items: center; justify-content: center; gap: 10px; }
[data-cheer][data-phase="done"] #cheer { display: flex; }
#cheer .happy { width: min(26vw, 16vh); } #cheer .star { width: min(9vw, 6vh); fill: #EFAA00; animation: appear 1.2s ease-out both; }
@keyframes appear { from { opacity: 0; transform: scale(.6); } }
[data-motion="steps"] #cheer .star { animation: none; }
[data-phase="paused"] #shape { opacity: .45; }

/* Finished: the shape is gone and what comes next takes its place. */
[data-phase="done"] #shape, [data-phase="done"] #arrow { display: none; }
[data-phase="done"]:not([data-nonext]) #next { display: block; width: min(64vw, 52vh); }
[data-phase="done"][data-nonext] #shape { display: grid; max-height: 300px; }
.ripple { fill: none; stroke: var(--shape); stroke-width: 3; animation: ripple 8s ease-in-out infinite; }
.ripple:nth-child(2) { animation-delay: -2.6s; } .ripple:nth-child(3) { animation-delay: -5.2s; }
@keyframes ripple { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
[data-motion="steps"] .ripple, [data-phase="ready"] .ripple { animation: none; opacity: .7; }

#digits { margin: 0; min-height: 1.3em; text-align: center; font-size: clamp(22px, 4vh, 34px); font-weight: 600; font-variant-numeric: tabular-nums; }
#digits:empty { display: none; }
#foot { min-height: 92px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 12px; }
#times { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
#times button { min-width: 72px; min-height: 60px; padding: 4px 14px; background: var(--panel); border: 2px solid var(--soft); border-radius: 18px; font-weight: 600; line-height: 1.15; }
#times small { display: block; font-weight: 400; font-size: 14px; }
#times button[aria-pressed="true"] { border: 4px solid var(--shape); padding: 2px 12px; }
.go-row { display: flex; gap: 16px; align-items: center; }
.go { width: 120px; height: 84px; border: 0; border-radius: 26px; background: var(--shape); color: var(--on-shape); display: grid; place-items: center; }
.go svg { width: 48px; height: 48px; fill: currentColor; }

/* ---------- Gate and controls ---------- */
#gate, #controls { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; padding: 24px 20px; }
#gate p { max-width: 28em; margin: 0; }
#gate-hold { position: relative; width: 168px; height: 168px; border: 0; border-radius: 50%; background: var(--panel); display: grid; place-items: center; font-weight: 700; font-size: 22px; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#gate-hold svg { position: absolute; inset: 0; transform: rotate(-90deg); }
#gate-hold circle { fill: none; stroke: var(--soft); stroke-width: 8; }
#gate-arc { stroke: var(--shape) !important; stroke-linecap: round; stroke-dasharray: 326.73; stroke-dashoffset: 326.73; opacity: 0; }
#controls button { width: min(100%, 340px); }
#controls-left { margin: 0; font-size: 22px; font-variant-numeric: tabular-nums; }
.primary, .plain { min-height: 56px; padding: 8px 22px; border-radius: 16px; }
.primary { background: var(--shape); color: var(--on-shape); border: 0; font-weight: 600; }
.plain { background: transparent; border: 2px solid var(--soft); }

/* ---------- Grown-ups screen ---------- */
#settings { min-height: 100dvh; padding: max(16px, env(safe-area-inset-top)) 16px 48px; }
.sheet { max-width: 680px; margin: 0 auto; }
.head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--bg); padding: 8px 0; z-index: 1; }
h1 { font-size: 28px; margin: 0; }
fieldset { border: 0; margin: 0 0 20px; padding: 16px; background: var(--panel); border-radius: 16px; min-width: 0; }
legend { float: left; width: 100%; padding: 0; margin-bottom: 10px; font-weight: 700; }
legend + * { clear: both; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chips button { min-height: 48px; padding: 6px 16px; background: transparent; border: 2px solid var(--soft); border-radius: 12px; }
/* The grown-ups screen keeps strong colours whatever the child's background is. */
#settings, #controls, #gate { --shape: #2C5470; --on-shape: #fff; }
[data-palette="dark"] :is(#settings, #controls, #gate) { --shape: #9FC3D9; --on-shape: #1E2530; }
.chips button[aria-pressed="true"] { background: var(--shape); border-color: var(--shape); color: var(--on-shape); font-weight: 600; }
.chips button:disabled { opacity: .45; cursor: default; }
.pics button { width: 92px; padding: 8px 4px; font-size: 14px; line-height: 1.2; }
.pics svg { display: block; width: 52px; height: 52px; padding: 4px; margin: 0 auto 4px; background: #fff; border-radius: 10px; }
.sub { margin: 14px 0 8px; font-size: 15px; font-weight: 600; }
.hint { margin: 6px 0 10px; font-size: 15px; }
.row { display: flex; gap: 12px; align-items: center; margin: 6px 0 10px; }
.row input[type="text"] { flex: 1; min-width: 0; min-height: 48px; padding: 8px 12px; background: var(--bg); border: 2px solid var(--soft); border-radius: 12px; }
.file { display: inline-flex; align-items: center; cursor: pointer; min-height: 48px; }
.file:focus-within { outline: 3px solid var(--shape); outline-offset: 3px; }

@media (orientation: portrait) {
  #stage { flex-direction: column; gap: 10px; }
  #shape { height: auto; flex: 1 1 0; min-height: 0; max-width: 100%; }
  #arrow { transform: rotate(90deg); width: 32px; }
  #next { width: min(30vw, 18vh); }
}
/* Small phones: what comes next sits beside the shape, and the buttons take less room. */
@media (orientation: portrait) and (max-height: 700px) {
  #stage { flex-direction: row; gap: 8px; }
  #shape { height: 100%; flex: 0 1 auto; max-width: 52vw; }
  #arrow { transform: none; width: 24px; }
  #next { width: 25vw; }
  #foot { min-height: 72px; gap: 8px; }
  #times { gap: 6px; } #times button { min-width: 58px; min-height: 52px; padding: 2px 6px; } #times button[aria-pressed="true"] { padding: 0 4px; }
  .go { height: 64px; } .tool { width: 64px; height: 64px; }
}
@media (max-width: 400px) { #turns { gap: 6px; } #turns .who { width: 44px; height: 44px; padding: 3px; } #turns li { width: 9px; height: 9px; } #turns ol { gap: 3px; flex-wrap: wrap; max-width: 60px; } .tool.small { min-width: 52px; padding: 0 8px; } }
@media (max-height: 520px) {
  .bar { min-height: 52px; } .tool.small { height: 52px; } .go { height: 60px; }
  [data-phase="done"]:not([data-nonext]) #next { width: 30vh; } #cheer .happy { width: 13vh; }
  #foot { flex-direction: row; justify-content: center; min-height: 64px; } #times button { min-height: 52px; }
  .tool { width: 60px; height: 60px; }
}
@media (max-width: 420px) { .tool.small span { display: none; } }
