/*
 * FunPassant - "sticker book" theme.
 *
 * Comic-strip look: a yellow header with die-cut chess-piece stickers, thick
 * ink outlines with offset "sticker" shadows on cards, buttons and tables,
 * Bangers for headings and Rubik for body text. Every color comes from the
 * tokens below; the dark-mode block at the end only redefines tokens (plus a
 * few header tweaks).
 */

:root {
  --ink: #1a1a1a;            /* outlines and main text */
  --paper: #fffdf5;          /* page background */
  --card: #ffffff;           /* card / table / chart background */
  --muted: #5c5a52;          /* secondary text */
  --sun: #ffe14d;            /* header and highlights */
  --coral: #ff6b6b;
  --teal: #4ecdc4;
  --violet: #a78bfa;
  --orange: #ff9f43;
  --tint-yellow: #fff3b0;
  --tint-pink: #ffd6d6;
  --tint-teal: #d2f5f2;
  --tint-violet: #e7dfff;
  --zebra: #fff7d6;
  --dark-band: #1a1a1a;      /* table headers, active tab, tooltips */
  --on-dark-band: #ffe14d;
  --shadow-color: #1a1a1a;   /* offset sticker shadows */
  --win-text: #2e8b57;
  --loss-text: #d64545;
  --error-text: #b83227;

  --border-w: 3px;
  --radius: 10px;
  --offset: 4px;

  /* Bangers has Latin only; other scripts swap the display font below. The
     Noto fonts cover Hindi (Devanagari) and Chinese body text. */
  --display: "Bangers", "Rubik", "Noto Sans Devanagari", "Noto Sans SC", sans-serif;
  --sans: "Rubik", -apple-system, "Noto Sans Devanagari", "Noto Sans SC", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "Noto Sans Devanagari", "Noto Sans SC", monospace;
  --pieces: "Noto Sans Symbols 2", "Segoe UI Symbol", "DejaVu Sans", serif;
}

:root:lang(ru) { --display: "Russo One", "Rubik", sans-serif; }
:root:lang(hi-IN), :root:lang(hi) { --display: "Baloo 2", "Noto Sans Devanagari", sans-serif; }
:root:lang(zh-CN), :root:lang(zh) { --display: "ZCOOL KuaiLe", "Noto Sans SC", sans-serif; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}

/* The shared "sticker": ink outline, rounded corners, hard offset shadow. */
.sidebar-section,
.win-rate-stat-tile,
.table-wrap,
.win-rate-chart-wrap,
.graph-container {
  background: var(--card);
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--offset) var(--offset) 0 var(--shadow-color);
}

/* ---------- top bar ---------- */

.topbar {
  background: var(--sun);
  color: var(--ink);
  border-bottom: var(--border-w) solid var(--ink);
}

.topbar-inner {
  position: relative;
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.topbar h1 {
  font-family: var(--display);
  font-weight: 400;
  font-size: 2.6rem;
  line-height: 1;
  letter-spacing: 0.03em;
  margin: 0;
}

.app-version {
  display: inline-block;
  margin-left: 0.6em;
  vertical-align: middle;
  font-family: var(--display);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  padding: 1px 7px;
  background: var(--card);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 6px;
  box-shadow: 2px 2px 0 var(--shadow-color);
  transform: rotate(-4deg);
}

/* Die-cut chess-piece stickers, purely decorative. */
.header-stickers {
  position: absolute;
  top: 10px;
  right: 24px;
  height: 64px;
  width: 250px;
  pointer-events: none;
}

.sticker {
  position: absolute;
  font-family: var(--pieces);
  line-height: 1.1;
  color: #ffffff;
  padding: 0 6px;
  border: var(--border-w) solid var(--ink);
  border-radius: 12px;
  box-shadow: 3px 3px 0 var(--shadow-color);
}

.sticker-1 { right: 190px; top: 2px; font-size: 40px; background: var(--coral); transform: rotate(-12deg); }
.sticker-2 { right: 128px; top: 12px; font-size: 34px; background: var(--teal); transform: rotate(9deg); }
.sticker-3 { right: 62px; top: 0; font-size: 38px; background: var(--violet); transform: rotate(-6deg); }
.sticker-4 { right: 4px; top: 18px; font-size: 28px; background: var(--orange); transform: rotate(14deg); }

.header-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 22px;
}

