/* Confidence Bet Quiz: a pinball backbox rebuilt as a betting console.
   Square keys, boxed readouts, engraved labels, tidy rows. Kit colors and fonts only. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  background-color: var(--ak-bg);
  background-image: var(--ak-backdrop-layer, var(--ak-bg-art));
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  overflow: hidden;
  display: grid;
  place-items: center;
  -webkit-text-size-adjust: 100%;
}

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

button:focus-visible {
  outline: 3px solid var(--ak-focus);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.engraved {
  margin: 0;
  font-family: var(--ak-font-body);
  font-weight: 700;
  font-size: 12px;
  line-height: 1.1;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
  text-shadow: 0 -1px 0 #000, 0 1px 0 color-mix(in srgb, var(--ak-ink) 18%, transparent);
}

/* ---------- the console grid ---------- */

.play {
  --gap: 6px;
  --edge: color-mix(in srgb, var(--ak-accent) 55%, var(--ak-bg));
  --deck-h: clamp(124px, 19.5dvh, 172px);
  --reels-h: clamp(46px, 6.6dvh, 58px);
  --plate-h: clamp(48px, 8dvh, 70px);
  --key-h: clamp(52px, 8.4dvh, 74px);
  --keys-w: min(100%, calc(var(--key-h) * 4.385 + 4 * var(--gap)));
  position: relative;
  height: 100dvh;
  width: min(100dvw, 520px);
  margin: 0 auto;
  padding:
    max(8px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto minmax(76px, 1fr) auto auto auto auto auto;
  grid-template-areas:
    "top"
    "ledger"
    "deck"
    "window"
    "answers"
    "status"
    "readouts"
    "keys"
    "action";
  gap: var(--gap);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.play[data-phase="idle"] > :not(.mute):not(.top) {
  visibility: hidden;
}

/* ---------- top: mute, logo, and room for the ? button ---------- */

.mute {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  z-index: 20;
  width: 48px;
  height: 48px;
  padding: 10px;
  border: 2px solid var(--edge);
  border-radius: 3px;
  background: var(--ak-surface);
  box-shadow: inset 0 -3px 0 var(--ak-bg);
  cursor: pointer;
}

.mute svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: var(--ak-ink);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mute .mute-horn {
  fill: var(--ak-ink);
}

.mute .mute-cross {
  display: none;
  stroke: var(--ak-accent-2);
}

.mute[aria-pressed="true"] .mute-waves {
  display: none;
}

.mute[aria-pressed="true"] .mute-cross {
  display: inline;
}

.top {
  grid-area: top;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 48px;
  padding: 0 60px;
}

.logo {
  display: block;
  height: clamp(28px, 4.6dvh, 40px);
  width: auto;
  max-width: 100%;
  object-fit: contain;
}

/* ---------- ledger: one bumper lamp per question ---------- */

.ledger {
  grid-area: ledger;
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(var(--rounds, 6), minmax(0, 1fr));
  gap: 4px;
}

.led {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "lamp key"
    "delta delta";
  align-items: center;
  justify-items: start;
  column-gap: 4px;
  row-gap: 2px;
  min-height: 42px;
  padding: 4px 5px;
  background: var(--ak-bg);
  border: 1px solid var(--edge);
  border-radius: 2px;
  box-shadow: inset 0 2px 0 #000;
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
  color: var(--ak-ink-muted);
}

.led-lamp {
  grid-area: lamp;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--edge);
  background: color-mix(in srgb, var(--ak-bg) 70%, var(--ak-accent));
  display: grid;
  place-items: center;
}

.led-lamp svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: var(--ak-bg);
  stroke-width: 3.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.led-key,
.led-delta {
  white-space: nowrap;
}

.led-key {
  grid-area: key;
}

.led-delta {
  grid-area: delta;
  justify-self: stretch;
  text-align: center;
  color: var(--ak-ink);
}

.led[data-state="now"] {
  border-color: var(--ak-accent);
}

.led[data-state="now"] .led-lamp {
  border-color: var(--ak-accent);
  background: var(--ak-bg);
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--ak-accent) 60%, var(--ak-bg));
}

.led[data-state="right"] .led-lamp {
  border-color: var(--ak-ink);
  background: radial-gradient(circle at 38% 34%, var(--ak-ink) 0 14%, var(--ak-accent) 46%);
}

