/* Brainmaster solver — styles. Mobile first; light/dark via tokens. */
:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #ebe6db;
  --board: #3a2f25;
  --board-2: #4a3d30;
  --board-line: #5b4b3b;
  --text: #1f1d1a;
  --text-2: #5f5a52;
  --text-on-board: #efe6d8;
  --text-on-board-2: #b9a993;
  --accent: #c2410c;
  --accent-soft: #fde8d7;
  --focus: #2563eb;
  --ok: #15803d;
  --border: #ddd5c6;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .06);
  --radius: 14px;
  --hole: #2a221b;
  --pin-black: #111;
  --pin-white: #f8f8f4;
  --gutter: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181d;
    --surface: #1f2228;
    --surface-2: #2a2e36;
    --board: #2b241d;
    --board-2: #362d24;
    --board-line: #46392c;
    --text: #ece8e1;
    --text-2: #a39d93;
    --accent: #fb923c;
    --accent-soft: #3b2415;
    --focus: #60a5fa;
    --ok: #4ade80;
    --border: #343842;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 16px rgb(0 0 0 / .25);
    --hole: #1a1511;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16181d; --surface: #1f2228; --surface-2: #2a2e36; --board: #2b241d; --board-2: #362d24;
  --board-line: #46392c; --text: #ece8e1; --text-2: #a39d93; --accent: #fb923c; --accent-soft: #3b2415;
  --focus: #60a5fa; --ok: #4ade80; --border: #343842; --hole: #1a1511; color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2 { margin: 0; line-height: 1.2; }
.hint { color: var(--text-2); margin: 0; }
.small { font-size: .82rem; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) var(--gutter) 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand h1 { font-size: 1.15rem; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.brand-sub { font-weight: 400; color: var(--text-2); }
.actions { display: flex; gap: 4px; }
.icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; min-width: 40px; padding: 0 10px; justify-content: center;
  background: transparent; border: 1px solid transparent; border-radius: 10px; cursor: pointer;
}
a.icon-btn { color: inherit; text-decoration: none; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:disabled { opacity: .35; cursor: default; background: none; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .lbl { font-size: .9rem; }
@media (max-width: 560px) { .icon-btn .lbl { display: none; } .brand-sub { display: none; } }
/* narrow phones (< 380px): keep the logo, hide the title visually (still read by screen readers) */
@media (max-width: 560px) { .actions { gap: 0; } .icon-btn { min-width: 36px; padding: 0 8px; } .brand h1 { font-size: 1.05rem; } }
@media (max-width: 379px) { .brand h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); } }

