/* Button Ball — the page around the table. The table itself is a canvas
   (render.js, art.js); the players' plates and panels sit over it, placed
   and turned from the script so each faces its player. Colours that change
   with the table 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: #bb232c;
  --t0-hi: #e85a5e;
  --t0-lo: #6f0d14;
  --t0-ink: #f7ecd2;
  --t0-ui: #b3202a;
  --t1: #1f4f9c;
  --t1-hi: #4a7fd0;
  --t1-lo: #0c2552;
  --t1-ink: #f7ecd2;
  --t1-ui: #1f4f9c;
  --x: 50%;
  --y: 50%;
  --w: 300px;
  --h: 80px;
  --r: 0deg;
}

/* ------------------------------------------------------------- themes */
/* Classic: green felt, oak (light) */
:root,
[data-theme="classic"] {
  color-scheme: light;
  --bg-a: #c99a66;
  --bg-b: #8d5b33;
  --ink: #1e2a20;
  --ink-soft: #566057;
  --paper: #fffdf8;
  --paper-2: #f2ede2;
  --glass: rgba(255, 252, 244, 0.88);
  --line: rgba(40, 30, 10, 0.14);
  --accent: #2b7a43;
  --accent-soft: rgba(43, 122, 67, 0.22);
  --btn-bg: rgba(255, 255, 255, 0.6);
  --btn-hover: rgba(255, 255, 255, 0.92);
  --btn-line: rgba(40, 30, 10, 0.16);
  --primary-a: #36924f;
  --primary-b: #226b37;
  --primary-line: #1b552c;
  --primary-ink: #ffffff;
  --backdrop: rgba(30, 20, 8, 0.4);
  --scrim-top: rgba(250, 244, 232, 0.9);
  --scrim-bottom: rgba(60, 35, 12, 0.35);
  --ca-accent: #2b7a43;
}

/* Retro: the 70s (light, warm) */
[data-theme="retro"] {
  color-scheme: light;
  --bg-a: #f1d8a8;
  --bg-b: #d9a35a;
  --ink: #3a2213;
  --ink-soft: #6e5038;
  --paper: #fff8ea;
  --paper-2: #f6e6c8;
  --glass: rgba(255, 247, 230, 0.9);
  --line: rgba(90, 50, 15, 0.16);
  --accent: #c25a14;
  --accent-soft: rgba(194, 90, 20, 0.22);
  --btn-bg: rgba(255, 250, 238, 0.65);
  --btn-hover: rgba(255, 252, 244, 0.95);
  --btn-line: rgba(90, 50, 15, 0.18);
  --primary-a: #e0742a;
  --primary-b: #b4531a;
  --primary-line: #8f3f10;
  --primary-ink: #ffffff;
  --backdrop: rgba(60, 30, 8, 0.4);
  --scrim-top: rgba(255, 244, 222, 0.9);
  --scrim-bottom: rgba(110, 55, 15, 0.35);
  --ca-accent: #c25a14;
}

/* Night stadium (dark) */
[data-theme="night"] {
  color-scheme: dark;
  --bg-a: #0b1124;
  --bg-b: #03050c;
  --ink: #eef1ff;
  --ink-soft: rgba(225, 232, 255, 0.68);
  --paper: #121a30;
  --paper-2: #1b2542;
  --glass: rgba(14, 20, 40, 0.86);
  --line: rgba(170, 190, 255, 0.16);
  --accent: #f2b326;
  --accent-soft: rgba(242, 179, 38, 0.24);
  --btn-bg: rgba(255, 255, 255, 0.06);
  --btn-hover: rgba(255, 255, 255, 0.12);
  --btn-line: rgba(170, 190, 255, 0.2);
  --primary-a: #f6c24a;
  --primary-b: #d8961a;
  --primary-line: #a87210;
  --primary-ink: #1d1400;
  --backdrop: rgba(0, 2, 10, 0.62);
  --scrim-top: rgba(4, 7, 16, 0.86);
  --scrim-bottom: rgba(0, 0, 0, 0.5);
  --ca-accent: #f2b326;
}

