:root {
  --line: 1.5px;
  --rule: color-mix(in srgb, var(--ak-ink) 24%, transparent);
  --pad: 10px;
  --gap: 8px;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --wash: color-mix(in srgb, var(--ak-bg) 85%, transparent);
  --ak-backdrop-layer: linear-gradient(var(--wash), var(--wash)), url("art/hush-tent.jpg");
  /* One lane is 2r wide and 5.2r tall; r comes from both the width and the height. */
  --r-w: calc((100dvw - 2 * var(--pad) - var(--sal) - var(--sar) - 2 * var(--gap)) / 6);
  --r-h: calc((100dvh - var(--sat) - var(--sab) - 494px) / 5.2);
  --r: max(50px, min(var(--r-w), var(--r-h), 72px));
  --cap-h: 98px;
}

* { box-sizing: border-box; }

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

body {
  background-color: var(--ak-bg);
  background-image: var(--ak-backdrop-layer);
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
  color: var(--ak-ink);
  font-family: var(--ak-font-body, system-ui);
  font-size: 16px;
  line-height: 1.4;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; }
img { -webkit-user-drag: none; user-select: none; }

/* ---------- layout ---------- */

.stage {
  position: relative;
  width: 100%;
  max-width: 980px;
  height: 100dvh;
  margin: 0 auto;
  padding: calc(var(--sat) + 6px) calc(var(--pad) + var(--sar)) calc(var(--sab) + 6px) calc(var(--pad) + var(--sal));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  touch-action: manipulation;
}

.mast {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 48px;
}
.mast-logo { height: 34px; width: auto; display: block; }

.board {
  flex: none;
  display: flex;
  gap: var(--gap);
  justify-content: center;
  align-items: flex-start;
}

.desk {
  flex: 1 1 auto;
  min-height: 0;
  width: min(100%, 440px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
}
.desk > * { flex: none; }

@media (orientation: landscape) {
  :root {
    --r-h: calc((100dvh - var(--sat) - var(--sab) - var(--cap-h) - 16px) / 5.2);
  }
  .stage {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "board mast" "board desk";
    column-gap: 28px;
    row-gap: 10px;
    align-content: center;
    align-items: start;
    justify-items: stretch;
    padding-left: calc(var(--pad) + var(--sal) + 56px);
    padding-top: calc(var(--sat) + 8px);
    padding-bottom: calc(var(--sab) + 8px);
  }
  .mast { grid-area: mast; justify-content: flex-start; padding-right: 60px; }
  .board { grid-area: board; }
  .desk {
    grid-area: desk;
    width: 100%;
    max-width: 460px;
    border-top: 0;
    padding-top: 0;
    gap: 10px;
  }
}

/* ---------- mute ---------- */

.mute {
  position: fixed;
  top: max(12px, var(--sat));
  left: max(12px, var(--sal));
  z-index: 20;
  width: 48px;
  height: 48px;
  padding: 0;
  display: grid;
  place-items: center;
  background: transparent;
  border: 0;
  cursor: pointer;
}
.mute svg { width: 24px; height: 24px; }
.mute svg path {
  stroke: var(--ak-ink);
  stroke-width: var(--line);
  stroke-linecap: round;
  stroke-linejoin: round;
}
.mute .mute-slash { display: none; }
.mute[aria-pressed="true"] .mute-slash { display: inline; }
.mute[aria-pressed="true"] .mute-wave { display: none; }
.mute:focus-visible, .btn:focus-visible, .lane:focus-visible {
  outline: 2px solid var(--ak-focus);
  outline-offset: 3px;
}

/* ---------- lanes ---------- */

.lane {
  position: relative;
  flex: none;
  width: calc(2 * var(--r));
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: transparent;
  border: 0;
  border-radius: 14px;
  text-align: left;
  cursor: default;
}
.lane.can-tap { cursor: pointer; }

.lane-body {
  position: relative;
  display: block;
  height: calc(5.2 * var(--r));
}

.lane-art {
  position: absolute;
  inset: 0;
  border-style: solid;
  border-color: transparent;
  border-width: calc(var(--r) * 0.795) calc(var(--r) * 0.373) calc(var(--r) * 0.497);
  border-image-source: url("art/checkout-lane.png");
  border-image-slice: 64 30 40 30;
  border-image-width: calc(var(--r) * 0.795) calc(var(--r) * 0.373) calc(var(--r) * 0.497) calc(var(--r) * 0.373);
  border-image-repeat: stretch;
  filter: grayscale(1) opacity(0.6);
}
.lane.can-tap .lane-art { filter: none; }

.queue {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--r) * 0.8);
  bottom: calc(var(--r) * 0.45);
}

