/* Mancala — acacia, ebony and sand. Every colour that changes with the look
   is a custom property under [data-theme]; the board and the stones are
   painted on the canvas by render.js. Motion is transform and opacity only. */

:root {
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, 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);
  --plate: 58px;
  --bw: 340px;
  --bh: 180px;
}

/* ------------------------------------------------------------- themes */
/* Acacia: a honey-coloured board on a linen cloth by day */
:root,
[data-theme="acacia"] {
  color-scheme: light;
  --bg-a: #f5ecdc;
  --bg-b: #e2cfb0;
  --glow-1: rgba(255, 250, 236, 0.92);
  --glow-2: rgba(181, 101, 29, 0.16);
  --ink: #2e1d10;
  --ink-soft: #6c5440;
  --chip-bg: rgba(255, 252, 245, 0.52);
  --chip-line: rgba(255, 255, 255, 0.74);
  --chip-shadow: 0 1px 2px rgba(70, 40, 14, 0.12);
  --active-bg: rgba(255, 252, 244, 0.95);
  --btn-bg: rgba(255, 255, 255, 0.56);
  --btn-hover: rgba(255, 255, 255, 0.86);
  --btn-line: rgba(80, 46, 18, 0.16);
  --primary-a: #b46a2c;
  --primary-b: #84461a;
  --primary-line: #63320f;
  --primary-ink: #fff6ea;
  --danger: #b23a26;
  --paper: #fbf6ed;
  --paper-2: #f0e5d3;
  --line: rgba(80, 46, 18, 0.14);
  --accent: #a35a1c;
  --accent-soft: rgba(163, 90, 28, 0.2);
  --ca-accent: #a35a1c; /* the accounts SDK's buttons: white on it reads at 5:1 */
  --cup-a: #8a5326;
  --cup-b: #4a2810;
  --cup-ink: #fff3dc;
  --row-glow: rgba(255, 214, 140, 0.55);
  --backdrop: rgba(44, 26, 10, 0.42);
  --toast: rgba(42, 28, 16, 0.94);
}

/* Ebony: dark wood and brass under a lamp at night */
[data-theme="ebony"] {
  color-scheme: dark;
  --bg-a: #231914;
  --bg-b: #0c0807;
  --glow-1: rgba(226, 182, 100, 0.13);
  --glow-2: rgba(120, 72, 40, 0.18);
  --ink: #f4e9d6;
  --ink-soft: rgba(240, 226, 204, 0.68);
  --chip-bg: rgba(255, 240, 210, 0.05);
  --chip-line: rgba(255, 236, 200, 0.1);
  --chip-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --active-bg: rgba(255, 226, 170, 0.1);
  --btn-bg: rgba(255, 240, 210, 0.07);
  --btn-hover: rgba(255, 240, 210, 0.13);
  --btn-line: rgba(255, 226, 170, 0.18);
  --primary-a: #e5bd6e;
  --primary-b: #b98d3c;
  --primary-line: #8d6624;
  --primary-ink: #1f1407;
  --danger: #e0634b;
  --paper: #201712;
  --paper-2: #2c2019;
  --line: rgba(255, 230, 190, 0.13);
  --accent: #e2b664;
  --accent-soft: rgba(226, 182, 100, 0.22);
  --ca-accent: #a35a1c;
  --cup-a: #3a2a20;
  --cup-b: #120c09;
  --cup-ink: #f3d79a;
  --row-glow: rgba(255, 200, 110, 0.4);
  --backdrop: rgba(4, 2, 1, 0.62);
  --toast: rgba(44, 33, 25, 0.96);
}

