/* Kitchen display — tokens only (rules 11). Dark ground = the skin's own ink, light cards on it,
   so a card reads across a kitchen. Age is FILL + border style + glyph + motion, never colour
   alone: a card that is behind turns yellow, then red and blinking, so it reads from the pass. */

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--text);
  color: var(--bg);
  display: grid;
  /* Explicit rows AND an explicit `grid-row` per child. `display:none` removes a child from
     grid placement entirely, so with auto-placement the hidden hint/banner let `.queue` walk
     backwards into an `auto` track and the `minmax(0,1fr)` landed *after* `.tray` — an empty
     queue collapsed to a 71px strip with the tray mid-screen. Naming the row of every child
     makes the queue's track the 1fr one in all four hint/banner combinations. */
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

/* ── header ─────────────────────────────────────────────────────────────── */
.bar {
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-5);
  border-bottom: var(--border) solid var(--text-dim);
}
.bar__title { font-family: var(--font-display); font-size: var(--text-xl); margin: 0; letter-spacing: var(--tracking-tight); }
.bar__count { font-family: var(--font-sans); font-size: var(--text-md); color: var(--text-faint); margin-left: var(--space-3); }
.bar__right { display: flex; gap: var(--space-3); align-items: center; }

.pill {
  font-size: var(--text-sm);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  border: var(--border) solid var(--stroke-strong);
  color: var(--bg);
}
.pill[data-state='live'] { border-color: var(--ok); border-style: solid; }
.pill[data-state='connecting'], .pill[data-state='reconnecting'], .pill[data-state='polling'] { border-color: var(--warn); border-style: dashed; }
.pill[data-state='offline'] { border-color: var(--danger); border-style: double; }

.sound {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  min-height: var(--tap-min);
  min-width: var(--tap-min);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: var(--border) solid var(--stroke-strong);
  background: transparent;
  color: var(--bg);
  display: inline-flex;
  gap: var(--space-2);
  align-items: center;
}
.sound[aria-pressed='true'] { border-style: dashed; color: var(--text-faint); }
.sound[aria-pressed='true'] .sound__glyph { text-decoration: line-through; }

.sound-hint {
  grid-row: 2;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  min-height: var(--tap-min);
  margin: var(--space-2) var(--space-5) 0;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  border: var(--border) dashed var(--accent);
  background: var(--accent-soft);
  color: var(--bg);
}
.sound-hint[hidden] { display: none; }

/* ── connection banner ──────────────────────────────────────────────────── */
.banner {
  grid-row: 3;
  display: flex;
  gap: var(--space-3);
  align-items: center;
  margin: var(--space-2) var(--space-5) 0;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  border: var(--border-thick) dashed var(--warn);
  font-size: var(--text-md);
}
.banner[data-level='danger'] { border-style: double; border-color: var(--danger); }
.banner[hidden] { display: none; }
.banner__glyph { font-size: var(--text-lg); }

/* ── the queue grid (KDS-7) ─────────────────────────────────────────────── */
.queue {
  grid-row: 4;
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(3, minmax(0, 1fr));
  grid-auto-columns: calc(50% - var(--space-3));
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
}
/* spec §5: "overflow past two columns scrolls horizontally with a visible edge fade". Gated on
   the attribute `render()` sets, because an unconditional mask dims the right-hand column's Done
   target — a tap area — on the ordinary two-column screen where there is nothing to scroll to.
   Keyword stops only: `transparent`/`black` are not literal colours, so this stays tokens-clean. */
.queue[data-overflow='true'] {
  -webkit-mask-image: linear-gradient(to right, black calc(100% - var(--space-8)), transparent);
  mask-image: linear-gradient(to right, black calc(100% - var(--space-8)), transparent);
}
.queue:empty::after {
  content: 'No open orders';
  grid-row: 1 / -1;
  align-self: center;
  justify-self: start;
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  color: var(--text-faint);
}

