/* ScoreKeeper — pinball backglass, shrunk to a phone.
   Dark is the default because this thing lives on a table at night. */

:root {
  --void: #0a0713;
  --cabinet: #14102a;
  --rail: #1e1840;
  --edge: #2c2456;
  --ink: #f4f0ff;
  --dim: #8c85b8;
  --faint: #5d5788;

  --cyan: #22e7ff;
  --magenta: #ff2e93;
  --lime: #c6ff3d;
  --gold: #ffc53d;
  --danger: #ff5c4d;

  --accent: var(--cyan);
  --shadow: 0 18px 40px -22px rgba(0, 0, 0, 0.9);
  --r: 14px;
  --dock-h: 68px;

  --display: 'Chakra Petch', ui-sans-serif, system-ui, sans-serif;
  --body: 'Inter Tight', ui-sans-serif, system-ui, -apple-system, sans-serif;

  color-scheme: dark;
}

[data-theme='light'] {
  --void: #f1eefb;
  --cabinet: #ffffff;
  --rail: #e6e1f7;
  --edge: #cfc7ec;
  --ink: #150f2c;
  --dim: #5b5484;
  --faint: #8f88b5;

  --cyan: #0090ad;
  --magenta: #d1006a;
  --lime: #5f8a00;
  --gold: #a97400;
  --danger: #cc3527;

  --shadow: 0 14px 30px -20px rgba(21, 15, 44, 0.5);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

/* Player colours are baked into the saved session as neons tuned for the dark
   cabinet. Everything reads them through --seat so light mode can darken the
   whole set in one place instead of per-component. */
.player-row,
.pcard,
.log-row,
.step-block {
  --seat: var(--seat-raw, var(--cyan));
}

[data-theme='light'] .player-row,
[data-theme='light'] .pcard,
[data-theme='light'] .log-row,
[data-theme='light'] .step-block {
  --seat: color-mix(in srgb, var(--seat-raw, var(--cyan)) 72%, #1a0f38);
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--void);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
}

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Small caps utility label — the page's structural voice. */
.tag {
  font-family: var(--display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--faint);
}

/* ------------------------------------------------------------------ *
 * Screens
 * ------------------------------------------------------------------ */

.screen {
  display: none;
  min-height: 100dvh;
  flex-direction: column;
}

.screen.is-active {
  display: flex;
}

/* ------------------------------------------------------------------ *
 * Setup
 * ------------------------------------------------------------------ */

.setup {
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  padding: 28px 18px 40px;
}

.setup-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 26px;
}

.wordmark {
  font-family: var(--display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: -0.01em;
  line-height: 1;
  margin: 0;
  text-transform: uppercase;
}

.wordmark em {
  font-style: normal;
  color: var(--cyan);
}

.setup-sub {
  margin: 6px 0 0;
  color: var(--dim);
  font-size: 14px;
}

.setup-block {
  margin-bottom: 26px;
}

.setup-block > .tag {
  display: block;
  margin-bottom: 10px;
}

.player-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--cabinet);
  border: 1px solid var(--edge);
  border-radius: var(--r);
  padding: 6px 6px 6px 0;
  overflow: hidden;
}

.player-row .spine {
  width: 6px;
  align-self: stretch;
  border-radius: 0 3px 3px 0;
  background: var(--seat, var(--cyan));
  flex: none;
}

.player-row .seat-no {
  font-family: var(--display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--seat, var(--cyan));
  width: 22px;
  flex: none;
}

.player-row input {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  padding: 12px 0;
  font-size: 16px;
  font-weight: 500;
}

.player-row input::placeholder {
  color: var(--faint);
}

.icon-btn {
  width: 40px;
  height: 40px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: var(--dim);
  transition: background 0.18s, color 0.18s, transform 0.18s;
}

.icon-btn:hover {
  background: var(--rail);
  color: var(--ink);
}

.icon-btn:active {
  transform: scale(0.9);
}

