/* First Client Ladder: a machine console. Square keys with a pressed state, small lit lamps,
   engraved small-caps labels, readouts in boxes. Hard edges, no gradients, no blur. */

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

:root {
  --edge: 2px;
  --gap: 8px;
  --tap: 48px;
  --rail: var(--ak-accent);
  --shade: color-mix(in srgb, var(--ak-bg) 70%, transparent);
  color-scheme: dark;
}

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

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

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible,
input:focus-visible { outline: 3px solid var(--ak-focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.ico {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.25;
  stroke-linecap: square;
  stroke-linejoin: miter;
}

/* ---------- engraved labels and boxed readouts ---------- */

.engrave {
  margin: 0;
  font: 600 12px/1.25 var(--ak-font-display);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
  text-shadow: 0 1px 0 var(--ak-bg);
}

.readout {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 7px;
  border: 1px solid var(--ak-outline);
  border-radius: 0;
  background: var(--ak-bg);
  color: var(--ak-ink);
  font: 700 14px/1 var(--ak-font-display);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}

.readout-key { color: var(--ak-ink-muted); font-weight: 600; }

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

.app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "deck" "bay" "dock";
  gap: var(--gap);
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding:
    calc(var(--ac-status-h, 72px) + 8px)
    max(12px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  touch-action: manipulation;
}

.deck {
  grid-area: deck;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.logo { flex: none; width: auto; height: 46px; }
/* With no goal open there are no tabs, so the nameplate takes the header. */
.app[data-view="home"] .logo { height: 54px; }

/* The room the chrome's message takes while it shows, so it never covers a rung (see app.js). */
.toast-slot { grid-area: slot; display: none; height: var(--toast-h, 0px); }
.app.has-toast .toast-slot { display: block; }

@media (orientation: portrait) {
  .app.has-toast {
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas: "deck" "slot" "bay" "dock";
  }
  .app.has-toast .sheetview { grid-row: 3 / -1; }
}

/* ---------- goal tabs: square switches ---------- */

.tabs {
  display: flex;
  gap: 6px;
  min-width: 0;
  padding: 2px 2px 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  position: relative;
  flex: none;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 5px;
  width: 58px;
  height: 58px;
  padding: 10px 4px 4px;
  border: var(--edge) solid var(--ak-bg);
  border-radius: 6px;
  background: var(--ak-surface);
  box-shadow: inset 0 -5px 0 var(--shade), 0 0 0 1px var(--ak-outline);
  color: var(--ak-ink-muted);
  font-family: var(--ak-font-display);
}
.tab::before {
  content: "";
  position: absolute;
  top: 6px;
  left: 8px;
  right: 8px;
  height: 4px;
  background: var(--ak-outline);
}
.tab[aria-selected="true"] {
  border-color: transparent;
  background: url("art/goal-tab.png") center / 100% 100% no-repeat;
  box-shadow: none;
  color: var(--ak-ink);
  transform: translateY(2px);
}
.tab[aria-selected="true"]::before { display: none; }
.tab:active { transform: translateY(2px); }
.tab-num { font-size: 21px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.tab-lamps { display: flex; gap: 3px; }
.tab-lamps i { width: 7px; height: 7px; background: var(--ak-bg); border: 1px solid var(--ak-outline); }
.tab-lamps i.is-on { background: var(--ak-accent); border-color: var(--ak-accent); }

/* ---------- the bay: ladder or empty home ---------- */

.bay {
  grid-area: bay;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.rig,
.home { flex: 1; min-height: 0; }
.app[data-view="home"] .rig,
.app[data-view="ladder"] .home { display: none; }

.rig { display: flex; flex-direction: column; gap: var(--gap); }

.cap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px 10px;
  padding: 8px 10px;
  border: 1px solid var(--ak-outline);
  border-top: 3px solid var(--ak-accent);
  background: var(--ak-bg);
}
.cap-name {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  font: 700 clamp(18px, 2.5dvh, 22px)/1.15 var(--ak-font-display);
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
/* Upright the next plate says it; sideways the goal panel spells it out (see the landscape block). */
.cap-next { display: none; }
.rig.is-summit .cap-read,
.rig.is-closing .cap-read { border-color: var(--ak-accent); }

.column { flex: 1; display: flex; gap: 8px; min-height: 0; }

/* The narrow bar beside the ladder, with 3/5 small at its head. */
.gauge {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 26px;
}
.gauge-num { font: 700 14px/1 var(--ak-font-display); font-variant-numeric: tabular-nums; }
.gauge-track {
  position: relative;
  flex: 1;
  width: 12px;
  border: var(--edge) solid var(--ak-ink-muted);
  background: var(--ak-bg);
}
.gauge-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--fill, 0) * 100%);
  background: var(--ak-accent);
}
.gauge-track i {
  position: absolute;
  left: -6px;
  right: -6px;
  bottom: calc(var(--n) * 20%);
  height: 2px;
  background: var(--ak-ink-muted);
}
.rig.is-summit .gauge-track { border-color: var(--ak-accent); }

/* ---------- the ladder: two rails and five plates, rung 1 at the bottom ---------- */

.ladder {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}
.ladder::before,
.ladder::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--rail);
}
.ladder::before { left: 16px; }
.ladder::after { right: 16px; }

