/* ChessDb web client */

:root {
  color-scheme: light dark;
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #f1eee8;
  --surface-3: #e8e3da;
  --border: #e0dad0;
  --border-strong: #cbc3b6;
  --text: #1e1c19;
  --muted: #6d675e;
  --accent: #8b5a2b;
  --accent-strong: #6f451d;
  --accent-text: #ffffff;
  --accent-soft: rgba(139, 90, 43, 0.12);
  --row-alt: #faf9f6;
  --row-hover: #f3ece1;
  --row-sel: #ead9c2;
  --comment: #1d6aa8;
  --nag: #9b2c1f;
  --win: #2c6e35;
  --loss: #a1281d;
  --draw: #6d675e;
  --danger: #b3261e;
  --ok: #2e8540;
  --warn: #b7791f;
  --shadow: 0 1px 2px rgba(30, 20, 10, 0.06), 0 4px 16px rgba(30, 20, 10, 0.06);
  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --board-frame: #5a402c;
  --radius: 10px;
  --tap: 40px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1d2024;
    --surface-2: #25292e;
    --surface-3: #2e333a;
    --border: #30353c;
    --border-strong: #444b54;
    --text: #e9e7e3;
    --muted: #9aa0a8;
    --accent: #d39a5c;
    --accent-strong: #e5b27b;
    --accent-text: #1a1209;
    --accent-soft: rgba(211, 154, 92, 0.16);
    --row-alt: #1a1d21;
    --row-hover: #262a30;
    --row-sel: #3a3128;
    --comment: #7cb8ee;
    --nag: #f08a7e;
    --win: #7ccf8a;
    --loss: #f08a7e;
    --draw: #9aa0a8;
    --danger: #e0574c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 18px rgba(0, 0, 0, 0.25);
  }
}

@media (pointer: coarse) {
  :root { --tap: 44px; }
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.view { flex: 1; min-height: 0; }
[hidden] { display: none !important; }

button, input, select { font: inherit; color: inherit; }

.ico {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* ---- buttons ------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  user-select: none;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active:not(:disabled) { background: var(--surface-3); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:focus-visible, .lh:focus-visible, .mv:focus-visible, .an-mv:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-icon { padding: 0; }
.btn-sm { min-height: 30px; min-width: 30px; padding: 0 10px; font-size: 13px; }
@media (pointer: coarse) { .btn-sm { min-height: 36px; min-width: 36px; } }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---- banner / header ------------------------------------------------------- */

.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--danger);
  color: #fff;
  font-weight: 500;
  z-index: 50;
}
.banner-text { flex: 1; }
.banner .btn { background: rgba(255, 255, 255, 0.15); border-color: rgba(255, 255, 255, 0.5); color: #fff; }

.app-bar {
  display: flex;
  align-items: center;
  height: 48px;
  flex: none;
  padding: 0 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
body[data-view="game"] .app-bar { display: none; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { width: 26px; height: 26px; flex: none; }
.brand-name { font-weight: 700; letter-spacing: 0.01em; }
.db-name {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-left: 10px;
  border-left: 1px solid var(--border);
}
.db-name:empty { display: none; }
.sign-out-btn { flex: none; margin-left: 6px; margin-right: -8px; }

/* ---- list view ------------------------------------------------------------- */

.view-list {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  min-height: 0;
}

.filters {
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  padding: 16px;
}
.filter-form { display: flex; flex-direction: column; gap: 12px; }
.ff { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); min-width: 0; }
.ff input, .ff select {
  height: 36px;
  width: 100%;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 400;
}
@media (pointer: coarse) { .ff input, .ff select { height: 44px; font-size: 16px; } }
.ff input:focus, .ff select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.ff-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ff-check { display: flex; align-items: center; gap: 8px; min-height: 32px; cursor: pointer; margin-top: -4px; }
.ff-check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.ff-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 4px; }
.ff-apply.dirty { box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 1px var(--accent-strong); }

/* Head-to-head: Player 1 vs Player 2 + colour. */
.ff-h2h { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 10px 12px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--bg); }
.ff-h2h legend { padding: 0 4px; font-size: 12px; font-weight: 700; color: var(--text); }
.ff-h2h .ff { color: var(--text); }
.ff-h2h input, .ff-h2h select { background: var(--surface); }
.ff-vs { align-self: center; margin: -4px 0 -6px; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.ff-hint { margin: -4px 0 0; font-size: 12px; font-style: italic; color: var(--accent); }

/* Advanced per-colour name fields. */
.ff-advanced summary { cursor: pointer; font-size: 12px; font-weight: 600; color: var(--muted); padding: 4px 0; }
.ff-advanced summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.ff-adv-note { font-weight: 400; font-style: italic; color: var(--accent); }
.ff-adv-fields { display: flex; flex-direction: column; gap: 12px; margin: 8px 0 0; padding: 0; border: 0; min-width: 0; }
.ff-adv-fields:disabled .ff, .ff-adv-fields:disabled .ff-check { opacity: 0.55; }
.ff-adv-off { margin: 0; font-size: 12px; font-style: italic; color: var(--muted); }

.list-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.list-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  min-height: 48px;
  flex: none;
}
.ff-toggle { display: none; }
.ff-badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 700;
}
.list-count { color: var(--muted); font-variant-numeric: tabular-nums; }

