/* App layout and components. Theme tokens and primitives are in theme.css. */

/* Jua, self-hosted so the first offline visit has it too. Latin only;
   anything outside the range falls back to the next font in the stack. */
@font-face {
  font-family: "Jua";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/jua-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root[data-mode="dark"] { color-scheme: dark; }

/* The board's fixed-meaning colours, like the footer heart in other uwuapps:
   a fruit reads as a fruit and each player keeps their colour whatever the
   swatch. The first snake is --brand-ink, the app's own green. js/render.js
   draws with these. */
:root,
:root[data-mode="light"] {
  --fruit: #d83a34;
  --fruit-leaf: #2f8a3a;
  --fruit-extra: #c99400;
  --snake-1: var(--brand-ink);
  --snake-2: #2f6fd0;
  --snake-3: #c2630a;
  --snake-4: #8a3fc0;
}
:root[data-mode="dark"] {
  --fruit: #ff6b63;
  --fruit-leaf: #5fd27a;
  --fruit-extra: #ffd24a;
  --snake-1: var(--brand-ink);
  --snake-2: #7fb0ff;
  --snake-3: #ffb35c;
  --snake-4: #d1a3ff;
}

:root {
  /* The body's own colour, for anything that has to match it. */
  --page-bg: color-mix(in srgb, var(--brand) 10%, var(--bg));
  /* Glass that text stays readable through when the board is behind it. */
  --glass-read: color-mix(in srgb, var(--bg) 80%, transparent);

  /* edge-tray-spec.md's tokens. --banner-h is the update bar's height,
     which js/update-bar.js publishes as --notice-h. */
  --banner-h: var(--notice-h, 0px);
  --glass-btn: 44px;
  --edge: max(16px, calc(env(safe-area-inset-right) + 16px));
  --edge-left: max(16px, calc(env(safe-area-inset-left) + 16px));
  --tray-top: max(calc(var(--banner-h, 0px) + 14px), calc(env(safe-area-inset-top) + 14px));
  --tray-time: 0.34s;
  --tray-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --accent-fill: var(--brand-fill);
  --on-accent: var(--on-brand);
}

h1, h2 { font-weight: normal; }

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* A full screen game: nothing scrolls, nothing bounces, and nothing pulls to
   refresh. touch-action on the stage hands every touch there to the game. */
html, body { overflow: hidden; overscroll-behavior: none; }
body {
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.stage {
  position: fixed;
  inset: 0;
  z-index: 0;
  touch-action: none;
}

.board {
  position: absolute;
  display: block;
  border-radius: 14px;
  box-shadow: var(--shadow);
  transition:
    left var(--tray-time) var(--tray-ease),
    top var(--tray-time) var(--tray-ease),
    width var(--tray-time) var(--tray-ease),
    height var(--tray-time) var(--tray-ease);
}

/* Hints and the countdown, in a pill at the foot of the screen. */
.stage-note {
  position: fixed;
  z-index: 4;
  left: 50%;
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 18px));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--glass-read);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 0.95rem;
  text-align: center;
  pointer-events: none;
}
.stage-note[hidden] { display: none; }
body.replaying .stage-note { display: none; }

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--surface-strong);
  border: 1px solid color-mix(in srgb, var(--ink) 25%, transparent);
  color: var(--muted-strong);
  font-size: 0.75rem;
  line-height: 1.4;
  text-align: center;
}

/* ---- Top left: the brand line and the stats ---- */

.hud-left {
  position: fixed;
  z-index: 5;
  top: var(--tray-top);
  left: var(--edge-left);
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: min(320px, calc(100vw - var(--edge-left) - 120px));
  pointer-events: none;
  text-shadow: 0 0 4px var(--page-bg), 0 0 8px var(--page-bg);
  transition: top 0.2s ease;
}

/* The app's logo and its name, and nothing else. Three quick taps on it
   toggle something: take them without selecting text or zooming. */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  font-size: 1.35rem;
  line-height: 1.1;
  color: var(--brand-ink);
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.brand img {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  flex-shrink: 0;
}

