/* --- Theme tokens ----------------------------------------------------------
   Every colour on the page comes from these variables. Dark values live in
   the prefers-color-scheme block and the [data-theme="dark"] block below. */

:root {
  color-scheme: light;
  --bg: #f3f2ee;
  --surface: #ffffff;
  --surface-2: #f6f5f1;
  --surface-hover: #ecebe5;
  --border: #dcd9d1;
  --border-strong: #c3bfb5;
  --text: #1f2320;
  --text-muted: #5b6058;
  --accent: #2f6b4f;
  --accent-strong: #234f3a;
  --accent-soft: #e2eee6;
  --on-accent: #ffffff;
  --white-side: #3a6ea5;
  --black-side: #a54a3a;
  --white-side-ref: #1c4a73;
  --black-side-ref: #7a3527;
  --swatch-white: #f4f4f1;
  --swatch-black: #2b2b2b;
  --error: #b3352a;
  --error-soft: #f8e1dd;
  --warn-bg: #fbf1d6;
  --warn-border: #dfc063;
  --warn-text: #6b5210;
  --live-bg: #e0eefb;
  --live-border: #a9cdeb;
  --live-text: #1c5a8a;
  --zone-typical: #3b7f56;
  --zone-typical-text: #ffffff;
  --zone-unusual: #e2b048;
  --zone-unusual-text: #332400;
  --zone-high: #b8423a;
  --zone-high-text: #ffffff;
  --chip-typical-bg: #dcecdf;
  --chip-typical-text: #1f5236;
  --chip-unusual-bg: #f6e6bb;
  --chip-unusual-text: #5e4508;
  --chip-high-bg: #f6d9d5;
  --chip-high-text: #8e2c22;
  --marker: #1f2320;
  --marker-halo: rgba(255, 255, 255, 0.85);
  --clock-bg: #e3e1db;
  --clock-text: #4a4e48;
  --clock-active-bg: #cfe2bd;
  --clock-active-text: #101210;
  --clock-low-text: #b3261e;
  --clock-low-bg: #f4d0cb;
  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --board-frame: #4a4038;
  --highlight-from: rgba(205, 210, 106, 0.75);
  --highlight-to: rgba(170, 162, 58, 0.55);
  --synthetic: #c8901f;
  --critical: #c0473a;
  --chart-grid: rgba(0, 0, 0, 0.07);
  --chart-tick: #5b6058;
  --chart-cursor: rgba(40, 40, 40, 0.45);
  --chart-point-ring: #ffffff;
  --overlay-scrim: rgba(243, 242, 238, 0.35);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.14);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --radius: 8px;
  --radius-sm: 5px;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  /* Layout: the board is sized from the viewport height so the whole
     analysis (board, both bars, controls, chart) fits on one screen. */
  --topbar-h: 48px;
  --bar-h: 38px;
  --controls-h: 32px;
  --chart-h: 186px;
  --gap: 12px;
  --side-w: clamp(400px, 34vw, 640px);
  --board-size: clamp(
    300px,
    min(
      calc(100vh - var(--topbar-h) - 2 * var(--bar-h) - var(--controls-h) - var(--chart-h) - 3 * var(--gap) - 12px),
      calc(100vw - var(--side-w) - 3 * var(--gap) - 32px)
    ),
    900px
  );
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #161512;
    --surface: #242320;
    --surface-2: #2c2a26;
    --surface-hover: #34322d;
    --border: #3b3934;
    --border-strong: #57544d;
    --text: #e4e2dd;
    --text-muted: #aba8a0;
    --accent: #5fae80;
    --accent-strong: #86cba2;
    --accent-soft: #23372b;
    --on-accent: #0f1a13;
    --white-side: #82b4ea;
    --black-side: #e79583;
    --white-side-ref: #b9d6f5;
    --black-side-ref: #f3c1b5;
    --swatch-white: #efefea;
    --swatch-black: #0c0c0b;
    --error: #ff8f80;
    --error-soft: #41231f;
    --warn-bg: #3a3120;
    --warn-border: #75612a;
    --warn-text: #f0d68e;
    --live-bg: #1f3044;
    --live-border: #38597a;
    --live-text: #a9d1f5;
    --zone-typical: #2f6b48;
    --zone-typical-text: #eaf6ee;
    --zone-unusual: #c1912c;
    --zone-unusual-text: #1c1300;
    --zone-high: #a7423a;
    --zone-high-text: #ffffff;
    --chip-typical-bg: #213a2b;
    --chip-typical-text: #9fdcb6;
    --chip-unusual-bg: #3f3317;
    --chip-unusual-text: #f0cf7a;
    --chip-high-bg: #472520;
    --chip-high-text: #ffb2a6;
    --marker: #f4f2ec;
    --marker-halo: rgba(0, 0, 0, 0.7);
    --clock-bg: #2f2d29;
    --clock-text: #b3b0a8;
    --clock-active-bg: #3d5a2c;
    --clock-active-text: #ffffff;
    --clock-low-text: #ff8f80;
    --clock-low-bg: #5a2620;
    --board-light: #dcc6a3;
    --board-dark: #a57c5a;
    --board-frame: #0c0b0a;
    --highlight-from: rgba(155, 199, 0, 0.42);
    --highlight-to: rgba(155, 199, 0, 0.3);
    --synthetic: #e0ad45;
    --critical: #ff8f80;
    --chart-grid: rgba(255, 255, 255, 0.08);
    --chart-tick: #aba8a0;
    --chart-cursor: rgba(230, 230, 230, 0.5);
    --chart-point-ring: #242320;
    --overlay-scrim: rgba(22, 21, 18, 0.35);
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161512;
  --surface: #242320;
  --surface-2: #2c2a26;
  --surface-hover: #34322d;
  --border: #3b3934;
  --border-strong: #57544d;
  --text: #e4e2dd;
  --text-muted: #aba8a0;
  --accent: #5fae80;
  --accent-strong: #86cba2;
  --accent-soft: #23372b;
  --on-accent: #0f1a13;
  --white-side: #82b4ea;
  --black-side: #e79583;
  --white-side-ref: #b9d6f5;
  --black-side-ref: #f3c1b5;
  --swatch-white: #efefea;
  --swatch-black: #0c0c0b;
  --error: #ff8f80;
  --error-soft: #41231f;
  --warn-bg: #3a3120;
  --warn-border: #75612a;
  --warn-text: #f0d68e;
  --live-bg: #1f3044;
  --live-border: #38597a;
  --live-text: #a9d1f5;
  --zone-typical: #2f6b48;
  --zone-typical-text: #eaf6ee;
  --zone-unusual: #c1912c;
  --zone-unusual-text: #1c1300;
  --zone-high: #a7423a;
  --zone-high-text: #ffffff;
  --chip-typical-bg: #213a2b;
  --chip-typical-text: #9fdcb6;
  --chip-unusual-bg: #3f3317;
  --chip-unusual-text: #f0cf7a;
  --chip-high-bg: #472520;
  --chip-high-text: #ffb2a6;
  --marker: #f4f2ec;
  --marker-halo: rgba(0, 0, 0, 0.7);
  --clock-bg: #2f2d29;
  --clock-text: #b3b0a8;
  --clock-active-bg: #3d5a2c;
  --clock-active-text: #ffffff;
  --clock-low-text: #ff8f80;
  --clock-low-bg: #5a2620;
  --board-light: #dcc6a3;
  --board-dark: #a57c5a;
  --board-frame: #0c0b0a;
  --highlight-from: rgba(155, 199, 0, 0.42);
  --highlight-to: rgba(155, 199, 0, 0.3);
  --synthetic: #e0ad45;
  --critical: #ff8f80;
  --chart-grid: rgba(255, 255, 255, 0.08);
  --chart-tick: #aba8a0;
  --chart-cursor: rgba(230, 230, 230, 0.5);
  --chart-point-ring: #242320;
  --overlay-scrim: rgba(22, 21, 18, 0.35);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}