.list-table {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin: 0 16px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.list-head, .lr:not(.lr-card) {
  display: grid;
  grid-template-columns:
    64px minmax(110px, 1.4fr) 52px minmax(110px, 1.4fr) 52px 58px 56px 50px minmax(100px, 1.3fr) minmax(80px, 1fr) 96px;
  align-items: center;
}
.list-head {
  flex: none;
  height: 36px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  padding-right: var(--sbw, 0px);
}
.lh {
  height: 100%;
  border: 0;
  background: none;
  padding: 0 8px;
  text-align: left;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lh:hover { color: var(--text); background: var(--surface-3); }
.lh.sorted { color: var(--accent); }
.lh .arrow { font-size: 9px; margin-left: 4px; vertical-align: 1px; }
.lh-mobile, .lh-dir { display: none !important; }

.list-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  outline: none;
}
.list-spacer { position: relative; width: 100%; }

.lr {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 32px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.lr.odd { background: var(--row-alt); }
.lr:hover { background: var(--row-hover); }
.lr.sel { background: var(--row-sel); }
.lr.active { box-shadow: inset 3px 0 0 var(--accent); }
.lc { padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-num { color: var(--muted); text-align: right; padding-right: 12px; }
.lh.c-num { text-align: right; padding-right: 12px; }
.c-name { font-weight: 550; }
.c-elo, .c-moves { color: var(--muted); }
.c-res { font-weight: 650; }
.res-w { color: var(--win); }
.res-b { color: var(--loss); }
.res-d { color: var(--draw); }
/* Rows whose page has not arrived: skeleton bars laid out in the real columns (same row height, so data replaces them
   without a jump). Bars fade in only after 150 ms (fast pages never flash) and carry a moving shimmer. */
.lr-skeleton { cursor: default; }
.lr-skeleton.odd:hover { background: var(--row-alt); }
.lr-skeleton:not(.odd):hover { background: transparent; }
.sk {
  display: block;
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--surface-3) 0%, var(--surface-3) 35%, var(--surface-2) 50%, var(--surface-3) 65%, var(--surface-3) 100%);
  background-size: 300% 100%;
  opacity: 0;
  animation: sk-reveal 0.2s ease-out 0.15s forwards, sk-shimmer 1.4s linear infinite;
}
.lr-skeleton.sk-late .sk { opacity: 1; animation: sk-shimmer 1.4s linear infinite; }
.lr-skeleton .c-num .sk { margin-left: auto; }
.lr-skeleton .c-res .sk { width: 28px !important; }
.lr-skeleton.lr-card .lc-top { align-items: center; }
.lr-skeleton .sk-res { flex: none; width: 30px; }
.lr-skeleton .sk-thin { height: 8px; }
@keyframes sk-reveal { to { opacity: 1; } }
@keyframes sk-shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@keyframes pulse { 50% { opacity: 0.45; } }

/* Rows whose page failed: clearly an error, with a retry. */
.lr-error {
  display: flex !important;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  cursor: default;
  background: color-mix(in srgb, var(--danger) 7%, var(--surface)) !important;
}
.lr-card.lr-error { flex-direction: row; }
.lr-msg { color: var(--danger); font-size: 13px; font-weight: 550; }
.lr-retry { min-height: 24px; height: 24px; }

/* Busy indicators (toolbar text, thin bar under the header) and the stale previous results. */
.list-ind { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.list-busy-ind { color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }
.ind-bar { position: relative; width: 56px; height: 4px; border-radius: 2px; background: var(--accent-soft); overflow: hidden; }
.ind-bar::after, .list-progress::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 40%;
  border-radius: 2px;
  background: var(--accent);
  animation: ind-slide 1.1s ease-in-out infinite;
}
.ind-dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--surface-3); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes ind-slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
.list-progress { position: absolute; left: 0; right: 0; top: 36px; height: 3px; z-index: 2; overflow: hidden; background: var(--accent-soft); pointer-events: none; }
.list-progress::after { width: 30%; border-radius: 0; }
.list-table.is-stale .list-scroll { opacity: 0.4; pointer-events: none; transition: opacity 0.15s; }
.list-count.is-stale { opacity: 0.55; }
.ff-apply { min-width: 116px; }
.ff-apply.busy { cursor: progress; }
.ff-apply.busy::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}

