/* Blueprint: thin light lines on the darkest kit colour, square corners, callouts with leaders. */
:root {
  --line: color-mix(in srgb, var(--ak-accent-2) 55%, transparent);
  --line-faint: color-mix(in srgb, var(--ak-accent-2) 22%, transparent);
  --grid: color-mix(in srgb, var(--ak-accent-2) 7%, transparent);
  --lamp-off: #1A2636;
  /* Plate frame scale: the painted frame is drawn at this fraction of its size. */
  --pk: 0.62;
  --band: 44px;
  --dim-h: 22px;
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }

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

body {
  overflow: hidden;
  background-color: var(--ak-bg);
  background-image: var(--ak-bg-art);
  background-size: var(--ak-bg-size);
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

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

.backdrop {
  position: fixed;
  inset: -3%;
  z-index: -1;
  background-color: var(--ak-bg);
  background-image: var(--ak-backdrop-layer, none);
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
}

.backdrop::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
}

/* ---------- layout: upright, board above the controls ---------- */
.deck {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  grid-template-areas:
    "top"
    "status"
    "board"
    "keys"
    "foot";
  gap: clamp(4px, 1.1dvh, 12px);
  width: min(100%, 560px);
  height: 100dvh;
  margin: 0 auto;
  padding:
    max(8px, var(--safe-t))
    max(12px, var(--safe-r))
    max(10px, var(--safe-b))
    max(12px, var(--safe-l));
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.deck[hidden] { display: none; }

.top {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 48px;
  padding-right: 60px;
}

.status { grid-area: status; position: relative; display: grid; gap: 6px; }
.board { grid-area: board; display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.keys { grid-area: keys; }
.foot { grid-area: foot; display: flex; justify-content: center; }

/* ---------- top rail ---------- */
.mute {
  flex: none;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--ak-bg);
  color: var(--ak-accent-2);
}

.mute svg { width: 26px; height: 26px; }
.mute:active { background: var(--ak-surface); }

.logo {
  height: 38px;
  width: auto;
  max-width: calc(100% - 60px);
  object-fit: contain;
  object-position: left center;
}

/* ---------- the clock: painted lamp rail with live lamps on top ---------- */
.clock {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.lamps {
  position: relative;
  flex: none;
  width: min(calc(100% - 76px), 360px, 12dvh * 384 / 118);
  aspect-ratio: 384 / 118;
}

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

.lamp {
  position: absolute;
  top: 50%;
  width: 6.4%;
  aspect-ratio: 1;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: var(--lamp-off);
  box-shadow: inset 0 2px 3px #00000088, 0 0 0 2px #05080D;
  transition: background-color 320ms ease, box-shadow 320ms ease;
}

.lamp.on {
  background: radial-gradient(circle at 38% 34%, #E8FFFF 0 14%, var(--ak-accent-2) 42%, #0FA8C0 100%);
  box-shadow: 0 0 0 2px #05080D;
}

.lamp.warn {
  background: radial-gradient(circle at 38% 34%, #FFE2CC 0 14%, var(--ak-accent) 46%, #A83C0C 100%);
}

.secs {
  margin: 0;
  display: grid;
  justify-items: center;
  min-width: 64px;
  padding: 4px 6px;
  background: var(--ak-bg);
  border: 1px solid var(--line);
  font-family: var(--ak-font-display);
  font-weight: 800;
  font-size: 26px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.secs small {
  margin-top: 3px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
}

.secs.low { color: var(--ak-accent); border-color: var(--ak-accent); }

/* ---------- readout strip: one drafting row, hairline dividers ---------- */
.readout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  overflow: hidden;
  background: var(--ak-bg);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.seg {
  margin: 0;
  display: grid;
  gap: 2px;
  padding: 4px 10px;
  min-width: 0;
}

.seg + .seg { border-left: 1px solid var(--line-faint); }

.seg small {
  font-family: var(--ak-font-display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
}

.seg b {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--ak-font-display);
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.best { color: var(--ak-ink-muted); }
#score { display: inline-block; }
.best.beaten { color: var(--ak-accent); }

.pips { display: inline-flex; gap: 2px; }

.pip {
  width: 6px;
  height: 6px;
  border: 1.5px solid var(--ak-accent-2);
  transform: rotate(45deg);
}

.pip.on { background: var(--ak-accent-2); }
.pip.step { margin-left: 4px; }

.frames { gap: 3px !important; }
.frames svg { width: 15px; height: 13px; }
.frames .fo { fill: none; stroke: var(--ak-ink-muted); stroke-width: 1.4; }
.frames .fi { fill: none; stroke: var(--line); stroke-width: 1; }
.frames .lit .fo { stroke: var(--ak-accent); }
.frames .lit .fi { fill: var(--ak-accent-2); stroke: var(--ak-accent-2); }

/* ---------- the reason the run ended, stamped over the clock ---------- */
.reason {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 2px;
  background: var(--ak-bg);
  border: 2px solid var(--ak-accent);
  outline: 1px solid var(--ak-accent);
  outline-offset: 3px;
  text-align: center;
}

.reason[hidden] { display: none; }

.reason strong {
  font-family: var(--ak-font-display);
  font-size: clamp(24px, 4.2dvh, 34px);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ak-accent);
}

.reason span {
  font-size: 16px;
  color: var(--ak-ink);
}

/* ---------- the stage: callout band, plate, dimension line ---------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 150px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: var(--band);
}

.plate {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--row, 12px);
  min-width: 210px;
  border-style: solid;
  border-width: calc(38px * var(--pk)) calc(18px * var(--pk)) calc(26px * var(--pk)) calc(18px * var(--pk));
  border-image-source: url('./art/name-plate.png');
  border-image-slice: 38 18 26 18;
  border-image-repeat: stretch;
  padding: 16px 12px 10px;
  background-color: var(--ak-bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 14px 14px;
  background-clip: padding-box;
  box-shadow: inset 0 0 0 2px var(--ak-accent-2);
}

.drop {
  position: absolute;
  z-index: 0;
  top: 5px;
  left: 0;
  width: 2px;
  height: 0;
  margin-left: -1px;
  background: repeating-linear-gradient(var(--ak-accent-2) 0 4px, transparent 4px 7px);
}

.line {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  gap: var(--sp);
  margin-top: 9px;
}

/* the dimension hairline over each row, with a tick at every letter */
.line::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: -8px;
  height: 1px;
  background: var(--line);
}

.word { display: flex; gap: var(--g); }

.ch, .gap, .mark {
  position: relative;
  flex: none;
  height: var(--s);
  background: var(--ak-bg);
}

.ch::before, .gap::before {
  content: '';
  position: absolute;
  left: 50%;
  top: -12px;
  width: 1px;
  height: 8px;
  background: var(--line);
}

.ch {
  display: grid;
  place-items: center;
  width: var(--c);
  font-family: var(--ak-font-display);
  font-size: var(--fs);
  font-weight: 800;
  line-height: 1;
  color: var(--ak-ink);
}

.mark {
  display: grid;
  place-items: end center;
  width: calc(var(--c) * 0.5);
  font-family: var(--ak-font-display);
  font-size: calc(var(--fs) * 0.7);
  color: var(--ak-ink-muted);
}

.gap {
  display: block;
  width: var(--s);
  padding: 0;
  border: 0;
  touch-action: manipulation;
}

.gap svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.gap .hole {
  fill: var(--ak-bg);
  stroke: var(--ak-accent-2);
  stroke-width: 1.6;
  stroke-dasharray: 4 3;
}

.gap.is-active .hole {
  stroke-width: 3;
  stroke-dasharray: none;
  fill: color-mix(in srgb, var(--ak-accent-2) 14%, var(--ak-bg));
}

.gap .caret {
  fill: var(--ak-accent-2);
}

.gap.is-wrong .hole { stroke: var(--ak-accent); stroke-width: 2.4; }

.gap .num {
  font-family: var(--ak-font-display);
  font-size: 7.5px;
  font-weight: 700;
  text-anchor: end;
  fill: var(--ak-ink-muted);
}

.gap .ruled {
  font-family: var(--ak-font-display);
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 1px;
  fill: var(--ak-accent);
}

.gap .strike { stroke: var(--ak-accent); stroke-width: 1.4; }
.gap.is-wrong.is-active .hole { stroke-dasharray: none; }
.gap .notch { fill: var(--ak-accent); }

.gap .pc {
  fill: var(--ak-accent-2);
  stroke: var(--ak-ink);
  stroke-width: 2.6;
  stroke-linejoin: round;
}

.gap .lt {
  font-family: var(--ak-font-display);
  font-weight: 800;
  font-size: 17px;
  text-anchor: middle;
  fill: var(--ak-bg);
}

.gap.bad .pc { fill: var(--ak-accent); }
.gap.bad .lt { fill: var(--ak-btn-ink); }

.gap.shown .pc {
  fill: var(--ak-bg);
  stroke: var(--ak-accent);
  stroke-dasharray: 3 2;
}

.gap.shown .lt { fill: var(--ak-accent); }

.dim {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--plate-w, 220px);
  max-width: 100%;
  height: var(--dim-h);
  margin-top: 4px;
}

.dim::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--line);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.dim::after {
  content: '';
  position: absolute;
  inset: 3px 0;
  border-left: 1px solid var(--ak-accent-2);
  border-right: 1px solid var(--ak-accent-2);
}

.stage.tight .dim { display: none; }

.dim span {
  position: relative;
  z-index: 1;
  padding: 0 8px;
  background: var(--ak-bg);
  font-family: var(--ak-font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
}

/* the callout tag rides above the plate, its dot on the gap being filled */
.callout {
  position: absolute;
  z-index: 4;
  left: 0;
  top: 0;
  width: var(--cw, 140px);
  aspect-ratio: 384 / 210;
  pointer-events: none;
}

.callout[hidden] { display: none; }

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

.callout.flip img { transform: scaleX(-1); }

.callout-text {
  position: absolute;
  left: 32%;
  top: 11.5%;
  width: 62%;
  height: 39%;
  display: grid;
  place-items: center;
  background: var(--ak-surface);
  font-family: var(--ak-font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--ak-ink);
}

.callout.flip .callout-text { left: 6%; }

/* ---------- clue note and the message line ---------- */
.note {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 6px 12px;
  background: var(--ak-surface);
  border: 1px solid var(--line-faint);
  border-left: 3px solid var(--ak-accent-2);
}

.note[hidden], .msg[hidden] { display: none; }

.note small {
  flex: none;
  font-family: var(--ak-font-display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ak-accent-2);
}

.note span { font-size: 17px; line-height: 1.25; }
.note.off span { color: var(--ak-ink-muted); }

.msg {
  margin: 0;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--ak-bg);
  border-left: 3px solid var(--line);
  font-size: 17px;
  line-height: 1.25;
}

.msg svg { flex: none; width: 20px; height: 20px; }
.msg.wrong { border-left-color: var(--ak-accent); }
.msg.wrong svg { color: var(--ak-accent); }
.msg.good { border-left-color: var(--ak-accent-2); }
.msg b { font-family: var(--ak-font-display); letter-spacing: 0.06em; }
.msg.wrong b { color: var(--ak-accent); }
.msg.turn b { white-space: nowrap; }

/* ---------- worked example ---------- */
.teach {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: var(--ak-surface);
  border: 2px solid var(--ak-accent-2);
}

.teach[hidden] { display: none; }

.standby {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: var(--ak-surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--ak-accent);
}

.standby[hidden] { display: none; }

.standby-title {
  margin: 0;
  font-family: var(--ak-font-display);
  font-size: clamp(20px, 3.2dvh, 28px);
  font-weight: var(--ak-title-weight);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ak-ink);
}

.standby-text {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
  color: var(--ak-ink);
}

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

.got-it {
  min-height: 56px;
  border: 0;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font-family: var(--ak-font-display);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  clip-path: polygon(12px 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0 100%, 0 12px);
}

.got-it:active { background: var(--ak-btn-active); }

/* ---------- vowel keys: the painted console with live keys over each bay ---------- */
.keys {
  position: relative;
  justify-self: center;
  width: min(100%, 440px, 19dvh * 384 / 149);
  aspect-ratio: 384 / 149;
  background: url('./art/vowel-keys.png') center / 100% 100% no-repeat;
}

.key {
  position: absolute;
  padding: 0;
  border: 0;
  background: transparent;
  touch-action: manipulation;
}

.key-face {
  position: absolute;
  background-image: url('./art/vowel-keys.png');
  background-repeat: no-repeat;
  background-color: #1B2633;
  transition: filter 160ms ease;
}

.key:disabled { cursor: default; }
.keys.locked .key-face { filter: saturate(0.45) brightness(0.7); }

.key-badge {
  position: absolute;
  top: -12px;
  left: 50%;
  margin-left: -14px;
  z-index: 2;
  display: none;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--ak-accent-2);
  color: var(--ak-bg);
  border: 2px solid var(--ak-bg);
  font-family: var(--ak-font-display);
  font-size: 15px;
  font-weight: 800;
}

