/* ---------- Theme tokens ---------- */
:root {
  color-scheme: light;
  --bg: #efe6d6;
  --surface: #f9f4ea;
  --surface-2: #f1e8d8;
  --border: #dccbb0;
  --text: #2b2119;
  --muted: #76634f;
  --accent: #a6461f;
  --accent-text: #fff8ef;
  --focus: #1f6feb;

  --board: #e6d3ae;
  --board-edge: #c9b088;
  --line: #5a4330;
  --dot: #5a4330;
  --target: #2f8f5b;
  --flash: #e0a526;
  --flash-dead: #8c7a68;

  --chip-a-hi: #f07a55;
  --chip-a-lo: #a8301b;
  --chip-a: #c4432a;
  --chip-b-hi: #6d86c7;
  --chip-b-lo: #1d2d55;
  --chip-b: #2f4682;
  --chip-ring: rgba(0, 0, 0, 0.35);

  --shadow: 0 1px 2px rgba(60, 40, 20, 0.08), 0 6px 20px rgba(60, 40, 20, 0.08);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #17130f;
    --surface: #221c17;
    --surface-2: #2b241d;
    --border: #3d332a;
    --text: #f1e7d8;
    --muted: #b3a08b;
    --accent: #e0754a;
    --accent-text: #1b120c;
    --focus: #6ea8ff;

    --board: #3b2f25;
    --board-edge: #2a211a;
    --line: #e8dbc4;
    --dot: #e8dbc4;
    --target: #5fd08f;
    --flash: #f2c14e;
    --flash-dead: #8f8170;

    --chip-a-hi: #ff9a72;
    --chip-a-lo: #b23a1f;
    --chip-a: #e0603f;
    --chip-b-hi: #a9bdf2;
    --chip-b-lo: #3a54a0;
    --chip-b: #7d95d8;
    --chip-ring: rgba(0, 0, 0, 0.5);

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #17130f;
  --surface: #221c17;
  --surface-2: #2b241d;
  --border: #3d332a;
  --text: #f1e7d8;
  --muted: #b3a08b;
  --accent: #e0754a;
  --accent-text: #1b120c;
  --focus: #6ea8ff;

  --board: #3b2f25;
  --board-edge: #2a211a;
  --line: #e8dbc4;
  --dot: #e8dbc4;
  --target: #5fd08f;
  --flash: #f2c14e;
  --flash-dead: #8f8170;

  --chip-a-hi: #ff9a72;
  --chip-a-lo: #b23a1f;
  --chip-a: #e0603f;
  --chip-b-hi: #a9bdf2;
  --chip-b-lo: #3a54a0;
  --chip-b: #7d95d8;
  --chip-ring: rgba(0, 0, 0, 0.5);

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.3);
}

/* ---------- Base ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

h1, h2 { margin: 0; line-height: 1.15; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

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

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 0.6rem 1rem;
  min-height: 44px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.07); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-icon { width: 44px; padding: 0; font-size: 1.2rem; display: inline-grid; place-items: center; }
.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon .icon-fill { fill: currentColor; }
.icon .icon-off { display: none; }
[aria-pressed="false"] .icon .icon-on { display: none; }
[aria-pressed="false"] .icon .icon-off { display: inline; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 16px;
  max-width: 1100px;
  margin: 0 auto;
}
.brand { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.brand h1 {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 1.75rem;
  letter-spacing: 0.02em;
  color: var(--accent);
}
.brand-sub { color: var(--muted); font-size: 0.9rem; }
.topbar-actions { display: flex; gap: 0.25rem; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px 32px;
  align-items: start;
}

.play { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.side { display: flex; flex-direction: column; gap: 16px; }

.status {
  margin: 0;
  padding: 0.7rem 1rem;
  min-height: 3rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-weight: 600;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  text-wrap: balance;
}
.status .dot-A, .status .dot-B {
  width: 0.9rem; height: 0.9rem; border-radius: 50%; display: inline-block;
  vertical-align: -0.1em; margin-right: 0.35rem;
}
.status .dot-A { background: var(--chip-a); }
.status .dot-B { background: var(--chip-b); }
.status.is-removing { border-color: var(--flash); box-shadow: 0 0 0 3px color-mix(in srgb, var(--flash) 30%, transparent); }

/* ---------- Board ---------- */
/* Keep the whole board on screen: its width follows the space left under the header. */
.board-wrap {
  position: relative;
  width: 100%;
  max-width: min(560px, calc((100dvh - 160px) * 6 / 7));
  min-width: min(100%, 280px);
  margin: 0 auto;
}

