:root {
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --text: #2a2722;
  --muted: #6b655b;
  --line: #ddd5c6;
  --accent: #6b4a2b;
  --accent-text: #ffffff;
  --warn: #a8321f;
  --info: #3d5a4b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a17;
    --panel: #262320;
    --text: #ece7de;
    --muted: #a59d90;
    --line: #3a362f;
    --accent: #c79a64;
    --accent-text: #1c1a17;
    --warn: #ff8f7d;
    --info: #9cc7b0;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.7 "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", "Noto Sans CJK JP", system-ui, sans-serif;
}
a { color: var(--accent); }
.top {
  display: flex; align-items: baseline; gap: 12px;
  max-width: 1100px; margin: 0 auto; padding: 14px 16px 4px;
}
.top h1 { margin: 0; font-size: 1.4rem; letter-spacing: 0.08em; font-weight: 600; }
.top-actions { margin-left: auto; display: flex; gap: 6px; align-self: center; }
.top-actions button { min-height: 36px; padding: 4px 12px; font-size: 0.9rem; }
.top-actions button.icon { padding: 4px 8px; width: 40px; display: inline-flex; align-items: center; justify-content: center; }
body[data-view="setup"] .top-actions { display: none; }
/* before a game: the card sits in the middle and the title lines up with its left edge (520px card + 16px gutters) */
body[data-view="setup"] .top, body[data-view="setup"] main, body[data-view="setup"] footer { max-width: 552px; }
/* during a game the page is exactly as wide as board + panel, so the header buttons end at the panel's right edge */
body[data-view="play"] .top, body[data-view="play"] main, body[data-view="play"] footer { max-width: min(1100px, calc(min(100vh - 230px, 100vw - 440px) + 412px)); }
main { max-width: 1100px; margin: 0 auto; padding: 8px 16px 24px; }
footer { max-width: 1100px; margin: 0 auto; padding: 0 16px 24px; color: var(--muted); font-size: 0.85rem; }