.chesscom-control {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.text-input,
.language-select,
.filter-select {
  font-family: var(--sans);
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 8px;
  box-shadow: 2px 2px 0 var(--shadow-color);
}

.text-input {
  padding: 8px 12px;
  min-width: 200px;
}

.text-input::placeholder { color: var(--muted); }

.text-input:focus-visible,
.filter-select:focus-visible,
.language-select:focus-visible {
  outline: 3px solid var(--coral);
  outline-offset: 2px;
}

.username-field-wrap {
  position: relative;
  display: inline-flex;
}

.username-field-wrap .text-input {
  border-radius: 8px 0 0 8px;
}

.username-dropdown-btn {
  padding: 0 10px;
  border: 2px solid var(--ink);
  border-left: none;
  border-radius: 0 8px 8px 0;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.7rem;
  box-shadow: 2px 2px 0 var(--shadow-color);
}

.username-dropdown-btn:hover { background: var(--zebra); }

.username-dropdown-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 6px 0 0;
  padding: 4px 0;
  list-style: none;
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 8px;
  box-shadow: 3px 3px 0 var(--shadow-color);
  max-height: 220px;
  overflow-y: auto;
  z-index: 20;
}

.username-dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 8px 7px 12px;
  font-size: 0.88rem;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}

.username-dropdown-item:hover { background: var(--zebra); }

.username-dropdown-item-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.username-dropdown-item-remove {
  flex: 0 0 auto;
  padding: 2px 6px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
}

.username-dropdown-item-remove:hover {
  color: var(--card);
  background: var(--coral);
}

.username-dropdown-empty {
  padding: 7px 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.file-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
}

/* Chunky sticker buttons. */
.btn {
  font-family: var(--display);
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  color: #ffffff;
  background: var(--coral);
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 6px 16px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 3px 3px 0 var(--shadow-color);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

#chooseFileBtn {
  background: var(--teal);
  color: #1a1a1a;
}

.btn:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--shadow-color);
}

.btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--shadow-color);
}

.btn:disabled { opacity: 0.6; cursor: progress; }

.btn:focus-visible, .btn-link:focus-visible, .tab-btn:focus-visible {
  outline: 3px solid var(--coral);
  outline-offset: 2px;
}

.language-select {
  padding: 6px 8px;
  cursor: pointer;
}

.language-select option {
  color: #1a1a1a;
  background: #ffffff;
}

.ignore-bots-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}

.ignore-bots-control input {
  accent-color: var(--coral);
  width: 17px;
  height: 17px;
  margin: 0;
  cursor: pointer;
}

.file-name {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: #4a4200;
}

.pawn-spinner {
  display: inline-block;
  font-family: var(--pieces);
  font-size: 1.5rem;
  line-height: 1;
  color: var(--ink);
  animation: pawn-spin 0.9s linear infinite;
  transform-origin: 50% 55%;
}

.pawn-spinner[hidden] { display: none; }

@keyframes pawn-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.chesscom-status {
  margin: 6px 0 0;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--muted);
  white-space: pre-line;
}

.chesscom-status.is-error { color: var(--error-text); }
.chesscom-status.is-cache { color: #8a6d1e; }
.chesscom-status.is-network { color: var(--win-text); }

/* ---------- top players ticker (topPlayers.js) ---------- */

.top-players:not([hidden]) {
  display: flex;
  align-items: stretch;
  background: var(--dark-band);
  color: #fffdf5;
  border-bottom: var(--border-w) solid var(--ink);
  font-size: 0.88rem;
}

.top-players-menu-wrap {
  position: relative;
  flex: none;
  display: flex;
  z-index: 15;
}

.top-players-label {
  font-family: var(--display);
  font-size: 1.1rem;
  letter-spacing: 0.04em;
  color: #ffffff;
  background: var(--coral);
  border: none;
  border-right: var(--border-w) solid var(--ink);
  padding: 4px 14px;
  cursor: pointer;
  white-space: nowrap;
}

.top-players-label:hover { filter: brightness(1.08); }

.top-players-label:focus-visible {
  outline: 3px solid var(--sun);
  outline-offset: -4px;
}

.top-players-menu {
  position: absolute;
  top: 100%;
  left: 8px;
  margin-top: 6px;
  min-width: 150px;
  padding: 4px 0;
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 8px;
  box-shadow: 3px 3px 0 var(--shadow-color);
}

.top-players-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  font-family: var(--sans);
  font-size: 0.9rem;
  color: var(--ink);
  background: none;
  border: none;
  padding: 7px 14px;
  cursor: pointer;
}

