/* Wellsnail: a storybook page drawn on a coarse pixel grid.
   Square corners, hard edges, no blur, motion in whole steps. */

:root {
  --px: 4px;
  --grid: 16px;
  --line: 4px solid var(--ak-ink);
  --gridline: color-mix(in srgb, var(--ak-ink) 8%, transparent);
  --hh: 46px;
  --notch: polygon(
    0 var(--px), var(--px) var(--px), var(--px) 0,
    calc(100% - var(--px)) 0, calc(100% - var(--px)) var(--px), 100% var(--px),
    100% calc(100% - var(--px)), calc(100% - var(--px)) calc(100% - var(--px)), calc(100% - var(--px)) 100%,
    var(--px) 100%, var(--px) calc(100% - var(--px)), 0 calc(100% - var(--px))
  );
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--ak-font-body);
  color: var(--ak-ink);
  background-color: var(--ak-bg);
  background-image: var(--ak-backdrop-layer, var(--ak-bg-art));
  background-size: cover;
  background-position: center;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  border-radius: 0;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
.track:focus-visible,
.ro-input:focus-visible {
  outline: 4px solid var(--ak-focus);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

/* ---------- mute: the one corner control ---------- */

.mute {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 30;
  width: 48px;
  height: 48px;
  padding: 10px;
  display: grid;
  place-items: center;
  background: var(--ak-choice-bg);
  border: var(--line);
  cursor: pointer;
}

.mute svg {
  width: 24px;
  height: 24px;
  fill: var(--ak-ink);
}

.mute[aria-pressed="true"] { background: var(--ak-surface); }

/* ---------- page layout: upright ---------- */

.app {
  position: fixed;
  inset: 0;
  margin: 0 auto;
  max-width: 560px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr);
  grid-template-areas: "head" "stage" "panel";
  gap: 8px;
  padding:
    max(10px, env(safe-area-inset-top))
    max(10px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(10px, env(safe-area-inset-left));
  touch-action: manipulation;
}

.head {
  grid-area: head;
  min-height: 48px;
  padding: 0 58px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 10px;
}

.logo {
  display: block;
  height: 30px;
  width: auto;
}

.pips {
  display: flex;
  gap: 3px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pips li {
  --pip: clamp(13px, 3.6vw, 18px);
  width: var(--pip);
  height: var(--pip);
  display: grid;
  place-items: center;
  background: var(--ak-surface);
  border: 3px solid var(--ak-ink);
}

.pips li svg {
  width: 100%;
  height: 100%;
}

.pips .now { background: var(--ak-bg); border-color: var(--ak-accent-2); }
.pips .right { background: var(--ak-choice-selected-bg); }
.pips .right svg { fill: var(--ak-choice-selected-ink); }
.pips .slip { background: var(--ak-bg); }
.pips .slip svg { fill: var(--ak-accent-2); }

.stage {
  grid-area: stage;
  height: min(46dvh, 470px);
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.app[data-phase="why"] .stage { height: min(32dvh, 400px); }
.app[data-phase="ending"] .stage { height: min(30dvh, 400px); }
.app[data-phase="why"] .lbl { display: none; }

.panel {
  grid-area: panel;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 12px 0;
  scroll-padding-bottom: 84px;
  background: var(--ak-surface);
  border: var(--line);
  clip-path: var(--notch);
}

@media (orientation: portrait) and (max-height: 720px) {
  .app[data-phase="ending"] .stage { height: 24dvh; }
  .stage { height: 40dvh; }
  .app[data-phase="why"] .stage { height: 28dvh; }
  .count { display: none; }
  .clue { font-size: 17px; line-height: 1.32; }
  .play-bits { gap: 8px; }
}

/* ---------- page layout: sideways ---------- */

@media (orientation: landscape) {
  .app {
    max-width: 1180px;
    max-height: 820px;
    margin: auto;
    grid-template-columns: minmax(0, 1fr) minmax(300px, 1.2fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "head panel" "stage panel";
    column-gap: 10px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }

  /* The answer screen: the locked slider steps aside and the why gets the width. */
  .app[data-phase="why"],
  .app[data-phase="ending"] {
    grid-template-columns: minmax(0, 0.72fr) minmax(300px, 1.5fr);
  }

  .app[data-phase="why"] .slider-col { display: none; }
  .app[data-phase="why"] .stage { grid-template-columns: minmax(0, 1fr); }

  /* The mute button sits at the start of the logo row. */
  .head {
    min-height: 56px;
    justify-content: flex-start;
    padding: 0 0 0 max(48px, calc(env(safe-area-inset-left) + 36px));
  }

  .answer-bar { grid-template-columns: 56px 56px minmax(0, 1fr) 56px 56px; }
  .nudge b { font-size: 20px; }

  /* Room for the round help button over the panel's top corner. */
  .clue::before {
    content: "";
    float: right;
    width: 40px;
    height: 40px;
  }

  .ending { padding-right: 44px; }

  .stage,
  .app[data-phase="why"] .stage,
  .app[data-phase="ending"] .stage {
    height: auto;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .app { gap: 6px; padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .head { min-height: 44px; }
  .play-bits { gap: 8px; }
  .count { display: none; }
  .coach { padding: 8px 10px; }
  .done { font-size: 44px; }
  .blink { font-size: 16px; }
  .clue { font-size: 17px; line-height: 1.32; }
  .why p, .verdict p, .says { font-size: 16px; }
  .answer-line { font-size: 17px !important; }
  .panel { padding-top: 8px; scroll-padding-bottom: 70px; }
  .actions { padding-bottom: 8px; }
  .card { gap: 6px; padding: 8px 10px; }
  .dodged { font-size: 19px; }
  .tally li { width: 28px; height: 28px; }
  .go, .hint, .plain { min-height: 50px; font-size: 18px; }
}

/* ---------- the scene frame ---------- */

.frame {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  background-color: var(--ak-bg);
  background-image:
    linear-gradient(to right, var(--gridline) 1px, transparent 1px),
    linear-gradient(to bottom, var(--gridline) 1px, transparent 1px);
  background-size: var(--grid) var(--grid);
  border: var(--line);
  clip-path: var(--notch);
}

.scene {
  position: relative;
  min-height: 0;
  overflow: hidden;
  container-type: size;
}

.scene-cap {
  margin: 0;
  min-height: calc(2 * 1.3em + 12px);
  padding: 6px 10px;
  font-size: 16px;
  line-height: 1.3;
  background: var(--ak-surface);
  border-top: var(--line);
}

.sc {
  position: absolute;
  inset: 0;
}

/* A very short scene (the first caption on the smallest phones) drops its corner tag. */
@container (max-height: 120px) {
  .tag { display: none; }
}

.tag {
  position: absolute;
  z-index: 3;
  top: 8px;
  left: 8px;
  margin: 0;
  padding: 2px 8px;
  font-family: var(--ak-font-display);
  font-weight: 800;
  font-size: 18px;
  background: var(--ak-bg);
  border: 3px solid var(--ak-ink);
}

/* well */

.well-box {
  position: absolute;
  left: 50%;
  bottom: 3cqh;
  height: 88cqh;
  aspect-ratio: 139 / 384;
  translate: -70% 0;
}

.well-img {
  display: block;
  width: 100%;
  height: 100%;
}

.ruler {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 100%;
  width: 52px;
}

.ruler span {
  position: absolute;
  left: 4px;
  bottom: calc(var(--p) * 1%);
  padding: 0 0 1px 2px;
  font-family: var(--ak-font-display);
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
  border-bottom: 3px solid var(--ak-ink);
  translate: 0 3px;
}

.well-snail {
  position: absolute;
  left: 8%;
  bottom: calc(var(--p, 7.6) * 1%);
  width: max(44px, 62%);
  height: auto;
  transform-origin: 20% 100%;
}

.well-snail.out { left: -34%; }
.well-snail.tip { transform: translateY(-14%) rotate(-20deg); }

/* lily pads */

.pond {
  position: absolute;
  left: 50%;
  top: 54%;
  translate: -50% -50%;
  width: min(84cqw, 76cqh);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  background: var(--ak-ink);
}

.cell {
  display: grid;
  place-items: center;
  background: var(--ak-ink-muted);
}

.cell img {
  width: 92%;
  height: 92%;
  visibility: hidden;
}

.cell.on img { visibility: visible; }
.cell.empty-half { box-shadow: inset 0 0 0 4px var(--ak-bg); }

/* candles */

.candles {
  position: absolute;
  left: 50%;
  top: 54%;
  translate: -50% -50%;
  display: grid;
  grid-template-columns: repeat(5, auto);
  gap: 3cqh 2cqw;
}

.candle {
  position: relative;
  width: min(17cqw, 15cqh);
  aspect-ratio: 158 / 384;
  background: url("./art/candle.png") 0 0 / 200% 100% no-repeat;
  transform-origin: 50% 100%;
}

.candle.blown { background-position: 100% 0; }
.candle[data-burn="1"] { transform: scaleY(0.75); }
.candle[data-burn="2"] { transform: scaleY(0.5); }
.candle[data-burn="3"] { transform: scaleY(0.3); }
.candle.gone { background: none; transform: none; }

.puddle {
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: 0;
  height: 12%;
  display: none;
  background: var(--ak-choice-bg);
  border: 3px solid var(--ak-ink-muted);
}

.candle.gone .puddle { display: block; }
.candle.keep { outline: 4px solid var(--ak-accent-2); outline-offset: 2px; }

/* leaf crew */

.meter {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 3px;
}

.meter i {
  width: 16px;
  height: 16px;
  background: var(--ak-bg);
  border: 3px solid var(--ak-ink);
}

.meter i.on { background: var(--ak-accent-2); }

.crew {
  position: absolute;
  top: 20cqh;
  bottom: 4cqh;
  left: 50%;
  translate: -50% 0;
  display: grid;
  grid-template-rows: repeat(var(--rows, 5), minmax(0, 1fr));
  gap: 1.5cqh;
}

.pair {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 0;
}

.pair img {
  height: 100%;
  width: auto;
}

.leaf {
  height: 100%;
  width: auto;
  fill: var(--ak-accent);
  stroke: var(--ak-ink);
  stroke-width: 0.12;
}

.leaf .eaten { visibility: hidden; }

.stamp {
  position: absolute;
  right: 6cqw;
  top: 50%;
  translate: 0 -50%;
  margin: 0;
  padding: 4px 10px;
  font-family: var(--ak-font-display);
  font-weight: 800;
  font-size: clamp(28px, 14cqmin, 56px);
  line-height: 1;
  background: var(--ak-bg);
  border: 4px solid var(--ak-ink);
  box-shadow: 4px 4px 0 var(--ak-accent-2);
}

/* fence */

.yard {
  --rail: 0;
  position: absolute;
  left: 9cqw;
  right: 9cqw;
  top: 26cqh;
  height: 44cqh;
}

.rail {
  position: absolute;
  left: 0;
  width: calc(var(--rail) * 100%);
  height: 6%;
  background: var(--ak-ink-muted);
}

.rail.r1 { top: 28%; }
.rail.r2 { top: 52%; }

.post {
  position: absolute;
  bottom: 18%;
  left: calc(var(--x) * 100%);
  --pw: max(10px, 4.2cqw);
  width: var(--pw);
  height: 70%;
  margin-left: calc(var(--pw) / -2);
  background: var(--ak-accent-2);
  border: 3px solid var(--ak-ink);
  transform-origin: 50% 100%;
  transform: scaleY(0);
}

.post.on { transform: none; }
.post.extra { background: var(--ak-accent); outline: 4px solid var(--ak-ink); outline-offset: 2px; }

.feet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 18%;
  border-top: 4px solid var(--ak-ink);
}

.feet span {
  position: absolute;
  top: 0;
  left: calc(var(--x) * 100%);
  translate: -50% 0;
  padding-top: 8px;
  font-family: var(--ak-font-display);
  font-weight: 700;
  font-size: 14px;
  line-height: 1;
}

.feet span::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 3px;
  height: 6px;
  translate: -50% 0;
  background: var(--ak-ink);
}

.unit {
  position: absolute;
  right: 9cqw;
  bottom: 12cqh;
  margin: 0;
  font-size: 14px;
}

/* ladybug hill */

.hill {
  /* Block size shrinks with the hill so a taller one still fits the frame. */
  --b: min(calc(80cqw / (var(--n) + 1)), calc(51cqh / var(--n)));
  position: absolute;
  left: 50%;
  bottom: 27cqh;
  width: calc((var(--n) + 1) * var(--b));
  height: calc(var(--n) * var(--b));
  translate: -50% 0;
  border-bottom: 4px solid var(--ak-ink);
}

.block {
  position: absolute;
  bottom: 0;
  left: calc(var(--c) * var(--b));
  width: var(--b);
  height: calc(var(--c) * var(--b));
  background: var(--ak-accent);
  border: 3px solid var(--ak-ink);
  border-bottom: 0;
}

.bug {
  position: absolute;
  left: calc(var(--s, 0) * var(--b) + var(--b) * 0.05);
  bottom: calc(var(--s, 0) * var(--b));
  width: calc(var(--b) * 0.9);
  aspect-ratio: 1;
}

.bug svg {
  display: block;
  width: 100%;
  height: 100%;
}

.bug .p1 { fill: var(--ak-accent-2); stroke: var(--ak-ink); stroke-width: 0.1; }
.bug .p2 { fill: var(--ak-ink); }

.timebar {
  position: absolute;
  left: 8cqw;
  right: 8cqw;
  bottom: 4cqh;
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
}

.timebar li {
  display: grid;
  gap: 2px;
  justify-items: center;
  font-size: 13px;
  font-family: var(--ak-font-display);
  font-weight: 700;
}

.timebar li::before {
  content: "";
  width: 100%;
  height: max(18px, 8cqh);
  background: var(--ak-bg);
  border: 3px solid var(--ak-ink);
}

.timebar li.on.up::before { background: var(--ak-accent); }
.timebar li.on.down::before { background: var(--ak-accent-2); }

/* acorn and seed */

.sc-acorn {
  --s: 0.06;
}

.rows {
  position: absolute;
  left: 4cqw;
  right: 4cqw;
  top: 50%;
  translate: 0 -40%;
  display: grid;
  gap: 4cqh;
}

.row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 40px;
  grid-template-areas: "thing bar num" "name bar num";
  align-items: center;
  column-gap: 6px;
}

.thing {
  grid-area: thing;
  justify-self: center;
  width: 30px;
  height: 30px;
}

.thing .p1 { fill: var(--ak-ink-muted); }
.thing .p2 { fill: var(--ak-accent-2); }

.name {
  grid-area: name;
  justify-self: center;
  font-size: 12px;
  line-height: 1.1;
}

.name.wide { grid-row: 1 / span 2; font-size: 13px; font-weight: 600; }

.bar {
  grid-area: bar;
  position: relative;
  display: flex;
  height: 30px;
  background: var(--ak-bg);
  border: 3px solid var(--ak-ink);
}

.bar i {
  display: grid;
  place-items: center;
  font-style: normal;
  font-family: var(--ak-font-display);
  font-weight: 800;
  font-size: 13px;
  border-right: 2px solid var(--ak-ink);
}

.b-diff {
  width: calc(var(--w) * 100%);
  background: var(--ak-choice-selected-bg);
  color: var(--ak-choice-selected-ink);
}

.b-seed {
  width: calc(var(--s) * 100%);
  background: repeating-linear-gradient(to bottom, var(--ak-accent-2) 0 4px, var(--ak-bg) 4px 8px);
}

.priced .b-seed { background: var(--ak-accent-2); }

.target {
  position: absolute;
  top: -8px;
  bottom: -8px;
  left: calc(var(--t) * 100%);
  width: 4px;
  translate: -2px 0;
  background: var(--ak-ink);
}

.num {
  grid-area: num;
  font-family: var(--ak-font-display);
  font-size: 20px;
  text-align: right;
}

.over .sum .bar { border-color: var(--ak-accent-2); }
.over .sum .num { text-decoration: line-through 3px var(--ak-accent-2); }

/* sparkle burst: square bits that jump out in whole steps */

.burst {
  position: absolute;
  z-index: 4;
  width: 0;
  height: 0;
  pointer-events: none;
}

.burst i {
  position: absolute;
  width: 12px;
  height: 12px;
  margin: -6px;
  background: var(--ak-accent-2);
  opacity: 0;
}

.burst i:nth-child(even) { background: var(--ak-accent); }

/* ---------- the answer slider: a garden cane with a snail handle ---------- */

.slider-col {
  width: 120px;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  padding: 8px;
  background: var(--ak-surface);
  border: var(--line);
}

.val {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 2px;
  min-height: 48px;
  padding: 4px 2px;
  text-align: center;
  background: var(--ak-bg);
  border: 3px solid var(--ak-ink);
}

.val b {
  font-family: var(--ak-font-display);
  font-weight: 800;
  font-size: 24px;
  line-height: 1;
  white-space: nowrap;
}

.val-unit {
  font-size: 14px;
  line-height: 1.1;
}

/* The number rides beside the snail, so the pick is clear while dragging. */
.flag {
  position: absolute;
  z-index: 2;
  left: 0;
  bottom: calc(var(--f, 0) * (100% - var(--hh)) + var(--hh) / 2);
  min-width: 32px;
  padding: 3px 3px;
  translate: 0 50%;
  font-family: var(--ak-font-display);
  font-weight: 800;
  font-size: 15px;
  line-height: 1;
  text-align: center;
  background: var(--ak-bg);
  border: 3px solid var(--ak-ink);
  pointer-events: none;
}

.track {
  position: relative;
  min-height: 110px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.track.grab { cursor: grabbing; }

.cane {
  position: absolute;
  top: calc(var(--hh) / 2 - 6px);
  bottom: calc(var(--hh) / 2 - 6px);
  left: 50px;
  width: 24px;
  background: var(--ak-accent);
  border: 3px solid var(--ak-ink);
}

.marks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.rung,
.lbl {
  position: absolute;
  bottom: calc(var(--f) * (100% - var(--hh)) + var(--hh) / 2);
}

.rung {
  left: 50px;
  width: 24px;
  height: 3px;
  translate: 0 50%;
  background: var(--ak-ink);
}

.lbl {
  left: 0;
  width: 42px;
  translate: 0 50%;
  text-align: right;
  font-family: var(--ak-font-display);
  font-size: 14px;
  line-height: 1;
}

.handle {
  position: absolute;
  left: 32px;
  bottom: calc(var(--f, 0) * (100% - var(--hh)));
  width: 60px;
  height: var(--hh);
  pointer-events: none;
}

.handle img {
  display: block;
  width: 100%;
  height: 100%;
}

.track[aria-disabled="true"] { cursor: default; }
.track[aria-disabled="true"] .handle img { opacity: 0.75; }


.app[data-phase="ending"] .stage { grid-template-columns: minmax(0, 1fr); }
.app[data-phase="ending"] .slider-col { display: none; }

/* ---------- the clue panel ---------- */

.play-bits {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.app[data-phase="ending"] .play-bits { display: none; }

.count {
  margin: 0;
  font-family: var(--ak-font-display);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
}

.clue {
  margin: 0;
  font-size: 18px;
  line-height: 1.38;
}

/* The answer bar: big and small steps either side of the number. */
.answer-bar {
  display: grid;
  grid-template-columns: 48px 48px minmax(0, 1fr) 48px 48px;
  gap: 6px;
}

.bar-tip {
  margin: 0 0 -4px;
  font-size: 16px;
  line-height: 1.3;
  color: var(--ak-ink-muted);
}

.nudge {
  min-height: 56px;
  padding: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 3px;
  font-family: var(--ak-font-display);
  line-height: 1;
  white-space: nowrap;
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
  border: 3px solid var(--ak-ink);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.nudge b {
  font-weight: 800;
  font-size: 18px;
}

.nudge small {
  font-family: var(--ak-font-body);
  font-size: 13px;
  font-weight: 600;
}

.nudge.big {
  background: var(--ak-choice-selected-bg);
  color: var(--ak-choice-selected-ink);
  border-color: var(--ak-ink);
}

.nudge:active:not(:disabled) { padding-top: 4px; }

.nudge:disabled {
  background: var(--ak-surface);
  color: var(--ak-ink-muted);
  border-color: var(--ak-choice-border);
  cursor: default;
}

.readout {
  margin: 0;
  min-width: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 2px;
  padding: 4px;
  text-align: center;
  background: var(--ak-bg);
  border: 3px solid var(--ak-ink);
}

.ro-cap {
  font-size: 14px;
  line-height: 1.1;
  color: var(--ak-ink-muted);
}

.readout { cursor: text; }

.ro-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.ro-row .ro-unit {
  font-family: var(--ak-font-display);
  font-weight: 800;
  font-size: 20px;
}

/* The number itself is a box you can type into. */
.ro-input {
  width: calc(var(--w, 2) * 1ch + 14px);
  min-height: 34px;
  margin: 0;
  padding: 0 4px;
  font-family: var(--ak-font-display);
  font-weight: 800;
  font-size: 20px;
  line-height: 1.1;
  text-align: center;
  color: var(--ak-ink);
  background: var(--ak-surface);
  border: 3px solid var(--ak-ink);
  border-radius: 0;
}

.ro-input:disabled { color: var(--ak-ink-muted); }

.ro-unit {
  font-size: 14px;
  line-height: 1.1;
}


/* A narrow panel (small phones, either way up) gives the number more room:
   slimmer step buttons, and the caption is kept for screen text only. */
.play-bits { container-type: inline-size; }

@container (max-width: 300px) {
  .answer-bar { grid-template-columns: 44px 44px minmax(0, 1fr) 44px 44px; gap: 4px; }
  .readout { padding: 2px; }
  .ro-input, .ro-row .ro-unit { font-size: 16px; }
  .ro-input { min-height: 30px; }
  .ro-row { gap: 4px; }
}

@container (max-width: 340px) {
  .ro-cap {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

.app:not([data-phase="pick"]) .answer-bar,
.app:not([data-phase="pick"]) .bar-tip,
.app[data-phase="why"] .count { display: none; }

.playing {
  padding: 8px 10px;
  background: var(--ak-bg);
  border: 4px solid var(--ak-ink);
}

.playing p {
  margin: 0 0 8px;
  font-size: 17px;
  line-height: 1.35;
}

.play-bar {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 3px;
}

.play-bar i {
  height: 14px;
  background: var(--ak-surface);
  border: 2px solid var(--ak-ink);
}

.play-bar i.on { background: var(--ak-accent); }

.verdict {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  background: var(--ak-bg);
  border: 4px solid var(--ak-ink);
  border-left-width: 12px;
  border-left-color: var(--ak-accent-2);
}

.verdict p {
  margin: 0;
  font-size: 17px;
  line-height: 1.35;
}

.v-icon {
  flex: none;
  width: 22px;
  height: 22px;
  margin-top: 1px;
}

.v-no { fill: var(--ak-accent-2); }
.v-yes { display: none; fill: var(--ak-choice-selected-ink); }

.verdict.yes {
  background: var(--ak-choice-selected-bg);
  color: var(--ak-choice-selected-ink);
  border-color: var(--ak-ink);
}

.verdict.yes .v-yes { display: block; }
.verdict.yes .v-no { display: none; }

.why {
  padding: 8px 10px;
  background: var(--ak-bg);
  border: 4px solid var(--ak-ink);
  border-left-width: 12px;
  border-left-color: var(--ak-accent-2);
}

.why.yes { border-left-color: var(--ak-choice-selected-bg); }
.why .v-no { fill: var(--ak-accent-2); }
.why .v-yes { fill: var(--ak-choice-selected-bg); }
.why.yes .v-yes { display: inline-block; }
.why.yes .v-no { display: none; }
.why .v-icon { width: 18px; height: 18px; margin: 0 6px 0 0; vertical-align: -2px; }

.why p {
  margin: 0 0 6px;
  font-size: 17px;
  line-height: 1.35;
}

.why p:last-child { margin-bottom: 0; }

.answer-line {
  font-family: var(--ak-font-display);
  font-weight: 800;
  font-size: 20px !important;
}

.hint-box {
  margin: 0;
  padding: 8px 10px;
  font-size: 18px;
  line-height: 1.35;
  background: var(--ak-bg);
  border: 4px dashed var(--ak-ink-muted);
}

.coach {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--ak-bg);
  border: 4px solid var(--ak-accent-2);
}

.coach p {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.35;
}

.coach-arrow {
  flex: none;
  width: 28px;
  height: 28px;
  fill: var(--ak-accent-2);
}

.coach[data-dir="right"] .coach-arrow { transform: rotate(-90deg); }
.actions .coach { flex: 1; padding: 4px 8px; }

/* Under the scene the caption reads first and its arrow points out to the slider. */
.frame .coach {
  border: 0;
  border-top: 4px solid var(--ak-accent-2);
  padding: 8px 10px;
}

.frame .coach-arrow { order: 2; }

@media (orientation: landscape) {
  .coach[data-dir="check"] .coach-arrow { transform: rotate(-90deg); }
}

.teach-ring {
  outline: 4px solid var(--ak-accent-2);
  outline-offset: 4px;
}

.actions {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  display: flex;
  gap: 8px;
  padding: 4px 0 12px;
  background: var(--ak-surface);
}

.go,
.hint,
.plain {
  min-height: 56px;
  padding: 8px 14px;
  font-family: var(--ak-font-display);
  font-weight: 800;
  font-size: 19px;
  border: 4px solid var(--ak-ink);
  cursor: pointer;
}

.go {
  flex: 1;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  box-shadow: inset 0 -5px 0 var(--ak-btn-active);
}

.go:active:not(:disabled) {
  background: var(--ak-btn-active);
  box-shadow: none;
  padding-top: 11px;
  padding-bottom: 5px;
}

.go:disabled {
  background: var(--ak-choice-bg);
  color: var(--ak-ink-muted);
  border-color: var(--ak-choice-border);
  box-shadow: none;
  cursor: default;
}

.hint,
.plain {
  min-width: 88px;
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
}

.hint:disabled {
  color: var(--ak-ink-muted);
  border-color: var(--ak-choice-border);
  cursor: default;
}

@media (hover: hover) {
  .go:hover:not(:disabled) { background: var(--ak-btn-hover); }
}

/* ---------- the ending ---------- */

.ending {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 12px;
}

.card {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 12px;
  text-align: center;
  background: var(--ak-bg);
  border: 4px solid var(--ak-ink);
}

.card p { margin: 0; }

.done {
  font-family: var(--ak-font-display);
  font-weight: 800;
  font-size: clamp(40px, 12vmin, 88px);
  line-height: 0.95;
  letter-spacing: 0.06em;
  color: var(--ak-accent);
  text-shadow: 4px 4px 0 var(--ak-ink);
}

.dodged {
  font-family: var(--ak-font-display);
  font-weight: 800;
  font-size: 22px;
}

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

.tally li {
  width: 32px;
  height: 32px;
  padding: 4px;
  border: 3px solid var(--ak-ink);
}

.tally li svg { display: block; width: 100%; height: 100%; }
.tally .right { background: var(--ak-choice-selected-bg); fill: var(--ak-choice-selected-ink); }
.tally .slip { background: var(--ak-bg); fill: var(--ak-accent-2); }

.says {
  font-size: 18px;
  line-height: 1.35;
}

.blink {
  font-family: var(--ak-font-display);
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.12em;
}

.blink::after {
  content: "";
  display: inline-block;
  width: 12px;
  height: 16px;
  margin-left: 8px;
  background: var(--ak-accent-2);
}

.end-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
}

.end-actions .go,
.end-actions .plain { flex: 1 1 8em; }

/* ---------- motion, in whole steps ---------- */

@media (prefers-reduced-motion: no-preference) {
  .handle { transition: bottom 80ms steps(1, start); }
  .val.bump b,
  .flag.bump { animation: bump 160ms steps(2, end); }
  .well-snail { transition: bottom 240ms steps(3, end), left 240ms steps(2, end), transform 300ms steps(3, end); }
  .post { transition: transform 160ms steps(2, end); }
  .bug { transition: left 120ms steps(2, end), bottom 120ms steps(2, end); }
  .candle { transition: transform 300ms steps(3, end); }
  .b-seed { transition: width 300ms steps(3, end); }

  .teach-ring { animation: ring 1s steps(1, end) infinite; }

  .burst i { animation: burst 640ms steps(4, end) forwards; }

  .settle { animation: settle 420ms steps(3, end) calc(var(--k, 0) * 90ms) both; }

  .frame.won { animation: won 900ms steps(1, end) 2; }

  .blink { animation: blink 1s steps(1, end) infinite; }

  .card:not([hidden]) .done { animation: drop 360ms steps(3, end) both; }
}

@keyframes ring {
  0% { outline-offset: 4px; outline-color: var(--ak-accent-2); }
  50% { outline-offset: 8px; outline-color: var(--ak-ink); }
}

@keyframes burst {
  0% { opacity: 1; transform: translate(0, 0); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)); }
}

@keyframes settle {
  0% { translate: 0 -12px; }
  50% { translate: 0 4px; }
  100% { translate: 0 0; }
}

@keyframes won {
  0% { border-color: var(--ak-accent); }
  50% { border-color: var(--ak-ink); }
}

@keyframes blink {
  0% { opacity: 1; }
  50% { opacity: 0; }
}

@keyframes bump {
  0% { transform: translateY(-4px); }
  100% { transform: none; }
}

@keyframes drop {
  0% { translate: 0 -24px; }
  100% { translate: 0 0; }
}

/* ---------- short screens: a compact answer screen ---------- */
/* Last in the file so it wins over the base rules above. */

@media (orientation: landscape) and (max-height: 500px), (orientation: portrait) and (max-height: 720px) {
  .why { padding: 6px 10px; }
  .why p { font-size: 16px; margin-bottom: 4px; line-height: 1.3; }
  .answer-line { font-size: 17px !important; }
  /* On the answer screen the riddle stays as smaller context above the why. */
  .app[data-phase="why"] .clue { font-size: 16px; line-height: 1.3; }
  .app[data-phase="why"] .play-bits { gap: 6px; }

  /* While picking, the whole riddle and your answer sit above Hint and Check
     with no scrolling. The slider tip stays as the answer bar's label. */
  .bar-tip { display: none; }
}

@media (orientation: portrait) and (max-height: 620px) {
  .app[data-phase="pick"] .stage { height: 33dvh; }
  .clue { font-size: 16px; line-height: 1.3; }
  .nudge { min-height: 50px; }
  .actions { padding-bottom: 8px; }
}

@media (orientation: landscape) and (max-height: 340px) {
  .clue { font-size: 16px; line-height: 1.24; }
  .nudge { min-height: 48px; }
  .go, .hint { min-height: 48px; }
  .actions { padding-bottom: 6px; }
  .play-bits { gap: 6px; }
  .panel { padding-top: 6px; }
}

/* ---------- the welcome screen ----------
   start.js builds it; this only dresses it in the pixel-grid look: one centered panel,
   the logo as the focal point beside a little well with the snail on its roof, and the
   Start here box and Play always in view (the how-to scrolls inside the panel if it must).
   Three ids so these win over start.js's own rules, which load after this sheet. */

html body #activity-start#activity-start#activity-start {
  display: grid;
  place-items: center;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  overflow: hidden;
  animation: none;
}

html body #activity-start#activity-start#activity-start .ak-sheet {
  position: relative;
  box-sizing: border-box;
  width: min(100%, 480px);
  max-height: calc(100dvh - 24px);
  min-height: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  text-align: left;
  background-color: var(--ak-surface);
  background-image:
    linear-gradient(to right, var(--gridline) 1px, transparent 1px),
    linear-gradient(to bottom, var(--gridline) 1px, transparent 1px);
  background-size: var(--grid) var(--grid);
  border: 4px solid var(--ak-ink);
  clip-path: var(--notch);
}

html body #activity-start#activity-start#activity-start .ak-sheet::before { display: none; }

html body #activity-start#activity-start#activity-start .ak-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas: "art logo" "art tag";
  align-items: center;
  column-gap: 12px;
  padding: 0;
  border: 0;
  animation: none;
}

/* The painted well with the snail perched on its roof: the game's look before play. */
html body #activity-start#activity-start#activity-start .ak-head::before {
  content: "";
  grid-area: art;
  width: 64px;
  height: 112px;
  background:
    url("./art/snail.png") 100% 0 / 42px auto no-repeat,
    url("./art/well.png") 0 100% / auto 98px no-repeat;
}