.led[data-state="wrong"] .led-lamp {
  border-color: var(--ak-ink);
  background: repeating-linear-gradient(135deg, var(--ak-accent-2) 0 4px, var(--ak-accent) 4px 8px);
}

.led[data-state="wrong"] .led-lamp svg {
  stroke: var(--ak-bg);
}

.led[data-state="off"] {
  opacity: 0.55;
}

/* ---------- deck: era card, reels, minis, gauge ---------- */

.deck {
  grid-area: deck;
  height: var(--deck-h);
  display: grid;
  grid-template-columns: calc(var(--deck-h) * 0.516) minmax(0, 1fr) auto;
  grid-template-rows: var(--reels-h) minmax(0, 1fr);
  grid-template-areas:
    "card reels reels"
    "card minis gauge";
  gap: var(--gap);
}

.era-card {
  grid-area: card;
  position: relative;
  container-type: inline-size;
  height: var(--deck-h);
  aspect-ratio: 198 / 384;
}

.era-art {
  display: block;
  width: 100%;
  height: 100%;
}

.era-name {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 13%;
  height: 26.5%;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 2px 3px;
  background: var(--ak-bg);
  border: 2px solid var(--ak-accent);
  border-radius: 4px;
  text-align: center;
  font-weight: 700;
  font-size: 14px;
  line-height: 0.98;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ak-ink);
  overflow: hidden;
  hyphens: manual;
}

.era-lamp {
  position: absolute;
  top: 45.8%;
  width: 25%;
  aspect-ratio: 1;
  translate: -50% -50%;
  border-radius: 50%;
  border: 2px solid var(--ak-bg);
  background: radial-gradient(circle at 40% 36%, color-mix(in srgb, var(--ak-accent) 30%, var(--ak-bg)) 0 30%, var(--ak-bg) 80%);
}

.era-lamp:nth-of-type(1) { left: 23.4%; }
.era-lamp:nth-of-type(2) { left: 49.6%; }
.era-lamp:nth-of-type(3) { left: 75.8%; }

.era-lamp.is-lit {
  background: radial-gradient(circle at 40% 36%, var(--ak-ink) 0 14%, var(--ak-accent) 42%, color-mix(in srgb, var(--ak-accent) 60%, var(--ak-accent-2)) 100%);
}

.era-tier {
  position: absolute;
  left: 13%;
  right: 13%;
  top: 59%;
  height: 22%;
  margin: 0;
  display: grid;
  place-content: center;
  gap: 2px;
  background: var(--ak-bg);
  border-radius: 3px;
  text-align: center;
  line-height: 1;
}

.era-tier b {
  font-family: var(--ak-font-display);
  font-weight: 400;
  font-size: clamp(11px, 15cqw, 18px);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ak-ink);
}

.era-tier span {
  font-weight: 700;
  font-size: clamp(10px, 12cqw, 14px);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
}

.reels-box {
  grid-area: reels;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px;
  background: var(--ak-bg);
  border: 2px solid var(--ak-accent);
  border-radius: 3px;
  box-shadow: inset 0 0 0 2px var(--ak-bg), inset 0 0 0 3px var(--edge);
}

.reels {
  display: flex;
  gap: 3px;
  height: calc(var(--reels-h) - 14px);
}

.reel {
  position: relative;
  width: calc((var(--reels-h) - 14px) * 0.7);
  height: 100%;
  overflow: hidden;
  background: var(--ak-ink);
  border-radius: 2px;
  box-shadow: inset 0 4px 4px -2px #0008, inset 0 -4px 4px -2px #0008;
}

.reel-strip {
  display: flex;
  flex-direction: column;
  translate: 0 calc(var(--d, 10) * -100% / 11);
}

.reel-strip span {
  display: grid;
  place-items: center;
  height: calc(var(--reels-h) - 14px);
  font-family: var(--ak-font-display);
  font-size: calc((var(--reels-h) - 14px) * 0.68);
  line-height: 1;
  color: var(--ak-bg);
}

.minis {
  grid-area: minis;
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: var(--gap);
  min-width: 0;
}

.mini {
  margin: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  padding: 4px 8px;
  background: var(--ak-bg);
  border: 1px solid var(--edge);
  border-radius: 2px;
  min-width: 0;
}