/* Sand: a board drawn on the beach, shells for stones */
[data-theme="sand"] {
  color-scheme: light;
  --bg-a: #f4e8d0;
  --bg-b: #dcc59c;
  --glow-1: rgba(255, 253, 244, 0.95);
  --glow-2: rgba(70, 170, 178, 0.16);
  --ink: #2f2617;
  --ink-soft: #6a5a40;
  --chip-bg: rgba(255, 253, 246, 0.55);
  --chip-line: rgba(255, 255, 255, 0.78);
  --chip-shadow: 0 1px 2px rgba(80, 60, 30, 0.12);
  --active-bg: rgba(255, 254, 248, 0.95);
  --btn-bg: rgba(255, 255, 255, 0.58);
  --btn-hover: rgba(255, 255, 255, 0.88);
  --btn-line: rgba(80, 60, 30, 0.16);
  --primary-a: #3f939a;
  --primary-b: #2a6e74;
  --primary-line: #1f5559;
  --primary-ink: #f4fbfb;
  --danger: #b23a26;
  --paper: #fcf8ee;
  --paper-2: #f1e7d2;
  --line: rgba(80, 60, 30, 0.14);
  --accent: #2f7f86;
  --accent-soft: rgba(47, 127, 134, 0.2);
  --ca-accent: #2f7f86;
  --cup-a: #d9bf8e;
  --cup-b: #a88655;
  --cup-ink: #3a2c16;
  --row-glow: rgba(160, 236, 240, 0.5);
  --backdrop: rgba(50, 40, 22, 0.4);
  --toast: rgba(40, 46, 44, 0.94);
}

/* before the script runs, a dark device starts on Ebony (no flash) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg-a: #231914;
    --bg-b: #0c0807;
    --ink: #f4e9d6;
    --ink-soft: rgba(240, 226, 204, 0.68);
    --glow-1: rgba(226, 182, 100, 0.13);
    --glow-2: rgba(120, 72, 40, 0.18);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
.no-anim *, .no-anim *::before, .no-anim *::after { transition: none !important; animation: none !important; }

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: 2px solid var(--accent); outline-offset: 2px; }

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

/* ---------------------------------------------------------- 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 58s ease-in-out infinite alternate; }
.bg .g2 { width: 60vmax; height: 60vmax; right: -25vmax; bottom: -25vmax; background: var(--glow-2); animation: drift 72s 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: flex;
  flex-direction: column;
  max-width: 1240px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 10px 4px 16px; max-width: 820px; width: 100%; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 40px; height: 40px; flex: 0 0 auto; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.25)); }
.brand > span { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand b { font-family: var(--serif); font-weight: 600; font-size: 24px; letter-spacing: 0.02em; }
.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; }
/* the stones per pit, as a number and a little stone */
.brand small .seed {
  display: inline-block;
  width: 7px;
  height: 6.5px;
  margin: 0 0 0 2px;
  border-radius: 50%;
  vertical-align: 0.5px;
  background: radial-gradient(circle at 35% 30%, #fff 0 12%, var(--accent) 45%, color-mix(in srgb, var(--accent) 60%, #000) 100%);
}
.menu { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; }
.account-chip { display: flex; align-items: center; min-width: 0; margin-left: 2px; }
.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.2s, opacity 0.2s;
  flex: 0 0 auto;
  touch-action: manipulation;
}
.icon-btn:hover { background: var(--btn-bg); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn:disabled { opacity: 0.3; cursor: default; transform: none; background: transparent; }
.icon-btn svg, .btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* --------------------------------------------------------------- stage */
.stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 4px 8px; position: relative; }
/* the room the board may take (measured by app.js) */
.measure { position: absolute; inset: 4px 8px; visibility: hidden; pointer-events: none; }
/* plates and board travel together as one table, centred in the stage */
.table { display: flex; flex-direction: column; align-items: center; gap: 8px; width: var(--bw); max-width: 100%; }