.add-player {
  margin-top: 10px;
  width: 100%;
  padding: 13px;
  border: 1px dashed var(--edge);
  border-radius: var(--r);
  color: var(--dim);
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 13px;
  transition: border-color 0.18s, color 0.18s;
}

.add-player:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}

/* Segmented control */
.segments {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: var(--cabinet);
  border: 1px solid var(--edge);
  border-radius: var(--r);
  padding: 6px;
}

.segment {
  padding: 12px 6px;
  border-radius: 9px;
  text-align: center;
  font-family: var(--display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--dim);
  transition: background 0.2s, color 0.2s;
}

.segment small {
  display: block;
  font-family: var(--body);
  font-size: 11px;
  letter-spacing: 0;
  font-weight: 400;
  opacity: 0.75;
  margin-top: 2px;
}

.segment[aria-pressed='true'] {
  background: var(--rail);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--cyan), 0 0 18px -6px var(--cyan);
}

.field {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--cabinet);
  border: 1px solid var(--edge);
  border-radius: var(--r);
  padding: 4px 14px;
}

.field label {
  color: var(--dim);
  font-size: 14px;
  white-space: nowrap;
}

.field input {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  padding: 13px 0;
  text-align: right;
  font-family: var(--display);
  font-weight: 700;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.quick-editor {
  display: flex;
  gap: 8px;
}

.quick-editor input {
  flex: 1;
  min-width: 0;
  background: var(--cabinet);
  border: 1px solid var(--edge);
  border-radius: var(--r);
  padding: 13px 10px;
  text-align: center;
  font-family: var(--display);
  font-weight: 700;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.hint {
  margin: 8px 0 0;
  color: var(--faint);
  font-size: 12.5px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--cabinet);
  border: 1px solid var(--edge);
  border-radius: var(--r);
  padding: 14px;
}

.toggle-row .toggle-copy {
  font-size: 14px;
}

.toggle-row .toggle-copy small {
  display: block;
  color: var(--faint);
  font-size: 12px;
}

.switch {
  width: 50px;
  height: 30px;
  flex: none;
  border-radius: 999px;
  background: var(--rail);
  border: 1px solid var(--edge);
  position: relative;
  transition: background 0.22s;
}

.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--dim);
  transition: transform 0.26s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.22s;
}

.switch[aria-checked='true'] {
  background: color-mix(in srgb, var(--cyan) 28%, var(--rail));
}

.switch[aria-checked='true']::after {
  transform: translateX(20px);
  background: var(--cyan);
}

.primary-btn {
  width: 100%;
  padding: 18px;
  border-radius: var(--r);
  background: var(--cyan);
  color: #06121a;
  font-family: var(--display);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  box-shadow: 0 0 34px -8px var(--cyan);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s;
}

[data-theme='light'] .primary-btn {
  color: #fff;
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 44px -6px var(--cyan);
}

.primary-btn:active {
  transform: scale(0.985);
}

.primary-btn[disabled] {
  opacity: 0.4;
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

.ghost-btn {
  width: 100%;
  padding: 15px;
  border-radius: var(--r);
  border: 1px solid var(--edge);
  color: var(--dim);
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 13px;
  transition: border-color 0.18s, color 0.18s;
}

.ghost-btn:hover {
  border-color: var(--dim);
  color: var(--ink);
}

.resume-card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--cabinet);
  border: 1px solid var(--cyan);
  border-radius: var(--r);
  padding: 16px;
  margin-bottom: 22px;
  box-shadow: 0 0 30px -14px var(--cyan);
}

.resume-card strong {
  display: block;
  font-family: var(--display);
  font-size: 16px;
  margin-bottom: 2px;
}

.resume-card span {
  color: var(--dim);
  font-size: 13px;
}

/* ------------------------------------------------------------------ *
 * Board — top rail
 * ------------------------------------------------------------------ */

.rail {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--void) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--edge);
}

.clock {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--edge);
  background: var(--cabinet);
  font-family: var(--display);
  font-weight: 700;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.2s, color 0.2s;
}

.clock .tag {
  font-size: 9px;
  letter-spacing: 0.14em;
}

