/* Curling — the page around the sheet. The sheet itself is a canvas
   (render.js); the scoreboard, the thrower's dock and the panels sit in
   layers over it: upright for solo and pass and play, and face to face a
   seat at each end of the device, the far one turned round. Colours that
   change with the sheet are custom properties under [data-theme]. */

:root {
  --round: "SF Pro Rounded", ui-rounded, "Nunito", "Arial Rounded MT Bold", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --ease: cubic-bezier(0.4, 0.1, 0.2, 1);
  --spring: cubic-bezier(0.25, 0.8, 0.3, 1);
  --t0: #d3282f;
  --t1: #f1bd1f;
  --t0-ink: #c2232a;
  --t1-ink: #a77a00;
  --fw: 100vw;
  --fh: 100vh;
  --ca-accent: var(--accent); /* the accounts SDK's sheets, chip and boards */
}

/* ------------------------------------------------------------- themes */
/* Arena: championship ice under white lights (light) */
:root,
[data-theme="arena"] {
  color-scheme: light;
  --bg-a: #eef3f8;
  --bg-b: #cfd9e4;
  --glow-1: rgba(255, 255, 255, 0.9);
  --glow-2: rgba(31, 95, 191, 0.12);
  --ink: #142033;
  --ink-soft: #536176;
  --paper: #ffffff;
  --paper-2: #eef2f7;
  --glass: rgba(255, 255, 255, 0.86);
  --line: rgba(20, 35, 60, 0.12);
  --accent: #1f5fbf;
  --accent-soft: rgba(31, 95, 191, 0.2);
  --btn-bg: rgba(255, 255, 255, 0.66);
  --btn-hover: rgba(255, 255, 255, 0.95);
  --btn-line: rgba(20, 35, 60, 0.14);
  --primary-a: #2f74d8;
  --primary-b: #1b4fa3;
  --primary-line: #163f82;
  --primary-ink: #ffffff;
  --backdrop: rgba(14, 24, 40, 0.38);
  --toast: rgba(20, 30, 46, 0.92);
  --scrim-top: rgba(238, 243, 248, 0.94);
  --scrim-bottom: rgba(207, 217, 228, 0.6);
  --band-short: #a9b2bf;
  --band-guard: #6fb2e8;
  --band-draw: #3fb27f;
  --band-hit: #f0a23a;
  --band-peel: #e2553f;
}

/* Lake at dusk: deep ice, snow and lanterns (dark) */
[data-theme="lake"] {
  color-scheme: dark;
  --bg-a: #1e2a40;
  --bg-b: #0b111d;
  --glow-1: rgba(255, 150, 110, 0.16);
  --glow-2: rgba(110, 150, 230, 0.14);
  --ink: #f2f4fa;
  --ink-soft: rgba(232, 236, 248, 0.7);
  --paper: #18223a;
  --paper-2: #222e4a;
  --glass: rgba(20, 28, 48, 0.86);
  --line: rgba(200, 215, 255, 0.15);
  --accent: #ffb27a;
  --accent-soft: rgba(255, 178, 122, 0.24);
  --btn-bg: rgba(255, 255, 255, 0.07);
  --btn-hover: rgba(255, 255, 255, 0.13);
  --btn-line: rgba(200, 215, 255, 0.2);
  --primary-a: #f39a62;
  --primary-b: #c8653a;
  --primary-line: #9c4b29;
  --primary-ink: #ffffff;
  --backdrop: rgba(3, 6, 14, 0.62);
  --toast: rgba(28, 38, 64, 0.95);
  --scrim-top: rgba(14, 20, 34, 0.9);
  --scrim-bottom: rgba(8, 12, 22, 0.55);
  --band-short: #6e7891;
  --band-guard: #6aa6e8;
  --band-draw: #46c08a;
  --band-hit: #f3a64a;
  --band-peel: #ef6650;
}