@media (max-height: 820px) {
  :root {
    --topbar-h: 44px;
    --bar-h: 36px;
    --controls-h: 32px;
    --chart-h: 170px;
    --gap: 8px;
  }
}

/* --- Base ------------------------------------------------------------------ */

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  background: var(--bg);
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: var(--fs-md);
  color: var(--text);
  line-height: 1.4;
  overflow-x: hidden;
}

h1,
h2 {
  margin: 0;
}

button {
  font-family: inherit;
  color: inherit;
}

textarea,
input[type="text"],
input[type="number"],
input[type="file"] {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--fs-md);
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}

textarea:focus,
input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 24px;
}

.card-title {
  font-size: var(--fs-md);
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  white-space: nowrap;
}

.card-subtle {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  white-space: nowrap;
}

.card-head-spacer,
.input-row-spacer,
.player-bar-spacer {
  flex: 1 1 auto;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.chip-warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn-text);
}

.chip-live {
  background: var(--live-bg);
  border-color: var(--live-border);
  color: var(--live-text);
}

.chip-plain {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-muted);
  font-weight: 500;
}

.primary-button,
.secondary-button,
.chip-button,
.icon-button {
  border-radius: var(--radius-sm);
  font-size: var(--fs-md);
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.2;
}

.primary-button {
  background: var(--accent);
  color: var(--on-accent);
  border: 1px solid var(--accent);
  padding: 6px 14px;
  font-weight: 600;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.primary-button:disabled {
  opacity: 0.6;
  cursor: progress;
}

.secondary-button,
.chip-button {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
}

.secondary-button:hover,
.chip-button:hover,
.icon-button:hover {
  background: var(--surface-hover);
}

.secondary-button:disabled {
  opacity: 0.55;
  cursor: default;
}

.secondary-button.small {
  padding: 3px 8px;
  font-size: var(--fs-sm);
}

.icon-button {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: var(--fs-lg);
  padding: 0;
}

.link-button {
  background: none;
  border: none;
  padding: 0;
  font-size: var(--fs-sm);
  color: var(--accent-strong);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* --- Theme toggle ---------------------------------------------------------- */

.theme-icon-light {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-icon-light {
    display: inline;
  }
  :root:not([data-theme="light"]) .theme-icon-dark {
    display: none;
  }
}

:root[data-theme="dark"] .theme-icon-light {
  display: inline;
}

:root[data-theme="dark"] .theme-icon-dark {
  display: none;
}

/* --- Top input bar ------------------------------------------------------------ */

.input-panel {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--space-4);
}

/* Empty state (nothing analyzed yet): the bar alone on a blank page reads as
   an unfinished stub, so give it room and a one-line intro until a game loads.
   Everything here is scoped to the panel while #results-panel is still hidden. */
.input-panel-intro {
  display: none;
}

body:has(#results-panel[hidden]) .input-panel {
  padding-block: 24px var(--space-4);
  min-height: 210px;
}

body:has(#results-panel[hidden]) .input-row {
  max-width: 1100px;
}

body:has(#results-panel[hidden]) .brand {
  font-size: calc(var(--fs-lg) * 1.35);
}

body:has(#results-panel[hidden]) .input-panel-intro {
  display: block;
  max-width: 1100px;
  margin: var(--space-3) auto 0;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  line-height: 1.5;
}

body:has(#results-panel[hidden]) .tab-panel.samples-panel {
  padding-top: var(--space-1);
}

.input-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  min-height: var(--topbar-h);
  padding-block: 6px;
  max-width: 1880px;
  margin: 0 auto;
}