/* ---------- layout ---------- */
.layout {
  display: grid; gap: 14px;
  padding: 14px var(--gutter) 28px;
  max-width: 1120px; margin: 0 auto;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "stats" "board" "side";
}
.stats { grid-area: stats; }
.board-wrap { grid-area: board; }
.side { grid-area: side; display: grid; gap: 14px; align-content: start; }
@media (min-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) minmax(340px, 420px);
    grid-template-areas: "board stats" "board side";
    grid-template-rows: auto 1fr;
    align-items: start;
  }
}

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 600px) and (max-width: 899px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; box-shadow: var(--shadow); min-width: 0;
}
.tile .k { font-size: .76rem; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.tile .v { font-size: 1.65rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 2px; }
.tile .v .u { font-size: .95rem; font-weight: 600; color: var(--text-2); margin-left: 2px; }
.tile .s { font-size: .8rem; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meter { height: 4px; border-radius: 2px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 2px; transition: width .3s; }
.tile.busy .v { color: var(--text-2); }

/* ---------- board ---------- */
.board-wrap {
  background: var(--board); border-radius: calc(var(--radius) + 4px); padding: 12px 10px 14px;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .06), var(--shadow);
  color: var(--text-on-board);
}
.board-head { display: flex; justify-content: space-between; font-size: .8rem; color: var(--text-on-board-2); padding: 0 6px 8px; }
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.row {
  --peg: clamp(30px, 10.5vw, 46px);
  display: grid; align-items: center; gap: 10px;
  grid-template-columns: 1.6em auto auto 1fr;
  padding: 7px 8px; border-radius: 12px; background: var(--board-2);
}
.row.future { opacity: .45; }
@media (max-width: 899px) { .row.future { display: none; } }
.caption {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
  padding: 0 8px 4px calc(1.6em + 18px); font-size: .8rem; color: var(--text-on-board-2);
}
.caption .chip { font-size: .75rem; }
.row.future .pegs .peg { box-shadow: inset 0 2px 3px rgb(0 0 0 / .5); }
.row.current { margin-bottom: 0; background: color-mix(in srgb, var(--board-2) 70%, var(--accent) 30%); outline: 2px solid color-mix(in srgb, var(--accent) 70%, transparent); }
.row.over .num { color: #f87171; }
.num { font-size: .85rem; color: var(--text-on-board-2); text-align: right; font-variant-numeric: tabular-nums; }
.pegs { display: flex; gap: clamp(5px, 1.8vw, 9px); }
.peg {
  width: var(--peg); height: var(--peg); border-radius: 50%; border: 0; padding: 0;
  background: radial-gradient(circle at 34% 30%, color-mix(in srgb, var(--c) 55%, white) 0 12%, var(--c) 45%, color-mix(in srgb, var(--c) 70%, black) 100%);
  box-shadow: 0 2px 3px rgb(0 0 0 / .45);
  display: grid; place-items: center;
  font-size: calc(var(--peg) * .38); font-weight: 700; color: var(--ink, #fff);
  text-shadow: 0 1px 1px rgb(0 0 0 / .25);
  -webkit-tap-highlight-color: transparent;
}
.peg.empty { background: var(--hole); box-shadow: inset 0 2px 4px rgb(0 0 0 / .6); }
.peg.small { --peg: 22px; }
button.peg { cursor: pointer; transition: transform .12s; }
button.peg:hover { transform: translateY(-1px); }
button.peg.sel { outline: 3px solid #fff; outline-offset: 2px; }
.no-numbers .peg span { display: none; }

.pins { display: grid; gap: 3px; justify-content: start; }
.pin { width: 11px; height: 11px; border-radius: 50%; background: var(--hole); box-shadow: inset 0 1px 2px rgb(0 0 0 / .6); }
.pin.b { background: radial-gradient(circle at 35% 30%, #555, var(--pin-black) 60%); box-shadow: 0 1px 1px rgb(0 0 0 / .5); }
.pin.w { background: radial-gradient(circle at 35% 30%, #fff, #d9d6cc 70%); box-shadow: 0 1px 1px rgb(0 0 0 / .5); }

.meta { justify-self: end; text-align: right; font-size: .78rem; color: var(--text-on-board-2); line-height: 1.25; font-variant-numeric: tabular-nums; min-width: 0; }
.meta b { color: var(--text-on-board); font-weight: 600; }
.chip {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 600;
  background: rgb(255 255 255 / .12); color: var(--text-on-board); white-space: nowrap;
}
.chip.exact { background: color-mix(in srgb, var(--ok) 35%, transparent); }
.chip.user { background: color-mix(in srgb, #60a5fa 35%, transparent); }
.linkish { background: none; border: 0; padding: 2px 0; color: var(--text-on-board); text-decoration: underline; cursor: pointer; font-size: .78rem; }

.palette {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 10px; margin-top: 2px;
  background: var(--board-2); border-radius: 12px; justify-content: center;
}
.palette .peg { --peg: 40px; }
.palette-label { width: 100%; text-align: center; font-size: .78rem; color: var(--text-on-board-2); }

.spinner {
  width: 16px; height: 16px; border-radius: 50%; display: inline-block; vertical-align: -3px;
  border: 2px solid rgb(255 255 255 / .25); border-top-color: var(--text-on-board);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(1turn); } }

.banner {
  margin-top: 10px; padding: 14px; border-radius: 12px; text-align: center;
  background: color-mix(in srgb, var(--ok) 25%, var(--board-2)); color: var(--text-on-board);
}
.banner h3 { margin: 0 0 4px; font-size: 1.25rem; }
.banner .btn { margin-top: 8px; }

/* ---------- answer pad ---------- */
.pad-wrap, .remaining {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.pad-head h2 { font-size: 1.05rem; }
.pad-head .hint { font-size: .85rem; margin: 2px 0 10px; }
.pad { display: grid; gap: 6px; }
.pad-row { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 6px; align-items: stretch; }
.ans {
  display: grid; justify-items: center; align-content: center; gap: 4px;
  min-height: 58px; padding: 6px 2px; border-radius: 10px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border);
  -webkit-tap-highlight-color: transparent; transition: transform .08s, background .15s;
}
.ans:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); }
.ans:active:not(:disabled) { transform: scale(.96); }
.ans:disabled { opacity: .28; cursor: not-allowed; }
.ans .pins { --pin-hole: var(--surface); }
.ans .pin { width: 10px; height: 10px; }
.ans .pin:not(.b):not(.w) { background: transparent; box-shadow: inset 0 0 0 1.5px var(--text-2); opacity: .45; }
.ans .p { font-size: .72rem; color: var(--text-2); font-variant-numeric: tabular-nums; line-height: 1; }
.ans.win { background: color-mix(in srgb, var(--ok) 18%, var(--surface-2)); }
.ans.win .p { color: var(--ok); font-weight: 700; }
#pad-foot { margin-top: 10px; }
.pad-wrap.disabled .pad { pointer-events: none; opacity: .5; }

/* ---------- remaining ---------- */
.remaining summary { cursor: pointer; font-weight: 600; }
.remaining-list { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 10px; }
.remaining-list .pegs { gap: 3px; }
.remaining-list .more { width: 100%; font-size: .82rem; color: var(--text-2); }

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 18px; padding: 0; background: var(--surface); color: var(--text);
  width: min(520px, calc(100vw - 2 * var(--gutter))); max-height: calc(100dvh - 32px); box-shadow: 0 20px 60px rgb(0 0 0 / .35);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
.dlg { padding: 20px; display: grid; gap: 14px; }
.dlg h2 { font-size: 1.15rem; }
.prose { gap: 8px; }
.prose h2 { margin-top: 8px; }
.prose p, .prose ul, .prose ol { margin: 0; }
.prose li { margin: 3px 0; }
.prose a { color: var(--accent); font-weight: 600; text-underline-offset: 2px; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field-label { font-weight: 600; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.stepper button { width: 44px; height: 40px; border: 0; background: var(--surface-2); cursor: pointer; font-size: 1.2rem; }
.stepper button:disabled { opacity: .35; cursor: default; }
.stepper output { min-width: 3ch; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.switch { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.switch input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.btn {
  min-height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer; font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }


@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation-duration: 0s !important; } }