#board {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.board-surface {
  fill: var(--board);
  stroke: var(--board-edge);
  stroke-width: 6;
}

.board-line {
  stroke: var(--line);
  stroke-width: 4;
  stroke-linecap: round;
}

.point-dot { fill: var(--dot); transition: r 0.15s, fill 0.15s; }
.point-dot.is-target { fill: var(--target); }
.point-ring {
  fill: none;
  stroke: var(--target);
  stroke-width: 4;
  opacity: 0;
  transition: opacity 0.15s;
}
.point-ring.is-target { opacity: 0.9; animation: ring-pulse 1.4s ease-in-out infinite; }
.point-ring.is-soft { opacity: 0.35; animation: none; }

@keyframes ring-pulse {
  0%, 100% { opacity: 0.9; }
  50% { opacity: 0.35; }
}

.hit {
  fill: transparent;
  cursor: pointer;
  outline: none;
}
.hit:focus-visible { stroke: var(--focus); stroke-width: 4; }

/* Chips: outer <g> carries position (animated), inner <g> carries scale effects. */
.chip {
  transition: transform 0.28s cubic-bezier(0.3, 0.7, 0.3, 1);
  pointer-events: none;
}
.chip.is-dragging { transition: none; }
.chip-inner { transform-box: fill-box; transform-origin: center; transition: transform 0.15s; }
.chip-body { stroke: var(--chip-ring); stroke-width: 2; }
.chip-A .chip-body { fill: url(#grad-A); }
.chip-B .chip-body { fill: url(#grad-B); }
.chip-shine { fill: rgba(255, 255, 255, 0.35); }
.chip-halo { fill: none; stroke-width: 5; opacity: 0; }

.chip.is-selected .chip-inner { transform: scale(1.14); }
.chip.is-selected .chip-halo { stroke: var(--target); opacity: 1; }
.chip.is-dragging .chip-inner { transform: scale(1.2); }
.chip.is-last .chip-halo { stroke: var(--muted); opacity: 0.55; stroke-dasharray: 6 5; }
.chip.is-movable .chip-halo { stroke: var(--target); opacity: 0.35; }
.chip.is-removable .chip-inner { animation: removable 0.9s ease-in-out infinite; }
.chip.is-removable .chip-halo { stroke: var(--flash); opacity: 1; }

.chip.is-new .chip-inner { animation: pop-in 0.28s cubic-bezier(0.3, 1.4, 0.5, 1); }
.chip.is-leaving .chip-inner { animation: pop-out 0.32s ease-in forwards; }

@keyframes pop-in { from { transform: scale(0.2); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes pop-out { to { transform: scale(0.1); opacity: 0; } }
@keyframes removable {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(0.88); }
}

.stop-a-hi { stop-color: var(--chip-a-hi); }
.stop-a-lo { stop-color: var(--chip-a-lo); }
.stop-b-hi { stop-color: var(--chip-b-hi); }
.stop-b-lo { stop-color: var(--chip-b-lo); }

/* Captured-line marks */
.line-mark { --mark: var(--chip-a); }
.line-mark.mark-B { --mark: var(--chip-b); }
.mark-band {
  stroke: var(--mark);
  stroke-linecap: round;
  transition: opacity 0.25s, stroke-width 0.25s;
}
.line-mark.is-held .mark-band { stroke-width: 13; opacity: 0.75; }
.line-mark.is-past .mark-band { stroke-width: 9; opacity: 0.4; }
.owner-badge { fill: var(--mark); stroke: var(--board); stroke-width: 3; }
.line-mark.is-past .owner-badge { opacity: 0.8; }
.owner-initial {
  fill: #fff;
  font: 700 16px system-ui, -apple-system, sans-serif;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

/* Mill flash */
.mill-flash {
  stroke: var(--flash);
  stroke-width: 22;
  stroke-linecap: round;
  opacity: 0.55;
  animation: flash 1.6s ease-out forwards;
}
.mill-flash.is-dead { stroke: var(--flash-dead); stroke-dasharray: 2 18; }

@keyframes flash {
  0% { opacity: 0; }
  12% { opacity: 0.85; }
  70% { opacity: 0.85; }
  100% { opacity: 0; }
}

.toast {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  font-weight: 700;
  text-align: center;
  max-width: 80%;
  pointer-events: none;
  animation: toast 2s ease-out forwards;
}
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, -40%); }
  12% { opacity: 1; transform: translate(-50%, -50%); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- Player cards ---------- */
.players { display: grid; gap: 12px; }

.player-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.player-card.is-turn[data-player="A"] { border-color: var(--chip-a); box-shadow: var(--shadow); }
.player-card.is-turn[data-player="B"] { border-color: var(--chip-b); box-shadow: var(--shadow); }
.player-card header { display: flex; align-items: center; gap: 0.5rem; }
.player-name { font-size: 1.05rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.turn-pill {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  visibility: hidden;
}
.player-card.is-turn .turn-pill { visibility: visible; color: var(--text); }

.swatch { width: 1.1rem; height: 1.1rem; border-radius: 50%; flex: none; display: inline-block; border: 1px solid var(--chip-ring); }
.swatch-A { background: radial-gradient(circle at 35% 30%, var(--chip-a-hi), var(--chip-a-lo)); }
.swatch-B { background: radial-gradient(circle at 35% 30%, var(--chip-b-hi), var(--chip-b-lo)); }

.hand { display: flex; flex-wrap: wrap; gap: 4px; margin: 10px 0 8px; min-height: 14px; }
.hand .pebble { width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--chip-ring); }
.hand .pebble.is-used { opacity: 0.18; }
.player-card[data-player="A"] .pebble { background: radial-gradient(circle at 35% 30%, var(--chip-a-hi), var(--chip-a-lo)); }
.player-card[data-player="B"] .pebble { background: radial-gradient(circle at 35% 30%, var(--chip-b-hi), var(--chip-b-lo)); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 0; }
.stats div { display: flex; flex-direction: column; }
.stats dt { font-size: 0.75rem; color: var(--muted); }
.stats dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 1.1rem; }

/* ---------- Controls & log ---------- */
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.log {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.log summary { font-weight: 700; cursor: pointer; min-height: 28px; }
.log ol {
  margin: 8px 0 0;
  padding-left: 2rem;
  max-height: 260px;
  overflow-y: auto;
  font-variant-numeric: tabular-nums;
  font-size: 0.92rem;
}
.log li { padding: 1px 0; }
.log li .who-A { color: var(--chip-a); font-weight: 700; }
.log li .who-B { color: var(--chip-b); font-weight: 700; }
.log .empty { color: var(--muted); list-style: none; margin-left: -2rem; }

/* ---------- Dialogs ---------- */
.dialog {
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
}
.dialog::backdrop { background: rgba(20, 12, 6, 0.55); backdrop-filter: blur(2px); }
.dialog-body { padding: 22px; display: flex; flex-direction: column; gap: 14px; margin: 0; }
.dialog-body.center { align-items: center; text-align: center; }
.dialog-body h2 { font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif; font-size: 1.5rem; }
.dialog-body p { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; width: 100%; }
.dialog-body.center .dialog-actions { justify-content: center; }

.name-fields { display: grid; gap: 8px; }
.name-field {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 12px;
}
.name-field input {
  flex: 1; min-width: 0;
  border: 0; background: transparent; color: var(--text);
  font: inherit; padding: 0.7rem 0; outline: none;
}
.name-field:focus-within { outline: 3px solid var(--focus); outline-offset: 1px; }

.rules-list { margin: 0; padding-left: 1.25rem; display: grid; gap: 8px; }

/* Coin toss */
.coin-stage { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 8px 0; perspective: 600px; }
.coin { width: 84px; height: 84px; position: relative; transform-style: preserve-3d; }
.coin-face {
  position: absolute; inset: 0;
  border-radius: 50%;
  display: grid; place-items: center;
  backface-visibility: hidden;
  border: 3px solid var(--chip-ring);
  color: #fff;
  font: 700 1.6rem "Iowan Old Style", Georgia, serif;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
.coin-A { background: radial-gradient(circle at 35% 30%, var(--chip-a-hi), var(--chip-a-lo)); }
.coin-B { background: radial-gradient(circle at 35% 30%, var(--chip-b-hi), var(--chip-b-lo)); transform: rotateY(180deg); }
.coin.flip-A { animation: flip-A 1.6s cubic-bezier(0.2, 0.6, 0.3, 1) forwards; }
.coin.flip-B { animation: flip-B 1.6s cubic-bezier(0.2, 0.6, 0.3, 1) forwards; }
@keyframes flip-A {
  0% { transform: translateY(0) rotateY(0); }
  40% { transform: translateY(-40px) rotateY(1080deg); }
  100% { transform: translateY(0) rotateY(1800deg); }
}
@keyframes flip-B {
  0% { transform: translateY(0) rotateY(0); }
  40% { transform: translateY(-40px) rotateY(1080deg); }
  100% { transform: translateY(0) rotateY(1980deg); }
}
.toss-result { min-height: 1.5em; font-weight: 700; text-align: center; }

.win-chip { width: 72px; height: 72px; border-radius: 50%; border: 3px solid var(--chip-ring); }
.win-chip.is-A { background: radial-gradient(circle at 35% 30%, var(--chip-a-hi), var(--chip-a-lo)); }
.win-chip.is-B { background: radial-gradient(circle at 35% 30%, var(--chip-b-hi), var(--chip-b-lo)); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .side { display: contents; }
  .players { order: 1; grid-template-columns: 1fr 1fr; gap: 8px; }
  .play { order: 2; }
  .controls { order: 3; }
  .log { order: 4; }
  .player-card { padding: 10px; }
  .board-wrap { max-width: min(560px, calc((100dvh - 300px) * 6 / 7)); }
  /* Room for two lines so a longer message never pushes the board down. */
  .status { min-height: calc(2 * 1.45em + 1.4rem); padding: 0.5rem 0.75rem; }
  .topbar { padding-top: 0.5rem; padding-bottom: 0.5rem; }
  .hand .pebble { width: 11px; height: 11px; }
  .stats dt { font-size: 0.7rem; }
  .stats dd { font-size: 1rem; }
  .turn-pill { display: none; }
  .brand h1 { font-size: 1.5rem; }
}

@media (max-width: 420px) {
  .stats div:nth-child(2) { display: none; }
  .stats { grid-template-columns: 1fr 1fr; }
}

/* Reduced motion: keep fades (toast, line flash) but drop movement and pulsing. */
@media (prefers-reduced-motion: reduce) {
  .chip, .chip-inner, .btn, .point-dot { transition: none; }
  .chip.is-new .chip-inner,
  .chip.is-leaving .chip-inner,
  .chip.is-removable .chip-inner,
  .point-ring.is-target { animation: none; }
  .chip.is-leaving { opacity: 0; }
  .coin.flip-A, .coin.flip-B { animation-duration: 0.01s; }
  @keyframes toast { 0% { opacity: 0; } 10%, 80% { opacity: 1; } 100% { opacity: 0; } }
}

/* ======================================================================
   Settings, move timer, pause, point names
   ====================================================================== */

.btn-small { min-height: 36px; padding: 0.35rem 0.8rem; font-size: 0.9rem; }

/* Undo button with a small second line ("Asha: 2 left") */
#btn-undo { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.15; gap: 1px; }
.btn-sub { font-size: 0.72rem; font-weight: 600; color: var(--muted); }
.btn-sub:empty { display: none; }

.controls.has-pause { grid-template-columns: 1fr 1fr 1fr; }

/* Clock on each player card */
.clock { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.clock[hidden] { display: none; }
.clock-time {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 1.05rem;
  min-width: 3.4em;
  color: var(--muted);
}
.clock.is-running .clock-time { color: var(--text); }
.clock-bar {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.clock-bar i {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(var(--p, 1));
  background: var(--target);
  transition: transform 0.2s linear;
}
.player-card[data-player="A"] .clock-bar i { background: var(--chip-a); }
.player-card[data-player="B"] .clock-bar i { background: var(--chip-b); }
.clock.is-low .clock-time { color: #d93a2b; }
.clock.is-low .clock-bar i { background: #d93a2b; }
.clock.is-low.is-running { animation: clock-pulse 1s ease-in-out infinite; }
@keyframes clock-pulse { 50% { opacity: 0.55; } }

/* Pause overlay over the board */
.paused-overlay {
  position: absolute;
  inset: 0;
  border: 0;
  border-radius: 28px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(3px);
  color: var(--text);
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
}
.paused-overlay[hidden] { display: none; }
.paused-title { font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif; font-size: 2rem; font-weight: 700; }
.paused-sub { color: var(--muted); font-weight: 600; }

/* Point names on the board */
.coord-label {
  display: none;
  fill: var(--muted);
  font: 600 15px system-ui, sans-serif;
  text-anchor: middle;
  dominant-baseline: central;
  paint-order: stroke;
  stroke: var(--board);
  stroke-width: 4px;
  pointer-events: none;
}
#board.show-coords .coord-label { display: inline; }

/* "×3" next to a line badge when a line captured more than once */
.owner-count {
  fill: var(--mark);
  font: 800 13px system-ui, sans-serif;
  text-anchor: start;
  dominant-baseline: central;
  paint-order: stroke;
  stroke: var(--board);
  stroke-width: 3px;
}

/* Start screen / rules: settings summary */
.game-summary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
}
.summary-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; font-size: 0.9rem; color: var(--muted); }
.summary-list strong { color: var(--text); }
.coin-stage[hidden] { display: none; }

/* Settings dialog */
.dialog-wide { width: min(560px, calc(100vw - 32px)); }
.dialog-body { overflow-y: auto; max-height: calc(100dvh - 34px); }

.settings-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  background: color-mix(in srgb, var(--flash) 18%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--flash) 55%, var(--border));
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.92rem;
  font-weight: 600;
}
.settings-note[hidden] { display: none; }

.settings-group {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px 14px 6px;
  margin: 0;
  min-width: 0;
}
.settings-group legend {
  padding: 0 6px;
  font-weight: 800;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.settings-group > legend + .setting { border-top: 0; }
.setting > label, .setting > span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.setting-name { font-weight: 700; }
.setting-help { font-size: 0.82rem; color: var(--muted); }
.setting-control { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: none; max-width: 60%; }

.setting select,
.setting input[type="number"] {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.45rem 0.6rem;
  min-height: 40px;
  max-width: 100%;
}
.setting input[type="number"] { width: 4.5em; text-align: right; }
.custom-time { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px; }
.custom-time[hidden], .custom-number[hidden] { display: none; }
.custom-time label { display: inline-flex; align-items: center; gap: 4px; font-size: 0.9rem; color: var(--muted); }
.custom-time .setting-help { width: 100%; text-align: right; }

/* Switches */
.setting-switch { cursor: pointer; }
.setting-switch input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 46px;
  height: 28px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
  margin: 0;
}
.setting-switch input[type="checkbox"]::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.15s;
}
.setting-switch input[type="checkbox"]:checked { background: var(--accent); }
.setting-switch input[type="checkbox"]:checked::after { transform: translateX(18px); }

.log .auto { font-size: 0.85em; }

@media (max-width: 520px) {
  .setting { flex-wrap: wrap; }
  .setting-control { max-width: 100%; width: 100%; align-items: stretch; }
  .setting select { width: 100%; }
  .custom-time { justify-content: flex-start; }
  .custom-time .setting-help { text-align: left; }
  .controls.has-pause { grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
  .controls .btn { padding: 0.5rem 0.4rem; }
}

/* Animations turned off in settings: same as the reduced-motion preference. */
.no-anim .chip, .no-anim .chip-inner, .no-anim .btn, .no-anim .point-dot,
.no-anim .clock-bar i, .no-anim .mark-band, .no-anim .setting-switch input, .no-anim .setting-switch input::after { transition: none; }
.no-anim .chip.is-new .chip-inner,
.no-anim .chip.is-leaving .chip-inner,
.no-anim .chip.is-removable .chip-inner,
.no-anim .point-ring.is-target,
.no-anim .clock.is-low.is-running { animation: none; }
.no-anim .chip.is-leaving { opacity: 0; }
.no-anim .coin.flip-A, .no-anim .coin.flip-B { animation-duration: 0.01s; }

/* ======================================================================
   Online play
   ====================================================================== */

.conn-banner {
  margin: 0;
  padding: 0.45rem 1rem;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--flash) 22%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--flash) 60%, var(--border));
  font-weight: 700;
  text-align: center;
}
.conn-banner[hidden] { display: none; }

.you-badge {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
}
.you-badge[hidden], .presence[hidden] { display: none; }
.presence {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.6;
  flex: none;
}
.presence.is-online { background: #2fa860; opacity: 1; box-shadow: 0 0 0 3px color-mix(in srgb, #2fa860 25%, transparent); }

.controls.is-online { grid-template-columns: 1fr 1fr 1fr; }
.controls .btn[hidden] { display: none; }

/* Start screen: "Play online" entry */
.online-entry {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  border-radius: 14px;
  padding: 0.75rem 1rem;
  text-align: left;
}
.online-entry[hidden] { display: none; }
.online-entry-title { font-weight: 800; }
.online-entry-sub { font-weight: 500; font-size: 0.88rem; color: var(--muted); }

.btn-wide { width: 100%; }

#online-choose, #online-invite { display: flex; flex-direction: column; gap: 12px; }
#online-choose[hidden], #online-invite[hidden] { display: none; }

.or-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.85rem; }
.or-divider::before, .or-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.join-row { display: flex; gap: 8px; }
.code-input, .invite-link {
  flex: 1;
  min-width: 0;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.6rem 0.8rem;
}
.code-input { text-transform: uppercase; letter-spacing: 0.12em; font-weight: 700; }
.code-input::placeholder { text-transform: none; letter-spacing: normal; font-weight: 400; }

.invite-code {
  font: 800 2.2rem/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.18em;
  text-align: center;
  padding: 14px 0;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  user-select: all;
}
.invite-link-row { display: flex; gap: 8px; }
.invite-link { font-size: 0.85rem; color: var(--muted); }

.waiting { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0; color: var(--muted); font-weight: 600; }
.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.form-error { margin: 0; color: #d93a2b; font-weight: 600; }
.form-error[hidden] { display: none; }
.rematch-note { margin: 0; font-weight: 700; }
.rematch-note[hidden] { display: none; }

@media (max-width: 420px) {
  .invite-code { font-size: 1.8rem; }
  .controls.is-online .btn { font-size: 0.9rem; }
}

.no-anim .spinner { animation-duration: 2.5s; }