.key.taught .key-badge { display: grid; }

.key-x {
  position: absolute;
  inset: 22% 18%;
  z-index: 2;
  display: none;
  pointer-events: none;
}

.key-x svg { width: 100%; height: 100%; }
.key.ruled .key-x { display: block; }
.key.ruled .key-face { filter: saturate(0.35) brightness(0.6); }
.key.taught .key-face { filter: none; outline: 3px solid var(--ak-accent-2); outline-offset: 1px; }

/* ---------- skip ---------- */
.skip {
  min-height: 52px;
  min-width: 200px;
  padding: 0 24px;
  border: 0;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font-family: var(--ak-font-display);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  clip-path: polygon(12px 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0 100%, 0 12px);
}

.skip span { margin-left: 6px; font-size: 13px; font-weight: 700; opacity: 0.9; }
.skip:active { background: var(--ak-btn-active); }
.skip:disabled { cursor: default; background: var(--ak-surface); color: var(--ak-ink-muted); }

@media (hover: hover) {
  .skip:not(:disabled):hover, .got-it:hover, .tb-go:hover { background: var(--ak-btn-hover); }
  .mute:hover { background: var(--ak-surface); }
  .tb-alt:hover { background: var(--ak-surface); }
}

/* ---------- the title block that lands in the corner ---------- */
.titleblock {
  position: fixed;
  z-index: 30;
  right: max(10px, var(--safe-r));
  bottom: max(10px, var(--safe-b));
  width: min(calc(100vw - 20px), 390px);
  display: grid;
  background: var(--ak-bg);
  border: 2px solid var(--ak-ink);
  outline: 1px solid var(--line);
  outline-offset: 4px;
}

