:root {
  --bg: #0d1117;
  --surface: #131922;
  --surface-2: #19212c;
  --line: #242f3d;
  --line-2: #334155;
  --ink: #e6edf3;
  --ink-2: #c3ccd7;
  --muted: #8a96a6;
  --faint: #5c6878;
  --accent: #e8a94a;
  --accent-ink: #1d1407;
  --live: #86e08f;
  --black: #e9dfc9;
  --white: #9fb6d6;
  --danger: #f08070;
  --task: #b48cf0;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.5 "Hiragino Sans", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
kbd {
  font: 10px/1 "SF Mono", Menlo, monospace;
  padding: 2px 4px;
  margin-left: 6px;
  border-radius: 4px;
  border: 1px solid currentColor;
  opacity: .55;
}

/* ---- header ---------------------------------------------------------- */
.top {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  min-height: 56px;
}
.brand { min-width: 0; flex: 1; }
.app { font-size: 11px; color: var(--muted); letter-spacing: .04em; }
.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tally { display: flex; gap: 18px; white-space: nowrap; }
.tally div { display: flex; flex-direction: column; align-items: flex-end; }
.tally span { font-size: 11px; color: var(--muted); }
.tally b { font-size: 16px; font-weight: 600; line-height: 1.2; }
.conn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink-2);
  white-space: nowrap;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.conn.ok .dot { background: var(--live); box-shadow: 0 0 0 3px rgba(134, 224, 143, .15); }
.conn.wait .dot { background: var(--accent); }
.conn.bad .dot { background: var(--danger); }

/* ---- layout ---------------------------------------------------------- */
main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(560px, 50%) 1fr;
}
.stage {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 18px 14px 20px;
  min-height: 0;
  border-right: 1px solid var(--line);
}