.brand {
  line-height: 32px;
  font-weight: 750;
  font-size: var(--fs-lg);
  letter-spacing: -0.01em;
  color: var(--accent-strong);
  white-space: nowrap;
}

.input-panel-body {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  flex: 1 1 0;
  min-width: 0;
}

.input-panel:not(.collapsed) .input-row-spacer {
  display: none;
}

.input-panel.collapsed .input-panel-body {
  display: none;
}

.toggle-caret {
  display: inline-block;
  transition: transform 0.15s ease;
  color: var(--text-muted);
}

.input-panel.collapsed .input-panel-toggle .toggle-caret {
  transform: rotate(-90deg);
}

.tabs {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.tab-button {
  background: none;
  border: none;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: var(--fs-md);
  cursor: pointer;
  color: var(--text-muted);
}

.tab-button:hover {
  color: var(--text);
}

.tab-button.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--border);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1 1 280px;
  min-width: 0;
  max-width: 760px;
}

.tab-panel[data-panel="paste"] textarea {
  font-family: var(--mono);
  font-size: var(--fs-sm);
  resize: none;
  height: 32px;
  white-space: pre;
  overflow: hidden;
}

.tab-panel[data-panel="paste"] textarea:focus {
  position: relative;
  z-index: 5;
  height: 180px;
  white-space: pre-wrap;
  overflow: auto;
  box-shadow: var(--shadow);
}

.tab-panel[data-panel="lichess"] input,
.tab-panel[data-panel="live"] input {
  max-width: 360px;
}

