/* SQUEEK PACK.

   The room is a workshop bench, not a dashboard. Paper is a chalk green, ink is
   green-black, and there is one accent: machine green, spent only on the work
   that has actually been packed and on the one button that commits it.

   Motif: the measuring rule and the stamp. The round is a steel rule with ten
   marks, one per thousand work units. Every number on the page sits under a
   thin rule, never in a floating card. */

:root {
  --bg: #e9ece2;
  --raised: #dfe3d7;
  --plate: #f2f4ec;
  --ink: #191c17;
  --line: #ccd2c2;
  --rule-line: #b9c1ad;
  --dim: #565c50;
  --faint: #5d6456;
  --accent: #1c6b45;
  --accent-lit: #227a4f;
  --pad: #d8e8bd;
  --gold: #6f5209;
  --red: #a3301f;
  --live-bg: #dfeede;
  --ghost-bg: #f2ecd7;
  --offline-bg: #f4e4df;
  --hatch: rgba(28, 107, 69, 0.16);
  --shadow: 0 1px 0 rgba(25, 28, 23, 0.06);
  --display: "Big Shoulders Display", "Arial Narrow", sans-serif;
  --data: "JetBrains Mono", ui-monospace, monospace;
  --voice: "Work Sans", system-ui, sans-serif;
}

/* Night shift. Same bench after dark: the paper goes blue-black, the accent goes
   lighter so it still clears AA on the dark plate. */
:root[data-theme="dark"] {
  --bg: #131713;
  --raised: #1d221c;
  --plate: #191e18;
  --ink: #eef0e8;
  --line: #2b322a;
  --rule-line: #3a4238;
  --dim: #a5ada0;
  --faint: #949d90;
  --accent: #86dc9e;
  --accent-lit: #9ce8b2;
  --pad: #26301c;
  --gold: #e6c76a;
  --red: #ff9d8c;
  --live-bg: #162a1c;
  --ghost-bg: #2c2712;
  --offline-bg: #301a16;
  --hatch: rgba(134, 220, 158, 0.18);
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--data);
  -webkit-text-size-adjust: 100%;
}

body {
  overscroll-behavior: none;
  touch-action: manipulation;
  overflow-x: hidden;
}

button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.stage {
  min-height: 100dvh;
  max-width: 1080px;
  margin: 0 auto;
  padding: clamp(8px, 2vh, 20px) clamp(12px, 3.2vw, 30px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(6px, 1.4vh, 14px);
}

/* ---------- head ---------- */

.hud {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px 16px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  padding-bottom: clamp(5px, 1vh, 10px);
}

.hud__left { min-width: 0; }

.wordmark {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(20px, 3.6vw, 30px);
  line-height: 0.92;
  letter-spacing: 0.01em;
}

.wordmark span {
  color: var(--accent);
}

.tagline {
  margin: 2px 0 0;
  font-family: var(--voice);
  font-size: clamp(10px, 1.4vw, 12px);
  color: var(--dim);
}

.hud__right {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.chip {
  font-size: 9px;
  letter-spacing: 0.14em;
  padding: 4px 7px;
  border: 1px solid var(--line);
  color: var(--dim);
  white-space: nowrap;
}

.chip[data-mode="live"] { background: var(--live-bg); border-color: var(--accent); color: var(--accent); }
.chip[data-mode="ghost"] { background: var(--ghost-bg); border-color: var(--gold); color: var(--gold); }
.chip[data-mode="offline"] { background: var(--offline-bg); border-color: var(--red); color: var(--red); }
.chip--holder { border-color: var(--accent); color: var(--accent); }

.ghostbtn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--dim);
  font-size: 9px;
  letter-spacing: 0.13em;
  padding: 5px 8px;
  min-height: 30px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.ghostbtn:hover { color: var(--ink); border-color: var(--ink); }
.ghostbtn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
.ghostbtn--wide { min-height: 44px; padding: 0 16px; font-size: 10px; }
.ghostbtn--quiet { border-style: dashed; }
.ghostbtn:disabled { cursor: not-allowed; opacity: 0.5; }

/* A phone has no space bar. Showing one is a promise the device cannot keep. */
@media (hover: none) and (pointer: coarse) {
  kbd { display: none; }
}

kbd {
  font-family: var(--data);
  font-size: 8px;
  letter-spacing: 0.06em;
  border: 1px solid currentColor;
  padding: 1px 3px;
  margin-left: 6px;
  opacity: 0.7;
}

/* ---------- board ---------- */

.board {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(8px, 1.6vh, 18px);
  min-height: 0;
}

.k {
  font-size: 9px;
  letter-spacing: 0.16em;
  color: var(--faint);
}

/* the rule: the round's capacity, measured */

.rule__head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.rule__cell { display: flex; align-items: baseline; gap: 6px; }
.rule__cell--right { margin-left: auto; }

.rule__cell .v {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(15px, 2.4vw, 20px);
  letter-spacing: 0.02em;
}

.rule__track {
  position: relative;
  height: clamp(34px, 7vh, 56px);
  border: 1px solid var(--rule-line);
  background: var(--raised);
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

:root[data-theme="dark"] .rule__track { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04); }

.rule__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background:
    repeating-linear-gradient(90deg, var(--hatch) 0 1px, transparent 1px 7px),
    var(--accent);
  transition: width 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

/* the burst you are about to take, shown as a pale extension of the fill so the
   decision is made with the eye as well as the arithmetic */
.rule__ghost {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--pad);
  border-left: 1px dashed var(--accent);
  transition: width 0.12s linear, left 0.12s linear;
}

