/* Layout: a Go-club table. The kaya board owns the left; the kifu and Maker's hand sit
   at its side like a scorer's sheet. Celadon paper ground, indigo for the proof's
   envelopes, vermilion seal for anything that matters to White. */
:root {
  --paper: #e4eae5;
  --paper-2: #f2f5f2;
  --ink: #17201d;
  --ink-soft: #4d5b56;
  --line: #c5cfc9;
  --ai: #2d4a80;          /* indigo: envelopes, proof structure */
  --ai-soft: rgba(45, 74, 128, .14);
  --shu: #c3412a;         /* vermilion: White's opportunities, the seal */
  --shu-ink: #fff6f0;
  --ok: #2f7d55;
  --wood-1: #e2b673;
  --wood-2: #c99550;
  --wood-grid: #3a2914;
  --f-display: "Shippori Mincho B1", "Hiragino Mincho ProN", "Yu Mincho", Georgia, serif;
  --f-body: "Zen Kaku Gothic New", "Hiragino Sans", "Segoe UI", system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --r: 6px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #111815; --paper-2: #18211d; --ink: #e2e8e4; --ink-soft: #9aa9a2; --line: #2b3732;
    --ai: #93acdd; --ai-soft: rgba(147, 172, 221, .16); --shu: #ec6a4f; --shu-ink: #1b0d08; --ok: #5cc08d;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #111815; --paper-2: #18211d; --ink: #e2e8e4; --ink-soft: #9aa9a2; --line: #2b3732;
  --ai: #93acdd; --ai-soft: rgba(147, 172, 221, .16); --shu: #ec6a4f; --shu-ink: #1b0d08; --ok: #5cc08d;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--ai); text-underline-offset: 2px; }
.wrap { max-width: 1240px; margin: 0 auto; padding-inline: 20px; padding-block: 28px 40px; }
h1, h2 { font-family: var(--f-display); text-wrap: balance; margin: 0; }
h2 { font-size: 1.15rem; font-weight: 800; letter-spacing: .01em; }
.label { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.mono { font-family: var(--f-mono); }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--ai); outline-offset: 2px; }

/* ---- hero ---- */
.hero { display: flex; gap: 32px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.hero-text { max-width: 640px; min-width: 0; }
.eyebrow { margin: 0 0 6px; font-size: .75rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-soft); }
h1 { font-size: clamp(2.4rem, 6vw, 4.2rem); font-weight: 800; line-height: 1; letter-spacing: -.01em; }
.seal {
  display: inline-grid; place-items: center; min-width: 1.25em; height: 1.25em; padding: 0 .08em;
  background: var(--shu); color: var(--shu-ink); border-radius: 8px; transform: rotate(-3deg);
  font-size: .82em; vertical-align: .05em; box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--shu-ink) 25%, transparent);
}
.lede { margin: 14px 0 0; font-size: 1.04rem; max-width: 62ch; }
.snaky-figure { margin: 0; display: grid; gap: 4px; justify-items: center; }
.snaky-figure svg { width: 220px; max-width: 100%; height: auto; }
.snaky-figure figcaption { font-family: var(--f-mono); font-size: .72rem; color: var(--ink-soft); }

/* ---- main play area ---- */
.play { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 28px; padding-top: 24px; align-items: start; }
@media (max-width: 960px) { .play { grid-template-columns: minmax(0, 1fr); } }
.board-col { min-width: 0; }
.board-shell { position: relative; max-width: 760px; margin: 0 auto; }
.board { display: block; width: 100%; height: auto; border-radius: 4px; touch-action: manipulation; user-select: none;
  box-shadow: 0 1px 0 rgba(0,0,0,.25), 0 18px 40px -18px rgba(40, 24, 6, .55); }