.clock.is-running {
  border-color: color-mix(in srgb, var(--lime) 55%, var(--edge));
  color: var(--lime);
}

.clock.is-running .tag {
  color: color-mix(in srgb, var(--lime) 70%, var(--dim));
}

.rail-spacer {
  flex: 1;
}

.target-flag {
  display: none;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 11px 14px;
  background: color-mix(in srgb, var(--gold) 14%, var(--cabinet));
  border-bottom: 1px solid color-mix(in srgb, var(--gold) 40%, transparent);
  color: var(--gold);
  font-family: var(--display);
  font-weight: 600;
  font-size: 13.5px;
  position: sticky;
  top: 57px;
  z-index: 19;
}

.target-flag.is-on {
  display: flex;
  animation: flag-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes flag-in {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }
}

/* ------------------------------------------------------------------ *
 * Board — player cards
 * ------------------------------------------------------------------ */

.board {
  flex: 1;
  display: grid;
  gap: 10px;
  padding: 12px 12px calc(var(--dock-h) + 24px);
  align-content: start;
}

.pcard {
  position: relative;
  background: var(--cabinet);
  border: 1px solid var(--edge);
  border-radius: var(--r);
  padding: 12px 12px 12px 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.pcard::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  background: var(--seat);
}

/* The leader's tube is lit — and it buzzes, like a real one. */
.pcard.is-leader {
  border-color: color-mix(in srgb, var(--seat) 60%, var(--edge));
}

.pcard.is-leader::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--r);
  pointer-events: none;
  box-shadow: inset 0 0 0 1px var(--seat), 0 0 26px -8px var(--seat);
  animation: tube-buzz 5.5s infinite steps(1, end);
}

@keyframes tube-buzz {
  0%,
  40%,
  44%,
  70%,
  74%,
  100% {
    opacity: 1;
  }
  42%,
  72% {
    opacity: 0.45;
  }
}

.pcard-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pcard-id {
  min-width: 0;
  flex: 1;
}

.pcard-rank {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--seat);
}