/* -------------------------------------------------------------- plates */
.plate {
  position: relative;
  width: min(100%, 600px);
  height: var(--plate);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 5px 4px 5px 6px;
  border-radius: 999px;
  background: var(--chip-bg);
  border: 1px solid var(--chip-line);
  box-shadow: var(--chip-shadow);
  transition: background 0.35s, box-shadow 0.35s, rotate 0.5s var(--ease);
}
.plate::after {
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: -1px;
  height: 2.5px;
  border-radius: 2px;
  background: var(--accent);
  transform: scaleX(0);
  opacity: 0;
  transition: transform 0.4s var(--ease), opacity 0.3s;
}
.plate.active { background: var(--active-bg); box-shadow: 0 0 0 1px var(--accent-soft), 0 6px 22px -10px var(--accent); }
.plate.active::after { transform: scaleX(1); opacity: 1; }
.plate.won { box-shadow: 0 0 0 1.5px var(--accent), 0 6px 20px -8px var(--accent); }
.plate.swap-in { animation: plate-in 0.42s var(--ease); }
@keyframes plate-in { from { opacity: 0; transform: translateY(6px); } }
/* face to face: the far player reads their own plate */
.app.face .plate.seat-top { rotate: 180deg; }

/* the score: a little carved cup with the count in it */
.cup {
  position: relative;
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 58% 64%, var(--cup-a), var(--cup-b) 78%);
  box-shadow: inset 2px 3px 6px rgba(0, 0, 0, 0.45), inset -1px -1px 1px rgba(255, 255, 255, 0.18), 0 1px 0 rgba(255, 255, 255, 0.5);
}
.cup .count {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--cup-ink);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}
.cup.bump { animation: bump 0.32s var(--ease); }
@keyframes bump { 50% { transform: scale(1.14); } }

.who { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.15; }
.who b { font-size: 15.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who small { font-size: 10.5px; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; min-height: 1.15em; }
.plate.active .who small { color: var(--accent); font-weight: 600; }
.plate.thinking .who small { animation: breathe 1.4s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: 0.45; } }
.plate .icon-btn { width: 42px; height: 42px; color: var(--ink-soft); }
.plate .icon-btn svg { width: 20px; height: 20px; }
.plate .icon-btn:hover { color: var(--ink); }

/* ---------------------------------------------------------------- board */
.board { position: relative; width: var(--bw); height: var(--bh); flex: 0 0 auto; touch-action: none; cursor: default; }
.board.pointing { cursor: pointer; }
.board canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
/* the side to move: a glow that breathes over its row (no frames drawn) */
.row-glow {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(var(--w, 0px) + 22px);
  height: calc(var(--h, 0px) + 14px);
  translate: calc(var(--x, 0px) - var(--w, 0px) / 2 - 11px) calc(var(--y, 0px) - var(--h, 0px) / 2 - 7px);
  border-radius: 999px;
  background: radial-gradient(closest-side, var(--row-glow), transparent);
  mix-blend-mode: screen;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s, translate 0.6s var(--ease);
}
.row-glow.on { opacity: 1; animation: glow 3.6s ease-in-out infinite; }
.row-glow.on.thinking { animation-duration: 1.8s; }
@keyframes glow { 50% { opacity: 0.4; } }
[data-theme="acacia"] .row-glow, [data-theme="sand"] .row-glow { mix-blend-mode: soft-light; }

/* the houses as buttons: invisible, for focus and screen readers */
.pits { position: absolute; inset: 0; pointer-events: none; }
.pit, .store-label {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--w, 0px);
  height: var(--h, 0px);
  translate: calc(var(--x, 0px) - var(--w, 0px) / 2) calc(var(--y, 0px) - var(--h, 0px) / 2);
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  border-radius: 999px;
  pointer-events: none;
}
.pit:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 3px; box-shadow: 0 0 0 7px var(--accent-soft); }
.banner {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 22px;
  border-radius: 18px;
  border: 1px solid var(--chip-line);
  background: var(--paper);
  color: var(--ink);
  font: 600 19px var(--serif);
  box-shadow: 0 16px 40px -14px rgba(0, 0, 0, 0.55);
  cursor: pointer;
  animation: popc 0.32s var(--ease);
  max-width: 86%;
  text-align: center;
  white-space: nowrap;
}
.banner small { font: 500 11px var(--sans); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }

