:root {
  color-scheme: light dark;
  --bg: #f0f0f0; --panel: #ffffff; --line: #b4b4b4; --text: #111; --muted: #666;
  --btn: #e6e6e6; --btn-hover: #d8d8d8; --memo: #ffffff; --beige: #eee8db;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #26262a; --panel: #1e1e21; --line: #55555c; --text: #eee; --muted: #aaa;
    --btn: #3b3b41; --btn-hover: #4a4a51; --memo: #17171a; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 12px/1.35 -apple-system, "Segoe UI", "Apple SD Gothic Neo", sans-serif; }
button, select, input { font: inherit; color: inherit; }
button { background: var(--btn); border: 1px solid var(--line); border-radius: 5px; padding: 3px 10px; cursor: pointer; }
button:hover:not(:disabled) { background: var(--btn-hover); }
button:disabled { opacity: .45; cursor: default; }
select, input[type=text], input[type=number], input:not([type]) { background: var(--memo); border: 1px solid var(--line);
  border-radius: 4px; padding: 2px 4px; }

#loading { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--beige); color: #222; gap: 6px; }
#loading h1 { margin: 0; font-size: 26px; }

#app { display: inline-flex; flex-direction: column; margin: 8px; border: 1px solid var(--line); background: var(--bg); }
#app[hidden], [hidden] { display: none !important; }
#toolbar { display: flex; align-items: center; gap: 5px; padding: 5px 6px; border-bottom: 1px solid var(--line); }
#toolbar .sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 3px; }
.grow { flex: 1; }
#tbAnalysis.on, #tbGraph.on, #bnAuto.on { background: #2f6fde; color: #fff; border-color: #2f6fde; }
#tbSamples { max-width: 170px; }

#main { display: flex; }
#boardArea { display: flex; align-items: center; justify-content: center; }
#board { display: block; touch-action: none; cursor: pointer; }
#panel { width: 321px; padding: 3px; display: flex; flex-direction: column; min-height: 0; }
#rule { height: 22px; line-height: 20px; text-align: center; font-weight: 700; font-size: 11px; border: 1px solid var(--line);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--panel); }
#players { display: flex; height: 44px; }
.player { flex: 1; display: flex; align-items: center; gap: 8px; padding: 0 6px; border: 1px solid var(--line);
  background: var(--panel); font-weight: 700; min-width: 0; }
.player .pinfo { flex: 1; min-width: 0; }
.player .pname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .prow { display: flex; justify-content: space-between; }
#pCho.tomove { background: #0000e6; color: #fff; }
#pHan.tomove { background: #d90000; color: #fff; }

#buttons { height: 139px; padding: 8px 8px 0; }
.brow { display: flex; gap: 17px; margin-bottom: 7px; }
.brow > button { flex: 1; height: 25px; }
.brow > .nav { flex: 1; display: flex; align-items: center; gap: 2px; }
.nav button { padding: 2px 6px; height: 25px; }
.nav span { flex: 1; text-align: center; font-size: 11px; }
#laReplayMode { font-size: 16px; font-weight: 700; font-style: italic; color: #808000; margin: 10px 6px 12px; }
.replaynav { display: flex; align-items: center; gap: 4px; }
.replaynav button { padding: 3px 7px; }
.replaynav span { flex: 1; text-align: center; font-size: 11px; }

#tabs { display: flex; gap: 2px; margin: 2px 0; }
#tabs button { border-radius: 5px 5px 0 0; border-bottom: none; background: transparent; }
#tabs button.active { background: var(--memo); font-weight: 700; }
.tab { flex: 1; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
pre { margin: 0; flex: 1; overflow: auto; background: var(--memo); border: 1px solid var(--line); padding: 4px;
  font: 11px/1.3 Menlo, "Courier New", monospace; min-height: 0; user-select: text; }
#analysisText { flex: 0 0 161px; }
#protoCmd { display: flex; gap: 4px; }
#protoCmd input { flex: 1; min-width: 0; font-family: Menlo, monospace; }

#graphPanel { border-top: 1px solid var(--line); padding: 6px 8px; }
#graphTitle { text-align: center; font-weight: 600; color: #2f6fde; font-size: 13px; }
#graph { display: block; width: 100%; height: 200px; cursor: pointer; }
#graphDetail { height: 16px; font-size: 11px; white-space: nowrap; overflow: hidden; }
#graphControls { display: flex; align-items: center; gap: 14px; font-size: 11px; }
#graphUnits { color: var(--muted); font-size: 10px; max-width: 46%; text-align: right; }

#status { display: flex; height: 23px; line-height: 22px; border-top: 1px solid var(--line); }
#stLeft { width: 200px; padding-left: 6px; border-right: 1px solid var(--line); white-space: nowrap; overflow: hidden; }
#stRight { flex: 1; padding-left: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

dialog { border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: var(--bg); color: var(--text);
  box-shadow: 0 12px 40px rgba(0,0,0,.4); max-width: 96vw; max-height: 96vh; overflow: auto; }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog.beige { background: var(--beige); color: #111; }
dialog h2 { margin: 0 0 10px; font-size: 14px; }
.dlgbuttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.dlgbuttons button { min-width: 70px; }
button.primary { background: #2f6fde; color: #fff; border-color: #2f6fde; }
button.primary:hover:not(:disabled) { background: #2a62c4; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 5px 0 0 5px; margin-left: 0; }
.seg button:last-child { border-radius: 0 5px 5px 0; }
.seg button.active { background: #2f6fde; color: #fff; border-color: #2f6fde; }
.optgrid { display: grid; grid-template-columns: auto auto auto auto; gap: 6px 10px; align-items: center; justify-content: start;
  margin-top: 10px; }
.optgrid input[type=number] { width: 60px; }
.setupgrid { display: grid; grid-template-columns: repeat(4, 130px); gap: 6px; width: 566px; height: 440px; overflow-y: auto;
  border: 1px solid var(--line); padding: 4px; margin-top: 10px; background: var(--panel); align-content: start; }
.setupcell { height: 142px; border: 1px solid var(--line); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; cursor: pointer; font-size: 10px; }
.setupcell.selected { outline: 2px solid #2f6fde; background: rgba(47,111,222,.25); }
.editor { display: flex; gap: 12px; }
.palette { display: grid; grid-template-columns: repeat(7, 36px); gap: 2px; margin: 4px 0; }
.palette canvas { width: 36px; height: 36px; border: 2px solid transparent; border-radius: 4px; cursor: pointer; }
.palette canvas.active, #toolErase.active { border-color: #2f6fde; background: rgba(47,111,222,.3); }
.editorside > * { margin-bottom: 8px; }
.fenline { font: 11px Menlo, monospace; margin-top: 8px; user-select: text; word-break: break-all; }
.settingsbody { width: 480px; min-height: 280px; padding: 12px 4px; }
.settingsbody label { display: block; margin: 8px 0; }
.settingsbody img { display: block; max-height: 180px; max-width: 100%; margin-top: 8px; background: #fff; }
.note { color: var(--muted); font-size: 11px; }
.about { width: 420px; text-align: center; }
.about p { text-align: left; font-size: 11px; white-space: pre-line; }
.gameover { text-align: center; }
.gameover img { width: 460px; max-width: 100%; display: block; }
.gameover .msg { font-size: 20px; font-weight: 700; margin: 10px 0; white-space: pre-line; }
table.gib { border-collapse: collapse; font-size: 11px; }
table.gib th, table.gib td { border: 1px solid var(--line); padding: 2px 6px; white-space: nowrap; }
table.gib tr.selected td { background: rgba(47,111,222,.35); }
table.gib tbody tr { cursor: pointer; }
.gibwrap { max-height: 340px; overflow: auto; }
