:root {
  color-scheme: dark;
  --bg: #0b0e14; --panel: #131925; --line: #243047; --text: #e8eef6; --muted: #93a1b4;
  --accent: #5ee7ff; --accent-ink: #06202a; --danger: #ff4d6a;
  --light: #f0d9b5; --dark: #b58863;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: radial-gradient(circle at 50% 0%, #182033, var(--bg) 60%); color: var(--text); font-family: "Segoe UI", system-ui, sans-serif; line-height: 1.45; display: flex; flex-direction: column; min-height: 100vh; }
a { color: var(--accent); }
button, .button { font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #1b2333; color: var(--text); cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .button:hover { border-color: var(--accent); }
button.primary, .button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.ghost { background: transparent; }
button.big { font-size: 18px; padding: 12px 22px; }
input, select { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: inherit; }

/* ---------- header ---------- */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; padding: 10px 18px; border-bottom: 1px solid #1a2233; }
.brand { color: var(--text); text-decoration: none; font-weight: 700; font-size: 18px; }
.brand .mark { color: var(--accent); }
nav { display: flex; gap: 14px; flex: 1; }
nav a { color: var(--muted); text-decoration: none; }
nav a:hover { color: var(--text); }
.sound-menu { position: relative; }
.stream-menu { margin-left: auto; }
.stream-menu[hidden] { display: none; }
.stream-menu[hidden] + .sound-menu { margin-left: auto; }
.look-panel { width: 300px; }
.look-panel b { font-size: 13px; color: var(--muted); font-weight: 600; }
.look-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.look-grid button { display: grid; justify-items: center; gap: 4px; padding: 8px 4px; font-size: 12px; font-weight: 400; }
.look-grid button.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.look-grid .pair { display: flex; }
.look-grid .pair img { width: 34px; height: 34px; }
.look-grid .pair img + img { margin-left: -8px; }
.look-grid .swatch { width: 44px; height: 44px; border-radius: 6px; background: repeating-conic-gradient(var(--d) 0 25%, var(--l) 0 50%) 0 0 / 50% 50%; }
.stream-panel { width: 300px; }
.stream-panel input[readonly] { width: 100%; font-size: 12px; }
.stream-panel .row2 { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.sound-panel { position: absolute; right: 0; top: calc(100% + 8px); z-index: 50; width: 250px; display: grid; gap: 10px;
  padding: 14px; border-radius: 12px; background: #141b29; border: 1px solid var(--line); box-shadow: 0 12px 30px #0008; }
.sound-panel label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.sound-panel select, .sound-panel input[type=range] { width: 100%; }
.sound-panel .btns { justify-content: flex-start; }
.sound-panel .fine { margin: 0; font-size: 11px; }
.sound-panel[hidden] { display: none; }
#user-slot { display: flex; gap: 10px; align-items: center; }
.me { color: var(--muted); }
.me b { color: #ffb86b; }
main { flex: 1; width: min(1200px, 100%); margin: 0 auto; padding: 16px; }
.loading { color: var(--muted); text-align: center; margin-top: 20vh; }

/* ---------- logged out ---------- */
.hero { text-align: center; padding: 8vh 0 32px; }
.hero h1 { font-size: clamp(30px, 6vw, 52px); margin: 0 0 10px; letter-spacing: -0.02em; }
.hero p { color: var(--muted); max-width: 560px; margin: 0 auto 22px; font-size: 18px; }
.fine { color: #6f7d90; font-size: 13px; margin: 10px 0 0; }
.hero .fine { font-size: 13px; }
.error { color: var(--danger); }
.cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); max-width: 720px; margin: 0 auto; }
a.card { display: block; padding: 20px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); color: inherit; text-decoration: none; }
a.card:hover { border-color: var(--accent); }
.card h2 { margin: 0 0 6px; font-size: 19px; }
.card p { margin: 0; color: var(--muted); }
.tag { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--accent); margin-bottom: 8px; }

/* ---------- home ---------- */
.home { display: grid; row-gap: 16px; }
/* Home lines up exactly with the board on the game and watch screens (same width math, same empty sidebar
   column), so an OBS crop of the board also frames the home page. Keep in sync with .game below. */
.home { column-gap: 14px; justify-content: center; align-items: start;
  --board: min(100%, calc((100vh - 100px) / 1.27));
  grid-template-columns: var(--board); }
.home > * { grid-column: 1; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; }
.panel.highlight { border-color: var(--accent); }
.panel h2 { margin: 0 0 12px; font-size: 17px; }
.notice { background: #2a2030; border: 1px solid #5a3550; padding: 10px 14px; border-radius: 10px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid #1c2536; }
.row:first-of-type { border-top: 0; }
.row button { margin-left: 6px; }
.tc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.tc-grid button { padding: 14px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tc-grid b { font-size: 20px; }
.tc-grid small { color: var(--muted); }
.seek-opts { margin-top: 12px; }
.seek-opts .check { margin-top: 0; }
/* Rated / Casual: two-button segmented choice */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg label { cursor: pointer; position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 8px 14px; background: #1b2333; color: var(--muted); }
.seg label + label span { border-left: 1px solid var(--line); }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); margin-top: 10px; }
.form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.form input[name=user] { flex: 1 1 180px; }
.form .check { margin-top: 0; }
.searching { color: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

/* ---------- live games / watching ---------- */
.panel h2 { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
button.small { font-size: 13px; padding: 4px 10px; font-weight: 400; }
.btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.your-turn { color: var(--accent); }
.tv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-top: 14px; }
.tv-card { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 10px; background: #1b2333; border: 1px solid var(--line); color: var(--text); text-decoration: none; }
.tv-card:hover { border-color: var(--accent); }
.tv-card span { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tv-card em { color: #ffb86b; font-style: normal; font-weight: 700; }
.logged-out-watch { margin-top: 24px; }
#watch-result { margin-top: 8px; }
/* "Find a game" in the watch screen's sidebar */
.watch-seek .panel { padding: 14px 16px; }
.watch-seek .tc-grid { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.watch-seek .tc-grid button { padding: 8px 4px; }
.watch-seek .tc-grid b { font-size: 16px; }
.watch-seek .fine { margin: 8px 0 0; }
.seek-status { border-color: var(--accent); }
.seek-status button { margin-top: 12px; }

/* ---------- game ----------
   Players + clocks always sit directly above and below the board, exactly board-wide, so
   "board + both bars" is one clean rectangle for an OBS window capture. Text scales with the
   board (cqw = 1% of the board column's width). */
.game { display: grid; gap: 14px; justify-content: center; align-items: start;
  /* portrait / narrow: board column, then the controls under it */
  --board: min(100%, calc((100vh - 100px) / 1.27));
  grid-template-columns: var(--board); }
@media (min-width: 900px) and (min-aspect-ratio: 5/4) {
  /* the board screens (play, watch, analysis) fit the window: never a page scrollbar */
  html:has(.game), html:has(.game) body { overflow: hidden; }
  /* Tactic Bingo on: a third column right of the sidebar, as big as the room allows; the board gives up a little
     width only on narrow windows. */
  .game.with-bingo { --bingo: clamp(320px, min(34vw, calc(100vw - 428px - (100vh - 100px) / 1.27)), 680px);
    --board: min(calc(100vw - 400px - var(--bingo) - 28px), calc((100vh - 100px) / 1.27));
    grid-template-columns: var(--board) 320px var(--bingo); }
  .game.with-bingo .side { left: 0; }
  /* watch screen: everything stacks from the top (the Tactic Bingo button, then Find a game right below it) */
  .side:has(.watch-seek) { grid-template-rows: none; grid-auto-rows: max-content; }
  .game.with-bingo .bingo-dock { max-height: calc(100vh - 100px); }
  .game, .home { --board: min(calc(100vw - 400px), calc((100vh - 100px) / 1.27)); grid-template-columns: var(--board) 320px; }
  .side { align-self: stretch; grid-template-rows: auto auto 1fr;
    /* Push only the sidebar right (200px gap in total) without moving the board.
       Narrow windows get less shift so the sidebar never leaves the screen. */
    position: relative; left: clamp(0px, calc((100vw - var(--board) - 334px) / 2 - 16px), 186px); }
}
.board-col { container-type: inline-size; display: flex; flex-direction: column; gap: 0.8cqw; }
.side { display: grid; gap: 10px; align-content: start; }
.player { display: flex; justify-content: space-between; align-items: center; gap: 2cqw; background: var(--panel); border: 1px solid var(--line); border-radius: 1.4cqw; padding: 1cqw 1cqw 1cqw 2.2cqw; min-height: 9cqw; }
.who { display: flex; align-items: baseline; gap: 1.6cqw; min-width: 0; font-size: max(14px, 4.2cqw); }
.who .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .rating { color: #b6c2d2; font-weight: 600; }
.who .title { color: #ffb86b; font-weight: 800; }
.dot { width: 0.6em; height: 0.6em; border-radius: 50%; flex: none; border: 1px solid #555; align-self: center; }
.dot.white { background: #fff; } .dot.black { background: #000; }
.clock { font: 700 max(20px, 6.4cqw)/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; padding: 0.18em 0.4em; border-radius: 1cqw; background: #0d121b; color: #b9c4d2; min-width: 4.6em; text-align: right; font-variant-numeric: tabular-nums; }
.clock.running { background: #e8eef6; color: #0b0e14; }
.clock.low.running { background: var(--danger); color: #fff; }
.status-line .status { font-weight: 600; font-size: 18px; }
.status-line .info { color: var(--muted); font-size: 13px; text-transform: capitalize; }
.status-line .error { margin-top: 6px; font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions .note { color: var(--muted); font-size: 14px; }
.movelist { margin: 0; padding: 8px 10px 8px 42px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; max-height: 260px; overflow-y: auto; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; }
.movelist:empty { display: none; }
.movelist li { padding: 1px 0; }
.movelist li span { display: inline-block; width: 7ch; }
.movelist li::marker { color: #5d6a7c; }
/* replay: click a move, or ⏮ ◀ ▶ ⏭ / arrow keys */
.moves-box { display: grid; gap: 8px; align-content: start; }
.movelist span[data-ply] { cursor: pointer; border-radius: 4px; padding: 0 3px; box-sizing: border-box; }
.movelist span[data-ply]:hover { background: #1f2838; }
.movelist span.cur { background: #2b5fb8; color: #fff; }
.game-nav { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.game-nav:empty { display: none; }
.game-nav > button { padding: 6px 12px; }
.game-nav button:disabled { opacity: .4; cursor: default; }
.game-nav .note { color: var(--muted); font-size: 14px; }

/* ---------- board ---------- */
.board { position: relative; width: 100%; aspect-ratio: 1; border-radius: 4px; overflow: visible; user-select: none; touch-action: none; cursor: pointer;
  background: repeating-conic-gradient(var(--dark) 0 25%, var(--light) 0 50%) 0 0 / 25% 25%; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.hl-layer, .piece-layer, .coords, .shape-layer { position: absolute; inset: 0; pointer-events: none; }
.shape-layer { width: 100%; height: 100%; z-index: 6; overflow: visible; }
.hl { position: absolute; width: 12.5%; height: 12.5%; }
.hl.hill { background: rgba(255, 196, 80, .16); box-shadow: inset 0 0 0 3px rgba(255, 196, 80, .65); }
.hl.last { background: rgba(155, 199, 0, .41); }
.hl.selected { background: rgba(20, 85, 30, .5); }
.hl.check { background: radial-gradient(ellipse at center, #ff0000 0%, #e70000 25%, rgba(169, 0, 0, 0) 89%); }
.hl.dest { background: radial-gradient(rgba(20, 85, 30, .5) 19%, transparent 20%); }
.hl.dest.capture { background: radial-gradient(transparent 79%, rgba(20, 85, 0, .35) 80%); }
.piece { position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%; will-change: transform; }
.piece.anim { transition: transform .18s ease-out; }
.piece.dragging { z-index: 5; transition: none; filter: drop-shadow(0 8px 10px rgba(0,0,0,.45)); }
.coords span { position: absolute; font-size: clamp(9px, 1.4vw, 13px); font-weight: 700; }
.coords .file { bottom: 1px; width: 12.5%; text-align: right; padding-right: 3px; }
.coords .rank { left: 3px; height: 12.5%; padding-top: 1px; }
.coords span:nth-child(odd).file, .coords .rank:nth-child(even) { color: var(--light); }
.coords span:nth-child(even).file, .coords .rank:nth-child(odd) { color: var(--dark); }
.promo { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); z-index: 10; }
.promo-col { position: absolute; width: 12.5%; display: flex; flex-direction: column; }
.promo-col.top { top: 0; }
.promo-col.bottom { bottom: 0; flex-direction: column-reverse; }
.promo-col button { padding: 0; border: 0; border-radius: 50%; background: #e8eef6; aspect-ratio: 1; display: grid; place-items: center; }
.promo-col button:hover { background: var(--accent); }
.promo-col img { width: 85%; }

/* Effects canvas: same engine as the overlay, over the whole page. */
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }
#watch-search input { flex: 1 1 260px; min-width: 0; }

[hidden] { display: none !important; }

/* ---------- analysis board ---------- */
.an-evalbar { padding: 1cqw 2cqw; gap: 2cqw; }
.an-bar { position: relative; flex: 1; height: 2.6cqw; min-height: 10px; border-radius: 99px; background: #f2f2f2; overflow: hidden; }
.an-fill { position: absolute; top: 0; bottom: 0; left: 0; width: 50%; background: #2a2f3a; transition: width 0.4s ease; }
.an-score { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: max(13px, 3.2cqw); color: var(--text); white-space: nowrap; }
.an-turn .an-variant { font-size: max(12px, 2.8cqw); }
/* the game screen's sidebar rows (auto auto 1fr) don't fit this panel: stack everything from the top */
.side.an-side { grid-template-rows: none; grid-auto-rows: max-content; align-content: start; overflow-y: auto; overflow-x: hidden; max-height: calc(100vh - 90px); padding-right: 4px; }
.an-side > * { min-width: 0; }
.an-side .status-line .info { text-transform: none; }
.an-fen input { flex: 1 1 200px; min-width: 0; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.an-engine { display: grid; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.an-engine-head { display: flex; gap: 10px; align-items: center; }
.an-engine-status { font-size: 12px; }
.an-line { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; padding: 2px 4px; border-radius: 6px; }
.an-line:hover { background: #1f2838; }
.an-line b { display: inline-block; min-width: 6ch; color: #fff; }
.an-moves span[data-go] { cursor: pointer; border-radius: 4px; padding: 0 3px; }
.an-moves span[data-go]:hover { background: #1f2838; }
.an-moves span.cur { background: #2b5fb8; color: #fff; }
.an-presets summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
.an-preset-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.an-preset-grid button { text-align: left; }
.stream-panel hr { border: 0; border-top: 1px solid rgba(255, 255, 255, 0.1); margin: 12px 0; }
.stream-panel { max-height: calc(100vh - 80px); overflow-y: auto; overflow-x: hidden; box-sizing: border-box; }
.stream-panel details.tally { margin-top: 10px; font-size: 13px; }
.stream-panel details.tally summary { cursor: pointer; color: var(--text); }
.stream-panel details.tally table { width: 100%; table-layout: fixed; border-collapse: collapse; margin-top: 6px; }
.stream-panel details.tally td, .stream-panel details.tally th { text-align: left; padding: 2px 4px; border-top: 1px solid rgba(255, 255, 255, 0.06); font-weight: 400; }
.stream-panel details.tally th { color: var(--muted); font-size: 12px; }
.stream-panel .tier.common { color: #7be08a; } .stream-panel .tier.medium { color: #ffd36b; } .stream-panel .tier.rare { color: #ff8a9a; }

/* ---------- Tactic Bingo dock ---------- */
.bingo-dock { width: 100%; aspect-ratio: 600 / 680; align-self: start; min-width: 0; }
.bingo-dock iframe { width: 100%; height: 100%; border: 0; display: block; background: transparent; color-scheme: normal; }
.bingo-toggle { justify-self: stretch; align-self: start; width: 100%; padding: 11px 16px; font-size: 15px; font-weight: 600; }

/* ---------- material difference next to the names ---------- */
.who .mat { display: inline-flex; align-items: center; align-self: center; gap: 0.25em; flex-shrink: 0; }
.who .mat-group { display: inline-flex; }
.who .mat img { width: 1.05em; height: 1.05em; filter: drop-shadow(0 0 1px rgba(255, 255, 255, 0.35)); }
.who .mat-group img + img { margin-left: -0.55em; }
.who .mat b { color: #b6c2d2; font-weight: 700; font-size: 0.9em; margin-left: 0.15em; }