.hud-stats { color: var(--ink); }
.hud-line {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  font-size: 1rem;
  color: var(--muted);
}
.hud-line b { font-weight: normal; color: var(--ink); font-variant-numeric: tabular-nums; }
.hud-sub { font-size: 0.85rem; }
.hud-pair { white-space: nowrap; }
.hud-players {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-size: 0.95rem;
}
.hud-players li { display: flex; align-items: center; gap: 6px; }
.hud-players b { font-weight: normal; margin-left: 4px; font-variant-numeric: tabular-nums; }
.hud-players li.out { color: var(--muted); }
.out-tag { font-size: 0.75rem; color: var(--muted); }
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid color-mix(in srgb, var(--ink) 30%, transparent);
}

/* ---- Top right: pause, and the edge tray (edge-tray-spec.md) ---- */

.glass-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--glass-btn);
  height: var(--glass-btn);
  padding: 0;
  border-radius: 14px;
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.glass-btn:hover { transform: translateY(-1px); background: var(--surface-strong); }
.glass-btn svg { width: 22px; height: 22px; }
.glass-btn.small { width: 36px; height: 36px; border-radius: 12px; }
.glass-btn.small svg { width: 18px; height: 18px; }
.glass-btn[hidden] { display: none; }

/* Fixed top right. Lets clicks through except on its children, so the empty
   space around the tray never blocks the board. */
.hud-right {
  position: fixed;
  z-index: 800;
  top: var(--tray-top);
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none;
  transition: top 0.2s ease;
}
.hud-right > * { pointer-events: auto; }

.hud-pause { margin-right: var(--edge); }
/* Nothing to pause before a game, or for a guest in someone else's. */
body:not(.playing) .hud-pause,
body.guest .hud-pause,
body.replaying .hud-pause { visibility: hidden; }

/* The tray: tab and column. Collapsed, the whole thing shifts right until
   only the tab is left, flush with the edge. */
.tray {
  --tray-shift: calc(var(--glass-btn) + 8px + var(--edge));
  display: flex;
  align-items: flex-start;
  gap: 8px;
  transition: transform var(--tray-time) var(--tray-ease);
}
.tray.collapsed { transform: translateX(var(--tray-shift)); }

.tray-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: var(--glass-btn);
  padding: 0;
  border-radius: 12px;
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow);
  color: var(--ink);
  cursor: pointer;
  transition: border-radius var(--tray-time) var(--tray-ease);
}
.tray-tab svg { width: 16px; height: 16px; transition: transform var(--tray-time) var(--tray-ease); }
/* At the edge it is a tab: flat on the side the screen cuts off. */
.tray.collapsed .tray-tab { border-radius: 12px 0 0 12px; border-right: none; }
.tray.collapsed .tray-tab svg { transform: rotate(180deg); }

.tray-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-right: var(--edge);
}

/* The buttons unroll: each fades in, slides back from the edge and grows,
   18 ms after the one above it. They move by translate and scale, leaving
   transform to the hover lift. */
.tray-buttons > * {
  transition:
    opacity calc(var(--tray-time) * 0.8) ease,
    translate var(--tray-time) var(--tray-ease),
    scale var(--tray-time) var(--tray-ease),
    transform 0.15s ease,
    background 0.15s ease,
    color 0.15s ease;
  transition-delay: calc(var(--i, 0) * 18ms), calc(var(--i, 0) * 18ms), calc(var(--i, 0) * 18ms), 0s, 0s, 0s;
}
.tray-buttons > :nth-child(2) { --i: 1; }
.tray-buttons > :nth-child(3) { --i: 2; }
.tray-buttons > :nth-child(4) { --i: 3; }
.tray-buttons > :nth-child(5) { --i: 4; }
.tray-buttons > :nth-child(6) { --i: 5; }
.tray.collapsed .tray-buttons > * {
  opacity: 0;
  translate: 12px 0;
  scale: 0.85;
  transition-delay: 0s;
}

