:root {
  --bg: #1d1f24; --panel: #272a31; --line: #3a3e47; --text: #e8e6e1; --dim: #9a9ca3;
  --accent: #7fa650; --light: #ecdab9; --dark: #ad7f5a;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 16px/1.4 system-ui, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
button, select, input[type=text], input:not([type]) {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px;
}
button { cursor: pointer; }
button:hover { border-color: #5a5f6b; }
button.go { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button:disabled { opacity: .5; cursor: default; }

header.bar { display: flex; align-items: center; gap: 14px; padding: 12px 18px; }
.brand { font-weight: 700; text-decoration: none; letter-spacing: .2px; }
.conn { color: #e0b85a; font-size: 14px; }

/* ---- lobby ---- */
.lobby { max-width: 420px; margin: 8vh auto; padding: 0 18px; }
.lobby h1 { font-size: 34px; margin: 0 0 6px; }
.lobby p { color: var(--dim); margin: 0 0 24px; }
.lobby label { display: block; font-size: 14px; color: var(--dim); margin: 14px 0 6px; }
.lobby input, .lobby select, .lobby button { width: 100%; }
.lobby button.go { margin-top: 22px; padding: 13px; }
.lobby .err { color: #e07a6a; min-height: 1.4em; margin-top: 10px; }

/* ---- board ---- */
.board { position: relative; width: 100%; aspect-ratio: 1; user-select: none; touch-action: none; border-radius: 6px; overflow: hidden; }
.board .squares, .board .pieces { position: absolute; inset: 0; }
.board .pieces { pointer-events: none; }
.sq { position: absolute; width: 12.5%; height: 12.5%; }
.sq.l { background: var(--light); color: var(--dark); }
.sq.d { background: var(--dark); color: var(--light); }
.sq::before { content: attr(data-rank); position: absolute; left: 4%; top: 2%; font-size: clamp(9px, 1.4vmin, 13px); font-weight: 700; }
.sq::after { content: attr(data-file); position: absolute; right: 5%; bottom: 1%; font-size: clamp(9px, 1.4vmin, 13px); font-weight: 700; }
.sq.last { box-shadow: inset 0 0 0 100vmax rgba(247, 221, 92, .42); }
.sq.sel { box-shadow: inset 0 0 0 100vmax rgba(127, 166, 80, .6); }
.sq.check { background-image: radial-gradient(circle, rgba(226, 60, 44, .95) 0%, rgba(226, 60, 44, .55) 45%, transparent 75%); }
.sq.tgt { cursor: pointer; background-image: radial-gradient(circle, rgba(20, 30, 15, .32) 0 17%, transparent 18%); }
.sq.tgt.cap { background-image: radial-gradient(circle, transparent 0 56%, rgba(20, 30, 15, .32) 57% 68%, transparent 69%); }
.pc { position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%; transition: transform .16s ease; will-change: transform; }
.pc.snap, .pc.drag { transition: none; }
.pc.drag { z-index: 5; }
.pc svg { display: block; width: 100%; height: 100%; filter: drop-shadow(0 2px 1.5px rgba(0, 0, 0, .3)); }
.pc-w * { fill: #f8f4ea; stroke: #23201c; stroke-width: 3.2; stroke-linejoin: round; }
.pc-b * { fill: #2c2926; stroke: #ded8cc; stroke-width: 2.2; stroke-linejoin: round; }
.pc-w .eye { fill: #23201c; stroke: none; }
.pc-b .eye { fill: #ded8cc; stroke: none; }
.pc svg .cut { fill: none; stroke-linecap: round; }
.pc.faint { opacity: .45; }
.board .arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; opacity: .8; }
.arrows line { stroke: #5b9bd5; stroke-width: .17; stroke-linecap: round; }
.arrows polygon { fill: #5b9bd5; }
.pc i { position: absolute; font: 700 10px/1 system-ui, sans-serif; padding: 2px 4px; border-radius: 4px; color: #fff; }
.pc i.note { right: 3%; top: 3%; background: #c2452d; }
.pc i.label { left: 3%; bottom: 3%; background: #3b5fb5; }
.promo { position: absolute; z-index: 6; display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .5); width: 50%; }
.promo[hidden] { display: none; }
.promo button { flex: 1; padding: 2px; border: 0; background: none; aspect-ratio: 1; }
.promo button:hover { background: rgba(255, 255, 255, .1); }
.promo svg { width: 100%; height: 100%; }

/* ---- play page ---- */
.play main { display: flex; gap: 22px; justify-content: center; align-items: flex-start; padding: 0 18px 24px; flex-wrap: wrap; }
.table { display: flex; gap: 10px; width: min(100%, calc(100vh - 170px), 720px); min-width: 280px; }
.table .col { flex: 1; min-width: 0; }
.evalbar { position: relative; width: 18px; margin: 44px 0; border-radius: 4px; overflow: hidden; background: #33302c; }
.evalbar .fill { position: absolute; left: 0; right: 0; bottom: 0; background: #f1ede3; transition: height .5s ease; }
.evalbar.flip .fill { bottom: auto; top: 0; }
.evalbar .num { position: absolute; left: 0; right: 0; bottom: 3px; text-align: center; font-size: 9px; font-weight: 700; color: #33302c; }
.evalbar.flip .num { bottom: auto; top: 3px; }
.evalbar .num.dark { color: #f1ede3; bottom: auto; top: 3px; }
.evalbar.flip .num.dark { top: auto; bottom: 3px; }
.who { display: flex; align-items: center; gap: 9px; height: 44px; }
.who .dot { width: 9px; height: 9px; border-radius: 50%; background: #555; }
.who.on .dot { background: var(--accent); }
.who .nm { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .clk { font: 600 20px/1 ui-monospace, Consolas, monospace; background: var(--panel); padding: 7px 11px; border-radius: 6px; color: var(--dim); }
.who.run .clk { background: #f1ede3; color: #1d1f24; }
.who.low.run .clk { background: #c2452d; color: #fff; }
aside.side { width: 280px; flex: 1 1 280px; max-width: 360px; display: flex; flex-direction: column; gap: 12px; margin-top: 44px; }
.status { font-size: 18px; font-weight: 600; min-height: 1.4em; }
.invite { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-size: 14px; color: var(--dim); }
.invite div { display: flex; gap: 8px; margin-top: 8px; }
.invite input { flex: 1; min-width: 0; color: var(--text); }
.moves { list-style: none; margin: 0; padding: 8px; background: var(--panel); border-radius: 10px; height: 300px; overflow-y: auto; font: 15px/1.7 ui-monospace, Consolas, monospace; }
.moves li { display: grid; grid-template-columns: 2.4em 1fr 1fr; padding: 0 6px; border-radius: 4px; }
.moves li:nth-child(odd) { background: rgba(255, 255, 255, .03); }
.moves .n { color: var(--dim); }
.btns { display: flex; gap: 8px; }
.btns button { flex: 1; }
[hidden] { display: none !important; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 22px; width: min(92vw, 340px); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0 0 12px; font-size: 20px; }
dialog form { display: flex; gap: 8px; }
dialog input { flex: 1; min-width: 0; }
.missing { text-align: center; margin-top: 18vh; color: var(--dim); }

@media (max-width: 760px) {
  aside.side { margin-top: 0; max-width: none; }
  .moves { height: 150px; }
}