/* ── a card ─────────────────────────────────────────────────────────────── */
.card {
  position: relative;
  display: grid;
  /* The left rail never participates in intrinsic sizing. The timer grows from 0:00 to 10:00
     and gains a large warning glyph at four minutes; when this track was `auto`, both changes
     pushed every menu icon and name sideways once per order. */
  grid-template-columns: calc(var(--space-9) + var(--space-2)) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  border: var(--border-thick) solid var(--stroke);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  scroll-snap-align: start;
  /* fix 2: `pan-x` was inverted. It hands horizontal drags to the scrolling grid — a swipe
     scrolled past six cards and fired pointercancel instead of Done — and forbids the vertical
     finger-scroll `.card__items` needs to reach a fourth line. `pan-y` keeps vertical scrolling
     for the browser and leaves horizontal movement to `attachSwipe`. */
  touch-action: pan-y;
  transition: transform var(--dur-base) var(--ease-out), opacity var(--dur-base) var(--ease-out);
}
/* fix 5: while a finger is dragging, the per-pointermove inline transform must land at once —
   the 240ms transition above made the card trail the finger. `attachSwipe` sets and clears the
   attribute; specificity (0,2,0) beats `.card`. */
.card[data-swiping='true'] { transition: none; }
@keyframes card-in { from { opacity: 0; transform: translateY(var(--space-5)); } to { opacity: 1; transform: none; } }
@keyframes card-out { to { opacity: 0; transform: translateX(var(--space-8)); } }

.card__number {
  grid-column: 1;
  grid-row: 1;
  font-family: var(--font-display);
  font-size: var(--text-4xl);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
}
.card__meta { grid-column: 1; grid-row: 2; align-self: end; display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-1); }
.card__station { font-family: var(--font-mono); font-size: var(--text-sm); color: var(--text-dim); }
.card__age {
  font-size: var(--text-md);
  color: var(--text-dim);
  display: inline-flex;
  gap: var(--space-2);
  align-items: center;
  font-variant-numeric: tabular-nums;
}
.card__age-text { min-width: 5ch; }
.card__glyph { display: none; font-size: var(--text-lg); }

.card__items { grid-column: 2; grid-row: 1 / -1; display: flex; flex-direction: column; gap: var(--space-2); min-height: 0; overflow-y: auto; overflow-x: hidden; }
.item { display: grid; grid-template-columns: auto auto 1fr; gap: var(--space-3); align-items: center; }
.item__art { width: var(--space-7); height: var(--space-7); }
.item__art img { width: 100%; height: 100%; display: block; }
.item__qty { font-size: var(--text-2xl); font-family: var(--font-display); min-width: var(--space-7); text-align: right; }
.item__name { font-size: var(--text-lg); line-height: var(--leading-tight); }
.item__mods { display: flex; flex-wrap: wrap; gap: var(--space-1); margin-top: var(--space-1); }
.chip {
  font-size: var(--text-sm);
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  border: var(--border) solid var(--stroke-strong);
  color: var(--text-dim);
}

/* The Done target: the whole right edge, at least --tap-min wide. Swipe right does the same. */
.card__done {
  position: absolute;
  inset: 0 0 0 auto;
  width: var(--space-9);
  border: 0;
  border-left: var(--border) dashed var(--stroke);
  background: var(--accent-soft);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}
.card__done:active { background: var(--accent); color: var(--accent-contrast); }
.card { padding-right: calc(var(--space-9) + var(--space-3)); }

/* ── age (rules 11 §5: fill + border style + glyph + motion, never colour alone) ──────────
   Sam, 2026-09-02: an amber dashed border and a small ⚠ were invisible across a kitchen. The WHOLE
   card now takes the colour — `--kitchen-warn` (yellow, dark ink) from warnAfterMs and
   `--kitchen-late` (red, white ink) from lateAfterMs, which hard-blinks against the surface at
   ~0.8 Hz (well under the 3 Hz photosensitivity ceiling; steady red under reduced motion). Both
   are sushi skin extras — `--warn`/`--danger` stay the text-on-surface pair. The shape channel is
   kept (dashed / double), the glyph grows, and the timer is the card's largest label after the
   number. Every inner colour under an aged card is `inherit`/`currentColor`, so the one `color`
   on the card carries the whole flip. */