.tray-tab:focus-visible,
.glass-btn:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* No flash on load for a tray left collapsed (edge-tray-spec.md, 6.4). */
.tray-start-collapsed .tray { transform: translateX(var(--tray-shift)); transition: none; }
.tray-start-collapsed .tray-buttons > * { opacity: 0; translate: 12px 0; scale: 0.85; transition: none; }
.tray-start-collapsed .board { transition: none; }
.tray-start-collapsed .tray-tab { border-radius: 12px 0 0 12px; border-right: none; }
.tray-start-collapsed .tray-tab svg { transform: rotate(180deg); }

/* ---- Watchers' tools ---- */

.tool-dock {
  position: fixed;
  z-index: 6;
  left: 50%;
  bottom: max(10px, calc(env(safe-area-inset-bottom) + 10px));
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 6px;
  border-radius: 18px;
  background: var(--glass-read);
}
.tool-dock[hidden] { display: none; }
.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--surface-strong);
  border: 1px solid var(--surface-border);
  color: var(--ink);
  font-size: 0.9rem;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.tool-btn svg { width: 20px; height: 20px; }
.tool-btn.active { background: var(--brand-fill); color: var(--on-brand); }
.tool-btn.cooling { opacity: 0.7; }
.tool-wait { font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.tool-wait:empty { display: none; }
/* The note would sit under the dock. */
body:has(.tool-dock:not([hidden])) .stage-note { bottom: calc(max(10px, env(safe-area-inset-bottom) + 10px) + 64px); }

/* ---- Instant replay ---- */

.replay-bar {
  position: fixed;
  z-index: 6;
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 14px;
  background: var(--glass-read);
}
.replay-bar[hidden] { display: none; }
.replay-bar .hidden { display: none !important; }

.replay-note {
  font-size: 0.8rem;
  color: var(--muted-strong);
}
.replay-note[hidden] { display: none; }
.replay-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.replay-caption {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--ink);
}
.replay-caption.bad { color: var(--error); }
.replay-time {
  font-size: 0.85rem;
  color: var(--muted-strong);
  font-variant-numeric: tabular-nums;
}

/* The timeline. The range input's own track is see-through; the bar under
   it, inset by half the thumb so the ends line up, draws the track, how
   much has played, a tick for each fruit and one for the end. */
.replay-track {
  position: relative;
  height: 24px;
}
.replay-marks {
  --played: 0%;
  position: absolute;
  left: 8px;
  right: 8px;
  top: 50%;
  height: 6px;
  margin-top: -3px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--ink) 18%, transparent);
  pointer-events: none;
}
/* How much has played: a flat fill over the track, no gradient. */
.replay-marks::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--played);
  border-radius: 3px;
  background: var(--brand-ink);
}
.replay-marks span {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  margin-left: -1px;
  border-radius: 1px;
  background: var(--ok);
}
.replay-marks span.end { background: var(--error); top: -5px; bottom: -5px; }
.replay-seek {
  position: relative;
  display: block;
  width: 100%;
  height: 24px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.replay-seek::-webkit-slider-runnable-track { height: 24px; background: transparent; }
.replay-seek::-moz-range-track { background: transparent; }
.replay-seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  box-sizing: border-box;
  width: 16px;
  height: 16px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--brand-ink);
  border: 2px solid var(--bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.replay-seek::-moz-range-thumb {
  box-sizing: border-box;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--brand-ink);
  border: 2px solid var(--bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
/* Scrubbing takes the drag for itself, not the page. */
.replay-seek { touch-action: none; }
/* A thumb a finger can find, on a track a finger can hit. */
@media (pointer: coarse) {
  .replay-track, .replay-seek, .replay-seek::-webkit-slider-runnable-track { height: 36px; }
  .replay-seek::-webkit-slider-thumb { width: 26px; height: 26px; margin-top: 5px; }
  .replay-seek::-moz-range-thumb { width: 26px; height: 26px; }
  .replay-marks { left: 13px; right: 13px; }
}

.replay-controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 6px 10px;
}
.replay-speed {
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
  grid-template-columns: repeat(4, auto);
  gap: 2px;
  padding: 3px;
  border-radius: 12px;
}
.replay-speed .mode-btn {
  padding: 6px 8px;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}
.replay-steps {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}
.replay-ends {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}
@media (max-width: 560px) {
  .replay-speed {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: center;
  }
}
/* Nested in the bar's glass. */
.replay-bar .glass-btn {
  background: var(--surface-strong);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: none;
}
.replay-keys {
  font-size: 0.8rem;
  text-align: center;
  color: var(--muted-strong);
}

/* Key hints mean nothing on a touch screen, and touch hints nothing with
   a mouse. */
.touch-only { display: none; }
@media (pointer: coarse) {
  .replay-keys, .kbd-only { display: none; }
  .touch-only { display: inline; }
}

/* ---- Panels: the pre-game screen, pause and game over ----
   The same look as the theme modal, on their own class so ui.js never
   counts them as an open window. Below the windows, which open on top. */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(10, 15, 12, 0.35);
  opacity: 1;
  visibility: visible;
  transition: opacity 0.2s ease, visibility 0s linear 0s;
}
.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.18s ease, visibility 0s linear 0.18s;
}
.overlay.hidden .modal {
  opacity: 0;
  transform: translateY(14px) scale(0.97);
}

