/* Race Day Ladder: medal kit on a coarse pixel grid. Square edges, no blur, motion in whole steps. */

:root {
  --g: 32px;
  --line: 2px;
  --wash: color-mix(in srgb, var(--ak-bg) 90%, transparent);
  --step-ms: 160ms;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  background-color: var(--ak-bg);
  background-image: var(--ak-backdrop-layer, linear-gradient(var(--wash), var(--wash)), url("art/switchback-path.jpg"));
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  font-size: 16px;
  line-height: 1.3;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; border-radius: 0; }
:focus-visible { outline: 3px solid var(--ak-focus); outline-offset: 2px; }

.ico { width: 18px; height: 18px; fill: currentColor; flex: none; }

/* ---- Frame ---- */

.app {
  position: fixed;
  inset: 0;
  max-width: 1120px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "head" "stage" "tools";
  gap: 8px;
  padding:
    calc(var(--ac-status-h, 68px) + 8px)
    max(12px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
}

.head { grid-area: head; display: flex; align-items: center; gap: 8px; min-width: 0; }
.logo { display: block; height: 40px; width: auto; flex: none; image-rendering: auto; }

.tabs {
  display: flex;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  padding-bottom: 8px;
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
  min-height: 48px;
  max-width: 180px;
  padding: 0 12px;
  border: var(--line) solid var(--ak-ink);
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: 18px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.tab-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Race names keep the player's own capitals; the display face has capitals only. */
.tab-race .tab-name { font-family: var(--ak-font-body); font-weight: 600; font-size: 16px; letter-spacing: 0; text-transform: none; }
.tab-count { font-size: 14px; color: var(--ak-ink-muted); font-variant-numeric: tabular-nums; }
.tab[aria-selected="true"] { background: var(--ak-btn-fill); color: var(--ak-btn-ink); border-color: var(--ak-btn-fill); }
.tab[aria-selected="true"] .tab-count { color: var(--ak-btn-ink); }
/* The ribbon tail: one square block under the open tab, pointing at the board. */
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  width: 12px;
  height: 6px;
  margin-left: -6px;
  background: var(--ak-btn-fill);
}
.tab-new { border-style: dashed; }

/* ---- Stage ---- */

.stage { grid-area: stage; position: relative; min-height: 0; min-width: 0; touch-action: manipulation; }
.view { position: absolute; inset: 0; display: none; }
.app[data-view="ladder"] .view-ladder,
.app[data-view="home"] .view-home,
.app[data-view="new"] .view-new,
.app[data-view="summits"] .view-summits { display: flex; }

.view-ladder { align-items: stretch; justify-content: center; gap: 8px; }

/* The tall progress bar up the left edge, with 2/5 small beside it. */
.meter { flex: none; width: 32px; display: flex; flex-direction: column; align-items: center; gap: 4px; align-self: center; }
.meter-num { font-family: var(--ak-font-display); font-size: 18px; line-height: 1; font-variant-numeric: tabular-nums; color: var(--ak-ink-muted); }
.meter-bar { display: flex; flex-direction: column-reverse; gap: 2px; width: 16px; height: var(--meter-h, 300px); padding: 2px; border: var(--line) solid var(--ak-outline); background: var(--ak-bg); }
.meter-block { flex: 1 1 0; background: transparent; }
.meter-block.is-full { background: var(--ak-accent); }

.board-box { position: relative; flex: 1 1 auto; min-width: 0; display: flex; align-items: center; justify-content: center; }
/* Only when even the smallest cells overflow: the board scrolls from its summit down, never cut off. */
.board-box.is-tight { overflow: auto; align-items: flex-start; justify-content: flex-start; overscroll-behavior: contain; }
.board-box.is-tight .board { margin: 2px; }

.board {
  position: relative;
  flex: none;
  width: calc(var(--g) * var(--cols, 10));
  height: calc(var(--g) * var(--rows, 20));
  /* Solid, so the painted path behind the page never reads as part of the ladder. */
  background-color: var(--ak-bg);
  /* The coarse grid every piece snaps to: hard one-pixel lines, one per cell. */
  background-image:
    linear-gradient(to right, color-mix(in srgb, var(--ak-outline) 80%, transparent) 1px, transparent 1px),
    linear-gradient(to bottom, color-mix(in srgb, var(--ak-outline) 80%, transparent) 1px, transparent 1px);
  background-size: var(--g) var(--g);
  outline: var(--line) solid var(--ak-outline);
}

.cellbox {
  position: absolute;
  left: calc(var(--g) * var(--x));
  top: calc(var(--g) * var(--y));
  width: calc(var(--g) * var(--w));
  height: calc(var(--g) * var(--h));
}

/* Path segments: square cream-outlined cells, solid gold once climbed. */
.seg-cell {
  position: absolute;
  left: calc(var(--g) * var(--x));
  top: calc(var(--g) * var(--y));
  width: var(--g);
  height: var(--g);
  border: var(--line) solid var(--ak-ink);
  background: var(--ak-bg);
}
.seg.is-solid .seg-cell { background: var(--ak-accent); border-color: var(--ak-accent); box-shadow: inset 0 0 0 var(--line) var(--ak-btn-active); }

.turn.is-next { color: var(--ak-ink); outline: 1px solid var(--ak-ink); }
.turn {
  position: absolute;
  left: calc(var(--g) * var(--x) + 3px);
  top: calc(var(--g) * var(--y) + 3px);
  width: calc(var(--g) - 6px);
  height: calc(var(--g) - 6px);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ak-bg);
  color: var(--ak-ink-muted);
  font-size: max(11px, calc(var(--g) * 0.36));
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  z-index: 2;
}