.pcard-name {
  margin: 1px 0 0;
  font-family: var(--display);
  font-size: 19px;
  font-weight: 600;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.pcard-score {
  flex: none;
  color: var(--seat);
  /* The glow has to live out here: each digit clips its own overflow to make
     the reel work, which would chop a text-shadow into a hard rectangle. */
  filter: drop-shadow(0 0 11px color-mix(in srgb, var(--seat) 50%, transparent));
}

[data-theme='light'] .pcard-score {
  filter: none;
}

.pcard.is-pulsing {
  animation: card-pulse 0.5s ease-out;
}

@keyframes card-pulse {
  0% {
    transform: scale(1);
  }
  35% {
    transform: scale(1.014);
  }
  100% {
    transform: scale(1);
  }
}

.pcard-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.step {
  flex: 1 1 0;
  min-width: 58px;
  min-height: 52px;
  border-radius: 11px;
  border: 1px solid var(--edge);
  background: color-mix(in srgb, var(--seat) 9%, transparent);
  color: var(--ink);
  font-family: var(--display);
  font-weight: 700;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  transition: transform 0.16s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.16s,
    border-color 0.16s;
}

.step:hover {
  border-color: var(--seat);
  background: color-mix(in srgb, var(--seat) 18%, transparent);
}

.step:active {
  transform: scale(0.93);
  background: color-mix(in srgb, var(--seat) 32%, transparent);
}

.step.is-minus {
  color: var(--dim);
}

.step.is-keypad {
  flex: 0 0 52px;
  min-width: 52px;
  font-size: 15px;
}

.step[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* Game called: the board becomes a record, not a control surface. */
.board.is-locked .pcard {
  opacity: 0.9;
}

/* ------------------------------------------------------------------ *
 * Score reel — the signature
 * ------------------------------------------------------------------ */

.reel {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  font-family: var(--display);
  font-weight: 700;
  font-size: 46px;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.reel-sign {
  opacity: 0;
  transition: opacity 0.2s;
  margin-right: 0.04em;
}

.reel-digit {
  display: block;
  height: 1em;
  overflow: hidden;
}

.reel-strip {
  display: block;
  will-change: transform;
}

.reel-cell {
  display: block;
  height: 1em;
  line-height: 1;
  text-align: center;
  min-width: 0.62em;
}

.delta-chip {
  position: fixed;
  z-index: 90;
  pointer-events: none;
  font-family: var(--display);
  font-weight: 700;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 16px currentColor;
}

/* Density.
   Up to four players the stacked card is the showpiece. From five up, a
   stacked card can't fit the table on one screen without shrinking the tap
   targets below 44px — so the card turns into a single row instead: name,
   score, and −1/+1/keypad all on one line. Quick buttons move into the keypad
   sheet rather than disappearing. Ten players still fit on a phone. */
.board[data-density='dense'] {
  gap: 8px;
}

.board[data-density='dense'] .pcard {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 14px;
}

.board[data-density='dense'] .pcard-top {
  flex: 1;
  min-width: 0;
}

.board[data-density='dense'] .pcard-rank {
  font-size: 10px;
}

.board[data-density='dense'] .pcard-name {
  font-size: 15px;
}

.board[data-density='dense'] .reel {
  font-size: 27px;
}

.board[data-density='dense'] .pcard-controls {
  margin-top: 0;
  flex-wrap: nowrap;
  gap: 5px;
}

.board[data-density='dense'] .step {
  flex: 0 0 44px;
  min-width: 44px;
  min-height: 44px;
  font-size: 15px;
}

.board[data-density='dense'] .step.is-quick {
  display: none;
}

.board[data-density='dense'] .step.is-keypad {
  flex: 0 0 44px;
  min-width: 44px;
  font-size: 13px;
}

/* Quick values, relocated into the keypad sheet for dense tables. */
.quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.qchip {
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: var(--rail);
  font-family: var(--display);
  font-weight: 700;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  transition: transform 0.16s, border-color 0.16s;
}

.qchip:active {
  transform: scale(0.93);
}

.qchip:hover {
  border-color: var(--cyan);
}

/* ------------------------------------------------------------------ *
 * Bottom dock
 * ------------------------------------------------------------------ */

.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--void) 92%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--edge);
}

.dock-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px;
  border-radius: 11px;
  color: var(--dim);
  font-family: var(--display);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: color 0.18s, background 0.18s, transform 0.18s;
}

.dock-btn svg {
  width: 21px;
  height: 21px;
}

.dock-btn:hover {
  color: var(--ink);
  background: var(--rail);
}

.dock-btn:active {
  transform: scale(0.92);
}

.dock-btn[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
}

.dock-btn.is-end {
  color: var(--gold);
}

/* ------------------------------------------------------------------ *
 * Sheets
 * ------------------------------------------------------------------ */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
}

.sheet.is-open {
  display: block;
}

.sheet-scrim {
  position: absolute;
  inset: 0;
  background: rgba(6, 4, 14, 0.62);
  animation: fade-in 0.25s ease;
}

[data-theme='light'] .sheet-scrim {
  background: rgba(21, 15, 44, 0.35);
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--cabinet);
  border-top: 1px solid var(--edge);
  border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  animation: sheet-up 0.34s cubic-bezier(0.22, 0.9, 0.24, 1);
}

@keyframes sheet-up {
  from {
    transform: translateY(100%);
  }
}

.sheet-grip {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--edge);
  margin: 4px auto 12px;
  flex: none;
}