/* -------------------------------------------------------------- actions */
.actions { display: flex; gap: 10px; padding: 6px 16px 12px; width: 100%; max-width: 640px; margin: 0 auto; }
.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: 48px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.15s, background 0.2s, box-shadow 0.2s, filter 0.2s, opacity 0.2s;
}
.btn svg { width: 19px; height: 19px; flex: 0 0 auto; }
.btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; 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.24);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.18);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.start { width: 100%; margin-top: 22px; min-height: 52px; font: 600 18px var(--serif); border-radius: 16px; }
.link { appearance: none; border: 0; background: none; color: var(--ink-soft); font: 500 14px var(--sans); padding: 12px 8px 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; min-height: 40px; }
.link:hover { color: var(--ink); }
.link.danger-link { display: block; margin: 8px auto 0; color: var(--danger); }

/* -------------------------------------------------------- sheets */
.backdrop { position: fixed; inset: 0; z-index: 20; background: var(--backdrop); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: fade 0.25s; }
.backdrop.soft { background: color-mix(in srgb, var(--backdrop) 55%, transparent); -webkit-backdrop-filter: none; backdrop-filter: none; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  z-index: 21;
  max-width: 560px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.3);
  padding-bottom: env(safe-area-inset-bottom);
  animation: rise 0.32s var(--ease);
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet header { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 6px 22px; flex: 0 0 auto; }
.sheet h2 { font: 600 24px var(--serif); 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; touch-action: pan-y; }
.sheet-body h3 { font: 600 17px var(--serif); margin: 20px 0 8px; color: var(--ink); }
.sheet-body h3:first-child { margin-top: 6px; }
.prose p { margin: 0 0 12px; }
.prose p.lead { font-size: 16px; color: var(--ink); margin-top: 12px; }
.prose ul { margin: 0; padding-left: 20px; }
.prose li { margin: 5px 0; }
.prose, .prose * { -webkit-user-select: text; user-select: text; }
.muted { color: var(--ink-soft); }
.note { font-size: 13px; color: var(--ink-soft); margin: 8px 0 0; line-height: 1.45; }
.note.tight { margin: -2px 0 8px; }
.note.indent { margin: 4px 0 0 58px; }
.about { font-size: 13px; margin-top: 10px; text-align: center; color: var(--ink-soft); }
.about b { 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: pop 0.28s var(--ease); }
}
@keyframes pop { from { opacity: 0; transform: translateY(-50%) scale(0.96); } }

/* the rules' drawings */
.fig { margin: 12px 0 6px; }
.fig figcaption { font-size: 13px; color: var(--ink-soft); text-align: center; margin-top: 4px; line-height: 1.4; }
.diagram { display: block; width: 100%; max-width: 420px; margin: 0 auto; height: auto; }
.dg-body { fill: var(--paper-2); stroke: var(--line); stroke-width: 1.5; }
.dg-pit { fill: color-mix(in srgb, var(--paper-2) 70%, var(--ink) 12%); stroke: var(--line); stroke-width: 1; }
.dg-pit.tray { fill: color-mix(in srgb, var(--paper-2) 80%, var(--ink) 8%); }
.dg-pit.from { stroke: var(--accent); stroke-width: 2.4; }
.dg-pit.last { fill: color-mix(in srgb, var(--accent) 22%, var(--paper-2)); stroke: var(--accent); stroke-width: 2; }
.dg-pit.cap { fill: color-mix(in srgb, var(--danger) 18%, var(--paper-2)); stroke: var(--danger); stroke-width: 2; stroke-dasharray: 4 3; }
.dg-n { font: 700 15px var(--sans); fill: var(--ink); text-anchor: middle; }
.dg-path { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-dasharray: 1 5; }
.dg-tip { fill: var(--accent); }
.dg-note { font: 600 12px var(--sans); fill: var(--accent); text-anchor: middle; }