.titleblock[hidden] { display: none; }

.tb-head {
  display: flex;
  justify-content: flex-start;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  font-family: var(--ak-font-display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
}

.tb-says {
  margin: 0;
  padding: 10px 12px;
  padding-right: 84px;
  border-bottom: 1px solid var(--line);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
}

.tb-grid {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--line);
}

.tb-grid div { padding: 6px 8px; }
.tb-grid div + div { border-left: 1px solid var(--line); }

.tb-grid dt {
  font-family: var(--ak-font-display);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
}

.tb-grid dd {
  margin: 2px 0 0;
  font-family: var(--ak-font-display);
  font-size: 24px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.tb-run {
  margin: 0;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
  line-height: 1.3;
  color: var(--ak-ink);
}

.tb-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px;
}

.tb-go, .tb-alt {
  min-height: 52px;
  padding: 0 10px;
  font-family: var(--ak-font-display);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.tb-go {
  border: 0;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}

.tb-go:active { background: var(--ak-btn-active); }

.tb-alt {
  border: 1px solid var(--ak-choice-border);
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
}

.tb-stamp {
  position: absolute;
  top: -20px;
  right: 14px;
  padding: 6px 8px;
  border: 3px solid var(--ak-accent);
  background: var(--ak-bg);
  color: var(--ak-accent);
  font-family: var(--ak-font-display);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1.05;
  text-align: center;
  text-transform: uppercase;
  transform: rotate(-8deg);
}

.tb-stamp:empty { display: none; }

/* ---------- effects layer ---------- */
.fx {
  position: fixed;
  inset: 0;
  z-index: 35;
  pointer-events: none;
  overflow: hidden;
}

.bit {
  position: absolute;
  width: 12px;
  height: 12px;
  border: 2.5px solid var(--ak-accent-2);
  opacity: 0;
}

.bit.tri { width: 0; height: 0; border: 0; border-left: 8px solid transparent; border-right: 8px solid transparent; border-bottom: 14px solid var(--ak-accent); }
.bit.dot { border-radius: 50%; border-color: var(--ak-ink); background: var(--ak-accent-2); }
.bit.bar { width: 6px; height: 16px; background: var(--ak-accent); border-color: var(--ak-accent); }

.gain {
  position: absolute;
  font-family: var(--ak-font-display);
  font-size: 22px;
  font-weight: 800;
  color: var(--ak-accent-2);
  background: var(--ak-bg);
  padding: 2px 8px;
  border: 1px solid var(--line);
  opacity: 0;
}

/* ---------- sideways: board on one side, controls and status on the other ---------- */
@media (orientation: landscape) {
  :root { --band: 40px; }

  .deck {
    width: min(100%, 1180px);
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "top    status"
      "board  status"
      "board  keys"
      "board  foot";
    column-gap: clamp(12px, 3vw, 40px);
    padding:
      max(8px, var(--safe-t))
      max(14px, var(--safe-r))
      max(8px, var(--safe-b))
      max(14px, var(--safe-l));
  }

  .top { padding-right: 0; }
  .status { align-self: start; padding-right: 60px; }
  .reason { right: 60px; }
  .clock { justify-content: flex-start; }
  .lamps { width: min(calc(100% - 76px), 360px, 19dvh * 384 / 118); }
  .keys { width: min(100%, 460px, 36dvh * 384 / 149); align-self: end; }
  .foot { align-self: end; }
  .logo { height: 40px; }
  .titleblock { width: min(46vw, 400px); }
}

@media (orientation: landscape) and (max-height: 500px) {
  .seg { padding: 2px 8px; }
  .seg b { font-size: 16px; }
  .secs { font-size: 22px; min-width: 56px; }
  .note, .msg { min-height: 34px; padding: 4px 10px; }
  .note span, .msg { font-size: 16px; }
  .skip { min-height: 48px; }
  .teach { padding: 8px; gap: 8px; }
  .teach-text { font-size: 18px; }
  .got-it { min-height: 50px; }
  .tb-says { font-size: 16px; padding: 8px 10px; padding-right: 80px; }
  .tb-grid dd { font-size: 20px; }
  .tb-actions { padding: 8px; }
  .tb-go, .tb-alt { min-height: 48px; }
}

@media (min-width: 900px) and (min-height: 640px) {
  :root { --pk: 0.85; --band: 52px; }
  .callout { --cw: 170px; }
  .callout-text { font-size: 15px; }
}

@media (orientation: portrait) and (max-height: 700px) {
  :root { --band: 38px; }
  .logo { height: 32px; }
  .dim { display: none; }
  .seg { padding: 2px 8px; }
  .seg b { font-size: 16px; }
  .note, .msg { min-height: 34px; padding: 4px 10px; }
  .note span, .msg { font-size: 16px; }
  .board { gap: 4px; }
  .skip { min-height: 48px; }
}

@media (min-width: 900px) and (min-height: 640px) {
  body { display: grid; place-items: center; }
  .deck { height: min(100dvh, 780px); }
  .logo { height: 56px; }
  .top { height: 60px; }
}

/* ---------- motion ---------- */
@media (prefers-reduced-motion: no-preference) {
  .backdrop { animation: drift 48s ease-in-out infinite alternate; }

  .callout { transition: transform 300ms var(--spring); }
  .drop { transition: transform 300ms var(--spring), height 300ms var(--ease-out); }

  .lamps .lamp.on { animation: hum 2.6s ease-in-out infinite; }
  .lamps.hurry .lamp.on { animation-duration: 0.5s; }
  .lamp.dying { animation: lamp-out 420ms ease-out; }

  .gap.is-active .hole { animation: ring 1.1s ease-in-out infinite; }
  .gap.is-active .caret { animation: blink 1s steps(2, start) infinite; }
  .gap.snap svg { animation: squash 340ms var(--spring); transform-origin: 50% 80%; }
  .gap.snap .pc { animation: flood 260ms ease-out; }
  .gap.bad svg { animation: shake 380ms ease-in-out; }
  .gap.drain svg { animation: drain 280ms ease-in forwards; }

  .plate.enter { animation: plate-in 420ms var(--spring); }
  .plate.printing .ch,
  .plate.printing .gap { animation: print 520ms var(--ease-out) both; animation-delay: calc(var(--i) * 45ms); }
  .plate.revealing .gap.shown svg { animation: pop-in 320ms var(--spring) both; animation-delay: calc(var(--i) * 45ms); }

  .callout.pop img { animation: tag-pop 360ms var(--spring); }

  .key:active .key-face { transform: translateY(2px) scale(0.92, 0.86); }
  .key-face { transition: transform 200ms var(--spring), filter 160ms ease; }
  .key.hit .key-face { animation: key-hit 260ms var(--spring); }
  .key.taught .key-face { animation: taught 1.3s ease-in-out infinite; }

  .skip:active, .got-it:active, .tb-go:active, .tb-alt:active, .mute:active { transform: scale(0.95); }
  .skip, .got-it, .tb-go, .tb-alt, .mute { transition: transform 180ms var(--spring), background-color 160ms ease; }

  .seg b.bump, #score.bump { animation: bump 380ms var(--spring); }
  .best.bump { display: inline-block; animation: bump 380ms var(--spring); }
  .frames .lit.new { animation: frame-on 560ms var(--spring); }
  .secs.low { animation: hum 0.5s ease-in-out infinite; }

  .msg.wrong.fresh { animation: nudge 320ms ease-in-out; }

  .reason:not([hidden]) { animation: stamp-in 420ms var(--spring); }
  .titleblock.slam { animation: slam 520ms cubic-bezier(0.2, 1.4, 0.4, 1) both; }
  .tb-stamp.thud { animation: thud 380ms cubic-bezier(0.3, 1.6, 0.5, 1) both; animation-delay: 380ms; }
  .titleblock.chase { animation: chase 1.6s ease-in-out 3; }
  .deck.shake { animation: deck-shake 260ms ease-in-out; animation-delay: 420ms; }

  .bit { animation: burst var(--t, 1100ms) var(--ease-out) forwards; }
  .gain { animation: rise 900ms var(--ease-out) forwards; }
}

@keyframes drift {
  from { transform: translate3d(-1%, 0, 0) scale(1); }
  to { transform: translate3d(1%, -1%, 0) scale(1.03); }
}

@keyframes hum {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.72; }
}