.board text { font-family: var(--f-body); }
.board .coord { fill: rgba(58, 41, 20, .75); font-size: 13px; font-weight: 500; }
.board .num { font-family: var(--f-mono); font-size: 15px; font-weight: 500; pointer-events: none; }
.board .heatnum { font-family: var(--f-mono); font-size: 12px; font-weight: 500; fill: #fff; pointer-events: none; }
.stone-drop { animation: drop .28s cubic-bezier(.2, .9, .3, 1.2); transform-box: fill-box; transform-origin: center; }
@keyframes drop { from { transform: scale(1.18); opacity: .4; } to { transform: scale(1); opacity: 1; } }
.pivot-pulse { animation: pulse 1.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes pulse { 50% { opacity: .35; } }
.snake-body { stroke-dasharray: 1000; stroke-dashoffset: 1000; animation: slither 1.4s ease-out forwards; }
@keyframes slither { to { stroke-dashoffset: 0; } }
.snake-head { opacity: 0; animation: appear .3s 1.2s forwards; }
@keyframes appear { to { opacity: 1; } }
.tongue { transform-box: fill-box; transform-origin: left center; animation: flick 1.1s 1.5s infinite; }
@keyframes flick { 0%, 60%, 100% { transform: scaleX(0); } 70%, 90% { transform: scaleX(1); } }
@media (prefers-reduced-motion: reduce) {
  .stone-drop, .pivot-pulse, .tongue { animation: none; }
  .snake-body { animation: none; stroke-dashoffset: 0; }
  .snake-head { animation: none; opacity: 1; }
}

.tip {
  position: absolute; z-index: 3; pointer-events: none; max-width: 260px;
  background: color-mix(in srgb, var(--paper-2) 80%, transparent); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r);
  padding: 8px 10px; font-size: .82rem; line-height: 1.4; box-shadow: 0 8px 24px -10px rgba(0,0,0,.35);
}
.tip b { font-family: var(--f-mono); font-weight: 500; }
.taunt {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%); z-index: 4; pointer-events: none;
  max-width: 90%; padding: 7px 14px; border-radius: 999px; background: var(--ink); color: var(--paper);
  font-size: .9rem; font-weight: 500; text-align: center; box-shadow: 0 10px 24px -12px rgba(0,0,0,.6);
  animation: taunt 3.2s ease forwards;
}
@keyframes taunt { 0% { opacity: 0; transform: translate(-50%, -6px); } 10%, 80% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }
.stone-fall { animation: fall .55s cubic-bezier(.3, 1.35, .5, 1) both; transform-box: fill-box; transform-origin: center; }
@keyframes fall { from { transform: translateY(-70px) scale(1.2); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .stone-fall, .taunt { animation: none; } }
.banner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 4;
  width: min(92%, 420px); text-align: center; background: var(--paper-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 20px 22px; box-shadow: 0 24px 60px -20px rgba(0,0,0,.55);
}
.banner h3 { font-family: var(--f-display); font-size: 1.6rem; margin: 0 0 6px; }
.banner p { margin: 0 0 14px; }
.banner .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.board-foot { margin-top: -4px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .8rem; color: var(--ink-soft); }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw-env { background: var(--wood-1); box-shadow: inset 0 0 0 3px var(--wood-1), inset 0 0 0 12px #2d4a80; }
.sw-heat1 { background: rgba(195, 65, 42, .35); }
.sw-heat2 { background: #c3412a; }
.sw-req { border-radius: 50%; background: #111; box-shadow: 0 0 0 2.5px #f2c14e; }
.sw-win { border-radius: 50%; border: 2px dashed #3f6b2a; }
.sw-pivot { border-radius: 50%; border: 2px solid #c3412a; }

/* ---- panel ---- */
.panel { display: grid; gap: 18px; min-width: 0; }
.modes { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 999px; padding: 3px; background: var(--paper-2); }
.mode { font: inherit; font-weight: 700; border: 0; background: transparent; color: var(--ink-soft); padding: 7px 10px; border-radius: 999px; cursor: pointer; }
.mode[aria-selected="true"] { background: var(--ink); color: var(--paper); }
.mode-note { margin: -8px 0 0; font-size: .86rem; color: var(--ink-soft); }
.clock { background: var(--paper-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; display: grid; gap: 10px; }
.clock-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-end; }
.big { font-family: var(--f-display); font-weight: 800; font-size: 2.4rem; line-height: 1; font-variant-numeric: tabular-nums; }
.big.small { font-size: 1.6rem; }
.big .of { font-size: .5em; color: var(--ink-soft); font-weight: 600; }
.forced-box { text-align: right; }
.forced-box.lost .big { color: var(--shu); }
.pips { display: grid; grid-template-columns: repeat(21, 1fr); gap: 3px; }
.pip { aspect-ratio: 1; max-width: 100%; border-radius: 50%; border: 1.5px solid var(--ink-soft); opacity: .55; }
.pip.done { background: radial-gradient(circle at 35% 30%, #6a6a6a, #111 60%); border-color: #111; opacity: 1; }
.pip.todo { opacity: 1; border-color: var(--ink); }
.pip.lost { border-style: dashed; border-color: var(--shu); opacity: .9; position: relative; }
.status { margin: 0; font-size: .9rem; min-height: 2.8em; }
.status b { color: var(--shu); }
.controls { display: flex; flex-wrap: wrap; gap: 8px; }
.btn { font: inherit; font-size: .88rem; font-weight: 500; padding: 7px 13px; border-radius: var(--r); border: 1px solid var(--line);
  background: var(--paper-2); color: var(--ink); cursor: pointer; }
.btn:hover:not(:disabled) { border-color: var(--ink-soft); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.on { background: var(--shu); color: var(--shu-ink); border-color: var(--shu); }
.opts { font-size: .86rem; color: var(--ink-soft); }
.opts summary { cursor: pointer; font-weight: 500; color: var(--ink); }
.opt { display: flex; gap: 8px; align-items: flex-start; margin-top: 6px; }
.glass, .kifu-sec, .review { display: grid; gap: 8px; }
.hand-note { margin: 0; font-size: .84rem; color: var(--ink-soft); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; }
.card { border: 1px solid var(--line); border-radius: 6px; background: var(--paper-2); padding: 4px 4px 3px; display: grid; gap: 2px;
  transition: opacity .15s, transform .15s, border-color .15s; position: relative; }
.card canvas { width: 100%; height: auto; aspect-ratio: 1; display: block; border-radius: 3px; }
.card .cn { font-family: var(--f-mono); font-size: .68rem; display: flex; justify-content: space-between; gap: 4px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; }
.card .cn b { color: var(--ink); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.card.blocked { opacity: .28; transform: scale(.96); }
.card.blocked::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top right, transparent calc(50% - 1px), var(--shu) 50%, transparent calc(50% + 1px)); border-radius: 6px; }
.card.chosen { border-color: var(--ai); box-shadow: 0 0 0 2px var(--ai); }
.card.fast { border-color: var(--ink-soft); }
.path { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; font-family: var(--f-mono); font-size: .74rem; }
.path li { padding: 2px 7px; border-radius: 4px; background: var(--ai-soft); color: var(--ink); white-space: nowrap; }
.path li .h { color: var(--ink-soft); margin-left: 4px; }
.path li.free { outline: 1px dashed var(--ai); }
.board-col { display: grid; gap: 14px; }
.board-col > * { width: 100%; max-width: 760px; margin-inline: auto; }
.kifu-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.kifu-hint { font-size: .8rem; color: var(--ink-soft); }
.kifu { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); gap: 2px 10px; max-height: 300px; overflow: auto;
  font-family: var(--f-mono); font-size: .78rem; font-variant-numeric: tabular-nums; }
.kifu li { display: grid; grid-template-columns: 2.4em 1.3em 3.4em minmax(0, 1fr); gap: 6px; padding: 2px 4px; border-radius: 4px; align-items: center; }
.kifu li { background: color-mix(in srgb, var(--ink) 4%, transparent); }
.kifu li[data-review]:hover { background: var(--ai-soft); }
.kifu li.current { background: var(--ai-soft); box-shadow: inset 0 0 0 1px var(--ai); }
.kifu .st { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.kifu .st.b { background: #151515; }
.kifu .st.w { background: #f4f2ea; box-shadow: inset 0 0 0 1px #8d8a82; }
.kifu .note { color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kifu .note .bad { color: var(--shu); }
.kifu .note .good { color: var(--ok); }
.review { background: var(--paper-2); border: 1px solid var(--ai); border-radius: 10px; padding: 10px 12px; }
.review-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.review-row input { flex: 1; min-width: 120px; }
.sgf summary { cursor: pointer; font-weight: 500; font-size: .88rem; }
.sgf-note { margin: 6px 0; font-size: .82rem; color: var(--ink-soft); }
.sgf textarea { width: 100%; font-family: var(--f-mono); font-size: .76rem; padding: 8px; border-radius: var(--r); border: 1px solid var(--line); background: var(--paper-2); color: var(--ink); resize: vertical; }
.sgf-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.sgf-msg { font-size: .82rem; color: var(--ink-soft); }
.rv-text { margin: 0; font-size: .88rem; }

/* ---- explanation & lab ---- */
.explain { margin-top: 44px; padding-top: 26px; border-top: 1px solid var(--line); }
.explain-text { max-width: 68ch; }
.explain-text p { margin: 10px 0 0; }
.fact { font-size: .9rem; color: var(--ink-soft); }
.lab { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); gap: 24px; margin-top: 30px; }
.lab-card { background: var(--paper-2); border: 1px solid var(--line); border-radius: 10px; padding: 18px; min-width: 0; display: grid; gap: 10px; align-content: start; }
.lab-card p { margin: 0; font-size: .92rem; }
.squeeze { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; }
.squeeze canvas, .cb-body canvas { width: 300px; max-width: 100%; height: auto; aspect-ratio: 1; border-radius: 4px; }
.sq-side { display: grid; gap: 6px; flex: 1; min-width: 160px; }
.sq-cardname { font-size: .8rem; color: var(--ink-soft); min-height: 1.3em; }
.cb-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.cb-bar input { width: 6em; font: inherit; padding: 6px 8px; border-radius: var(--r); border: 1px solid var(--line); background: var(--paper); color: var(--ink); }
.cb-body { display: flex; gap: 16px; flex-wrap: wrap; }
.cb-info { flex: 1; min-width: 180px; display: grid; gap: 8px; align-content: start; }
.cb-title { font-family: var(--f-display); font-weight: 800; font-size: 1.3rem; }
.cb-stats { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0; font-size: .86rem; font-variant-numeric: tabular-nums; }
.cb-stats dt { color: var(--ink-soft); }
.cb-stats dd { margin: 0; font-family: var(--f-mono); }
.cb-kids { display: flex; flex-wrap: wrap; gap: 4px; max-height: 180px; overflow: auto; }
.cb-kids button { font-family: var(--f-mono); font-size: .74rem; padding: 2px 7px; border-radius: 4px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); cursor: pointer; }
.cb-kids button:hover { border-color: var(--ai); }
.cb-line { margin: 0; font-family: var(--f-mono); font-size: .72rem; white-space: pre-wrap; word-break: break-word; max-height: 140px; overflow: auto;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 8px; color: var(--ink-soft); }
.foot { margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--line); font-size: .8rem; color: var(--ink-soft); }
.foot { display: grid; gap: 10px; }
.foot h2 { color: var(--ink); }
.credits { display: grid; grid-template-columns: 8.5em minmax(0, 1fr); gap: 8px 16px; margin: 0; max-width: 100ch; line-height: 1.5; }
.credits dt { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; padding-top: .15em; }
.credits dd { margin: 0; color: var(--ink); opacity: .85; }
@media (max-width: 560px) { .credits { grid-template-columns: minmax(0, 1fr); gap: 2px; } .credits dd { margin-bottom: 8px; } }
.tempo { margin: 0; display: grid; gap: 2px; }
.tempo svg { width: 100%; height: auto; display: block; cursor: pointer; }
.tempo text { font-family: var(--f-mono); font-size: 11px; fill: var(--ink-soft); }
.tempo .t-line { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.tempo .t-area { fill: var(--ai-soft); }
.tempo .t-grid { stroke: var(--line); stroke-width: 1; }
.tempo .t-ok { fill: var(--paper); stroke: var(--ink); stroke-width: 2; }
.tempo .t-loss { fill: var(--shu); stroke: var(--paper); stroke-width: 2; }
.tempo .t-cur { stroke: var(--ai); stroke-width: 2; stroke-dasharray: 3 3; }
.tempo .t-hover { stroke: var(--ink-soft); stroke-width: 1; }
.tempo .t-lab { fill: var(--ink); font-weight: 500; }
.tempo-cap { font-size: .8rem; color: var(--ink-soft); min-height: 1.4em; }