.rule__marks {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(90deg, var(--rule-line) 0 1px, transparent 1px 10%);
  opacity: 0.85;
}

.rule__foot {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 5px;
  font-size: 9px;
  letter-spacing: 0.1em;
  color: var(--faint);
  text-transform: uppercase;
}

.rule__scale { font-variant-numeric: tabular-nums; }

/* the chute: one burst, and the time it is still here */

/* The chute takes the height the viewport has left over and centres its number
   in it, so a tall screen has one focal point instead of a void between the rule
   and the readout. */
.chute {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 1px solid var(--line);
  background: var(--plate);
  padding: clamp(8px, 1.8vh, 16px) clamp(12px, 2.4vw, 20px) clamp(10px, 2vh, 18px);
  text-align: center;
  box-shadow: var(--shadow);
  min-height: clamp(126px, 24vh, 214px);
}

.chute__label { margin: 0; display: flex; justify-content: center; gap: 6px; align-items: baseline; }
.chute__label b { font-size: 10px; letter-spacing: 0.1em; color: var(--dim); }

.chute__value {
  margin: 2px 0 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(38px, 11vh, 76px);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.chute__unit {
  margin: 4px 0 0;
  font-size: 9px;
  letter-spacing: 0.2em;
  color: var(--faint);
}

.chute__timer {
  height: 2px;
  margin: 8px auto 0;
  max-width: 320px;
  background: var(--line);
}

.chute__timer i {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform-origin: left center;
}

.chute__hint,
.chute__next {
  margin: 7px 0 0;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--dim);
  min-height: 14px;
}

.chute__next { color: var(--accent); }

.chute[data-fit="over"] .chute__value { color: var(--red); }
.chute[data-fit="over"] .chute__hint { color: var(--red); }

/* acts */