/* Start strip at the foot of the path. */
.start {
  display: flex;
  align-items: center;
  padding: 0 8px;
  background: var(--ak-bg);
  border: var(--line) solid var(--ak-ink-muted);
  color: var(--ak-ink-muted);
  font-size: max(12px, calc(var(--g) * 0.42));
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
}

/* Summit plate: gold, square, the race name as the player typed it. */
.summit {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 0 0 10px;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  border: var(--line) solid var(--ak-ink);
  box-shadow: inset 0 0 0 var(--line) var(--ak-btn-active);
}
.summit-icon { flex: none; height: calc(100% - 10px); max-height: 56px; width: auto; image-rendering: pixelated; }
.summit-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.summit-name {
  font-weight: 600;
  font-size: max(16px, calc(var(--g) * 0.6));
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.summit-date { font-size: max(12px, calc(var(--g) * 0.4)); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- Rungs ---- */

.rung { z-index: 1; }
.rung-hit {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  /* Clear of the pencil: its width, its inset from the tile's edge, and a gap. */
  padding: 0 calc(max(44px, var(--g) * 1.5) + var(--g) * var(--h) * 0.1 + 6px) 0 calc(var(--tile-edge) + 6px);
  border: 0;
  background: transparent;
  color: var(--ak-ink);
  text-align: left;
  --tile-edge: calc(var(--g) * var(--h) * 0.145);
}
.rung-hit:focus-visible { outline-offset: -2px; }

/* The painted tile: its two ends at true scale (so the notch and the side outlines keep one
   thickness) over a middle stretched only sideways (so the top and bottom outlines match). */
.skin {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: url("art/rung-tile.png") 0 0 / 100% 230.5% no-repeat;
}
.skin::before, .skin::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  /* Narrower than the tile at true scale, so an end never shows the far edge's outline. */
  width: min(50%, calc(var(--g) * var(--h) * 1.9));
  background-image: url("art/rung-tile.png");
  background-repeat: no-repeat;
  background-size: auto 230.5%;
}
.skin::before { left: 0; background-position: 0 0; }
.skin::after { right: 0; background-position: 100% 0; }
.skin-gold { visibility: hidden; background-position: 0 99%; }
.skin-gold::before { background-position: 0 99%; }
.skin-gold::after { background-position: 100% 99%; }
.rung.is-climbed .skin-gold { visibility: visible; }
.rung.is-climbed .rung-hit { color: var(--ak-btn-ink); }

/* A locked step: a small padlock before its words; the open step and climbed steps have none. */
.rung-lock { display: none; position: relative; flex: none; color: var(--ak-ink-muted); }
.rung-lock .ico { width: max(14px, calc(var(--g) * 0.5)); height: max(14px, calc(var(--g) * 0.5)); }
.rung.is-locked .rung-lock { display: flex; }
.rung-text { position: relative; flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.rung-words {
  font-weight: 600;
  font-size: max(13px, calc(var(--g) * 0.42));
  line-height: 1.05;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow-wrap: anywhere;
}
.rung:not(.is-next):not(.is-climbed) .rung-hit { color: var(--ak-ink-muted); }
.rung-meta {
  font-size: max(12px, calc(var(--g) * 0.4));
  font-weight: 500;
  color: var(--ak-ink-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rung.is-climbed .rung-meta { color: var(--ak-btn-ink); }
.rung-cue {
  font-size: max(12px, calc(var(--g) * 0.38));
  font-weight: 600;
  color: var(--ak-ink);
  white-space: nowrap;
}
.rung.is-blank .rung-words { color: var(--ak-ink-muted); font-style: italic; }

.rung.is-next .rung-words {
  font-weight: 600;
  font-size: max(18px, calc(var(--g) * 0.62));
  line-height: 1.05;
  color: var(--ak-ink);
  white-space: normal;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.rung.is-next .rung-meta { color: var(--ak-ink); white-space: normal; line-height: 1.15; }
.rung.is-next .rung-text { gap: 1px; }
/* The note under the board already says to tap it; the rung keeps its words and date. */
.board.is-compact .rung-cue { display: none; }
/* Sideways the rung words and dates get floors of their own, larger than the cell math gives a
   short screen; app.js shortens the dates to match (drawLadder). */
.board.is-wide .rung-words { font-size: clamp(15px, calc(var(--g) * 0.7), 22px); line-height: 1.1; }
.board.is-wide .rung-meta { font-size: clamp(13px, calc(var(--g) * 0.6), 17px); }
.board.is-wide .rung.is-next .rung-words { font-size: clamp(18px, calc(var(--g) * 0.88), 28px); }
.board.is-wide .rung-cue { font-size: clamp(13px, calc(var(--g) * 0.56), 17px); }
.board.is-compact .rung:not(.is-next) .rung-words { -webkit-line-clamp: 1; }


.done-mark { position: relative; flex: none; width: max(18px, calc(var(--g) * 0.6)); height: max(18px, calc(var(--g) * 0.6)); fill: var(--ak-btn-ink); }

.pencil {
  position: absolute;
  top: 50%;
  right: calc(var(--g) * var(--h) * 0.1);
  width: max(44px, calc(var(--g) * 1.5));
  height: max(44px, min(calc(var(--g) * 1.5), calc(var(--g) * var(--h) - 4px)));
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: var(--line) solid currentColor;
  background: var(--ak-bg);
  color: var(--ak-ink);
  z-index: 2;
}
.pencil .ico { width: 20px; height: 20px; }
.summit .pencil { position: relative; top: auto; right: auto; transform: none; flex: none; margin-right: 4px; height: max(44px, calc(var(--g) * 1.5)); }

/* After a tap on the wrong step, the open one is outlined until the next move. */
.rung.is-pointed::after {
  content: "";
  position: absolute;
  inset: -5px;
  border: 3px solid var(--ak-ink);
  pointer-events: none;
}

.board.is-loading > * { visibility: hidden; }

/* ---- Home ---- */

.view-home { align-items: center; justify-content: center; padding: 8px 0; overflow-y: auto; }
.home-wrap { width: min(100%, 460px); display: flex; flex-direction: column; gap: 12px; }
/* The empty ladder: the painted rungs, blank, with what will go on each. */
.ghost-ladder { list-style: none; margin: 0; padding: 12px; display: flex; flex-direction: column; gap: 6px; background: var(--ak-bg); border: var(--line) solid var(--ak-outline); --g: 18px; }
.ghost-summit { min-height: 40px; display: flex; align-items: center; padding: 0 12px; border: var(--line) dashed var(--ak-accent); color: var(--ak-ink); font-weight: 600; font-size: 15px; }
.ghost-rung { position: relative; height: 36px; display: flex; align-items: center; padding: 0 16px 0 22px; color: var(--ak-ink-muted); font-size: 14px; font-weight: 500; }
.ghost-rung:nth-child(n + 3) { margin-left: 0; }
.ghost-rung:nth-child(odd) { margin-right: 28px; }
.ghost-rung:nth-child(even) { margin-left: 28px; }
.ghost-text { position: relative; }
.home-card { display: flex; flex-direction: column; align-items: stretch; gap: 10px; padding: 16px; background: var(--ak-bg); border: var(--line) solid var(--ak-ink); }
.home-kicker { margin: 0; font-family: var(--ak-font-display); font-size: 18px; letter-spacing: 0.08em; color: var(--ak-ink-muted); text-transform: uppercase; }
.home-title { margin: 0; font-family: var(--ak-font-display); font-weight: 400; font-size: clamp(30px, 8vw, 44px); line-height: 0.95; letter-spacing: 0.02em; text-transform: uppercase; }
.home-text { margin: 0; font-size: 16px; color: var(--ak-ink); }

.big-go {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 64px;
  padding: 0 24px;
  border: var(--line) solid var(--ak-ink);
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font-family: var(--ak-font-display);
  font-size: 28px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.big-go .ico { width: 22px; height: 22px; }
.big-go:active { background: var(--ak-btn-active); }

.link-btn, .small-btn {
  min-height: 48px;
  padding: 0 16px;
  border: var(--line) solid var(--ak-ink);
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: 18px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ---- New ladder form ---- */

.view-new {
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--ak-bg);
  border: var(--line) solid var(--ak-ink);
}
.form-title { margin: 0; font-family: var(--ak-font-display); font-weight: 400; font-size: 32px; letter-spacing: 0.04em; text-transform: uppercase; line-height: 1; }
.race-fields { display: grid; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-family: var(--ak-font-display); font-size: 18px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ak-ink-muted); }
.input {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  border: var(--line) solid var(--ak-ink);
  border-radius: 0;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 17px;
}
.input[aria-invalid="true"] { border-color: var(--ak-accent-2); box-shadow: inset 0 0 0 var(--line) var(--ak-accent-2); }
.input::placeholder { color: var(--ak-ink-muted); opacity: 1; }
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); opacity: 0.9; cursor: pointer; }

.date-row { display: flex; align-items: center; gap: 12px; }
.date-row .input { flex: 0 1 200px; }
.date-away { font-family: var(--ak-font-display); font-size: 20px; letter-spacing: 0.04em; color: var(--ak-ink-muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 48px;
  padding: 4px 12px;
  border: var(--line) solid var(--ak-choice-border);
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
  font-size: 15px;
  font-weight: 600;
  text-align: left;
}
.chip-clue { display: block; font-size: 12px; font-weight: 500; color: var(--ak-ink-muted); }
.chip[aria-pressed="true"] { background: var(--ak-choice-selected-bg); color: var(--ak-choice-selected-ink); border-color: var(--ak-choice-selected-border); }
.chip[aria-pressed="true"] .chip-clue { color: var(--ak-choice-selected-ink); }
.chip-more { border-style: dashed; font-family: var(--ak-font-display); font-weight: 400; font-size: 16px; letter-spacing: 0.06em; text-transform: uppercase; }

.field-help { margin: 0; font-size: 14px; color: var(--ak-ink-muted); }
.plans { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.plan-btn {
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  padding: 6px 10px;
  border: var(--line) solid var(--ak-choice-border);
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
  text-align: left;
}
.plan-name { font-family: var(--ak-font-display); font-size: 22px; line-height: 1; letter-spacing: 0.04em; text-transform: uppercase; }
.plan-about { font-size: 13px; font-weight: 500; line-height: 1.2; }
.plan-tag { margin-top: 2px; padding: 1px 6px; background: var(--ak-accent); color: var(--ak-btn-ink); font-family: var(--ak-font-display); font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; }
.plan-btn[aria-pressed="true"] { background: var(--ak-choice-selected-bg); color: var(--ak-choice-selected-ink); border-color: var(--ak-choice-selected-border); }

.steps-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.draft-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column-reverse; gap: 8px; }
.draft-step { display: grid; grid-template-columns: 36px minmax(0, 1fr); grid-template-areas: "num words" ". meta"; gap: 4px 6px; align-items: center; }
.draft-meta { grid-area: meta; display: flex; align-items: center; gap: 8px; min-width: 0; }
.draft-num { grid-area: num; height: 48px; display: flex; align-items: center; justify-content: center; border: var(--line) solid var(--ak-ink); font-family: var(--ak-font-display); font-size: 20px; }
.draft-step.is-race .draft-num { background: var(--ak-btn-fill); color: var(--ak-btn-ink); border-color: var(--ak-btn-fill); }
.draft-words { grid-area: words; }
.draft-date { flex: 0 0 150px; width: 150px; padding: 0 6px; font-size: 15px; }
.draft-race-date { flex: none; min-height: 48px; display: flex; align-items: center; font-family: var(--ak-font-display); font-size: 18px; letter-spacing: 0.04em; }
.draft-clue { flex: 1 1 auto; min-width: 0; margin: 0; font-size: 13px; color: var(--ak-ink-muted); }
.draft-empty { padding: 16px; border: var(--line) dashed var(--ak-ink-muted); color: var(--ak-ink-muted); font-size: 16px; margin: 0; }

/* The ladder in miniature: the race on top (gold once named), the plan's five steps under it. */
.form-map { margin: -6px 0 0; display: flex; flex-direction: column; gap: 6px; padding: 10px; border: var(--line) solid var(--ak-outline); }
.map-row { display: grid; grid-template-columns: 132px minmax(0, 1fr); align-items: center; gap: 10px; }
.map-top { display: flex; flex-direction: column; min-width: 0; padding: 5px 8px; border: var(--line) solid var(--ak-accent); color: var(--ak-ink); line-height: 1.15; }
.map-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-date { font-size: 12px; font-weight: 500; white-space: nowrap; }
.map-top.is-set { background: var(--ak-accent); color: var(--ak-btn-ink); }
.map-steps { display: flex; flex-direction: column-reverse; gap: 3px; padding: 0 0 0 12px; }
.map-steps i { display: block; height: 7px; border: var(--line) solid var(--ak-ink-muted); }
.map-steps.is-set i { border-color: var(--ak-ink); background: var(--ak-ink); }
.map-steps i:first-child { margin-right: 24px; }
.map-steps i:nth-child(2) { margin-right: 18px; }
.map-steps i:nth-child(3) { margin-right: 12px; }
.map-steps i:nth-child(4) { margin-right: 6px; }
.map-says { margin: 0; font-size: 15px; line-height: 1.3; color: var(--ak-ink); }
.map-says b { font-weight: 700; }
/* The step chips stay at the top of the form as it scrolls; the parts scroll in below them. */
.form-steps {
  position: sticky;
  top: -16px;
  z-index: 3;
  margin: 0 -16px;
  padding: 12px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--ak-bg);
  border-bottom: var(--line) solid var(--ak-outline);
}
.form-how { margin: 0; font-size: 16px; font-weight: 600; line-height: 1.25; }
.step-chips { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 1.6fr); gap: 4px; }
.step-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 44px;
  padding: 0 6px;
  border: var(--line) dashed var(--ak-ink-muted);
  background: var(--ak-bg);
  color: var(--ak-ink-muted);
  font-family: var(--ak-font-display);
  font-size: 16px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
}
.step-mark { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; background: var(--ak-ink-muted); color: var(--ak-bg); font-size: 14px; letter-spacing: 0; }
.step-chip.is-done { border-style: solid; border-color: var(--ak-accent); color: var(--ak-ink); }
.step-chip.is-done .step-mark { background: var(--ak-accent); color: var(--ak-btn-ink); }
.step-chip.is-now { border: 3px solid var(--ak-ink); color: var(--ak-ink); }
.step-chip.is-now .step-mark { background: var(--ak-ink); }
.step-go.is-now { border-color: var(--ak-accent); background: var(--ak-accent); color: var(--ak-btn-ink); }
.step-go.is-now .step-mark { background: var(--ak-btn-ink); color: var(--ak-accent); }
/* Every part lands just under the chips when one is tapped or comes next. */
.view-new .field { scroll-margin-top: 112px; }
/* Ready: the one button left is outlined in the accent. */
#set-race.is-ready { outline: 3px solid var(--ak-accent); outline-offset: 3px; }

.part-num { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; margin-right: 8px; background: var(--ak-ink); color: var(--ak-bg); font-size: 16px; letter-spacing: 0; }
.cal-btn { flex: none; width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; padding: 0; border: var(--line) solid var(--ak-ink); background: var(--ak-surface); color: var(--ak-ink); }
.cal-btn .ico { width: 22px; height: 22px; }
p.date-away { margin: 0; }
.name-ok { margin: 0; font-size: 16px; font-weight: 600; color: var(--ak-ink); }
.name-ok::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 8px; background: var(--ak-accent); }
.date-help { margin: 0; font-size: 14px; color: var(--ak-ink-muted); }
/* Set the race sits with the controls, always in view and never over the form, with the next
   thing to do written beside it. Only the new-ladder screen shows it. */