.list-state {
  position: absolute;
  inset: 36px 0 0 0;
  display: grid;
  place-items: center;
  background: var(--surface);
  padding: 24px;
}
.state-box { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; max-width: 380px; margin: 24px auto; }
.state-title { font-weight: 650; font-size: 15px; }
.state-sub { color: var(--muted); }
.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--surface-3);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress { width: 260px; max-width: 70vw; height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); transition: width 0.4s ease; }

@media (max-width: 1180px) {
  .list-head, .lr:not(.lr-card) {
    grid-template-columns: 58px minmax(100px, 1.4fr) 50px minmax(100px, 1.4fr) 50px 56px 50px minmax(90px, 1.2fr) 92px;
  }
  .c-site, .c-moves { display: none; }
}

/* Phone / narrow list */
@media (max-width: 760px) {
  .view-list { display: flex; flex-direction: column; }
  .filters {
    display: none;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    max-height: 70dvh;
    flex: none;
    box-shadow: var(--shadow);
  }
  .view-list.filters-open .filters { display: block; }
  .ff-toggle { display: inline-flex; }
  .list-toolbar { padding: 8px 12px; order: -1; }
  .view-list.filters-open .list-toolbar { order: 0; }
  .list-main { flex: 1; }
  .list-table { margin: 0; border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0; box-shadow: none; }
  .list-head { display: flex; gap: 8px; align-items: center; padding: 0 12px; height: 48px; }
  .list-head .lh { display: none; }
  .lh-mobile { display: flex !important; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); flex: 1; min-width: 0; }
  .lh-mobile select {
    flex: 1;
    min-width: 0;
    max-width: 220px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    padding: 0 8px;
    font-size: 15px;
  }
  .lh-dir { display: inline-flex !important; }
  .list-state { inset: 48px 0 0 0; }
  .list-progress { top: 48px; }
}