.top-players-menu-item::first-letter { text-transform: uppercase; }
.top-players-menu-item:hover { background: var(--zebra); }

.top-players-menu-item[aria-checked="true"] {
  font-weight: 600;
  box-shadow: inset 4px 0 0 var(--coral);
}

.top-players-viewport {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

/* Two copies of the list side by side, sliding left by one copy's width,
   so the loop is seamless. Hover or keyboard focus pauses it. */
.top-players-track {
  display: flex;
  width: max-content;
  animation: top-players-scroll 40s linear infinite;
}

.top-players-track:hover,
.top-players-track:focus-within {
  animation-play-state: paused;
}

@keyframes top-players-scroll {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

.top-players-group {
  display: flex;
  gap: 6px;
  padding-right: 6px;
}

.top-player {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--sans);
  font-size: 0.88rem;
  color: #fffdf5;
  background: none;
  border: none;
  border-radius: 6px;
  padding: 7px 10px;
  cursor: pointer;
  white-space: nowrap;
}

.top-player:hover .top-player-name,
.top-player:focus-visible .top-player-name {
  text-decoration: underline;
  text-decoration-color: var(--coral);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.top-player:focus-visible {
  outline: 2px solid var(--sun);
  outline-offset: -2px;
}

.top-player-rank { color: #b8b4a8; font-weight: 600; }

.top-player-title {
  font-size: 0.68rem;
  font-weight: 600;
  color: #1a1a1a;
  background: var(--sun);
  border-radius: 3px;
  padding: 0 4px;
}

.top-player-name { font-weight: 500; }
.top-player-detail { color: var(--sun); font-variant-numeric: tabular-nums; }

/* For visitors who've asked for less motion: no scrolling; the row can be
   scrolled by hand, and the duplicate copy isn't needed. */
@media (prefers-reduced-motion: reduce) {
  .top-players-track { animation: none; }
  .top-players-viewport { overflow-x: auto; }
  .top-players-group[aria-hidden="true"] { display: none; }
}

.btn-surprise {
  background: var(--violet);
  color: #ffffff;
}

.btn-surprise[hidden],
#chooseFileBtn[hidden] { display: none; }

.btn-piece { font-family: var(--pieces); }

/* ---------- content ---------- */

.content {
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

.empty-state p, .error-state p {
  font-size: 1.15rem;
  max-width: 60ch;
  margin: 0;
  padding: 18px 22px;
  background: var(--card);
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--offset) var(--offset) 0 var(--shadow-color);
}

.error-state p {
  color: var(--error-text);
  background: var(--tint-pink);
}

code {
  font-family: var(--mono);
  background: var(--tint-yellow);
  border: 1.5px solid var(--ink);
  padding: 0 5px;
  border-radius: 4px;
}

/* Results: a left column (what's loaded, then the filters) beside the
   tabs. On narrow screens the column stacks above the tabs. */
.results:not([hidden]) {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  column-gap: 36px;
  align-items: start;
}

.sidebar {
  min-width: 0;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 16px;
  margin-bottom: 22px;
}

.sidebar-section:nth-child(2) {
  background: var(--tint-violet);
}

.sidebar-section > * {
  /* Lets long lines (the download status, file dates) wrap instead of
     widening the column. */
  min-width: 0;
}

.main-panel {
  min-width: 0;
}

/* Two counts side by side ("Games loaded" / "Opponents faced"). */
.meta-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.meta-pair .meta-value {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.8rem;
  line-height: 1.1;
  letter-spacing: 0.03em;
}

@media (max-width: 860px) {
  .results:not([hidden]) {
    grid-template-columns: minmax(0, 1fr);
  }
}

.time-control-treemap-wrap { min-width: 0; }

.time-control-treemap-container {
  position: relative;
  margin-top: 4px;
  height: 110px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--card);
}

#timeControlTreemapSvg,
#filteredTimeControlTreemapSvg {
  width: 100%;
  height: 100%;
  display: block;
}

.time-control-treemap-cell {
  stroke: var(--ink);
  stroke-width: 1.5px;
  cursor: default;
}

.games-histogram-wrap { min-width: 0; }

.games-histogram-container {
  position: relative;
  margin-top: 4px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--card);
  overflow: hidden;
}