.mini b {
  font-family: var(--ak-font-display);
  font-weight: 400;
  font-size: clamp(14px, 2.2dvh, 19px);
  line-height: 1;
  color: var(--ak-ink);
  white-space: nowrap;
  overflow: hidden;
}

.gauge {
  grid-area: gauge;
  position: relative;
  height: calc(var(--deck-h) - var(--reels-h) - var(--gap));
  aspect-ratio: 384 / 368;
  container-type: inline-size;
}

.gauge-art,
.dial {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.dial-plate {
  fill: var(--ak-surface);
  stroke: var(--ak-accent);
  stroke-width: 5;
}

.dial-band {
  fill: none;
  stroke-width: 34;
}

.band-careful { stroke: var(--ak-ink-muted); }
.band-judged { stroke: var(--ak-accent); }
.band-bold { stroke: var(--ak-accent-2); }

.dial-word {
  font-family: var(--ak-font-body);
  font-weight: 700;
  font-size: 23px;
  letter-spacing: 1.5px;
  fill: var(--ak-bg);
  text-anchor: middle;
  dominant-baseline: central;
}

.needle {
  transform-box: view-box;
  transform-origin: 192px 232px;
  transform: rotate(var(--needle, 0deg));
}

.needle path {
  fill: var(--ak-ink);
  stroke: var(--ak-bg);
  stroke-width: 4;
  stroke-linejoin: round;
}

.hub {
  fill: var(--ak-accent);
  stroke: var(--ak-bg);
  stroke-width: 6;
}

.hub-cap {
  fill: var(--ak-bg);
}

.gauge-read {
  position: absolute;
  left: 11%;
  right: 11%;
  top: 69.5%;
  height: 19%;
  margin: 0;
  display: grid;
  place-items: center;
  background: var(--ak-bg);
  border-radius: 2px;
  font-weight: 700;
  font-size: clamp(10px, 11cqw, 16px);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ak-ink);
  white-space: nowrap;
}

/* ---------- question window ---------- */

.window {
  grid-area: window;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  padding: 8px 12px;
  background: var(--ak-surface);
  border: 2px solid var(--ak-accent);
  border-radius: 3px;
  box-shadow: inset 0 0 0 3px var(--ak-surface), inset 0 0 0 4px var(--edge);
  overflow: hidden;
}

.window-text {
  margin: 0;
  font-weight: 600;
  font-size: 19px;
  line-height: 1.2;
  color: var(--ak-ink);
}

.window[data-mode="era"] .window-text {
  font-family: var(--ak-font-display);
  font-weight: 400;
  font-size: clamp(22px, 3.4dvh, 32px);
  letter-spacing: 0.02em;
}

.window-sub {
  margin: 0;
  font-weight: 600;
  font-size: 16px;
  line-height: 1.2;
  color: var(--ak-ink-muted);
}

.window-sub:empty {
  display: none;
}

.window-sub b {
  color: var(--ak-ink);
}

/* ---------- answer plates (2x2) ---------- */

.answers {
  grid-area: answers;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: var(--plate-h);
  gap: var(--gap);
}

.plate {
  position: relative;
  display: flex;
  min-width: 0;
  height: var(--plate-h);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  text-align: left;
}

.plate-tab,
.plate-face {
  display: grid;
  place-items: center;
  background-image: url("./art/answer-plate.png");
  background-repeat: no-repeat;
  background-size: 480% 327%;
  background-position: 0% var(--row, 0%);
}

.plate-tab {
  flex: 0 0 auto;
  height: 100%;
  aspect-ratio: 80 / 89;
}

.plate-face {
  flex: 1 1 auto;
  min-width: 0;
  background-size: 126.3% 327%;
  background-position: 100% var(--row, 0%);
  padding: 0 9% 0 4%;
  justify-items: start;
}

.plate-letter {
  font-family: var(--ak-font-display);
  font-size: calc(var(--plate-h) * 0.36);
  line-height: 1;
  color: var(--ak-ink);
}