/* Club: warm cream ice, wood and tartan (light, warm) */
[data-theme="club"] {
  color-scheme: light;
  --bg-a: #f3ebdf;
  --bg-b: #d9c9b0;
  --glow-1: rgba(255, 250, 240, 0.9);
  --glow-2: rgba(47, 107, 79, 0.14);
  --ink: #2a2017;
  --ink-soft: #6b5a48;
  --paper: #fffaf2;
  --paper-2: #f2e9db;
  --glass: rgba(255, 250, 242, 0.88);
  --line: rgba(70, 45, 20, 0.14);
  --accent: #2f6b4f;
  --accent-soft: rgba(47, 107, 79, 0.2);
  --btn-bg: rgba(255, 252, 245, 0.7);
  --btn-hover: rgba(255, 252, 245, 0.96);
  --btn-line: rgba(70, 45, 20, 0.16);
  --primary-a: #3a8562;
  --primary-b: #255a41;
  --primary-line: #1d4733;
  --primary-ink: #ffffff;
  --backdrop: rgba(40, 26, 12, 0.38);
  --toast: rgba(42, 32, 23, 0.92);
  --scrim-top: rgba(243, 235, 223, 0.94);
  --scrim-bottom: rgba(217, 201, 176, 0.6);
  --band-short: #b8ab9a;
  --band-guard: #7aa9c9;
  --band-draw: #4f9a6c;
  --band-hit: #d99a3e;
  --band-peel: #c4483c;
}

