:root {
  --bg: #0f1115;
  --panel: #171a21;
  --line: #2a2f3a;
  --text: #e7e9ee;
  --muted: #9aa3b2;
  --p1: #4f8cff;
  --p2: #ff7a59;
  --cz: #2b3b2a;
  --cz-edge: #4f8a4a;
  --pillar: #3a3f4b;
  --target: #f2d35b;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* .btn sets display, which would otherwise override the hidden attribute */
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; width: min(560px, 100% - 32px); margin: 24px auto; }
code { font-size: 0.85em; color: var(--muted); }
a { color: var(--p1); }

.top {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.logo { color: var(--cz-edge); }
.tag { font-size: 12px; font-weight: 500; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }
.top-right { display: flex; gap: 8px; align-items: center; }

select, .btn {
  font: inherit; color: var(--text); background: #1f2430; border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 12px;
}
.btn { cursor: pointer; text-decoration: none; display: inline-block; }
.btn:hover { border-color: #3d4554; }
.btn:disabled { opacity: 0.5; cursor: progress; }
.btn.primary { background: var(--p1); border-color: var(--p1); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.card h1 { margin: 0 0 8px; font-size: 22px; }
.lead { color: var(--muted); margin: 0 0 18px; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; min-height: 1em; }

.score {
  text-align: center; font-size: 22px; font-weight: 700; letter-spacing: 0.01em;
  padding: 10px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line);
}
.status { text-align: center; color: var(--muted); margin: 10px 0 14px; min-height: 1.5em; }
.status b { color: var(--text); }

.board-wrap { display: flex; justify-content: center; }
.board {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px;
  width: min(440px, 100%); aspect-ratio: 1;
}
.cell {
  position: relative; border: 1px solid var(--line); border-radius: 8px; background: #141821;
  display: flex; align-items: center; justify-content: center; padding: 0; cursor: default;
  font: inherit; color: inherit;
}
.cell.cz { background: var(--cz); border-color: var(--cz-edge); }
.cell.pillar { background: repeating-linear-gradient(45deg, var(--pillar), var(--pillar) 6px, #31353f 6px, #31353f 12px); }
.cell .coord { position: absolute; left: 5px; top: 3px; font-size: 10px; color: var(--muted); opacity: 0.7; }
.cell.clickable { cursor: pointer; }
.cell.selected { outline: 2px solid var(--target); outline-offset: 1px; }
.cell.target::after {
  content: ""; width: 26%; height: 26%; border-radius: 50%; background: var(--target); opacity: 0.85;
}
.cell.capture::after { content: ""; position: absolute; inset: 10%; border: 3px solid var(--target); border-radius: 50%; }
.unit {
  width: 62%; height: 62%; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #fff; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}
.unit.p1 { background: var(--p1); }
.unit.p2 { background: var(--p2); }
.unit.fort { box-shadow: 0 0 0 4px var(--bg), 0 0 0 7px #e7e9ee; }
.cell.last { box-shadow: inset 0 0 0 2px rgba(242, 211, 91, 0.35); }

.actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 16px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; color: var(--muted); font-size: 13px; }
.legend i { display: inline-block; width: 12px; height: 12px; vertical-align: -1px; margin-right: 4px; }
.tok { border-radius: 50%; }
.tok.p1 { background: var(--p1); }
.tok.p2 { background: var(--p2); }
.tok.fort { border: 2px solid #e7e9ee; }
.sq { border-radius: 3px; }
.sq.cz { background: var(--cz); border: 1px solid var(--cz-edge); }
.sq.pillar { background: var(--pillar); }

.rules { margin-top: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; }
.rules summary { cursor: pointer; font-weight: 600; }
.rules ul { color: var(--muted); padding-left: 18px; }
.session-note { color: var(--muted); font-size: 13px; text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #232937; border: 1px solid var(--line); border-radius: 8px; padding: 10px 16px; max-width: 90vw;
}
.toast.error { border-color: #b94a48; }

footer { text-align: center; color: var(--muted); font-size: 12px; padding: 16px; border-top: 1px solid var(--line); }

.players { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.pcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.pcard.active { border-color: var(--target); box-shadow: 0 0 0 1px var(--target); }
.pcard.winner { border-color: var(--cz-edge); box-shadow: 0 0 0 1px var(--cz-edge); }
.pcard .who { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.pcard .dot { width: 12px; height: 12px; border-radius: 50%; }
.pcard .dot.p1 { background: var(--p1); }
.pcard .dot.p2 { background: var(--p2); }
.pcard .badge { font-size: 11px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; }
.pcard .addr { color: var(--muted); font-size: 12px; font-family: ui-monospace, monospace; margin: 2px 0 6px; }
.pcard .facts { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--muted); }
.pcard .facts b { color: var(--text); }
.gameover { display: flex; gap: 8px; justify-content: center; margin: 4px 0 14px; }
.status { font-size: 16px; }

.opponent { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px 12px; margin: 0 0 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; }
.opponent legend { color: var(--muted); font-size: 13px; padding: 0 6px; }
.opponent label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.muted { color: var(--muted); font-size: 12px; }
.hintline { text-align: center; color: var(--target); font-size: 14px; margin: -6px 0 12px; min-height: 1em; }