.live-status-line {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.options-menu {
  position: relative;
}

.options-menu summary {
  list-style: none;
  display: inline-block;
}

.options-menu summary::-webkit-details-marker {
  display: none;
}

.baseline-inputs {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  right: 0;
  width: 290px;
  margin: 0;
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: auto 100px;
  gap: var(--space-2);
  align-items: center;
}

.baseline-inputs legend {
  float: left;
  grid-column: 1 / -1;
  font-weight: 600;
  font-size: var(--fs-sm);
  padding: 0;
}

.baseline-inputs label {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.samples-panel.active {
  flex: 1 1 100%;
  max-width: none;
  flex-direction: column;
  align-items: stretch;
  order: 10;
}

.samples-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.samples-grid {
  align-items: start;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: var(--space-2);
  padding-bottom: var(--space-2);
}

.samples-grid.loading {
  opacity: 0.6;
  pointer-events: none;
}

.samples-group-title {
  grid-column: 1 / -1;
  font-size: var(--fs-xs);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: var(--space-1) 0 0;
}

.sample-card {
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.sample-card:hover,
.sample-card:focus-within {
  border-color: var(--accent);
  background: var(--surface-hover);
}

.sample-card-main {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  background: none;
  border: none;
  text-align: left;
  padding: 6px 8px 2px;
  cursor: pointer;
  min-width: 0;
}

.sample-card-title {
  font-weight: 600;
  font-size: var(--fs-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sample-card-badge-line {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.sample-card-desc {
  display: flex;
  align-items: baseline;
  gap: var(--space-1);
  padding: 0 8px 6px;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  min-width: 0;
}

.sample-card-desc-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sample-card-desc.expanded .sample-card-desc-text {
  white-space: normal;
}

.more-toggle {
  flex: 0 0 auto;
  background: none;
  border: none;
  padding: 0;
  font-size: var(--fs-xs);
  color: var(--accent-strong);
  cursor: pointer;
}

.sample-tag {
  font-size: var(--fs-xs);
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 1px 6px;
  white-space: nowrap;
}

.error-message {
  max-width: 1880px;
  margin: 0 auto var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--error);
  background: var(--error-soft);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: var(--fs-md);
}

/* --- Results grid ------------------------------------------------------------ */

.results-panel {
  display: grid;
  grid-template-columns: var(--board-size) minmax(0, var(--side-w));
  grid-template-areas:
    "board side"
    "chart chart";
  justify-content: center;
  gap: var(--gap);
  padding: var(--gap) var(--space-4);
}

.board-column {
  grid-area: board;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.side-column {
  grid-area: side;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-width: 0;
  min-height: 0;
  /* Size containment keeps the side column from growing the grid row: the
     row height comes from the board column and this column fills it, with
     the move list absorbing whatever height is left. */
  contain: size;
}

.chart-section {
  grid-area: chart;
  position: relative;
  height: var(--chart-h);
  padding: var(--space-1) var(--space-3) var(--space-2);
}

/* --- Player bars and clocks -------------------------------------------------- */

.player-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--bar-h);
  min-width: 0;
  font-size: var(--fs-md);
  container-type: inline-size;
  overflow: hidden;
}

.player-bar > * {
  flex-shrink: 0;
}

.side-swatch {
  flex: 0 0 auto;
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid var(--border-strong);
  background: var(--swatch-white);
}

.side-swatch.is-black,
.side-swatch-black {
  background: var(--swatch-black);
}

.player-bar-name {
  font-weight: 650;
  font-size: var(--fs-lg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 3ch;
  flex: 0 1 auto;
}

.player-stat {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  white-space: nowrap;
}

.player-stat-value {
  font-size: var(--fs-lg);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.player-stat-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
}

.error-chip {
  font-size: var(--fs-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}

.player-bar-clock-note {
  font-size: var(--fs-xs);
  font-style: italic;
  color: var(--text-muted);
  white-space: nowrap;
}

.clock {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1;
  min-width: 92px;
  text-align: right;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--clock-bg);
  color: var(--clock-text);
  transition: background-color 0.2s ease, opacity 0.2s ease;
}

.clock.active {
  background: var(--clock-active-bg);
  color: var(--clock-active-text);
}

.clock.low {
  color: var(--clock-low-text);
}

.clock.active.low {
  background: var(--clock-low-bg);
  color: var(--clock-low-text);
}

.results-panel.live-offline .clock {
  opacity: 0.45;
}

.clock-info {
  opacity: 0.7;
}

@container (max-width: 520px) {
  .player-stat-label .info-icon,
  .clock-info {
    display: none;
  }
  .player-bar-clock-note {
    font-size: 11px;
  }
}

@container (max-width: 420px) {
  .player-bar-clock-note {
    display: none;
  }
}

/* --- Board ----------------------------------------------------------------- */

.board-wrap {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
}

.chessboard {
  width: calc(var(--board-size) - 4px);
  transition: filter 0.25s ease, opacity 0.25s ease;
}

.board-b72b1 {
  border-color: var(--board-frame) !important;
}

.white-1e1d7 {
  background-color: var(--board-light) !important;
  color: var(--board-dark) !important;
}

.black-3c85d {
  background-color: var(--board-dark) !important;
  color: var(--board-light) !important;
}

.notation-322f9 {
  font-size: 12px !important;
  font-weight: 600;
}

.square-55d63.highlight-from {
  box-shadow: inset 0 0 0 999px var(--highlight-from);
}

.square-55d63.highlight-to {
  box-shadow: inset 0 0 0 999px var(--highlight-to);
}

.board-wrap.is-offline .chessboard {
  filter: blur(2px) grayscale(0.4);
  opacity: 0.6;
}

.board-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--overlay-scrim);
  z-index: 20;
}

.board-overlay-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: var(--fs-lg);
  font-weight: 600;
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.board-badge {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: var(--fs-md);
  font-weight: 650;
}

.board-controls {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  height: var(--controls-h);
  margin-top: 2px;
}

.board-controls button {
  flex: 1 1 0;
  height: 30px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--fs-lg);
  line-height: 1;
}

.board-controls button:hover {
  background: var(--surface-hover);
}

.board-controls .play-button {
  flex: 1.4 1 0;
  font-size: var(--fs-md);
  font-weight: 600;
}

.board-controls button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}

.ply-indicator {
  flex: 0 0 auto;
  min-width: 72px;
  text-align: right;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.new-move-pill {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 40;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  box-shadow: var(--shadow);
  cursor: pointer;
}

/* --- Side column ------------------------------------------------------------- */

.side-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-block: 6px;
}

.results-title {
  font-size: var(--fs-lg);
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 0 1 auto;
}

.switch {
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch-track {
  position: relative;
  width: 30px;
  height: 17px;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background-color 0.15s ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--surface);
  transition: transform 0.15s ease;
}

.switch input:checked + .switch-track {
  background: var(--accent);
}

.switch input:checked + .switch-track::after {
  transform: translateX(13px);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.metrics-glossary {
  position: relative;
}

.metrics-glossary summary {
  list-style: none;
}

.metrics-glossary summary::-webkit-details-marker {
  display: none;
}

.metrics-glossary-list {
  position: absolute;
  z-index: 35;
  right: 0;
  top: calc(100% + 6px);
  width: min(460px, calc(100vw - 32px));
  max-height: 60vh;
  overflow-y: auto;
  margin: 0;
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
  font-size: var(--fs-sm);
}

.metrics-glossary-list dt {
  font-weight: 650;
  margin-top: var(--space-2);
}

.metrics-glossary-list dt:first-child {
  margin-top: 0;
}

.metrics-glossary-list dd {
  margin: 0;
  color: var(--text-muted);
}

.live-status-panel {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-block: 6px;
  font-size: var(--fs-sm);
}

.live-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-muted);
}