/* -------------------------------------------------------- choices */
.choices { display: grid; gap: 8px; }
.choices.two { grid-template-columns: 1fr 1fr; }
.choice {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 10px 12px;
  min-height: 60px;
  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;
}
.choice > svg { flex: 0 0 auto; width: 32px; height: 32px; fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.choice span { display: flex; flex-direction: column; min-width: 0; }
.choice b { font: 600 15px var(--sans); }
.choice small { font-size: 12px; color: var(--ink-soft); line-height: 1.3; margin-top: 1px; }
.choice:active { transform: scale(0.98); }
.choice[aria-checked="true"] { border-color: var(--accent); background: var(--paper); box-shadow: 0 0 0 3px var(--accent-soft); }
.choice > svg.mini-board { width: 48px; height: 24px; stroke-width: 0; }
.mb-body { fill: color-mix(in srgb, var(--accent) 22%, var(--paper-2)); stroke: var(--accent); stroke-width: 1; }
.mb-pit { fill: color-mix(in srgb, var(--accent) 55%, var(--ink) 20%); stroke: none; }
.rulesets .choice { align-items: center; }

.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  appearance: none;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  font: 500 14px var(--sans);
  padding: 8px 14px 8px 10px;
  min-height: 44px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  touch-action: manipulation;
  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); }
.opts.plain .opt { padding-left: 16px; padding-right: 16px; min-width: 64px; justify-content: center; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 4px; }
.tabs .opt { padding: 6px 12px; min-height: 40px; font-size: 13.5px; }
.pickers { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 6px; }
.pickers .tabs { margin: 0; }

/* a look's swatch: its board with three of its stones */
.swatch {
  display: inline-block;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  flex: 0 0 auto;
  position: relative;
  background: linear-gradient(160deg, var(--sa), var(--sb));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}