.sheet-title {
  margin: 0 0 14px;
  font-family: var(--display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 720px) {
  .sheet-panel {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 50%;
    width: min(520px, 92vw);
    transform: translate(-50%, -50%);
    border-radius: 20px;
    border: 1px solid var(--edge);
    animation: sheet-pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  }
  @keyframes sheet-pop {
    from {
      transform: translate(-50%, -46%) scale(0.94);
      opacity: 0;
    }
  }
  .sheet-grip {
    display: none;
  }
}

/* Keypad */
.keypad-display {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 16px;
  background: var(--void);
  border: 1px solid var(--edge);
  border-radius: var(--r);
  margin-bottom: 12px;
  font-family: var(--display);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.keypad-display .who {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
  text-align: left;
}

.keypad-display .amount {
  font-size: 36px;
  line-height: 1;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.key {
  min-height: 58px;
  border-radius: 12px;
  background: var(--rail);
  font-family: var(--display);
  font-weight: 700;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  transition: transform 0.14s, background 0.14s;
}

.key:active {
  transform: scale(0.94);
  background: var(--edge);
}

.key.is-util {
  font-size: 16px;
  color: var(--dim);
}

.keypad-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.keypad-actions button {
  padding: 16px;
  border-radius: 12px;
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 14px;
}

.keypad-actions .subtract {
  background: color-mix(in srgb, var(--danger) 16%, var(--rail));
  color: var(--danger);
}

.keypad-actions .add {
  background: var(--cyan);
  color: #06121a;
}

[data-theme='light'] .keypad-actions .add {
  color: #fff;
}

/* History */
.log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.log-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid color-mix(in srgb, var(--edge) 55%, transparent);
  font-size: 14px;
}

.log-row .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  background: var(--seat);
}

.log-row .who {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-row .delta {
  font-family: var(--display);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.log-row .delta.up {
  color: var(--lime);
}

.log-row .delta.down {
  color: var(--danger);
}

.log-row .at {
  color: var(--faint);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  width: 62px;
  text-align: right;
  flex: none;
}

.empty {
  padding: 28px 0;
  text-align: center;
  color: var(--faint);
  font-size: 14px;
}

/* Dice */
.dice-picker {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 10px;
  margin-bottom: 4px;
  scrollbar-width: none;
}

.dice-picker::-webkit-scrollbar {
  display: none;
}

.dice-chip {
  flex: none;
  padding: 9px 15px;
  border-radius: 999px;
  border: 1px solid var(--edge);
  font-family: var(--display);
  font-weight: 700;
  font-size: 14px;
  color: var(--dim);
  transition: color 0.18s, border-color 0.18s, background 0.18s;
}

.dice-chip[aria-pressed='true'] {
  color: var(--magenta);
  border-color: var(--magenta);
  background: color-mix(in srgb, var(--magenta) 14%, transparent);
}

.dice-stage {
  display: grid;
  place-items: center;
  padding: 22px 0 8px;
  perspective: 700px;
}

.die {
  position: relative;
  width: 152px;
  height: 152px;
  display: grid;
  place-items: center;
  transform-style: preserve-3d;
}

.die svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: color-mix(in srgb, var(--magenta) 12%, transparent);
  stroke: var(--magenta);
  stroke-width: 2.5;
  filter: drop-shadow(0 0 16px color-mix(in srgb, var(--magenta) 45%, transparent));
}

.die svg .die-inner {
  fill: none;
  stroke-width: 1.2;
  opacity: 0.45;
}

.die-value {
  position: relative;
  font-family: var(--display);
  font-weight: 700;
  font-size: 48px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  text-shadow: 0 0 20px color-mix(in srgb, var(--magenta) 60%, transparent);
}

.die-value.is-word {
  font-size: 26px;
  letter-spacing: 0.08em;
}

.die.is-rolling .die-value {
  opacity: 0.7;
}

.die.is-landed svg {
  fill: color-mix(in srgb, var(--magenta) 26%, transparent);
}

.dice-caption {
  text-align: center;
  color: var(--faint);
  font-size: 13px;
  margin: 4px 0 14px;
  min-height: 1.4em;
}

/* Menu list */
.menu-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 15px 14px;
  border-radius: 12px;
  background: var(--rail);
  font-size: 15px;
  transition: background 0.18s;
}

.menu-item:hover {
  background: var(--edge);
}

.menu-item small {
  display: block;
  color: var(--faint);
  font-size: 12.5px;
}

.menu-item.is-danger {
  color: var(--danger);
}

.storage-note {
  margin: 16px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px dashed var(--edge);
  color: var(--faint);
  font-size: 12.5px;
  line-height: 1.5;
}

/* ------------------------------------------------------------------ *
 * Finale — podium + fireworks
 * ------------------------------------------------------------------ */

.finale {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  flex-direction: column;
  background: var(--void);
}

.finale.is-open {
  display: flex;
}

#fireworks {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.finale-inner {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 22px 16px calc(18px + env(safe-area-inset-bottom));
  overflow-y: auto;
}

