:root {
  --bg: #ecefe8;
  --card: #fdfefb;
  --ink: #1f2620;
  --muted: #6b7568;
  --line: #d9dfd3;
  --accent: #1f7a4d;
  --accent-ink: #fff;
  --btn: #f2f5ee;
  --btn-hover: #e3eadc;
  --good: #2f9e61;
  --warn: #d2413a;
  --chance: #2f7fbf;
  --shadow: 0 1px 2px rgba(20, 40, 20, .08), 0 6px 20px rgba(20, 40, 20, .07);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161a17;
    --card: #1f2520;
    --ink: #e4ebe2;
    --muted: #97a393;
    --line: #333c33;
    --accent: #3fa36d;
    --btn: #29302a;
    --btn-hover: #333b34;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
  .g-white { opacity: .14; } /* keep the light win-rate line readable on the graph's lower band */
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, select, input { font: inherit; color: inherit; }
kbd {
  font: 11px/1 ui-monospace, Consolas, monospace; padding: 2px 5px; border-radius: 4px;
  border: 1px solid var(--line); background: var(--btn); color: var(--muted);
}
.muted { color: var(--muted); }
.small { font-size: 12px; font-weight: 400; }

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 22px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 14px 18px 40px;
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); padding: 10px 16px 40px; }
}