/* before the script runs, a dark device starts on Night (no flash) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg-a: #0b1124;
    --bg-b: #03050c;
    --ink: #eef1ff;
    --ink-soft: rgba(225, 232, 255, 0.68);
  }
}

* { 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;
}

/* --------------------------------------------------------------- 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;
  /* the safe-area insets, read by the layout */
  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: filter 0.35s var(--ease), opacity 0.35s var(--ease);
}
.stage.dimmed canvas { filter: brightness(0.62) saturate(0.85); }

/* team colours for whatever belongs to a side */
[data-side="0"] { --me: var(--t0); --me-hi: var(--t0-hi); --me-lo: var(--t0-lo); --me-ink: var(--t0-ink); --me-ui: var(--t0-ui); }
[data-side="1"] { --me: var(--t1); --me-hi: var(--t1-hi); --me-lo: var(--t1-lo); --me-ink: var(--t1-ink); --me-ui: var(--t1-ui); }

/* -------------------------------------------------------------- plates */
.plate {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--w);
  height: var(--h);
  transform: translate(-50%, -50%) rotate(var(--r));
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
  transition: opacity 0.35s var(--ease);
}
.plate.swap { opacity: 0; }
.plate-in {
  pointer-events: auto;
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 440px;
  max-height: 100%;
  padding: 8px 8px 8px 12px;
  border-radius: 20px;
  background: var(--glass);
  border: 1.5px solid var(--line);
  box-shadow: 0 10px 28px -14px rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(12px) saturate(1.15);
  backdrop-filter: blur(12px) saturate(1.15);
  transition: border-color 0.35s, box-shadow 0.35s, transform 0.35s var(--spring);
}
.plate.active .plate-in {
  border-color: var(--me-ui);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--me) 30%, transparent), 0 0 28px -2px color-mix(in oklab, var(--me) 60%, transparent), 0 10px 28px -14px rgba(0, 0, 0, 0.55);
  transform: scale(1.02);
}
/* a mini button: the team's colour, four holes; the far team's milled edge */
.crest {
  flex: 0 0 auto;
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 39% 39%, rgba(10, 10, 6, 0.85) 0 5.5%, transparent 7%),
    radial-gradient(circle at 61% 39%, rgba(10, 10, 6, 0.85) 0 5.5%, transparent 7%),
    radial-gradient(circle at 39% 61%, rgba(10, 10, 6, 0.85) 0 5.5%, transparent 7%),
    radial-gradient(circle at 61% 61%, rgba(10, 10, 6, 0.85) 0 5.5%, transparent 7%),
    radial-gradient(circle at 50% 50%, var(--me) 0 54%, var(--me-lo) 56% 60%, var(--me-hi) 62% 66%, var(--me) 68%);
  box-shadow: inset 0 2px 3px rgba(255, 255, 255, 0.45), inset 0 -2px 4px rgba(0, 0, 0, 0.35), 0 2px 5px rgba(0, 0, 0, 0.35);
}
.plate[data-side="1"] .crest::after {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: 50%;
  border: 3px dotted var(--me-lo);
  opacity: 0.8;
}
.plate.active .crest { animation: breathe 1.8s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.08); box-shadow: inset 0 2px 3px rgba(255, 255, 255, 0.45), inset 0 -2px 4px rgba(0, 0, 0, 0.35), 0 0 0 4px color-mix(in oklab, var(--me) 35%, transparent); } }
.who { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.who .name { font: 700 16px var(--round); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .status { margin-top: 2px; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 1.15em; }
.plate.active .who .status { color: var(--me-ui); }
.pscore { display: flex; align-items: baseline; gap: 6px; font: 800 30px/1 var(--round); font-variant-numeric: tabular-nums; padding: 0 2px; }
.pscore .mine { color: var(--me-ui); display: inline-block; }
.pscore .sep, .pscore .theirs { font-size: 18px; color: var(--ink-soft); }
.plate.solo .pscore .sep, .plate.solo .pscore .theirs { display: none; }
.pscore .mine.tick { animation: tick 0.7s var(--spring); }
@keyframes tick { 0% { transform: scale(1.9) rotate(-8deg); } 60% { transform: scale(0.94); } }
.plate .pause { flex: 0 0 auto; width: 44px; height: 44px; border: 1px solid var(--btn-line); background: var(--btn-bg); }
/* a narrow column (landscape, read upright) */
.plate.tall .plate-in { flex-direction: column; width: auto; min-width: 0; max-width: 100%; padding: 10px 8px; gap: 6px; text-align: center; }
.plate.tall .who { align-items: center; max-width: 100%; }
.plate.tall .who .status { white-space: normal; }
.plate.tight .plate-in { padding: 5px 6px 5px 8px; gap: 7px; border-radius: 16px; }
.plate.tight .crest { width: 28px; height: 28px; }
.plate.tight .pscore { font-size: 25px; }
.plate.tight .who .name { font-size: 15px; }
.plate.tight .pause { width: 40px; height: 40px; }

/* --------------------------------------------------------------- panels */
.panels { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.panel {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--w);
  height: var(--h);
  transform: translate(-50%, -50%) rotate(var(--r));
  display: grid;
  place-items: center;
  padding: 10px;
  pointer-events: none;
}
.card-in {
  position: relative;
  pointer-events: auto;
  width: min(100%, 340px);
  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.6);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
  backdrop-filter: blur(14px) saturate(1.15);
  animation: pop 0.34s var(--spring);
}
.panel.upright .card-in { width: min(100%, 380px); padding: 22px 20px 18px; }
@keyframes pop { from { opacity: 0; transform: scale(0.92) translateY(8px); } }
.card-in .glow {
  position: absolute;
  inset: -50% -20% auto;
  height: 80%;
  background: radial-gradient(ellipse at 50% 45%, color-mix(in oklab, var(--me) 35%, transparent), transparent 68%);
  pointer-events: none;
}
.card-in h2 { position: relative; margin: 0; font: 700 23px/1.15 var(--round); letter-spacing: 0.01em; }
.panel.won h2 { color: var(--me-ui); }
.card-in p { position: relative; margin: 4px 0 10px; font-size: 14px; color: var(--ink-soft); line-height: 1.4; }
.card-in p.streak { color: var(--accent); font-weight: 700; }
.card-in .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;
}
.score .t0 { color: var(--t0-ui); }
.score .t1 { color: var(--t1-ui); }
.card-in .score .dash { font-size: 24px; color: var(--ink-soft); }
.card-in .chips { position: relative; display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.card-in .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);
}
.card-in .chips b { font: 700 14px var(--round); letter-spacing: 0; text-transform: none; color: var(--ink); }
.card-in .row { position: relative; display: flex; gap: 8px; }
.card-in .row + .row { margin-top: 8px; }
.card-in .row:empty { display: none; }
.card-in .row .btn { min-width: 0; }
.card-in .tools { position: relative; display: flex; justify-content: center; gap: 6px; margin-top: 10px; }
.card-in .tools .icon-btn { width: 44px; height: 44px; border: 1px solid var(--btn-line); background: var(--btn-bg); }
@media (max-height: 640px) and (orientation: portrait), (max-width: 640px) and (orientation: landscape) {
  .panel:not(.upright) .card-in { padding: 12px 12px 10px; border-radius: 18px; }
  .panel:not(.upright) .card-in h2 { font-size: 20px; }
  .panel:not(.upright) .card-in .score { font-size: 32px; margin-top: 2px; }
  .panel:not(.upright) .card-in p { margin: 2px 0 6px; font-size: 13px; }
  .panel:not(.upright) .card-in .chips { margin: 4px 0 8px; }
  .panel:not(.upright) .btn { min-height: 44px; padding: 8px 10px; }
}