.acts {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.primary {
  appearance: none;
  flex: 1 1 180px;
  min-height: 46px;
  border: 1px solid var(--accent);
  background: var(--accent);
  /* white, not paper: paper on machine green lands at 4.43, just under AA */
  color: #f7faf4;
  font-size: 11px;
  letter-spacing: 0.16em;
  cursor: pointer;
  transition: background 0.14s ease, transform 0.08s ease;
}

:root[data-theme="dark"] .primary { color: #10240f; }

.primary:hover { background: var(--accent-lit); border-color: var(--accent-lit); }
.primary:active { transform: translateY(1px); }
.primary[data-fit="over"] { background: transparent; color: var(--red); border-color: var(--red); }
.primary:disabled { cursor: not-allowed; opacity: 0.55; }

.acts .ghostbtn { flex: 0 1 auto; }

/* flash line: one line, one state, never a toast stack */

.flash {
  margin: 0;
  min-height: 15px;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
  text-align: center;
}

.flash[data-tone="good"] { color: var(--accent); }
.flash[data-tone="bad"] { color: var(--red); }
.flash[data-tone="gold"] { color: var(--gold); }

/* the settle: what the round was worth */

.settle {
  border: 1px solid var(--accent);
  background: var(--plate);
  padding: clamp(10px, 2vh, 16px) clamp(12px, 2.4vw, 20px);
}

.settle__bar { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }

.settle__title {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(18px, 3.2vw, 26px);
  letter-spacing: 0.02em;
}

.settle__sub { margin: 0; font-size: 10px; letter-spacing: 0.1em; color: var(--dim); }

.settle__grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0 12px;
}

.settle__grid div { border-top: 1px solid var(--line); padding-top: 5px; min-width: 0; }
.settle__grid dt { font-size: 8px; letter-spacing: 0.14em; color: var(--faint); text-transform: uppercase; }
.settle__grid dd {
  margin: 3px 0 0;
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(14px, 2.4vw, 19px);
  overflow-wrap: anywhere;
}

/* readout strip: four numbers under thin rules, never cards */

.readout {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px 14px;
  margin: 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.readout__cell { min-width: 0; border-top: 1px solid var(--line); padding-top: 5px; }
.readout dt { margin: 0; }
.readout dd {
  margin: 3px 0 0;
  font-size: clamp(11px, 1.8vw, 14px);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.readout dd.v--big {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(22px, 4.4vw, 34px);
  line-height: 1;
  color: var(--accent);
}

.readout dd[data-round="seeded"] { color: var(--accent); }

/* ---------- foot ---------- */

.foot {
  display: flex;
  align-items: center;
  gap: 8px 14px;
  flex-wrap: wrap;
  border-top: 1px solid var(--line);
  padding-top: clamp(5px, 1vh, 10px);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--faint);
}

.foot p { margin: 0; }

.foot__right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-left: auto;
}

/* The maker's mark: a screenshot of the arcade carries where it came from, and
   it is a link so the claim can be checked rather than taken on trust. */
.foot__mark {
  font-family: var(--data);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  border: 1px solid var(--line);
  padding: 4px 8px;
  text-decoration: none;
  white-space: nowrap;
  margin-left: auto;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.foot__mark:hover,
.foot__mark:focus-visible { color: var(--ink); border-color: var(--ink); }

/* ---------- state machine ---------- */

.board[data-state="idle"] .readout dd.v--big { color: var(--faint); }
.board[data-state="play"] .settle { display: none; }

/* Once a round is settled the chute is history: it stays in place so the eye
   does not lose the board, but it steps back and its clock stops. */
.board[data-state="settle"] .chute { opacity: 0.5; }
.board[data-state="settle"] .chute__timer { visibility: hidden; }

/* A clock that is not counting is a lie: the bar only exists while a burst does. */
.board[data-state="idle"] .chute__timer,
.board[data-state="over"] .chute__timer { visibility: hidden; }

/* ---------- sheets ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: clamp(10px, 3vw, 28px);
  background: color-mix(in srgb, var(--ink) 58%, transparent);
}

.sheet[hidden] { display: none; }

.sheet__card {
  width: min(560px, 100%);
  max-height: min(88dvh, 760px);
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--line);
  padding: clamp(14px, 2.4vw, 24px);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

.sheet__card--wide { width: min(720px, 100%); }

.sheet__bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  margin-bottom: 12px;
}

.sheet__bar h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(20px, 3.4vw, 28px);
  letter-spacing: 0.02em;
}

.sheet__close {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--dim);
  width: 30px;
  height: 30px;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  flex: none;
}

.sheet__close:hover { color: var(--ink); border-color: var(--ink); }

.sheet__lead {
  margin: 0 0 12px;
  font-family: var(--voice);
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink);
}

.sheet__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px;
  margin: 0 0 12px;
}

.sheet__grid div { border-top: 1px solid var(--line); padding-top: 5px; min-width: 0; }
.sheet__grid dt { font-size: 8px; letter-spacing: 0.14em; color: var(--faint); text-transform: uppercase; }
.sheet__grid dd {
  margin: 3px 0 0;
  font-size: clamp(12px, 1.8vw, 14px);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.sheet__line {
  margin: 0 0 12px;
  font-family: var(--voice);
  font-size: 12px;
  line-height: 1.5;
  color: var(--dim);
}

.sheet__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sheet__actions .primary { flex: 1 1 160px; }

.sheet__note {
  margin: 12px 0 0;
  font-family: var(--voice);
  font-size: 11px;
  line-height: 1.55;
  color: var(--dim);
}

.sheet__note code { font-family: var(--data); font-size: 10px; color: var(--ink); }

.steps {
  margin: 0 0 12px;
  padding-left: 18px;
  font-family: var(--voice);
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink);
}

.steps li { margin-bottom: 7px; }
.steps strong { font-weight: 600; }

.fields {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 10px;
  font-size: 10px;
}

.fields caption {
  text-align: left;
  font-size: 8px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  padding-bottom: 5px;
}

.fields td {
  border-top: 1px solid var(--line);
  padding: 5px 8px 5px 0;
  vertical-align: top;
  line-height: 1.45;
  color: var(--dim);
}

.fields td:first-child { white-space: nowrap; color: var(--ink); }
.fields code { font-family: var(--data); font-size: 10px; }

.holdbox { margin-bottom: 12px; }
.holdbox .k { display: block; margin-bottom: 5px; }

.ghostbox__row { display: flex; gap: 6px; flex-wrap: wrap; }

.ghostbox__input {
  flex: 1 1 160px;
  min-height: 36px;
  padding: 0 10px;
  background: var(--plate);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: var(--data);
  font-size: 12px;
}

.ghostbox__input::placeholder { color: var(--faint); }

.holdbox__status {
  margin: 8px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--dim);
}

.holdbox__status[data-tone="good"] { color: var(--accent); }
.holdbox__status[data-tone="bad"] { color: var(--red); }

/* ---------- small screens ---------- */

@media (max-width: 720px) {
  .tagline { display: none; }
  .hud__right { width: 100%; justify-content: flex-start; }
  .readout { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settle__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* A phone in portrait is the screen this game is actually played on, so it gets
   its own type scale rather than a squeezed desktop one. */
@media (max-width: 400px) {
  .stage { padding: 6px 10px; gap: 5px; }
  .hud { gap: 4px 8px; padding-bottom: 4px; }
  .wordmark { font-size: 19px; }
  .hud__right { gap: 4px; }
  .ghostbtn { font-size: 8px; letter-spacing: 0.07em; padding: 4px 6px; min-height: 26px; }
  .chip { font-size: 8px; padding: 3px 5px; letter-spacing: 0.1em; }
  .board { gap: 6px; }
  .rule__head { gap: 8px; margin-bottom: 4px; }
  .rule__cell .v { font-size: 14px; }
  .rule__track { height: 26px; }
  .rule__scale { display: none; }
  .rule__foot { font-size: 8px; }
  .chute { min-height: 96px; padding: 6px 10px 8px; }
  .chute__value { font-size: 40px; }
  .chute__hint, .chute__next { font-size: 9px; margin-top: 4px; }
  .chute__unit { font-size: 8px; }
  .primary { min-height: 42px; font-size: 10px; flex: 1 1 auto; }
  .ghostbtn--wide { min-height: 40px; font-size: 9px; padding: 0 12px; }
  .readout { gap: 5px 10px; padding-top: 5px; }
  .readout dd { font-size: 10px; }
  .readout dd.v--big { font-size: 20px; }
  .foot { font-size: 8px; gap: 4px 8px; }
  .foot__note { display: none; }
  .foot__mark { font-size: 9px; padding: 3px 6px; }
}

@media (max-height: 620px) {
  .stage { padding-top: 6px; padding-bottom: 6px; gap: 5px; }
  .board { gap: 6px; }
  .chute { min-height: 96px; }
  .chute__value { font-size: clamp(30px, 8.5vh, 46px); }
  .chute__timer { margin-top: 5px; }
  .chute__hint, .chute__next { margin-top: 4px; }
  .rule__track { height: 30px; }
  .tagline { display: none; }
  .foot { padding-top: 3px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