.rung {
  position: relative;
  z-index: 1;
  display: flex;
  flex: 1 1 auto;
  min-height: 48px;
}
.rung.is-next { flex-grow: 2.4; min-height: 92px; }

.plate {
  position: relative;
  flex: 1;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 7px 8px 7px 8px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--ak-accent) 40%, var(--ak-outline));
  border-radius: 0;
  background: var(--ak-surface);
  box-shadow: inset 0 -3px 0 var(--shade);
  text-align: left;
  touch-action: manipulation;
}
.plate:active { transform: translateY(2px); box-shadow: none; }

/* The lamp and the rung's number, read across a room. */
.plate-num {
  display: grid;
  justify-items: center;
  gap: 5px;
  min-width: 30px;
}
.plate-num b {
  color: var(--ak-ink-muted);
  font: 700 17px/1 var(--ak-font-display);
  font-variant-numeric: tabular-nums;
}

.lamp {
  flex: none;
  width: 16px;
  height: 16px;
  border: var(--edge) solid var(--ak-outline);
  border-radius: 50%;
  background: var(--ak-bg);
}
.lamp.is-ready { border-color: var(--ak-accent); }

.plate-body { display: grid; gap: 4px; min-width: 0; }
.plate-tag { color: var(--ak-ink); }
.plate-words {
  display: -webkit-box;
  overflow: hidden;
  color: var(--ak-ink);
  font: 600 15px/1.2 var(--ak-font-body);
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.plate-proof {
  display: -webkit-box;
  overflow: hidden;
  color: var(--ak-ink-muted);
  font: 600 13px/1.25 var(--ak-font-display);
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.plate-proof-key {
  color: var(--ak-ink);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.plate-side { display: flex; align-items: center; gap: 8px; height: 100%; }

/* The date, stacked so the words keep the width. */
.plate-due {
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 5px 7px;
}
.plate-due .readout-key { font-size: 11px; letter-spacing: 0.1em; }
.readout-val { font-size: 15px; }

.plate-pencil {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--ak-accent);
  background: var(--ak-bg);
  color: var(--ak-accent);
}
.plate-pencil .ico { width: 20px; height: 20px; }

/* open: a dark lamp, words in plain ink */
.rung.is-open .plate-words { font-weight: 500; }

/* next: the biggest plate, bold words, its date in a boxed readout */
.rung.is-next .plate {
  gap: 12px;
  padding: 10px 12px 10px 8px;
  border: 3px solid var(--ak-accent);
  box-shadow: inset 0 -4px 0 var(--shade), 0 0 0 1px var(--ak-bg);
}
.rung.is-next .lamp { width: 22px; height: 22px; border-color: var(--ak-accent); border-width: 3px; }
.rung.is-next .plate-num b { color: var(--ak-ink); font-size: 24px; }
.rung.is-next .plate-body { gap: 6px; }
.rung.is-next .plate-words {
  font: 700 clamp(18px, 2.6dvh, 23px)/1.22 var(--ak-font-display);
  -webkit-line-clamp: 4;
}
.rung.is-next .readout-val { font-size: 17px; }

/* climbed: the plate is full, the lamp lit, the date stamped, the proof under the words */
.rung.is-climbed .plate {
  border: var(--edge) solid var(--ak-accent);
  box-shadow: inset 6px 0 0 var(--ak-accent), inset 0 -3px 0 var(--shade);
  padding-left: 12px;
}
.rung.is-climbed .plate-num b { color: var(--ak-ink); }
.rung.is-climbed .lamp {
  border-color: var(--ak-btn-ink);
  background: var(--ak-accent);
  box-shadow: 0 0 0 2px var(--ak-accent);
}

.stamp {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  height: 46px;
  aspect-ratio: 384 / 225;
}
.stamp img { position: absolute; inset: 0; width: 100%; height: 100%; }
.stamp-date {
  position: relative;
  color: var(--ak-ink);
  font: 700 12px/1 var(--ak-font-display);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* past due: a dashed readout and a plain word, never a colour alone */
.rung.is-late .plate-due { border: var(--edge) dashed var(--ak-accent-2); }

/* blank: a dashed plate that waits for words */
.rung.is-blank .plate { border-style: dashed; }
.rung.is-blank .plate-words { color: var(--ak-ink-muted); font-style: italic; }

/* edit mode: every plate takes the pencil */
.rig.is-editing .plate { border-style: dashed; border-color: var(--ak-accent); }
.rung.is-picked .plate { border: 3px solid var(--ak-accent); }

/* a wrong rung keeps its mark until the next tap */
.rung.is-wrong .plate { outline: 3px dashed var(--ak-accent-2); outline-offset: -3px; }

/* Too many long rungs for the height: smaller type and a one-line proof, words still whole. */
.rig.is-tight .ladder { gap: 6px; }
.rig.is-tight .plate { padding-top: 4px; padding-bottom: 4px; }
.rig.is-tight .plate-words { font-size: 14px; }
.rig.is-tight .plate-proof { font-size: 12.5px; }
.rig.is-tight .rung.is-next .plate-words { font-size: 18px; -webkit-line-clamp: 3; }
.rig.is-tight .stamp { height: 38px; }

/* ---------- home: the empty ladder ---------- */

.home {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "copy" "ghost" "guide" "go" "shelf";
  align-content: start;
  gap: 12px;
  overflow-y: auto;
}

.home-copy {
  grid-area: copy;
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid var(--ak-outline);
  border-top: 3px solid var(--ak-accent);
  background: var(--ak-bg);
}
.home-title {
  margin: 0;
  font: 700 clamp(22px, 6.6vw, 28px)/1.05 var(--ak-font-display);
  letter-spacing: 0.01em;
  text-transform: uppercase;
}
.home-text { margin: 0; color: var(--ak-ink); font-size: 16px; line-height: 1.4; }

/* Five plates, each with its number and what it is for; the bottom one lit as the way in. */
.ghost {
  grid-area: ghost;
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.ghost li {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}
.ghost img {
  display: block;
  width: auto;
  height: clamp(28px, 4.1dvh, 44px);
  filter: grayscale(1) brightness(0.5);
}
.ghost-num {
  color: var(--ak-ink-muted);
  font: 700 18px/1 var(--ak-font-display);
  font-variant-numeric: tabular-nums;
}
.ghost-say {
  color: var(--ak-ink-muted);
  font: 600 13px/1.2 var(--ak-font-display);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.ghost-first img { filter: none; }
.ghost-first .ghost-num,
.ghost-first .ghost-say { color: var(--ak-ink); }

/* Upright the invitation's parts sit in the home grid itself; sideways they stack in the main area. */
.home-lead { display: contents; }
.home-guide { grid-area: guide; }
.home-go { grid-area: go; }

.home-shelf {
  grid-area: shelf;
  display: grid;
  gap: 6px;
  min-width: 0;
}
.home-shelf-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }

.home-card,
.shelf-item {
  flex: none;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 190px;
  min-height: 64px;
  padding: 6px 10px 6px 6px;
  border: var(--edge) solid var(--ak-outline);
  border-radius: 0;
  background: var(--ak-surface);
  text-align: left;
}
.home-card img,
.shelf-item img { width: 34px; height: auto; display: block; }
.shelf-text { display: grid; gap: 3px; min-width: 0; }
.shelf-name {
  overflow: hidden;
  font: 700 14px/1.2 var(--ak-font-display);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.shelf-date { color: var(--ak-ink-muted); font: 600 11px/1 var(--ak-font-display); letter-spacing: 0.1em; text-transform: uppercase; }
.shelf-item[aria-pressed="true"] { border-color: var(--ak-accent); box-shadow: inset 0 3px 0 var(--ak-accent); }

/* ---------- keys and fields ---------- */

.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0 14px;
  border: var(--edge) solid var(--ak-outline);
  border-bottom-width: 4px;
  border-radius: 2px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font: 700 13px/1 var(--ak-font-display);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  touch-action: manipulation;
}
.key:active { transform: translateY(2px); border-bottom-width: 2px; margin-bottom: 2px; }
.key-go {
  border-color: var(--ak-btn-ink);
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
}
.key-go:active { background: var(--ak-btn-active); }
.key-big { min-height: 60px; width: 100%; font-size: 18px; }
.key-big .ico { width: 26px; height: 26px; }
.key-sq { flex: none; width: var(--tap); padding: 0; }
.key-wide { flex: 1 1 auto; }

.input {
  width: 100%;
  min-width: 0;
  min-height: var(--tap);
  padding: 0 12px;
  border: var(--edge) solid var(--ak-outline);
  border-radius: 0;
  background: var(--ak-bg);
  color: var(--ak-ink);
  font: 500 16px/1.2 var(--ak-font-body);
}
.input::placeholder { color: var(--ak-ink-muted); opacity: 0.8; }
.input:focus { border-color: var(--ak-accent); outline: none; }
.input[aria-invalid="true"] { border-color: var(--ak-accent-2); border-style: dashed; }
.input-big { min-height: 54px; font-size: 18px; font-weight: 600; }
.input-date { font-family: var(--ak-font-display); font-weight: 600; letter-spacing: 0.04em; }

.row { display: flex; align-items: center; gap: 8px; min-width: 0; }

.err {
  margin: 0;
  padding: 7px 10px;
  border-left: 4px solid var(--ak-accent-2);
  background: var(--ak-bg);
  color: var(--ak-ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
}

.hint-line {
  margin: 0;
  color: var(--ak-ink-muted);
  font: 600 12.5px/1.3 var(--ak-font-display);
  letter-spacing: 0.02em;
}

/* ---------- the dock: tools along the bottom edge ---------- */

.dock {
  grid-area: dock;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-width: 0;
}

.tools {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 6px;
}

.tool {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 62px;
  padding: 8px 2px 6px;
  border: var(--edge) solid var(--ak-outline);
  border-bottom-width: 5px;
  border-radius: 2px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  touch-action: manipulation;
}
.tool-label {
  font: 700 12px/1.1 var(--ak-font-display);
  letter-spacing: 0.04em;
  text-align: center;
  text-transform: uppercase;
}
.tool[aria-pressed]::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 5px;
  width: 6px;
  height: 6px;
  background: var(--ak-bg);
  border: 1px solid var(--ak-outline);
}
.tool:active,
.tool[aria-pressed="true"] {
  transform: translateY(3px);
  border-bottom-width: 2px;
  margin-bottom: 3px;
}
.tool[aria-pressed="true"] { border-color: var(--ak-accent); }
.tool[aria-pressed="true"]::after { background: var(--ak-accent); border-color: var(--ak-accent); }
.tool-new { border-color: var(--ak-btn-ink); background: var(--ak-btn-fill); color: var(--ak-btn-ink); }
.tool-count {
  position: absolute;
  top: 3px;
  left: 5px;
  font: 700 13px/1 var(--ak-font-display);
  font-variant-numeric: tabular-nums;
  color: var(--ak-ink);
}

.dock:not([data-mode="tools"]) .tools { display: none; }

.pane {
  border: 1px solid var(--ak-outline);
  border-top: 3px solid var(--ak-accent);
  background: var(--ak-bg);
}
.pane-in { display: grid; gap: 8px; padding: 10px 12px 12px; }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0; }
.pane-head .engrave { margin-right: auto; color: var(--ak-ink); }
.pane-words { margin: 0; font: 700 17px/1.25 var(--ak-font-display); }
.pane-keys { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { color: var(--ak-ink-muted); letter-spacing: 0.08em; text-transform: lowercase; font-style: italic; }
.count { flex: none; min-width: 60px; justify-content: center; }

.kept {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--ak-ink-muted);
  font: 500 14px/1.3 var(--ak-font-body);
}
.kept-lamp {
  flex: none;
  width: 10px;
  height: 10px;
  border: 1px solid var(--ak-outline);
  background: var(--ak-bg);
}
.kept.is-set .kept-lamp { background: var(--ak-accent); border-color: var(--ak-accent); }
.kept.is-error { color: var(--ak-ink); }
.kept.is-error .kept-lamp { background: var(--ak-accent-2); border-color: var(--ak-accent-2); }

/* ---------- the guide: first round only ---------- */

.guide-slot:empty { display: none; }
.guide {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: var(--edge) solid var(--ak-accent);
  background: var(--ak-surface);
  color: var(--ak-ink);
}
.guide-arrow {
  flex: none;
  width: 30px;
  height: 30px;
  fill: none;
  stroke: var(--ak-accent);
  stroke-width: 3;
  stroke-linecap: square;
}
.guide-text { margin: 0; font: 600 18px/1.35 var(--ak-font-body); }

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

/* ---------- sheet views: new goal and summits ---------- */

.sheetview {
  grid-row: 2 / 4;
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--ak-outline);
  border-top: 3px solid var(--ak-accent);
  background: var(--ak-bg);
}
.app[data-view="form"] .bay,
.app[data-view="form"] .dock,
.app[data-view="shelf"] .bay,
.app[data-view="shelf"] .dock { display: none; }

.sv-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--ak-outline);
}
.sv-title {
  margin: 0 auto 0 0;
  font: 700 22px/1 var(--ak-font-display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.sv-body {
  flex: 1;
  display: grid;
  align-content: start;
  gap: 14px;
  min-height: 0;
  padding: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sv-foot { display: grid; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--ak-outline); }

.field { display: grid; gap: 6px; }

.presets-box { display: grid; gap: 6px; }
.presets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.preset {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 6px 10px;
  border: var(--edge) solid var(--ak-outline);
  border-bottom-width: 4px;
  border-radius: 2px;
  background: var(--ak-surface);
  font: 700 13px/1.15 var(--ak-font-display);
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
}
.preset-lamp { flex: none; width: 10px; height: 10px; border: 1px solid var(--ak-outline); background: var(--ak-bg); }
.preset[aria-pressed="true"] { border-color: var(--ak-accent); transform: translateY(2px); border-bottom-width: 2px; margin-bottom: 2px; }
.preset[aria-pressed="true"] .preset-lamp { background: var(--ak-accent); border-color: var(--ak-accent); }
.preset:active { transform: translateY(2px); }

.form-sub { padding-top: 4px; border-top: 1px solid var(--ak-outline); }
.form-rungs { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.frung {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--ak-outline);
  background: var(--ak-surface);
}
.frung-num {
  display: grid;
  place-items: center;
  align-self: start;
  height: 44px;
  border: var(--edge) solid var(--ak-outline);
  background: var(--ak-bg);
  font: 700 18px/1 var(--ak-font-display);
  font-variant-numeric: tabular-nums;
}
.frung-main { display: grid; gap: 6px; min-width: 0; }
.row-date .engrave { flex: none; width: 44px; }
.row-date .input { max-width: 220px; }

.shelf-body {
  flex: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  min-height: 0;
  padding: 10px;
}
.shelf-list { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.shelf-list:empty { display: none; }

/* The summit card: a hard-edged column that reads like a short case file. */
.file {
  display: grid;
  align-content: start;
  gap: 10px;
  width: 100%;
  max-width: 560px;
  min-height: 0;
  margin: 0 auto;
  padding: 0 0 12px;
  overflow-y: auto;
  border: var(--edge) solid var(--ak-ink-muted);
  background: var(--ak-surface);
}
.file-empty { margin: 0; padding: 16px; color: var(--ak-ink-muted); font-size: 16px; line-height: 1.4; }
.file-tab {
  justify-self: start;
  margin: 0 0 0 12px;
  padding: 6px 12px;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font: 700 12px/1 var(--ak-font-display);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.file-name { margin: 0; padding: 0 14px; font: 700 22px/1.15 var(--ak-font-display); }
.file-dates { justify-self: start; margin: 0 14px; }
.file-lines { display: grid; margin: 0; padding: 0; list-style: none; }
.file-line {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 12px;
  padding: 10px 14px;
  border-top: 1px solid var(--ak-outline);
}
.file-check {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: var(--edge) solid var(--ak-accent);
  background: var(--ak-bg);
  color: var(--ak-accent);
}
.file-check .ico { width: 18px; height: 18px; stroke-width: 3; }
.file-text { display: grid; gap: 3px; min-width: 0; }
.file-text p { margin: 0; }
.file-words { font: 700 16px/1.25 var(--ak-font-display); }
.file-meta { color: var(--ak-ink-muted); font: 600 11.5px/1.2 var(--ak-font-display); letter-spacing: 0.1em; text-transform: uppercase; }
.file-proof { font: 600 14px/1.3 var(--ak-font-display); letter-spacing: 0.02em; overflow-wrap: anywhere; }
.file-proof.is-none { color: var(--ak-ink-muted); font-style: italic; }
.file-delete { justify-self: start; margin: 4px 14px 0; }

/* ---------- delete sheet ---------- */

.confirm {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--ak-bg) 84%, transparent);
}
.confirm-box {
  display: grid;
  gap: 10px;
  width: min(100%, 400px);
  padding: 16px;
  border: var(--edge) solid var(--ak-ink);
  border-top: 4px solid var(--ak-accent-2);
  background: var(--ak-surface);
}
.confirm-title { margin: 0; font: 700 20px/1.2 var(--ak-font-display); }
.confirm-text { margin: 0; color: var(--ak-ink); font-size: 15px; line-height: 1.4; }

/* ---------- upright with a pane open: every plate the same small height, so the whole ladder still fits ---------- */

/* The last step down, sideways when the rungs still do not fit, and upright with a pane open. */
.rig.is-compact .ladder { gap: 6px; }
.rig.is-compact .rung,
.rig.is-compact .rung.is-next { flex-grow: 1; min-height: 44px; }
.rig.is-compact .plate { padding-top: 3px; padding-bottom: 3px; }
.rig.is-compact .plate-tag { display: none; }
.rig.is-compact .plate-words,
.rig.is-compact .plate-proof { -webkit-line-clamp: 1; }
.rig.is-compact .rung.is-next .plate-words { font-size: 16px; -webkit-line-clamp: 1; }
.rig.is-compact .plate-due { flex-direction: row; padding: 4px 7px; }
.rig.is-compact .plate-num { grid-auto-flow: column; align-items: center; gap: 6px; }
.rig.is-compact .rung.is-next .plate-num b { font-size: 18px; }
.rig.is-compact .rung.is-next .lamp { width: 18px; height: 18px; }
.rig.is-compact .stamp { height: 32px; }

@media (orientation: portrait) {
  .rig.is-compact .cap { padding: 5px 10px; }
  .rig.is-compact .plate-proof { display: none; }
}

/* ---------- phone turned sideways: ladder on one side, goal and tools on the other ---------- */

@media (orientation: landscape) {
  .app {
    max-width: 1100px;
    grid-template-columns: minmax(0, 1.5fr) minmax(260px, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "ladder deck" "ladder cap" "ladder dock";
    column-gap: 16px;
  }
  .app.has-toast {
    grid-template-rows: auto auto auto minmax(0, 1fr);
    grid-template-areas: "ladder deck" "ladder slot" "ladder cap" "ladder dock";
  }
  .app.has-toast:is([data-view="form"], [data-view="shelf"]) {
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "slot slot" "ladder dock";
  }
  .app.has-toast:is([data-view="form"], [data-view="shelf"]) .sheetview { grid-row: 2 / -1; }
  .bay,
  .rig { display: contents; }
  .column,
  .home { grid-area: ladder; min-height: 0; }
  .cap { grid-area: cap; grid-template-columns: minmax(0, 1fr) auto; }
  .cap-next {
    display: block;
    grid-column: 1 / -1;
    margin: 0;
    padding-top: 6px;
    border-top: 1px solid var(--ak-outline);
    color: var(--ak-ink);
    font: 600 15px/1.3 var(--ak-font-body);
  }
  .app.has-toast .cap-next { display: none; }
  .dock { overflow-y: auto; align-content: start; }
  .sheetview { grid-row: 1 / -1; }
  .app[data-view="form"] .deck,
  .app[data-view="shelf"] .deck { display: none; }
  /* Sideways the empty home rearranges: the invitation and New goal take the main area, and the
     labelled ladder moves to the side panel, where the goal panel will sit once there is a goal. */
  .home { display: contents; }
  .home-lead {
    grid-area: ladder;
    display: grid;
    align-content: safe center;
    gap: 12px;
    min-height: 0;
    overflow-y: auto;
  }
  .home-lead > * { grid-area: auto; }
  .ghost { grid-area: cap; align-self: start; gap: 4px; }
  .ghost li { gap: 10px; }
  .ghost img { height: 26px; }
  .shelf-body { grid-template-columns: 220px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .shelf-list { flex-direction: column; overflow-x: hidden; overflow-y: auto; }
  .shelf-item { width: 100%; }
  .presets { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .form-rungs { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
}

/* A short screen: a phone on its side. Keep every plate readable and at least 44px. */
@media (max-height: 500px) {
  .logo { height: 34px; }
  .app[data-view="home"] .logo { height: 40px; }
  .tab { width: 52px; height: 52px; padding-top: 9px; }
  .tab-num { font-size: 18px; }
  .cap { padding: 5px 10px; }
  .cap-name { font-size: 17px; }
  .cap-next { font-size: 14px; }
  .ladder { gap: 5px; }
  .rung { min-height: 44px; }
  .rung.is-next { min-height: 78px; flex-grow: 2; }
  .plate { padding-top: 3px; padding-bottom: 3px; }
  .rung:not(.is-next) .plate-tag { display: none; }
  .stamp { height: 32px; }
  .app.has-toast .dock { gap: 6px; }
  .app.has-toast .tool { min-height: 48px; padding: 4px 2px; gap: 2px; }
  .app.has-toast .tool .ico { width: 20px; height: 20px; }
  .app:not([data-pane="tools"]) .cap { display: none; }
  .pane-in { gap: 6px; padding: 8px 10px 10px; }
  .rung.is-next .plate-words { -webkit-line-clamp: 2; }
  .plate-words { -webkit-line-clamp: 2; }
  .plate-proof { -webkit-line-clamp: 1; }
  .plate-due { padding: 3px 6px; gap: 2px; }
  .readout-day { display: none; }
  /* A short screen's middle step: open rungs keep two lines; a climbed rung keeps one line and its proof. */
  .rig.is-tight .rung.is-climbed .plate-words { -webkit-line-clamp: 1; }
  .rig.is-tight .plate-proof { -webkit-line-clamp: 1; }
  .rig.is-tight .rung.is-next { min-height: 64px; }
  .rig.is-tight .rung.is-next .plate-tag { display: none; }
  .rig.is-tight .rung.is-next .plate { padding-top: 6px; padding-bottom: 6px; }
  .rig.is-tight .rung.is-next .plate-words { font-size: 17px; -webkit-line-clamp: 2; }
  .plate-tag { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .plate-num { grid-auto-flow: column; align-items: center; gap: 6px; }
  .home-copy { padding: 10px; gap: 6px; }
  .home-title { font-size: 24px; }
  .home-text { display: none; }
  .ghost img { height: 22px; }
  .ghost-num { font-size: 15px; }
  .ghost-say { font-size: 12px; }
  .tool { min-height: 54px; }
  .guide-text { font-size: 18px; }
}

/* The narrowest phones. */
@media (max-width: 380px) {
  .tool-label { font-size: 11px; letter-spacing: 0.04em; }
}

/* ---------- motion: slow and mechanical; never when asked for less ---------- */

@media (prefers-reduced-motion: no-preference) {
  :root:not(.ac-still) .gauge-fill { transition: height 420ms steps(4, end); }

  :root:not(.ac-still) .cap-read.is-printing { animation: print-line 520ms steps(10, end) both; }

  :root:not(.ac-still) .rung.is-just .plate::after {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--ak-accent);
    transform-origin: left center;
    animation: plate-snap 620ms steps(6, end) both;
  }
  :root:not(.ac-still) .rung.is-just .lamp { animation: lamp-click 620ms steps(1, end) both; }
  :root:not(.ac-still) .rung.is-just .stamp { animation: stamp-print 420ms steps(3, end) 520ms both; }

  :root:not(.ac-still) .rig.is-summit .lamp {
    animation: lamp-click 260ms steps(1, end) both;
    animation-delay: calc(var(--i) * 260ms);
  }
  :root:not(.ac-still) .rig.is-summit .rung:last-child .plate { animation: none; }

  :root:not(.ac-still) .rung.is-wrong .plate { animation: nudge 300ms steps(3, end); }

  :root:not(.ac-still) .is-guided { animation: ring-blink 1400ms steps(1, end) infinite; }

  :root:not(.ac-still) .file.is-printing .file-tab,
  :root:not(.ac-still) .file.is-printing .file-name,
  :root:not(.ac-still) .file.is-printing .file-dates { animation: print-line 420ms steps(6, end) both; }
  :root:not(.ac-still) .file.is-printing .file-line {
    animation: print-row 420ms steps(5, end) both;
    animation-delay: calc(var(--n) * 380ms);
  }

  :root:not(.ac-still) .guide { animation: print-row 360ms steps(4, end) both; }
}

@keyframes print-line {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(0 0 0 0); }
}
@keyframes print-row {
  from { clip-path: inset(0 0 100% 0); }
  to { clip-path: inset(0 0 0 0); }
}
@keyframes plate-snap {
  0% { transform: scaleX(0); opacity: 1; }
  50% { transform: scaleX(1); opacity: 1; }
  100% { transform: scaleX(1); opacity: 0; }
}
@keyframes lamp-click {
  0% { background: var(--ak-bg); box-shadow: none; }
  100% { background: var(--ak-accent); box-shadow: 0 0 0 2px var(--ak-accent); }
}
/* Pressed down into the plate, never larger than it, so the stamp is never cut at the plate's edge. */
@keyframes stamp-print {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes nudge {
  0%, 100% { translate: 0 0; }
  33% { translate: -4px 0; }
  66% { translate: 4px 0; }
}
@keyframes ring-blink {
  0% { outline-color: var(--ak-accent); }
  50% { outline-color: transparent; }
}