.modal .hidden,
.overlay .hidden { display: none !important; }

.panel {
  align-items: center;
  gap: 12px;
  text-align: center;
}
.panel h2 {
  font-size: 1.5rem;
  color: var(--brand-ink);
}
.panel p {
  line-height: 1.5;
  color: var(--muted-strong);
}
.keys-legend { font-size: 0.85rem; }

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}
.panel-actions .btn { padding: 9px 16px; }
.btn.big { padding: 11px 20px; font-size: 1rem; }

/* Pause in a party game has only Continue. */
.party-only { display: none; }
body.party-pause #pauseOverlay .party-only { display: block; }
body.party-pause #pauseOverlay .solo-only { display: none; }

.coffee-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}
.coffee-link svg { width: 16px; height: 16px; }

.over-cause:empty { display: none; }

.final-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
}
.final-stats > div {
  padding: 8px 4px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
}
.final-stats dt {
  font-size: 0.8rem;
  color: var(--muted-strong);
}
.final-stats dd {
  font-size: 1.3rem;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
#gameOverOverlay.party .final-stats { display: none; }

.party-results {
  list-style: none;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.party-results li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  color: var(--ink);
  text-align: left;
}
.pr-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.pr-score { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.pr-len { font-size: 0.8rem; color: var(--muted-strong); }

/* Buttons. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  transition: background 0.15s ease;
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-primary {
  background: var(--brand-fill);
  color: var(--on-brand);
}
.btn-primary:hover { background: var(--brand-fill-strong); }
.btn-quiet {
  color: var(--ink);
  border: 1px solid var(--surface-border);
}
.btn-quiet:hover { background: var(--surface-strong); }
.pill { border-radius: 999px; }
.link-btn {
  color: var(--brand-ink);
  text-decoration: underline;
  font-size: inherit;
}

/* Text fields. Their font stays at 16px or more, under which iOS zooms the
   page on focus. */
.guess {
  display: flex;
  gap: 8px;
  width: 100%;
}
.guess[hidden] { display: none; }
.field {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface-strong);
  /* 3:1 against the card, as a field's edge must be. */
  border: 1px solid color-mix(in srgb, var(--ink) 45%, transparent);
  color: var(--ink);
  font-size: 1rem;
}
.field::placeholder { color: var(--muted-strong); opacity: 1; }
.guess .btn {
  padding: 10px 16px;
  font-size: 0.95rem;
}

.submit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.submit-label {
  font-size: 0.95rem;
  color: var(--ink);
}
.panel .submit-msg {
  min-height: 1.2em;
  font-size: 0.85rem;
  color: var(--error);
}
.panel .submit-msg:empty { display: none; }
.panel .ok-msg { color: var(--ok); }
.panel .submit-note {
  font-size: 0.8rem;
  color: var(--muted-strong);
}
.submitted {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--ok) 14%, transparent);
  text-align: left;
}
.panel .submitted p { color: var(--ok); }
.ok-icon {
  display: inline-flex;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--ok);
}
.ok-icon svg { width: 100%; height: 100%; }

