/* Carrom — the page around the board. The board itself is a canvas
   (render.js); the seat plates and panels are DOM layered over it, turned
   to face their players when the device lies on a table. Light and dark
   follow the system; the board look sets the accent (--accent, from JS). */

: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);
  --accent: #b3262d;
  --accent-ink: #c8343b;
  --accent-soft: rgba(179, 38, 45, 0.22);
  --ca-accent: #b3262d;
  --man-w: #f2deb4;
  --man-w-light: #fff3d6;
  --man-w-dark: #c9a66c;
  --man-b: #33211a;
  --man-b-light: #5a3d2e;
  --man-b-dark: #160c08;
  --man-q: #c81e2e;
  --bx: 50%;
  --by: 50%;
  --bs: 300px;
  --depth: 60px;

  color-scheme: light;
  --bg-a: #f6efe3;
  --bg-b: #dccbb0;
  --lamp: rgba(255, 246, 222, 0.95);
  --ink: #2a1e15;
  --ink-soft: #6b5a4b;
  --paper: #fffaf2;
  --paper-2: #f2e9db;
  --glass: rgba(255, 250, 242, 0.88);
  --line: rgba(60, 35, 15, 0.14);
  --btn-bg: rgba(255, 250, 242, 0.7);
  --btn-hover: rgba(255, 255, 255, 0.95);
  --btn-line: rgba(60, 35, 15, 0.16);
  --primary-ink: #ffffff;
  --backdrop: rgba(30, 20, 10, 0.38);
  --toast: rgba(36, 24, 16, 0.92);
  --scrim-top: rgba(246, 239, 227, 0.92);
  --scrim-bottom: rgba(220, 203, 176, 0.6);
  --shadow: rgba(40, 20, 5, 0.45);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg-a: #261b14;
    --bg-b: #0d0907;
    --lamp: rgba(255, 205, 140, 0.16);
    --ink: #f4eadb;
    --ink-soft: rgba(244, 234, 219, 0.68);
    --paper: #221913;
    --paper-2: #2f241c;
    --glass: rgba(34, 25, 19, 0.88);
    --line: rgba(255, 225, 190, 0.14);
    --btn-bg: rgba(255, 240, 220, 0.07);
    --btn-hover: rgba(255, 240, 220, 0.13);
    --btn-line: rgba(255, 225, 190, 0.18);
    --backdrop: rgba(5, 3, 2, 0.6);
    --toast: rgba(52, 38, 28, 0.96);
    --scrim-top: rgba(20, 14, 10, 0.9);
    --scrim-bottom: rgba(13, 9, 7, 0.55);
    --shadow: rgba(0, 0, 0, 0.6);
  }
  :root[data-board="club"] { --accent-ink: #e65a60; }
}

