/* RPS 9x9 — design system (lichess-inspired dark theme).
 * Board colors are user-specified and intentionally left unchanged.
 * Everything else is driven by the tokens below so future screens stay consistent.
 */
:root {
  /* Board (user-specified) */
  --light: #f0d9b5;
  --dark: #b58863;

  /* Surfaces */
  --bg: #161512;
  --surface: #262421;
  --surface-2: #2e2c28;
  --surface-3: #35332f;
  --border: #3c3a37;

  /* Text */
  --text: #c8c3bc;
  --text-bright: #ffffff;
  --muted: #84807a;

  /* Accents */
  --accent: #3692e7;          /* links / blue */
  --primary: #629924;         /* lichess green CTA */
  --primary-hover: #72aa2b;
  --danger: #c33;
  --danger-hover: #d6493f;
  --blue: #2b6fe0;
  --red: #d64545;
  --blue-bright: #4a86f0;
  --red-bright: #ef6a6a;
  --selected: #f6d743;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "Menlo", "Consolas", "Liberation Mono", monospace;

  /* Spacing */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;

  /* Radii */
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;

  /* Shadow */
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);

  /* Lichess theme tokens (lobby / home) */
  --block-gap: 16px;
  --ui-roundness: 7px;
  --c-bg: hsl(37, 7%, 14%);
  --c-bg-page: hsl(37, 10%, 8%);
  --c-bg-zebra: hsl(37, 5%, 19%);
  --c-bg-low: hsl(37, 7%, 22%);
  --c-bg-mid: hsl(37, 7%, 16%);
  --c-font: hsl(0, 0%, 73%);
  --c-font-dim: hsl(0, 0%, 58%);
  --c-font-dimmer: hsl(0, 0%, 42%);
  --c-font-clear: hsl(0, 0%, 80%);
  --c-font-clearer: hsl(0, 0%, 89%);
  --c-border: hsl(0, 0%, 25%);
  --c-border-light: hsl(0, 0%, 40%);
  --c-metal-top: hsl(37, 7%, 22%);
  --c-metal-bottom: hsl(37, 5%, 19%);
  --c-metal-top-hover: hsl(37, 7%, 25%);
  --c-metal-bottom-hover: hsl(37, 5%, 22%);
  --c-primary: hsl(209, 79%, 56%);
  --c-secondary: hsl(88, 62%, 37%);
  --c-good: hsl(88, 62%, 37%);
  --c-bad: hsl(0, 60%, 50%);
  --c-brag: hsl(37, 74%, 43%);
  --c-accent: hsl(22, 100%, 42%);
  --c-accent-glass: rgba(214, 79, 0, 0.2);
  --c-accent-cloud: rgba(214, 79, 0, 0.5);
  --c-pool-button: rgba(51, 48, 45, 0.66);
  --c-font-shadow: rgba(0, 0, 0, 0.66);
  --c-link: var(--c-primary);
}

/* Lichess icon font: see assets/lichess-icons.LICENSE.txt. */
@font-face {
  font-family: "lichess-icons";
  src: url("/assets/lichess-icons.woff2") format("woff2");
  font-display: block;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--c-bg-page);
  color: var(--c-font);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* Personal display preferences. */