html body #activity-start#activity-start#activity-start .ak-title { grid-area: logo; }

html body #activity-start#activity-start#activity-start .ak-logo {
  max-width: 100%;
  max-height: 96px;
  margin: 0;
  animation: none;
}

html body #activity-start#activity-start#activity-start .ak-tagline {
  grid-area: tag;
  margin: 6px 0 0;
  text-align: left;
  font-family: var(--ak-font-display);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.08em;
  color: var(--ak-ink-muted);
}

html body #activity-start#activity-start#activity-start .ak-howto {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 10px 12px;
  background: var(--ak-bg);
  border: 3px solid var(--ak-ink);
  animation: none;
}

html body #activity-start#activity-start#activity-start .ak-section {
  display: block;
  padding-left: 10px;
  border-left: 4px solid var(--ak-accent);
  animation: none;
}

html body #activity-start#activity-start#activity-start .ak-badge { display: none; }

html body #activity-start#activity-start#activity-start .ak-label {
  margin: 0 0 2px;
  font-family: var(--ak-font-display);
  font-size: 12px;
  letter-spacing: 0.16em;
}

html body #activity-start#activity-start#activity-start .ak-body {
  font-size: 16px;
  line-height: 1.4;
}

html body #activity-start#activity-start#activity-start .ak-controls li + li { margin-top: 2px; }