.card[data-age='warn'], .card[data-age='late'] { transition: background var(--dur-base) var(--ease-out), color var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out), opacity var(--dur-base) var(--ease-out); }
.card[data-age='warn'] .card__station, .card[data-age='late'] .card__station,
.card[data-age='warn'] .card__age,     .card[data-age='late'] .card__age,
.card[data-age='warn'] .chip,          .card[data-age='late'] .chip { color: inherit; }
.card[data-age='warn'] .chip, .card[data-age='late'] .chip { border-color: currentColor; }
.card[data-age='warn'] .card__age, .card[data-age='late'] .card__age { font-size: var(--text-xl); font-weight: 700; }
.card[data-age='warn'] .card__glyph, .card[data-age='late'] .card__glyph { display: inline; font-size: var(--text-2xl); }
/* The Done edge stays a light, labelled target on both fills — it must not blink with the card. */
.card[data-age='warn'] .card__done, .card[data-age='late'] .card__done { background: var(--surface-raised); color: var(--text); border-left-color: var(--stroke-strong); }

.card[data-age='warn'] { background: var(--kitchen-warn); color: var(--text); border-color: var(--text); border-style: dashed; }

.card[data-age='late'] {
  background: var(--kitchen-late);
  color: var(--accent-contrast);
  border-color: var(--accent-contrast);
  border-style: double;
  animation: late-blink calc(2 * var(--dur-slower)) linear infinite;
}
/* Two held halves = a hard blink: red with white ink, then white with red ink. The 0.01% gap
   keeps `linear` from ever showing a mid-mix frame. */
@keyframes late-blink {
  0%, 50%      { background: var(--kitchen-late); color: var(--accent-contrast); border-color: var(--accent-contrast); }
  50.01%, 100% { background: var(--surface);      color: var(--kitchen-late);    border-color: var(--kitchen-late); }
}

/* ── READY (KDS-5): the number fills the card so the chef can call it across the pass ── */
/* Two rows: the number, then READY and Undo side by side. A three-row column stack does not fit
   — see the arithmetic in the fix report — and the first row is `minmax(0, auto)` so that when
   the tray is open (which takes another 108px off the queue) the squeeze lands on the number,
   never on the Undo target. */