.plate-mark {
  display: none;
  width: calc(var(--plate-h) * 0.36);
  height: calc(var(--plate-h) * 0.36);
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.plate-text {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-weight: 700;
  font-size: clamp(14px, calc(var(--plate-h) * 0.27), 21px);
  line-height: 1.1;
  color: var(--ak-choice-ink);
  overflow-wrap: anywhere;
}

.plate[data-state="idle"] {
  cursor: default;
}

.plate[data-state="idle"] .plate-tab,
.plate[data-state="idle"] .plate-face {
  filter: brightness(0.75) saturate(0.7);
}

.plate-lock {
  display: none;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
}

.plate-lock svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--ak-ink-muted);
  stroke-width: 2.4;
  stroke-linejoin: round;
}

.plate[data-state="idle"] .plate-lock {
  display: inline-flex;
}

.plate[data-state="idle"] .plate-text {
  display: none;
}

.plate[data-state="idle"] .plate-letter {
  color: var(--ak-ink-muted);
}

.plate[data-state="right"],
.plate[data-state="answer"] {
  --row: 50%;
}

.plate[data-state="right"] .plate-text,
.plate[data-state="answer"] .plate-text {
  color: var(--ak-btn-ink);
}

.plate[data-state="right"] .plate-letter,
.plate[data-state="answer"] .plate-letter,
.plate[data-state="wrong"] .plate-letter {
  display: none;
}

.plate[data-state="right"] .plate-mark.is-tick,
.plate[data-state="answer"] .plate-mark.is-tick {
  display: block;
  stroke: var(--ak-btn-ink);
}

.plate[data-state="wrong"] {
  --row: 100%;
}

.plate[data-state="wrong"] .plate-mark.is-cross {
  display: block;
  stroke: var(--ak-accent-2);
}

.plate[data-state="wrong"] .plate-text {
  padding: 3px 6px;
  background: var(--ak-bg);
  border-radius: 2px;
  color: var(--ak-ink);
}

.plate[data-state="dim"] .plate-tab,
.plate[data-state="dim"] .plate-face {
  filter: brightness(0.55) saturate(0.5);
}

.plate[data-state="dim"] .plate-text,
.plate[data-state="dim"] .plate-letter {
  color: var(--ak-ink-muted);
}

.plate-pick {
  position: absolute;
  right: 6%;
  top: -2px;
  padding: 1px 5px;
  background: var(--ak-bg);
  border: 1px solid var(--ak-accent);
  border-radius: 2px;
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ak-ink);
  display: none;
}

.plate[data-picked="true"] .plate-pick {
  display: block;
}

/* ---------- status strip ---------- */

.status {
  grid-area: status;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 12px;
  background: var(--ak-bg);
  border-top: 1px solid var(--edge);
  border-bottom: 1px solid var(--edge);
  font-weight: 600;
  font-size: 16px;
  line-height: 1.2;
  color: var(--ak-ink);
}

.status-lamp {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ak-accent);
  box-shadow: 0 0 0 2px var(--ak-bg), 0 0 0 3px var(--edge);
}

.status[data-kind="error"] .status-lamp {
  border-radius: 1px;
  rotate: 45deg;
  background: var(--ak-accent-2);
}

.status[data-kind="error"] {
  border-color: var(--ak-accent-2);
}

.status[data-kind="wrong"] .status-lamp {
  background: repeating-linear-gradient(135deg, var(--ak-accent-2) 0 3px, var(--ak-accent) 3px 6px);
}

/* ---------- stake keys and their readouts ---------- */

.readouts,
.keys {
  width: var(--keys-w);
  justify-self: center;
  display: grid;
  grid-template-columns: 61fr 61fr 61fr 61fr 98fr;
  column-gap: var(--gap);
}

.readouts {
  grid-area: readouts;
  row-gap: 3px;
}

.readouts-label {
  grid-column: 1 / -1;
  text-align: center;
}

.ro {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  min-height: 28px;
  padding: 1px 0;
  background: var(--ak-bg);
  border-bottom: 2px solid transparent;
  font-weight: 600;
  font-size: 12px;
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
  color: var(--ak-ink-muted);
}

.ro-win,
.ro-lose,
.ro-total {
  color: var(--ak-ink-muted);
}

.ro-total {
  font-size: 13px;
  font-weight: 700;
}

.ro.is-mine {
  border-bottom-color: var(--ak-accent);
}

.ro.is-mine .ro-win,
.ro.is-mine .ro-lose,
.ro.is-mine .ro-total {
  color: var(--ak-ink);
  font-weight: 700;
}

.keys {
  grid-area: keys;
  align-items: end;
}