html body #activity-start#activity-start#activity-start .ak-first {
  flex: none;
  margin: 0;
  padding: 10px 12px;
  font-size: 17px;
  line-height: 1.35;
  background: var(--ak-bg);
  border: 4px solid var(--ak-accent-2);
  border-radius: 0;
}

html body #activity-start#activity-start#activity-start .ak-go {
  position: static;
  flex: none;
  width: 100%;
  min-width: 0;
  min-height: 56px;
  margin: 0;
  padding: 0 16px;
  font-size: 20px;
  letter-spacing: 0.14em;
  border: 4px solid var(--ak-ink);
  border-radius: 0;
  box-shadow: inset 0 -5px 0 var(--ak-btn-active);
  animation: none;
  transition: none;
}

html body #activity-start#activity-start#activity-start .ak-go:active {
  transform: none;
  padding-top: 5px;
  box-shadow: none;
}

/* Sideways: the logo and the well on the left, Start here, the how-to and Play on the right. */
@media (orientation: landscape) {
  html body #activity-start#activity-start#activity-start .ak-sheet {
    width: min(100%, 860px);
    display: grid;
    grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "head first" "head howto" "head go";
    gap: 10px 16px;
  }

  html body #activity-start#activity-start#activity-start .ak-head {
    grid-area: head;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "art" "logo" "tag";
    justify-items: center;
    align-content: center;
    row-gap: 8px;
  }

  html body #activity-start#activity-start#activity-start .ak-tagline { text-align: center; }
  html body #activity-start#activity-start#activity-start .ak-first { grid-area: first; }
  html body #activity-start#activity-start#activity-start .ak-howto { grid-area: howto; align-self: stretch; }
  html body #activity-start#activity-start#activity-start .ak-go { grid-area: go; }
}