/* ---- game tabs ------------------------------------------------------- */
.games {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.game {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 6px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
  text-align: left;
  min-width: 0;
}
.game:hover { background: var(--surface-2); }
.game.active { background: var(--line-2); box-shadow: inset 0 0 0 1px #45546a; }
.game-name { font-weight: 600; display: flex; align-items: center; gap: 6px; width: 100%; }
.game-score { margin-left: auto; white-space: nowrap; font-weight: 500; font-size: 12px; color: var(--ink-2); }
.game-name .n {
  display: inline-grid;
  place-items: center;
  width: 18px; height: 18px;
  border-radius: 50%;
  font-size: 11px;
  background: var(--faint);
  color: var(--bg);
}
.game.active .game-name .n { background: var(--live); }
.game-sub {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.game-sub.end { color: var(--accent); }

/* ---- review banner --------------------------------------------------- */
.review {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 6px 6px 14px;
  border-radius: var(--radius);
  background: rgba(232, 169, 74, .12);
  border: 1px solid rgba(232, 169, 74, .45);
}
.review[hidden] { display: none; }
.review-label { color: var(--accent); font-weight: 600; }
.review-move { flex: 1; color: var(--ink-2); }

/* ---- board ----------------------------------------------------------- */
.board-wrap { flex: 1; min-height: 300px; position: relative; }
.board-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

.caption {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.caption-main { flex: 1; min-width: 0; }
.now { font-size: 15px; font-weight: 600; white-space: normal; overflow-wrap: anywhere; }
.now .ply { color: var(--muted); font-weight: 400; margin-right: 8px; }
.now .turn { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 10px; }
.now .result { color: var(--accent); margin-left: 10px; }
.recent { font-size: 12px; color: var(--muted); white-space: normal; line-height: 1.7; }
.recent .move { display: inline-block; white-space: nowrap; margin-right: 10px; }
.recent i { font-style: normal; color: var(--faint); margin-right: 3px; font-size: 11px; }

.study {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 4px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.study .task { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.study .task span { color: var(--muted); margin-right: 8px; }
.study b { color: var(--ink); font-weight: 600; }
.streak { display: flex; align-items: center; gap: 8px; }
.pips { display: flex; gap: 2px; }
.pips i { width: 6px; height: 10px; border-radius: 1px; background: var(--line-2); }
.pips i.on { background: var(--live); }
.progress { width: 90px; height: 6px; border-radius: 3px; background: var(--line-2); overflow: hidden; }
.progress i { display: block; height: 100%; min-width: 2px; background: var(--live); }
.notice {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  color: #f5c08a;
  background: rgba(240, 128, 112, .08);
  border: 1px solid rgba(240, 128, 112, .3);
  white-space: pre-line;
  max-height: 80px;
  overflow: auto;
}
.notice[hidden] { display: none; }

/* ---- buttons --------------------------------------------------------- */
.btn {
  border: 1px solid var(--line-2);
  background: var(--surface-2);
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
}
.btn:hover { background: var(--line-2); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-accent:hover { background: #f2bb66; }
.btn-icon { width: 28px; height: 28px; padding: 0; justify-content: center; font-size: 15px; }
.btn:focus-visible, .game:focus-visible, canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- tree ------------------------------------------------------------ */
.treepane { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.tree-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 10px 18px 8px;
}
.tree-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.tree-title h2 { white-space: nowrap; margin: 0; font-size: 14px; font-weight: 600; }
.meta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.tree-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.tree-fold { display: flex; align-items: center; gap: 4px; }
.tree-fold[hidden] { display: none; }
.tree-fold .btn { padding: 3px 7px; font-size: 12px; }
.zoom { display: flex; align-items: center; gap: 4px; margin-left: 4px; }
#zoom-value { width: 42px; text-align: center; font-size: 12px; color: var(--muted); }

.switch { white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: var(--ink-2); user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.track { width: 30px; height: 18px; border-radius: 9px; background: var(--line-2); position: relative; transition: background .15s; }
.knob { position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--ink-2); transition: transform .15s; }
.switch input:checked + .track { background: var(--live); }
.switch input:checked + .track .knob { transform: translateX(12px); background: var(--bg); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.tree-wrap {
  flex: 1;
  min-height: 200px;
  position: relative;
  margin: 0 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0f141b;
  overflow: hidden;
}
.tree-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; outline: none; }
.tree-wrap canvas.dragging { cursor: grabbing; }
.tree-wrap canvas.pointing { cursor: pointer; }
.hint {
  position: absolute;
  left: 10px;
  bottom: 8px;
  font-size: 11px;
  color: var(--faint);
  pointer-events: none;
  background: rgba(15, 20, 27, .85);
  padding: 2px 6px;
  border-radius: 4px;
}

.detail {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  gap: 12px;
  height: 154px;
  flex-shrink: 0;
  padding: 8px 18px;
}
.detail-node { min-width: 0; min-height:0; overflow:auto; display: flex; flex-direction: column; gap: 6px; }
.detail-head { font-size: 17px; font-weight: 600; }
.detail-head .ply { color: var(--muted); font-weight: 400; font-size: 13px; margin-right: 8px; }
.detail-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: 11.5px;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  color: var(--ink-2);
}
.tag.live { border-color: rgba(134, 224, 143, .5); color: var(--live); }
.tag.added { border-color: rgba(159, 182, 214, .5); color: var(--white); }
.detail-comment {
  flex: 1;
  overflow: auto;
  font-size: 12.5px;
  color: #c5dcb4;
  white-space: pre-wrap;
  border-left: 2px solid #4b6a3a;
  padding-left: 10px;
}
.detail-comment:empty { display: none; }
.detail-next { min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.detail-sub { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.next-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.next-list li button {
  width: 100%;
  display: grid;
  grid-template-columns: 7.2em minmax(12px, 1fr) 4.6em 5.6em;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.next-list li button:hover { background: var(--surface-2); }
.next-list .bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.next-list .bar i { display: block; height: 100%; background: #6f86a6; border-radius: 3px; }
.next-list li.on-live .bar i { background: var(--live); }
.next-list .cnt { text-align: right; color: var(--ink-2); font-size: 12px; white-space: nowrap; }
.next-list .kind { font-size: 11px; color: var(--white); white-space: nowrap; }
.next-list li button > span:first-child { white-space: nowrap; }
.next-list .empty { color: var(--faint); font-size: 12px; padding: 4px 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .4);
}
.toast[hidden] { display: none; }

/* ---- task card ------------------------------------------------------- */
.task {
  display: flex;
  gap: 8px;
  margin: 10px 18px 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(180, 140, 240, .10), rgba(180, 140, 240, .04));
  border: 1px solid rgba(180, 140, 240, .35);
}
.task-thumb {
  display: none;
  flex: none;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  width: 176px;
  height: 158px;
  border-radius: 6px;
}
.task-thumb:hover { outline: 2px solid var(--task); outline-offset: 2px; }
.task-thumb canvas { width: 100%; height: 100%; display: block; }
.task-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.task-top { display: flex; align-items: center; gap: 10px; font-size: 12px; white-space: nowrap; }
.task-no { color: var(--task); font-weight: 700; letter-spacing: .02em; }
.task-state { padding: 0 8px; border-radius: 999px; font-size: 11px; background: rgba(180, 140, 240, .2); color: #d9c6fa; }
.task-state.done { background: rgba(134, 224, 143, .18); color: var(--live); }
.task-state.viewing { background: rgba(232, 169, 74, .18); color: var(--accent); }
.task-pos { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.task-name { font-size: 15px; font-weight: 700; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-comment { font-size: 12px; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.task-comment:empty { display: none; }
.task-stats { display: flex; align-items: center; flex-wrap:wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); white-space: nowrap; margin-top: 2px; }
.task-stats b { color: var(--ink); font-weight: 600; }
.task-list { display: flex; flex-wrap: wrap; gap: 3px; }
.task-list button {
  width: 22px; height: 18px;
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  background: transparent;
  font-size: 10px;
  color: var(--faint);
  cursor: pointer;
}
.task-list button.done { background: rgba(134, 224, 143, .18); border-color: rgba(134, 224, 143, .4); color: var(--live); }
.task-list button.running { background: var(--task); border-color: var(--task); color: #1b1030; font-weight: 700; }
.task-list button.viewing { outline: 2px solid var(--accent); outline-offset: 1px; }
.task-list button:hover { border-color: var(--ink-2); }
.now .from-task { font-size: 12px; font-weight: 500; color: #d9c6fa; margin-left: 10px; padding: 0 8px; border-radius: 999px; background: rgba(180, 140, 240, .16); }
.tag.task { border-color: rgba(180, 140, 240, .5); color: #d9c6fa; }

.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; padding: 3px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); white-space: nowrap; font-weight: 600; }
.seg button:hover:not(:disabled) { color: var(--ink); }
.seg button.on { background: var(--line-2); color: var(--ink); }
.seg button[data-v="task"].on { background: var(--task); color: #1b1030; }
.seg button:disabled { opacity: .4; cursor: default; }

.btn-small { padding: 1px 10px; font-size: 11.5px; border-radius: 5px; }
.btn[disabled] { opacity: .4; cursor: default; }
.btn[hidden] { display: none; }
.task-top .btn-small { margin-left: auto; }