.key {
  position: relative;
  width: 100%;
  aspect-ratio: 61 / 78;
  padding: 0;
  border: 0;
  background-color: transparent;
  background-image: url("./art/stake-key.png");
  background-repeat: no-repeat;
  background-size: 629.5% 167.95%;
  background-position: var(--kx) 50.94%;
  cursor: pointer;
  filter: drop-shadow(0 3px 0 #000);
}

.key[data-key="0"] { --kx: 5.263%; }
.key[data-key="10"] { --kx: 25.08%; }
.key[data-key="25"] { --kx: 44.27%; }
.key[data-key="50"] { --kx: 63.16%; }

.key[data-key="all"] {
  --kx: 93.36%;
  aspect-ratio: 98 / 78;
  background-size: 391.84% 167.95%;
  filter: drop-shadow(0 3px 0 #000) brightness(1.14) saturate(0.8);
}

.key-lamp {
  position: absolute;
  left: 50.8%;
  top: 30.8%;
  width: 25%;
  aspect-ratio: 1;
  translate: -50% -50%;
  border-radius: 50%;
}

.key[data-key="all"] .key-lamp {
  left: 46.9%;
  width: 19%;
  background: radial-gradient(circle at 40% 36%, color-mix(in srgb, var(--ak-accent) 45%, var(--ak-bg)) 0 30%, color-mix(in srgb, var(--ak-accent) 30%, var(--ak-bg)) 75%);
  box-shadow: 0 0 0 1px var(--ak-bg);
}

.key[aria-pressed="true"] {
  translate: 0 3px;
  filter: brightness(0.8) saturate(1.15);
}

.key[data-key="all"][aria-pressed="true"] {
  filter: none;
}

.key[aria-pressed="true"] .key-lamp {
  background: radial-gradient(circle at 40% 36%, var(--ak-ink) 0 16%, var(--ak-accent) 50%, color-mix(in srgb, var(--ak-accent) 70%, var(--ak-accent-2)) 100%);
  box-shadow: 0 0 0 1px var(--ak-bg);
}

.key:disabled {
  cursor: default;
}

.play[data-phase="answer"] .key:not([aria-pressed="true"]),
.play[data-phase="result"] .key:not([aria-pressed="true"]) {
  filter: drop-shadow(0 3px 0 #000) brightness(0.62) saturate(0.6);
}

.key.is-demo {
  outline: 3px solid var(--ak-accent);
  outline-offset: 4px;
}

.keys.is-nudge .key {
  outline: 2px solid var(--ak-accent-2);
  outline-offset: 2px;
}

/* ---------- the big action key ---------- */

.action,
.print-btn,
.got-it {
  min-height: 52px;
  padding: 0 20px;
  border: 2px solid var(--ak-bg);
  border-radius: 3px;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  box-shadow: inset 0 -5px 0 var(--ak-btn-active), inset 0 2px 0 color-mix(in srgb, var(--ak-ink) 60%, transparent), 0 0 0 1px var(--edge);
  font-family: var(--ak-font-display);
  font-size: 18px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.action {
  grid-area: action;
  width: var(--keys-w);
  justify-self: center;
}

.action:active,
.print-btn:active,
.got-it:active {
  translate: 0 3px;
  box-shadow: inset 0 -2px 0 var(--ak-btn-active), 0 0 0 1px var(--edge);
}

.action.is-waiting {
  background: var(--ak-surface);
  color: var(--ak-ink);
  border-color: var(--ak-accent);
  box-shadow: inset 0 -4px 0 var(--ak-bg), 0 0 0 1px var(--edge);
}

.action[aria-disabled="true"] {
  background: var(--ak-surface);
  color: var(--ak-ink-muted);
  box-shadow: inset 0 -3px 0 var(--ak-bg), 0 0 0 1px var(--edge);
  cursor: default;
}

.action[aria-disabled="true"]:active {
  translate: none;
}

.action.is-down {
  translate: 0 3px;
  box-shadow: inset 0 -2px 0 var(--ak-btn-active), 0 0 0 1px var(--edge);
}

/* ---------- worked example ---------- */

.teach {
  grid-row: window-start / status-end;
  grid-column: window-start / window-end;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--ak-bg);
  border: 2px solid var(--ak-accent);
  border-radius: 3px;
  box-shadow: inset 0 0 0 3px var(--ak-bg), inset 0 0 0 4px var(--edge);
  z-index: 2;
}

.teach-text {
  margin: 0;
  font-weight: 600;
  font-size: 19px;
  line-height: 1.3;
  color: var(--ak-ink);
}

.teach-text b {
  font-weight: 700;
  color: var(--ak-ink);
  border-bottom: 2px solid var(--ak-accent);
}

.teach-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.teach-arrow {
  width: 44px;
  height: 44px;
  fill: none;
  stroke: var(--ak-accent);
  stroke-width: 5;
  stroke-linecap: square;
}

.got-it {
  flex: 1 1 auto;
  max-width: 240px;
  min-height: 56px;
  font-size: 20px;
}

/* ---------- final readout ---------- */

.print {
  /* Fills the slot the controls leave behind; never pushes the console around. */
  contain: size;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  background: var(--ak-bg);
  border: 2px solid var(--ak-accent);
  border-radius: 3px;
  box-shadow: inset 0 0 0 3px var(--ak-bg), inset 0 0 0 4px var(--edge);
  min-height: 0;
  overflow: auto;
}

.print-trade {
  grid-area: answers;
  justify-content: center;
}

.print-main {
  grid-row: status-start / action-end;
  grid-column: status-start / status-end;
}

.print-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.print-story {
  margin: 0;
  font-weight: 600;
  font-size: 15px;
  line-height: 1.25;
  color: var(--ak-ink);
}

.window-note {
  display: block;
}

.print-copy {
  margin: 0;
  font-weight: 600;
  font-size: 17px;
  line-height: 1.28;
  color: var(--ak-ink);
}

.print-row {
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr));
  gap: 4px;
}

.print-cell {
  margin: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  padding: 5px 6px;
  border: 1px solid var(--edge);
  border-radius: 2px;
  background: var(--ak-surface);
  min-width: 0;
}

.print-cell b {
  font-family: var(--ak-font-display);
  font-weight: 400;
  font-size: 16px;
  line-height: 1;
  color: var(--ak-ink);
  white-space: nowrap;
  overflow: hidden;
}

.print-cell.is-best {
  border: 2px solid var(--ak-accent);
}

.print-cell.is-best {
  background: var(--ak-btn-fill);
}

.print-cell.is-best .engraved,
.print-cell.is-best b {
  color: var(--ak-btn-ink);
  text-shadow: none;
}

.print-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: auto;
}

