:root {
  --chrome-h: 112px;
  --bg: #0a0a0b;
  --bg-2: #101012;
  --surface: #161618;
  --surface-2: #1c1c1f;
  --line: #2c2c31;
  --text: #f4efe9;
  --muted: #9c958d;
  --dim: #6f6a65;
  --accent: #e8633a;
  --accent-2: #ff8a62;
  --accent-soft: rgba(232, 99, 58, 0.14);
  --accent-glow: rgba(232, 99, 58, 0.45);
  --white-sq: #e7d6bf;
  --black-sq: #3b332d;
  --last: rgba(232, 99, 58, 0.48);
  --select: rgba(232, 99, 58, 0.32);
  --legal: rgba(232, 99, 58, 0.88);
  --ok: #d7c4a8;
  --danger: #e8633a;
  --font: "Outfit", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --radius: 14px;
  --header-h: 72px;
  --ticker-h: 40px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body { min-height: 100vh; letter-spacing: 0.01em; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; }

.skip {
  position: absolute; left: -999px; top: 8px;
}
.skip:focus { left: 8px; z-index: 80; background: var(--accent); color: #111; padding: 8px 12px; border-radius: 8px; }

/* Sticky header + ticker */
.site-chrome {
  position: sticky; top: 0; z-index: 40;
}
.site-header {
  height: var(--header-h);
  display: flex; align-items: center; gap: 20px;
  padding: 0 24px;
  background: rgba(10, 10, 11, 0.92);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 14px; color: inherit; text-decoration: none; min-width: 220px; }
.brand:hover { text-decoration: none; }
.brand img { width: 48px; height: 48px; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-weight: 600; font-size: 15px; letter-spacing: 0.08em; text-transform: uppercase; }
.brand-text span { font-size: 12px; color: var(--muted); letter-spacing: 0.12em; text-transform: uppercase; margin-top: 3px; }

.header-mid { flex: 1; display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.header-mid h1 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: 0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-mid .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

.header-status { display: flex; align-items: center; gap: 16px; }
.score-block { text-align: right; }
.score-block .score { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.score-block .updated { color: var(--muted); font-size: 11px; letter-spacing: 0.04em; }

.live-badge {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent); color: #140804;
  font-weight: 700; font-size: 12px; letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 7px 12px; border-radius: 999px;
}
.live-badge .dot {
  width: 8px; height: 8px; border-radius: 50%; background: #140804;
  box-shadow: 0 0 0 0 rgba(20, 8, 4, 0.6);
  animation: pulse 1.6s infinite;
}
.badge-rest, .badge-upcoming, .badge-finished {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
}
.badge-rest .dot, .badge-upcoming .dot, .badge-finished .dot { animation: none; background: var(--muted); box-shadow: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(20, 8, 4, 0.5); }
  70% { box-shadow: 0 0 0 8px rgba(20, 8, 4, 0); }
  100% { box-shadow: 0 0 0 0 rgba(20, 8, 4, 0); }
}

/* Ticker */
.ticker {
  height: var(--ticker-h);
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  display: flex; align-items: stretch; overflow: hidden;
}
.ticker-label {
  flex: 0 0 auto;
  display: flex; align-items: center;
  padding: 0 14px;
  background: var(--accent); color: #140804;
  font-size: 11px; font-weight: 700; letter-spacing: 0.16em;
  text-transform: uppercase;
  z-index: 1;
}
.ticker-track-wrap { flex: 1; overflow: hidden; display: flex; align-items: center; }
.ticker-track {
  display: flex; gap: 0; white-space: nowrap;
  animation: ticker 60s linear 1s infinite;
}
.ticker-track > :first-child { padding-left: 16px; }
.ticker:hover .ticker-track { animation-play-state: paused; }
.ticker-track a, .ticker-track span {
  color: var(--text); padding: 0 28px; font-size: 13px;
  border-right: 1px solid var(--line);
}
.ticker-track a:hover { color: var(--accent-2); text-decoration: none; }
@keyframes ticker {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

.page { width: min(1280px, calc(100% - 32px)); margin: 0 auto; padding: 28px 0 80px; }

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel-h {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 14px 18px 0;
}
.panel-h h2 { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.panel-h .meta { color: var(--dim); font-size: 12px; }
.panel-b { padding: 14px 18px 18px; }

.desk {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
  gap: 22px;
}

/* Players / clocks */
.player-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 4px;
}
.player-row .who { display: flex; flex-direction: column; }
.player-row .name { font-size: 16px; font-weight: 600; }
.player-row .elo { color: var(--muted); font-size: 12px; letter-spacing: 0.06em; }
.clock {
  font-family: var(--mono); font-size: 22px; font-weight: 500;
  font-variant-numeric: tabular-nums;
  padding: 6px 12px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--line);
}
.clock.active { border-color: var(--accent); color: var(--accent-2); background: var(--accent-soft); }
.clock.trouble { color: var(--accent); }

.board-wrap {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 12px;
  align-items: stretch;
}

/* Eval bar */
.evalbar {
  position: relative;
  border-radius: 9px;
  overflow: hidden;
  background: #1a1714;
  border: 1px solid var(--line);
}
.evalbar-white {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--white-sq);
  width: 100%;
  height: 50%;
  transition: height 0.45s ease;
}
.evalbar-label {
  position: absolute; left: 0; right: 0;
  text-align: center; font-size: 10px; font-weight: 700;
  letter-spacing: 0.02em;
  font-family: var(--mono);
  z-index: 1;
}
.evalbar-label.top { top: 6px; color: #f4efe9; }
.evalbar-label.bot { bottom: 6px; color: #1a1410; }
.evalbar.flipped .evalbar-white { top: 0; bottom: auto; }
.eval-caption { font-family: var(--mono); font-size: 13px; color: var(--accent-2); margin: 8px 0 0; font-weight: 600; }

/* Board */
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  user-select: none;
  touch-action: none;
  box-shadow: 0 0 0 1px rgba(232, 99, 58, 0.08);
}
.board-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%; height: 100%;
}
.sq { position: relative; }
.sq.light { background: var(--white-sq); }
.sq.dark { background: var(--black-sq); }
.sq.last { box-shadow: inset 0 0 0 999px var(--last); }
.sq.selected { box-shadow: inset 0 0 0 999px var(--select); }
.sq.legal::after {
  content: "";
  position: absolute; inset: 36%;
  background: var(--legal);
  border-radius: 50%;
  opacity: 0.85;
}
.sq.legal.occupied::after { inset: 8%; background: transparent; border: 4px solid var(--accent); border-radius: 50%; opacity: 0.85; }
.sq.critical { outline: 2px solid var(--accent); outline-offset: -2px; }
.sq img.piece {
  position: absolute; inset: 5%;
  width: 90%; height: 90%;
  pointer-events: none;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.35));
}
.coord {
  position: absolute; font-size: 10px; font-weight: 600; opacity: 0.72;
  font-family: var(--mono); pointer-events: none;
}
.coord.file { right: 3px; bottom: 2px; }
.coord.rank { left: 3px; top: 2px; }
.sq.light .coord { color: var(--black-sq); }
.sq.dark .coord { color: var(--white-sq); }