/* before the script runs, a dark device starts on the lake (no flash) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg-a: #1e2a40;
    --bg-b: #0b111d;
    --ink: #f2f4fa;
    --ink-soft: rgba(232, 236, 248, 0.7);
    --glow-1: rgba(255, 150, 110, 0.16);
    --glow-2: rgba(110, 150, 230, 0.14);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background: linear-gradient(165deg, var(--bg-a), var(--bg-b)) fixed;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; }

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

/* ---------------------------------------------------------- background */
.bg { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
.bg .glow { position: absolute; border-radius: 50%; filter: blur(70px); will-change: transform; }
.bg .g1 { width: 70vmax; height: 70vmax; left: -25vmax; top: -30vmax; background: var(--glow-1); animation: drift 60s ease-in-out infinite alternate; }
.bg .g2 { width: 60vmax; height: 60vmax; right: -25vmax; bottom: -25vmax; background: var(--glow-2); animation: drift 74s ease-in-out infinite alternate-reverse; }
@keyframes drift { to { transform: translate(7vmax, 5vmax) scale(1.1); } }

/* --------------------------------------------------------------- stage */
.stage {
  position: fixed;
  inset: 0;
  z-index: 1;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  transition: filter 0.35s var(--ease);
}
.stage.dimmed canvas { filter: brightness(0.7) saturate(0.8); }

/* chips: a side's colour and its mark (a bead or two bands), never colour alone */
.chip {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #c9ced5, #7d838c 60%, #555b63);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  vertical-align: -3px;
}
.chip::after {
  content: "";
  position: absolute;
  left: 2px;
  right: 2px;
  top: 50%;
  height: 5px;
  margin-top: -2.5px;
  border-radius: 3px;
  background: var(--c);
}
.chip.t0 { --c: var(--t0); }
.chip.t1 { --c: var(--t1); }
.chip.t0::before {
  content: "";
  position: absolute;
  z-index: 1;
  left: 3.5px;
  top: 50%;
  width: 3px;
  height: 3px;
  margin-top: -1.5px;
  border-radius: 50%;
  background: #fff;
}
.chip.t1::before {
  content: "";
  position: absolute;
  z-index: 1;
  left: 4px;
  top: 50%;
  width: 4px;
  height: 5px;
  margin-top: -2.5px;
  border-left: 1.2px solid #fff;
  border-right: 1.2px solid #fff;
}

/* ------------------------------------------- the seats (face to face) */
.frame {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--fw);
  height: var(--fh);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.frame.turned { transform: translate(-50%, -50%) rotate(-90deg); }
.half {
  position: absolute;
  left: 0;
  right: 0;
  height: 50%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0 max(8px, env(safe-area-inset-left)) max(6px, env(safe-area-inset-bottom));
}
.half.near { bottom: 0; }
.half.far { top: 0; transform: rotate(180deg); }
.half .spot { flex: 1 1 auto; display: grid; place-items: end center; min-height: 0; padding: 8px 4px; }
.has-panel .seat .dock-body { display: none; }
.half::after {
  /* the side to throw glows along its edge */
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 0;
  height: 3px;
  border-radius: 3px;
  background: var(--me, var(--t0));
  box-shadow: 0 0 18px 4px var(--me, var(--t0));
  opacity: 0;
  transition: opacity 0.4s;
}
.half.active::after { opacity: 0.85; }
.half.near, .seat[data-team="0"], .panel[data-team="0"], .team-row[data-team="0"] { --me: var(--t0); --me-ink: var(--t0-ink); --them: var(--t1); }
.half.far, .seat[data-team="1"], .panel[data-team="1"], .team-row[data-team="1"] { --me: var(--t1); --me-ink: var(--t1-ink); --them: var(--t0); }

.seat {
  pointer-events: auto;
  width: min(100%, 560px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.seat-bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px -16px rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(14px) saturate(1.1);
  backdrop-filter: blur(14px) saturate(1.1);
  transition: box-shadow 0.3s, border-color 0.3s;
}
.seat.active .seat-bar { border-color: var(--me); box-shadow: 0 0 0 2px color-mix(in oklab, var(--me) 45%, transparent), 0 10px 30px -14px var(--me); }
.seat-bar .who { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1 1 auto; font-weight: 650; font-size: 14px; }
.seat-bar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-score { display: flex; align-items: baseline; gap: 4px; font: 800 18px var(--round); font-variant-numeric: tabular-nums; }
.mini-score i { font-style: normal; color: var(--ink-soft); font-size: 14px; }
.mini-score .theirs { color: var(--ink-soft); }
.mini-score .total { color: var(--me-ink); }
.end-label { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-soft); white-space: nowrap; }
.hammer { width: 15px; height: 15px; flex: 0 0 auto; color: var(--ink); fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------- solo and pass and play: upright layers */
.upright {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  pointer-events: none;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}
.upright .spot { flex: 1 1 auto; display: grid; place-items: center; min-height: 0; padding: 8px 0; }
.upright .spot > .panel.end { align-self: end; }
.scoreboard {
  pointer-events: auto;
  align-self: center;
  width: min(100%, 560px);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px 5px 4px;
  border-radius: 20px;
  background: var(--glass);
  border: 1px solid var(--line);
  box-shadow: 0 12px 34px -18px rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(14px) saturate(1.1);
  backdrop-filter: blur(14px) saturate(1.1);
}
.scoreboard .teams { flex: 1 1 auto; display: grid; gap: 2px; min-width: 0; }
.team-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 2px 8px;
  border-radius: 10px;
  min-height: 27px;
  transition: background 0.3s, box-shadow 0.3s;
}
.team-row.active { background: color-mix(in oklab, var(--me) 15%, transparent); box-shadow: inset 3px 0 0 var(--me); }
.team-row .name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; font-size: 14.5px; }
.team-row .total { font: 800 21px/1 var(--round); min-width: 1.5em; text-align: right; color: var(--me-ink); font-variant-numeric: tabular-nums; }
.end-box { display: grid; place-items: center; min-width: 64px; padding: 0 2px 0 8px; border-left: 1px solid var(--line); text-align: center; }
.end-box b { font: 700 12px/1.25 var(--sans); letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-soft); }
.total { display: inline-block; perspective: 120px; }
.total span { display: inline-block; transform-origin: 50% 50%; }
.total.flip span { animation: flip 0.6s var(--spring); }
@keyframes flip {
  0% { transform: rotateX(0); }
  45% { transform: rotateX(90deg); opacity: 0.2; }
  55% { transform: rotateX(-90deg); opacity: 0.2; }
  100% { transform: rotateX(0); }
}
.pips { display: inline-flex; gap: 3px; flex: 0 0 auto; }
.pips i { width: 7px; height: 7px; border-radius: 50%; border: 1.3px solid var(--me); opacity: 0.55; }
.pips i.on { background: var(--me); opacity: 1; }