.print-btn.is-quiet {
  background: var(--ak-surface);
  color: var(--ak-ink);
  border-color: var(--ak-accent);
  box-shadow: inset 0 -4px 0 var(--ak-bg), 0 0 0 1px var(--edge);
  font-size: 16px;
}

.play[data-phase="over"].is-printed .answers,
.play[data-phase="over"].is-printed .status,
.play[data-phase="over"].is-printed .readouts,
.play[data-phase="over"].is-printed .keys,
.play[data-phase="over"].is-printed .action {
  visibility: hidden;
}

/* ---------- landscape: board on the left, controls on the right ---------- */

@media (orientation: landscape) {
  .play {
    --deck-h: clamp(120px, 36dvh, 280px);
    --reels-h: clamp(42px, 11dvh, 64px);
    --plate-h: clamp(44px, 12dvh, 74px);
    --key-h: clamp(50px, 14dvh, 86px);
    width: min(100dvw, 1080px);
    height: min(100dvh, 700px);
    grid-template-columns: minmax(0, 1.08fr) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto auto;
    grid-template-areas:
      "ledger  top"
      "window  deck"
      "answers readouts"
      "answers keys"
      "status  action";
    column-gap: 14px;
  }

  .top {
    min-height: 44px;
    padding: 0 60px 0 0;
    justify-content: flex-start;
  }

  .ledger {
    padding-left: 56px;
    align-self: center;
  }

  .era-name {
    padding: 1px 2px;
    letter-spacing: 0.02em;
  }

  .deck {
    align-self: center;
  }

  .answers {
    align-content: center;
  }

  .window-text {
    font-size: clamp(16px, 4.6dvh, 30px);
  }

  .window-sub {
    font-size: clamp(15px, 3dvh, 20px);
  }

  .teach-arrow {
    rotate: -90deg;
    order: 2;
  }

  .print-main {
    grid-row: readouts-start / action-end;
    grid-column: readouts-start / readouts-end;
  }

  .print-trade {
    grid-row: answers-start / answers-end;
  }

  .play[data-phase="over"].is-printed .status {
    visibility: visible;
  }

  .print-copy {
    font-size: 15px;
  }

  .print-main .print-row {
    display: none;
  }

  .print-story {
    font-size: 14px;
    line-height: 1.2;
  }

  .print-trade {
    gap: 5px;
    container-type: inline-size;
  }

  .print-trade .print-cell {
    gap: 1px;
    padding: 3px 5px;
  }

  .print-trade .print-cell .engraved {
    font-size: 10px;
  }

  .print-trade .print-cell b {
    font-size: 14px;
  }

  /* With room, key totals print on one line each so the run story fits above them. */
  @container (min-width: 380px) {
    .print-trade .print-cell {
      flex-direction: row;
      align-items: baseline;
      justify-content: space-between;
      gap: 4px;
      padding: 4px 6px;
    }
  }
}