.live-status-panel[data-state="connected"] .live-dot {
  background: #3fae62;
  box-shadow: 0 0 0 3px rgba(63, 174, 98, 0.25);
}

.live-status-panel[data-state="connecting"] .live-dot,
.live-status-panel[data-state="reconnecting"] .live-dot {
  background: var(--zone-unusual);
}

.live-status-panel[data-state="disconnected"] .live-dot,
.live-status-panel[data-state="error"] .live-dot {
  background: var(--error);
}

.live-status-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.live-status-panel[data-state="error"] .live-status-text {
  white-space: normal;
}

.live-status-actions {
  margin-left: auto;
  display: inline-flex;
  gap: var(--space-1);
}

.sample-meta-box {
  font-size: var(--fs-sm);
  padding-block: 6px;
}

.sample-meta-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.sample-meta-title {
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 0 0 auto;
  max-width: 65%;
}

.sample-meta-header .sample-tag {
  min-width: 0;
  flex: 0 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sample-meta-details {
  margin: var(--space-2) 0 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 2px var(--space-3);
  font-size: var(--fs-sm);
}

.sample-meta-details dt {
  color: var(--text-muted);
}

.sample-meta-details dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.sample-meta-description {
  grid-column: 1 / -1;
  color: var(--text-muted);
  margin: 0 0 var(--space-1);
}

.warnings-box {
  font-size: var(--fs-sm);
  padding-block: 6px;
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn-text);
}

