/* Gomoku — the page round the board: the top bar, the players' plates, the
   board's window (the board itself is a canvas, render.js), the actions,
   sheets and dialogs. Calm catalogue chrome in notebook colours: ink blue,
   margin red, paper. The far player's plate and questions turn round in
   face-to-face play. */

: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;
  --hand: "Bradley Hand", "Segoe Print", "Chalkboard SE", "Comic Neue", var(--round);
  --ease: cubic-bezier(0.4, 0.1, 0.2, 1);
  --spring: cubic-bezier(0.25, 0.8, 0.3, 1);
  color-scheme: light;
  --bg-a: #f7f3ea;
  --bg-b: #e6ddca;
  --glow-1: rgba(255, 255, 255, 0.85);
  --glow-2: rgba(39, 71, 184, 0.1);
  --ink: #1f2433;
  --ink-soft: #5b6170;
  --paper: #fffdf8;
  --paper-2: #f1ebdf;
  --glass: rgba(255, 253, 248, 0.84);
  --line: rgba(40, 35, 20, 0.13);
  --accent: #2747b8;
  --accent-soft: rgba(39, 71, 184, 0.18);
  --ink-x: #2241a8;
  --ink-o: #c0352c;
  --grid: rgba(78, 132, 205, 0.2);
  --btn-bg: rgba(255, 255, 255, 0.6);
  --btn-hover: rgba(255, 255, 255, 0.95);
  --btn-line: rgba(40, 35, 20, 0.15);
  --primary-a: #3459cf;
  --primary-b: #213f9f;
  --primary-line: #1b3485;
  --primary-ink: #ffffff;
  --backdrop: rgba(30, 26, 18, 0.36);
  --toast: rgba(31, 36, 51, 0.94);
  --desk: #c9bb9f;
  --left: 1;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg-a: #1a1d29;
    --bg-b: #0a0b11;
    --glow-1: rgba(120, 140, 255, 0.12);
    --glow-2: rgba(255, 140, 110, 0.06);
    --ink: #eceef6;
    --ink-soft: rgba(236, 238, 246, 0.66);
    --paper: #1d2130;
    --paper-2: #272c3d;
    --glass: rgba(29, 33, 48, 0.86);
    --line: rgba(200, 210, 255, 0.13);
    --accent: #8ea4ff;
    --accent-soft: rgba(142, 164, 255, 0.22);
    --ink-x: #93a9ff;
    --ink-o: #ff8f80;
    --grid: rgba(142, 164, 255, 0.12);
    --btn-bg: rgba(255, 255, 255, 0.06);
    --btn-hover: rgba(255, 255, 255, 0.12);
    --btn-line: rgba(200, 210, 255, 0.18);
    --primary-a: #6e86f0;
    --primary-b: #4359c8;
    --primary-line: #34479f;
    --backdrop: rgba(3, 4, 8, 0.6);
    --toast: rgba(40, 45, 64, 0.96);
    --desk: #1d150f;
  }
}

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

/* -------------------------------------------------------------- layout */
.app {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  grid-template-areas: "top" "far" "board" "near" "actions";
  row-gap: 8px;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) max(8px, env(safe-area-inset-bottom)) env(safe-area-inset-left);
  opacity: 0;
  transition: opacity 0.4s var(--ease);
}
.app.ready { opacity: 1; }
.app:not(.ready) .plate { transition: none; }
.table { display: contents; }
.top { grid-area: top; }
.plate.far-slot { grid-area: far; }
.plate.near-slot { grid-area: near; }
.board-wrap { grid-area: board; }
.actions { grid-area: actions; }

/* wide screens: the board on the left, everything else in a column on the right */
@media (min-aspect-ratio: 5/4) {
  .app {
    grid-template-columns: minmax(0, 1fr) clamp(260px, 32vw, 380px);
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    grid-template-areas: "board top" "board far" "board ." "board near" "board actions";
    column-gap: 4px;
    padding-top: max(8px, env(safe-area-inset-top));
  }
  .board-wrap { margin: 0 0 0 10px; }
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 8px 0 14px;
  min-width: 0;
}
.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.22)); }
.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;
  flex: 0 0 auto;
  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; }

/* --------------------------------------------------------------- board */
.board-wrap {
  position: relative;
  margin: 0 10px;
  min-height: 0;
  border-radius: 20px;
  overflow: hidden;
  background: var(--desk);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5), 0 18px 40px -22px rgba(30, 20, 5, 0.55), inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.board-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: pointer;
  outline: none;
}
.board-wrap canvas:focus-visible { box-shadow: inset 0 0 0 3px var(--accent); }
.board-wrap.nudge canvas { animation: nudge 0.34s var(--ease); }
@keyframes nudge {
  20% { transform: translateX(-5px); }
  45% { transform: translateX(4px); }
  70% { transform: translateX(-2px); }
}