.pair {
  position: absolute;
  left: 50%;
  top: 0;
  height: var(--r);
  display: flex;
  align-items: center;
  gap: 3px;
  transform: translate(-50%, calc(var(--pos) * var(--r)));
}

.shopper {
  display: block;
  height: calc(var(--r) * 0.94);
  width: auto;
  aspect-ratio: 278 / 384;
}

.load {
  display: grid;
  place-items: center;
  width: max(44px, calc(var(--r) * 0.84));
  height: max(44px, calc(var(--r) * 0.84));
}
.load svg { display: block; width: 100%; height: 100%; }
.load img { display: block; width: 100%; height: auto; }
.load svg * {
  stroke: var(--ak-ink);
  stroke-width: var(--line);
  stroke-linejoin: round;
  stroke-linecap: round;
}

.lane.is-pick {
  outline: var(--line) solid var(--ak-ink);
  outline-offset: 4px;
}
.lane.is-dim .lane-body,
.lane.is-dim .cap { opacity: 0.38; }

.cap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: var(--cap-h);
  padding: 7px 2px 0;
}
.cap-clerk { display: flex; align-items: center; gap: 4px; width: 100%; }
.cap-face { flex: none; width: 28px; height: 28px; }
.cap-face svg { display: block; width: 100%; height: 100%; overflow: visible; }
.cap-face svg * {
  stroke: var(--ak-ink);
  stroke-width: 1.3;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.cap-who { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; }
.cap-plate {
  padding: 0 4px;
  border: 1px solid var(--ak-ink);
  font-size: 11px;
  font-weight: 700;
  line-height: 15px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  white-space: nowrap;
}
.cap-tag {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
  white-space: nowrap;
}
.cap-note {
  font-size: 12px;
  line-height: 1.25;
  color: var(--ak-ink-muted);
}
.cap-time {
  font-family: var(--ak-font-display, system-ui);
  font-weight: var(--ak-title-weight, 400);
  font-size: 16px;
  line-height: 1.2;
  color: var(--ak-ink);
}
.cap-stall {
  display: block;
  font-size: 12px;
  color: var(--ak-ink-muted);
}
.cap-marks {
  display: flex;
  flex-wrap: wrap;
  gap: 1px 7px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ak-ink);
}

.pair.is-served { opacity: 0; transform: translate(-50%, calc(var(--pos) * var(--r) - 8px)); }
.pair.is-hop { opacity: 0; transform: translate(calc(-50% + 14px), calc(var(--pos) * var(--r))); }

/* ---------- desk ---------- */

.label {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
}

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
}
.legend li { display: flex; align-items: center; gap: 3px; }
.legend .load { flex: none; }
.legend .label { color: var(--ak-ink); letter-spacing: 0.1em; }
.legend small { display: block; font-size: 12px; color: var(--ak-ink-muted); letter-spacing: 0; }
.legend small b { font-weight: 600; }
.legend small i { font-style: normal; }