.warnings-box summary {
  cursor: pointer;
  font-weight: 600;
}

.warnings-box ul {
  margin: var(--space-1) 0 0;
  padding-left: 18px;
  color: var(--text);
}

/* --- Suspicion ------------------------------------------------------------- */

/* One grid for both rows (rows use display: contents) so the chip and
   value columns size to the widest entry and stay aligned. */
.suspicion-section {
  display: grid;
  grid-template-columns: max-content max-content max-content minmax(0, 1fr);
  align-items: center;
  gap: 6px var(--space-2);
}

.suspicion-section > .card-head {
  grid-column: 1 / -1;
}

.suspicion-bar-row {
  display: contents;
}

.suspicion-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.suspicion-value {
  font-size: var(--fs-lg);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.suspicion-scale-wrap {
  position: relative;
  min-width: 0;
}

.suspicion-scale {
  display: flex;
  height: 22px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  min-width: 0;
}

.suspicion-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  /* overflow: hidden below already zeroes the flex-item automatic minimum
     size (it only defaults to min-content when overflow is visible), so a
     zone can otherwise shrink smaller than its own label needs. Force
     min-content back so a squeezed zone borrows space from its siblings
     instead of clipping its label; renderSuspicionScale() overrides this
     to 0 for zones meant to collapse fully (the no-cutoffs fallback). */
  min-width: min-content;
  overflow: hidden;
  transition: flex-basis 0.3s ease;
}

.suspicion-zone-typical {
  background: var(--zone-typical);
  color: var(--zone-typical-text);
  flex-basis: 100%;
}

.suspicion-zone-unusual {
  background: var(--zone-unusual);
  color: var(--zone-unusual-text);
  flex-basis: 0%;
}

.suspicion-zone-highly-unusual {
  background: var(--zone-high);
  color: var(--zone-high-text);
  flex-basis: 0%;
}

.suspicion-zone-label {
  display: block;
  max-width: 100%;
  padding: 0 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-xs);
  font-weight: 650;
}

.suspicion-marker {
  position: absolute;
  top: -4px;
  bottom: -4px;
  left: 0%;
  width: 4px;
  transform: translateX(-50%);
  border-radius: 2px;
  background: var(--marker);
  box-shadow: 0 0 0 1.5px var(--marker-halo);
  pointer-events: none;
  transition: left 0.3s ease;
}

.suspicion-label-chip {
  justify-self: start;
  max-width: 100%;
  font-size: var(--fs-xs);
  font-weight: 650;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.suspicion-label-chip[data-level="typical"] {
  background: var(--chip-typical-bg);
  color: var(--chip-typical-text);
}

.suspicion-label-chip[data-level="unusual"] {
  background: var(--chip-unusual-bg);
  color: var(--chip-unusual-text);
}

.suspicion-label-chip[data-level="highly_unusual"] {
  background: var(--chip-high-bg);
  color: var(--chip-high-text);
}

/* Method selector: which suspicion score the bars show, with that method's
   own measured results as a one-line caption. */
.suspicion-method-row {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px var(--space-2);
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

.suspicion-method-term {
  font-weight: 600;
}

.suspicion-method-select {
  max-width: 100%;
  min-width: 0;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}

.suspicion-method-select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.suspicion-method-caption {
  flex: 1 1 16rem;
  min-width: 0;
  font-variant-numeric: tabular-nums;
}

/* --- Move list ----------------------------------------------------------------- */

.move-list-panel {
  flex: 1 1 0;
  min-height: 90px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: var(--space-1);
}

.critical-marker-legend {
  color: var(--critical);
}

.synthetic-marker-legend {
  color: var(--synthetic);
}

.move-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) minmax(0, 1fr);
  grid-auto-rows: 26px;
  align-content: start;
}

.move-list-empty {
  grid-column: 1 / -1;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  margin: var(--space-2) 0 0;
}