#gamesHistogramSvg {
  display: block;
  width: 100%;
}

.games-histogram-bar {
  fill: var(--violet);
  stroke: var(--ink);
  stroke-width: 1.5px;
  cursor: default;
}

.games-histogram-bar:hover { fill: var(--coral); }

/* ---------- headings and text ---------- */

h2, h3 {
  font-family: var(--display);
  font-weight: 400;
  letter-spacing: 0.03em;
  line-height: 1.1;
}

h2 {
  font-size: 1.9rem;
  margin: 0 0 6px;
}

h3 {
  font-size: 1.55rem;
  margin: 24px 0 10px;
}

.subtle {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

.meta-label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.meta-value {
  display: block;
  font-weight: 500;
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 6px;
  padding-bottom: 14px;
  margin-bottom: 26px;
  border-bottom: var(--border-w) solid var(--ink);
}

.tab-btn {
  font-family: var(--display);
  font-size: 1.2rem;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: none;
  border: var(--border-w) solid transparent;
  border-radius: var(--radius);
  padding: 3px 12px;
  cursor: pointer;
}

.tab-btn:hover { color: var(--ink); }

.tab-btn.is-active {
  color: var(--on-dark-band);
  background: var(--dark-band);
  border-color: var(--ink);
  box-shadow: 3px 3px 0 var(--coral);
}

.tab-panel[hidden] { display: none; }

/* ---------- Where are They Now tab ---------- */

.where-now-group { margin-bottom: 40px; }
.where-now-group h3 { margin: 0 0 6px; }
.where-now-blank { cursor: help; }
.where-now-loading { white-space: normal; }

.where-now-change {
  margin-left: 6px;
  font-size: 0.8rem;
  font-weight: 500;
}

/* ---------- stat tiles (Win Rate Trends and Fun Facts) ---------- */

.win-rate-trends-group { margin-bottom: 40px; }
.win-rate-trends-group h3 { margin: 0 0 14px; }

.win-rate-stat-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.win-rate-stat-tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 128px;
  padding: 10px 14px;
}

/* Tiles cycle through the sticker tints. */
.win-rate-stat-tile:nth-child(4n + 1) { background: var(--tint-yellow); }
.win-rate-stat-tile:nth-child(4n + 2) { background: var(--tint-teal); }
.win-rate-stat-tile:nth-child(4n + 3) { background: var(--tint-violet); }
.win-rate-stat-tile:nth-child(4n + 4) { background: var(--tint-pink); }

.win-rate-stat-tile .meta-value { font-size: 1.35rem; }

.win-rate-chart-wrap {
  position: relative;
  padding: 10px 10px 6px;
}

.win-rate-chart-wrap + .win-rate-chart-wrap { margin-top: 16px; }

.win-rate-chart-title {
  font-family: var(--display);
  font-size: 1.1rem;
  letter-spacing: 0.03em;
  color: var(--ink);
  margin-bottom: 6px;
}

#winRateTrendsContent svg {
  width: 100%;
  display: block;
}

.win-rate-bar {
  stroke: var(--ink);
  stroke-width: 1.5px;
  cursor: default;
}

.win-rate-reference-line {
  stroke: var(--muted);
  stroke-width: 1px;
  stroke-dasharray: 4 3;
  pointer-events: none;
}

.elo-comparison-connector {
  stroke: var(--muted);
  stroke-width: 1.5px;
  pointer-events: none;
}

.elo-comparison-dot-main,
.elo-comparison-dot-opponent {
  stroke: var(--ink);
  stroke-width: 1.5px;
  cursor: default;
}