.form-actions {
  display: none;
  gap: 8px 12px;
  align-items: center;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--ak-bg);
  border: var(--line) solid var(--ak-ink);
}
.app[data-view="new"] .form-actions { display: flex; }
.form-actions .big-go { flex: 1 1 200px; min-height: 56px; font-size: 26px; }
.form-next { flex: 1 1 100%; margin: 0; font-size: 16px; font-weight: 600; }
.form-next.is-ready { color: var(--ak-accent); }
.form-next.is-blocked::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 8px; background: var(--ak-accent-2); }

.err {
  margin: 0;
  padding: 6px 10px;
  border-left: 6px solid var(--ak-accent-2);
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 15px;
  font-weight: 600;
}

/* ---- Summits shelf ---- */

.view-summits { flex-direction: column; gap: 12px; padding: 16px; overflow-y: auto; overscroll-behavior: contain; background: var(--ak-bg); border: var(--line) solid var(--ak-ink); }
.shelf-title { margin: 0; font-family: var(--ak-font-display); font-weight: 400; font-size: 32px; letter-spacing: 0.04em; text-transform: uppercase; line-height: 1; }
.shelf-count { color: var(--ak-ink-muted); font-variant-numeric: tabular-nums; }
.shelf-empty { margin: 0; font-size: 17px; }
.shelf-best { margin: 0; font-size: 17px; font-weight: 600; }
/* The medal set: one slot a plan; a slot not won yet is the same medal, dimmed. */
.medals { display: flex; flex-direction: column; gap: 8px; }
.medals-title { margin: 0; font-family: var(--ak-font-display); font-weight: 400; font-size: 22px; letter-spacing: 0.04em; text-transform: uppercase; line-height: 1; }
#medals-count { color: var(--ak-ink-muted); }
.medal-slots { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.medal { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; border: var(--line) dashed var(--ak-ink-muted); text-align: center; }
.medal.is-won { border-style: solid; border-color: var(--ak-accent); }
.medal-art { height: 48px; width: auto; image-rendering: pixelated; opacity: 0.3; filter: grayscale(1); }
.medal.is-won .medal-art { opacity: 1; filter: none; }
.medal-name { font-size: 14px; font-weight: 600; line-height: 1.1; }
.medal-count { font-size: 12px; color: var(--ak-ink-muted); }
.medal.is-won .medal-count { color: var(--ak-ink); font-weight: 600; }
/* The next race, one plan harder: the shelf's way back up. */
.step-up { flex: none; align-self: flex-start; max-width: 100%; min-height: 56px; padding: 0 18px; font-size: 22px; text-align: left; }
.shelf { list-style: none; margin: 0; padding: 0 0 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px 12px; border-bottom: 6px solid var(--ak-ink); }
.card { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.card-art {
  position: relative;
  margin: 0;
  width: 100%;
  max-width: 220px;
  aspect-ratio: 225 / 384;
  background: url("art/summit-card.png") center / 100% 100% no-repeat;
  container-type: inline-size;
}
.card-name {
  position: absolute;
  left: 15%;
  right: 15%;
  top: 5.6%;
  height: 7.4%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ak-choice-selected-ink);
  font-weight: 600;
  font-size: 8.4cqw;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-row {
  position: absolute;
  left: 25.5%;
  width: 48.5%;
  top: calc(21.6% + 9.34% * var(--i));
  height: 5.3%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2px;
  padding: 0 3cqw;
  color: var(--ak-choice-selected-ink);
  font-family: var(--ak-font-display);
  font-size: 8.4cqw;
  line-height: 1;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}
.card-row b { font-weight: 400; opacity: 0.75; }
.card-remove { align-self: flex-start; display: inline-flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 12px; border: var(--line) solid var(--ak-ink-muted); background: var(--ak-bg); color: var(--ak-ink); font-family: var(--ak-font-display); font-size: 16px; letter-spacing: 0.06em; text-transform: uppercase; }

/* ---- The reason beat: shown on the play screen while the ending card waits a second ---- */

.beat {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 20px;
  padding: 24px;
  background: var(--ak-bg);
  border: var(--line) solid var(--ak-ink);
}
.beat-plate {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  border: var(--line) solid var(--ak-ink);
  font-weight: 600;
  font-size: clamp(28px, 9vw, 64px);
  line-height: 1;
  overflow-wrap: anywhere;
}
.beat-medal { flex: none; height: clamp(64px, 18vw, 120px); width: auto; }
.beat-day { display: flex; align-items: center; gap: 12px; }
.beat-stamp { flex: none; height: 56px; width: auto; }
.beat-big { margin: 0; font-family: var(--ak-font-display); font-size: clamp(56px, 18vw, 128px); line-height: 0.85; letter-spacing: 0.04em; }
.beat-bar { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; height: 28px; padding: 3px; border: var(--line) solid var(--ak-ink); }
.beat-bar span { background: transparent; }
.beat-bar span.is-full { background: var(--ak-accent); }
.beat-prompt { margin: 0; font-family: var(--ak-font-display); font-size: clamp(28px, 8vw, 48px); letter-spacing: 0.08em; line-height: 1; }
.beat-line { margin: 0; font-size: 18px; }

/* ---- Tools ---- */

.tools { grid-area: tools; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tool-row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.tool {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  min-width: 48px;
  padding: 0 16px;
  border: var(--line) solid var(--ak-ink);
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: 20px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.tool-done { background: var(--ak-ink); color: var(--ak-bg); }
.tool-undo { margin-right: auto; }
.undo-blocks { display: inline-flex; gap: 2px; }
.undo-blocks i { display: block; width: 4px; height: 14px; background: var(--ak-accent); }
.undo-blocks i.is-gone { background: var(--ak-outline); }
#hint { margin-right: auto; }
#undo:not([hidden]) ~ #done { margin-left: 0; }

.note {
  margin: 0;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px;
  background: var(--ak-bg);
  border-left: 6px solid var(--ak-ink-muted);
  color: var(--ak-ink);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.25;
}
.note.is-said { border-left-color: var(--ak-accent); font-weight: 600; }
/* The streak to keep, always beside the note on a ladder; solid gold while it is the best yet. */
/* The scores sit on their own row above the note's words. */
.note { flex-wrap: wrap; row-gap: 6px; }
.score-strip { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 6px; }
.note-text { flex: 1 1 0; min-width: 0; }
.coach-tip { flex: 1 1 100%; display: flex; gap: 8px; align-items: baseline; padding-top: 6px; border-top: 1px solid var(--ak-outline); font-weight: 500; }
.coach-tip b { flex: none; padding: 1px 6px; background: var(--ak-ink); color: var(--ak-bg); font-family: var(--ak-font-display); font-weight: 400; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; }
.streak-chip {
  flex: none;
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 8px;
  padding: 3px 8px;
  border: var(--line) solid var(--ak-accent);
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  line-height: 1.05;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}
.streak-chip b { font-weight: 400; font-size: 16px; font-variant-numeric: tabular-nums; }
.streak-chip small { font-size: 11px; color: var(--ak-ink-muted); }
.streak-chip.is-best { background: var(--ak-accent); color: var(--ak-btn-ink); }
.streak-chip.is-best small { color: var(--ak-btn-ink); }
.app[data-view="new"] .note,
.app[data-view="new"] #hint,
.app[data-view="new"] .kept { display: none; }
.is-guided { outline: 3px solid var(--ak-accent); outline-offset: 4px; }
.big-go.is-guided { outline-offset: 6px; }
.guide-inline { margin: 0 0 4px; padding: 8px 12px; background: var(--ak-surface); border-left: 6px solid var(--ak-accent); color: var(--ak-ink); font-size: 18px; font-weight: 600; line-height: 1.3; }
/* One line on the opening saying what New ladder asks for (start.js draws the buttons). */
.opening-help { margin: 4px 0 16px; max-width: 520px; padding: 12px; border: var(--line) solid var(--ak-accent); background: var(--ak-bg); color: var(--ak-ink); text-align: left; }
.opening-help-head { margin: 0 0 8px; font-size: 16px; font-weight: 700; line-height: 1.3; }
.opening-parts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 15px; line-height: 1.3; }
.opening-parts li { display: grid; grid-template-columns: 28px minmax(0, 1fr); align-items: start; }
.opening-parts .part-num { width: 20px; height: 20px; margin: 0; font-size: 14px; font-family: var(--ak-font-display); }
.opening-parts b { font-weight: 700; }
/* On a phone on its side the button comes first, the three parts under it. */
@media (orientation: landscape) and (max-height: 520px) {
  #activity-start .opening-help { order: 1; }
}
.kept { margin: 0; min-height: 18px; font-size: 13px; color: var(--ak-ink-muted); text-align: right; letter-spacing: 0.02em; }
.kept.is-trouble { color: var(--ak-ink); }
.kept.is-trouble::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 6px; background: var(--ak-accent-2); vertical-align: -1px; }

/* ---- Sheet ---- */

.sheet-layer {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--ak-bg) 82%, transparent);
}
.sheet {
  width: min(100%, 520px);
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  border: var(--line) solid var(--ak-ink);
  border-top-width: 6px;
}
.sheet-title { margin: 0; font-family: var(--ak-font-display); font-weight: 400; font-size: 28px; letter-spacing: 0.04em; text-transform: uppercase; line-height: 1; }
.sheet-body { display: flex; flex-direction: column; gap: 12px; }
.sheet-body .input { background: var(--ak-bg); }
.sheet-note { margin: 0; font-size: 16px; }
.count { font-size: 13px; color: var(--ak-ink-muted); text-align: right; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.sheet-actions .big-go { flex: 1 1 160px; min-height: 56px; font-size: 24px; }
.danger { display: inline-flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 14px; border: var(--line) solid var(--ak-accent-2); background: var(--ak-bg); color: var(--ak-ink); font-family: var(--ak-font-display); font-size: 18px; letter-spacing: 0.06em; text-transform: uppercase; }
.danger .ico { color: var(--ak-accent-2); }

/* ---- Guide: ring, arrow, caption. Never covers what it points at. ---- */

.guide { position: fixed; inset: 0; z-index: 28; pointer-events: none; }
.guide-ring { position: fixed; border: 4px solid var(--ak-accent); outline: var(--line) solid var(--ak-bg); }
.guide-arrow { position: fixed; width: 28px; height: 28px; fill: var(--ak-accent); }
.guide-arrow.is-up { transform: rotate(180deg); }
.guide-caption {
  position: fixed;
  margin: 0;
  padding: 12px 14px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  border: var(--line) solid var(--ak-accent);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
}

.caret { display: inline-block; }

/* ---- Landscape: the board on one side, tabs, tools and status on the other ---- */

@media (orientation: landscape) {
  .app {
    /* app.js sets --side-w to what the board cannot use at full height (sizeSide). */
    grid-template-columns: minmax(0, 1fr) var(--side-w, clamp(190px, 30vw, 300px));
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "stage head" "stage tools";
    column-gap: 16px;
  }
  .head { flex-direction: column; align-items: stretch; gap: 8px; min-height: 0; }
  .logo { height: 36px; align-self: flex-start; }
  .tabs { flex: 1 1 auto; min-height: 0; flex-direction: column; overflow-x: hidden; overflow-y: auto; padding: 0 8px 0 0; }
  .tab { max-width: none; width: 100%; justify-content: space-between; }
  .tab[aria-selected="true"]::after { left: auto; right: -8px; top: 50%; bottom: auto; width: 6px; height: 12px; margin: -6px 0 0; }
  .tool-row { justify-content: stretch; }
  .tool { flex: 1 1 auto; justify-content: center; }
  .tool-undo, #hint { margin-right: 0; }
  .kept { text-align: left; }
  .view-new { padding: 12px; gap: 12px; }
  .form-steps { top: -12px; margin: 0 -12px; padding: 8px 12px; gap: 6px; }
  .form-how { font-size: 15px; }
  .form-actions { padding: 8px; gap: 6px 8px; }
  .form-next { font-size: 15px; }
  .form-actions .big-go { flex: 1 1 auto; min-height: 52px; font-size: 22px; padding: 0 12px; }
  .form-actions .small-btn { flex: none; min-height: 52px; }
  .app[data-view="new"] #hint { display: none; }
  .home-wrap { width: min(100%, 760px); flex-direction: row; align-items: center; }
  .ghost-ladder { flex: 1 1 0; padding: 8px; gap: 4px; }
  .ghost-summit { min-height: 32px; }
  .ghost-rung { height: 30px; --g: 15px; }
  .home-card { flex: 1 1 0; padding: 12px; gap: 8px; }
  .home-title { font-size: clamp(26px, 5vw, 38px); }
  .home-text { font-size: 15px; }
  .home-card .big-go { min-height: 56px; font-size: 24px; }
  .beat { gap: 12px; padding: 16px; }
  .beat-plate { font-size: clamp(24px, 8vh, 56px); }
  .beat-medal { height: clamp(56px, 22vh, 96px); }
  .beat-big { font-size: clamp(48px, 16vh, 112px); }
}

/*
 * A phone on its side: too short for a column of tabs. The tabs run in one row at the top of the
 * side column, the logo steps aside (the opening and the tabs name the race), the note takes the
 * room left and scrolls if a line runs long, and Undo and Done share one row of big buttons.
 */
@media (orientation: landscape) and (max-height: 520px) {
  .app { grid-template-rows: auto minmax(0, 1fr); }
  .logo { display: none; }
  .head { min-height: auto; }
  .tabs { flex: none; flex-direction: row; overflow-x: auto; overflow-y: hidden; padding: 0 0 8px; }
  .tab { width: auto; max-width: 180px; min-height: 44px; padding: 0 8px; gap: 6px; font-size: 15px; }
  .tab-race .tab-name { max-width: 120px; font-size: 15px; }
  .tab[aria-selected="true"]::after { left: 50%; right: auto; top: auto; bottom: -8px; width: 12px; height: 6px; margin: 0 0 0 -6px; }
  .tools { min-height: 0; }
  .note { flex: 0 1 auto; min-height: 0; overflow-y: auto; align-items: flex-start; flex-wrap: wrap; row-gap: 4px; padding: 6px 10px; font-size: 15px; }
  .tool-row { margin-top: auto; flex-wrap: nowrap; }
  .tool { flex: 1 1 0; min-height: 56px; padding: 0 10px; font-size: 22px; }
  /* The ten seconds left run as a bar along the foot of Undo, so the button fits half the row. */
  .tool-undo { position: relative; }
  .tool-undo .undo-blocks { position: absolute; left: 8px; right: 8px; bottom: 5px; }
  .tool-undo .undo-blocks i { flex: 1 1 0; width: auto; height: 5px; }
  .kept { min-height: 16px; font-size: 12px; }
  .score-strip { gap: 4px; }
  .streak-chip { gap: 5px; padding: 2px 6px; letter-spacing: 0.03em; }
  .streak-chip b { font-size: 14px; }
  .streak-chip small { font-size: 10px; }
  .note-text { flex-basis: 100%; }
  /* The summit plate is half width here: the race name keeps the room, the note names the medal. */
  .summit-icon { display: none; }
}

@media (max-width: 380px) {
  .plan-name { font-size: 20px; }
  .draft-step { grid-template-columns: 32px minmax(0, 1fr); }
  .draft-date { flex-basis: 136px; width: 136px; }
}

/* ---- Motion: slow, quiet, in whole steps. Off for reduced motion and for Less motion. ---- */

@media (prefers-reduced-motion: no-preference) {
  :root:not(.ac-still) .rung {
    transition:
      top calc(var(--step-ms) * 2) steps(1, end) 520ms,
      height calc(var(--step-ms) * 2) steps(1, end) 520ms;
  }
  :root:not(.ac-still) .board.no-anim .rung { transition: none; }

  :root:not(.ac-still) .rung.just-climbed .skin-gold { animation: fill-steps calc(var(--step-ms) * 3) steps(3, end) both; }
  :root:not(.ac-still) .rung.just-climbed .rung-hit { animation: ink-late calc(var(--step-ms) * 3) steps(1, end) both; }
  /* The done date drops on after the fill, in two whole steps. */
  :root:not(.ac-still) .rung.just-climbed .rung-meta {
    animation:
      ink-late calc(var(--step-ms) * 3) steps(1, end) both,
      mark-drop calc(var(--step-ms) * 2) steps(2, end) calc(var(--step-ms) * 3) both;
  }


  :root:not(.ac-still) .guide-ring { animation: ring-step 1200ms steps(2, jump-none) infinite alternate; }
  :root:not(.ac-still) .guide-arrow { animation: arrow-step 1200ms steps(2, jump-none) infinite alternate; }
  :root:not(.ac-still) .guide-arrow.is-up { animation-name: arrow-step-up; }

  :root:not(.ac-still) .caret { animation: blink 1000ms steps(1, end) infinite; }
  :root:not(.ac-still) .card.is-new { animation: shelf-in calc(var(--step-ms) * 4) steps(4, end) both; }
  :root:not(.ac-still) .beat.is-summit .beat-bar span { animation: bar-step var(--step-ms) steps(1, end) both; animation-delay: calc(var(--i) * var(--step-ms)); }
}

@keyframes fill-steps { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes mark-drop { from { transform: translateY(calc(var(--g) * -1)); opacity: 0; } 50% { opacity: 1; } to { transform: none; opacity: 1; } }
@keyframes ink-late { from { color: var(--ak-ink); } to { color: var(--ak-btn-ink); } }
@keyframes ring-step { from { transform: scale(1); } to { transform: scale(1.04); } }
@keyframes arrow-step { from { translate: 0 0; } to { translate: 0 6px; } }
@keyframes arrow-step-up { from { translate: 0 0; } to { translate: 0 -6px; } }
@keyframes blink { 0% { opacity: 1; } 50% { opacity: 0; } }
@keyframes shelf-in { from { transform: translateX(-100%); } to { transform: none; } }
@keyframes bar-step { from { background: transparent; } to { background: var(--ak-accent); } }