.move-row {
  display: contents;
}

.move-number {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  background: var(--surface-2);
  font-variant-numeric: tabular-nums;
}

.move-cell {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-2);
  border: none;
  background: none;
  text-align: left;
  padding: 0 8px;
  font-family: var(--mono);
  font-size: var(--fs-md);
  cursor: pointer;
  min-width: 0;
  white-space: nowrap;
}

.move-cell > span:first-child {
  flex: 0 1 8ch;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.move-cell:hover {
  background: var(--surface-hover);
}

.move-cell.active {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 650;
}

.move-cell.critical > span:first-child::after {
  content: " \2605";
  color: var(--critical);
}

.move-cell.active.critical > span:first-child::after {
  color: var(--on-accent);
}

.move-cell.synthetic {
  box-shadow: inset 3px 0 0 var(--synthetic);
}

.move-cell.empty {
  cursor: default;
}

.move-cell-time {
  font-family: inherit;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-weight: 400;
}

.move-cell.active .move-cell-time {
  color: var(--on-accent);
  opacity: 0.85;
}

/* --- Move details --------------------------------------------------------------- */

.metrics-panel {
  flex: 0 0 auto;
  padding-block: 6px;
}

.metrics-panel > summary {
  list-style: none;
  cursor: pointer;
}

.metrics-panel > summary::-webkit-details-marker {
  display: none;
}

.metrics-panel:not([open]) .toggle-caret {
  transform: rotate(-90deg);
}

.metrics-content {
  margin-top: 6px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) max-content minmax(0, 1fr);
  gap: 3px var(--space-3);
  margin: 0;
  font-size: var(--fs-sm);
  align-items: baseline;
}

.metrics-grid dt {
  color: var(--text-muted);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.metrics-grid dd {
  margin: 0;
  font-size: var(--fs-md);
  font-weight: 550;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metrics-grid dd.wide {
  grid-column: span 3;
}

.metrics-grid .delta {
  font-size: var(--fs-xs);
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 2px;
}

/* --- Chart ------------------------------------------------------------------------- */

.chart-title {
  position: absolute;
  top: 8px;
  left: var(--space-3);
  z-index: 1;
  font-size: var(--fs-sm);
  font-weight: 650;
  color: var(--text);
  pointer-events: none;
}

.chart-title .info-icon {
  pointer-events: auto;
}

.chart-canvas-wrap {
  position: relative;
  height: 100%;
}

.chart-canvas-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

/* --- Info icons and popover ---------------------------------------------------- */

.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  font-style: italic;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  vertical-align: middle;
  margin-left: 2px;
}

.info-icon:hover,
.info-icon:focus-visible {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  outline: none;
}

.info-popover {
  position: fixed;
  z-index: 60;
  max-width: 300px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  box-shadow: var(--shadow);
  font-size: var(--fs-sm);
  line-height: 1.4;
}

.info-popover strong {
  display: block;
  margin-bottom: 2px;
}

.info-popover p {
  margin: 0;
  color: var(--text-muted);
}

/* --- Narrow screens (phone layout is a separate pass; keep it usable) --------- */

@media (max-width: 1000px) {
  :root {
    --board-size: min(calc(100vw - 32px), 640px);
  }

  .results-panel {
    grid-template-columns: minmax(0, var(--board-size));
    grid-template-areas:
      "board"
      "side"
      "chart";
  }

  .side-column {
    contain: none;
  }

  .move-list-panel {
    flex: 0 0 auto;
  }

  .move-list {
    height: 260px;
  }

  .input-row {
    flex-wrap: wrap;
  }

  .input-panel-body {
    flex-basis: 100%;
    order: 5;
  }

  .tab-panel.active {
    flex-wrap: wrap;
  }
}

@media (max-width: 520px) {
  .suspicion-section {
    grid-template-columns: max-content max-content minmax(0, 1fr);
  }

  .suspicion-scale-wrap {
    grid-column: 1 / -1;
  }

  .player-bar {
    gap: 6px;
  }

  .player-bar-name {
    font-size: var(--fs-md);
  }

  .clock {
    font-size: 18px;
    min-width: 70px;
  }

  .metrics-grid {
    grid-template-columns: max-content minmax(0, 1fr);
  }

  .metrics-grid dd.wide {
    grid-column: auto;
  }

  .card-subtle {
    display: none;
  }
}