.elo-comparison-dot-main { fill: #3a6ea5; }
.elo-comparison-dot-opponent { fill: #b0aa98; }

.elo-comparison-diff-label,
.elo-comparison-dot-label-main,
.elo-comparison-dot-label-opponent,
.move-range-label {
  font-family: var(--sans);
  stroke: var(--card);
  stroke-width: 3px;
  paint-order: stroke;
  pointer-events: none;
}

.elo-comparison-diff-label {
  font-size: 10px;
  font-weight: 600;
  fill: var(--ink);
}

.elo-comparison-dot-label-main {
  font-size: 9px;
  fill: #3a6ea5;
  text-anchor: middle;
}

.elo-comparison-dot-label-opponent {
  font-size: 9px;
  fill: var(--muted);
  text-anchor: middle;
}

.win-rate-chart-axis-label {
  font-family: var(--sans);
  font-size: 9px;
  fill: var(--muted);
  pointer-events: none;
}

/* ---------- Fun Facts tab ---------- */

.fun-facts-group {
  position: relative;
  margin-bottom: 40px;
}

.fun-facts-group h3 { margin: 0 0 6px; }
.fun-facts-group > h3 + .win-rate-stat-row { margin-top: 14px; }

.fun-facts-tile { max-width: 260px; }

/* One playfully tilted tile per section, at most. */
.fun-facts-tile.tilt { transform: rotate(2deg); }

.fun-facts-detail {
  font-size: 0.8rem;
  color: var(--muted);
}

.fun-facts-detail a {
  color: var(--ink);
  font-weight: 500;
  text-decoration-color: var(--coral);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.fun-facts-list {
  margin: 0 0 16px;
  padding-left: 22px;
  font-size: 0.9rem;
}

/* The comic "POW!" burst beside the Rage Quit heading. */
.burst {
  display: inline-flex;
  vertical-align: middle;
  margin-left: 14px;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  font-family: var(--display);
  font-size: 1.05rem;
  letter-spacing: 0.03em;
  color: #ffffff;
  background: var(--coral);
  border: var(--border-w) solid var(--ink);
  border-radius: 50%;
  box-shadow: 3px 3px 0 var(--shadow-color);
  transform: rotate(12deg);
  pointer-events: none;
}

#funFactsContent svg {
  width: 100%;
  display: block;
}

.move-range-line {
  stroke: var(--muted);
  stroke-width: 2px;
  pointer-events: none;
}

.move-range-dot-min,
.move-range-dot-max {
  fill: #b0aa98;
  stroke: var(--ink);
  stroke-width: 1.5px;
}

.move-range-dot-avg {
  fill: var(--coral);
  stroke: var(--ink);
  stroke-width: 1.5px;
}

.move-range-label {
  font-size: 9px;
  fill: var(--ink);
}

/* ---------- filters ---------- */

.filter-control {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-select {
  padding: 7px 10px;
  width: 100%;
}

.tc-filter-wrap { position: relative; }

.tc-filter-btn {
  width: 100%;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tc-filter-btn::after {
  content: "▾";
  color: var(--muted);
  font-size: 0.7rem;
}

.tc-filter-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 6px;
  padding: 4px 0;
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 8px;
  box-shadow: 3px 3px 0 var(--shadow-color);
  max-height: 240px;
  overflow-y: auto;
  z-index: 20;
}

.tc-filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 0.85rem;
  color: var(--ink);
  cursor: pointer;
}

.tc-filter-item input { accent-color: var(--coral); }
.tc-filter-item:hover { background: var(--zebra); }

.tc-filter-select-all {
  font-weight: 500;
  border-bottom: 2px solid var(--ink);
  margin-bottom: 4px;
}

/* ---------- graph ---------- */

.graph-controls-row {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 24px;
}

.graph-controls-group { flex: 1 1 220px; }
.graph-controls-group h3 { margin-top: 0; }

.graph-controls {
  display: flex;
  gap: 24px;
  align-items: center;
  margin-bottom: 4px;
}

.graph-status {
  margin: 0 0 14px;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted);
}

.graph-status.is-error { color: var(--error-text); }
.graph-status.is-network { color: var(--win-text); }

.graph-container {
  width: 100%;
  height: 520px;
  position: relative;
  overflow: hidden;
}

#graphSvg {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#graphSvg:active { cursor: grabbing; }

/* +/- / fit buttons in the graph's top-right corner. */
.graph-zoom-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.graph-zoom-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--shadow-color);
}