.zoom {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 6px 18px -8px rgba(0, 0, 0, 0.4);
  animation: fade 0.3s var(--ease);
}
.zoom .icon-btn { width: 40px; height: 40px; }
.zoom .icon-btn svg { width: 19px; height: 19px; stroke-width: 2; }
.zoom { opacity: 0.88; transition: opacity 0.2s; }
.zoom:hover, .zoom:focus-within { opacity: 1; }

.veil {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(20, 16, 8, 0.28);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade 0.3s var(--ease);
}
.veil-card {
  width: min(100%, 320px);
  text-align: center;
  padding: 20px 18px 16px;
  border-radius: 22px;
  background: var(--glass);
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px -18px rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  animation: pop 0.3s var(--spring);
}
.veil-card h2 { margin: 0 0 4px; font: 700 22px var(--round); }
.veil-card p { margin: 0 0 14px; font-size: 14px; color: var(--ink-soft); line-height: 1.4; }
.veil-card .btn { width: 100%; }

/* --------------------------------------------------------------- plates */
.plate {
  --me: var(--ink-x);
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 10px;
  padding: 7px 8px 7px 8px;
  min-height: 58px;
  border-radius: 18px;
  background: var(--glass);
  border: 1.5px solid var(--line);
  box-shadow: 0 8px 22px -16px rgba(0, 0, 0, 0.45);
  transition: border-color 0.35s var(--ease), box-shadow 0.35s var(--ease), transform 0.5s var(--spring), opacity 0.35s;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.plate[data-mark="o"] { --me: var(--ink-o); }
.plate.far { transform: rotate(180deg); }
.plate:not(.active) { opacity: 0.86; }
.plate.active {
  opacity: 1;
  border-color: color-mix(in oklab, var(--me) 70%, transparent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--me) 18%, transparent), 0 12px 30px -14px color-mix(in oklab, var(--me) 70%, transparent);
}
.plate .badge {
  position: relative;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  color: var(--me);
  background:
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 11px 11px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 11px 11px,
    var(--paper);
  box-shadow: inset 0 0 0 1px var(--line);
}
.plate .badge svg { width: 32px; height: 32px; }
.plate.active .badge::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 16px;
  border: 2px solid var(--me);
  opacity: 0;
  animation: breathe 2.2s ease-in-out infinite;
}
@keyframes breathe { 50% { opacity: 0.55; transform: scale(1.04); } }
.plate.winner .badge { animation: cheer 0.9s var(--spring) 0.6s both; }
@keyframes cheer { 30% { transform: scale(1.18) rotate(-6deg); } 60% { transform: scale(0.96) rotate(3deg); } }
.plate .who { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.plate .name { font: 700 16.5px/1.2 var(--round); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plate .status { font-size: 12.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plate.active .status { color: var(--me); font-weight: 600; }
.plate.winner .status { color: var(--me); font-weight: 700; }
.plate.thinking .status::after { content: ""; display: inline-block; width: 1.1em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.plate .clock {
  flex: 0 0 auto;
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font: 700 12.5px var(--round);
  font-variant-numeric: tabular-nums;
  background: conic-gradient(var(--me) calc(var(--left) * 1turn), var(--line) 0);
  isolation: isolate;
}
.plate .clock::before { content: ""; position: absolute; inset: 4px; border-radius: 50%; background: var(--paper); z-index: -1; }
.plate .clock.low { --me: #d8342a; color: #d8342a; animation: throb 1s ease-in-out infinite; }
@keyframes throb { 50% { transform: scale(1.08); } }
.plate .flag { width: 44px; height: 44px; color: var(--ink-soft); }
.plate .flag svg { width: 20px; height: 20px; }

/* --------------------------------------------------------------- actions */
.actions {
  display: flex;
  gap: 6px;
  padding: 0 10px;
}
.btn {
  appearance: none;
  flex: 1;
  min-width: 0;
  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, color 0.2s, border-color 0.2s;
}
.btn svg { width: 20px; height: 20px; flex: 0 0 auto; }
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.42; cursor: default; transform: none; }
.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.subtle { flex: none; width: 100%; }
.actions .btn {
  flex-direction: column;
  gap: 3px;
  padding: 6px 4px;
  min-height: 54px;
  font-size: 12.5px;
  line-height: 1.1;
  border-radius: 16px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.actions .btn span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions .btn.primary { animation: invite 2.4s ease-in-out infinite; }
@keyframes invite { 50% { box-shadow: 0 0 0 5px var(--accent-soft), 0 6px 16px -6px rgba(0, 0, 0, 0.45); } }
.toggle-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); background: var(--paper); box-shadow: 0 0 0 3px var(--accent-soft); }
.toggle-btn[aria-pressed="true"] svg { fill: color-mix(in oklab, var(--accent) 22%, transparent); }

@media (max-height: 640px) and (orientation: portrait) {
  .app { row-gap: 6px; }
  .plate { min-height: 50px; padding: 4px 8px; }
  .plate .badge { width: 38px; height: 38px; }
  .plate .badge svg { width: 28px; height: 28px; }
  .actions .btn { min-height: 48px; }
  .brand img { width: 34px; height: 34px; }
  .brand b { font-size: 19px; }
}
@media (max-width: 380px) {
  .brand small { display: none; }
  .brand b { font-size: 19px; }
  .top { padding-left: 10px; padding-right: 4px; }
  .nav { gap: 0; }
  .actions { gap: 4px; padding: 0 8px; }
  .actions .btn { font-size: 11.5px; }
}
@media (min-aspect-ratio: 5/4) {
  .plate { margin: 0 10px 0 6px; }
  .actions { padding: 0 10px 0 6px; flex-wrap: wrap; }
  .actions .btn { flex: 1 1 40%; flex-direction: row; min-height: 46px; font-size: 14px; }
  .top { padding-left: 6px; }
}
/* the side column is narrow: the icon says what the app is, the title needs room */
@media (min-aspect-ratio: 5/4) and (max-width: 1120px) {
  .brand span { display: none; }
}
@media (min-aspect-ratio: 5/4) and (max-height: 430px) {
  .app { row-gap: 5px; }
  .brand small { display: none; }
  .brand img { width: 32px; height: 32px; }
  .brand b { font-size: 18px; }
  .plate { min-height: 48px; padding: 3px 6px; }
  .plate .badge { width: 36px; height: 36px; }
  .plate .badge svg { width: 26px; height: 26px; }
  .actions .btn { min-height: 44px; font-size: 13px; padding: 4px 6px; }
  .actions .btn svg { width: 18px; height: 18px; }
}

/* -------------------------------------------------------- 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;
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(0.94); } }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  z-index: 21;
  max-width: 560px;
  max-height: 90dvh;
  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 24px;
  font-size: 15px;
  line-height: 1.55;
  touch-action: pan-y;
}
.sheet-body.prose { -webkit-user-select: text; user-select: text; }
.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: 650; }
.muted { color: var(--ink-soft); }
.note { font-size: 12.5px; color: var(--ink-soft); margin: 14px 0 0; line-height: 1.45; }
.note.small { margin-top: 6px; }
.center { text-align: center; }
.about { font-size: 13px; margin-top: 10px; 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: 86dvh; animation: popm 0.28s var(--ease); }
}
@keyframes popm { from { opacity: 0; transform: translateY(-50%) scale(0.96); } }

/* the new-game sheet */
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }
.mode {
  appearance: none;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: center;
  text-align: left;
  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 { grid-row: 1 / 3; width: 34px; height: 34px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; color: var(--accent); }
.mode b { font: 700 16px var(--round); }
.mode small { font-size: 12.5px; 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: 14px 0 16px; }
.opt-row { display: grid; grid-template-columns: 104px 1fr; align-items: center; gap: 8px; }
.opt-row h3, .sheet-body .opt-row h3 { margin: 0; font: 700 11px var(--sans); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.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 13px;
  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 svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.opt:active { transform: scale(0.97); }
.opt[aria-checked="true"], .opt[aria-selected="true"] { border-color: var(--accent); background: var(--paper); box-shadow: 0 0 0 3px var(--accent-soft); }
.opts.small .opt { min-height: 36px; padding: 4px 11px; font-size: 13px; }
.hint { margin: 8px 2px 0; font-size: 12.5px; line-height: 1.4; color: var(--ink-soft); }
.hint.sub { margin: -4px 0 2px; padding-left: 112px; }
.btn.play { width: 100%; min-height: 54px; font: 700 18px var(--round); border-radius: 16px; }
@media (max-width: 460px) {
  .opt-row { grid-template-columns: 1fr; gap: 5px; }
  .hint.sub { padding-left: 2px; }
  .opts .opt { flex: 1 1 auto; padding-left: 9px; padding-right: 9px; }
}
@media (max-width: 360px) {
  .mode { grid-template-columns: 1fr; }
  .mode svg { display: none; }
}

/* 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 1px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}
.swatch.paper { background: linear-gradient(90deg, transparent 6px, var(--sc) 6px, var(--sc) 7.5px, transparent 7.5px), linear-gradient(var(--sb) 1px, transparent 1px) 0 0 / 6.5px 6.5px, linear-gradient(90deg, var(--sb) 1px, transparent 1px) 0 0 / 6.5px 6.5px, var(--sa); }
.swatch.wood::before, .swatch.wood::after { content: ""; position: absolute; width: 10px; height: 10px; border-radius: 50%; top: 8px; }
.swatch.wood::before { left: 3px; background: var(--sb); }
.swatch.wood::after { right: 3px; background: var(--sc); box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.3); }
.swatch.wood { background: linear-gradient(var(--sa), color-mix(in oklab, var(--sa) 80%, #5a3a10)); }
.swatch.chalk { background: linear-gradient(135deg, transparent 45%, var(--sb) 45%, var(--sb) 55%, transparent 55%), radial-gradient(circle at 70% 70%, transparent 4px, var(--sc) 4px, var(--sc) 5.5px, transparent 5.5px), var(--sa); }
.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; }
.toggle-text { display: flex; flex-direction: column; }
.toggle-text small { font-size: 12.5px; color: var(--ink-soft); }
.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); }

/* results */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 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; min-width: 0; }
.tile small { font-size: 10.5px; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-soft); }
.tile b { font: 800 22px var(--round); font-variant-numeric: tabular-nums; }
.tile.accent b { color: var(--accent); }
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; }
table + table { margin-top: 10px; }
th.num, td.num { text-align: right; }
td.name { font-weight: 600; max-width: 10em; overflow: hidden; text-overflow: ellipsis; }
td.who { max-width: 10em; overflow: hidden; text-overflow: ellipsis; color: var(--ink-soft); }
td.res { font-weight: 600; }
td.res.w { color: var(--accent); }
@media (max-width: 420px) {
  table.recent { font-size: 12.5px; }
  table.recent td, table.recent th { padding-left: 2px; padding-right: 2px; }
}
.friends { margin-top: 18px; }
.friends-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.friends-head h3 { margin: 0; }
.friends .note { margin-top: 4px; }
.friends-board { margin-top: 6px; --ca-accent: var(--accent); }
.friends-board .ca-board-title:empty { display: none; }

/* dialogs: a question, the result */
.dialog {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 30;
  width: min(100vw - 32px, 360px);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  transform: translate(-50%, -50%);
  padding: 20px 18px 16px;
  border-radius: 24px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: 0 30px 80px -24px rgba(0, 0, 0, 0.6);
  text-align: center;
  animation: popc 0.32s var(--spring);
}
.dialog.far { transform: translate(-50%, -50%) rotate(180deg); animation-name: popf; }
@keyframes popc { from { opacity: 0; transform: translate(-50%, -50%) scale(0.92); } }
@keyframes popf { from { opacity: 0; transform: translate(-50%, -50%) rotate(180deg) scale(0.92); } }
.dialog p { margin: 0 0 14px; font-size: 16px; line-height: 1.4; }
.dialog .note { margin: -6px 0 14px; font-size: 13px; }
.dialog .row { display: flex; gap: 8px; }
.result {
  z-index: 25;
  width: min(100vw - 28px, 380px);
  padding-top: 18px;
  background:
    linear-gradient(90deg, transparent 26px, rgba(222, 86, 76, 0.45) 26px, rgba(222, 86, 76, 0.45) 27.5px, transparent 27.5px),
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 100% 22px,
    var(--paper);
}
.result .mirror {
  margin: -4px 0 8px;
  font: 700 16px var(--round);
  color: var(--ink-soft);
  transform: rotate(180deg);
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--line);
}
.result-mark { width: 74px; height: 74px; margin: 0 auto 4px; color: var(--ink-x); }
.result[data-mark="o"] .result-mark { color: var(--ink-o); }
.result[data-mark="draw"] .result-mark { color: var(--ink-soft); }
.result-mark svg { width: 100%; height: 100%; stroke-dasharray: 80; stroke-dashoffset: 80; animation: draw 0.9s var(--ease) 0.15s forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.result h2 { margin: 0 0 4px; font: 800 26px var(--round); }
.result.won h2 { color: var(--accent); }
.result > p { color: var(--ink-soft); font-size: 15px; margin-bottom: 10px; }
.chips { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.chips > span {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--paper-2);
  font-size: 10.5px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.chips b { font: 700 14px var(--round); letter-spacing: 0; text-transform: none; color: var(--ink); }
#result-extra .note { margin: -4px 0 12px; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%) translateY(6px);
  z-index: 40;
  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%); }
.toast.far { transform: translate(-50%, -50%) rotate(180deg) translateY(6px); }
.toast.far.show { transform: translate(-50%, -50%) rotate(180deg); }

@media (prefers-reduced-motion: reduce) {
  .bg .glow, .plate.active .badge::after, .actions .btn.primary, .plate .clock.low { animation: none; }
  .sheet, .backdrop, .dialog, .veil, .veil-card, .zoom { animation-duration: 0.01s; }
  .result-mark svg { animation: none; stroke-dashoffset: 0; }
  .plate { transition: none; }
  .board-wrap.nudge canvas { animation: none; }
}