.finale-head {
  text-align: center;
  margin-bottom: 6px;
  animation: rise-in 0.6s 0.15s backwards cubic-bezier(0.22, 0.9, 0.24, 1);
}

.finale-head h2 {
  margin: 6px 0 4px;
  font-family: var(--display);
  font-size: clamp(28px, 9vw, 44px);
  font-weight: 700;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  color: var(--gold);
  text-shadow: 0 0 30px color-mix(in srgb, var(--gold) 55%, transparent);
}

.finale-head p {
  margin: 0;
  color: var(--dim);
  font-size: 14px;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
}

.podium {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  align-items: end;
  gap: 8px;
  margin: 30px 0 0;
  padding-top: 20px;
  border-bottom: 2px solid color-mix(in srgb, var(--gold) 32%, var(--edge));
}

.step-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.step-names {
  text-align: center;
  margin-bottom: 8px;
  min-width: 0;
  width: 100%;
  animation: rise-in 0.5s backwards cubic-bezier(0.34, 1.56, 0.64, 1);
}

.step-medal {
  font-size: 26px;
  line-height: 1;
  display: block;
  margin-bottom: 4px;
}

.step-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
  overflow-wrap: anywhere;
  color: var(--seat);
}

.step-score {
  display: block;
  font-family: var(--display);
  font-weight: 700;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--dim);
}

/* A two- or one-step podium shouldn't stretch a pillar across the screen.
   Centre with align-self, never margin-inline:auto — auto cross-axis margins
   on a flex child cancel the stretch and collapse the grid to content width. */
.podium[data-blocks='1'],
.podium[data-blocks='2'] {
  width: 100%;
  align-self: center;
}

.podium[data-blocks='1'] {
  max-width: 210px;
}

.podium[data-blocks='2'] {
  max-width: 340px;
}

.step-pillar {
  width: 100%;
  border-radius: 10px 10px 0 0;
  border: 1px solid var(--seat);
  border-bottom: 0;
  background: linear-gradient(
    to top,
    color-mix(in srgb, var(--seat) 28%, transparent),
    color-mix(in srgb, var(--seat) 6%, transparent)
  );
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-weight: 700;
  font-size: 30px;
  color: var(--seat);
  transform-origin: bottom;
  animation: pillar-rise 0.8s backwards cubic-bezier(0.22, 1.2, 0.3, 1);
}

@keyframes pillar-rise {
  from {
    transform: scaleY(0.04);
    opacity: 0.2;
  }
}

.step-block[data-place='1'] .step-pillar {
  height: 148px;
  animation-delay: 0.75s;
  box-shadow: 0 0 40px -10px var(--seat);
}

.step-block[data-place='2'] .step-pillar {
  height: 104px;
  animation-delay: 0.45s;
}

.step-block[data-place='3'] .step-pillar {
  height: 76px;
  animation-delay: 0.15s;
}

.step-block[data-place='1'] .step-names {
  animation-delay: 1.25s;
}

.step-block[data-place='2'] .step-names {
  animation-delay: 0.95s;
}

.step-block[data-place='3'] .step-names {
  animation-delay: 0.65s;
}

.also-ran {
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  color: var(--faint);
  font-size: 13px;
  animation: rise-in 0.5s 1.5s backwards ease;
}

.also-ran span {
  font-variant-numeric: tabular-nums;
}

.finale-stats {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin: 16px 0 0;
  color: var(--dim);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  animation: rise-in 0.5s 1.6s backwards ease;
}