.graph-zoom-btn:hover { background: var(--zebra); }
.graph-zoom-btn:active { transform: translate(2px, 2px); box-shadow: none; }

.node-circle {
  stroke: var(--ink);
  stroke-width: 2px;
  cursor: pointer;
}

.node-group-aggregate .node-circle { cursor: context-menu; }

.node-pie-slice {
  stroke: var(--card);
  stroke-width: 0.5px;
  cursor: pointer;
}

.node-group-aggregate .node-pie-slice { cursor: context-menu; }

.node-circle-outline {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2px;
  pointer-events: none;
}

/* The main player's vertex always gets this glowing blue outline instead
   of the plain ink one, so it stays identifiable regardless of what color
   its own win/loss pie happens to be. */
.node-circle-outline-main,
.node-circle-main {
  stroke: #4fc3f7;
  stroke-width: 3px;
  filter: drop-shadow(0 0 3px #4fc3f7) drop-shadow(0 0 8px #4fc3f7);
}

.node-label {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  fill: var(--ink);
  pointer-events: none;
  paint-order: stroke;
  stroke: var(--card);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.link-segment {
  stroke-opacity: 0.85;
  fill: none;
}

.graph-tooltip {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  background: var(--dark-band);
  color: #fffdf5;
  font-size: 0.8rem;
  line-height: 1.6;
  padding: 10px 14px;
  border: 2px solid var(--sun);
  border-radius: 8px;
  box-shadow: 3px 3px 0 var(--coral);
  max-width: 240px;
}

.graph-tooltip .tt-name {
  font-family: var(--display);
  font-size: 1.05rem;
  letter-spacing: 0.03em;
  color: var(--sun);
  margin-bottom: 2px;
  display: block;
}

/* The sidebar charts' tooltips float above the page (positioned by
   positionFloatingTooltip in script.js), so the narrow sidebar and the
   histogram box's overflow can't cut them off. */
#gamesHistogramTooltip,
#filteredGamesHistogramTooltip,
#timeControlTreemapTooltip,
#filteredTimeControlTreemapTooltip {
  position: fixed;
  z-index: 50;
  max-width: none;
  white-space: nowrap;
}

/* ---------- Graph tab network facts (graphFacts.js) ---------- */

.network-facts { margin: 4px 0 22px; }
.network-facts:empty { display: none; }

.network-facts-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  margin-bottom: 12px;
}

.network-facts-header h3 { margin: 0; }
.network-facts-header .subtle { margin: 0; }

.network-facts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}

.network-fact {
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: left;
  font-family: var(--sans);
  color: var(--ink);
  padding: 10px 12px;
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--offset) var(--offset) 0 var(--shadow-color);
  background: var(--card);
  min-width: 0;
}

button.network-fact {
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

button.network-fact:hover { transform: translate(-1px, -1px); }

button.network-fact:focus-visible {
  outline: 3px solid var(--coral);
  outline-offset: 2px;
}

.network-fact:nth-child(4n + 1) { background: var(--tint-yellow); }
.network-fact:nth-child(4n + 2) { background: var(--tint-teal); }
.network-fact:nth-child(4n + 3) { background: var(--tint-violet); }
.network-fact:nth-child(4n + 4) { background: var(--tint-pink); }

.network-fact.is-active {
  box-shadow: var(--offset) var(--offset) 0 var(--coral);
  transform: rotate(-1deg);
}

/* Locked facts are a call to action: clicking expands players to unlock them. */
.network-fact.is-locked {
  background: var(--card);
  border-style: dashed;
  box-shadow: none;
}

.network-fact.is-locked .network-fact-value {
  color: var(--coral);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.network-fact.is-locked:hover {
  border-style: solid;
  box-shadow: var(--offset) var(--offset) 0 var(--shadow-color);
}

.network-fact .meta-label { margin-bottom: 0; }

.network-fact-value {
  font-weight: 600;
  font-size: 1.02rem;
  overflow-wrap: anywhere;
}

.network-fact-new {
  display: inline-block;
  margin-left: 6px;
  font-family: var(--display);
  font-size: 0.85rem;
  letter-spacing: 0.03em;
  color: #ffffff;
  background: var(--coral);
  border: 2px solid var(--ink);
  border-radius: 6px;
  padding: 0 5px;
  transform: rotate(-6deg);
}

/* A fact highlighted on the graph: its players and edges stand out, the
   rest fades back. */
#graphSvg.graph-dimmed .node-group:not(.is-highlighted),
#graphSvg.graph-dimmed .link-group:not(.is-highlighted) {
  opacity: 0.15;
}

#graphSvg .node-group.is-highlighted .node-shape {
  filter: drop-shadow(0 0 4px var(--coral)) drop-shadow(0 0 10px var(--coral));
}