* { 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: radial-gradient(120% 90% at 50% 38%, 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 .lamp {
  position: absolute;
  left: 50%;
  top: 40%;
  width: 130vmax;
  height: 130vmax;
  margin: -65vmax 0 0 -65vmax;
  border-radius: 50%;
  background: radial-gradient(circle, var(--lamp) 0, transparent 55%);
  animation: breathe 9s ease-in-out infinite alternate;
}
@keyframes breathe { to { transform: scale(1.06); opacity: 0.85; } }

/* --------------------------------------------------------------- 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;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  transition: opacity 0.35s var(--ease), filter 0.35s var(--ease);
}
.stage.dimmed canvas { opacity: 0.55; filter: saturate(0.8); }

/* ------------------------------------------------------- the scoreboard */
.scoreboard {
  position: absolute;
  left: 0;
  right: 0;
  top: max(var(--sbt, 0px), env(safe-area-inset-top));
  padding: 8px max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
  pointer-events: none;
  animation: fade 0.35s var(--ease);
}
.sb-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.sb-top .pause-btn { pointer-events: auto; border: 1px solid var(--btn-line); background: var(--btn-bg); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.board-label { margin: 0; font: 700 12px var(--sans); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.plates { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-width: 640px; margin: 0 auto; }
.plates.four { grid-template-columns: 1fr 1fr; grid-auto-rows: auto; }
.landscape .scoreboard { top: 0; bottom: 0; padding-top: max(10px, env(safe-area-inset-top)); }
.scoreboard .plate { padding-top: 9px; }
.scoreboard .pts { position: absolute; top: -9px; right: 12px; padding: 2px 8px; font-size: 11.5px; border: 1px solid var(--line); }
.scoreboard .due { right: auto; left: 12px; }
.landscape .sb-top { position: absolute; left: max(10px, env(safe-area-inset-left)); top: max(8px, env(safe-area-inset-top)); flex-direction: column; align-items: flex-start; }
.landscape .plates {
  position: absolute;
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  top: 50%;
  transform: translateY(-50%);
  max-width: none;
  margin: 0;
  grid-template-columns: minmax(0, calc((100% - var(--bs)) / 2 - 18px)) minmax(0, calc((100% - var(--bs)) / 2 - 18px));
  justify-content: space-between;
  grid-auto-flow: column;
  grid-template-rows: auto;
  row-gap: 10px;
}
.landscape .plates.four { grid-template-rows: auto auto; }

/* ------------------------------------------------- face to face: the ring */
.ring { position: absolute; inset: 0; pointer-events: none; }
/* each seat: placed by its centre and its own size, then turned to face its edge */
.ring .seat, .frame .side {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--w);
  height: var(--h);
  transform: translate(-50%, -50%) rotate(var(--r));
  pointer-events: none;
}
.ring .plate { position: absolute; inset: 0; padding: 4px 6px 4px 8px; pointer-events: auto; }

/* short plates (four players round a phone): the essentials only */
.ring .seat.tight .plate { gap: 6px; padding: 3px 4px 3px 6px; }
.ring .seat.tight .pips, .ring .seat.tight .pts { display: none; }
.ring .seat.tight .man { width: 22px; height: 22px; }
.ring .seat.tight .man::before { inset: 3px; }
.ring .seat.tight .man::after { inset: 7px; }
.ring .seat.tight .who .name { font-size: 13px; }
.ring .seat.tight .who .msg { font-size: 10.5px; }
.ring .seat.tight .plate .more { width: 36px; height: 36px; }

/* ---------------------------------------------------------- the plates */
.plate {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 7px 10px;
  border-radius: 16px;
  background: var(--glass);
  border: 1px solid var(--line);
  box-shadow: 0 8px 22px -14px var(--shadow);
  -webkit-backdrop-filter: blur(12px) saturate(1.15);
  backdrop-filter: blur(12px) saturate(1.15);
  pointer-events: auto;
  transition: border-color 0.3s, box-shadow 0.3s, transform 0.3s var(--spring);
}
.plate.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft), 0 6px 26px -6px var(--accent);
  animation: glow 1.6s ease-in-out infinite alternate;
}
@keyframes glow { to { box-shadow: 0 0 0 4px var(--accent-soft), 0 8px 34px -4px var(--accent); } }
.man {
  position: relative;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: radial-gradient(circle at 42% 38%, var(--man-w-light), var(--man-w) 52%, var(--man-w-dark) 90%);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35), inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}