/* the replay's skip */
.skip {
  position: absolute;
  left: var(--x);
  top: var(--y);
  transform: translate(-50%, -50%);
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(12, 12, 16, 0.78);
  color: #fff;
  font: 700 15px var(--round);
  letter-spacing: 0.03em;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  animation: fade 0.3s var(--ease);
}
.skip svg { width: 18px; height: 18px; }

/* --------------------------------------------------------------- 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 38%, 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: 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;
  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, 600px);
  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.55);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  backdrop-filter: blur(18px) saturate(1.2);
  animation: rise 0.42s 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-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 9px;
  align-items: center;
  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 { grid-row: 1 / 3; width: 32px; height: 32px; 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; flex: 0 0 auto; }
.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);
}
.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 (max-width: 560px) {
  .modes { grid-template-columns: 1fr; gap: 6px; }
  .mode { min-height: 52px; padding: 7px 11px; grid-template-columns: 30px 1fr; }
  .mode svg { width: 28px; height: 28px; }
}
/* short landscape: the card goes wide, two columns */
@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: 48px; padding: 6px 10px; grid-template-columns: 28px 1fr; }
  .mode svg { width: 26px; height: 26px; }
  .mode small { display: none; }
  .opts-grid { grid-area: opts; margin: 0; gap: 6px; align-content: start; }
  .opt-row { grid-template-columns: 1fr; gap: 4px; }
  .opt { min-height: 42px; 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 { display: none; }
  .brand b { white-space: normal; font-size: 18px; line-height: 1.05; max-height: 2.2em; }
  .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; }
  .mode small { font-size: 11.5px; }
}
@media (max-width: 440px) and (orientation: portrait) {
  .opt-row { grid-template-columns: 1fr; gap: 5px; }
  .opts .opt { flex: 1 1 0; padding-left: 6px; padding-right: 6px; }
}