.lr-card {
  height: 64px;
  padding: 9px 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
}
.lc-top { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.lc-players { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.lc-players b { font-weight: 600; }
.lc-elo { color: var(--muted); font-size: 12px; }
.lc-dash { color: var(--muted); margin: 0 2px; }
.lc-res { flex: none; font-weight: 700; font-variant-numeric: tabular-nums; }
.lc-meta { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- game view -------------------------------------------------------------- */

.view-game { display: flex; flex-direction: column; min-height: 0; }

.game-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 56px;
  flex: none;
  padding: 0 12px;
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  padding-top: env(safe-area-inset-top);
  box-sizing: content-box;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.game-back { border-color: transparent; background: transparent; }
.game-title { flex: 1; min-width: 0; line-height: 1.25; }
.gt-players, .gt-meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gt-players { font-weight: 650; font-size: 15px; }
.gt-meta { color: var(--muted); font-size: 12.5px; }
.game-actions { display: flex; gap: 6px; flex: none; }

.game-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: auto minmax(300px, 1fr);
  gap: 16px;
  padding: 16px;
  --board: min(calc(100dvh - 56px - 32px - 98px), calc(100vw - 32px - 16px - 360px - 26px), 900px);
}

.board-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.board-row { display: flex; gap: 8px; align-items: stretch; }

.board-host {
  width: var(--board);
  height: var(--board);
  flex: none;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 0 0 3px var(--board-frame), 0 6px 24px rgba(0, 0, 0, 0.18);
  margin: 3px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.board-svg { display: block; width: 100%; height: 100%; cursor: default; }
.sq-light { fill: var(--board-light); }
.sq-dark { fill: var(--board-dark); }
.hl-last { fill: rgba(246, 232, 74, 0.44); }
.hl-sel { fill: rgba(92, 160, 60, 0.5); }
.hl-hover { fill: none; stroke: rgba(255, 255, 255, 0.8); stroke-width: 6; }
.tg-dot { fill: rgba(32, 64, 16, 0.4); }
.tg-capture { fill: none; stroke: rgba(32, 64, 16, 0.4); stroke-width: 9; }
.board-coords text { font: 600 19px var(--font); pointer-events: none; user-select: none; }
.co-on-light { fill: var(--board-dark); }
.co-on-dark { fill: var(--board-light); }
.pc { cursor: grab; }
.drag-piece { filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.35)); }
/* Promotion picker: Lichess-style strip over the promotion file, the rest of the board dimmed. */
.promo-shade { fill: rgba(20, 16, 12, 0.62); cursor: default; }
.promo-choice { cursor: pointer; }
.promo-bg { fill: transparent; }
.promo-disc { fill: #c9c4bc; transition: fill 0.1s; }
.promo-choice.focus .promo-bg { fill: rgba(255, 255, 255, 0.12); stroke: #f0a040; stroke-width: 4; }
.promo-choice.focus .promo-disc, .promo-choice:hover .promo-disc { fill: #f0a040; }
.promoting .pc { cursor: default; }

.evalbar {
  position: relative;
  width: 20px;
  flex: none;
  margin: 3px 0;
  border-radius: 4px;
  overflow: hidden;
  background: #3b3a39;
  border: 1px solid var(--border-strong);
}
.evalbar-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50%;
  background: #fbfaf8;
  transition: height 0.35s ease;
}
.evalbar.flipped .evalbar-fill { bottom: auto; top: 0; }
.evalbar-label {
  position: absolute;
  left: 0;
  right: 0;
  top: 4px;
  font: 700 9px/1 var(--mono);
  text-align: center;
  color: #f4f2ee;
  writing-mode: horizontal-tb;
  letter-spacing: -0.04em;
}
.evalbar-label.on-white { top: auto; bottom: 4px; color: #3b3a39; }
.evalbar.flipped .evalbar-label { top: auto; bottom: 4px; }
.evalbar.flipped .evalbar-label.on-white { top: 4px; bottom: auto; }

.nav-bar { display: flex; gap: 8px; justify-content: center; padding: 0 3px; }
.nav-btn { flex: 1; max-width: 120px; height: 44px; }

/* "Continue with" at a branch point (↑/↓ select, → enters) and the side-to-move line. */
.pos-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 16px;
  min-height: 32px;
  max-width: calc(var(--board) + 26px);
}
.choices { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 8px; }
.choices-label { color: var(--muted); font-size: 12.5px; }
.choices-list { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.choice { font-weight: 500; }
.choice.sel { font-weight: 700; border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.pos-status { text-align: center; color: var(--muted); font-size: 12.5px; }

/* Popup menu (notation context menu, ⋯ menu) */
.menu {
  position: fixed;
  z-index: 50;
  min-width: 210px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;
}
.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  text-align: left;
  cursor: pointer;
}
@media (pointer: coarse) { .menu-item { min-height: 44px; } .menu-hint { display: none; } }
.menu-item:hover:not(:disabled), .menu-item:focus-visible { background: var(--surface-3); outline: none; }
.menu-item:disabled { opacity: 0.45; cursor: default; }
.menu-hint { font: 12px var(--font); color: var(--muted); }
.menu-sep { height: 1px; margin: 4px 6px; background: var(--border); }

.toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  max-width: calc(100vw - 32px);
  padding: 8px 14px;
  border-radius: var(--radius);
  background: #2c2a2b;
  color: #f4f2ee;
  font-size: 13.5px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="error"] { background: var(--danger); color: #fff; }

.side-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  min-height: 0;
}
.side-col > * {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.game-info { padding: 12px 14px; flex: none; }
.gi-players { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.gi-player { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.gi-player:last-child { justify-content: flex-end; text-align: right; }
.gi-player b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.gi-elo { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.gi-swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; align-self: center; border: 1px solid var(--border-strong); }
.gi-swatch.w { background: #f4f1ea; }
.gi-swatch.b { background: #2a2729; }
.gi-player:last-child .gi-swatch { order: 3; }
.gi-result { font-weight: 750; font-size: 15px; font-variant-numeric: tabular-nums; }
.gi-tags {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  margin: 10px 0 0;
  font-size: 12.5px;
}
.gi-tags dt { color: var(--muted); }
.gi-tags dd { margin: 0; overflow-wrap: anywhere; }
.gi-tags:empty { display: none; }

.notation-wrap { flex: 1; min-height: max(140px, 28%); display: flex; flex-direction: column; overflow: hidden; }
.notation {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px 20px;
  font-size: 15px;
  line-height: 1.75;
  overscroll-behavior: contain;
}
.nt-para { margin: 0; }
.nt-var {
  margin: 4px 0 4px 6px;
  padding: 1px 0 1px 12px;
  border-left: 2px solid var(--border-strong);
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
}
.nt-var + .nt-var { margin-top: 2px; }
.nt-l2 { margin-left: 28px; }
.nt-l3 { margin-left: 50px; }
.nt-para + .nt-para:not(.nt-var) { margin-top: 2px; }
.mv { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
.nt-paren { color: var(--muted); }
.nt-comment { color: var(--comment); font-style: normal; }
.nt-result { font-weight: 750; margin-left: 4px; }
.nt-empty { color: var(--muted); }
.mv {
  cursor: pointer;
  padding: 2px 3px;
  margin: 0 -1px;
  border-radius: 4px;
  white-space: nowrap;
}
.mv:hover { background: var(--surface-3); }
.mv-main { font-weight: 650; }
.mv-num { color: var(--muted); font-weight: 400; margin-right: 1px; }
.mv-main .mv-num { font-weight: 500; }
.mv-nag { color: var(--nag); }
.mv.cur { background: var(--accent); color: var(--accent-text); }
.mv.cur .mv-num, .mv.cur .mv-nag { color: inherit; }
/* Clean view: a small raised dot marks a move with a comment (absolutely sized so selection never reflows the line). */
.mv-dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-left: 2px;
  border-radius: 50%;
  background: var(--comment);
  vertical-align: 0.55em;
  opacity: 0.85;
}
.mv.cur .mv-dot { background: currentColor; }
.mv-root { padding: 2px 5px; }
.mv-root .mv-dot { margin-left: 0; }

/* Details strip of the shown move, under the notation. Shown (with a fixed height) only for games with data; a move
   without data keeps the space but hides the content, so the notation never jumps. */
.move-details {
  display: none;
  flex: none;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  padding: 6px 14px 7px;
  font-size: 13px;
  line-height: 1.45;
  border-radius: 0 0 var(--radius) var(--radius);
}
.has-details .move-details { display: block; }
.move-details.empty > * { visibility: hidden; }
.md-row { display: flex; align-items: baseline; gap: 4px 12px; height: 19px; overflow: hidden; }
.md-facts { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.md-clocks { flex: none; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.md-move { font-weight: 650; margin-right: 10px; }
.md-label, .mp-facts .md-label { color: var(--muted); margin-right: 4px; }
.md-value { font-weight: 600; font-variant-numeric: tabular-nums; margin-right: 12px; }
.md-comment { display: none; color: var(--comment); height: calc(2 * 1.45em); overflow-y: auto; margin-top: 3px; overscroll-behavior: contain; }
.has-text .md-comment { display: block; }

/* Details popover of another move (hover, Ctrl+click, "Show details"). */
.mv-pop {
  position: fixed;
  z-index: 45;
  max-width: min(340px, calc(100vw - 16px));
  padding: 8px 11px 9px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.18);
  font-size: 13px;
  line-height: 1.45;
}
.mv-pop.hover { pointer-events: none; }
.mp-head { font-weight: 650; }
.mp-facts { margin-top: 2px; }
.mp-clocks { color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 1px; }
.mp-comment { color: var(--comment); margin-top: 5px; overflow-wrap: anywhere; }
.mp-none { color: var(--muted); }

/* Player clocks next to the names, from [%clk]; the side to move is lit. */
.gi-clock {
  flex: none;
  align-self: center;
  font: 600 12.5px/1.5 var(--mono);
  padding: 0 6px;
  border-radius: 4px;
  background: var(--surface-3);
  color: var(--text);
}
.gi-clock.run { background: var(--accent); color: var(--accent-text); }
.gi-player:last-child .gi-clock { order: -1; }

/* analysis */
.analysis { flex: 0 1 auto; display: flex; flex-direction: column; max-height: 44%; min-height: 0; overflow: hidden; }
.an-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 12px;
  border-bottom: 1px solid var(--border);
  min-height: 44px;
  flex: none;
}
.an-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--border-strong); flex: none; }
.an-dot[data-state="on"] { background: var(--ok); box-shadow: 0 0 0 3px rgba(46, 133, 64, 0.2); }
.an-dot[data-state="busy"] { background: var(--warn); animation: pulse 1s infinite; }
.an-dot[data-state="warn"] { background: var(--warn); }
.an-dot[data-state="error"] { background: var(--danger); }
.an-status { font-size: 13px; color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.an-spacer { flex: 1; }
.an-pvctl { display: flex; align-items: center; gap: 4px; flex: none; }
.an-pvn { min-width: 16px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.an-lines { overflow-y: auto; min-height: 0; }
.an-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.an-line:last-child { border-bottom: 0; }
.an-eval {
  flex: none;
  min-width: 56px;
  padding: 1px 6px;
  border-radius: 5px;
  font: 700 13px/1.6 var(--mono);
  text-align: center;
}
.ev-white { background: #f4f2ee; color: #1e1c19; box-shadow: inset 0 0 0 1px var(--border-strong); }
.ev-black { background: #2c2a2b; color: #f4f2ee; }
.ev-even { background: var(--surface-3); color: var(--text); }
.an-agree {
  flex: none;
  font: 600 11px/1.9 var(--mono);
  color: var(--muted);
  padding: 0 5px;
  border-radius: 5px;
  border: 1px solid var(--border);
}
.an-agree.full { color: var(--ok); border-color: currentColor; }
.an-pv {
  flex: 1;
  min-width: 0;
  line-height: 1.65;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.an-num { color: var(--muted); margin-left: 3px; }
.an-mv {
  border: 0;
  background: none;
  padding: 0 2px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 550;
}
.an-mv:hover { background: var(--accent-soft); color: var(--accent); }
.an-run.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.an-msg { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 8px 12px; font-size: 13px; color: var(--muted); }
.an-errors { display: flex; align-items: flex-start; gap: 8px; padding: 6px 8px 6px 12px; background: var(--danger-soft, rgba(200, 40, 40, 0.1)); color: var(--danger); font-size: 12.5px; border-bottom: 1px solid var(--border); }
.an-errors-list { flex: 1; min-width: 0; }
.analysis.background .an-lines, .analysis.background .an-engines { opacity: 0.5; }
.evalbar.dim { opacity: 0.45; }
.an-engines {
  display: flex;
  flex-direction: column;
  padding: 4px 0;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  flex: none;
  overflow-y: auto;
  max-height: 40%;
}
.an-engines:empty { display: none; }
.an-engine summary { display: flex; gap: 6px; min-width: 0; padding: 3px 12px; cursor: pointer; list-style: none; }
.an-engine summary::-webkit-details-marker { display: none; }
.an-engine summary::before { content: '▸'; color: var(--muted); width: 10px; flex: none; }
.an-engine[open] summary::before { content: '▾'; }
.an-engine summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.an-eline { padding: 4px 12px 4px 28px; font-size: 12.5px; }
.an-depth { flex: none; font: 600 11px/1.9 var(--mono); color: var(--muted); }
.an-ename { font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.an-estats { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Desktop: notation, then analysis, then masters; the three share the column height (none collapses to its header). */
@media (min-width: 761px) {
  .game-info { order: 1; }
  .notation-wrap { order: 2; flex: 1 1 0; min-height: 140px; }
  .analysis { order: 3; flex: 1 1 0; min-height: 170px; }
  .side-col > .masters { order: 4; flex: 1 1 0; min-height: 130px; }
}
@media (min-width: 761px) and (max-height: 700px) {
  .gi-tags { display: none; }
}

/* Narrow laptops: stack when the board would get too small next to the side column. */
@media (min-width: 761px) and (max-width: 1000px) and (orientation: portrait) {
  .game-body { grid-template-columns: 1fr; overflow-y: auto; --board: min(calc(100vw - 32px - 34px), 62dvh); }
  .board-col { align-items: center; }
  .side-col { min-height: 420px; }
}

/* Phone */
@media (max-width: 760px) {
  .game-bar { height: 52px; padding-left: max(4px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); gap: 4px; }
  .act-label { display: none; }
  .act-analysis { padding: 0; }
  .act-pgn, .act-play, .act-comments { display: none; } /* in the ⋯ menu */
  .move-details { padding: 5px 12px 6px; font-size: 12.5px; }
  /* Two fixed lines on a phone: the move facts, then both clocks (constant height whatever the move has). */
  .md-row { flex-wrap: wrap; height: auto; gap: 0; }
  .md-facts, .md-clocks { flex: 1 0 100%; min-height: 1.45em; }
  .md-value { margin-right: 10px; }
  .choices-label { display: none; }
  .pos-line { width: 100%; max-width: none; min-height: 0; margin-top: -2px; padding-bottom: 6px; gap: 4px 10px; }
  .pos-status { font-size: 12px; }
  .game-body {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    --board: min(calc(100vw - 30px), calc(100dvh - 52px - 60px - 170px));
  }
  .board-col { flex: none; gap: 0; padding: 8px 8px 0; align-items: center; background: var(--bg); }
  .board-row { gap: 6px; }
  .evalbar { width: 10px; }
  .evalbar-label { display: none; }
  .board-host { margin: 2px; box-shadow: 0 0 0 2px var(--board-frame); }
  .nav-bar { width: 100%; padding: 8px 0; }
  .nav-btn { max-width: none; height: 44px; }
  .side-col {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 8px max(12px, env(safe-area-inset-bottom));
    gap: 8px;
  }
  .side-col > * { box-shadow: none; }
  .analysis { order: 0; max-height: none; overflow: visible; }
  .an-lines { overflow: visible; }
  .an-engines { max-height: none; }
  .an-pv { -webkit-line-clamp: 1; line-clamp: 1; }
  /* The notation scrolls by itself (current move kept in view) so the panels below stay reachable. */
  .notation-wrap { order: 1; flex: none; min-height: auto; max-height: 42dvh; }
  .notation { padding: 10px 12px 14px; }
  .game-info { order: 3; }
  .gi-players { display: none; }
  .gi-tags { margin: 0; }
}

/* Landscape phones: board left, everything else scrolls on the right. */
@media (max-height: 520px) and (orientation: landscape) {
  .game-bar { height: 44px; }
  .game-body {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    padding: 8px;
    gap: 10px;
    --board: calc(100dvh - 44px - 16px - 52px - env(safe-area-inset-top));
  }
  .board-col { gap: 6px; padding: 0; }
  .nav-bar { padding: 0; }
  .nav-btn { height: 40px; }
  .side-col { overflow-y: auto; padding: 0; }
  .analysis { order: 0; max-height: none; overflow: visible; }
  .notation-wrap { order: 1; flex: none; min-height: auto; max-height: 70dvh; }
  .game-info { order: 3; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