@media (orientation: landscape) and (max-height: 500px) {
  html body #activity-start#activity-start#activity-start .ak-head::before { width: 56px; height: 92px; background-size: 36px auto, auto 80px; }
  html body #activity-start#activity-start#activity-start .ak-logo { max-height: 92px; }
  html body #activity-start#activity-start#activity-start .ak-first { padding: 8px 10px; font-size: 16px; }
  html body #activity-start#activity-start#activity-start .ak-go { min-height: 52px; }
}

/* The snail on the well hops in whole steps. */
@media (prefers-reduced-motion: no-preference) {
  html body #activity-start#activity-start#activity-start .ak-head::before { animation: welcome-hop 1.6s steps(1, end) infinite; }
}

@keyframes welcome-hop {
  0% { background-position: 100% 0, 0 100%; }
  50% { background-position: 100% 4px, 0 100%; }
}

.best {
  font-family: var(--ak-font-display);
  font-weight: 800;
  font-size: 16px;
  line-height: 1.3;
  color: var(--ak-accent);
}

.summary {
  margin: 0;
  padding-top: 8px;
  font-size: 16px;
  line-height: 1.35;
  border-top: 3px dashed var(--ak-choice-border);
}

/* ---------- the result card, compact enough that Another and Change settings stay in view ---------- */

.end-actions { flex-wrap: nowrap; }

.end-actions .go,
.end-actions .plain {
  flex: 1 1 0;
  min-width: 0;
  padding: 6px 8px;
  font-size: 17px;
  line-height: 1.15;
}

@media (orientation: landscape) and (max-height: 500px) {
  .card {
    grid-template-columns: auto auto;
    column-gap: 12px;
    row-gap: 4px;
    align-items: center;
  }

  .card > * { grid-column: 1 / -1; }
  .card > .dodged { grid-column: 1; justify-self: end; white-space: nowrap; }
  .tally li { width: 26px; height: 26px; padding: 3px; }
  .card > .tally { grid-column: 2; justify-self: start; }
  .done { font-size: 40px; }
  .says { font-size: 16px; }
  .summary { font-size: 15px; padding-top: 4px; }
}

@media (orientation: portrait) and (max-height: 720px) {
  .card { gap: 6px; padding: 8px 10px; }
  .done { font-size: 40px; }
  .says,
  .summary { font-size: 15px; }
  .tally li { width: 28px; height: 28px; }
}
