/* Play Clumpity: the hand-colored board, its parchment rulebook, and the pastel letters of the bag's label. The
   letters are the original board's own, traced (letters.js), not a font. */
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("/atkinson-hyperlegible-next.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
}

:root {
  --ink: #1f1b16;
  --bg: #f4ecd8;
  --panel: #fffaf0;
  --text: #1f1b16;
  --muted: #5f574a;
  --line: #d9cdb1;
  --accent: #2178b4;
  --accent-ink: #ffffff;
  --win: #2e7d4f;
  --warn: #a4400f;
  /* The pawns, dice and chips. */
  --yellow: #f2c230; --green: #1f9a5b; --red: #d9342b; --blue: #2b62d0;
  /* The board's wedges, as colored by hand. */
  --w-yellow: #eab950; --w-green: #2f8a45; --w-red: #f2895c; --w-blue: #36a4de; --w-white: #fbf8f0;
  /* The bag label's letters. */
  --l-c: #c9c35a; --l-u: #8fd3a5; --l-p: #ef8f9a; --l-t: #8fb3e0; --l-w: #fbf8f0;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1915; --panel: #26231d; --text: #f0ebe0; --muted: #b3aa98; --line: #3d382e; --accent: #5fb2ea;
    --accent-ink: #0d1b26; --win: #7fcb9b; --warn: #f0a57a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1915; --panel: #26231d; --text: #f0ebe0; --muted: #b3aa98; --line: #3d382e; --accent: #5fb2ea;
  --accent-ink: #0d1b26; --win: #7fcb9b; --warn: #f0a57a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 "Atkinson Hyperlegible Next", system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
a { color: var(--accent); }

/* ---------- header ---------- */
.bar { background: #2a2520; color: #fff; }
.bar-in { max-width: 1120px; margin: 0 auto; padding: 10px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px; }
.mark { margin: 0; line-height: 1; display: flex; align-items: flex-start; gap: 2px; }
.mark-art { height: 2.6rem; width: auto; display: block; overflow: visible; }
.mark .tm { font: 700 0.75rem "Atkinson Hyperlegible Next", sans-serif; color: #fff; }
.letter .ink { fill: #000; fill-rule: evenodd; }
.letter .face { fill-rule: evenodd; }
.tag { margin: 0; font-weight: 600; color: #e9e1d0; }
.links { margin-left: auto; display: flex; gap: 14px; flex-wrap: wrap; }
.link { background: none; border: 0; padding: 0; color: #fff; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

main { flex: 1; width: 100%; max-width: 1120px; margin: 0 auto; padding: 16px; }
h2 { margin: 0 0 12px; font-size: 1.35rem; }

.go {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 999px; padding: 10px 22px;
  font-weight: 700; cursor: pointer; min-height: 44px;
}
.go:disabled { opacity: 0.45; cursor: default; }
.ghost-btn {
  background: transparent; border: 2px solid var(--line); border-radius: 999px; padding: 8px 18px; font-weight: 700;
  cursor: pointer; min-height: 44px;
}
.go:focus-visible, .ghost-btn:focus-visible, .move:focus-visible, .mode:focus-visible, .seg button:focus-visible,
.stepper button:focus-visible, .link:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.hint { color: var(--muted); font-size: 0.92rem; margin: 6px 0 0; }

/* ---------- setup ---------- */
.setup { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; max-width: 760px; margin: 16px auto; }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-bottom: 16px; }
.mode {
  text-align: left; background: var(--bg); border: 2px solid var(--line); border-radius: 12px; padding: 12px 14px;
  cursor: pointer; display: flex; flex-direction: column; gap: 2px;
}
.mode strong { font-size: 1.05rem; }
.mode span { color: var(--muted); font-size: 0.9rem; }
.mode[aria-checked="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.mode .kind { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; color: var(--accent); }
.mode-opts { margin: 0 0 14px; border: 0; padding: 0; }
.mode-opts legend { font-weight: 700; margin-bottom: 6px; padding: 0; }
.steppers { display: flex; flex-wrap: wrap; gap: 12px 28px; }
.stepper { display: flex; flex-direction: column; gap: 4px; }
.stepper-label { font-weight: 700; }
.stepper-ctl { display: flex; align-items: center; gap: 10px; }
.stepper-ctl button {
  width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--line); background: var(--bg); font-size: 1.3rem;
  font-weight: 700; cursor: pointer;
}
.stepper-ctl button:disabled { opacity: 0.4; cursor: default; }
.stepper-ctl output { min-width: 1.5ch; text-align: center; font-size: 1.4rem; font-weight: 700; }
.seg { display: inline-flex; border: 2px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 8px 18px; font-weight: 700; cursor: pointer; min-height: 40px; }
.seg button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }
.mode-blurb { margin: 0 0 16px; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 12px; }
.field label { font-weight: 700; }
.field-row { display: flex; gap: 8px; }
.field-row .text { flex: 1; min-width: 0; }
.text {
  font: inherit; color: var(--text); background: var(--bg); border: 2px solid var(--line); border-radius: 10px;
  padding: 8px 12px; min-height: 44px; max-width: 100%;
}
.text:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.text.code { text-transform: uppercase; letter-spacing: 0.15em; font-weight: 700; max-width: 10ch; }
.ghost-btn.small, .go.small { min-height: 36px; padding: 5px 14px; font-size: 0.92rem; }
.field .hint { margin: 2px 0 0; }
.field.join { margin-top: 16px; }
.seats-hint { margin: -4px 0 12px; }
.rejoin { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 8px; }
.error { color: var(--warn); font-weight: 700; margin: 0; min-height: 1.2em; }
.muted { color: var(--muted); }

/* ---------- an online room's lobby ---------- */
.lobby { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; max-width: 760px; margin: 16px auto; }
.eyebrow { margin: 0; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; color: var(--accent); }
.room-code { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; letter-spacing: 0.12em; }
.lobby-status { margin: 0 0 14px; font-weight: 600; }
.seats-title { font-size: 1rem; margin: 6px 0 6px; }
.seats { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.seat { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--bg); border: 2px solid var(--line); border-radius: 12px; padding: 6px 10px; min-height: 52px; }
.seat.you { border-color: var(--accent); }
.seat-n { width: 1.8em; height: 1.8em; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--panel); border: 1px solid var(--line); flex: none; }
.seat-who { flex: 1; min-width: 8em; }
.seat-who small { color: var(--muted); }
.seat-ctl { display: flex; gap: 6px; flex-wrap: wrap; }
.seat-add { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 14px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 10; margin: 0; max-width: calc(100% - 32px);
  background: #2a2520; color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 600; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}

/* ---------- the table ---------- */
.table { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.board-wrap { position: sticky; top: 12px; }
.board { width: 100%; max-width: 560px; display: block; margin: 0 auto; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.18)); }
.where { text-align: center; color: var(--muted); min-height: 1.5em; margin: 8px 0 0; }

.board .wedge { stroke: #111; stroke-width: 2.2; stroke-linejoin: round; }
.board .rim { fill: #efe5c8; stroke: #6b5a3a; stroke-width: 3; }
.board .hub { fill: #f4efe2; stroke: #111; stroke-width: 2; }
.board .hub-arrow { fill: none; stroke: #222; stroke-width: 1.8; }
.board .target { fill: none; stroke: #111; stroke-width: 4; stroke-dasharray: 7 6; opacity: 0; transition: opacity 0.15s; }
.board .target.on { opacity: 1; }
.board .pawn { stroke: #111; stroke-width: 2; transition: transform 0.35s ease; }
.board .pawn-g { cursor: default; }
.board .pawn-g.can { cursor: pointer; }
.board .pawn-g.can .pawn { stroke-width: 3; }
.board .pawn-g:focus-visible { outline: none; }
.board .pawn-g:focus-visible .pawn { stroke: var(--accent); stroke-width: 4; }
.board .flash { fill: none; stroke: #111; stroke-width: 3; }
.board .count { font: 700 15px "Atkinson Hyperlegible Next", sans-serif; text-anchor: middle; dominant-baseline: central; fill: #111; }

.panel { display: flex; flex-direction: column; gap: 14px; }
.turn-head { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.turn-line { margin: 0; font-size: 1.2rem; font-weight: 700; }
.game-line { margin: 2px 0 0; color: var(--muted); }
.banner { border-radius: 12px; padding: 10px 14px; font-weight: 700; background: #fff3c4; color: #4a3800; border: 1px solid #e6cf73; }

.dice-area { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.dice { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.die-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.die-row.used { opacity: 0.55; }
.die {
  width: 46px; height: 46px; border-radius: 9px; border: 2px solid #111; flex: none; display: grid;
  grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); padding: 5px; position: relative;
}
.die i { width: 8px; height: 8px; border-radius: 50%; background: #fff; place-self: center; box-shadow: 0 0 0 1px rgba(0,0,0,0.35); }
.die.c0 { background: #d49a1c; } .die.c1 { background: var(--green); } .die.c2 { background: var(--red); } .die.c3 { background: var(--blue); }
.die-row.used .die::after { content: "✓"; position: absolute; right: -8px; top: -10px; background: var(--panel); color: var(--win); border-radius: 50%; font-weight: 800; width: 20px; height: 20px; display: grid; place-items: center; border: 1px solid var(--line); font-size: 0.8rem; }
.moves { display: flex; flex-wrap: wrap; gap: 6px; }
.move {
  border: 2px solid var(--line); background: var(--bg); border-radius: 10px; padding: 6px 10px; cursor: pointer;
  text-align: left; min-height: 44px; display: flex; flex-direction: column; justify-content: center;
}
.move b { font-size: 1rem; }
.move small { color: var(--muted); }
.move.clumps { border-color: #111; }
.move:disabled { cursor: not-allowed; opacity: 0.5; }
.move:not(:disabled):hover { border-color: var(--accent); }
.done-note { color: var(--muted); }
.turn-ctl { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.haul { margin: 0; min-height: 1.4em; font-weight: 600; }

.chip { display: inline-block; width: 0.85em; height: 0.85em; border-radius: 50%; border: 1.5px solid #111; vertical-align: -0.1em; margin-right: 2px; }
.chip.c0 { background: var(--yellow); } .chip.c1 { background: var(--green); } .chip.c2 { background: var(--red); } .chip.c3 { background: var(--blue); }

.scores { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.scores th, .scores td { padding: 8px 8px; text-align: center; border-bottom: 1px solid var(--line); }
.scores th:first-child, .scores td:first-child { text-align: left; }
.scores thead th { font-size: 0.8rem; color: var(--muted); font-weight: 700; }
.scores tr.now td { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.scores td.score { font-weight: 800; font-size: 1.1rem; }
.scores .who-computer { color: var(--muted); font-size: 0.8rem; display: block; }
.scores tr:last-child td { border-bottom: 0; }

.bowls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.bowl { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 6px; text-align: center; }
.bowl b { display: block; font-size: 1.6rem; line-height: 1.1; }
.bowl small { color: var(--muted); }
.bowl.empty b { color: var(--win); }

.log-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; }
.log-wrap summary { cursor: pointer; font-weight: 700; }
.log { margin: 8px 0 0; padding-left: 1.2em; max-height: 240px; overflow: auto; font-size: 0.92rem; }
.log li { margin: 2px 0; }

/* ---------- results ---------- */
.result { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; max-width: 640px; margin: 16px auto; }
.result-ctl { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.big { font-size: 2.4rem; font-weight: 800; margin: 4px 0; }
.result table { border-collapse: collapse; width: 100%; }
.result td, .result th { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }

/* ---------- how to play ---------- */
.howto { border: 0; border-radius: 16px; padding: 0; max-width: 640px; width: calc(100% - 32px); background: var(--panel); color: var(--text); }
.howto::backdrop { background: rgba(0, 0, 0, 0.5); }
.howto-in { padding: 20px 22px; max-height: 85vh; overflow: auto; }
.howto h3 { margin: 16px 0 4px; font-size: 1.05rem; }
.howto p, .howto li { margin: 4px 0; }
.howto table { border-collapse: collapse; margin: 6px 0; }
.howto td, .howto th { border: 1px solid var(--line); padding: 3px 10px; text-align: center; }

.foot { text-align: center; color: var(--muted); font-size: 0.85rem; padding: 18px 16px 24px; }
.foot p { margin: 0; }

@media (max-width: 820px) {
  .table { grid-template-columns: 1fr; }
  .board-wrap { position: static; }
  .board { max-width: min(330px, 86vw); }
  .mark-art { height: 2.1rem; }
  .tag { font-size: 0.9rem; }
  .links { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .board .pawn, .board .target { transition: none; }
}