/* Short sideways phones: tighten the type so every row still fits. */
@media (orientation: landscape) and (max-height: 430px) {
  .top {
    min-height: 40px;
  }

  .led {
    min-height: 36px;
    padding: 3px 4px;
    font-size: 12px;
  }

  .led-lamp {
    width: 14px;
    height: 14px;
  }

  .led-lamp svg {
    width: 9px;
    height: 9px;
  }

  .readouts-label {
    font-size: 10px;
  }

  .led {
    font-size: 11px;
    column-gap: 3px;
  }

  .ro {
    min-height: 32px;
  }

  .status {
    min-height: 40px;
    font-size: 14px;
  }

  .teach {
    padding: 10px 12px;
    gap: 6px;
  }

  .teach-text {
    font-size: 18px;
    line-height: 1.22;
  }

  .got-it {
    min-height: 48px;
  }

  .print {
    padding: 6px 8px;
    gap: 5px;
  }

  .print-btn {
    min-height: 48px;
    font-size: 15px;
  }
}

/* Small upright phones */
@media (orientation: portrait) and (max-height: 720px) {
  .play {
    --gap: 4px;
    --deck-h: clamp(108px, 21dvh, 150px);
    --reels-h: 42px;
    --plate-h: 44px;
    --key-h: 52px;
    grid-template-rows: auto auto auto minmax(58px, 1fr) auto auto auto auto auto;
  }

  .top {
    min-height: 44px;
  }

  .logo {
    height: 26px;
  }

  .minis {
    grid-template-rows: none;
    grid-template-columns: 1fr 1fr;
  }

  .mini {
    padding: 4px 6px;
  }

  .mini b {
    font-size: 14px;
  }

  .readouts-label {
    font-size: 10px;
  }

  .ro {
    min-height: 30px;
  }

  .action {
    min-height: 48px;
  }

  .window {
    padding: 4px 10px;
  }

  /* The locked plates say it already; keep the short window for the era. */
  .window-note {
    display: none;
  }

  .print-story {
    font-size: 14px;
  }

  .led {
    min-height: 36px;
    font-size: 12px;
  }

  .window-text {
    font-size: 17px;
  }

  .status {
    min-height: 36px;
    padding: 4px 10px;
    font-size: 15px;
  }

  .teach {
    padding: 10px 12px;
    gap: 6px;
  }

  .teach-text {
    font-size: 18px;
    line-height: 1.22;
  }

  .got-it {
    min-height: 48px;
  }

  .print {
    padding: 6px 8px;
    gap: 5px;
  }

  .print-copy {
    font-size: 15px;
  }

  .print-main .print-row {
    display: none;
  }

  .print-btn {
    min-height: 48px;
    font-size: 15px;
  }
}

/* ---------- motion: things snap, roll, and swing ---------- */

