:root {
  --bg: #1b1c1f;
  --panel: #26282c;
  --panel-2: #2f3237;
  --line: #3a3d43;
  --text: #ecebe8;
  --muted: #9b9a96;
  --accent: #7fb069;
  --accent-ink: #11160e;
  --warn: #e0a458;
  --danger: #d1605a;
  --gutter: 12px;
  --s-cheney: #9a58e0;   /* Cheney = purple, Alex = blue; pair validated for CVD on the dark panel */
  --s-alex: #22a2c0;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px;
  cursor: pointer; touch-action: manipulation;
}
button:hover { border-color: #565a62; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 6px; }

.top {
  display: flex; align-items: center; gap: 10px;
  padding: 10px var(--gutter); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.brand { font-size: 18px; margin: 0; flex: 1; letter-spacing: .02em; }
.back { padding: 6px 10px; }
.who { color: var(--muted); font-size: 14px; background: none; border: 0; padding: 6px 4px; }
.who:empty { display: none; }

main { max-width: 1100px; margin: 0 auto; padding: var(--gutter); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.center { text-align: center; }
.muted { color: var(--muted); }
h2 { font-size: 18px; margin: 0 0 12px; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.theme-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.theme-row > .muted { width: 3.4em; }
.theme-row .seg { flex: 1; }
.seg2 { grid-template-columns: 1fr 1fr; }
.seg3 { grid-template-columns: 1fr 1fr 1fr; }
.seg button.on { border-color: var(--accent); background: #34402f; }
.section { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 22px 0 8px; }
.games { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.games li button {
  width: 100%; text-align: left; display: flex; justify-content: space-between; gap: 10px;
  align-items: center; background: var(--panel); padding: 12px 14px;
}
.games li.mine button { border-color: var(--accent); }
.games .g-title { font-weight: 600; }
.games .g-sub { color: var(--muted); font-size: 13px; }
.games .empty { color: var(--muted); font-size: 14px; padding: 4px 2px; }
.foot { display: flex; justify-content: space-between; flex-wrap: wrap; margin-top: 28px; }

/* ---- stats ---- */
.nav-stats { padding: 6px 12px; }
#v-stats { display: grid; gap: 12px; }
.pcards { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.pcard { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.pcard .pc-name { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.sw-Cheney { background: var(--s-cheney); }
.sw-Alex { background: var(--s-alex); }
.pcard .pc-elo { font-size: 36px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; margin: 6px 0 2px; }
.pcard .pc-rec { font-variant-numeric: tabular-nums; }
.small { font-size: 13px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.chart-head h2 { margin: 0; }
.legend { display: flex; gap: 14px; font-size: 14px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart { position: relative; margin-top: 10px; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .base { stroke: #565a62; stroke-width: 1; stroke-dasharray: 3 4; }
.chart .ax { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .dl { fill: var(--text); font-size: 12px; font-weight: 600; }
.chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .ln-Cheney, .chart .dot-Cheney { stroke: var(--s-cheney); }
.chart .ln-Alex, .chart .dot-Alex { stroke: var(--s-alex); }
.chart .dot { fill: var(--panel); stroke-width: 2; }
.chart .xh { stroke: #8a8f98; stroke-width: 1; }
.chart .empty { fill: var(--muted); font-size: 14px; }
.tip { position: absolute; pointer-events: none; background: #111214; border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; font-size: 13px; white-space: nowrap; z-index: 3; }
.tip div { display: flex; align-items: center; gap: 6px; }
.tip .t-sub { color: var(--muted); }
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
.tbl th, .tbl td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.tbl th { color: var(--muted); font-weight: 500; }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl tr:last-child td { border-bottom: 0; }
.up { color: var(--accent); }
.down { color: var(--danger); }

/* ---- game view ---- */
.game { display: grid; gap: 12px; }
.board-col { display: grid; gap: 6px; justify-items: center; }
.board-wrap { position: relative; width: var(--bsize); height: var(--bsize); }
.board { width: 100%; height: 100%; }
.board3d { width: 100%; height: 100%; touch-action: manipulation; }
/* the tilted board is wider than it is tall: give it a shorter stage */
body.view-3d .board-wrap { height: calc(var(--bsize) * 0.86); }
.board3d canvas { display: block; width: 100%; height: 100%; }
body.view-3d .board-wrap { box-shadow: none !important; }
body.view-3d .board-wrap::after { display: none !important; }
.game { --bsize: min(calc(100vw - 2 * var(--gutter)), calc(100dvh - 250px), 640px); }
.player { width: var(--bsize); display: flex; justify-content: space-between; align-items: center; min-height: 26px; }
.pname { font-weight: 600; }
.pname.to-move::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); margin-right: 7px; vertical-align: 1px; }
.caps { color: var(--muted); font-size: 18px; letter-spacing: -2px; }

.side-col { display: grid; gap: 10px; align-content: start; }
.status { font-weight: 600; text-align: center; min-height: 24px; }
.status.alert { color: var(--warn); }
.ask { background: var(--panel); border: 1px solid var(--warn); border-radius: 12px; padding: 10px 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ask span { flex: 1; min-width: 140px; }
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.actions button { padding: 9px 4px; font-size: 14px; }
#actions-over { grid-template-columns: 2fr 1fr; }
.moves {
  margin: 0; padding: 8px 10px; list-style: none; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; max-height: 180px; overflow-y: auto;
  display: grid; grid-template-columns: 2.4em 1fr 1fr; gap: 2px 6px; font-variant-numeric: tabular-nums;
}
.moves .num { color: var(--muted); }
.moves .ply { cursor: pointer; padding: 1px 6px; border-radius: 6px; }
.moves .ply.cur { background: var(--panel-2); outline: 1px solid var(--accent); }
.moves .none { grid-column: 1 / -1; color: var(--muted); }
.navbtns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }

/* promotion picker sits over the board */
.promo { position: absolute; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 10; }
.promo .row { display: flex; gap: 8px; background: var(--panel); padding: 10px; border-radius: 14px; }
.promo button { width: calc(var(--bsize) / 6); height: calc(var(--bsize) / 6); padding: 0; background-size: 85%; background-repeat: no-repeat; background-position: center; }

/* The picker row is a .cg-wrap so Chessground's piece images apply; undo its board layout. */
.promo .row.cg-wrap { width: auto; height: auto; }
.promo .row.cg-wrap piece { position: static; display: block; width: 100%; height: 100%; transform: none; }
.promo button { background: #f0d9b5; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; max-width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.6); }
#dlg-input { width: 100%; font: 13px ui-monospace, monospace; padding: 8px; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 12px; }
.dlg-btns { display: flex; justify-content: flex-end; gap: 8px; }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #000c; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: calc(100vw - 32px); }

/* Wide screens (desktop, iPad landscape): board left, panel right. */
@media (min-width: 820px) and (min-aspect-ratio: 1/1) {
  .game { grid-template-columns: auto minmax(260px, 340px); align-items: start; justify-content: center;
          --bsize: min(calc(100vw - 420px), calc(100dvh - 140px), 760px); }
  .moves { max-height: calc(var(--bsize) - 200px); }
  .side-col { padding-top: 32px; }
}

/* Chessground's coordinates hang ~12px outside the board, which scrolls a phone
   sideways. Tuck them inside the edge squares instead. */
.cg-wrap coords { font-size: 10px; font-weight: 700; opacity: .75; }
.cg-wrap coords.files { left: 0; bottom: 1px; }
.cg-wrap coords.files coord { text-align: right; padding-right: 3px; }
.cg-wrap coords.ranks { left: 2px; top: 2px; }
.cg-wrap coords.ranks coord { transform: none; }
body { overflow-x: hidden; }
