:root {
  --bg: #161512; --panel: #262421; --panel2: #302e2c; --line: #3d3a36; --line2: #4a4744;
  --text: #bababa; --strong: #e2e2e2; --dim: #8a8784;
  --blue: #3692e7; --green: #629924; --red: #cc3333; --amber: #d59120;
  --light: #f0d9b5; --dark: #b58863; --hl: rgba(155, 199, 0, .41);
  --board: min(calc(100vh - 150px), calc(100vw - 790px));
  --shadow: 0 2px 2px 0 rgba(0,0,0,.14), 0 3px 1px -2px rgba(0,0,0,.2), 0 1px 5px 0 rgba(0,0,0,.12);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg) linear-gradient(to bottom, #2e2a24, var(--bg) 116px) no-repeat; color: var(--text); font: 14px/1.45 'Noto Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; min-height: 100vh; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button, select, input { font: inherit; color: inherit; }
h1, h2, h3 { color: var(--strong); font-weight: 400; margin: 0 0 10px; }
h2 { font-size: 1.15rem; }
[hidden] { display: none !important; }

/* header */
.top { display: flex; align-items: center; gap: 26px; height: 54px; padding: 0 22px; }
.logo { display: flex; align-items: center; gap: 9px; color: var(--strong); font-size: 1.55rem; letter-spacing: -.01em; }
.logo:hover { text-decoration: none; color: #fff; }
.top nav { display: flex; gap: 4px; }
.top nav a { color: var(--text); text-transform: uppercase; font-size: .86rem; letter-spacing: .04em; padding: 8px 12px; border-radius: 3px; }
.top nav a:hover { text-decoration: none; color: var(--strong); background: rgba(255,255,255,.04); }
.top nav a.on { color: var(--strong); background: var(--panel); }
.icon-btn { margin-left: auto; background: none; border: 0; padding: 6px; cursor: pointer; color: var(--dim); display: grid; place-items: center; border-radius: 3px; }
.icon-btn:hover { color: var(--strong); background: rgba(255,255,255,.05); }

/* arena: side | board | moves, like a Lichess game page */
.arena { display: grid; grid-template-columns: minmax(250px, 320px) auto minmax(260px, 360px); grid-template-areas: "side center rcol" "tree tree tree"; gap: 18px 22px; padding: 6px 22px 40px; justify-content: center; align-items: start; }
.side { grid-area: side; }
.center { grid-area: center; }
.rcol { grid-area: rcol; display: flex; flex-direction: column; height: var(--board); }
.tree { grid-area: tree; }

.card { background: var(--panel); border-radius: 4px; box-shadow: var(--shadow); padding: 16px 16px 18px; margin-bottom: 14px; }
.card h2 { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card h2 small { font-size: .8rem; color: var(--dim); }
.sub { color: var(--dim); font-size: .85rem; }
.lbl { display: block; color: var(--dim); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; margin: 14px 0 6px; }

/* board */
.board-wrap { position: relative; display: flex; gap: 8px; }
.board { position: relative; width: var(--board); height: var(--board); user-select: none; box-shadow: var(--shadow); }
.board .squares { position: absolute; inset: 0; display: grid; grid-template: repeat(8, 1fr) / repeat(8, 1fr); }
.sq { position: relative; }
.sq.l { background: var(--light); } .sq.d { background: var(--dark); }
.sq span { position: absolute; font-weight: 700; font-size: calc(var(--board) / 54); }
.sq .rank { top: 2%; left: 4%; } .sq .file { bottom: 1%; right: 5%; }
.sq.l span { color: var(--dark); } .sq.d span { color: var(--light); }
.marks, .pieces { position: absolute; inset: 0; pointer-events: none; }
.mk { position: absolute; width: 12.5%; height: 12.5%; }
.mk.last { background: var(--hl); }
.mk.check { background: radial-gradient(ellipse at center, rgba(255,0,0,1) 0%, rgba(231,0,0,1) 25%, rgba(169,0,0,0) 89%, rgba(158,0,0,0) 100%); }
.piece { position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%; transition: transform .14s ease; will-change: transform; }
.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.gauge { position: relative; width: 14px; height: var(--board); background: #4d4d4d; border-radius: 2px; overflow: hidden; flex: none; }
.gauge-w { position: absolute; left: 0; right: 0; bottom: 0; height: 50%; background: #fff; transition: height .4s ease; }
.gauge::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 2px; margin-top: -1px; background: rgba(214,79,0,.6); }
.gauge span { position: absolute; left: 0; right: 0; text-align: center; font-size: 9px; font-weight: 700; color: #333; bottom: 2px; writing-mode: vertical-rl; transform: rotate(180deg); }
.gauge.flip .gauge-w { bottom: auto; top: 0; }
.gauge.bneg span { bottom: auto; top: 2px; color: #ddd; }

.overlay { position: absolute; inset: 0 0 0 22px; display: grid; place-items: center; background: rgba(22,21,18,.72); }
.ov-box { background: var(--panel); border-radius: 4px; box-shadow: var(--shadow); padding: 18px 22px; width: min(340px, 80%); }
.ov-box b { color: var(--strong); display: block; margin-bottom: 8px; font-weight: 500; }
.ov-bar { height: 6px; border-radius: 3px; background: var(--panel2); overflow: hidden; margin: 8px 0 6px; }
.ov-bar i { display: block; height: 100%; width: 0; background: var(--blue); transition: width .2s; }
.ov-box .err { color: #e06666; }

/* eval graph */
.graph { margin-top: 12px; margin-left: 22px; background: var(--panel); border-radius: 4px; box-shadow: var(--shadow); height: 110px; overflow: hidden; }
.graph:empty { display: none; }
.graph svg { display: block; width: 100%; height: 100%; cursor: pointer; }

/* right column: player boxes, engine lines, moves */
.pbox { display: flex; align-items: stretch; justify-content: space-between; background: var(--panel); box-shadow: var(--shadow); min-height: 48px; }
.pbox:first-child { border-radius: 4px 4px 0 0; }
.pbox:last-child { border-radius: 0 0 4px 4px; }
.pname { display: flex; align-items: center; gap: 8px; padding: 6px 12px; min-width: 0; }
.pname b { color: var(--strong); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pname .tag { color: var(--dim); font-size: .8rem; white-space: nowrap; }
.side-dot { width: 11px; height: 11px; border-radius: 50%; flex: none; border: 1px solid #000; }
.side-dot.w { background: #fff; } .side-dot.b { background: #222; border-color: #777; }
.pscore { color: var(--strong); font-weight: 700; margin-left: 4px; }
.clock { font-family: 'Roboto Mono', ui-monospace, Menlo, monospace; font-size: 1.85rem; color: #999; background: #2c2a27; padding: 2px 14px; display: flex; align-items: center; min-width: 120px; justify-content: flex-end; }
.clock.run { background: #3a4b2a; color: #fff; }
.clock.low { background: #6d2a2a; color: #fff; }
.clock.mini { font-size: 1rem; min-width: 0; color: var(--dim); background: none; }

.ceval { background: #2b2926; padding: 7px 12px; min-height: 58px; border-left: 3px solid transparent; font-size: .85rem; }
.ceval.on { border-left-color: var(--blue); }
.ceval .row1 { display: flex; align-items: baseline; gap: 10px; }
.ceval .ev { font-size: 1.25rem; font-weight: 700; color: var(--strong); min-width: 62px; }
.ceval .meta { color: var(--dim); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ceval .pv { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.ceval .pv i { color: var(--dim); font-style: normal; }
.ceval.idle { color: var(--dim); }

.movebox { flex: 1; min-height: 120px; display: flex; flex-direction: column; background: var(--panel); box-shadow: var(--shadow); overflow: hidden; }
.ctrl { display: flex; gap: 1px; background: var(--line); border-bottom: 1px solid var(--line); }
.ctrl button, .ctrl select { flex: 1; background: var(--panel2); border: 0; padding: 7px 4px; cursor: pointer; color: var(--text); display: grid; place-items: center; min-width: 0; }
.ctrl select { flex: 1.6; appearance: none; text-align: center; text-align-last: center; font-size: .8rem; }
.ctrl button:hover:not(:disabled), .ctrl select:hover { background: #3b3936; color: var(--strong); }
.ctrl button:disabled { opacity: .35; cursor: default; }
.ctrl button.on { color: var(--blue); }
.moves { flex: 1; overflow-y: auto; display: grid; grid-template-columns: 13% 43.5% 43.5%; align-content: start; font-size: .95rem; }
.moves .no { background: var(--panel2); color: var(--dim); text-align: center; padding: 3px 0; border-right: 1px solid var(--line); }
.moves .mv { padding: 3px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 6px; }
.moves .mv:hover { background: #2d3f51; color: #fff; }
.moves .mv.cur { background: #293a49; color: #fff; font-weight: 700; }
.moves .mv small { color: var(--dim); font-weight: 400; font-size: .75rem; }
.moves .empty { grid-column: 1 / -1; color: var(--dim); padding: 14px; text-align: center; }
.result { text-align: center; padding: 8px; border-top: 1px solid var(--line); }
.result:empty { display: none; }
.result b { display: block; font-size: 1.25rem; color: var(--strong); }
.result span { color: var(--dim); font-size: .85rem; }

/* forms (Lichess "create a game" style) */
.ent { border: 1px solid var(--line); border-radius: 4px; padding: 10px 10px 12px; margin-bottom: 10px; background: #2a2825; }
.ent-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--strong); }
.ent-head .x { margin-left: auto; background: none; border: 0; color: var(--dim); cursor: pointer; font-size: 1.1rem; line-height: 1; padding: 2px 6px; }
.ent-head .x:hover { color: #e06666; }
.ent-head .seed { color: var(--dim); font-size: .8rem; min-width: 18px; }
select.sel { width: 100%; background: #1f1d1b; border: 1px solid var(--line2); border-radius: 3px; padding: 7px 8px; color: var(--strong); }
.seg { display: flex; border: 1px solid var(--line2); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.seg button { flex: 1; background: #1f1d1b; border: 0; border-right: 1px solid var(--line2); padding: 6px 4px; cursor: pointer; font-size: .85rem; color: var(--text); }
.seg button:last-child { border-right: 0; }
.seg button:hover { color: var(--strong); background: #2a2825; }
.seg button.on { background: var(--blue); color: #fff; }
.range { margin-top: 10px; }
.range .rl { display: flex; justify-content: space-between; font-size: .85rem; }
.range .rl b { color: var(--strong); }
input[type=range] { width: 100%; accent-color: var(--blue); margin: 4px 0 0; }
.note { color: var(--dim); font-size: .78rem; margin-top: 6px; }
.chk { display: flex; gap: 8px; align-items: flex-start; margin-top: 14px; font-size: .88rem; cursor: pointer; }
.chk input { accent-color: var(--blue); margin-top: 3px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--panel2); border: 1px solid var(--line2); border-radius: 3px; color: var(--text); padding: 7px 12px; cursor: pointer; font-size: .85rem; }
.btn:hover { color: var(--strong); background: #3b3936; text-decoration: none; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; text-transform: uppercase; letter-spacing: .04em; font-size: .9rem; padding: 11px 14px; width: 100%; margin-top: 16px; }
.btn.primary:hover { background: #4aa0ef; }
.btn.danger:hover { background: var(--red); border-color: var(--red); color: #fff; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.swap { display: flex; justify-content: center; margin: -4px 0 6px; }
.swap button { background: none; border: 0; color: var(--dim); cursor: pointer; padding: 2px 8px; font-size: .82rem; }
.swap button:hover { color: var(--strong); }

/* match / record summary */
.score { width: 100%; border-collapse: collapse; margin: 6px 0 4px; }
.score td { padding: 5px 0; border-bottom: 1px solid var(--line); }
.score td:last-child { text-align: right; color: var(--strong); font-weight: 700; font-size: 1.1rem; }
.score tr.lead td:first-child { color: var(--strong); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: .85rem; margin-top: 8px; }
.kv dt { color: var(--dim); } .kv dd { margin: 0; color: var(--strong); text-align: right; }
.glist { margin-top: 12px; max-height: 260px; overflow-y: auto; border-top: 1px solid var(--line); }
.grow { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; padding: 6px 4px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: .85rem; }
.grow:hover { background: rgba(255,255,255,.03); }
.grow.cur { background: #293a49; }
.grow .n { color: var(--dim); }
.grow .r { color: var(--strong); font-weight: 700; }
.grow small { display: block; color: var(--dim); font-size: .75rem; }
.stats { width: 100%; border-collapse: collapse; font-size: .8rem; margin-top: 10px; }
.stats th { color: var(--dim); font-weight: 400; text-align: right; padding: 3px 0 3px 6px; }
.stats th:first-child, .stats td:first-child { text-align: left; padding-left: 0; }
.stats td { text-align: right; padding: 4px 0 4px 6px; border-top: 1px solid var(--line); color: var(--strong); }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--red); margin-right: 6px; animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.banner { background: #2d3f51; color: #dfe9f3; border-radius: 3px; padding: 8px 10px; font-size: .85rem; margin-bottom: 10px; }

/* bracket tree */
.tree { background: var(--panel); border-radius: 4px; box-shadow: var(--shadow); padding: 16px; overflow-x: auto; }
.rounds { display: flex; gap: 34px; min-width: max-content; }
.round { display: flex; flex-direction: column; width: 220px; }
.round h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); margin: 0 0 8px; }
.round .slots { flex: 1; display: flex; flex-direction: column; justify-content: space-around; gap: 10px; }
.mbox { position: relative; border: 1px solid var(--line2); border-radius: 3px; background: #2a2825; font-size: .82rem; cursor: pointer; }
.mbox:hover { border-color: #6a6662; }
.mbox.now { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.mbox .ln { display: flex; justify-content: space-between; gap: 6px; padding: 4px 8px; }
.mbox .ln + .ln { border-top: 1px solid var(--line); }
.mbox .ln span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mbox .ln i { font-style: normal; color: var(--dim); margin-right: 6px; }
.mbox .ln.win { color: var(--strong); font-weight: 700; }
.mbox .ln.lose { color: var(--dim); }
.mbox .ln.tbd { color: #5d5a57; }
.mbox .note2 { position: absolute; right: 6px; bottom: -15px; font-size: .68rem; color: var(--dim); }
.champ { margin-top: 12px; color: var(--strong); }
.champ b { color: #e8c547; }

/* pages */
.page { max-width: 900px; margin: 10px auto 60px; padding: 0 22px; }
.page .card { padding: 20px 22px; }
.hlist { width: 100%; border-collapse: collapse; }
.hlist td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.hlist tr:hover td { background: rgba(255,255,255,.02); }
.hlist .t { color: var(--strong); }
.hlist .acts { text-align: right; white-space: nowrap; }
.hlist .acts .btn { padding: 5px 9px; font-size: .8rem; margin-left: 4px; }
.page p, .page li { line-height: 1.6; }
.page h3 { font-size: 1rem; margin-top: 18px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--panel); color: var(--strong); padding: 10px 16px; border-radius: 4px; box-shadow: 0 4px 18px rgba(0,0,0,.5); z-index: 50; max-width: 90vw; }

@media (max-width: 1180px) {
  :root { --board: min(calc(100vw - 80px), calc(100vh - 150px)); }
  .arena { grid-template-columns: auto; grid-template-areas: "center" "rcol" "side" "tree"; }
  .rcol { height: 520px; }
}

/* engine picker */
.pick { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: #1f1d1b; border: 1px solid var(--line2); border-radius: 3px; padding: 7px 9px; cursor: pointer; color: var(--text); }
.pick:hover { border-color: #6a6662; background: #262421; }
.pk-ico { color: var(--dim); display: inline-grid; place-items: center; flex: none; }
.pk-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pk-txt b { color: var(--strong); font-weight: 500; }
.pk-txt small { color: var(--dim); font-size: .75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pk-r { color: var(--dim); font-size: .8rem; flex: none; }
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 20px; }
.mbody { background: var(--panel); border-radius: 4px; box-shadow: 0 8px 30px rgba(0,0,0,.6); width: min(860px, 100%); max-height: 88vh; overflow-y: auto; padding: 18px 22px 10px; }
.mhead { display: flex; justify-content: space-between; align-items: center; }
.mhead h2 { margin: 0; }
.mbody .x { background: none; border: 0; color: var(--dim); font-size: 1.6rem; cursor: pointer; line-height: 1; }
.mbody .x:hover { color: var(--strong); }
.mbody h3 { display: flex; align-items: center; gap: 8px; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); margin: 18px 0 8px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.card2 { display: flex; flex-direction: column; gap: 3px; text-align: left; background: #2a2825; border: 1px solid var(--line2); border-radius: 3px; padding: 9px 11px; cursor: pointer; color: var(--text); }
.card2:hover { border-color: #6a6662; background: #302e2b; }
.card2.on { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.c-top { display: flex; justify-content: space-between; gap: 8px; }
.c-top b { color: var(--strong); font-weight: 500; }
.c-r { color: var(--dim); font-size: .85rem; }
.c-note { font-size: .8rem; }
.c-meta { color: var(--dim); font-size: .72rem; }
.c-meta .warn { color: var(--amber); }