/* -------------------------------------------------------- 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: 5px 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.08em; text-transform: uppercase; color: var(--ink-soft); }
.tile b { font: 800 22px var(--round); font-variant-numeric: tabular-nums; }
.boards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.board { background: var(--paper-2); border-radius: 16px; padding: 6px 10px; min-height: 60px; }
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: 9em; overflow: hidden; text-overflow: ellipsis; }
td.score { font: 700 14px var(--round); }
td.score .w { color: var(--accent); }
td.who { max-width: 11em; overflow: hidden; text-overflow: ellipsis; color: var(--ink-soft); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: 0; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25); }
.dot.t0 { background: var(--t0); }
.dot.t1 { background: var(--t1); box-shadow: inset 0 0 0 2px var(--t1-lo); }
.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; }
}

/* ------------------------------------------------------------- settings */
.swatch {
  display: inline-block;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  flex: 0 0 auto;
  position: relative;
  background: linear-gradient(var(--sf), var(--sf)) 50% 50% / 64% 74% no-repeat, var(--sb);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}
.swatch::before, .swatch::after { content: ""; position: absolute; left: 50%; width: 8px; height: 8px; margin-left: -4px; border-radius: 50%; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.35); }
.swatch::before { top: 6px; background: var(--sc); }
.swatch::after { bottom: 6px; background: var(--sa); }
.swatch.auto { background: linear-gradient(135deg, #2f7d41 50%, #1f6235 50%); }
.swatch.auto::before, .swatch.auto::after { display: none; }
.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; }
.field input {
  appearance: none;
  font: 500 16px var(--sans); /* 16 px: iOS never zooms into the field */
  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); }

@media (prefers-reduced-motion: reduce) {
  .card-in, .sheet, .backdrop, .menu, .card, .skip { animation: none; }
  .plate.active .crest, .pscore .mine.tick { animation: none; }
  .plate.active .plate-in { transform: none; }
  .stage canvas, .plate, .plate-in { transition: none; }
}