.finale-actions {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  animation: rise-in 0.5s 1.7s backwards ease;
}

@media (min-width: 680px) {
  .board {
    grid-template-columns: repeat(2, 1fr);
  }
  .setup {
    padding-top: 44px;
  }
  .podium {
    width: 100%;
    max-width: 520px;
    align-self: center;
  }
}

@media (min-width: 1040px) {
  .board[data-density='dense'] {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ================================================================== *
 * v2 — account, rounds, sharing, saved games
 * ================================================================== */

/* --- account bar + entry points --- */

.account-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  background: var(--cabinet);
  border: 1px solid var(--edge);
  border-radius: var(--r);
}

.account-who .tag {
  display: block;
  margin-bottom: 1px;
}

.account-who strong {
  font-family: var(--display);
  font-size: 15px;
  font-weight: 600;
}

.chip-btn {
  flex: none;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--cyan);
  color: var(--cyan);
  background: color-mix(in srgb, var(--cyan) 10%, transparent);
  font-family: var(--display);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.06em;
  transition: transform 0.18s, background 0.18s;
}

.chip-btn:active {
  transform: scale(0.94);
}

.entry-links {
  display: grid;
  gap: 6px;
  margin-bottom: 22px;
}

.entry-links:empty {
  margin-bottom: 0;
}

.entry-link {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 13px 15px;
  border-radius: 12px;
  border: 1px solid var(--edge);
  background: var(--cabinet);
  transition: border-color 0.18s, transform 0.18s;
}

.entry-link:hover {
  border-color: var(--cyan);
}

.entry-link:active {
  transform: scale(0.99);
}

.entry-link span {
  font-family: var(--display);
  font-weight: 600;
  font-size: 15px;
}

.entry-link small {
  color: var(--faint);
  font-size: 12.5px;
}

/* --- roster chips --- */

.roster-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.roster-chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: var(--cabinet);
  color: var(--dim);
  font-size: 13.5px;
  font-weight: 500;
  transition: color 0.18s, border-color 0.18s, transform 0.18s;
}

.roster-chip:hover {
  color: var(--ink);
  border-color: var(--cyan);
}

.roster-chip:active {
  transform: scale(0.94);
}

.roster-chip.is-manage {
  color: var(--faint);
  border-style: dashed;
}

/* --- rounds --- */

.round-bar {
  position: sticky;
  top: 57px;
  z-index: 18;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--cyan) 8%, var(--cabinet));
  border-bottom: 1px solid color-mix(in srgb, var(--cyan) 30%, transparent);
}

.round-count {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex: none;
}

.round-count .tag {
  font-size: 9px;
}

.round-count strong {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
}

.round-of {
  font-family: var(--display);
  font-size: 11px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.round-status {
  flex: 1;
  margin: 0;
  min-width: 0;
  font-size: 13px;
  color: var(--dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.round-pips {
  display: flex;
  gap: 3px;
  flex: none;
}

.pip {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--edge);
}

.pip.is-done {
  background: var(--cyan);
}

.pip.is-now {
  background: var(--gold);
  box-shadow: 0 0 8px var(--gold);
}

.pcard-round {
  margin-top: 12px;
}

.board[data-density='dense'] .pcard-round {
  margin-top: 0;
  flex: 0 0 auto;
}

.round-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  padding: 8px 14px;
  border-radius: 11px;
  border: 1px dashed var(--edge);
  color: var(--dim);
  font-family: var(--display);
  font-weight: 600;
  font-size: 14px;
  transition: border-color 0.18s, background 0.18s, transform 0.16s;
}

.board[data-density='dense'] .round-chip {
  min-height: 44px;
  width: auto;
  min-width: 116px;
  font-size: 13px;
}

.round-chip.is-open {
  border-style: solid;
  border-color: color-mix(in srgb, var(--seat) 45%, var(--edge));
  background: color-mix(in srgb, var(--seat) 10%, transparent);
  color: var(--ink);
}

.round-chip.is-open:active {
  transform: scale(0.96);
}

.round-chip.is-in {
  border-style: solid;
  border-color: color-mix(in srgb, var(--seat) 60%, var(--edge));
  background: color-mix(in srgb, var(--seat) 16%, transparent);
  color: var(--seat);
}

.round-chip.is-done {
  border-style: solid;
  opacity: 0.6;
}

.round-chip[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

.round-tick {
  font-size: 13px;
}

.round-points {
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.round-label {
  font-family: var(--body);
  font-size: 11px;
  font-weight: 400;
  color: var(--faint);
}

.board.is-rounds .pcard-controls {
  display: none;
}

/* --- "you" marker --- */

.you-tag {
  display: inline-block;
  margin-left: 7px;
  padding: 2px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--seat) 22%, transparent);
  border: 1px solid color-mix(in srgb, var(--seat) 50%, transparent);
  color: var(--seat);
  font-family: var(--display);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  vertical-align: middle;
}

/* --- share code --- */

.code-pill {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--lime) 55%, var(--edge));
  background: color-mix(in srgb, var(--lime) 12%, transparent);
  color: var(--lime);
  font-family: var(--display);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.14em;
}