/* The game's seed, with its copy button. */
.panel .seed-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.9rem;
}
.seed-code {
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  color: var(--ink);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 1rem;
  letter-spacing: 0.08em;
  /* One tap selects it all, for copying by hand. */
  user-select: all;
  -webkit-user-select: all;
}
.seed-line .btn { padding: 5px 12px; }
.seed-input:not(:placeholder-shown),
.code-input:not(:placeholder-shown) { text-transform: uppercase; letter-spacing: 0.08em; }

/* ---- The pre-game screen ---- */

.start-panel { max-width: 460px; }
.start-form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  text-align: left;
}
.start-label {
  font-size: 0.9rem;
  color: var(--ink);
  margin-top: 4px;
}
.level-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.level-chips { display: flex; gap: 6px; }
.chip {
  min-width: 44px;
  padding: 9px 10px;
  border-radius: 999px;
  background: var(--surface-strong);
  border: 1px solid var(--surface-border);
  color: var(--ink);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  transition: background 0.15s ease;
}
.chip.active { background: var(--brand-fill); color: var(--on-brand); }
.level-input { max-width: 96px; text-align: center; }
.start-summary {
  margin-top: 4px;
  font-size: 0.85rem;
}
.start-form .panel-actions { justify-content: center; }

/* The editions, once there is more than one. */
.edition-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  width: 100%;
}
.edition-list[hidden] { display: none; }
.edition {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  color: var(--ink);
  text-align: left;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.edition.active {
  background: var(--brand-fill);
  color: var(--on-brand);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ink) 50%, transparent);
}
.edition-name { font-size: 1.05rem; }
.edition-about { font-size: 0.8rem; opacity: 0.85; }

/* ---- Settings modal ---- */

.saved-name {
  font-size: 0.95rem;
  color: var(--ink);
}
.clear-name { align-self: flex-start; }
.mode-toggle.thirds { grid-template-columns: repeat(3, 1fr); }
.mode-toggle.quarters { grid-template-columns: repeat(4, 1fr); }

.setting-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  font-size: 0.9rem;
  color: var(--ink);
  text-align: left;
}
.setting-toggle > span:first-child { flex: 1; }
.switch-state {
  font-size: 0.8rem;
  color: var(--muted-strong);
}
.switch {
  position: relative;
  flex-shrink: 0;
  width: 40px;
  height: 24px;
  border-radius: 999px;
  background: var(--surface-strong);
  border: 1px solid color-mix(in srgb, var(--ink) 45%, transparent);
  transition: background 0.18s ease, border-color 0.18s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted-strong);
  transition: transform 0.18s ease, background 0.18s ease;
}
.setting-toggle[aria-checked="true"] .switch {
  background: var(--brand-ink);
  border-color: var(--brand-ink);
}
.setting-toggle[aria-checked="true"] .switch::after {
  background: var(--bg);
  transform: translateX(16px);
}

/* ---- Leaderboard modal ---- */

.board-body {
  min-height: 120px;
  max-height: 50vh;
  overflow-y: auto;
  transition: opacity 0.15s ease;
}
.board-body[aria-busy="true"] { opacity: 0.6; }
.board-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.board-table th {
  padding: 6px 8px;
  text-align: left;
  font-weight: normal;
  font-size: 0.8rem;
  color: var(--muted-strong);
}
.board-table td {
  padding: 7px 8px;
  border-top: 1px solid var(--surface-border);
  color: var(--ink);
  overflow-wrap: anywhere;
}
.board-table th:first-child,
.board-table td:first-child { width: 2.5em; color: var(--muted-strong); }
.board-watch { font-size: 0.85rem; }
.board-empty {
  padding: 32px 8px;
  text-align: center;
  color: var(--muted-strong);
}