body.light-mode {
  --c-bg-page: #f1f3f5; --c-bg: #ffffff; --c-bg-zebra: #f6f7f8;
  --c-bg-low: #e7e9eb; --c-bg-mid: #ffffff; --c-font: #394047;
  --c-font-dim: #66717b; --c-font-clear: #252b31; --c-font-clearer: #111;
  --c-border: #ccd2d8; --c-border-light: #aab3bc; --surface: #fff;
  --surface-2: #f4f6f8; --surface-3: #e6e9ec; --text: #394047;
  --text-bright: #15191d; --muted: #66717b; --border: #ccd2d8;
  --c-metal-top: #ffffff; --c-metal-bottom: #e5e8eb;
  --c-metal-top-hover: #f4f6f8; --c-metal-bottom-hover: #d8dde2;
  --c-font-shadow: rgba(0, 0, 0, 0.12);
}
body.light-mode .button-metal,
body.light-mode .btn,
body.light-mode .mode-btn,
body.light-mode .tc-preset { color: var(--text); text-shadow: none; }
body.light-mode .button-metal:hover,
body.light-mode .btn:hover,
body.light-mode .mode-btn:hover,
body.light-mode .tc-preset:hover { color: var(--text-bright); }
body.light-mode .btn:hover { background: #dfe5ea; }
body.light-mode .btn.danger { background: #c85a5a; }
body.light-mode .btn.danger:hover { background: #b94b4b; }
body.light-mode .nav-link-btn,
body.light-mode .time-control-summary,
body.light-mode .tc-row label,
body.light-mode .tc-val,
body.light-mode .game-mode,
body.light-mode .gamestatus,
body.light-mode .clock,
body.light-mode .profile-ratings-side,
body.light-mode .editor-tool img { color: #111820; }
body.light-mode .nav-link-btn:hover { color: #000; background: rgba(0, 0, 0, .06); }
body.light-mode .time-control-summary strong { color: #000; }
body.light-mode .game-mode.casual { background: #c8cdd2; color: #111820; }
body.light-mode .gamestatus.over { background: #b9d5b9; color: #172217; }
body.light-mode .clock { background: #e0e4e8; color: #111820; }
body.light-mode .clock.active { background: var(--primary); color: #fff; }
body.light-mode .clock.low { background: #c84d45; color: #fff; }
body.light-mode input[type="range"]::-webkit-slider-thumb { background: #eef1f3; border-color: #87939e; }
body.light-mode input[type="range"]::-moz-range-thumb { background: #eef1f3; border-color: #87939e; }
body.light-mode .editor-palette .editor-tool img { filter: none; }
body.board-theme-default { --light: #f0d9b5; --dark: #b58863; }
body.board-theme-light { --light: #f5f5f5; --dark: #c5c5c5; }
body.board-theme-white { --light: #fff; --dark: #fff; }
body.board-theme-white .sq { border: 1px solid #111; }
body.board-theme-blue { --light: #b9d7ee; --dark: #4d79a8; }
body.board-theme-green { --light: #d8e8c8; --dark: #6b9561; }
body .piece svg[class^="piece-svg-"] { filter: drop-shadow(0 1px 1px rgba(0,0,0,.18)); }
body.blindfold-mode #board .piece { visibility: hidden; }
body.no-piece-animations .piece { animation: none !important; transition: none !important; }
body:not(.no-piece-animations) .board .piece-moving { animation: piece-move .18s ease-out; }
@keyframes piece-arrive { from { opacity: .25; transform: scale(.9); } to { opacity: 1; transform: scale(1); } }
@keyframes piece-move { from { opacity: .65; transform: translate(var(--piece-dx), var(--piece-dy)); } to { opacity: 1; transform: translate(0, 0); } }

/* ---------------------------------------------------------------------------
   Home / lobby
--------------------------------------------------------------------------- */
.screen {
  max-width: 1080px;
  margin: 0 auto;
  padding: var(--s6) var(--s4) 30px;
}

#home {
  max-width: 1400px;
}
#history { max-width: 1580px; }

h1 { margin: 0; font-size: 30px; letter-spacing: 0.5px; color: var(--text-bright); }
h1 span { color: var(--muted); font-weight: 400; }

.rules {
  font-size: 13px;
  line-height: 1.55;
  color: var(--c-font-dim);
}
.rules p { margin: var(--s2) 0; }
.lobby__side .rules { line-height: 1.35; }
.lobby__side .rules p { margin: 3px 0; }
.rules b { color: var(--c-font); }

.field-label { display: block; font-size: 13px; color: var(--muted); margin: var(--s3) 0 var(--s1); }

.select, .input {
  width: 100%;
  padding: 11px 12px;
  font-size: 15px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.select:focus, .input:focus { outline: none; border-color: var(--accent); }
.input[readonly] { color: var(--muted); }

/* Buttons */
.btn {
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: var(--r-md);
  cursor: pointer;
  background: var(--surface-3);
  color: var(--text);
  transition: background 0.15s, color 0.15s;
}
.btn:hover { background: #3f3d39; color: var(--text-bright); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { background: #7a2f2f; color: #fff; }
.btn.danger:hover { background: var(--danger-hover); }
.btn.small { padding: 9px 12px; font-size: 14px; }

.join-row { display: flex; gap: var(--s2); }
.join-row .input { flex: 1; }

.error { margin-top: 10px; padding: 10px 12px; border-radius: var(--r-md); background: #5a2323; color: #ffd7d7; font-size: 14px; }

/* ---------------------------------------------------------------------------
   Game layout
--------------------------------------------------------------------------- */
.game-layout {
  display: flex;
  gap: var(--s5);
  align-items: flex-start;
  justify-content: center;
}

.players-col {
  width: min(70vh, 600px);
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

.player {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s2) var(--s4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  min-height: 56px;
  border-left: 4px solid transparent;
}
.player-identity { min-width: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.player-rating-info { color: var(--muted); font-size: 14px; font-family: var(--font-mono); }
.player-captured { display: inline-flex; align-items: center; gap: 2px; }
.player-captured .captured-piece { width: 24px; height: 24px; }

.player .pname { font-size: 21px; font-weight: 600; }
.pname.profile-link {
  border: 0;
  padding: 0;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.pname.profile-link:hover { text-decoration: underline; }
.pname.profile-link:disabled { cursor: default; text-decoration: none; }
.pname.blue { color: var(--blue-bright); }
.pname.red { color: var(--red-bright); }

/* Clock — lichess-style: dim when inactive, bright when running, red when low. */
.clock {
  font-family: var(--font-mono);
  font-size: 30px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #8d8a86;
  background: #1d1c1a;
  padding: 4px 14px;
  border-radius: var(--r-md);
  min-width: 92px;
  text-align: center;
}
.clock.active { color: #ffffff; background: var(--primary); }
.clock.low { color: #ffffff; background: #b0332a; }
.clock-wrap { display: flex; align-items: center; gap: 8px; }
.grace {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: #e8e6e3;
  background: #4a4944;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}


.board-wrap { position: relative; display: flex; justify-content: center; }
.board-with-captured { position: relative; width: 100%; }
.board-with-captured .board-wrap { width: 100%; }

/* Board arrows overlay (right-click drag) */
.arrows-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 4;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(9, minmax(0, 1fr));
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--r-sm);
  overflow: hidden;
  box-shadow: var(--shadow);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }
.sq.lastmove { background-image: linear-gradient(rgba(155, 199, 0, 0.41), rgba(155, 199, 0, 0.41)); }
.sq.selected { background: var(--selected); }
.sq.goal-blue { background-image: linear-gradient(rgba(74, 134, 240, 0.55), rgba(74, 134, 240, 0.55)); }
.sq.goal-red { background-image: linear-gradient(rgba(239, 106, 106, 0.55), rgba(239, 106, 106, 0.55)); }
.sq.drag-source { background-image: linear-gradient(rgba(100, 150, 100, 0.38), rgba(100, 150, 100, 0.38)); }

.piece { width: 82%; height: 82%; position: relative; cursor: default; z-index: 2; }
.piece svg { width: 100%; height: 100%; display: block; }

.coord-file {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: clamp(9px, 1.4vmin, 12px);
  font-weight: 600;
  pointer-events: none;
  z-index: 1;
}
.sq.light .coord-file { color: var(--dark); }
.sq.dark .coord-file { color: var(--light); }

.coord-rank {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: clamp(9px, 1.4vmin, 12px);
  font-weight: 600;
  pointer-events: none;
  z-index: 1;
}
.sq.light .coord-rank { color: var(--dark); }
.sq.dark .coord-rank { color: var(--light); }

.mv-dot {
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.18);
  z-index: 3;
  pointer-events: none;
}
.mv-dot.capture {
  width: 88%;
  height: 88%;
  border-radius: 50%;
  background: transparent;
  border: 4px solid rgba(0, 0, 0, 0.18);
}

/* Premove markers — same overlay style as last-move, but grey */
.sq.premove-from { background-image: linear-gradient(rgba(90, 90, 90, 0.55), rgba(90, 90, 90, 0.55)); }
.sq.premove-to { background-image: linear-gradient(rgba(90, 90, 90, 0.55), rgba(90, 90, 90, 0.55)); }

.setting-switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0; color: var(--text); font-size: 14px; cursor: pointer; }
.setting-switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { width: 42px; height: 24px; padding: 3px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border); transition: background .15s; }
.switch-thumb { display: block; width: 16px; height: 16px; border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s; }
.setting-switch input:checked + .switch-track { background: var(--primary); }
.setting-switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); background: #fff; }
.private-game-panel { margin-top: var(--s3); padding: var(--s3); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); }
.private-game-panel #privateCancel { margin-top: var(--s3); width: 100%; }

.drag-ghost { position: fixed; pointer-events: none; z-index: 1000; }
.drag-ghost svg { width: 100%; height: 100%; }
.editor-cursor-piece { position: absolute; pointer-events: none; z-index: 10; opacity: .78; }
.editor-cursor-piece svg { width: 100%; height: 100%; display: block; }
.editor-cursor-piece img { width: 100%; height: 100%; display: block; filter: invert(80%); }

/* ---------------------------------------------------------------------------
   Side panel
--------------------------------------------------------------------------- */
.side {
  width: 300px;
  flex: 0 0 300px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s4);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}

.side h1 { font-size: 22px; }

.side-head { display: flex; flex-wrap: wrap; align-items: center; column-gap: 10px; row-gap: 6px; }
.side-head h1 { margin-right: auto; }
.side-head .gamestatus { margin-top: 0; width: 100%; }

.game-mode {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--c-font-clear);
  background: var(--c-font-dimmer);
}
.game-mode.casual { background: hsl(0, 0%, 34%); }

.gamestatus {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  font-weight: 600;
  font-size: 14px;
  background: var(--surface-3);
  color: var(--text);
}
.gamestatus.waiting { background: var(--surface-3); color: var(--muted); }
.gamestatus.yourturn { background: #23406b; color: #fff; }
.gamestatus.over { background: #2f4d2f; color: #fff; border: 0; outline: 0; }
.rating-preview { padding: 8px 10px; border: 1px solid var(--border); background: var(--surface-2); border-radius: var(--r-md); color: var(--muted); font-size: 11px; }
.rating-preview-values { display: flex; justify-content: space-between; margin-top: 5px; color: var(--text); font-size: 12px; }

.link-block .field-label { margin-top: 0; }

.movelist-label { font-size: 13px; color: var(--muted); margin-bottom: -6px; }

/* Move list — lichess-style: numbered rows, two columns, last move highlighted. */
.moves {
  margin: 0;
  padding: 0;
  list-style: none;
  min-height: 60px;
  max-height: 240px;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

.moves li {
  display: grid;
  grid-template-columns: 2.4em 1fr 1fr;
  align-items: center;
  min-height: 32px;
  line-height: 32px;
}
.moves li:nth-child(odd) { background: rgba(255, 255, 255, 0.02); }

.moves .num {
  color: var(--muted);
  text-align: right;
  padding-right: 10px;
  font-size: 13px;
  user-select: none;
}

.moves .move {
  padding: 0 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.moves .move.current {
  background: #46433e;
  color: var(--text-bright);
  font-weight: 600;
  border-radius: 3px;
}
.move-clock { margin-left: 7px; color: var(--muted); font-size: 10px; font-family: var(--font-mono); font-weight: 500; }
.analysis-start .move { color: var(--muted); font-style: italic; }

.actions { display: flex; gap: var(--s2); margin-top: auto; }
.actions .btn { flex: 1; }
#finishedActions { flex-direction: column; }
#finishedActions .btn { border: 0; border-color: transparent; outline: 0; }
#finishedActions .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.game-actions {
  display: flex;
  justify-content: space-evenly;
  gap: var(--s2);
  margin-top: var(--s2);
}
.game-actions .icon-btn.hidden { display: inline-flex !important; visibility: hidden; pointer-events: none; }
.icon-btn {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-btn svg { width: 26px; height: 26px; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.08); color: var(--text-bright); }
.icon-btn.danger:hover { background: rgba(204, 51, 51, 0.18); color: #ff8a80; }
.move-nav { display: flex; align-items: center; gap: 2px; margin-top: -4px; }
.move-nav .icon-btn { width: 34px; height: 32px; border-radius: 0; }
.move-nav .icon-btn:disabled { opacity: .35; cursor: default; }
.move-nav-icon { font-family: "lichess-icons"; font-size: 18px; line-height: 1; }
.move-nav-icon::before { content: attr(data-icon); }
.move-settings { padding: 8px 10px; background: var(--surface-2); color: var(--muted); font-size: 12px; }
.move-settings label { display: flex; align-items: center; gap: 6px; }
.hide-coordinates .coord-rank, .hide-coordinates .coord-file { display: none; }

.action-confirm {
  padding: var(--s3);
  background: var(--surface-2);
  border-radius: var(--r-md);
  font-size: 14px;
  color: var(--text);
  margin-top: var(--s2);
}
.action-confirm-text { display: block; font-weight: 600; margin-bottom: var(--s2); }
.action-confirm-btns { display: flex; gap: var(--s2); }
.action-confirm-btns .btn { flex: 1; }

.claim-actions { display: flex; flex-direction: column; gap: var(--s2); margin-top: var(--s2); }
.claim-actions .btn { flex: 1; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: #000;
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--r-md);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 2000;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------------------------------------------------------------------
   Top navigation
--------------------------------------------------------------------------- */
#nav {
  position: relative;
  background: linear-gradient(to bottom, hsl(37, 9%, 21%), var(--c-bg-page));
  border-bottom: none;
  box-shadow: none;
}
body.light-mode #nav { background: linear-gradient(to bottom, #e5e8eb, var(--c-bg-page)); }
.nav-inner {
  max-width: none;
  margin: 0 auto;
  padding: 12px 0 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
@media (max-width: 560px) { .nav-inner { padding: 12px 8px; } }
.nav-brand {
  color: var(--text-bright);
  font-size: 30px;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 0.5px;
}
.nav-brand span { color: var(--muted); font-weight: 400; }
#navAuth { display: flex; align-items: center; gap: var(--s2); }
#navGuest { margin-right: 16px; }
.nav-user { color: var(--text-bright); font-weight: 600; }
.nav-rating { color: var(--muted); font-family: var(--font-mono); font-size: 14px; }
.nav-profile-btn {
  margin-right: 5px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: none;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-bright);
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.nav-profile-btn:hover { background: rgba(255, 255, 255, 0.07); }
.nav-profile-icon { width: 22px; height: 22px; flex: 0 0 auto; }
.nav-mail-btn {
  position: relative;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-bright);
  cursor: pointer;
  transition: background 0.15s;
}
.nav-mail-btn:hover, .nav-mail-btn:focus-visible { background: rgba(255, 255, 255, 0.07); }
.nav-mail-icon { width: 21px; height: 21px; }
.mail-count {
  position: absolute;
  top: 1px;
  right: 0;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  line-height: 17px;
  text-align: center;
  font-weight: 700;
}
.mail-panel {
  position: absolute;
  top: calc(100% - 2px);
  right: 12px;
  z-index: 1500;
  width: min(390px, calc(100vw - 24px));
  padding: var(--s3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .28);
}
.mail-panel-head { margin-bottom: var(--s2); color: var(--text-bright); font-size: 17px; font-weight: 700; }
.mail-list { display: grid; gap: var(--s2); max-height: 360px; overflow-y: auto; }
.mail-item, .challenge-incoming {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s2);
  background: var(--c-bg-page);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 14px;
}
.mail-item > span:first-child, .challenge-incoming > span:first-child { min-width: 0; }
.mail-item strong, .challenge-incoming strong { color: var(--text-bright); }
.mail-empty { margin: 0; color: var(--muted); font-size: 14px; }
.nav-settings-btn {
  margin-right: 7px;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-bright);
  cursor: pointer;
  transition: background 0.15s;
}
.nav-settings-btn:hover, .nav-settings-btn:focus-visible { background: rgba(255, 255, 255, 0.07); }
.nav-settings-icon { width: 22px; height: 22px; }

.nav-left { display: flex; align-items: center; gap: var(--s4); }
.nav-links { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.nav-link-btn {
  min-height: 48px;
  padding: 13px 18px;
  font-family: var(--font-sans);
  font-size: 18px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-link-btn:hover { background: rgba(255, 255, 255, 0.07); color: var(--text-bright); }

/* Home note (guest vs logged-in) */
.home-note {
  padding: 10px 12px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
  margin-bottom: var(--s4);
}

/* ---------------------------------------------------------------------------
   Screen heads (history / analysis)
--------------------------------------------------------------------------- */
.screen-head {
  display: flex;
  align-items: center;
  gap: var(--s4);
  margin-bottom: var(--s5);
}
.screen-head h1 { font-size: 24px; margin-right: auto; }
.screen-head h1 { display: none; }
.screen-head { margin-bottom: var(--s2); justify-content: flex-start; }
.profile-logout { flex: 0 0 auto; }
.back-arrow { display: inline-block; font-size: 28px; line-height: 1; transform: translateY(-1px); }

.discord-link { color: var(--accent); font-weight: 700; text-decoration: none; }
.discord-link:hover, .discord-link:focus-visible { text-decoration: underline; }
.youtube-link { display: block; width: fit-content; margin-top: var(--s2); }
.discord-box .discord-link + .discord-link { display: block; width: fit-content; margin-top: var(--s2); }

.time-control-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: var(--s3) 0;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}
.time-control-summary .time-control-symbol { color: var(--accent); font-size: 24px; }
.time-control-summary #timeControlRatingLabel { margin-left: auto; color: var(--muted); font-weight: 500; }
.time-control-summary strong { color: var(--text-bright); font-family: var(--font-mono); }

/* Analysis grows with its move tree and data fields so the page can reach the
 * FEN/PGN section. The editor keeps its viewport-contained layout. */
#explorer { height: auto; min-height: calc(100vh - 76px); overflow: visible; }
#explorer .game-layout { height: auto; min-height: 0; align-items: flex-start; }
#explorer .side { max-height: none; overflow: visible; }
#editor { height: calc(100vh - 76px); overflow: visible; }
#editor .game-layout { height: calc(100% - 58px); min-height: 0; }
#editor .side { max-height: 100%; overflow-y: auto; }

/* Lichess-style spare-piece trays for the editor. */
.editor-palette {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  padding: 4px;
  margin: 4px 0;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--border);
}
.editor-palette button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 38px;
  padding: 4px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  color: var(--text);
  background: transparent;
  cursor: pointer;
  touch-action: none;
}
.editor-palette button:hover, .editor-palette button.active { background: var(--surface-3); border-color: var(--accent); }
.editor-palette .editor-piece-tool svg { width: 34px; height: 34px; }
.editor-palette .editor-tool { font-size: 24px; line-height: 1; }
.editor-palette .editor-tool img { width: 28px; height: 28px; display: block; filter: invert(80%); }
.editor-action-icon {
  display: inline-block;
  width: 1.25em;
  margin-right: .45em;
  text-align: center;
  font-family: "lichess-icons";
  font-size: 1.15em;
  line-height: 1;
  color: currentColor;
}
.editor-action-icon::before { content: attr(data-icon); }

.play-position-setting { margin-top: var(--s3); margin-bottom: var(--s3); }
.checkbox-label { display: flex; align-items: center; gap: var(--s2); font-size: 13px; font-weight: 600; color: var(--c-font-dim); cursor: pointer; }
.checkbox-label input { width: 16px; height: 16px; accent-color: var(--primary); }
.position-preview { width: min(100%, 250px); margin-top: var(--s3); }
.position-preview .board { box-shadow: 0 3px 12px rgba(0, 0, 0, .35); }
#home .position-preview { width: min(100%, 210px); }
#editor .players-col { width: min(70vh, 600px); }
#editor { padding-top: 0; padding-bottom: 28px; }
#editor .screen-head { justify-content: flex-start; margin-bottom: 8px; position: relative; z-index: 1000; isolation: isolate; pointer-events: auto; }
#editor .screen-head button { display: inline-flex; pointer-events: auto; position: relative; z-index: 1001; touch-action: manipulation; }
#editor .board-wrap { flex-direction: column; }
#editor .board { order: 2; }
#editor #editorPaletteTop { order: 1; }
#editor #editorPaletteBottom { order: 3; }
#editor .side { gap: 8px; }
#editor .actions { flex-direction: column; width: 100%; margin-top: 0; gap: 8px; }
#editor .editor-action { flex: none; width: 100%; border: 0; border-color: transparent; outline: 0; background: transparent; text-align: left; padding: 8px 4px; appearance: none; }
#editor .editor-action:hover, #editor .editor-action:focus { background-color: var(--surface-3); color: var(--text); transition: background 0.15s; }
#editor .editor-action:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
#editor .editor-action:disabled, #editor .editor-action:disabled:hover, #editor .editor-action:disabled:focus { color: #c8c3bc !important; -webkit-text-fill-color: #c8c3bc !important; opacity: 1; cursor: default; transition: none; }
#editor .btn.editor-action:disabled:hover { background: transparent; color: #c8c3bc !important; }

.home-featured, .directory-panel { max-width: 1200px; margin: var(--s4) auto 0; }
.directory-panel { background: var(--surface); border-radius: var(--r-md); padding: var(--s5); }
.directory-panel h2 { margin: 0 0 var(--s3); color: var(--text-bright); font-size: 20px; }
.watch-filters { display: flex; flex-wrap: wrap; gap: var(--s2); margin-bottom: var(--s4); }
.watch-filter { padding: 9px 14px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.watch-filter:hover, .watch-filter.active { border-color: var(--accent); background: var(--surface-3); color: var(--text-bright); }
.watch-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--s4); }
.players-list { display: flex; flex-direction: column; gap: var(--s2); margin-top: var(--s3); }
.watch-game { display: grid; grid-template-columns: 1fr; align-content: start; gap: 6px; width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface-2); color: var(--text); text-align: left; cursor: pointer; }
.watch-game:hover, .watch-game:focus-visible { background: var(--surface-3); color: var(--text-bright); }
.watch-game-preview { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); grid-template-rows: repeat(9, minmax(0, 1fr)); width: 100%; height: auto; aspect-ratio: 1 / 1; overflow: hidden; border-radius: 2px; }
.watch-game-preview .sq { width: 100%; height: 100%; min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center; }
.watch-game-preview svg { width: 86%; height: 86%; }
.watch-game-players { font-size: 12px; font-weight: 600; line-height: 1.3; }
.watch-game-status { color: var(--muted); font-size: 13px; white-space: nowrap; }
.watch-game-time-control { color: var(--muted); font-size: 13px; }
.lobby-players-panel { margin-top: var(--s2); padding: var(--s3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); }
.lobby-players-panel h2 { margin: 0 0 var(--s2); font-size: 18px; color: var(--text-bright); }
.lobby-players-list { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.lobby-player { border: 0; padding: 2px 0; background: transparent; color: var(--text); font: inherit; cursor: pointer; }
.lobby-player:hover { color: var(--primary); }
.player-status-dot { display: inline-block; width: 5px; height: 5px; margin-right: 5px; border-radius: 50%; vertical-align: middle; }
.player-status-dot.online { background: #42b866; box-shadow: 0 0 0 2px rgba(66,184,102,.18); }
.player-status-dot.offline { background: #d34d4d; box-shadow: 0 0 0 2px rgba(211,77,77,.12); }
.player-directory-name { display: inline-flex; align-items: center; min-width: 0; }
.rating-distribution { margin: 0 0 12px; color: var(--muted); text-align: center; }
.rating-distribution svg { display: block; width: 100%; height: 140px; overflow: visible; }
.rating-distribution line { stroke: var(--border); stroke-width: 1; }
.rating-distribution polygon { fill: rgba(90,145,220,.22); }
.rating-distribution polyline { fill: none; stroke: var(--primary); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.rating-distribution text { fill: var(--muted); font: 10px var(--font-mono); }
.rating-distribution small { font-size: 11px; }
.lobby-active-games { margin-top: var(--s2); }
.lobby-active-games h2 { margin: 0 0 var(--s2); font-size: 18px; color: var(--text-bright); }
.home-active-games { display: grid; gap: var(--s2); }
.home-active-games .watch-game { padding: 6px; }
.analysis-toggle-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); color: var(--text); font-size: 13px; cursor: default; }
.directory-rating { color: var(--muted); font-family: var(--font-mono); font-size: 12px; margin-left: 4px; }
.featured-label { display: block; color: var(--muted); font-size: 13px; margin-bottom: var(--s2); }
.home-featured { width: 100%; max-width: none; margin: 0; }
.home-featured .featured-label { margin-bottom: 4px; }
.home-featured .watch-game { padding: 6px; gap: 3px; }
.home-featured .watch-game-preview { max-width: 140px; margin: 0 auto; }
.home-featured .watch-game-players,
.home-featured .watch-game-time-control,
.home-featured .watch-game-status { font-size: 11px; }
.player-directory-row { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(300px, 2fr) 100px; align-items: center; gap: var(--s3); width: 100%; padding: 10px 12px; border: 0; background: var(--surface-2); border-radius: var(--r-sm); color: var(--text); text-align: left; cursor: pointer; }
.player-directory-row:hover, .player-directory-row:focus-visible { background: var(--surface-3); color: var(--text-bright); }
.player-directory-name { color: var(--text-bright); font-weight: 600; }
.player-ratings-inline { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s2); font-family: var(--font-mono); font-size: 12px; }
.player-rating-inline { white-space: nowrap; }
.time-control-symbol { color: var(--muted); font-family: "lichess-icons"; font-size: 18px; vertical-align: middle; }
.player-record { color: var(--muted); font-size: 12px; text-align: right; }

.leaderboard-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s4); min-height: calc(100vh - 190px); align-items: stretch; }
#leaderboard { max-width: 1400px; width: 100%; }
.leaderboard-panel { background: var(--surface); padding: var(--s5); border-radius: var(--r-md); min-width: 0; }
.leaderboard-panel h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 var(--s3); color: var(--text-bright); font-size: 24px; }
.leaderboard-panel h2 .time-control-symbol { font-size: 28px; }
.leaderboard-panel table { table-layout: fixed; }
.leaderboard-panel th:nth-child(1), .leaderboard-panel td:nth-child(1) { width: 2.5em; }
.leaderboard-panel th:nth-child(3), .leaderboard-panel td:nth-child(3) { width: 4.5em; }
.leaderboard-panel th:nth-child(2), .leaderboard-panel td:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard-panel th, .leaderboard-panel td { font-size: 16px; }
.leaderboard-panel table { width: 100%; border-collapse: collapse; }
.leaderboard-panel th, .leaderboard-panel td { padding: 7px 4px; text-align: left; border-bottom: 1px solid var(--border); }
.leaderboard-panel th:last-child, .leaderboard-panel td:last-child { text-align: right; }
.leaderboard-player { border: 0; background: transparent; color: var(--accent); padding: 0; cursor: pointer; font: inherit; }
.leaderboard-player:hover { text-decoration: underline; }
.analysis-source { box-shadow: inset 0 0 0 4px rgba(110, 170, 110, .7); }
.analysis-destination { box-shadow: inset 0 0 0 4px rgba(110, 170, 110, .85); }
.time-control-symbol::before { content: attr(data-icon); }

.in-game-notice {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin: 0 0 var(--s4);
  padding: var(--s3) var(--s4);
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--r-md);
  color: var(--text-bright);
  font-size: 18px;
  font-weight: 700;
}
.in-game-notice > span { margin-right: auto; }
.challenge-incoming-actions { display: flex; gap: var(--s2); }

@media (min-width: 1000px) {
  #home { width: 100%; max-width: none; }
}

/* ---------------------------------------------------------------------------
   History list
--------------------------------------------------------------------------- */
.history-list {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}
.profile-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: var(--s5);
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
  align-items: start;
}
.profile-ratings-side { grid-column: 1; }
.profile-history-column { grid-column: 2; min-width: 0; }
.profile-history-column .history-list { max-width: none; margin: 0; }
.profile-layout > .history-list { grid-column: 2; }
.profile-layout > .history-list { min-width: 0; }
.profile-layout > .history-list { max-width: none; margin: 0; }
.profile-layout .history-row { grid-template-columns: 260px 58px minmax(320px, 1fr) 94px 76px 150px; }
.history-empty { color: var(--muted); text-align: center; padding: var(--s6) 0; }
.history-row {
  display: grid;
  grid-template-columns: 64px 1fr 70px 90px 150px;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background 0.15s;
}
.history-row.history-row-active {
  width: 100%;
  color: var(--text);
  font: inherit;
  text-align: left;
}
.history-row:hover { background: var(--surface-2); }
.hist-outcome { font-weight: 700; font-size: 17px; }
.hist-outcome.playing { color: #7fd07f; }
.history-main { min-width: 0; }
.hist-outcome.win { color: #7fd07f; }
.hist-outcome.loss { color: #ef6a6a; }
.hist-outcome.draw { color: var(--muted); }
.hist-opp { display: grid; grid-template-columns: minmax(0, auto) auto minmax(0, auto); justify-content: center; align-items: start; gap: 6px; color: var(--text); font-weight: 600; font-size: 19px; }
.profile-game-preview { display: block; width: 260px; }
.profile-game-preview .watch-game-preview { display: grid; width: 100%; }
.profile-player-card { display: flex; min-width: 0; flex-direction: column; align-items: flex-start; gap: 3px; }
.profile-player-card.red { align-items: flex-end; text-align: right; }
.profile-player-versus { padding-top: 2px; color: var(--muted); font-size: 16px; font-weight: 500; line-height: 1; }
.profile-player-rating { display: flex; gap: 6px; color: var(--muted); font-family: var(--font-mono); font-size: 12px; line-height: 1.2; }
.profile-game-filters { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 8px; margin-bottom: var(--s4); padding: 12px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); }
.profile-game-filters .input { width: 100%; min-width: 0; font-size: 12px; }
.profile-filter-search { grid-column: span 3; display: grid; gap: 4px; color: var(--muted); font-size: 11px; }
.profile-filter-options { grid-column: span 3; display: flex; flex-wrap: wrap; align-content: start; gap: 5px 10px; min-width: 0; margin: 0; padding: 5px 8px 8px; border: 1px solid var(--border); border-radius: var(--r-sm); }
.profile-filter-speeds { grid-column: span 6; }
.profile-filter-options legend { padding: 0 4px; color: var(--muted); font-size: 11px; }
.profile-filter-options label { display: inline-flex; align-items: center; gap: 3px; color: var(--text); font-size: 12px; white-space: nowrap; }
.profile-filter-range { grid-column: span 4; display: grid; grid-template-columns: minmax(78px, auto) minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 5px; color: var(--muted); font-size: 11px; }
#profileFiltersClear { grid-column: 11 / -1; }
.profile-game-player { display: block; max-width: 100%; overflow-wrap: anywhere; border: 0; padding: 0; background: transparent; color: inherit; font: inherit; font-weight: inherit; line-height: 1.25; cursor: pointer; text-align: inherit; }
.profile-game-player:hover, .profile-game-player:focus-visible { color: var(--primary); text-decoration: underline; }
.hist-tc { display: grid; grid-template-rows: 24px auto; justify-items: center; align-items: center; gap: 3px; color: var(--muted); font-family: var(--font-mono); font-size: 13px; text-align: center; }
.hist-tc .time-control-symbol { display: block; min-width: 24px; font-size: 20px; line-height: 24px; text-align: center; }
.hist-tc .infinite-symbol { font-family: var(--font-sans); font-size: 24px; }
.hist-rating { color: var(--text); font-family: var(--font-mono); font-size: 14px; }
.hist-rating small { font-weight: 700; }
.hist-rating .delta-pos { color: #7fd07f; }
.hist-rating .delta-neg { color: #ef6a6a; }
.hist-date { color: var(--muted); font-size: 12px; text-align: right; }
.player-rating-preview { color: var(--muted); font-weight: 500; white-space: nowrap; margin-left: 6px; }
.rating-delta { margin-left: 4px; }
.game-time-control { color: var(--muted); font-family: var(--font-mono); font-size: 13px; }
.game-status-hidden { min-height: 0; height: 0; overflow: hidden; margin: 0 !important; padding: 0 !important; }
.private-game-panel + .lobby__start { margin-top: var(--s4); }
.analysis-data { display: grid; gap: 6px; margin-top: var(--s3); }
.analysis-data label { display: block; color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.analysis-data .input { font-family: var(--font-mono); font-size: 11px; }
.analysis-player { justify-content: space-between; margin: 0 0 var(--s2); }
.analysis-player + .board-wrap + .analysis-player { margin: var(--s2) 0 0; }
.analysis-line { display: block; min-width: 0; }
.analysis-root-line { margin-bottom: 2px; }
.analysis-move-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) minmax(0, 1fr);
  align-items: stretch;
  min-height: 32px;
}
.analysis-move-row:nth-child(odd) { background: rgba(255, 255, 255, 0.02); }
.analysis-move-row .num {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
}
.analysis-move-slot { min-width: 0; }
.analysis-branch {
  margin: 3px 0 3px 14px;
  padding-left: 7px;
  border-left: 2px solid var(--border);
  background: transparent;
}
.analysis-context-menu { position: fixed; z-index: 20; display: grid; gap: 2px; padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); box-shadow: var(--shadow); }
.analysis-context-menu button { border: 0; background: transparent; color: var(--text); padding: 7px 9px; text-align: left; cursor: pointer; white-space: nowrap; }
.analysis-context-menu button:hover { background: var(--surface-2); }
.analysis-context-menu button span { display: inline-block; width: 20px; }
.analysis-tree-move { border: 0; border-radius: 3px; padding: 5px 7px; background: transparent; color: var(--text); cursor: pointer; font: inherit; text-align: left; min-width: 0; }
.analysis-tree-move:hover { background: var(--surface-3); }
.analysis-tree-move.current { background: var(--primary); color: #fff; }
.analysis-invite { display: grid; gap: var(--s2); }
.analysis-invite #analysisInvitePanel { display: grid; gap: var(--s2); }
.captured-pieces { display: flex; align-items: center; justify-content: space-between; gap: 4px; min-height: 32px; margin: 4px 0 8px; color: var(--muted); font-size: 11px; }
.captured-left { position: absolute; right: calc(100% + 8px); top: 50%; width: 108px; transform: translateY(-50%); display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: stretch; justify-content: initial; min-height: 0; margin: 0; }
.captured-type { display: flex; width: 100%; min-width: 0; min-height: 100%; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.captured-type-label { color: var(--muted); font-size: 10px; line-height: 1; text-transform: capitalize; }
.captured-type-pieces { display: flex; width: 100%; align-content: center; justify-content: center; flex-wrap: wrap; gap: 2px; min-height: 36px; }
.captured-left .captured-piece { width: 38px; height: 38px; }
@media (max-width: 560px) {
  .board-with-captured { display: flex; flex-direction: column-reverse; align-items: stretch; }
  .board-with-captured .captured-left { position: static; width: 100%; transform: none; grid-template-columns: repeat(3, minmax(0, 1fr)); min-height: 44px; }
  .board-with-captured .captured-left .captured-type { width: 100%; }
}
.captured-side { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; min-height: 32px; }
.captured-side-red { justify-content: flex-end; }
.captured-label { margin-right: 4px; }
.captured-piece { display: inline-flex; width: 36px; height: 36px; opacity: .82; }
.captured-piece svg { width: 100%; height: 100%; }
.leaderboard-you-row { background: rgba(98, 153, 36, .18); }
#watch, #players, #leaderboard, #explorer, #editor { padding-top: 0; position: relative; }
#watch .screen-head, #players .screen-head, #leaderboard .screen-head, #explorer .screen-head, #editor .screen-head {
  margin: 0 0 2px;
  transform: translateX(-12px);
}

@media (min-width: 700px) {
  #watch .screen-head, #players .screen-head, #leaderboard .screen-head, #explorer .screen-head, #editor .screen-head {
    position: absolute;
    top: 4px;
    left: -30px;
    margin: 0;
    transform: none;
    z-index: 5;
  }
  /* The editor clips its contents; keep the back control inside the screen
   * instead of placing it at a negative x-coordinate. */
  #editor .screen-head { left: -30px; z-index: 1000; }
}

@media (max-width: 699px) {
  #watch .screen-head, #players .screen-head, #leaderboard .screen-head, #explorer .screen-head, #editor .screen-head {
    transform: translateX(max(-12px, calc(8px - var(--s4))));
  }
}

/* Profile panel (per-time-control ratings + volatility) */
.profile-panel {
  max-width: 1500px;
  margin: 0 auto var(--s4);
}
.profile-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s4);
}
.profile-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s3);
}
.profile-name { font-size: 20px; font-weight: 700; color: var(--text-bright); }
.profile-meta { font-size: 13px; color: var(--muted); font-family: var(--font-mono); }
.profile-actions { display: flex; gap: var(--s2); margin-bottom: var(--s3); }
.profile-ratings-side {
  min-width: 0;
  padding: 0;
  background: transparent;
  border: 0;
}
.profile-ratings-side h2 { display: none; }
.profile-ratings {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s2);
}
.profile-rating {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--s3) var(--s2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
}
.profile-rating-label { font-size: 13px; font-weight: 700; color: var(--text); text-transform: uppercase; letter-spacing: 0.4px; }
.profile-crown { color: #e5b93f; font-size: 18px; margin-left: 5px; cursor: help; }
.profile-rating-label .time-control-symbol { margin-right: 3px; }
.profile-rating-value { font-size: 22px; font-weight: 700; font-family: var(--font-mono); color: var(--text-bright); }
.profile-rating-rank { font-size: 14px; color: var(--muted); font-family: var(--font-mono); }
.profile-rating-rd { font-size: 12px; color: var(--muted); font-family: var(--font-mono); }
.profile-rating-range { font-size: 11px; color: var(--c-font-dimmer); }
.rating-stats-card { max-width: 850px; margin: 0 auto; padding: var(--s5); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); }
.rating-stats-card h2 { margin: 0; color: var(--text-bright); }
.rating-stat-description { color: var(--muted); }
.rating-stat-summary { display: flex; flex-wrap: wrap; gap: var(--s5); margin: var(--s4) 0; font-family: var(--font-mono); }
.rating-stat-summary strong { color: var(--text-bright); font-size: 20px; }
.rating-stat-chart svg { display: block; width: 100%; min-height: 220px; }
.rating-stat-chart line:first-child { stroke: var(--border); }
.rating-stat-chart polygon { fill: rgba(90,145,220,.22); }
.rating-stat-chart polyline { fill: none; stroke: var(--primary); stroke-width: 3; }
.rating-stat-chart .rating-player-line { stroke: #e2a52b; stroke-width: 2; stroke-dasharray: 5 4; }
.rating-stat-chart .rating-player-point { fill: #e2a52b; stroke: var(--surface); stroke-width: 2; }
.rating-stat-chart .rating-player-label { fill: var(--text-bright); font: 14px var(--font-mono); }
@media (max-width: 560px) {
  .mail-panel { right: 8px; }
  .challenge-incoming { align-items: flex-start; flex-direction: column; }
  .challenge-incoming-actions { width: 100%; }
  .challenge-incoming-actions .btn { flex: 1; }
}

/* One shared anchor for the section back controls.  Keep this at the end so
 * earlier per-screen layout rules cannot move one of them independently. */
#watch .screen-head, #players .screen-head, #leaderboard .screen-head, #explorer .screen-head, #editor .screen-head {
  position: absolute;
  top: 4px;
  left: -30px;
  margin: 0;
  transform: none;
  z-index: 1000;
}
@media (max-width: 699px) {
  #watch .screen-head, #players .screen-head, #leaderboard .screen-head, #explorer .screen-head, #editor .screen-head {
    left: -8px;
  }
}
@media (max-width: 1360px) {
  .profile-layout { grid-template-columns: 1fr; }
  .profile-ratings-side { order: -1; }
  .profile-history-column { grid-column: 1; }
  .profile-layout .history-row { grid-template-columns: 180px 56px minmax(220px, 1fr) 84px 70px; }
  .profile-game-preview, .profile-game-preview .watch-game-preview { width: 180px; }
  .profile-layout .history-row .hist-date { grid-column: 3 / -1; text-align: right; }
  .profile-filter-search, .profile-filter-options, .profile-filter-speeds { grid-column: span 6; }
  .profile-filter-range { grid-column: span 6; }
}
@media (max-width: 560px) {
  .profile-layout { gap: var(--s3); }
  .profile-layout .history-row { grid-template-columns: 96px minmax(0, 1fr) auto; gap: 8px; padding: 8px; }
  .profile-game-preview, .profile-game-preview .watch-game-preview { width: 96px; }
  .profile-layout .history-row .profile-game-preview { grid-column: 1; grid-row: 1 / span 4; }
  .profile-layout .history-row .hist-outcome { grid-column: 2; grid-row: 1; }
  .profile-layout .history-row .history-main { grid-column: 2 / -1; grid-row: 2; }
  .profile-layout .history-row .hist-tc { grid-column: 2; grid-row: 3; justify-self: start; }
  .profile-layout .history-row .hist-rating { grid-column: 3; grid-row: 3; }
  .profile-layout .history-row .hist-date { grid-column: 2 / -1; grid-row: 4; text-align: left; }
  .profile-game-filters { grid-template-columns: 1fr; }
  .profile-filter-search, .profile-filter-options, .profile-filter-speeds, .profile-filter-range, #profileFiltersClear { grid-column: 1; }
  .profile-filter-range { grid-template-columns: 1fr 1fr auto 1fr; }
  .profile-ratings { grid-template-columns: repeat(2, 1fr); }
  .watch-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .player-directory-row { grid-template-columns: 1fr; gap: var(--s2); }
  .player-ratings-inline { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 561px) and (max-width: 1000px) {
  .watch-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .leaderboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .leaderboard-grid { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------------------
   Auth modal
--------------------------------------------------------------------------- */
.modal { position: fixed; inset: 0; z-index: 1500; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.6); }
.modal-card {
  position: relative;
  width: min(92vw, 380px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s5);
  box-shadow: var(--shadow);
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { color: var(--text-bright); }
.auth-card { width: min(92vw, 480px); padding: var(--s6); }
.auth-card .auth-tabs { padding-right: 40px; }
.auth-card #authForm { padding-top: var(--s2); }
.auth-card #authPassword { margin-bottom: var(--s2); }
.auth-card #authSubmit { margin-top: var(--s2); }
.settings-card { width: min(92vw, 420px); }
.settings-card h2 { margin: 0 0 var(--s4); color: var(--text-bright); }
.settings-volume-row { display: flex; align-items: center; gap: var(--s3); }
.settings-volume-row input[type="range"] { flex: 1; accent-color: var(--primary); }
.settings-volume-row output { min-width: 3.5em; color: var(--text-bright); font-family: var(--font-mono); text-align: right; }
.auth-tabs { display: flex; gap: var(--s2); margin-bottom: var(--s4); }
.auth-tab {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}
.auth-tab.active { background: var(--surface-3); color: var(--text-bright); border-color: var(--accent); }
.auth-tab:hover { color: var(--text-bright); }

/* ---------------------------------------------------------------------------
   Quick pairing & opening explorer
--------------------------------------------------------------------------- */
.queue-status {
  margin-top: var(--s2);
  padding: 9px 12px;
  border-radius: var(--r-md);
  background: #23406b;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}

/* Lobby — lichess-style main page */
.lobby {
  --cols: 1;
  display: grid;
  grid-template-areas:
    "app"
    "table"
    "side"
    "about";
  gap: var(--block-gap);
  align-items: start;
}

.lobby__side { grid-area: side; display: flex; flex-direction: column; gap: var(--block-gap); min-width: 0; }
.lobby__app { grid-area: app; min-width: 0; }
.lobby__table { grid-area: table; }
.lobby__about { grid-area: about; }

@media (min-width: 800px) {
  .lobby {
    --cols: 2;
    grid-template-columns: 34% 1fr;
    grid-template-areas:
      "table app"
      "side app"
      "about about";
  }
}
@media (min-width: 1260px) {
  .lobby {
    --cols: 3;
    grid-template-columns: 320px 1fr 320px;
    grid-template-areas:
      "side app table"
      "about about about";
  }
}

/* Center: lobby pools */
.lobby__app {
  min-height: 540px;
  display: flex;
  flex-direction: column;
}
.tabs-horiz {
  display: none;
  justify-content: center;
  align-items: flex-end;
  margin-bottom: var(--s2);
}
.tabs-horiz > span {
  flex: 1 1 auto;
  text-align: center;
  padding: 0.5em 0.2em;
  border-bottom: 2px solid transparent;
  color: var(--c-font-dim);
}

.lobby__app__content {
  position: relative;
  flex: 1;
  min-height: 500px;
  overflow-y: auto;
  background: var(--c-bg);
  border-radius: var(--ui-roundness);
  box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.08), 0 3px 1px -2px rgba(0, 0, 0, 0.18), 0 1px 5px 0 rgba(0, 0, 0, 0.1);
}

.lpools {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: minmax(96px, 1fr);
  gap: 9px;
  padding: 9px;
  min-height: 100%;
  font-size: 14px;
}

.lpool {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  color: var(--c-font-dim);
  background: var(--c-pool-button);
  border: none;
  border-radius: var(--ui-roundness);
  padding: 0.4em 0.5em;
  transition: all 150ms ease;
  font-family: var(--font-sans);
  text-align: center;
}
.lpool:hover {
  color: var(--c-font);
  background: var(--c-accent-glass);
}
.lpool.active {
  color: var(--c-font-clear);
  background: var(--c-accent-cloud);
}
.lpool-name {
  font-weight: 600;
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.lpool-rating { color: inherit; font-family: var(--font-mono); font-size: 13px; opacity: 0.85; }
.lpool-mode {
  color: var(--muted);
  background: transparent;
  border-radius: 0;
  padding: 1px 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.lpool-mode.casual { background: transparent; }
.lpool .clock {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.5em;
  line-height: 1.4em;
  letter-spacing: 0.1em;
  color: inherit;
}
.infinite-symbol { font-size: 1.15em; line-height: 1; margin-right: 4px; }

.lobby-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  color: var(--c-font-dim);
  font-size: 14px;
  text-align: center;
  padding: var(--s5);
  pointer-events: none;
}
.lobby-count { color: var(--c-font-dim); font-size: 13px; }

/* Right: start buttons */
.lobby__table { display: flex; flex-direction: column; gap: var(--block-gap); }
.lobby__start { display: flex; flex-direction: column; gap: 9px; }

.button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 1em;
  font-family: var(--font-sans);
  font-size: 1.1em;
  font-weight: bold;
  padding: 0.8em 1.3em;
  border: none;
  border-radius: var(--ui-roundness);
  cursor: pointer;
  color: var(--c-font-clear);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
  transition: all 150ms ease;
}
.button-metal {
  background: linear-gradient(to bottom, var(--c-metal-top), var(--c-metal-bottom));
  box-shadow: inset 0 1px 3px -2px hsl(0, 0%, 45%), inset 0 -4px 8px -3px rgba(0, 0, 0, 0.6), 0 1px 3px 0 rgba(0, 0, 0, 0.2);
}
.button-metal:hover {
  background: linear-gradient(to bottom, var(--c-metal-top-hover), var(--c-metal-bottom-hover));
  color: var(--c-font-clearer);
}

.lobby__start__button {
  font-size: 1.2em;
  gap: 1em;
  padding: 0.4em 1.5em;
  height: 3.2em;
  letter-spacing: 0;
}
.lobby__start__icon { flex: 0 0 auto; width: 26px; height: 26px; color: var(--c-font-dimmer); }
.lobby__start__button:hover .lobby__start__icon { color: var(--c-accent); }

.lobby__counters {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 1.4em;
}

/* Left: boxes + about */
.lobby__box {
  background: var(--c-bg);
  border-radius: var(--ui-roundness);
  overflow: hidden;
  box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.08), 0 3px 1px -2px rgba(0, 0, 0, 0.18), 0 1px 5px 0 rgba(0, 0, 0, 0.1);
}
.lobby__box__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45em 0.8em;
  background: linear-gradient(to bottom, var(--c-metal-top), var(--c-metal-bottom));
  box-shadow: inset 0 1px 3px -2px hsl(0, 0%, 45%), inset 0 -4px 8px -3px rgba(0, 0, 0, 0.6);
}
.lobby__box__top .title {
  font-size: 0.95em;
  font-weight: bold;
  color: var(--c-font-dim);
  text-shadow: 0 1px 0 var(--c-font-shadow);
}
.lobby__box__content { padding: var(--s3); }

/* Public chat */
.chat-log {
  height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: var(--s2);
  font-size: 13px;
  line-height: 1.4;
  border: 1px solid var(--border);
  padding: 4px;
  background: var(--surface-2);
}
.lobby__side > .lobby__box .chat-log { height: 120px; }
.chat-msg {
  padding: 3px 6px;
  border-radius: 4px;
  word-break: break-word;
}
.chat-msg:hover { background: rgba(255, 255, 255, 0.04); }
.chat-time {
  color: var(--c-font-dimmer);
  font-family: var(--font-mono);
  font-size: 11px;
  margin-right: 6px;
}
.chat-user {
  color: var(--c-font-clear);
  font-weight: 700;
  margin-right: 6px;
}
.chat-text { color: var(--c-font); }
.chat-input-row { display: flex; gap: var(--s2); }
.chat-input-row .input { flex: 1; }

/* In-game chat */
.game-chat { display: flex; flex-direction: column; gap: var(--s2); margin-top: var(--s2); }
.game-chat-log { height: 120px; }
.takeback-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: var(--s2); }
.takeback-actions span { margin-right: auto; color: var(--muted); font-size: 13px; }
.takeback-actions button { width: 32px; height: 32px; border: 0; border-radius: var(--r-sm); color: #fff; font-size: 22px; line-height: 1; cursor: pointer; }
.takeback-yes { background: var(--primary); }
.takeback-no { background: var(--danger); }

/* Draw offer notice */
.draw-offer {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  padding: var(--s3);
  background: var(--surface-2);
  border-radius: var(--r-md);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.draw-offer-text { margin-bottom: var(--s1); }

/* New game controls (sliders, presets, rated/casual) */
.tc-sliders { display: flex; flex-direction: column; gap: var(--s3); margin-bottom: var(--s4); }
.tc-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s2); }
.tc-row label { font-size: 13px; font-weight: 600; color: var(--c-font-dim); }
.tc-val { font-family: var(--font-mono); font-size: 13px; color: var(--c-font); font-weight: 600; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: var(--c-bg-low);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--c-font-clear);
  border: 3px solid var(--c-font-dimmer);
  margin-top: -7px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
input[type="range"]::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: var(--c-bg-low);
}
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--c-font-clear);
  border: 3px solid var(--c-font-dimmer);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.tc-presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--s4); }
.tc-preset {
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--c-font-dim);
  background: var(--c-bg-low);
  border: 1px solid var(--c-border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 150ms ease;
  font-family: var(--font-sans);
}
.tc-preset:hover { color: var(--c-font-clear); background: var(--c-bg-mid); }
.tc-preset.active { color: var(--c-font-clearer); background: var(--c-accent-glass); border-color: var(--c-accent); }

.mode-toggle { display: flex; gap: 8px; margin-bottom: var(--s4); }
.mode-btn {
  flex: 1;
  padding: 12px 16px;
  font-size: 16px;
  font-weight: 700;
  color: var(--c-font);
  background: var(--c-bg-low);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all 150ms ease;
  font-family: var(--font-sans);
}
.mode-btn:hover { background: var(--c-bg-mid); }
.mode-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.about-side {
  color: var(--c-font-dim);
  font-size: 0.85em;
  font-weight: bold;
  line-height: 1.5;
  text-shadow: 0 1px 0 var(--c-font-shadow);
}
.about-side .about-brand { color: var(--c-font-clear); }

.lobby__about {
  display: flex;
  flex-wrap: wrap;
  gap: 1.2em;
  font-size: 0.85em;
  font-weight: bold;
  color: var(--c-font-dim);
  padding-top: var(--s2);
}
.lobby__about a { color: var(--c-font-dim); text-decoration: none; white-space: nowrap; }
.lobby__about a:hover { color: var(--c-link); }

.moves li.explorer-move {
  grid-template-columns: 2.4em 96px 1fr;
  cursor: pointer;
}
.moves li.explorer-move:hover { background: rgba(255, 255, 255, 0.04); }
.moves .move.stat { text-align: right; color: var(--muted); font-size: 12px; overflow: visible; white-space: normal; }

/* Opening explorer stat column: 3-color win/draw/loss percentage bar */
.moves li.explorer-move .stat {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  justify-content: flex-end;
}
.stat-bar {
  display: flex;
  width: 100%;
  height: 8px;
  min-width: 40px;
  border-radius: 3px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.28);
}
.stat-bar .seg { height: 100%; }
.stat-bar .seg.win { background: #4a86f7; }
.stat-bar .seg.draw { background: #9b9b9b; }
.stat-bar .seg.loss { background: #d64545; }
.stat-text {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  min-width: 2.4em;
  text-align: right;
}

/* Board editor controls */
.editor-group { display: flex; flex-direction: column; gap: var(--s2); margin-bottom: var(--s3); }
.editor-group .movelist-label { margin-bottom: 0; }
.editor-group .mode-toggle { margin-bottom: 0; }
.editor-toggle { display: flex; gap: 8px; }
.editor-toggle .mode-btn { padding: 10px 8px; font-size: 14px; }

/* Final shared positioning for all section back buttons. */
#watch .screen-head, #players .screen-head, #leaderboard .screen-head, #explorer .screen-head, #editor .screen-head {
  position: absolute;
  top: 4px;
  left: -30px;
  margin: 0;
  transform: none;
  z-index: 1000;
}
@media (max-width: 699px) {
  #watch .screen-head, #players .screen-head, #leaderboard .screen-head, #explorer .screen-head, #editor .screen-head {
    left: -8px;
    transform: none;
  }
}

/* Opening explorer: taller stat list, compact move path */
.moves.explorer-list { min-height: 192px; max-height: 420px; }

@media (max-width: 900px) {
  .game-layout { flex-direction: column; align-items: center; }
  .players-col { width: min(92vw, 560px); }
  .side { width: min(92vw, 560px); flex: auto; }
}

/* Keep the physical viewport position identical on every section. */
#watch .screen-head, #players .screen-head, #leaderboard .screen-head, #explorer .screen-head, #editor .screen-head {
  position: fixed;
  top: 64px;
  left: 10px;
  margin: 0;
  transform: none;
  z-index: 1100;
}
#watch .screen-head button, #players .screen-head button, #leaderboard .screen-head button, #explorer .screen-head button, #editor .screen-head button { display: none; }
/* Analysis collaboration controls use the same switch geometry as settings. */
.analysis-toggle-row .toggle-btn { display: inline-flex; align-items: center; width: 42px; height: 24px; min-width: 42px; padding: 0; border: 0; background: transparent; cursor: pointer; }
.analysis-toggle-row .toggle-btn .switch-track { display: block; }
.analysis-toggle-row .toggle-btn.active .switch-track { background: var(--primary); }
.analysis-toggle-row .toggle-btn.active .switch-thumb { transform: translateX(18px); background: #fff; }
.rating-stat-player-name { margin: 8px 0 0; text-align: center; color: var(--text-bright); font-family: var(--font-mono); font-weight: 700; }