.dock {
  pointer-events: auto;
  align-self: center;
  width: min(100%, 560px);
}
.dock-body {
  min-height: 116px;
  padding: 10px;
  border-radius: 22px;
  background: var(--glass);
  border: 1px solid var(--line);
  box-shadow: 0 16px 40px -18px rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(16px) saturate(1.15);
  backdrop-filter: blur(16px) saturate(1.15);
  position: relative;
  animation: dockin 0.28s var(--ease);
}
@keyframes dockin { from { opacity: 0.4; transform: translateY(4px); } }
.dock-body.aim {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "turns throw" "weight weight";
  gap: 8px 10px;
  align-items: center;
}
.turns { grid-area: turns; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.turn {
  appearance: none;
  min-width: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 46px;
  padding: 4px 8px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s, transform 0.15s;
}
.turn svg { width: 24px; height: 24px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; color: var(--me-ink, var(--accent)); }
.turn .tx { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.turn b { font: 700 14px var(--round); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turn small { font-size: 11px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turn[aria-checked="true"] { border-color: var(--me, var(--accent)); background: var(--paper); box-shadow: 0 0 0 3px color-mix(in oklab, var(--me, var(--accent)) 25%, transparent); }
.turn:active { transform: scale(0.97); }
.throw { grid-area: throw; min-width: 96px; min-height: 50px; font: 700 17px var(--round); }
.weight { grid-area: weight; display: grid; gap: 5px; }
.wlabel { font-size: 13px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wlabel b { color: var(--ink); font: 700 14px var(--round); }
.gauge {
  position: relative;
  display: flex;
  height: 26px;
  border-radius: 13px;
  overflow: visible;
  cursor: ew-resize;
  touch-action: none;
  box-shadow: inset 0 0 0 1px var(--line);
}
.gauge .band { width: var(--w); height: 100%; opacity: 0.38; transition: opacity 0.2s; }
.gauge .band:first-child { border-radius: 13px 0 0 13px; }
.gauge .band:nth-last-child(2) { border-radius: 0 13px 13px 0; }
.gauge .band.short { background: var(--band-short); }
.gauge .band.guard { background: var(--band-guard); }
.gauge .band.draw { background: var(--band-draw); }
.gauge .band.hit { background: var(--band-hit); }
.gauge .band.peel { background: var(--band-peel); }
.gauge[data-band="short"] .band.short, .gauge[data-band="guard"] .band.guard, .gauge[data-band="draw"] .band.draw, .gauge[data-band="hit"] .band.hit, .gauge[data-band="peel"] .band.peel { opacity: 0.9; }
.gauge .marker {
  position: absolute;
  top: -5px;
  bottom: -5px;
  left: var(--g, 50%);
  width: 6px;
  margin-left: -3px;
  border-radius: 3px;
  background: var(--ink);
  box-shadow: 0 0 0 2px var(--paper), 0 2px 6px rgba(0, 0, 0, 0.35);
}
.dock-body.sweep, .dock-body.ai, .dock-body.wait {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px 10px;
}
.dock-body .msg { margin: 0; display: flex; align-items: center; gap: 8px; font: 650 15px/1.3 var(--round); min-width: 0; }
.dock-body .msg svg { width: 26px; height: 26px; flex: 0 0 auto; fill: none; stroke: var(--me-ink, var(--accent)); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dock-body.sweep .msg { animation: urge 1.1s ease-in-out infinite; }
@keyframes urge { 50% { transform: translateX(3px); } }
.dock-body.wait { grid-template-columns: 1fr; text-align: center; }
.dock-body.wait .msg { justify-content: center; color: var(--ink-soft); font-weight: 600; }
.sweep-btn { min-width: 112px; min-height: 52px; touch-action: none; }
.sweep-btn.on { background: color-mix(in oklab, var(--me, var(--accent)) 30%, var(--paper)); border-color: var(--me, var(--accent)); }
.meter { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--paper-2); overflow: hidden; box-shadow: inset 0 0 0 1px var(--line); }
.meter i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--band-guard), var(--me, var(--accent))); transform-origin: 0 50%; transform: scaleX(var(--k, 0)); transition: transform 0.08s linear; }
.btn.ff { min-width: 104px; }
.btn.ff.on { background: color-mix(in oklab, var(--accent) 22%, var(--paper)); border-color: var(--accent); }
.notice {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translate(-50%, 6px);
  margin: 0;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--toast);
  color: #fff;
  font-size: 13.5px;
  white-space: nowrap;
  max-width: 96%;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
.notice.show { opacity: 1; transform: translate(-50%, 0); }

/* short screens and landscape: one row */
@media (orientation: landscape) and (max-height: 560px) {
  .upright .dock-body { min-height: 68px; padding: 8px; }
  .upright .dock-body.aim { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr) auto; grid-template-areas: "turns weight throw"; }
  .upright .turn { min-height: 44px; }
  .upright .turn small { display: none; }
  .scoreboard { width: min(100%, 520px); padding: 3px 8px 3px 2px; }
  .team-row { min-height: 23px; }
  .team-row .total { font-size: 18px; }
}
@media (max-width: 380px) {
  .turn svg { width: 20px; height: 20px; }
  .turn b { font-size: 13px; }
  .turn small { font-size: 10.5px; }
  .throw { min-width: 92px; }
  .pips i { width: 6px; height: 6px; }
}
/* face to face on a phone: compact seats */
[data-mode="face"] .dock-body { min-height: 104px; }
@media (max-height: 760px) and (orientation: portrait), (max-width: 760px) and (orientation: landscape) {
  [data-mode="face"] .dock-body { min-height: 96px; padding: 8px; }
  [data-mode="face"] .dock-body.aim { gap: 6px 8px; }
  [data-mode="face"] .turn { min-height: 44px; }
  [data-mode="face"] .turn small { display: none; }
  [data-mode="face"] .gauge { height: 22px; }
  [data-mode="face"] .seat-bar { gap: 6px; }
}

/* ------------------------------------------------------------- panels */
.panel {
  position: relative;
  pointer-events: auto;
  width: min(100%, 380px);
  max-height: 100%;
  overflow: auto;
  background: var(--glass);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 16px 16px 14px;
  text-align: center;
  box-shadow: 0 18px 50px -18px rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
  backdrop-filter: blur(14px) saturate(1.15);
  animation: pop 0.32s var(--spring);
}
.panel.end { width: min(100%, 420px); }
@keyframes pop { from { opacity: 0; transform: scale(0.94) translateY(6px); } }
.panel .glow {
  position: absolute;
  inset: -50% -20% auto;
  height: 80%;
  background: radial-gradient(ellipse at 50% 45%, color-mix(in oklab, var(--me) 30%, transparent), transparent 68%);
  pointer-events: none;
}
.panel h2 { position: relative; margin: 0; font: 700 23px/1.15 var(--round); letter-spacing: 0.01em; }
.panel.won h2 { color: var(--me-ink); }
.panel p { position: relative; margin: 4px 0 10px; font-size: 14px; color: var(--ink-soft); line-height: 1.4; }
.panel .result-line { font: 650 16px/1.35 var(--round); color: var(--ink); margin-top: 6px; }
.panel .note { font-size: 12.5px; margin: 8px 0 10px; }
.panel .score {
  position: relative;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
  margin: 6px 0 2px;
  font: 800 40px/1 var(--round);
  font-variant-numeric: tabular-nums;
}
.panel .score .mine { color: var(--me-ink); }
.panel .score .dash { font-size: 24px; color: var(--ink-soft); }
.panel .chips { position: relative; display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin: 10px 0 12px; }
.panel .chips span {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--paper-2);
  font-size: 10.5px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.panel .chips b { font: 700 14px var(--round); letter-spacing: 0; text-transform: none; color: var(--ink); }
.panel .row { position: relative; display: flex; gap: 8px; }
.panel .row + .row { margin-top: 8px; }
.panel .row .btn { min-width: 0; }
.panel .tools { position: relative; display: flex; justify-content: center; gap: 6px; margin-top: 8px; }
.panel .tools .icon-btn { width: 44px; height: 44px; border: 1px solid var(--btn-line); background: var(--btn-bg); }
.btn.quiet { background: transparent; border-color: transparent; color: var(--ink-soft); }

/* the end-by-end scoreboard */
.endboard-wrap { position: relative; overflow-x: auto; margin: 8px 0 4px; border-radius: 12px; background: var(--paper-2); }
table.endboard { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.endboard th, table.endboard td { padding: 5px 4px; text-align: center; border: 0; white-space: nowrap; }
table.endboard th { font-size: 10.5px; font-weight: 650; color: var(--ink-soft); letter-spacing: 0.04em; }
table.endboard td.side, table.endboard th.side { text-align: left; padding-left: 8px; max-width: 7.5em; overflow: hidden; text-overflow: ellipsis; }
table.endboard td.side { font-weight: 650; width: 38%; max-width: 9em; }
table.endboard td.side .chip { margin-right: 6px; }
table.endboard td.pts { font: 800 15px var(--round); color: var(--me-ink); }
table.endboard td.zero { color: var(--ink-soft); opacity: 0.55; }
table.endboard td.total, table.endboard th.total { font: 800 15px var(--round); padding: 5px 10px; background: color-mix(in oklab, var(--ink) 7%, transparent); }
table.endboard .now { background: color-mix(in oklab, var(--accent) 12%, transparent); }
table.endboard tbody tr:first-child td { border-bottom: 1px solid var(--line); }
table.endboard tr[data-team="0"] { --me: var(--t0); --me-ink: var(--t0-ink); }
table.endboard tr[data-team="1"] { --me: var(--t1); --me-ink: var(--t1-ink); }
table.endboard td.pts.now { animation: tickin 0.6s var(--spring); }
@keyframes tickin { from { transform: scale(1.6); } }

@media (max-height: 640px) and (orientation: portrait), (max-width: 760px) and (orientation: landscape) {
  .half .panel { padding: 12px 12px 10px; border-radius: 18px; }
  .half .panel h2 { font-size: 20px; }
  .half .panel .score { font-size: 30px; margin-top: 2px; }
  .half .panel p { margin: 2px 0 6px; font-size: 13px; }
  .half .panel .chips { margin: 4px 0 8px; }
  .half .panel .btn { min-height: 44px; padding: 8px 10px; }
  .half .panel table.endboard th, .half .panel table.endboard td { padding: 3px 3px; }
  .half .panel .note { margin: 4px 0 6px; font-size: 12px; }
  .half .panel .chips span { padding: 3px 8px; }
  .half .panel .glow { display: none; }
}
@media (max-height: 760px) and (orientation: portrait) {
  .half .panel .chips { display: none; }
  .half .panel .tools { display: none; }
}

/* --------------------------------------------------------------- menu */
.menu {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: linear-gradient(180deg, var(--scrim-top) 0, transparent 22%, transparent 40%, var(--scrim-bottom) 100%);
  animation: fade 0.35s var(--ease);
}
@keyframes fade { from { opacity: 0; } }
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 10px 10px 4px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.brand img { width: 40px; height: 40px; flex: 0 0 auto; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3)); }
.brand span { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand b { font: 700 22px var(--round); letter-spacing: 0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { font-size: 11px; color: var(--ink-soft); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; }
.account-chip { display: flex; align-items: center; margin-left: 4px; }
.account-chip:empty { display: none; }

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}
.icon-btn:hover { background: var(--btn-bg); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg, .btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.pause svg { stroke-width: 2.4; }

.card {
  width: min(100% - 20px, 560px);
  margin: auto auto 12px;
  padding: 16px 16px 12px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: 0 24px 60px -24px rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  backdrop-filter: blur(18px) saturate(1.2);
}
.card .label, .opt-row h3 {
  margin: 0 0 8px 2px;
  font: 700 11px var(--sans);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mode {
  appearance: none;
  display: grid;
  grid-template-rows: auto auto auto;
  justify-items: start;
  gap: 2px;
  text-align: left;
  padding: 10px 11px;
  min-height: 64px;
  border-radius: 16px;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s, transform 0.15s;
}
.mode svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; color: var(--accent); }
.mode b { font: 700 15.5px var(--round); }
.mode small { font-size: 12px; color: var(--ink-soft); line-height: 1.25; }
.mode:active { transform: scale(0.98); }
.mode[aria-checked="true"] { border-color: var(--accent); background: var(--paper); box-shadow: 0 0 0 3px var(--accent-soft); }

.opts-grid { display: grid; gap: 10px; margin: 12px 0 14px; }
.opt-row { display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 8px; }
.opt-row h3 { margin: 0; }
.opts { display: flex; flex-wrap: wrap; gap: 6px; }
.opt {
  appearance: none;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  font: 600 14px var(--sans);
  padding: 7px 14px;
  min-height: 44px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s, box-shadow 0.2s;
}
.opt:active { transform: scale(0.97); }
.opt[aria-checked="true"] { border-color: var(--accent); background: var(--paper); box-shadow: 0 0 0 3px var(--accent-soft); }
.hint { margin: 10px 4px 2px; font-size: 12.5px; line-height: 1.4; color: var(--ink-soft); text-align: center; }

.btn {
  appearance: none;
  flex: 1;
  border: 1px solid var(--btn-line);
  background: var(--btn-bg);
  color: var(--ink);
  font: 600 15px var(--sans);
  padding: 10px 14px;
  min-height: 46px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s, box-shadow 0.2s, filter 0.2s;
}
.btn svg { width: 19px; height: 19px; }
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: linear-gradient(180deg, var(--primary-a), var(--primary-b));
  color: var(--primary-ink);
  border-color: var(--primary-line);
  box-shadow: 0 6px 16px -6px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.play { width: 100%; min-height: 54px; font: 700 18px var(--round); border-radius: 16px; }
.btn.play svg { width: 20px; height: 20px; }
.btn.wide { width: 100%; margin-top: 4px; }

@media (orientation: landscape) and (max-height: 560px) {
  .top { padding-top: 4px; }
  .brand img { width: 34px; height: 34px; }
  .brand b { font-size: 19px; }
  .card {
    width: min(100% - 24px, 780px);
    margin-bottom: 8px;
    display: grid;
    grid-template-columns: 1fr 1.15fr;
    grid-template-areas: "label label" "modes opts" "play play" "hint hint";
    column-gap: 16px;
    padding: 12px 14px 8px;
  }
  .card .label { grid-area: label; }
  .modes { grid-area: modes; grid-template-columns: 1fr; align-content: start; gap: 6px; }
  .mode { min-height: 44px; padding: 6px 10px; grid-template-columns: auto 1fr; grid-template-rows: auto; align-items: center; column-gap: 8px; }
  .mode svg { width: 24px; height: 24px; }
  .mode small { display: none; }
  .opts-grid { grid-area: opts; margin: 0; gap: 6px; }
  .opt-row { grid-template-columns: 74px 1fr; }
  .opt { min-height: 40px; padding: 5px 12px; }
  .btn.play { grid-area: play; margin-top: 10px; min-height: 46px; }
  .hint { grid-area: hint; margin-top: 6px; }
}
@media (orientation: landscape) and (max-height: 420px) {
  .hint { display: none; }
  .brand small { display: none; }
}
@media (max-width: 400px) {
  .brand small { letter-spacing: 0.03em; font-size: 10.5px; }
  .top { padding-left: 10px; padding-right: 4px; }
  .brand { gap: 7px; }
  .brand img { width: 32px; height: 32px; }
  .brand b { font-size: 18px; letter-spacing: 0; }
  .nav { gap: 0; }
}
@media (max-width: 520px) and (orientation: portrait) {
  .modes { grid-template-columns: 1fr; gap: 6px; }
  .mode { grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; min-height: 54px; padding: 8px 10px; align-items: center; }
  .mode svg { grid-row: 1 / 3; width: 28px; height: 28px; }
  .opt-row { grid-template-columns: 1fr; gap: 5px; }
  .opts .opt { flex: 1 1 0; padding-left: 8px; padding-right: 8px; }
}
@media (max-width: 520px) and (orientation: portrait) and (max-height: 700px) {
  .mode small { display: none; }
  .mode { min-height: 46px; }
}

/* -------------------------------------------------------- sheets, dialogs */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--backdrop);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade 0.25s;
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  z-index: 21;
  max-width: 560px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.3);
  padding-bottom: env(safe-area-inset-bottom);
  animation: rise 0.32s var(--ease);
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet header { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 6px 22px; flex: 0 0 auto; }
.sheet h2 { font: 700 23px var(--round); margin: 0; letter-spacing: 0.01em; }
.sheet-body {
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 2px 22px 26px;
  font-size: 15px;
  line-height: 1.55;
  -webkit-user-select: text;
  user-select: text;
  touch-action: pan-y;
}
.sheet-body h3 { font: 700 16px var(--round); margin: 20px 0 8px; color: var(--ink); }
.sheet-body h3:first-child { margin-top: 6px; }
.prose p { margin: 0 0 12px; }
.prose ul { margin: 0; padding-left: 20px; }
.prose li { margin: 4px 0; }
.prose li b { font-weight: 600; }
.muted { color: var(--ink-soft); }
.small { font-size: 12.5px; margin: 6px 2px 0; }
.about { font-size: 13px; margin-top: 18px; text-align: center; }
.about b { display: block; font-weight: 600; color: var(--ink); }
@media (min-width: 700px) and (min-height: 560px) {
  .sheet { bottom: auto; top: 50%; transform: translateY(-50%); border-radius: 24px; max-height: 84dvh; animation: popm 0.28s var(--ease); }
}
@media (orientation: landscape) and (max-height: 560px) {
  .sheet { max-height: 94dvh; }
}
@keyframes popm { from { opacity: 0; transform: translateY(-50%) scale(0.96); } }