@keyframes lamp-out {
  0% { transform: translate(-50%, -50%) scale(1.25); background: var(--ak-ink); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

@keyframes ring {
  0%, 100% { stroke-opacity: 1; }
  50% { stroke-opacity: 0.45; }
}

@keyframes blink {
  to { visibility: hidden; }
}

@keyframes squash {
  0% { transform: scale(1.35, 0.7); }
  45% { transform: scale(0.88, 1.14); }
  75% { transform: scale(1.05, 0.96); }
  100% { transform: scale(1); }
}

@keyframes flood {
  from { fill-opacity: 0; }
  to { fill-opacity: 1; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px) rotate(-4deg); }
  45% { transform: translateX(5px) rotate(3deg); }
  70% { transform: translateX(-3px); }
}

@keyframes drain {
  to { transform: scale(0.4); opacity: 0; }
}

@keyframes pop-in {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes plate-in {
  from { transform: translateX(28px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes print {
  0% { transform: translateY(0); color: var(--ak-ink); }
  35% { transform: translateY(-6px); color: var(--ak-accent-2); }
  100% { transform: translateY(0); color: var(--ak-ink); }
}

@keyframes tag-pop {
  0% { transform: scale(0.7); }
  100% { transform: scale(1); }
}

@keyframes key-hit {
  0% { transform: translateY(3px) scale(0.9, 0.84); }
  100% { transform: none; }
}

@keyframes taught {
  0%, 100% { outline-color: var(--ak-accent-2); }
  50% { outline-color: transparent; }
}

@keyframes bump {
  0% { transform: scale(1.3); color: var(--ak-accent-2); }
  100% { transform: scale(1); }
}

@keyframes frame-on {
  0% { transform: scale(1.8); }
  100% { transform: scale(1); }
}

@keyframes nudge {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-5px); }
  65% { transform: translateX(4px); }
}

@keyframes stamp-in {
  0% { transform: scale(1.4); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes slam {
  0% { transform: translate(60%, 70%) scale(1.12); opacity: 0; }
  60% { transform: translate(-2%, -3%) scale(0.98); opacity: 1; }
  100% { transform: none; opacity: 1; }
}

@keyframes thud {
  0% { transform: rotate(-8deg) scale(2.4); opacity: 0; }
  100% { transform: rotate(-8deg) scale(1); opacity: 1; }
}

@keyframes chase {
  0%, 100% { outline-color: var(--line); outline-offset: 4px; }
  50% { outline-color: var(--ak-accent-2); outline-offset: 7px; }
}

@keyframes deck-shake {
  0%, 100% { transform: translate(0, 0); }
  30% { transform: translate(-3px, 2px); }
  60% { transform: translate(3px, -1px); }
}

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

@keyframes rise {
  0% { opacity: 0; transform: translateY(10px) scale(0.8); }
  25% { opacity: 1; transform: translateY(0) scale(1.08); }
  100% { opacity: 0; transform: translateY(-36px) scale(1); }
}

@media (orientation: portrait) {
  .deck.is-over .msg,
  .deck.is-over .note { visibility: hidden; }
}

@media (orientation: portrait) and (max-height: 760px) {
  .tb-head { padding: 4px 10px; }
  .tb-says { font-size: 16px; padding: 6px 10px; padding-right: 80px; }
  .tb-grid div { padding: 4px 8px; }
  .tb-grid dd { font-size: 19px; }
  .tb-run { font-size: 14px; padding: 5px 10px; }
  .tb-actions { padding: 8px; }
  .tb-go, .tb-alt { min-height: 48px; }
}