.say {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 92px;
}
.twist {
  margin: 0;
  padding: 7px 10px 8px;
  border: var(--line) dashed var(--ak-ink);
  border-radius: 2px;
  font-size: 14px;
  line-height: 1.35;
}
.twist .label { display: block; margin-bottom: 1px; }
.prompt { margin: 0; font-size: 17px; line-height: 1.4; }
.prompt.invite {
  position: relative;
  margin-top: 8px;
  padding: 9px 14px 11px;
  background: var(--ak-surface);
  border: var(--line) solid var(--ak-ink);
  border-radius: 16px 16px 16px 3px;
  font-size: 18px;
}
.prompt.invite::before,
.prompt.invite::after {
  content: '';
  position: absolute;
  left: 26px;
  border-style: solid;
  border-width: 0 9px 11px;
  border-color: transparent transparent var(--ak-ink);
}
.prompt.invite::before { top: -11px; }
.prompt.invite::after {
  top: -8.5px;
  border-bottom-color: var(--ak-surface);
}
.prompt.invite .label { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.prompt.invite .label svg { flex: none; width: 20px; height: 20px; }
.prompt.invite .label svg path {
  fill: none;
  stroke: var(--ak-ink);
  stroke-width: var(--line);
  stroke-linecap: round;
  stroke-linejoin: round;
}
.prompt.warn { font-weight: 600; }
.verdict { margin: 0; font-size: 18px; line-height: 1.3; font-weight: 600; }
.facts { margin: 0; display: grid; grid-template-columns: 7.2em minmax(0, 1fr); gap: 3px 10px; align-items: baseline; }
.facts dt { margin: 0; }
.facts dd { margin: 0; font-size: 14px; line-height: 1.3; }
.facts dd b { font-weight: 700; }
.facts-note { margin: 0; font-size: 13px; color: var(--ak-ink-muted); }

.clock { display: flex; align-items: center; gap: 12px; }
.sw { position: relative; flex: none; width: 52px; height: 57px; }
.sw img { display: block; width: 100%; height: 100%; }
.sw-patch {
  position: absolute;
  left: 50%;
  top: 56%;
  width: 68%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #F0EAC8;
}
.sw-hand {
  position: absolute;
  left: 50%;
  top: 56%;
  width: 68%;
  aspect-ratio: 1;
  margin: 0;
  transform: translate(-50%, -50%) rotate(var(--hand, 0deg));
  overflow: visible;
}
.clock-read { font-family: var(--ak-font-display, system-ui); font-size: 24px; line-height: 1.1; }
.clock-read small { font-family: var(--ak-font-body, system-ui); font-size: 14px; color: var(--ak-ink-muted); margin-left: 4px; }

.actions { display: flex; gap: 10px; }
.actions[hidden] { display: none; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 20px;
  background: transparent;
  border: var(--line) solid var(--ak-accent);
  border-radius: var(--ak-radius, 4px);
  color: var(--ak-ink);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn svg path { fill: none; stroke: var(--ak-accent); stroke-width: var(--line); stroke-linecap: round; stroke-linejoin: round; }
.btn.is-quiet {
  border-color: var(--ak-ink-muted);
  color: var(--ak-ink-muted);
}
.btn.is-quiet svg path { stroke: var(--ak-ink-muted); }
.btn.big { min-height: 60px; font-size: 15px; width: 100%; }
#go { flex: 1 1 auto; }

.ledger { display: flex; flex-direction: column; gap: 4px; }
.ledger-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.ledger-total { font-size: 12px; color: var(--ak-ink-muted); }
.ledger-total b { color: var(--ak-ink); font-weight: 700; }
.ledger-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px 14px;
}
.ledger-list li {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-height: 20px;
  font-size: 12px;
  border-bottom: 1px solid color-mix(in srgb, var(--ak-ink) 12%, transparent);
  color: var(--ak-ink-muted);
}
.ledger-list li.is-now { color: var(--ak-ink); border-bottom-color: var(--ak-ink); }
.ledger-list .n { flex: none; width: 1.2em; font-weight: 700; color: var(--ak-ink); }
.ledger-list .m { flex: none; min-width: 3.4em; color: var(--ak-ink); font-weight: 600; }
.ledger-list .t { min-width: 0; }

.desk.is-teaching .legend,
.desk.is-teaching .say,
.desk.is-teaching .actions,
.desk.is-teaching .ledger,
.desk.is-ending .legend,
.desk.is-ending .say,
.desk.is-ending .actions,
.desk.is-ending .ledger,
.desk.is-reading .legend { display: none; }

/* ---------- teaching ---------- */

.teach {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 14px 14px;
  background: var(--ak-surface);
  border: var(--line) solid var(--ak-ink);
  border-radius: var(--ak-radius, 4px);
  color: var(--ak-ink);
}
.teach[hidden], .finale[hidden] { display: none; }
.teach .sum { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; font-size: 24px; line-height: 1; }
.teach .sum b { font-family: var(--ak-font-display, system-ui); font-weight: var(--ak-title-weight, 400); }
.teach .sum small { font-size: 18px; color: var(--ak-ink-muted); }
.teach-say { margin: 0; font-size: 18px; line-height: 1.4; }

/* ---------- ending ---------- */

.finale { display: flex; flex-direction: column; gap: 14px; }
.finale .reason { margin: 0; font-size: 14px; color: var(--ak-ink-muted); }
.finale .reason b { color: var(--ak-ink); font-weight: 600; }
.finale .sentence { margin: 0; font-size: 22px; line-height: 1.3; font-weight: 400; }
.finale .facts dd { font-size: 14px; }
.finale .buttons { display: flex; flex-wrap: wrap; gap: 10px; }
.finale .buttons .btn { flex: 1 1 140px; padding: 0 12px; letter-spacing: 0.12em; }

.stage.is-ending .pair,
.stage.is-ending .cap { opacity: 0; }
.stage.is-ending .lane { cursor: default; }
.stage.is-ending .lane.is-pick { outline-color: transparent; }

/* ---------- motion ---------- */

@media (prefers-reduced-motion: no-preference) {
  .pair { transition: transform 0.7s ease, opacity 0.6s ease; }
  .lane-art { transition: filter 0.8s ease; }
  .lane-body, .cap { transition: opacity 0.9s ease; }
  .lane.is-invite.can-tap .lane-art { animation: breathe 3.6s ease-in-out infinite; }
  .stage.is-ending .pair, .stage.is-ending .cap { transition: opacity 1.8s ease; }
  .stage.is-ending .lane.is-pick { transition: outline-color 1.8s ease; }
  .say > *, .finale > * { animation: settle 0.6s ease both; }
  .finale > :nth-child(2) { animation-delay: 0.5s; }
  .finale > :nth-child(3) { animation-delay: 1.1s; }
  .finale > :nth-child(4) { animation-delay: 1.5s; }
  .sw-hand { transition: transform 0.07s linear; }
  .load.wobble { animation: wobble 0.95s ease-in-out both; transform-origin: 50% 85%; }
}
@keyframes wobble {
  0% { transform: none; }
  18% { transform: translateY(-4px) rotate(-7deg); }
  42% { transform: translateY(0) rotate(6deg); }
  64% { transform: translateY(-1.5px) rotate(-3deg); }
  82% { transform: rotate(1.5deg); }
  100% { transform: none; }
}
@keyframes breathe {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
@keyframes settle {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@media (max-height: 760px) and (orientation: portrait) {
  :root {
    --cap-h: 92px;
    --r-h: calc((100dvh - var(--sat) - var(--sab) - 462px) / 5.2);
  }
  .stage { gap: 4px; padding-top: calc(var(--sat) + 6px); }
  .mast { height: 44px; margin-bottom: 6px; }
  .mast-logo { height: 28px; }
  .desk { gap: 6px; padding-top: 8px; }
  .ledger-list li { min-height: 18px; }
  .say { min-height: 0; gap: 6px; }
  .prompt, .prompt.invite { font-size: 16px; }
  .prompt.invite { font-size: 17px; }
  .twist { font-size: 13px; }
}

@media (orientation: landscape) and (max-height: 420px) {
  :root {
    --cap-h: 96px;
    --r: max(48px, min(var(--r-w), var(--r-h), 72px));
  }
  .stage { column-gap: 18px; }
  .mast { height: 40px; }
  .mast-logo { height: 28px; }
  .desk { gap: 7px; }
  .ledger { gap: 2px; }
  .ledger-list li { min-height: 18px; }
  .say { min-height: 0; gap: 6px; }
  .verdict { font-size: 16px; }
  .facts dd { font-size: 13px; }
  .prompt.invite { font-size: 17px; }
}

@media (orientation: landscape) and (max-height: 420px) and (max-width: 760px) {
  .stage { padding-left: calc(var(--pad) + var(--sal) + 52px); column-gap: 12px; }
  .legend { flex-wrap: nowrap; gap: 0 10px; }
  .legend .label, .legend small i { display: none; }
  .legend small b { font-size: 20px; color: var(--ak-ink); font-weight: 700; }
  .prompt.invite { font-size: 15px; }
  .prompt { font-size: 15px; }
  .btn { min-height: 48px; }
  .ledger-list li { min-height: 18px; }
}

@media (max-height: 700px) and (orientation: portrait) {
  :root { --r: max(48px, min(var(--r-w), var(--r-h), 72px)); }
  .prompt, .prompt.invite { font-size: 15px; line-height: 1.35; }
  .ledger-list { grid-template-columns: repeat(3, 1fr); }
  .ledger-list .t { display: none; }
}

@media (max-height: 700px) and (orientation: portrait) {
  .stage { padding-bottom: 2px; }
  .desk { gap: 4px; padding-top: 6px; }
  .say { gap: 4px; }
  .ledger { gap: 2px; }
}
@media (orientation: landscape) and (max-height: 420px) and (max-width: 760px) {
  .ledger-list { grid-template-columns: repeat(3, 1fr); }
  .ledger-list .t { display: none; }
  .desk { gap: 5px; }
}

@media (max-height: 700px) and (orientation: portrait) {
  .verdict { font-size: 16px; line-height: 1.25; }
  .facts { grid-template-columns: 6.4em minmax(0, 1fr); gap: 2px 8px; }
  .facts dd { font-size: 13px; line-height: 1.25; }
  .facts-note { font-size: 12px; }
  .btn { min-height: 48px; }
  .ledger-head { display: none; }
}

/* Very short phones: the clerk keeps a name plate but loses the face and the tag line. */
@media (max-height: 700px) and (orientation: portrait) {
  :root { --cap-h: 78px; }
  .cap-face, .cap-tag { display: none; }
  .prompt.invite { margin-top: 6px; padding: 7px 10px 8px; }
}

/* Help: a small navy pennant hung from the top edge, edged in gold like the valance. */
html #activity-help {
  top: max(0px, var(--sat));
  right: max(10px, var(--sar));
  width: 48px;
  height: 56px;
  padding: 0 0 10px;
  border: 0;
  border-top: 5px solid var(--ak-accent-2);
  border-radius: 0;
  background: var(--ak-ink);
  color: var(--ak-btn-ink);
  box-shadow: none;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%);
  font-size: 22px;
}
html #activity-help:active,
html #activity-help:hover,
html #activity-help:focus-visible { background: var(--ak-ink-muted); outline: none; }
html #activity-help:focus-visible { border-top-color: var(--ak-focus); border-top-width: 8px; }

/* The start screen is start.js's; here it is only dressed as a ticket in front of the tent. */
html #activity-start.has-backdrop::before {
  background-image:
    linear-gradient(color-mix(in srgb, var(--ak-bg) 28%, transparent), color-mix(in srgb, var(--ak-bg) 28%, transparent)),
    url("art/hush-tent.jpg");
}
html #activity-start.layout-panel .ak-sheet {
  border: 0;
  border-radius: 6px;
  box-shadow: inset 0 0 0 1.5px var(--ak-ink);
  outline: 1.5px dashed var(--ak-ink-muted);
  outline-offset: -10px;
  -webkit-mask:
    radial-gradient(circle 14px at 0 50%, #0000 97%, #000) left / 51% 100% no-repeat,
    radial-gradient(circle 14px at 100% 50%, #0000 97%, #000) right / 51% 100% no-repeat;
  mask:
    radial-gradient(circle 14px at 0 50%, #0000 97%, #000) left / 51% 100% no-repeat,
    radial-gradient(circle 14px at 100% 50%, #0000 97%, #000) right / 51% 100% no-repeat;
}

/* Compact phones: a shorter pennant lets the lanes start higher; the speech bubble tightens. */
@media (max-height: 760px) and (orientation: portrait) {
  :root { --cap-h: 90px; }
  .stage { padding-top: calc(var(--sat) + 4px); }
  .mast { height: 40px; margin-bottom: 4px; }
  .desk { gap: 5px; }
  html #activity-help { height: 50px; padding-bottom: 8px; }
  .prompt.invite { margin-top: 6px; padding: 6px 10px 8px; font-size: 16px; line-height: 1.3; }
  .prompt.invite .label { margin-bottom: 1px; }
  .prompt.invite::before { top: -10px; }
  .prompt.invite::after { top: -7.5px; }
}
@media (max-height: 700px) and (orientation: portrait) {
  .mast { height: 36px; }
  .mast-logo { height: 26px; }
  html #activity-help { height: 46px; padding-bottom: 6px; }
  .prompt.invite { font-size: 15px; }
}
@media (max-height: 700px) and (orientation: portrait) {
  :root { --cap-h: 68px; }
}