.controls {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center;
}
.controls button, .btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.controls button:hover, .btn:hover { border-color: var(--accent); color: #fff; }
.controls button:disabled { opacity: 0.4; cursor: default; border-color: var(--line); color: var(--muted); }
.btn-accent { background: var(--accent); color: #140804; border-color: var(--accent); font-weight: 600; }
.btn-accent:hover { filter: brightness(1.05); text-decoration: none; color: #140804; }
.explore-flag {
  font-size: 12px; color: var(--accent-2); letter-spacing: 0.08em; text-transform: uppercase; font-weight: 600;
}

.move-list {
  margin-top: 14px;
  max-height: 280px;
  overflow: auto;
  display: grid;
  grid-template-columns: 28px 1fr 1fr;
  gap: 0;
  font-family: var(--mono); font-size: 13px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
.move-list .n { color: var(--dim); padding: 5px 8px; border-bottom: 1px solid #222; }
.move-list button.mv {
  all: unset; cursor: pointer; padding: 5px 8px; border-bottom: 1px solid #222; display: block;
}
.move-list button.mv:hover { background: var(--accent-soft); }
.move-list button.mv.active { background: var(--accent); color: #140804; font-weight: 600; }
.move-list button.mv.alert { color: var(--accent-2); }
.move-list button.mv.active.alert { color: #140804; }

/* Right column */
.lines { display: flex; flex-direction: column; gap: 8px; }
.line {
  display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: start;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  cursor: pointer;
}
.line:hover { border-color: var(--accent); }
.line .rank { color: var(--accent); font-weight: 700; font-family: var(--mono); }
.line .pv { font-family: var(--mono); font-size: 13px; }
.line .wdl { font-size: 11px; color: var(--muted); text-align: right; font-family: var(--mono); }
.wdl-bar { display: flex; height: 6px; border-radius: 99px; overflow: hidden; margin-top: 6px; background: #222; }
.wdl-bar span { display: block; height: 100%; }
.wdl-bar .w { background: var(--white-sq); }
.wdl-bar .d { background: #6b635c; }
.wdl-bar .b { background: #1a1714; }

.engine-note { color: var(--dim); font-size: 12px; margin: 0 0 10px; }
.stockfish-box { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.stockfish-box pre {
  margin: 8px 0 0; font-family: var(--mono); font-size: 12px; white-space: pre-wrap;
  color: var(--ok); background: var(--bg); padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line);
}

.moment {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.moment:last-child { border-bottom: 0; }
.moment:hover h3 { color: var(--accent-2); }
.moment .move { color: var(--accent); font-family: var(--mono); font-size: 12px; font-weight: 600; letter-spacing: 0.06em; }
.moment h3 { margin: 4px 0 6px; font-size: 16px; font-weight: 600; }
.moment p { margin: 0 0 6px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.moment.hot { background: var(--accent-soft); margin: 0 -18px; padding: 12px 18px; border-bottom-color: transparent; }

/* Graph */
.graph-panel { margin-top: 22px; }
#eval-graph { width: 100%; height: 220px; display: block; }
.graph-legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.graph-legend i { display: inline-block; width: 12px; height: 3px; margin-right: 6px; vertical-align: middle; }
.sw-w { background: var(--white-sq); }
.sw-b { background: var(--accent); }

/* Two columns below */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; margin-top: 22px; }
.opening ul { margin: 0; padding: 0 0 0 18px; color: var(--muted); }
.opening li { margin: 0 0 8px; line-height: 1.5; }
.watch { margin: 12px 0 0; padding: 10px 12px; background: var(--bg); border-left: 3px solid var(--accent); color: var(--text); font-size: 14px; }

/* Repertoire */
.rep-list { display: flex; flex-direction: column; gap: 8px; }
.rep-item {
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  padding: 10px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
.rep-item h3 { margin: 0; font-size: 14px; }
.rep-item p { margin: 2px 0 0; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.rep-empty { color: var(--muted); font-size: 14px; }

/* Schedule */
.table-wrap { overflow: auto; margin-top: 22px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; font-weight: 600; }
tr.live td { background: var(--accent-soft); }
tr.rest td { color: var(--dim); }
.status-pill {
  display: inline-block; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 700;
  padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line);
}
.status-pill.live { background: var(--accent); color: #140804; border-color: var(--accent); }
.notes { color: var(--muted); font-size: 14px; line-height: 1.6; padding: 0 4px; }

/* News + X */
.news-grid { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 22px; margin-top: 22px; }
.news-item { padding: 14px 0; border-bottom: 1px solid var(--line); }
.news-item h3 { margin: 0 0 6px; font-size: 16px; }
.news-item p { margin: 0 0 8px; color: var(--muted); line-height: 1.55; }
.news-item .src { font-size: 12px; color: var(--dim); }
blockquote.quote {
  margin: 0 0 8px; padding: 0 0 0 14px; border-left: 3px solid var(--accent);
  color: var(--text); font-size: 15px; line-height: 1.5;
}
.x-card {
  display: block; color: inherit; padding: 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); margin-bottom: 10px;
}
.x-card:hover { border-color: var(--accent); text-decoration: none; }
.x-card .by { font-weight: 600; }
.x-card .handle { color: var(--muted); font-weight: 400; margin-left: 6px; }
.x-card p { margin: 8px 0 0; line-height: 1.5; }
.x-card .ctx { margin-top: 8px; font-size: 11px; color: var(--dim); letter-spacing: 0.04em; }

/* Toasts */
.toasts {
  position: fixed; right: 18px; bottom: 18px; z-index: 60;
  display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100% - 32px));
}
.toast {
  background: var(--surface-2); border: 1px solid var(--accent); border-radius: 12px;
  padding: 12px 14px; box-shadow: var(--shadow);
  animation: in 0.25s ease;
}
.toast strong { display: block; color: var(--accent-2); font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 4px; }
@keyframes in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.site-footer {
  border-top: 1px solid var(--line);
  padding: 28px 24px 40px;
  color: var(--dim); font-size: 13px; text-align: center;
}
.site-footer a { color: var(--muted); }
.disclaimer { max-width: 800px; margin: 0 auto 10px; line-height: 1.55; }

@media (max-width: 980px) {
  .desk, .split, .news-grid { grid-template-columns: 1fr; }
  .header-mid h1 { font-size: 15px; }
  .site-header { gap: 10px; padding: 0 12px; }
  .brand-text span { display: none; }
}
@media (max-width: 640px) {
  .score-block .score { font-size: 16px; }
  .clock { font-size: 18px; }
  .brand img { width: 40px; height: 40px; }
}

/* Fan toggle + sound */
.site-header { height: auto; min-height: var(--header-h); padding: 10px 24px; }
.fan-toggle {
  display: inline-flex; margin-top: 6px; border: 1px solid var(--line); border-radius: 999px;
  overflow: hidden; background: var(--bg);
}
.fan-toggle button {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 5px 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.fan-toggle button[aria-checked="true"] { background: var(--accent); color: #140804; }
.fan-toggle .flag { width: 16px; height: 11px; border-radius: 1px; display: block; box-shadow: 0 0 0 1px rgba(255,255,255,0.2); }
.sound-toggle {
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 10px; cursor: pointer; font-size: 11px;
  font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
}
.sound-toggle[aria-pressed="true"] { color: var(--text); border-color: var(--accent); }

/* Flag stripe */
.site-chrome::before { content: none; }
html[data-fan="gukesh"] .site-chrome::before,
html[data-fan="sindarov"] .site-chrome::before {
  content: ""; display: block; height: 4px;
}
html[data-fan="gukesh"] .site-chrome::before {
  background: linear-gradient(90deg, #ff9933 0 33.33%, #fff 33.33% 66.66%, #138808 66.66%);
}
html[data-fan="sindarov"] .site-chrome::before {
  background: linear-gradient(90deg, #0099b5 0 33.33%, #fff 33.33% 66.66%, #1eb53a 66.66%);
}

html[data-fan="gukesh"] {
  --accent: #ff9933;
  --accent-2: #ffc35a;
  --accent-soft: rgba(255, 153, 51, 0.16);
  --accent-glow: rgba(255, 153, 51, 0.45);
  --legal: #138808;
  --ok: #8ee08a;
  --last: rgba(255, 153, 51, 0.48);
  --select: rgba(19, 136, 8, 0.28);
}
html[data-fan="sindarov"] {
  --accent: #1aa3c4;
  --accent-2: #7ad7ec;
  --accent-soft: rgba(26, 163, 196, 0.16);
  --accent-glow: rgba(26, 163, 196, 0.45);
  --legal: #1eb53a;
  --ok: #8ee08a;
  --last: rgba(26, 163, 196, 0.48);
  --select: rgba(30, 181, 58, 0.28);
}

.player-row.fan-focus {
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 10px 10px;
  box-shadow: inset 0 0 0 1px var(--accent);
}

.news-item.fan-hit, .x-card.fan-hit, .moment.fan-hit {
  box-shadow: inset 3px 0 0 var(--accent);
  background: var(--accent-soft);
  border-radius: 8px;
  padding-left: 14px;
}
.x-card.fan-hit { padding: 14px 14px 14px 16px; }

.celebrations { margin-bottom: 14px; }
.celebration {
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.celebration strong { display: block; letter-spacing: 0.1em; text-transform: uppercase; font-size: 11px; color: var(--accent-2); margin-bottom: 4px; }

/* Time trouble — broadcast banner */
.time-trouble {
  display: none;
  width: 100%;
  background: #7a1414;
  color: #fff6f4;
  border-bottom: 2px solid #ff4d3a;
  box-shadow: 0 8px 32px rgba(122, 20, 20, 0.45);
}
.time-trouble.is-on { display: block; }
.time-trouble-inner {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 0;
}
.tt-kicker {
  font-size: 11px; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase;
  background: #ff4d3a; color: #1a0505; padding: 4px 8px; border-radius: 4px;
}
#tt-message { font-size: 18px; font-weight: 700; letter-spacing: 0.02em; }
.tt-countdown {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}
.time-trouble.under-one {
  background: #9b0c0c;
  animation: ttflash 0.7s ease-in-out infinite;
  border-bottom-color: #fff;
}
.time-trouble.under-one .tt-countdown { font-size: 34px; text-shadow: 0 0 18px rgba(255, 80, 60, 0.9); }
.time-trouble.fan-own { background: #6a1010; }
@keyframes ttflash {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.18); }
}

.clock.trouble-alert {
  color: #ffd2cc;
  background: #5a1010;
  border-color: #ff4d3a;
  animation: clockpulse 1.15s ease-in-out infinite;
}
.clock.trouble-critical {
  color: #fff;
  background: #8a0c0c;
  border-color: #fff;
  animation: clockpulse 0.55s ease-in-out infinite;
  box-shadow: 0 0 0 2px #ff4d3a, 0 0 22px rgba(255, 60, 40, 0.7);
  font-weight: 700;
}
@keyframes clockpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 77, 58, 0.7); }
  50% { box-shadow: 0 0 0 8px rgba(255, 77, 58, 0); }
}

@media (max-width: 980px) {
  .fan-toggle { margin-top: 8px; }
  .tt-countdown { margin-left: 0; }
}

.opening.lead-gukesh #open-black, .opening.lead-sindarov #open-white { /* highlight the fan side list */ }
.opening.lead-gukesh #open-black { background: var(--accent-soft); border-radius: 10px; padding: 8px 12px 8px 28px; }
.opening.lead-sindarov #open-white { background: var(--accent-soft); border-radius: 10px; padding: 8px 12px 8px 28px; }