/* ---- Party modal ---- */

.party-view {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.party-view[hidden] { display: none; }
.party-code {
  text-align: center;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 2.2rem;
  letter-spacing: 0.18em;
  color: var(--ink);
  user-select: all;
  -webkit-user-select: all;
}
/* Centred, with its white quiet zone, so a phone pointed at the middle of
   the screen finds it (STUN-p2p-spec.md). */
.party-qr {
  align-self: center;
  width: min(220px, 60vw);
  padding: 8px;
  border-radius: 12px;
  background: #ffffff;
}
.party-qr:empty { display: none; }
.party-qr svg { display: block; width: 100%; height: auto; }
/* A QR code is black on white whatever the theme: scanners expect it. */
.party-qr .qr-bg { fill: #ffffff; }
.party-qr .qr-fg { fill: #000000; }
.party-link {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted-strong);
  overflow-wrap: anywhere;
}
.party-link .btn { padding: 5px 12px; }
.party-status {
  font-size: 0.95rem;
  color: var(--ink);
  line-height: 1.5;
}
.party-people {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.party-people li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  font-size: 0.9rem;
  color: var(--ink);
}
.pp-role { color: var(--muted-strong); font-size: 0.8rem; }
.party-view .panel-actions { justify-content: flex-start; }

/* ---- Slither ----
   The world fills the screen behind everything. Classic's board, its stats
   and its tools step aside while it is on. */

.world {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
}
body.slither .world { display: block; }
body.slither .board,
body.slither #hudStats,
body.slither .tool-dock,
body.slither #stageNote { display: none !important; }
/* Pause in Slither only continues; there is no restart or seed here. */
body.slither #pauseOverlay .solo-only,
body.slither #pauseOverlay .seed-line { display: none; }

.slither-hud {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.slither-hud[hidden] { display: none; }

/* The join code, top left from the first second: a tap shows the QR. */
.join-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 0.9rem;
  pointer-events: auto;
  text-shadow: none;
}
.join-chip svg { width: 16px; height: 16px; }
.join-chip b {
  font-weight: normal;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: 0.08em;
  color: var(--brand-ink);
}
.join-chip.off b { color: var(--muted-strong); letter-spacing: 0; font-family: inherit; }
.join-count { font-size: 0.8rem; color: var(--muted-strong); }
.join-count:empty { display: none; }

.slither-top {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 2px;
  font-size: 0.85rem;
  color: var(--muted);
}
.slither-top li { display: flex; justify-content: space-between; gap: 12px; min-width: 150px; }
.slither-top li b { font-weight: normal; color: var(--ink); font-variant-numeric: tabular-nums; }
.slither-top li.me, .slither-top li.me b { color: var(--brand-ink); }

/* Boost, bottom left on a touch screen, held down. */
.boost-btn {
  position: fixed;
  z-index: 6;
  left: max(18px, calc(env(safe-area-inset-left) + 18px));
  bottom: max(22px, calc(env(safe-area-inset-bottom) + 22px));
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 1rem;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  transition: background 0.12s ease, transform 0.12s ease;
}
.boost-btn[hidden] { display: none; }
.boost-btn.on {
  background: var(--brand-fill-strong);
  color: var(--on-brand);
  transform: scale(0.95);
}
body.replaying .boost-btn { display: none; }

.slither-note { bottom: max(120px, calc(env(safe-area-inset-bottom) + 120px)); }

/* The skin builder. */
.skin-modal { max-width: 480px; }
.skin-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.skin-preview {
  width: 100%;
  height: 90px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
}
.skin-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.preset {
  display: inline-flex;
  gap: 2px;
  padding: 6px 8px;
  border-radius: 999px;
  background: var(--surface-strong);
  border: 1px solid var(--surface-border);
}
.preset span {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--ink) 30%, transparent);
}
.skin-seq-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.skin-seq {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 30px;
}
.seq-dot, .pal-dot {
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--dot);
  border: 2px solid color-mix(in srgb, var(--ink) 30%, transparent);
}
.pal-dot { width: 36px; height: 36px; }
/* Starred colours wear a small white star, as inline SVG. */
.seq-dot.star::after, .pal-dot.star::after {
  content: "";
  position: absolute;
  inset: 22%;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23ffffff' d='M12 2l2.9 6.6 7.1.6-5.4 4.7 1.6 7-6.2-3.7-6.2 3.7 1.6-7L2 9.2l7.1-.6z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.skin-palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  gap: 6px;
  justify-items: center;
}
.mode-toggle.outfits { grid-template-columns: repeat(4, 1fr); }
.mode-toggle.outfits .mode-btn { font-size: 0.8rem; padding: 7px 4px; }
.skin-row { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.skin-row[hidden], .level-block[hidden] { display: none; }

/* ---- Update bar ----
   Per update-bar-spec.md: quieter than the controls, full width, tinted
   enough to read as a notice. Fixed, since everything in the game is, and
   js/update-bar.js publishes its height for the tray and the board. */

.update-notice {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 900;
  background: color-mix(in srgb, var(--brand-ink) 12%, var(--bg));
  border-bottom: 1px solid var(--surface-border);
  color: var(--ink);
  font-size: 0.875rem;
  animation: notice-in 0.2s ease;
}
@keyframes notice-in {
  from { transform: translateY(-100%); }
}
.update-notice-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 720px;
  margin: 0 auto;
  padding: 0.5rem 1rem;
  /* Under the notch on a phone, where the bar is the topmost thing on screen. */
  padding-top: max(0.5rem, env(safe-area-inset-top));
}
.update-notice p { flex: 1 1 auto; min-width: 0; }
.update-notice .btn {
  flex: none;
  padding: 6px 12px;
}