.card__ready {
  position: absolute;
  inset: 0;
  display: none;
  grid-template-columns: auto auto;
  grid-template-rows: minmax(0, auto) auto;
  align-content: center;
  justify-content: center;
  align-items: center;
  gap: var(--space-1) var(--space-3);
  background: var(--surface-raised);
  color: var(--text);
  border-radius: var(--radius-lg);
}
.card[data-ready='true'] { border-color: var(--ok); border-style: solid; animation: none; background: var(--surface); color: var(--text); }
.card[data-ready='true'] .card__ready { display: grid; animation: card-in var(--dur-base) var(--ease-out); }
.ready__number {
  grid-column: 1 / -1;
  justify-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 0;
  overflow: hidden;
  gap: var(--space-1);
}
.ready__number-label {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-tight);
  color: var(--text-dim);
}
.ready__number-value {
  font-family: var(--font-display);
  font-size: var(--text-5xl);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
}
.ready__label { grid-column: 1; font-size: var(--text-xl); letter-spacing: var(--tracking-wide); text-transform: uppercase; color: var(--ok); }
.ready__undo {
  grid-column: 2;
  font-family: var(--font-sans);
  font-size: var(--text-md);
  min-height: var(--tap-min);
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-pill);
  border: var(--border) solid var(--stroke-strong);
  background: var(--surface);
  color: var(--text);
}
.ready__bar { position: absolute; left: 0; right: 0; bottom: 0; height: var(--space-1); background: var(--ok); transform-origin: left; }
.ready__bar--run { animation: ready-drain linear forwards; }
@keyframes ready-drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* ── the Done tray (KDS-5) ──────────────────────────────────────────────── */
.tray {
  grid-row: 5;
  border-top: var(--border) solid var(--text-dim);
  /* fix 6: additive to the existing 0 bottom padding — on a Face-ID iPad the home indicator
     otherwise sits on top of the toggle. `env()` is not a `var()`, so tokens:check is happy. */
  padding: 0 var(--space-5) env(safe-area-inset-bottom);
  background: var(--text);
}
.tray__toggle {
  font-family: var(--font-sans);
  font-size: var(--text-md);
  min-height: var(--tap-min);
  padding: var(--space-2) var(--space-4);
  border: 0;
  background: transparent;
  color: var(--bg);
  display: inline-flex;
  gap: var(--space-2);
  align-items: center;
}
.tray__count { font-family: var(--font-mono); font-size: var(--text-sm); color: var(--text-faint); }
.tray__list {
  display: flex;
  gap: var(--space-3);
  overflow-x: auto;
  max-height: 0;
  padding-bottom: 0;
  transition: max-height var(--dur-slow) var(--ease-out), padding var(--dur-slow) var(--ease-out);
}
.tray[data-open='true'] .tray__list { max-height: var(--space-9); padding-bottom: var(--space-3); }
.tray-chip {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  min-height: var(--tap-min);
  min-width: var(--space-8);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  border: var(--border) solid var(--ok);
  background: transparent;
  color: var(--bg);
  display: inline-flex;
  gap: var(--space-2);
  align-items: baseline;
  flex: none;
}
.tray-chip small { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-faint); }

/* ── toast (POST failed → snapped back) ─────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: var(--space-8);
  transform: translateX(-50%);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-pill);
  border: var(--border-thick) double var(--danger);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-md);
  box-shadow: var(--shadow-md);
  animation: card-in var(--dur-base) var(--ease-out);
}
.toast[hidden] { display: none; }
@keyframes shake { 25% { transform: translateX(calc(-1 * var(--space-2))); } 75% { transform: translateX(var(--space-2)); } }

/* ── transient motion states, LAST on purpose ───────────────────────────── */
/* leave/shake are doubled = (0,2,0) so they out-specify `.card[data-age='late']`'s infinite
   blink — at (0,1,0) a red card never slid out and never shook, and `leave()` sat waiting for
   its 700ms fallback. They also sit *after* `.card[data-ready='true'] { animation: none }`,
   which is the same (0,2,0): a card that leaves at the end of its READY hold is the common case,
   and the later rule is the one that wins a specificity tie.

   `card--enter` is deliberately NOT doubled. It is the one class here that is added at build
   time rather than for the length of a gesture, and doubling it cost the late blink outright:
   every card matched `animation: card-in` forever, so a card going red never blinked. It is now
   (0,1,0) — it can never out-rank an age rule again — and `render()` removes it once the landing
   animation has finished. Both halves matter: either alone leaves the bug reachable. */
.card--enter { animation: card-in var(--dur-slow) var(--ease-spring) backwards; }
.card.card--leave { animation: card-out var(--dur-slow) var(--ease-in) forwards; }
.card.card--shake { animation: shake var(--dur-slow) var(--ease-out); }

@media (prefers-reduced-motion: reduce) {
  /* Doubled to match the (0,2,0) rules above — at (0,1,0) reduced motion would have lost.
     `card--enter` is single there, so it is single here, and this block still comes last. */
  .card, .card--enter, .card.card--leave, .card[data-age='late'], .card.card--shake,
  .toast, .card[data-ready='true'] .card__ready { animation: none; transition: none; }
  .ready__bar--run { animation: none; transform: scaleX(0); }
}