.swatch::before, .swatch::after { content: ""; position: absolute; width: 10px; height: 9px; border-radius: 50%; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.35), inset -1px -1px 2px rgba(0, 0, 0, 0.25), inset 1px 1px 1px rgba(255, 255, 255, 0.5); }
.swatch::before { left: 5px; top: 6px; background: var(--s1); }
.swatch::after { right: 5px; top: 9px; background: var(--s2); box-shadow: 0 1px 1px rgba(0, 0, 0, 0.35), inset -1px -1px 2px rgba(0, 0, 0, 0.25), inset 1px 1px 1px rgba(255, 255, 255, 0.5), -6px 9px 0 -1px var(--s3); }
.swatch.auto { background: linear-gradient(135deg, #e7c99b 50%, #2a1b14 50%); }
.swatch.auto::before, .swatch.auto::after { display: none; }

.toggle { display: flex; align-items: center; gap: 12px; margin-top: 14px; 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; }

.players-edit { display: grid; gap: 8px; }
.player-row { display: flex; align-items: center; gap: 10px; }
.seat-no {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font: 700 15px var(--serif);
  color: var(--cup-ink);
  background: radial-gradient(circle at 58% 64%, var(--cup-a), var(--cup-b) 78%);
  box-shadow: inset 1px 2px 4px rgba(0, 0, 0, 0.45);
}
.text-in {
  flex: 1;
  min-width: 0;
  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: 46px;
  -webkit-user-select: text;
  user-select: text;
}
.text-in:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ------------------------------------------------------------- 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-reverse; gap: 2px; }
.tile small { font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.tile b { font: 700 24px var(--serif); font-variant-numeric: tabular-nums; }
.board-mount { min-width: 0; background: var(--paper-2); border-radius: 16px; padding: 4px 10px; }
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: 12em; overflow: hidden; text-overflow: ellipsis; }
.recent { list-style: none; margin: 0; padding: 0; }
.recent li { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.recent .when { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.recent .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent .res { color: var(--ink-soft); white-space: nowrap; font-variant-numeric: tabular-nums; }
.recent .res.w { color: var(--accent); font-weight: 600; }
.recent .why { grid-column: 2 / 4; font-size: 12px; color: var(--ink-soft); }

/* ------------------------------------------------------------- dialogs */
/* centred; in face-to-face play each faces the player it speaks to */
.dialogs { position: fixed; inset: 0; z-index: 22; pointer-events: none; }
.dialog {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  width: min(92vw, 400px);
  max-height: 92dvh;
  overflow: auto;
  background: var(--paper);
  color: var(--ink);
  border-radius: 24px;
  padding: 24px 22px 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  text-align: center;
  pointer-events: auto;
  animation: popc 0.32s var(--ease);
}
@keyframes popc { from { opacity: 0; scale: 0.95; } }
.dialog p { position: relative; margin: 4px 0 18px; color: var(--ink-soft); font-size: 15.5px; line-height: 1.5; }
.dialog p.lead { color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.dialog .row { position: relative; display: flex; gap: 10px; }
.dialog .row .btn { min-width: 0; }
.dialogs.face .dialog.to-top { top: 25%; rotate: 180deg; max-height: 48dvh; }
.dialogs.face .dialog.to-bottom { top: 75%; max-height: 48dvh; }
.dialogs.face .dialog.result { width: min(92vw, 380px); padding: 12px 16px 8px; }
.dialogs.face .result .crest { height: 40px; margin: -2px auto 2px; }
.dialogs.face .result h2 { font-size: 23px; }
.dialogs.face .result p { margin: 2px 0 8px; font-size: 14.5px; }
.dialogs.face .result-stats { margin-bottom: 10px; }
.dialogs.face .dialog .btn { min-height: 44px; padding: 9px 10px; }
.dialogs.face .result .link { padding-top: 6px; min-height: 34px; }

.result { overflow: hidden; }
.result .glow { position: absolute; inset: -45% -20% auto; height: 75%; background: radial-gradient(ellipse at 50% 42%, var(--accent-soft), transparent 66%); pointer-events: none; }
.result.won .glow { background: radial-gradient(ellipse at 50% 42%, color-mix(in oklab, var(--accent) 42%, transparent), transparent 66%); }
.result .crest { position: relative; display: flex; justify-content: center; align-items: flex-end; gap: 2px; height: 50px; margin: -4px auto 6px; }
.stone-token { display: block; width: var(--size, 30px); height: var(--size, 30px); }
.result .crest .stone-token:nth-child(1) { translate: 4px -2px; }
.result .crest .stone-token:nth-child(3) { translate: -4px -1px; }
.result h2 { position: relative; margin: 0; font: 600 28px var(--serif); }
.result.won h2 { animation: shimmer 2.6s ease-in-out infinite; }
@keyframes shimmer { 50% { text-shadow: 0 0 18px color-mix(in oklab, var(--accent) 70%, transparent); } }
.result p { margin: 6px 0 14px; }
.result p.best { color: var(--accent); font-weight: 600; font-size: 14px; margin: -6px 0 14px; }
.result-stats { position: relative; display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.result-stats > span { display: inline-flex; align-items: baseline; gap: 6px; background: var(--paper-2); border-radius: 999px; padding: 5px 12px; font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.result-stats b { font-family: var(--serif); font-size: 15px; font-weight: 600; color: var(--ink); letter-spacing: 0; text-transform: none; white-space: nowrap; }

/* phones: the result card sits low, so the board stays in view */
@media (max-width: 600px) and (min-height: 600px) {
  .dialogs:not(.face) .dialog.result { top: auto; bottom: calc(12px + env(safe-area-inset-bottom)); translate: -50% 0; padding: 18px 18px 12px; }
  .result h2 { font-size: 25px; }
}

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  translate: -50% 8px; /* the individual property: applied before a rotation */
  z-index: 30;
  background: var(--toast);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  width: max-content;
  max-width: min(88vw, 440px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, translate 0.25s;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.toast.show { opacity: 1; translate: -50% 0; }
.toast.to-top { bottom: auto; top: calc(84px + env(safe-area-inset-top)); rotate: 180deg; }

/* a phone held upright with height to spare: the board grows tall (render.js
   fitBoard) and the plates grow with it */
@media (max-width: 520px) and (min-height: 740px) {
  :root { --plate: 68px; }
  .table { gap: 12px; }
  .cup { width: 54px; height: 54px; }
  .cup .count { font-size: 22px; }
  .who b { font-size: 16.5px; }
  .who small { font-size: 11px; }
}

/* ------------------------------------------------------- small screens */
@media (max-height: 720px) {
  :root { --plate: 52px; }
  .top { padding-top: 6px; }
  .brand img { width: 34px; height: 34px; }
  .brand b { font-size: 21px; }
  .cup { width: 40px; height: 40px; }
  .cup .count { font-size: 17px; }
  .actions { padding-bottom: 8px; padding-top: 4px; }
  .btn { min-height: 44px; padding: 8px 10px; }
  .table { gap: 6px; }
}
@media (max-width: 520px) {
  .dialog .btn, .sheet .btn { font-size: 14.5px; padding: 11px 10px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .choices.two .choice { padding: 8px 10px; gap: 8px; }
  .choice > svg.mini-board { width: 40px; height: 20px; }
}
@media (max-width: 440px) {
  .stage { padding-left: 4px; padding-right: 4px; }
  .measure { left: 4px; right: 4px; }
}
@media (max-width: 374px) {
  .top { padding-left: 12px; padding-right: 6px; }
  .menu .icon-btn { width: 40px; }
  .plate { gap: 7px; }
  .who b { font-size: 14px; }
  .plate .icon-btn { width: 38px; }
  .actions { padding-left: 12px; padding-right: 12px; gap: 8px; }
  .stage { padding-left: 4px; padding-right: 4px; }
  .measure { left: 4px; right: 4px; }
  .brand small { letter-spacing: 0.04em; }
  .actions .btn { font-size: 14px; padding: 8px; gap: 6px; }
  .actions .btn svg { width: 17px; height: 17px; }
}

/* low landscape (a phone on its side): the board fills the height on the
   left; header, plates and actions stack beside it (the far plate on top) */
@media (min-aspect-ratio: 5/4) and (max-height: 560px) {
  .app {
    display: grid;
    max-width: none;
    grid-template-columns: minmax(0, 1fr) minmax(250px, 320px);
    grid-template-rows: auto auto 1fr auto auto;
    column-gap: 14px;
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }
  .stage, .table { display: contents; }
  .measure { position: static; grid-column: 1; grid-row: 1 / -1; margin: 6px 0; }
  .board { grid-column: 1; grid-row: 1 / -1; align-self: center; justify-self: center; }
  .top { grid-column: 2; grid-row: 1; padding-left: 0; padding-right: 0; }
  .plate { position: relative; }
  .plate.seat-top { grid-column: 2; grid-row: 2; margin: 8px 0 0; width: 100%; }
  .plate.seat-bottom { grid-column: 2; grid-row: 4; margin: 0 0 8px; width: 100%; }
  .actions { grid-column: 2; grid-row: 5; padding-left: 0; padding-right: 0; gap: 8px; }
  .actions .btn { padding: 8px 8px; font-size: 14px; gap: 6px; }
  .toast { left: auto; right: max(20px, env(safe-area-inset-right)); translate: 0 8px; bottom: calc(80px + env(safe-area-inset-bottom)); max-width: 300px; }
  .toast.show { translate: 0 0; }
  .toast.to-top { bottom: auto; top: calc(70px + env(safe-area-inset-top)); }
  .brand small { display: none; }
  .top { padding-top: 4px; padding-bottom: 0; }
  :root { --plate: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  .bg .glow { animation: none; }
  .plate { transition-duration: 0.01s; }
  .plate.thinking .who small, .row-glow.on { animation: none; }
  .row-glow { transition: none; }
  .sheet, .dialog, .backdrop, .result h2, .banner, .plate.swap-in, .cup.bump { animation: none; }
}