.man::before, .man::after { content: ""; position: absolute; border-radius: 50%; }
.man::before { inset: 4px; box-shadow: 0 0 0 1.2px rgba(90, 55, 20, 0.45), inset 0 0 0 0.6px rgba(255, 255, 255, 0.35); }
.man::after { inset: 10px; box-shadow: 0 0 0 1.2px rgba(90, 55, 20, 0.45); }
.man.b { background: radial-gradient(circle at 42% 38%, var(--man-b-light), var(--man-b) 52%, var(--man-b-dark) 90%); }
.coach {
  position: absolute;
  left: 50%;
  top: calc(var(--by) + var(--bs) / 2 + 16px);
  transform: translateX(-50%);
  width: min(calc(var(--bs) - 24px), 420px);
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
  color: var(--ink-soft);
  pointer-events: none;
  animation: fade 0.6s var(--ease);
}
.landscape .coach { display: none; }
.man.b { box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35), inset 0 0 0 1px rgba(255, 225, 190, 0.25); }
.man.b::before, .man.b::after { box-shadow: 0 0 0 1.2px rgba(0, 0, 0, 0.5), 0 0 0 2px rgba(255, 220, 180, 0.18); }
.who { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; line-height: 1.15; }
.who .name { font: 700 15px var(--round); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .msg { font-size: 11.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.who .msg.on { color: var(--accent-ink); font-weight: 600; }
.count { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; flex: 0 0 auto; }
.count b { font: 800 15px var(--round); font-variant-numeric: tabular-nums; }
.pips { display: flex; gap: 2px; }
.pip { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.pip.in.w { background: var(--man-w); box-shadow: 0 0 0 1px rgba(90, 55, 20, 0.45); }
.pip.in.b { background: var(--man-b); box-shadow: 0 0 0 1px rgba(255, 220, 180, 0.25); }
.pip.q { background: var(--man-q); box-shadow: 0 0 0 1.5px #ffd76a; }
.pip.q.pending { opacity: 0.55; }
.pts { flex: 0 0 auto; font: 700 12.5px var(--round); padding: 3px 8px; border-radius: 999px; background: var(--paper-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.due { position: absolute; top: -8px; right: 10px; font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--accent); color: #fff; }
.plate .bubble {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  width: max-content;
  max-width: 94%;
  padding: 7px 14px;
  border-radius: 14px;
  background: var(--toast);
  color: #fff;
  font: 600 13.5px/1.3 var(--sans);
  text-align: center;
  pointer-events: none;
  box-shadow: 0 8px 22px -8px rgba(0, 0, 0, 0.5);
}
.plate .bubble::after { content: ""; position: absolute; left: 50%; top: 100%; margin-left: -6px; border: 6px solid transparent; border-top-color: var(--toast); }
.plate .bubble.fresh { animation: bubble 0.35s var(--spring); }
@keyframes bubble { from { opacity: 0; transform: translateX(-50%) translateY(6px) scale(0.92); } }
.plate .more { flex: 0 0 auto; width: 40px; height: 40px; margin: -4px -2px -4px 0; }
@media (max-width: 420px) {
  .scoreboard .plate { padding: 6px 8px; gap: 6px; }
  .scoreboard .man { width: 24px; height: 24px; }
  .scoreboard .man::before { inset: 3px; }
  .scoreboard .man::after { inset: 8px; }
  .scoreboard .pips { display: none; }
  .scoreboard .pts { padding: 2px 6px; font-size: 11.5px; }
  .who .name { font-size: 14px; }
}
.landscape .scoreboard .plate { flex-wrap: wrap; }
@media (min-width: 1000px) and (min-height: 600px) {
  .plate { padding: 11px 14px; gap: 10px; border-radius: 18px; }
  .who .name { font-size: 17px; }
  .who .msg { font-size: 12.5px; }
  .man { width: 36px; height: 36px; }
  .man::before { inset: 5px; }
  .man::after { inset: 12px; }
  .count b { font-size: 17px; }
  .pip { width: 7px; height: 7px; }
  .board-label { font-size: 13px; }
}
.landscape .scoreboard .pips { display: flex; }

/* ------------------------------------------------- panels (over the board) */
.frame { position: absolute; inset: 0; pointer-events: none; }
/* a seat's panel gets the room the layout gives it (panelRegion) and
   tightens itself to fit — never a scrolling box */
.frame .side { display: flex; align-items: center; justify-content: center; padding: 10px; container-type: size; }
.frame .side .panel { max-height: 100%; width: min(100%, 360px); }
.frame[data-mode="four"] .side .panel { width: min(100%, 320px); }
.frame[data-mode="four"] .panel p:not(.q), .frame[data-mode="four"] .panel .kicker, .frame[data-mode="four"] .panel .tools { display: none; }
.upright {
  position: absolute;
  inset: 0;
  container-type: size;
  display: grid;
  place-items: center;
  pointer-events: none;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.panel {
  position: relative;
  pointer-events: auto;
  width: min(100%, 360px);
  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 var(--shadow);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
  backdrop-filter: blur(14px) saturate(1.15);
  animation: pop 0.32s var(--spring);
  overscroll-behavior: contain;
}
.upright .panel { width: min(100%, 380px); padding: 22px 20px 18px; }
@keyframes pop { from { opacity: 0; transform: scale(0.94) translateY(8px); } }
.panel .glow {
  position: absolute;
  inset: -50% -20% auto;
  height: 80%;
  background: radial-gradient(ellipse at 50% 45%, color-mix(in oklab, var(--accent) 30%, transparent), transparent 68%);
  pointer-events: none;
}
.panel h2 { position: relative; margin: 0; font: 700 22px/1.15 var(--round); letter-spacing: 0.01em; }
.panel.won h2 { color: var(--accent-ink); }
.panel .kicker { position: relative; display: block; font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); margin: 2px 0 4px; }
.panel p { position: relative; margin: 4px 0 10px; font-size: 14px; color: var(--ink-soft); line-height: 1.4; }
.panel p.streak { color: var(--accent-ink); font-weight: 600; }
.panel .score {
  position: relative;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin: 6px 0 4px;
  font: 800 38px/1 var(--round);
  font-variant-numeric: tabular-nums;
}
.panel .score small { font-size: 16px; color: var(--ink-soft); margin-left: -6px; }
.panel .score .mine { color: var(--accent-ink); }
.panel .score .dash { font-size: 22px; color: var(--ink-soft); }
.chips { position: relative; display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin: 8px 0 10px; }
.chips span {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--paper-2);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.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: 10px; }
.panel .tools .icon-btn { border: 1px solid var(--btn-line); background: var(--btn-bg); }
/* little room (a phone's half, a landscape phone): a compact panel … */
@container (max-height: 450px) {
  .panel, .upright .panel { padding: 10px 12px 10px; border-radius: 18px; }
  .panel h2 { font-size: 19px; }
  .panel .kicker { margin: 0 0 2px; }
  .panel .score { font-size: 28px; margin: 2px 0; }
  .panel p { margin: 2px 0 6px; font-size: 13px; }
  .chips { margin: 4px 0 6px; }
  .panel .btn { min-height: 44px; padding: 6px 10px; font-size: 14.5px; }
  .panel .row { gap: 6px; }
  .panel .row + .row { margin-top: 6px; }
  .panel .tools { margin-top: 6px; }
  .panel .tools .icon-btn { width: 40px; height: 40px; }
}
/* … and with very little, only what you act on: the title, the score, the buttons */
@container (max-height: 330px) {
  .panel p:not(.q), .panel .tools, .panel .chips, .panel .kicker { display: none; }
  .panel h2 { font-size: 18px; }
  .panel .score { font-size: 24px; }
}

/* --------------------------------------------------------------- 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 18%, transparent 46%, var(--scrim-bottom) 100%);
  animation: fade 0.35s var(--ease);
  pointer-events: none;
}
.menu > * { pointer-events: auto; }
@keyframes fade { from { opacity: 0; } }
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  max-width: 760px;
  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;
  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; }

.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 var(--shadow);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  backdrop-filter: blur(18px) saturate(1.2);
  animation: rise 0.45s var(--spring);
}
.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;
  text-align: left;
  gap: 2px;
  padding: 10px 12px;
  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-ink); margin-bottom: 2px; }
.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, opacity 0.2s;
}
.btn svg { width: 19px; height: 19px; }
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn.primary {
  background: linear-gradient(180deg, color-mix(in oklab, var(--accent) 82%, #fff), var(--accent));
  color: var(--primary-ink);
  border-color: color-mix(in oklab, var(--accent) 70%, #000);
  box-shadow: 0 6px 16px -6px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  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%; flex: none; }

@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: 1.25fr 1fr;
    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; align-content: start; }
  .mode { min-height: 56px; padding: 8px 10px; }
  .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: 460px) and (orientation: portrait) {
  .opt-row { grid-template-columns: 1fr; gap: 5px; }
  .opts .opt { flex: 1 1 0; padding-left: 8px; padding-right: 8px; }
  .mode { padding: 8px 9px; }
  .mode small { font-size: 11px; }
}
@media (max-width: 370px) {
  .opt { padding: 6px 10px; font-size: 13.5px; }
  .mode svg { display: none; }
}

/* -------------------------------------------------------- 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: 580px;
  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); }
.about { font-size: 13px; margin-top: 14px; 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.06em; text-transform: uppercase; color: var(--ink-soft); line-height: 1.25; }
.tile b { font: 800 22px var(--round); font-variant-numeric: tabular-nums; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
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); }
td { padding: 7px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
th.num, td.num { text-align: right; }
td.name { font-weight: 600; max-width: 10em; overflow: hidden; text-overflow: ellipsis; }
td.score { font: 700 14px var(--round); }
td.score .w { color: var(--accent-ink); }
td.who { max-width: 12em; overflow: hidden; text-overflow: ellipsis; color: var(--ink-soft); }
.note { font-size: 12.5px; color: var(--ink-soft); margin: 14px 0 0; }
.friends { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.fboard { background: var(--paper-2); border-radius: 16px; padding: 4px 12px 8px; min-height: 60px; }

/* ------------------------------------------------------------- settings */
.swatch {
  display: inline-block;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  flex: 0 0 auto;
  position: relative;
  background: var(--sa);
  box-shadow: inset 0 0 0 4px var(--sb), inset 0 0 0 5px rgba(0, 0, 0, 0.25);
}
.swatch::after { content: ""; position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; background: var(--sc); }
.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); }
.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(var(--by) - var(--bs) * 0.18);
  transform: translate(-50%, -50%) translateY(6px) scale(0.98);
  z-index: 15;
  background: var(--toast);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  width: max-content;
  max-width: min(88vw, 440px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.3s var(--spring);
  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 .lamp { animation: none; }
  .panel, .sheet, .backdrop, .menu, .card, .scoreboard { animation: none; }
  .plate.active { animation: none; }
  .stage canvas { transition: none; }
}