@media (prefers-reduced-motion: no-preference) {
  .key {
    transition: translate 70ms cubic-bezier(0.2, 0, 0, 1), filter 70ms linear;
  }

  .reel-strip {
    transition: translate 90ms cubic-bezier(0.3, 0, 0.2, 1);
  }

  .needle {
    transition: transform 900ms cubic-bezier(0.3, 1.7, 0.5, 1);
  }

  .play[data-phase="bet"] .key:not([aria-pressed="true"]) .key-lamp {
    animation: lamp-wait 2.4s steps(1) infinite;
    animation-delay: calc(var(--i) * 0.24s);
  }

  .play[data-phase="bet"] .keys:has(.key[aria-pressed="true"]) .key-lamp {
    animation: none;
  }

  .ro.is-tick {
    animation: tick-in 260ms steps(4) both;
    animation-delay: calc(var(--i) * 90ms);
  }

  .plate[data-state="right"] .plate-face,
  .plate[data-state="wrong"] .plate-face,
  .plate[data-state="answer"] .plate-face {
    animation: relay 180ms steps(2) both;
  }

  .led.is-fresh .led-lamp {
    animation: relay 240ms steps(3) both;
  }

  .play.is-printed .led .led-lamp {
    animation: chase 1.4s steps(1) both;
    animation-delay: calc(var(--i) * 120ms);
  }

  .play.is-settling .needle {
    animation: settle 1.6s cubic-bezier(0.2, 0.8, 0.3, 1) both;
  }

  .print.is-printing > * {
    animation: print-line 320ms steps(6) both;
    animation-delay: calc(var(--line, 0) * 150ms);
  }

  .key.is-demo {
    animation: ring 1.2s ease-in-out infinite;
  }

  .status[data-kind="error"] .status-lamp {
    animation: relay 300ms steps(3) both;
  }
}

@keyframes lamp-wait {
  0%, 12% {
    background: radial-gradient(circle at 40% 36%, var(--ak-ink) 0 16%, var(--ak-accent) 55%);
  }
  13%, 100% {
    background: transparent;
  }
}

@keyframes tick-in {
  from {
    clip-path: inset(0 0 100% 0);
  }
  to {
    clip-path: inset(0 0 0 0);
  }
}

@keyframes relay {
  0% { opacity: 0.35; }
  50% { opacity: 1; }
  70% { opacity: 0.6; }
  100% { opacity: 1; }
}

@keyframes chase {
  0% { filter: brightness(1); }
  20% { filter: brightness(1.8); }
  40% { filter: brightness(0.5); }
  60% { filter: brightness(1.8); }
  80%, 100% { filter: brightness(1); }
}

@keyframes settle {
  0% { transform: rotate(var(--needle-from, 0deg)); }
  35% { transform: rotate(calc(var(--needle, 0deg) + 14deg)); }
  60% { transform: rotate(calc(var(--needle, 0deg) - 7deg)); }
  80% { transform: rotate(calc(var(--needle, 0deg) + 3deg)); }
  100% { transform: rotate(var(--needle, 0deg)); }
}

@keyframes print-line {
  from {
    clip-path: inset(0 0 100% 0);
  }
  to {
    clip-path: inset(0 0 0 0);
  }
}

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

/* ---------- start screen (built by start.js): lighter wash, and Play gets its own room ---------- */

body #activity-start.has-backdrop::before {
  background-image:
    linear-gradient(color-mix(in srgb, var(--ak-bg) 55%, transparent), color-mix(in srgb, var(--ak-bg) 55%, transparent)),
    url("./art/console-backdrop.jpg");
  background-size: auto, cover;
}

body #activity-start .ak-section {
  padding: 8px 12px;
  background: var(--ak-bg);
  border-radius: 2px;
}

body #activity-start .ak-howto {
  gap: 10px;
  margin-top: 14px;
}

body #activity-start .ak-badge {
  font-size: 20px;
}

body #activity-start .ak-tagline {
  display: inline-block;
  padding: 4px 10px;
  background: var(--ak-bg);
}

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

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

body #activity-start .ak-first {
  margin-top: 14px;
  padding: 10px 14px;
  font-size: 18px;
}

body #activity-start .ak-go {
  margin-top: 14px;
}

body #activity-start .ak-first {
  border-radius: 3px;
}

body #activity-start .ak-go {
  border-radius: 3px;
}

@media (orientation: portrait) {
  body #activity-start .ak-go {
    position: static;
  }
}

/* Sideways the sheet scrolls, so Play stays docked on a solid tray instead of floating over text. */
@media (orientation: landscape) {
  body #activity-start .ak-go {
    bottom: 0;
    box-shadow: 0 0 0 12px var(--ak-surface), 0 16px 0 12px var(--ak-surface);
  }
}