/* ------------------------------------------------------------- results */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; margin: 4px 0 6px; }
.tile { background: var(--paper-2); border-radius: 16px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.tile small { font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.tile b { font: 800 22px var(--round); font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12px; color: var(--ink-soft); }
.sheet-body table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.sheet-body th { text-align: left; vertical-align: bottom; font-weight: 600; color: var(--ink-soft); font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; padding: 4px; border-bottom: 1px solid var(--line); }
.sheet-body td { padding: 7px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
.sheet-body th.num, .sheet-body td.num { text-align: right; }
.sheet-body td.name { font-weight: 600; max-width: 9em; overflow: hidden; text-overflow: ellipsis; }
.sheet-body td.score { font: 700 14px var(--round); }
.sheet-body td.score .w { color: var(--accent); }
.sheet-body td.who { max-width: 11em; overflow: hidden; text-overflow: ellipsis; color: var(--ink-soft); }
.note { font-size: 12.5px; color: var(--ink-soft); margin: 16px 0 0; }
@media (max-width: 420px) {
  table.recent { font-size: 12.5px; }
  table.recent td, table.recent th { padding-left: 2px; padding-right: 2px; }
}
/* the friends' board, drawn by the SDK in the sheet's font and colours */
.friends { margin-top: 22px; border-top: 1px solid var(--line); }
.friends-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin: 16px 0 8px; }
.sheet-body .friends-head h3 { margin: 0; }
.friends-head .opt { padding: 6px 12px; font-size: 13px; min-height: 40px; }
.friends-board .ca-board-title:empty { display: none; }
.friends-board .ca-board-list li { padding: 7px 8px; }
.friends-board .ca-board-score { font-family: var(--round); font-size: 15px; }
.friends-board .ca-board-note { color: var(--ink-soft); opacity: 1; }

/* ------------------------------------------------------------- settings */
.swatch {
  display: inline-block;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: radial-gradient(circle, var(--si) 0 22%, var(--sb) 23% 46%, var(--si) 47% 62%, var(--sa) 63% 100%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}
.swatch.auto { background: linear-gradient(135deg, #2b4a63 50%, #f2f6fa 50%); }
.toggle { display: flex; align-items: center; gap: 12px; margin-top: 16px; cursor: pointer; font-size: 15px; line-height: 1.35; min-height: 32px; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .track { flex: 0 0 auto; width: 46px; height: 28px; border-radius: 999px; background: var(--line); position: relative; transition: background 0.25s; box-shadow: inset 0 0 0 1px var(--line); }
.toggle .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.25s var(--ease); }
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::after { transform: translateX(18px); }
.toggle input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.field { display: grid; gap: 4px; margin-top: 10px; }
.field span { font-size: 12.5px; color: var(--ink-soft); display: flex; align-items: center; gap: 6px; }
.field input {
  appearance: none;
  font: 500 16px var(--sans);
  color: var(--ink);
  background: var(--paper-2);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  min-height: 44px;
  -webkit-user-select: text;
  user-select: text;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 104px);
  transform: translate(-50%, -50%) translateY(6px);
  z-index: 15;
  background: var(--toast);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  width: max-content;
  max-width: min(88vw, 420px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.toast.show { opacity: 1; transform: translate(-50%, -50%); }

@media (prefers-reduced-motion: reduce) {
  .bg .glow { animation: none; }
  .panel, .sheet, .backdrop, .menu, .dock-body, .dock-body.sweep .msg, .total.flip span, table.endboard td.pts.now { animation: none; }
  .stage canvas { transition: none; }
}