/* ---------------------------------------------------------------- board column */
.board-col { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.topbar {
  width: 100%; max-width: min(100%, calc(100vh - 170px)); min-width: min(100%, 420px);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; flex-wrap: wrap;
}
.brand { font-weight: 750; font-size: 20px; letter-spacing: .2px; white-space: nowrap; }
.brand .logo { width: 28px; height: 28px; border-radius: 6px; vertical-align: -7px; margin-right: 8px; }
.brand span { color: var(--accent); font-weight: 600; }
.players { display: flex; gap: 8px; }
.player {
  display: flex; align-items: center; gap: 7px; padding: 5px 10px; border-radius: 999px;
  background: var(--card); border: 2px solid transparent; box-shadow: var(--shadow); font-size: 14px;
}
.player.turn { border-color: var(--accent); }
.player .count { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 2ch; text-align: right; }
.player .mob { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.player .mob::before { content: "·"; margin-right: 6px; }
.player.thinking .pname::after { content: " …"; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.disc-icon { width: 16px; height: 16px; border-radius: 50%; display: inline-block; flex: none; }
.disc-icon.black { background: radial-gradient(circle at 35% 30%, #666, #000 70%); }
.disc-icon.white { background: radial-gradient(circle at 35% 30%, #fff, #bbb 90%); box-shadow: inset 0 0 0 1px #aaa; }

.board-wrap {
  width: 100%;
  max-width: min(100%, calc(100vh - 170px));
  min-width: min(100%, 420px);
  aspect-ratio: 1;
  touch-action: manipulation;
}
.board-svg { width: 100%; height: 100%; display: block; border-radius: 12px; box-shadow: 0 10px 30px rgba(10, 40, 20, .3); cursor: pointer; user-select: none; }
.board-svg text { font-family: system-ui, sans-serif; }
.region-num { font-size: 24px; font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.disc-num { text-anchor: middle; dominant-baseline: central; font-weight: 700; pointer-events: none; }
.hint-main { text-anchor: middle; dominant-baseline: central; font-size: 30px; font-weight: 750; fill: #fff; pointer-events: none; }
.hint-sub { text-anchor: middle; dominant-baseline: central; font-size: 21px; font-weight: 600; fill: #fff; opacity: .9; pointer-events: none; }
.disc { transform-box: fill-box; transform-origin: center; }
.disc.fresh { animation: drop .16s ease-out; }
@keyframes drop { from { transform: scale(1.2); opacity: .4; } to { transform: scale(1); opacity: 1; } }
/* A flip: the old colour narrows to an edge, then the new colour widens. */
.disc.flip-out { animation: flipOut .13s ease-in var(--d, .1s) both; }
.disc.flip-in { animation: flipIn .13s ease-out calc(var(--d, .1s) + .13s) both; }
@keyframes flipOut { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes flipIn { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@media (prefers-reduced-motion: reduce) {
  .disc.fresh, .disc.flip-in, .disc.flip-out { animation: none; transform: none; }
  .disc.flip-out { display: none; }
}

.message {
  min-height: 2.9em; width: 100%; max-width: min(100%, calc(100vh - 170px));
  padding: 8px 4px 0; text-align: center; color: var(--muted);
}
.message.bad { color: var(--warn); font-weight: 600; }

.controls, .nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 6px; }
button {
  background: var(--btn); border: 1px solid var(--line); border-radius: 9px; padding: 7px 12px; cursor: pointer;
  transition: background .12s;
}
button:hover:not(:disabled) { background: var(--btn-hover); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.07); background: var(--accent); }
button.on { background: #fff3c4; border-color: #e2c35a; color: #3b2f00; }
button.pass-btn { display: none; }
.nav { align-items: center; }
.nav button { min-width: 42px; }
.move-label { min-width: 170px; text-align: center; font-variant-numeric: tabular-nums; }
/* Phones: the row spans the board and the label gives way, rather than wrapping (it needs 362px). */
@media (max-width: 480px) {
  .nav { align-self: stretch; flex-wrap: nowrap; }
  .move-label { min-width: 0; flex: 1; }
}
.variations { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center; margin-top: 8px; font-size: 13px; }
.chip { padding: 3px 9px; border-radius: 999px; font-size: 13px; }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------------------------------------------------------------- side */
.side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card { background: var(--card); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.coach { min-height: 400px; } /* room for a typical comment from the start; it grows from there (holdCoachHeight) */
.card h2 { font-size: 15px; margin: 0 0 10px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }

.winbar {
  position: relative; height: 26px; border-radius: 8px; overflow: hidden;
  background: #f4f3ee; border: 1px solid #c9cfc3;
}
.winbar-b { position: absolute; inset: 0 auto 0 0; background: linear-gradient(#3a3a3a, #111); transition: width .35s; }
.wl { position: absolute; top: 50%; transform: translateY(-50%); font-size: 12px; font-weight: 650; }
.wl-b { left: 8px; color: #fff; mix-blend-mode: difference; }
.wl-w { right: 8px; color: #222; }
.score-est { margin: 6px 0 4px; font-size: 14px; }
.opening { margin: 0 0 8px; font-size: 14px; }

.feedback p { margin: 6px 0; }
.feedback .tip { color: var(--ink); background: color-mix(in srgb, var(--accent) 8%, transparent); padding: 8px 10px; border-radius: 8px; }
.fb-entry { padding: 8px 0; }
.fb-entry + .fb-entry { border-top: 1px solid var(--line); }
.fb-entry:not(.latest) { opacity: .8; }
.fb-entry:first-child { padding-top: 0; }
.fb-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--pill, #888); color: #fff; letter-spacing: .2px;
}
.pill.pending { background: var(--line); color: var(--muted); }
.fb-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.fb-actions button { font-size: 13px; padding: 5px 10px; }
.explain, .warnings { list-style: none; margin: 8px 0 0; padding: 0; }
.explain li { padding: 3px 0 3px 18px; position: relative; font-size: 14px; }
.explain li::before { content: "›"; position: absolute; left: 4px; color: var(--accent); font-weight: 700; }
.warnings li { margin-top: 6px; padding: 6px 9px; border-radius: 8px; font-size: 13.5px; }
.warnings .warn { background: color-mix(in srgb, var(--warn) 12%, transparent); border-left: 3px solid var(--warn); }
.warnings .chance { background: color-mix(in srgb, var(--chance) 12%, transparent); border-left: 3px solid var(--chance); }

.threat-box {
  margin-top: 10px; padding: 8px 10px; border-radius: 8px; font-size: 14px;
  background: color-mix(in srgb, #e03131 10%, transparent); border-left: 3px solid #e03131;
}
.threat-box p { margin: 4px 0; }
.review { margin-top: 10px; display: grid; gap: 7px; font-size: 13px; }
.rv-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.rv-row .pill { font-size: 11px; padding: 1px 7px; }
.rv-worst { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.graph { height: 110px; cursor: pointer; }
.graph-svg { width: 100%; height: 100%; display: block; border-radius: 6px; }
/* Upper half is Black's side of 50%, lower half is White's; tinted to match. */
.g-black { fill: #2d2a26; opacity: .12; }
.g-white { fill: #fff; opacity: .6; }
.g-mid { stroke: var(--muted); stroke-dasharray: 4 4; opacity: .5; }
.g-cur { stroke: var(--accent); stroke-width: 2; }
.g-wr { fill: none; stroke: var(--ink); stroke-width: 2; }
.g-score { fill: none; stroke: #3b82c4; stroke-width: 1.5; stroke-dasharray: 5 3; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; vertical-align: middle; margin-right: 5px; }
.lg-wr { width: 16px; border-top: 2px solid var(--ink); }
.lg-score { width: 16px; border-top: 2px dashed #3b82c4; }
.lg-dot { width: 9px; height: 9px; border-radius: 50%; }

.toggles { display: grid; gap: 4px; }
.toggle { display: grid; grid-template-columns: 38px 1fr; column-gap: 8px; align-items: center; cursor: pointer; padding: 4px 0; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle .sw { width: 34px; height: 20px; border-radius: 999px; background: var(--line); position: relative; transition: background .15s; }
.toggle .sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.toggle input:checked + .sw { background: var(--accent); }
.toggle input:checked + .sw::after { transform: translateX(14px); }
.toggle input:focus-visible + .sw { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle .tl { font-weight: 600; font-size: 14px; }
.toggle small { grid-column: 2; color: var(--muted); font-size: 12px; line-height: 1.35; }

.settings { display: grid; gap: 10px; }
.settings label { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.settings label.inline { justify-content: flex-start; }
.settings select { padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--btn); }
.settings .help { margin-top: -6px; font-size: 12px; }
.settings .row { display: flex; gap: 8px; }

.learn details { border-top: 1px solid var(--line); padding: 8px 0; }
.learn details:first-of-type { border-top: 0; padding-top: 0; }
.learn summary { cursor: pointer; font-weight: 600; }
.learn p, .learn ul { margin: 6px 0; font-size: 14px; }
.learn ul { padding-left: 20px; }
.credits { font-size: 12px; line-height: 1.5; color: var(--muted); text-align: center; padding: 0 8px; }
.credits a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.credits a:hover { color: var(--accent); }

.score-panel { border: 2px solid var(--accent); }
.score-panel .big { font-size: 20px; font-weight: 700; margin: 4px 0 8px; }
.score-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; margin-bottom: 6px; }
.score-table th, .score-table td { padding: 4px 6px; text-align: right; border-bottom: 1px solid var(--line); }
.score-table th:first-child, .score-table td:first-child { text-align: left; }
.score-table .total td { font-weight: 700; border-bottom: 0; }
.score-panel p.muted { font-size: 13px; margin: 6px 0; }
.score-panel .advice { background: color-mix(in srgb, var(--good) 14%, transparent); padding: 6px 9px; border-radius: 8px; font-size: 14px; }

/* ---------------------------------------------------------------- dialog */
dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 32px));
  background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
dialog::backdrop { background: rgba(20, 15, 5, .45); }
dialog form { padding: 18px 20px; }
dialog h2 { margin: 0 0 10px; }
fieldset { border: 0; padding: 0; margin: 0 0 14px; }
legend { font-weight: 650; margin-bottom: 6px; }
fieldset.row { display: flex; gap: 16px; flex-wrap: wrap; }
fieldset.row label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
fieldset.row select, fieldset.row input { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--btn); width: 120px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg label, .level { cursor: pointer; }
.seg input, .level input { position: absolute; opacity: 0; }
.seg span { display: block; padding: 7px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--btn); }
.seg input:checked + span, .level input:checked + span { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--btn)); }
.seg input:focus-visible + span, .level input:focus-visible + span { outline: 2px solid var(--accent); }
.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px; }
.level span { display: block; padding: 8px 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--btn); height: 100%; }
.level small { display: block; color: var(--muted); font-size: 12px; line-height: 1.3; margin-top: 2px; }
menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 10px 0 0; }
.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; }
.coords text { transition: font-size 0.12s, fill 0.12s; }
.coords text.on { font-size: 36px; font-weight: 800; fill: #fff; }

/* ---------------------------------------------------------------- puzzles */
.puzzle-panel { border: 2px solid #7b5ea7; }
.puzzle-panel .big { font-size: 17px; font-weight: 700; margin: 4px 0 8px; }
.puzzle-panel .big.good { color: var(--good); }
.puzzle-panel .big.bad { color: var(--warn); }
.puzzle-panel p { margin: 6px 0; }
.hint-line { background: color-mix(in srgb, #e2c35a 22%, transparent); padding: 6px 9px; border-radius: 8px; font-size: 14px; }
.lesson { background: color-mix(in srgb, #7b5ea7 12%, transparent); border-left: 3px solid #7b5ea7; padding: 6px 9px; border-radius: 6px; font-size: 14px; }
.pz-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; flex-wrap: wrap; }
.pz-foot select { padding: 4px 6px; border-radius: 8px; border: 1px solid var(--line); background: var(--btn); }