#graphSvg .link-group.is-highlighted .link-segment {
  stroke-opacity: 1;
  filter: drop-shadow(0 0 3px var(--coral));
}

/* ---------- tables ---------- */

.table-wrap {
  overflow-x: auto;
  margin-bottom: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}

thead th {
  text-align: left;
  font-family: var(--display);
  font-weight: 400;
  font-size: 1rem;
  letter-spacing: 0.04em;
  color: var(--on-dark-band);
  background: var(--dark-band);
  padding: 7px 12px;
  white-space: nowrap;
}

th.col-num, td.col-num { text-align: right; }

tbody td {
  padding: 7px 12px;
  border-bottom: 1.5px solid var(--ink);
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:nth-child(even) { background: var(--zebra); }

tbody tr.row-all-games {
  background: var(--sun);
  color: #1a1a1a;
  font-weight: 600;
}

tbody tr.outcome-win td.outcome-cell { color: var(--win-text); font-weight: 500; }
tbody tr.outcome-loss td.outcome-cell { color: var(--loss-text); font-weight: 500; }
tbody tr.outcome-draw td.outcome-cell { color: var(--muted); }

/* ---------- links ---------- */

.btn-link {
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink);
  background: none;
  border: none;
  padding: 4px 0;
  margin: 8px 0 32px;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--coral);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

.btn-link:hover { text-decoration-color: var(--ink); }

/* "Show matches" / "Hide matches" links around a collapsible list (collapsible.js). */
.collapse-toggle {
  display: block;
  margin: 2px 0 12px;
}

/* display: block above would otherwise override the hidden attribute. */
.collapse-toggle[hidden] { display: none; }

.table-wrap + .collapse-toggle { margin: 10px 0 0; }

/* ---------- small screens ---------- */

@media (max-width: 700px) {
  .sticker-2, .sticker-3, .sticker-4 { display: none; }
  .header-stickers { width: 70px; right: 12px; }
  .sticker-1 { right: 4px; }
}

@media (max-width: 520px) {
  :root {
    --border-w: 2px;
    --offset: 3px;
  }

  .topbar h1 { font-size: 2.1rem; }
  .header-controls { flex-direction: column; align-items: flex-start; }
}

/* ---------- dark mode ---------- */

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f4f1e8;
    --paper: #17171c;
    --card: #24242c;
    --muted: #b8b4a8;
    --tint-yellow: #3a3420;
    --tint-pink: #3d2526;
    --tint-teal: #1f3a38;
    --tint-violet: #2e2846;
    --zebra: #2b2b33;
    --dark-band: #0f0f12;
    --shadow-color: #ffe14d;
    --win-text: #6fd39a;
    --loss-text: #ff8a8a;
    --error-text: #ff8a8a;
  }

  .topbar {
    background: #2a2a33;
    border-bottom-color: var(--sun);
  }

  .topbar h1 { color: var(--sun); }
  .file-name { color: var(--muted); }
  .chesscom-status.is-cache { color: #e0c46c; }
  .tab-btn.is-active { border-color: var(--sun); }
  tbody tr.row-all-games { background: #4a4119; color: var(--sun); }

  /* Win/loss colors set inline by the chart code (GRAPH_COLORS) are tuned
     for light backgrounds; lift them on dark tiles and table cells. */
  .win-rate-stat-tile .meta-value,
  .where-now-change {
    filter: brightness(1.6);
  }
}