/* Stacking, per edge-tray-spec.md: the board, the panels, the tray (800),
   the update bar, then windows. The panels sit under the tray so its
   leaderboard, theme and settings stay to hand on the pre-game screen. */
.modal-backdrop { z-index: 950; }
.overlay { z-index: 700; }

/* On a narrow screen a panel keeps clear of the open tray, as the spec's
   content column does, and takes the width back when it collapses. */
.overlay {
  transition: opacity 0.2s ease, visibility 0s linear 0s, padding-right var(--tray-time) var(--tray-ease);
}
@media (max-width: 920px) {
  body.tray-open .overlay { padding-right: calc(var(--glass-btn) + var(--edge) + 20px); }
}

@media (prefers-reduced-motion: reduce) {
  .hud-right, .hud-left, .tray, .tray-tab, .tray-tab svg, .tray-buttons > *, .glass-btn, .board, .overlay {
    transition-duration: 0.001ms !important;
    transition-delay: 0s !important;
  }
}

@media (max-width: 480px) {
  :root {
    --glass-btn: 40px;
    --edge: max(10px, calc(env(safe-area-inset-right) + 10px));
    --edge-left: max(10px, calc(env(safe-area-inset-left) + 10px));
  }
  .brand { font-size: 1.15rem; }
  .brand img { width: 26px; height: 26px; }
  .hud-line { font-size: 0.9rem; gap: 0 10px; }
  .pause-btn svg { width: 22px; height: 22px; }
  .final-stats { grid-template-columns: repeat(2, 1fr); }
  .update-notice-inner { flex-wrap: wrap; }
  .update-notice p { flex-basis: 100%; }
  .level-row { flex-wrap: wrap; }
  .chip { min-width: 40px; }
  .party-code { font-size: 1.8rem; }
}