.panel {
  max-width: 520px; margin: 16px 0; padding: 20px 20px 24px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.panel h2 { margin: 0 0 12px; font-size: 1.1rem; }
fieldset { border: 0; padding: 0; margin: 0 0 14px; }
legend { padding: 0; margin-bottom: 6px; color: var(--muted); font-size: 0.9rem; }
.seg { display: flex; gap: 8px; }
.seg label { flex: 1; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block; text-align: center; padding: 10px 0; min-height: 44px;
  border: 1px solid var(--line); border-radius: 8px; cursor: pointer; background: transparent;
}
.seg input:checked + span { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.field { flex: 1 1 160px; display: block; margin-bottom: 8px; }
.field span { display: block; color: var(--muted); font-size: 0.9rem; margin-bottom: 4px; }
select, input[type="number"] {
  width: 100%; min-height: 44px; padding: 8px 10px; font: inherit; color: inherit;
  background: transparent; border: 1px solid var(--line); border-radius: 8px;
}
.hint { margin: 4px 0 16px; color: var(--muted); font-size: 0.88rem; }

button {
  font: inherit; color: inherit; background: transparent; cursor: pointer;
  min-height: 44px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.layout { display: grid; grid-template-columns: minmax(0, min(calc(100vh - 230px), calc(100vw - 440px))) 360px; gap: 20px; align-items: start; justify-content: start; } /* panel hugs the board */
.stage { width: 100%; max-width: min(100%, calc(100vh - 230px)); margin: 0; } /* the board's left edge lines up with the title */
.board-wrap { width: 100%; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.goban { display: block; width: 100%; height: auto; user-select: none; -webkit-user-select: none; cursor: pointer; }
.side { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.stone-dot { width: 20px; height: 20px; border-radius: 50%; border: 1px solid #777; display: inline-block; }
.stone-dot.black { background: radial-gradient(circle at 35% 32%, #666, #111); }
.stone-dot.white { background: radial-gradient(circle at 35% 32%, #fff, #c9c9c0); }
.facts { margin: 0 0 8px; }
.facts div { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; border-bottom: 1px dashed var(--line); }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; }
.notice { min-height: 1.7em; margin: 4px 0; font-size: 0.92rem; }
.notice.warn { color: var(--warn); }
.notice.info { color: var(--info); }
.nav { display: grid; grid-template-columns: 52px 1fr 1fr 52px; gap: 6px; margin-bottom: 10px; }
.nav button { padding-inline: 6px; }
.slider { display: block; margin-bottom: 10px; }
.slider span { color: var(--muted); font-size: 0.9rem; }
.slider input { width: 100%; accent-color: var(--accent); }
.variation { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.below { margin-top: 8px; }
.variation button { min-width: 44px; }

.hint.warn { color: var(--warn); min-height: 1.4em; }
#btn-open-sgf-setup { margin-left: 8px; }
.scoring { margin: 0; }
.scoring[hidden] { display: none; }
.scoring h2 { margin: 0 0 6px; font-size: 1rem; }
.scoring .how { margin: 0 0 8px; color: var(--muted); font-size: 0.85rem; line-height: 1.55; }
.score-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.score-table th, .score-table td { padding: 3px 6px; text-align: right; border-bottom: 1px dashed var(--line); font-weight: normal; }
.score-table th:first-child { text-align: left; color: var(--muted); }
.score-table thead th { font-weight: 600; color: var(--text); }
.score-table .total th, .score-table .total td { font-weight: 700; color: var(--text); border-bottom: 0; border-top: 1px solid var(--line); }
.scoring .result { margin: 10px 0 4px; font-size: 1.15rem; font-weight: 700; }
.scoring .hint { margin: 0 0 8px; font-size: 0.82rem; color: var(--muted); }
button.small { min-height: 36px; padding: 4px 12px; font-size: 0.88rem; }


@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .stage { max-width: min(100%, 92vh); }
  body[data-view="play"] .top, body[data-view="play"] main, body[data-view="play"] footer { max-width: 1100px; }
}

.tabpanel .hint { margin: 8px 0 4px; font-size: 0.82rem; }
.stats-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.stats-table th { text-align: left; font-weight: 400; color: var(--muted); }
.stats-table td { text-align: right; }
.stats-table th, .stats-table td { padding: 2px 4px; border-bottom: 1px dashed var(--line); }
.stats-table tr.total th, .stats-table tr.total td { font-weight: 600; color: var(--text); }
.st-graph { width: 100%; height: 80px; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; cursor: pointer; display: block; }
.st-graph .mid { stroke: var(--line); stroke-dasharray: 4 3; }
.st-graph .wr { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.st-graph .now { stroke: var(--warn); stroke-width: 1; vector-effect: non-scaling-stroke; }
.st-swings { list-style: none; margin: 0; padding: 0; font-size: 0.88rem; display: flex; flex-wrap: wrap; align-content: flex-start; min-height: 7rem; }
.st-swings li { display: contents; } /* room for the longest list, so the panel keeps its height */
#batch-status { min-height: 2.9em; }
#stats-note { min-height: 2.9em; }
.st-swings button { margin: 2px 4px 2px 0; min-height: 32px; padding: 2px 10px; }

.batch { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-top: 8px; }
.batch button { flex: 1 1 8em; }
@media (max-width: 360px) { .batch button { flex-basis: 0; padding-inline: 6px; font-size: 0.85rem; } } /* the two buttons stay side by side on the narrowest phones */
.batch button { white-space: nowrap; }

/* ---- scoreboard: black | win rate and move count | white. The side to move has its disc lit. ---- */
.scoreboard { display: grid; grid-template-columns: auto minmax(12em, 1fr) auto; gap: 0; align-items: stretch; margin-bottom: 8px; border-radius: 10px; overflow: hidden; border: 1px solid #8f8777; background: var(--panel); }
.plate { display: flex; align-items: center; gap: 10px; padding: 8px 12px; min-width: 0; }
.plate { color: var(--text); }
.plate.white { flex-direction: row-reverse; text-align: right; }
.plate .info { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.plate .how-play { font-weight: 700; font-size: 1rem; }
.plate .cap { font-size: 0.8rem; opacity: 0.85; white-space: nowrap; }
.plate .cap b { font-variant-numeric: tabular-nums; font-size: 0.95rem; }
.disc { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; margin: 3px; border-radius: 50%; font-weight: 700; font-size: 1.05rem; border: 2px solid transparent; opacity: 0.3; filter: grayscale(0.6); transition: opacity 0.15s, box-shadow 0.15s, transform 0.15s; }
.disc.black { background: radial-gradient(circle at 35% 32%, #5a5a5a, #0e0e0e); color: #f3efe6; border-color: #6f6a60; }
.disc.white { background: radial-gradient(circle at 35% 32%, #ffffff, #d4d0c4); color: #1d1b18; border-color: #a49d8c; }
.plate.turn .disc { opacity: 1; filter: none; transform: scale(1.3); border-color: #e0b030; box-shadow: 0 0 0 4px #e0b030, 0 0 16px 5px rgba(224, 176, 48, 0.75); animation: turn-pulse 1.6s ease-in-out infinite; }
.plate.turn .how-play { color: #b07d00; }
@media (prefers-color-scheme: dark) { .plate.turn .how-play { color: #f2c94c; } }
@keyframes turn-pulse { 50% { box-shadow: 0 0 0 4px #e0b030, 0 0 22px 8px rgba(224, 176, 48, 0.35); } }
@media (prefers-reduced-motion: reduce) { .plate.turn .disc { animation: none; } }
.scoreboard .center { display: flex; flex-direction: column; justify-content: center; align-items: stretch; gap: 3px; padding: 6px 10px; min-width: 0; }
.wr-row { display: flex; justify-content: space-between; align-items: baseline; font-variant-numeric: tabular-nums; line-height: 1.1; }
.wr-row .pb, .wr-row .pw { font-size: 1.4rem; font-weight: 700; }
.wr-row .wr-label { font-size: 0.85rem; font-weight: 600; color: var(--text); }
.mb-head { display: flex; justify-content: space-between; align-items: baseline; }
.mb-komi { color: var(--muted); font-size: 0.9rem; }
.wr-track { height: 16px; border-radius: 4px; background: #f6f2e8; border: 1px solid #8f8777; overflow: hidden; }
.wr-track .fill { height: 100%; width: 50%; background: #1d1b18; transition: width 0.25s ease; }
.scoreboard .meta { text-align: center; font-size: 0.75rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.scoreboard .meta .lead { color: var(--text); }
.wr-row[hidden], .wr-track[hidden] { display: none; }

/* ---- tabs of the side panel ---- */
.tabs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; margin-top: 14px; border-bottom: 1px solid var(--line); }
.tabs button[hidden] { display: none; }
.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 6px 6px 0 0; min-height: 40px; color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.panels { display: grid; } /* the tallest panel (the stats) decides the height; its note reserves two lines, so texts never move the page */
#stats-note { line-height: 1.5; min-height: 3em; }
/* every panel sits in the same cell, so the area is as tall as the tallest one (the stats): switching tabs never changes the page height and nothing scrolls */
.tabpanel { grid-area: 1 / 1; padding-top: 10px; min-width: 0; }
.tabpanel[hidden] { display: block; visibility: hidden; pointer-events: none; }
.tabpanel .check { display: flex; align-items: center; gap: 8px; min-height: 36px; cursor: pointer; font-weight: 600; }
.tabpanel .check input { width: 18px; height: 18px; accent-color: var(--accent); }
.tabpanel .players { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 8px; margin: 6px 0; }
.tabpanel .players .field { margin: 0; flex: none; }
.tabpanel .players select { min-height: 38px; padding: 4px 8px; }
.tabpanel .hint[role="status"] { line-height: 1.5; min-height: 1.5em; } /* one line is always reserved: the buttons below must not move */

/* the pass: the button stays as it is; when the pass is a candidate a mark like the ones on the board sits beside it */
.passrow { position: relative; display: flex; align-items: center; justify-content: center; margin-top: 8px; min-height: 46px; } /* the chip sits beside the button without pushing it */
.passrow #btn-pass { min-width: 8em; }
.pass-chip { position: absolute; right: calc(50% + 4em + 12px); top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; align-items: center; justify-content: center; width: 46px; height: 46px; border-radius: 50%; border: 2px solid #3a2a1a; line-height: 1.05; font-variant-numeric: tabular-nums; }
.pass-chip[hidden] { display: none; }
.pass-chip b { font-size: 0.95rem; }
.pass-chip small { font-size: 0.66rem; }
.pass-chip.gold { background: linear-gradient(145deg, #fff3a8, #f0c020 40%, #b07a00); color: #2a1d10; }
.pass-chip.silver { background: linear-gradient(145deg, #ffffff, #cfd6de 45%, #8793a1); color: #2a1d10; }
.pass-chip.bronze { background: linear-gradient(145deg, #f0ad78, #c47a3c 45%, #7a4318); color: #fff; }
.pass-chip.other { background: #6b7a8f; color: #fff; }

/* ---- move bar (replaces the slider): one stroke per move, coloured by its rating ---- */
.movebar-wrap { margin: 4px 0 10px; }
.mb-title { color: var(--muted); font-size: 0.9rem; }
.mb-title b { color: var(--text); font-variant-numeric: tabular-nums; }
.movebar { position: relative; margin-top: 4px; padding-bottom: 18px; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; border-radius: 4px; }
.movebar:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mb-ticks { display: block; width: 100%; height: 30px; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; }
.mb-ticks .g { fill: #e0b030; } .mb-ticks .s { fill: #aab3bd; } .mb-ticks .b { fill: #b8733a; } .mb-ticks .o { fill: #6b7a8f; } .mb-ticks .u { fill: none; stroke: var(--muted); stroke-width: 1; vector-effect: non-scaling-stroke; }
.mb-ticks .p { opacity: 0.45; }
.mb-ticks .c { fill: var(--line); }
.mb-ticks .mid { stroke: var(--line); stroke-width: 0.4; }
.mb-cur { position: absolute; top: 0; height: 32px; min-width: 3px; border: 2px solid var(--warn); border-radius: 3px; pointer-events: none; box-sizing: border-box; }
.mb-branches { position: absolute; left: 0; right: 0; top: 32px; height: 18px; }
.mb-branches button { position: absolute; transform: translateX(-50%); min-height: 0; height: 18px; width: 22px; padding: 0; border: 0; background: transparent; color: var(--accent); font-size: 0.8rem; line-height: 18px; }
.mb-branches button.here { color: var(--warn); }
.mb-legend { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 0.75rem; color: var(--muted); }
.mb-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 3px; vertical-align: -1px; }
.mb-legend .g { background: #e0b030; } .mb-legend .s { background: #aab3bd; } .mb-legend .b { background: #b8733a; } .mb-legend .o { background: #6b7a8f; }
.mb-legend .u { background: transparent; border: 1px dashed var(--muted); width: 8px; height: 8px; }
.mb-legend .p { background: #e0b030; opacity: 0.45; }
.mb-legend .row-note { margin-left: auto; }

/* ---- the next moves to choose from at a branch ---- */
.choices { display: flex; align-items: center; gap: 6px; margin: 6px 0; }
.choices[hidden] { display: none; }
.ch-title { color: var(--muted); font-size: 0.9rem; }
.ch-list { display: flex; gap: 6px; flex: 1; justify-content: center; min-width: 0; }
.ch-list button { width: 42px; min-height: 42px; height: 42px; padding: 0; border-radius: 50%; border: 2px solid #3a2a1a; font-weight: 700; font-size: 0.8rem; }
.ch-list button.gold { background: linear-gradient(145deg, #fff3a8, #f0c020 40%, #b07a00); color: #2a1d10; }
.ch-list button.silver { background: linear-gradient(145deg, #ffffff, #cfd6de 45%, #8793a1); color: #2a1d10; }
.ch-list button.bronze { background: linear-gradient(145deg, #f0ad78, #c47a3c 45%, #7a4318); color: #fff; }
.ch-list button.other { background: #6b7a8f; color: #fff; }
.ch-list button.unrated { background: transparent; color: var(--text); border-style: dashed; }
.ch-list button.sel { box-shadow: 0 0 0 3px var(--accent); }
.ch-arrow { min-height: 36px; padding: 4px 8px; }
.ch-arrow:disabled { visibility: hidden; }

@media (max-width: 520px) {
  .top { gap: 8px; }
  .top h1 { white-space: nowrap; font-size: 1.25rem; }
  .top-actions button { white-space: nowrap; }
}

@media (max-width: 520px) {
  .plate, .plate.white { flex-direction: column; justify-content: center; text-align: center; padding: 6px 6px; gap: 0; }
  .plate .info { align-items: center; }
  .disc { width: 30px; height: 30px; font-size: 0.9rem; margin: 3px 4px; }
  .plate .cap { font-size: 0.72rem; }
  .plate .how-play { font-size: 0.9rem; }
  .scoreboard { grid-template-columns: auto minmax(9.5em, 1fr) auto; }
  .wr-row .pb, .wr-row .pw { font-size: 1.05rem; }
  .scoreboard .meta { font-size: 0.68rem; white-space: normal; line-height: 1.25; }
  .scoreboard .meta .lead { display: block; }
}

.board-holder { position: relative; }
.scoring-wait { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 5; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 16px 22px; max-width: 86%; text-align: center; border: 1px solid #8f8777; border-radius: 12px; background: rgba(255, 252, 244, 0.95); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3); font-size: 1rem; font-weight: 600; color: #1d1b18; }
.scoring-wait[hidden] { display: none; }
.scoring-wait .spin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid #d9c9a3; border-top-color: #6b4a2b; animation: wait-spin 0.9s linear infinite; }
.scoring-wait button { font-size: 0.85rem; font-weight: 400; padding: 4px 10px; }
@keyframes wait-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .scoring-wait .spin { animation: none; } }

/* the move just played: who and which, then its mark as it stood before the move (same look as a candidate mark) */
.last-move { position: absolute; right: 0; top: 50%; transform: translateY(-50%); display: flex; align-items: center; gap: 6px; max-width: calc(50% - 4em - 14px); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.last-move[hidden] { display: none; }
.last-move .lm-text { text-align: right; line-height: 1.3; }
.last-move .lm-disc { display: inline-block; width: 0.8em; height: 0.8em; border-radius: 50%; vertical-align: -0.05em; margin-right: 0.25em; border: 1px solid #6f6a60; }
.last-move .lm-disc.black { background: #1d1b18; }
.last-move .lm-disc.white { background: #f6f2e8; }
.lm-chip { flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; width: 46px; height: 46px; border-radius: 50%; border: 2px solid #3a2a1a; line-height: 1.05; font-variant-numeric: tabular-nums; }
.lm-chip b { font-size: 0.95rem; }
.lm-chip small { font-size: 0.66rem; }
.lm-chip.gold { background: linear-gradient(145deg, #fff3a8, #f0c020 40%, #b07a00); color: #2a1d10; }
.lm-chip.silver { background: linear-gradient(145deg, #ffffff, #cfd6de 45%, #8793a1); color: #2a1d10; }
.lm-chip.bronze { background: linear-gradient(145deg, #f0ad78, #c47a3c 45%, #7a4318); color: #fff; }
.lm-chip.other { background: #6b7a8f; color: #fff; }
.lm-chip.faint { opacity: 0.5; }
.lm-chip.none { background: transparent; border-style: dashed; color: var(--muted); }
@media (max-width: 520px) { .last-move .lm-text { display: block; width: 3.4em; text-align: right; } .last-move .lm-disc { display: block; margin: 0 0 0 auto; } }

/* the dialog that replaces the browser's alert / confirm */
.dlg { width: min(92vw, 380px); padding: 18px 20px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); box-shadow: 0 8px 28px rgba(0,0,0,0.28); }
.dlg::backdrop { background: rgba(20, 16, 10, 0.45); }
.dlg-title { margin: 0 0 8px; font-size: 1.05rem; font-weight: 600; }
.dlg-msg { margin: 0; white-space: pre-line; }
.dlg-note { margin: 6px 0 0; color: var(--muted); font-size: 0.88rem; }
.dlg-note:empty, .dlg-msg:empty { display: none; }
.dlg-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dlg-btns button { min-width: 88px; }
.dlg-btns button[hidden] { display: none; }

/* ---- start page: the ad and the explanation under the settings card ---- */
.ad { max-width: 520px; margin: 24px 0 0; } /* room around it: it must not be pressed by mistake */
.ad[hidden] { display: none; }
.ad:not(:has(ins.adsbygoogle[data-ad-status="filled"])) { height: 0; margin: 0; overflow: hidden; } /* collapsed until an ad actually fills it; the width stays so AdSense can measure the slot */
.intro { max-width: 520px; margin: 24px 0 0; }
.intro p { margin: 8px 0; }
.spec h2 { margin: 28px 0 6px; font-size: 1.1rem; }
.spec ul { margin: 8px 0; padding-left: 1.4em; }
.spec li { margin: 6px 0; }
.load-link { margin: 8px 0 0; font-size: 0.88rem; line-height: 1.5; min-height: 1.5em; } /* the line is always reserved, so nothing moves when it appears */
.load-link[hidden] { display: block; visibility: hidden; pointer-events: none; }
.load-link a { font-weight: 600; margin-left: 0.4em; }