.code-display {
  margin: 6px 0 14px;
  padding: 20px 12px;
  border-radius: var(--r);
  border: 1px dashed color-mix(in srgb, var(--lime) 50%, var(--edge));
  background: color-mix(in srgb, var(--lime) 8%, transparent);
  text-align: center;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(34px, 13vw, 52px);
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  color: var(--lime);
  line-height: 1;
}

.code-input {
  width: 100%;
  margin: 10px 0;
  padding: 18px 12px;
  border-radius: var(--r);
  border: 1px solid var(--edge);
  background: var(--void);
  text-align: center;
  font-family: var(--display);
  font-weight: 700;
  font-size: 32px;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  text-transform: uppercase;
}

.code-input::placeholder {
  color: var(--faint);
  letter-spacing: 0.22em;
}

.hint.is-error {
  color: var(--danger);
}

/* --- seat pickers --- */

.seat-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.seat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--edge);
  background: var(--rail);
  transition: border-color 0.18s, transform 0.16s;
}

.seat-row:not([disabled]):hover {
  border-color: var(--seat);
}

.seat-row:not([disabled]):active {
  transform: scale(0.99);
}

.seat-row[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.seat-row .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--seat);
  flex: none;
}

.seat-name {
  flex: 1;
  min-width: 0;
  font-family: var(--display);
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-state {
  flex: none;
  font-size: 12px;
  color: var(--faint);
  text-transform: lowercase;
}

/* --- saved games --- */

.game-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.game-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.game-open {
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--edge);
  background: var(--rail);
  transition: border-color 0.18s;
}

.game-open:hover {
  border-color: var(--cyan);
}

.game-head {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}

.game-head strong {
  font-family: var(--display);
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-state {
  flex: none;
  font-family: var(--display);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
}

.game-state.is-live {
  color: var(--lime);
}

.game-meta {
  display: block;
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--faint);
}

.log-round {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--rail);
  color: var(--faint);
  font-family: var(--display);
  font-size: 10px;
  font-weight: 700;
}

.board-photo {
  display: block;
  width: 100%;
  margin-top: 12px;
  border-radius: 12px;
  border: 1px solid var(--edge);
}

/* --- toast --- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--dock-h) + 18px + env(safe-area-inset-bottom));
  z-index: 95;
  transform: translate(-50%, 14px);
  max-width: min(440px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--rail);
  border: 1px solid var(--edge);
  color: var(--ink);
  font-size: 13.5px;
  text-align: center;
  box-shadow: 0 16px 34px -18px rgba(0, 0, 0, 0.9);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.26s, transform 0.26s cubic-bezier(0.22, 0.9, 0.24, 1);
}

.toast.is-open {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.is-error {
  border-color: color-mix(in srgb, var(--danger) 55%, var(--edge));
  color: var(--danger);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
