:root {
  --paper: #e6eaee;
  --surface: #f4f6f8;
  --ink: #1c2433;
  --muted: #5b6779;
  --line: #c6ced8;
  --sq-light: #d4dbe3;
  --sq-dark: #6f8399;
  --signal: #f0be2e;
  --alert: #c8372d;
  --clock-face: #1c2433;
  --clock-text: #e9edf2;
  --focus: #2f6fd6;
  --better: #1a9d6c;
  --piece-white: #fbfbf8;
  --piece-black: #1a1f2a;
  --cap-b-rim: none; /* light outline for black captured pieces on dark backgrounds */
  --font: 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --pieces: 'Noto Sans Symbols 2', 'Segoe UI Symbol', 'Apple Symbols', 'DejaVu Sans', serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --cap-b-rim: drop-shadow(0 0 1.2px #dfe7f0) drop-shadow(0 0 1.2px #dfe7f0) drop-shadow(0 0 .6px #dfe7f0);
    --paper: #141922;
    --surface: #1c2330;
    --ink: #e4e9f0;
    --muted: #97a3b4;
    --line: #2e3849;
    --sq-light: #a7b4c3;
    --sq-dark: #55687f;
    --clock-face: #0c1017;
    --clock-text: #e4e9f0;
    --focus: #7fb0ff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --cap-b-rim: drop-shadow(0 0 1.2px #dfe7f0) drop-shadow(0 0 1.2px #dfe7f0) drop-shadow(0 0 .6px #dfe7f0);
  --paper: #141922; --surface: #1c2330; --ink: #e4e9f0; --muted: #97a3b4; --line: #2e3849;
  --sq-light: #a7b4c3; --sq-dark: #55687f; --clock-face: #0c1017; --clock-text: #e4e9f0; --focus: #7fb0ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
}
[hidden] { display: none !important; }
a { color: inherit; text-underline-offset: 3px; }
h1, h2 { font-stretch: 112%; line-height: 1.15; margin: 0; }
h2 { font-size: 1.05rem; font-weight: 700; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
}
.brand { white-space: nowrap; display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 800; font-stretch: 118%; font-size: 1.1rem; }
.brand-mark {
  width: 22px; height: 22px; display: inline-block;
  background: conic-gradient(var(--ink) 0 25%, var(--signal) 0 50%, var(--ink) 0 75%, var(--signal) 0);
}
.app-version { font-weight: 500; font-stretch: 100%; font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.topbar-room { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.room-label { color: var(--muted); font-size: .9rem; }
.room-code {
  border: 1.5px solid var(--ink); background: transparent; padding: 2px 10px; cursor: pointer;
  font-weight: 800; font-stretch: 125%; letter-spacing: .08em; font-size: 1rem;
}
.room-code:hover { background: var(--ink); color: var(--paper); }
.conn { font-size: .85rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.conn::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.conn[data-state="live"]::before { background: #2f9e5b; }
.conn[data-state="polling"]::before { background: #2f9e5b; box-shadow: 0 0 0 2px color-mix(in srgb, #2f9e5b 35%, transparent); }
.conn[data-state="reconnecting"]::before, .conn[data-state="connecting"]::before { background: var(--signal); }

/* ---------- shared bits ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); padding: 18px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1.5px solid var(--ink); background: transparent; padding: 8px 14px; cursor: pointer;
  font-weight: 650; text-decoration: none; line-height: 1.2; min-height: 40px;
}
.btn:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover { background: color-mix(in srgb, var(--ink) 85%, var(--paper)); }
.btn.big { min-height: 48px; font-size: 1.05rem; width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.danger { border-color: var(--alert); color: var(--alert); }
.link-btn { background: none; border: 0; padding: 2px 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; color: var(--muted); font-size: .9rem; }
.link-btn:hover { color: var(--ink); }
.actions-row { display: flex; flex-wrap: wrap; gap: 8px; }
.form-error { color: var(--alert); margin: 8px 0 0; font-size: .92rem; min-height: 0; }
.form-error:empty { display: none; }

/* Relay choice in the lobby: ntfy.sh, or your own (see relay/README.md). */
.relay-box { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 10px; }
.relay-box summary { cursor: pointer; list-style: none; font-size: .92rem; font-weight: 650; color: var(--muted); }
.relay-box summary::-webkit-details-marker { display: none; }
.relay-box summary::before { content: '▸'; display: inline-block; width: 1em; }
.relay-box[open] summary::before { content: '▾'; }
.relay-box .hint { margin-top: 8px; }
.relay-fields { display: grid; gap: 10px; margin-top: 12px; }
.relay-fields .field { margin: 0; }
.relay-status { margin: 0; font-size: .9rem; color: var(--muted); }
.relay-status:empty { display: none; }
.relay-status.ok { color: #2f9e5b; }
.relay-status.bad { color: var(--alert); }
.relay-fields input.mono { font-family: ui-monospace, 'Cascadia Mono', Menlo, Consolas, monospace; font-size: .92rem; letter-spacing: .02em; }
.hint { color: var(--muted); font-size: .9rem; margin: 12px 0 0; }
.tc-hint { margin: 8px 0 0; font-size: .85rem; }
.code-inline { font-stretch: 125%; letter-spacing: .06em; }

.field { display: block; border: 0; padding: 0; margin: 0 0 18px; }
.field > span, .field legend { display: block; font-weight: 650; margin-bottom: 6px; padding: 0; }
.field legend small { font-weight: 400; color: var(--muted); margin-left: 6px; }
input[type="text"], input:not([type]), input[type="number"], input[type="url"], input[type="password"] {
  width: 100%; border: 1.5px solid var(--line); background: var(--paper); padding: 9px 11px; min-height: 42px;
}
input:not([type]):focus, input[type="number"]:focus, input[type="url"]:focus, input[type="password"]:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 35%, transparent); }

.seg, .tc-grid { display: grid; gap: 6px; }
.seg { grid-template-columns: repeat(3, 1fr); }
.tc-grid { grid-template-columns: repeat(4, 1fr); }
.seg label, .tc-grid label { position: relative; }
.seg input, .tc-grid input { position: absolute; opacity: 0; inset: 0; margin: 0; pointer-events: none; }
.seg span, .tc-grid span {
  display: flex; align-items: center; justify-content: center; min-height: 42px; padding: 6px;
  border: 1.5px solid var(--line); cursor: pointer; font-weight: 650; font-variant-numeric: tabular-nums; text-align: center;
}
.seg input:checked + span, .tc-grid input:checked + span { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.seg input:focus-visible + span, .tc-grid input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.tc-grid span { flex-direction: column; line-height: 1.2; }
.tc-grid span small { font-weight: 400; font-size: .75rem; opacity: .8; }
.tc-custom { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.tc-custom span { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 4px; }

/* ---------- lobby ---------- */
.lobby { max-width: 1040px; margin: 0 auto; padding: 48px 20px 64px; }
.lobby-intro { max-width: 46rem; margin-bottom: 36px; }
.lobby-intro h1 { font-size: clamp(2rem, 5vw, 3.3rem); font-weight: 800; font-stretch: 118%; letter-spacing: -.01em; }
.lobby-intro p { color: var(--muted); font-size: 1.08rem; max-width: 40rem; margin: 16px 0 0; }
.lobby-forms { display: grid; grid-template-columns: 1.5fr 1fr; gap: 20px; align-items: start; }
.lobby-forms h2 { margin-bottom: 16px; font-size: 1.25rem; }

/* ---------- room ---------- */
.room { padding: 20px; }
.loading { padding: 64px 0; text-align: center; color: var(--muted); }
.missing { max-width: 34rem; margin: 48px auto; }
.missing h2 { font-size: 1.4rem; margin-bottom: 8px; }

.game {
  display: grid; gap: 24px; max-width: 1240px; margin: 0 auto;
  grid-template-columns: minmax(0, min(78vh, 680px)) minmax(300px, 1fr);
  align-items: start;
}
.side-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.board-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

/* player bars with the chess-clock faces — the loud part of the page */
.player-bar { display: flex; align-items: stretch; justify-content: space-between; gap: 12px; }
.pb-who { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.pb-name { font-weight: 750; font-stretch: 110%; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pb-meta { color: var(--muted); font-size: .88rem; display: flex; align-items: center; gap: 6px; }
.pb-swatch { width: 12px; height: 12px; border: 1.5px solid var(--ink); display: inline-block; }
.pb-swatch.w { background: var(--piece-white); }
.pb-swatch.b { background: var(--piece-black); }
.clock {
  position: relative; background: var(--clock-face); color: var(--clock-text);
  font-weight: 800; font-stretch: 125%; font-variant-numeric: tabular-nums; letter-spacing: .02em;
  font-size: clamp(1.6rem, 3.6vw, 2.4rem); line-height: 1; padding: 10px 16px 10px 22px; min-width: 7.2ch; text-align: right;
  opacity: .55; transition: opacity .15s;
}
.clock::before { /* the flag */
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 8px; background: transparent;
}
.clock.running { opacity: 1; }
.clock.running::before { background: var(--signal); }
.clock.low.running { color: #ffb3ab; }
.clock.low.running::before { background: var(--alert); }
.clock.flagged { opacity: 1; color: #ffb3ab; }
.clock.untimed { font-size: 1rem; font-stretch: 100%; padding: 12px 14px; opacity: .8; }

/* ---------- board themes ---------- */
:root[data-board="midnight"] { --sq-light: #3d4d5a; --sq-dark: #283641; }
:root[data-board="sand"] { --sq-light: #ecdfc6; --sq-dark: #b78e66; }
:root[data-board="midnight"] .board { border-color: #141b22; }
/* Dark pieces get a light rim on the dark board so they don't sink into it. */
:root[data-board="midnight"] .soft.b { --pc-fill: #2b3440; --pc-side: #1a2029; --pc-top: #3e4a5a; --pc-edge: #a3b2c3; --pc-hi: #c0ccd8; }
:root[data-board="midnight"] .piece.b, :root[data-board="midnight"] .drag-ghost.b { filter: drop-shadow(0 0 1px #a3b2c3) drop-shadow(0 0 1px #a3b2c3); }

/* ---------- "Soft" piece set (SVG) ---------- */
.soft { --pc-fill: #eef2f6; --pc-side: #aebbc8; --pc-top: #ffffff; --pc-edge: #56636f; --pc-hi: #ffffff; }
.soft.b { --pc-fill: #4f5d6d; --pc-side: #2f3945; --pc-top: #6d7d91; --pc-edge: #151b23; --pc-hi: #9fb0c3; }
/* The box itself is sized (not just the SVG inside it) so flex/grid centering applies. */
.piece.soft, .drag-ghost.soft { width: 1.14em; height: 1.14em; }
.cap-piece.soft { width: 1.05em; height: 1.05em; }
.soft-svg { display: block; width: 100%; height: 100%; overflow: visible; }
.soft-svg .f, .soft-svg .s, .soft-svg .t { stroke: var(--pc-edge); stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.soft-svg .f { fill: var(--pc-fill); }
.soft-svg .s { fill: var(--pc-side); }
.soft-svg .t { fill: var(--pc-top); }
.soft-svg .sh { fill: #0d1520; opacity: .16; }
.soft-svg .hi { fill: var(--pc-hi); opacity: .85; }
.soft-svg .hl { fill: none; stroke: var(--pc-hi); stroke-width: 2.6; stroke-linecap: round; opacity: .75; }
.soft-svg .ln { fill: none; stroke: var(--pc-edge); stroke-width: 2.6; stroke-linecap: round; }
.soft-svg .e { fill: var(--pc-edge); }
.soft-svg .gs { fill: #000; opacity: .18; }
.soft.b .soft-svg .sh { opacity: .28; }
.soft.b .soft-svg .hl { opacity: .55; }

/* ---------- Style menu ---------- */
.topbar-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: flex-end; }
.style-menu { position: relative; }
.style-menu summary {
  list-style: none; cursor: pointer; border: 1.5px solid var(--line); padding: 3px 10px; font-weight: 650; font-size: .92rem;
}
.style-menu summary::-webkit-details-marker { display: none; }
.style-lang { color: var(--muted); font-size: .8em; font-weight: 650; letter-spacing: .03em; }
.style-menu summary::after { content: ' ▾'; color: var(--muted); }
.style-menu[open] summary { border-color: var(--ink); }
/* One grid for the whole panel: the label column takes the widest label (it's translated), the
   selects fill what's left and never push past the edge (a select's natural width is its longest
   option, so it needs min-width: 0 and a bounded track). */
.style-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; background: var(--surface); border: 1.5px solid var(--ink);
  padding: 12px; display: grid; grid-template-columns: max-content minmax(0, 1fr); align-items: center; gap: 10px 10px;
  width: 320px; max-width: calc(100vw - 24px); box-sizing: border-box;
  box-shadow: 0 6px 0 color-mix(in srgb, var(--ink) 12%, transparent);
}
.style-pop label { display: contents; font-weight: 650; font-size: .92rem; }
.style-pop select {
  width: 100%; min-width: 0; min-height: 36px; border: 1.5px solid var(--line); background: var(--paper); font: inherit; color: inherit;
  padding: 0 6px; text-overflow: ellipsis;
}
.style-pop .look-voice-note, .style-pop .look-preview { grid-column: 1 / -1; }
.look-preview { display: grid; grid-template-columns: repeat(6, 1fr); border: 1.5px solid var(--ink); }
.lp-sq { aspect-ratio: 1; background: var(--sq-light); display: grid; place-items: center; container-type: size; }
.lp-sq.dark { background: var(--sq-dark); }

/* captured pieces, between the name and the clock */
.pb-captures {
  flex: 1; min-width: 0; display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap;
  gap: 2px 6px; padding: 0 4px; align-self: center;
}
.cap-group { display: inline-flex; }
.cap-group .cap-piece + .cap-piece { margin-left: -0.42em; } /* overlap duplicates, like a scoresheet */
.cap-piece {
  font-family: var(--pieces); line-height: 1; font-size: clamp(16px, 2.2vw, 22px);
  width: 1em; height: 1em; display: inline-grid; place-items: center;
}
.cap-piece.b { filter: var(--cap-b-rim); }
.cap-lead { font-weight: 750; font-variant-numeric: tabular-nums; color: var(--muted); margin-left: 2px; font-size: .95rem; }

/* board */
.board-row { display: flex; align-items: stretch; gap: 8px; }
.board-wrap { position: relative; flex: 1 1 auto; min-width: 0; aspect-ratio: 1; }
/* advantage bar: White's share grows from White's edge, the number sits at the leading end */
.eval-bar {
  position: relative; flex: 0 0 22px; width: 22px; border: 2px solid var(--ink); background: var(--piece-black);
  overflow: hidden; border-radius: 3px; container-type: size;
}
.eval-bar[hidden] { display: none; }
.eval-white { position: absolute; left: 0; right: 0; bottom: 0; height: 50%; background: var(--piece-white); transition: height .45s cubic-bezier(.25,.75,.35,1); }
.eval-bar::after { /* the midline */
  content: ''; position: absolute; left: 0; right: 0; top: 50%; height: 2px; margin-top: -1px; background: var(--alert); opacity: .7; pointer-events: none;
}
.eval-val {
  position: absolute; left: 0; right: 0; text-align: center; font-size: 9px; font-weight: 800; line-height: 1; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; pointer-events: none; padding: 3px 0;
}
.eval-val.at-bottom { bottom: 0; }
.eval-val.at-top { top: 0; }
.eval-val.on-white { color: var(--piece-black); }
.eval-val.on-black { color: var(--piece-white); }
.eval-bar.mate .eval-val { font-size: 8.5px; }
@media (max-width: 520px) { .board-row { gap: 6px; } .eval-bar { flex-basis: 18px; width: 18px; } .eval-val { font-size: 8px; } }
.board {
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  width: 100%; height: 100%; border: 2px solid var(--ink); user-select: none; touch-action: none;
}
.sq {
  position: relative; border: 0; padding: 0; margin: 0; cursor: default; background: var(--sq-light);
  display: flex; align-items: center; justify-content: center; container-type: size;
}
.sq.dark { background: var(--sq-dark); }
.sq.last::after, .sq.sel::after { content: ''; position: absolute; inset: 0; background: var(--signal); opacity: .5; pointer-events: none; }
.sq.sel::after { opacity: .75; }
.sq.check { background-image: radial-gradient(circle, var(--alert) 0 30%, color-mix(in srgb, var(--alert) 45%, transparent) 55%, transparent 72%); }
.sq.target::before {
  content: ''; position: absolute; width: 28%; height: 28%; border-radius: 50%;
  background: color-mix(in srgb, var(--ink) 38%, transparent); z-index: 2; pointer-events: none;
}
.sq.target.capture::before { width: 92%; height: 92%; background: transparent; border: 5px solid color-mix(in srgb, var(--ink) 38%, transparent); }
.sq.movable { cursor: grab; }
.sq.target { cursor: pointer; }
.sq.hover-target { box-shadow: inset 0 0 0 4px var(--signal); }
.coord { position: absolute; font-size: clamp(8px, 1.4vw, 12px); font-weight: 700; pointer-events: none; opacity: .85; z-index: 3; }
.coord.file { right: 4%; bottom: 1%; }
.coord.rank { left: 5%; top: 2%; }
.sq .coord { color: var(--sq-dark); }
.sq.dark .coord { color: var(--sq-light); }

.piece {
  position: relative; z-index: 1; font-family: var(--pieces); line-height: 1; pointer-events: none;
  font-size: 80cqh; width: 1em; height: 1em; display: inline-grid; place-items: center;
}
.piece > span, .drag-ghost > span, .cap-piece > span { grid-area: 1 / 1; }
.piece > span::before, .drag-ghost > span::before, .cap-piece > span::before { content: attr(data-g); }
.piece.w .fill, .cap-piece.w .fill { color: var(--piece-white); }
.cap-piece.w .outline, .cap-piece.b .fill, .cap-piece.b .outline { color: var(--piece-black); }
.piece.w .outline { color: var(--piece-black); }
.piece.b .fill { color: var(--piece-black); }
.piece.b .outline { color: var(--piece-black); }
.drag-ghost {
  position: fixed; z-index: 50; pointer-events: none; transform: translate(-50%, -50%);
  font-family: var(--pieces); line-height: 1; display: inline-grid; place-items: center;
}
.drag-ghost > span { grid-area: 1 / 1; }
.sq.dragging .piece { opacity: .25; }
.piece.cap-ghost { position: absolute; z-index: 0; }

.promo {
  position: absolute; inset: 0; background: rgba(10, 14, 20, .78);
  display: flex; align-items: center; justify-content: center; gap: 3%; z-index: 20;
}
/* The choices sit on a light tile in every theme and board style, so both black and white
   pieces stand out (black pieces vanished on the dark-mode surface). */
.promo button {
  width: 20%; aspect-ratio: 1; background: #eef1f5; border: 3px solid #fff; border-radius: 6px; cursor: pointer;
  container-type: size; display: grid; place-items: center; box-shadow: 0 4px 14px rgba(0, 0, 0, .45);
  transition: transform .08s, background .08s;
}
.promo button:hover, .promo button:focus-visible { background: var(--signal); border-color: var(--signal); transform: scale(1.06); outline: none; }
.promo .piece { filter: none; }
.banner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 15;
  background: var(--ink); color: var(--paper); padding: 16px 24px; text-align: center; min-width: 60%;
  box-shadow: 0 0 0 6px var(--signal);
}
.banner strong { display: block; font-size: 1.6rem; font-stretch: 120%; font-weight: 800; }

/* analysis: arrows, badges, tags */
.arrows { position: absolute; inset: 2px; width: calc(100% - 4px); height: calc(100% - 4px); pointer-events: none; z-index: 6; }
.arrow-better { stroke: var(--better); stroke-width: .17; stroke-linecap: round; opacity: .85; }
.arrowhead { fill: var(--better); }
.badge {
  position: absolute; top: -6%; right: -6%; z-index: 7; min-width: 42%; height: 42%; padding: 0 4%;
  border-radius: 999px; display: grid; place-items: center; font-size: 26cqh; font-weight: 800; line-height: 1;
  color: #fff; background: var(--tag); box-shadow: 0 0 0 2px var(--surface);
}
.tag-brilliant { --tag: #1a9d97; } .tag-great { --tag: #4f7fb0; } .tag-best { --tag: #5d9b3c; }
.tag-good { --tag: #78955e; } .tag-book { --tag: #9a7a55; } .tag-interesting { --tag: #8a6fc2; }
.tag-inaccuracy { --tag: #c99a13; } .tag-mistake { --tag: #dd7a1f; } .tag-blunder { --tag: #c8372d; }
.tag-missed-win { --tag: #b0457a; } .tag-better-available { --tag: #3f7fd0; } .tag-note { --tag: #5b6779; }
.sym { color: var(--tag); font-weight: 800; margin-left: 3px; font-size: .9em; }

.banner-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; align-items: center; }
.btn.on-dark { border-color: var(--paper); color: var(--paper); min-height: 36px; padding: 6px 12px; }
.btn.on-dark:hover { background: color-mix(in srgb, var(--paper) 15%, transparent); }
.btn.on-dark.primary-ish { background: var(--signal); border-color: var(--signal); color: #1c2433; }

.review-panel { border-left: 6px solid var(--better); }
.review-panel .panel-head { margin-bottom: 6px; }
.rv-where { font-weight: 750; font-stretch: 110%; font-size: 1.15rem; margin: 0 0 8px; }
.rv-note { border-top: 1px solid var(--line); padding-top: 8px; margin-bottom: 8px; }
.rv-note p { margin: 4px 0; }
.rv-tag { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; color: #fff; background: var(--tag); font-weight: 650; font-size: .88rem; }
.rv-better strong { color: var(--better); }
.rv-by { color: var(--muted); font-size: .88rem; }
.rv-empty { color: var(--muted); }
.rv-summary { background: var(--paper); border: 1px solid var(--line); padding: 10px 12px; margin: 8px 0; }
.rv-summary h3 { margin: 0 0 4px; font-size: .95rem; }
.rv-summary p { margin: 0; }
.rv-nav { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.rv-nav .nav { min-width: 44px; font-size: 1rem; }
.sheet button.m { font: inherit; font-weight: 650; text-align: left; border: 0; background: none; cursor: pointer; color: inherit; }
.sheet button.m:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.sheet button.m.latest { background: var(--signal); color: #1c2433; }

/* opening name chip (above the move list) and opening panel */
.opening-chip {
  display: flex; align-items: center; gap: 8px; width: 100%; margin: 0 0 10px; padding: 6px 10px;
  border: 1.5px solid var(--line); background: var(--paper); color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.opening-chip:hover { border-color: var(--ink); }
.opening-chip .eco, .op-title .eco {
  flex: 0 0 auto; font-weight: 800; font-size: .78rem; letter-spacing: .02em; padding: 1px 6px;
  background: var(--ink); color: var(--paper); font-variant-numeric: tabular-nums;
}
.opening-chip .oname { flex: 1; min-width: 0; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opening-chip .more { color: var(--muted); font-size: 1.2rem; line-height: 1; }

.opening-panel { border-left: 6px solid var(--ink); }
.op-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.op-title { display: flex; align-items: baseline; gap: 8px; min-width: 0; flex-wrap: wrap; }
.op-title h2 { font-size: 1.05rem; }
.op-nav { display: flex; }
.mini-board {
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); aspect-ratio: 1;
  width: 100%; max-width: 320px; margin: 0 auto 10px; border: 2px solid var(--ink);
}
.mini-board .sq { cursor: default; }
.op-line { display: flex; flex-wrap: wrap; gap: 2px 4px; margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.op-move { border: 0; background: none; padding: 2px 5px; font: inherit; font-weight: 650; color: inherit; cursor: pointer; }
.op-move:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.op-move.current { background: var(--signal); color: #1c2433; }
.op-where { color: var(--muted); font-size: .9rem; margin: 0 0 10px; }
.op-primer p, .op-note p { margin: 0 0 8px; }
.op-primer h3, .op-note h3 { font-size: .92rem; margin: 10px 0 2px; }
.op-note { border-top: 1px solid var(--line); margin-top: 8px; }
.op-credit { color: var(--muted); font-size: .8rem; margin: 10px 0; }
.op-close { width: 100%; min-height: 38px; }

/* analysis progress (requester side) */
.an-status { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-weight: 600; font-size: .93rem; }
.an-status.waiting { color: var(--muted); }
.an-status.done { color: var(--better); }
.banner .an-status { justify-content: center; margin: 8px 0 0; color: var(--paper); font-weight: 500; }
.banner .an-status.done { color: #7fe0b4; }
.throbber {
  flex: 0 0 auto; width: 15px; height: 15px; border-radius: 50%;
  border: 2.5px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor;
  animation: an-spin .8s linear infinite;
}
.throbber.idle { animation-duration: 2.4s; opacity: .7; }
.an-check { flex: 0 0 auto; display: grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; background: var(--better); color: #fff; font-size: .7rem; line-height: 1; }
.an-done { align-self: flex-start; }
@keyframes an-spin { to { transform: rotate(360deg); } }

/* ---------- puzzle page ---------- */
.pz-turn { display: flex; align-items: center; gap: 8px; font-weight: 750; font-stretch: 110%; font-size: 1.1rem; min-height: 32px; }
.pz-kicker { margin: 0 0 4px; color: var(--muted); font-size: .9rem; }
.pz-title { font-size: 1.45rem; font-weight: 800; font-stretch: 115%; margin-bottom: 8px; }
.pz-intro { margin: 0 0 14px; }
.pz-feedback { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.fb { margin: 0; padding: 8px 10px; border-left: 4px solid var(--line); background: var(--paper); font-size: .95rem; }
.fb.good { border-color: var(--better); }
.fb.bad { border-color: var(--alert); }
.fb.hint { border-color: var(--signal); }
.fb.reply { border-color: var(--muted); }
.fb.info { color: var(--muted); }
.sq.wrong::after { content: ''; position: absolute; inset: 0; background: var(--alert); opacity: .45; pointer-events: none; }
.pz-done { border-left: 6px solid var(--better); }
.pz-done h2 { font-size: 1.3rem; margin-bottom: 4px; }
.pz-done h3 { font-size: .95rem; margin: 14px 0 4px; }
.pz-stats { margin: 0; color: var(--muted); }
.pz-conclusion p { margin: 0; }
.pz-line { margin: 0 0 12px; padding-left: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: .93rem; }
.pz-line li.theirs { color: var(--muted); }

/* arrow and highlight colors (puzzles and lessons) */
.arrow-red { stroke: var(--alert); } .arrowhead-red { fill: var(--alert); }
.arrow-blue { stroke: #3f7fd0; } .arrowhead-blue { fill: #3f7fd0; }
.arrow-yellow { stroke: #e0a800; } .arrowhead-yellow { fill: #e0a800; }
.sq.hl::after { content: ''; position: absolute; inset: 0; pointer-events: none; opacity: .42; background: var(--hl); }
.sq.hl-green { --hl: var(--better); } .sq.hl-red { --hl: var(--alert); } .sq.hl-blue { --hl: #3f7fd0; } .sq.hl-yellow { --hl: #e0a800; }

/* "go on" buttons (puzzle Continue, lesson Next): brand yellow with a slow, soft pulse */
.btn.go { background: var(--signal); border-color: var(--signal); color: #1c2433; font-weight: 750; animation: go-pulse 2.2s ease-out infinite; }
.btn.go:hover { background: color-mix(in srgb, var(--signal) 85%, #fff); }
.btn.go:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn.wide { width: 100%; min-height: 46px; justify-content: center; }
@keyframes go-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--signal) 70%, transparent); }
  70%, 100% { box-shadow: 0 0 0 9px color-mix(in srgb, var(--signal) 0%, transparent); }
}
/* Retry after a wrong move: same place and size, but quiet slate instead of gold */
.btn.retry { background: color-mix(in srgb, var(--ink) 7%, var(--surface)); border-color: var(--ink); color: var(--ink); font-weight: 750; animation: retry-pulse 2.6s ease-out infinite; }
.btn.retry:hover { background: color-mix(in srgb, var(--ink) 13%, var(--surface)); }
.btn.retry span { font-size: 1.1em; line-height: 1; }
@keyframes retry-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--muted) 55%, transparent); }
  70%, 100% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--muted) 0%, transparent); }
}
.pz-progress:empty { display: none; }
.pz-progress { margin: 0 0 14px; }
.ls-inline-next { margin: 16px 0 0; }

/* ---------- lesson page ---------- */
.ls-slide-head { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; margin-bottom: 4px; }
.ls-slide-head .pz-kicker { margin: 0; }
.ls-voice { display: flex; align-items: center; gap: 10px; }
.ls-voice[hidden] { display: none; }
.ls-listen { min-height: 32px; padding: 4px 10px; font-size: .9rem; }
.ls-listen.speaking { background: var(--ink); color: var(--paper); }
.rv-voice { margin: 0 0 10px; }
.ls-voice { flex-wrap: wrap; }
.ls-voice-status { font-size: .85rem; color: var(--muted); }
.ls-voice-status:empty { display: none; }
.look-voice-note { margin: -4px 0 0; font-size: .82rem; color: var(--muted); max-width: 16rem; }
.look-voice-note:empty { display: none; }
.ls-auto { display: inline-flex; align-items: center; gap: 5px; font-size: .88rem; color: var(--muted); cursor: pointer; }
.ls-nav { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.ls-nav .btn { min-width: 96px; }
.ls-dots { flex: 1; display: flex; gap: 4px; align-items: center; min-width: 0; }
.ls-dot { flex: 1; height: 8px; min-width: 4px; border: 0; padding: 0; background: var(--line); cursor: pointer; }
.ls-dot.seen { background: color-mix(in srgb, var(--better) 45%, var(--line)); }
.ls-dot.task { box-shadow: inset 0 -3px 0 var(--signal); }
.ls-dot.current { background: var(--ink); }
.ls-dot:disabled { cursor: not-allowed; opacity: .55; }
.ls-count { color: var(--muted); font-size: .9rem; white-space: nowrap; }
.ls-primer { border-left: 6px solid var(--signal); }
.ls-primer > summary { cursor: pointer; font-weight: 750; font-stretch: 110%; }
.ls-primer[open] > summary { margin-bottom: 8px; }
.rich p { margin: 0 0 10px; }
.rich p:last-child, .rich ul:last-child { margin-bottom: 0; }
.rich ul { margin: 0 0 10px; padding-left: 20px; }
.rich li { margin-bottom: 3px; }
.rich h4 { margin: 12px 0 6px; font-size: 1rem; font-weight: 750; }
.rich code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em; background: var(--paper); padding: 0 4px; }
.ls-slide-title { font-size: 1.3rem; font-weight: 800; font-stretch: 112%; margin-bottom: 8px; }
.ls-task { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.ls-task h3 { margin: 0 0 6px; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.ls-task-prompt { margin: 0 0 10px; }
.ls-done-note { margin: 0 0 12px; padding: 8px 10px; border-left: 4px solid var(--better); background: var(--paper); }
.ls-end { border-left: 6px solid var(--better); }
.ls-end h2 { font-size: 1.3rem; margin-bottom: 6px; }

/* side column */
.status-line { margin: 0 0 12px; font-weight: 650; font-size: 1.05rem; }
.status-line .your-move { background: var(--signal); color: #1c2433; padding: 1px 6px; }
.move-form label { display: block; font-weight: 650; margin-bottom: 6px; }
.move-row { display: flex; gap: 8px; }
.move-row input { flex: 1; min-width: 0; font-weight: 650; font-stretch: 110%; }
.move-form { margin-bottom: 12px; }
.move-note { margin: 6px 0 0; color: var(--muted); font-size: .92rem; }
.move-note:empty { display: none; }
.rv-ask { background: color-mix(in srgb, var(--signal) 22%, transparent); border-left: 4px solid var(--signal); padding: 8px 10px; margin: 0 0 10px; }
.rv-form { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.rv-form h3 { margin: 0; font-size: .95rem; }
.rv-row { display: flex; gap: 8px; flex-wrap: wrap; }
.rv-row select { flex: 0 0 auto; min-height: 42px; border: 1.5px solid var(--line); background: var(--paper); padding: 0 8px; font: inherit; color: inherit; }
.rv-row input { flex: 1 1 140px; }
.rv-row input.rv-eval { flex: 0 1 9rem; }
.rv-form textarea { width: 100%; border: 1.5px solid var(--line); background: var(--paper); padding: 9px 11px; font: inherit; color: inherit; resize: vertical; }
.rv-form .btn { align-self: flex-start; }
.draw-offer { border: 1.5px solid var(--signal); padding: 10px 12px; margin-bottom: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.draw-offer p { margin: 0; flex: 1 1 100%; }

.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.mini-actions { display: flex; gap: 12px; }
.sheet {
  list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; position: relative;
  display: grid; grid-template-columns: 2.6rem 1fr 1fr; font-variant-numeric: tabular-nums;
}
.sheet li { display: contents; }
.sheet .n { color: var(--muted); padding: 3px 0; }
.sheet .m { padding: 3px 6px; font-weight: 650; }
.sheet .m.latest { background: var(--signal); color: #1c2433; }
.sheet .empty { grid-column: 1 / -1; color: var(--muted); }
.sheet .res { grid-column: 1 / -1; font-weight: 800; padding-top: 6px; }

.feed { list-style: none; margin: 10px 0 12px; padding: 0; max-height: 220px; overflow-y: auto; font-size: .93rem; }
.feed li { padding: 4px 0; border-bottom: 1px solid var(--line); }
.feed li.system { color: var(--muted); }
.feed li b { font-weight: 750; }
.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; min-width: 0; }

details.panel summary { cursor: pointer; font-weight: 700; }
details.panel[open] summary { margin-bottom: 10px; }
.text-state pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: .85rem; line-height: 1.45; font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace; }
.agent-help p, .agent-help li { font-size: .93rem; }
.agent-help pre, .invite-panel pre {
  background: var(--paper); border: 1px solid var(--line); padding: 10px; overflow-x: auto; font-size: .8rem;
  font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-all;
}
.invite-panel h2, .seat-panel h2 { font-size: 1.2rem; margin-bottom: 8px; }
.invite-panel p, .seat-panel p { margin: 0 0 12px; }
.share-link { display: flex; gap: 8px; margin-bottom: 12px; }
.share-link input { flex: 1; min-width: 0; font-size: .9rem; }
.invite-panel .actions-row { margin-top: 4px; }
.seat-panel .field { margin-bottom: 12px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  background: var(--ink); color: var(--paper); padding: 10px 16px; font-weight: 600; max-width: calc(100vw - 32px);
}

/* Review panel: compact on stacked (mobile/tablet) layouts. */
.rv-close-bottom { display: none; }
.rv-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rv-top .rv-where { margin-bottom: 8px; }
.rv-mininav { display: none; gap: 4px; flex: 0 0 auto; }
.rv-mininav.op-nav { display: flex; }
.rv-mininav .mini {
  width: 32px; height: 28px; padding: 0; border: 1.5px solid var(--ink); background: transparent; color: inherit;
  font: inherit; font-size: .8rem; line-height: 1; cursor: pointer; display: grid; place-items: center;
}
.rv-mininav .mini:last-child { font-size: 1.05rem; font-weight: 800; }
.rv-mininav .mini:disabled { opacity: .35; cursor: default; }
.rv-mininav .mini:not(:disabled):hover { background: color-mix(in srgb, var(--ink) 10%, transparent); }
.pb-swatch-inline { display: none; }
.nav-end { display: contents; }
@media (max-width: 900px) {
  .review-panel { padding: 12px 14px; }
  .review-panel .rv-head, .review-panel .rv-tip, .review-panel .rv-by, .review-panel .nav-end { display: none; }
  .rv-where { font-size: 1.05rem; margin-bottom: 6px; }
  .rv-nav { display: none; }
  .rv-mininav { display: flex; }
  .rv-top { margin-bottom: 2px; }
  .rv-top .rv-where { margin: 0; }
  .rv-note { padding-top: 6px; margin-bottom: 4px; }

  /* One tidy line per player: swatch + name, captures, a clock at the same size as the name. */
  .player-bar { align-items: center; gap: 8px; }
  .pb-meta { display: none; }
  .pb-swatch-inline { display: inline-block; flex: 0 0 auto; width: 11px; height: 11px; margin-right: 7px; }
  .pb-name { display: flex; align-items: center; font-size: 1rem; }
  .clock { font-size: 1rem; padding: 4px 9px 4px 13px; min-width: 0; letter-spacing: 0; }
  .clock::before { width: 5px; }
  .clock.untimed { font-size: .85rem; padding: 4px 9px; }
  .cap-piece { font-size: 15px; }
  .cap-lead { font-size: .85rem; }
  .rv-close-bottom { display: flex; width: 100%; margin-top: 10px; min-height: 38px; }
}
@media (max-width: 900px) {
  .game { grid-template-columns: minmax(0, 1fr); }
  .board-col { max-width: 640px; width: 100%; margin: 0 auto; }
  .lobby-forms { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .room { padding: 12px 16px; }
  .topbar { padding: 10px 16px; }
  .lobby { padding: 28px 16px 48px; }
  .tc-grid { grid-template-columns: repeat(2, 1fr); }
  .panel { padding: 14px; }
  .room-label { display: none; }
  .conn { font-size: 0; gap: 0; }
  /* One-line top bar on phones. */
  .topbar { padding: 8px 12px; gap: 8px; flex-wrap: nowrap; }
  .brand { font-size: .98rem; gap: 7px; }
  .brand-mark { width: 16px; height: 16px; }
  .brand { min-width: 0; }
  .brand > span:not(.brand-mark) { flex-shrink: 0; }
  .app-version { font-size: .7rem; flex-shrink: 1 !important; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-right { flex-wrap: nowrap; gap: 8px; }
  .topbar-room { flex-wrap: nowrap; gap: 6px; }
  .room-code { font-size: .85rem; padding: 1px 6px; letter-spacing: .04em; }
  .style-menu summary { padding: 1px 7px; font-size: .85rem; white-space: nowrap; }
  /* The panel hangs from the top bar, not the button, so it can't run off either edge. */
  .topbar { position: relative; }
  .style-menu { position: static; }
  .style-pop { left: 12px; right: 12px; width: auto; max-width: none; top: calc(100% + 4px); }
}
@media (max-width: 380px) {
  .brand-mark { display: none; }
  .topbar { padding: 8px 10px; }
  .brand { font-size: .92rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .btn.go { box-shadow: 0 0 0 3px color-mix(in srgb, var(--signal) 45%, transparent); }
  .btn.retry { box-shadow: 0 0 0 3px color-mix(in srgb, var(--muted) 40%, transparent); }
}
