/* ——— tokens ——— */
:root {
  --bg: #14110E;
  --bg-raised: #1B1815;
  --bg-inset: #0F0D0A;
  --line: #2A2520;
  --line-strong: #3A332C;
  --fg: #EDE6D6;
  --fg-dim: #A49C8C;
  --fg-muted: #6E6759;
  --accent: #C84B3F;          /* crimson */
  --accent-dim: #7A2E27;
  --good: #8FA96B;            /* muted olive */
  --warn: #D69648;
  --board-light: #E8DFCB;
  --board-dark: #8E7A5A;
  --board-hi: rgba(200, 75, 63, 0.35);
  --board-sel: rgba(143, 169, 107, 0.45);

  --radius-sm: 3px;
  --radius: 6px;
  --radius-lg: 10px;

  --font-ui: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-serif: "IBM Plex Serif", Georgia, serif;
  --font-mono: "IBM Plex Mono", "SF Mono", Menlo, monospace;

  --gutter: 24px;
  --pad: 16px;
}

body.theme-light {
  --bg: #F5F0E4;
  --bg-raised: #FBF7EC;
  --bg-inset: #EBE4D3;
  --line: #D9D0BB;
  --line-strong: #BFB59C;
  --fg: #1A1611;
  --fg-dim: #55503F;
  --fg-muted: #8A8271;
  --accent: #A8382D;
  --accent-dim: #D68A82;
  --board-light: #ECE3CE;
  --board-dark: #A88F67;
}

body.theme-sepia {
  --bg: #2A2118;
  --bg-raised: #332820;
  --bg-inset: #1F1812;
  --line: #463830;
  --line-strong: #5A4B40;
  --fg: #F0DFC3;
  --fg-dim: #BFA985;
  --fg-muted: #88765B;
  --accent: #E08A3C;
  --accent-dim: #8A5224;
}

body.palette-violet { --accent: #8E5FC8; --accent-dim: #4E3573; }
body.palette-ember  { --accent: #D97C3A; --accent-dim: #7A4419; }

body.density-compact { --pad: 10px; --gutter: 14px; }

/* ——— login / loading / empty ——— */
.login-screen, .loading-screen, .empty-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.login-card, .empty-card {
  max-width: 420px;
  width: 100%;
  padding: 40px 32px;
  border: 1px solid var(--line);
  background: var(--bg-raised);
  border-radius: var(--radius-lg);
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
.login-card .brand-mark {
  width: 44px; height: 44px;
  margin: 0 auto 18px;
  display: block;
  transform: none;
}
.login-card .brand-name {
  font-family: var(--font-serif);
  font-size: 30px;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.login-card .brand-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 28px;
}
.login-card .login-desc {
  color: var(--fg-dim);
  font-size: 14px;
  line-height: 1.55;
  margin-bottom: 28px;
  text-align: left;
}
.login-card .login-desc b { color: var(--fg); font-weight: 600; }
.login-card .btn {
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 600;
  width: 100%;
  justify-content: center;
}
.login-card .foot {
  margin-top: 18px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--fg-muted);
  letter-spacing: 0.04em;
}

.loading-screen {
  color: var(--fg-dim);
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.loading-screen .dots::after {
  content: "";
  display: inline-block;
  animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots {
  0%, 20% { content: ""; }
  40% { content: "."; }
  60% { content: ".."; }
  80%, 100% { content: "..."; }
}

.empty-card .empty-title {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 500;
  margin-bottom: 6px;
}
.empty-card .empty-sub {
  color: var(--fg-dim);
  font-size: 13px;
  line-height: 1.55;
  margin-bottom: 22px;
}

/* sync progress pill extends */
.sync-pill.error .dot { background: var(--accent); animation: none; }

/* logout button */
.topbar .logout-btn {
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 4px;
}
.topbar .logout-btn:hover { color: var(--fg); background: var(--bg-raised); }

/* ——— reset ——— */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); }
body {
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum" 1, "cv11" 1;
  min-height: 100vh;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
h1, h2, h3, h4, p { margin: 0; }
input, select { font: inherit; color: inherit; }

/* ——— layout ——— */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.brand-mark {
  width: 22px; height: 22px;
  position: relative;
  display: inline-block;
  transform: translateY(4px);
}
.brand-mark::before, .brand-mark::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--fg);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.brand-mark::after {
  background: var(--accent);
  transform: scale(0.55) translateY(-18%);
  transform-origin: bottom;
}
.brand-name {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.brand-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.topbar .user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--fg-dim);
  font-size: 13px;
}
.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-dim), var(--accent));
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-size: 11px;
  color: #fff;
  font-weight: 600;
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 11px 5px 9px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--fg-dim);
}
.sync-pill .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--good) 25%, transparent);
}
.sync-pill.syncing .dot { background: var(--warn); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--bg-raised);
  color: var(--fg);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.btn:hover { border-color: var(--fg-dim); }
.btn-primary {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}
.btn-primary:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--bg-raised); }

/* ——— main grid ——— */
.main {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 360px;
  gap: 0;
  min-height: 0;
}
.col {
  padding: var(--gutter);
  min-width: 0;
}
.col-filters { border-right: 1px solid var(--line); }
.col-center { background: var(--bg); }
.col-right { border-left: 1px solid var(--line); background: var(--bg-inset); }

/* ——— filters ——— */
.filter-title {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin: 20px 0 8px;
}
.filter-title:first-child { margin-top: 0; }

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  padding: 2px;
  gap: 2px;
}
.seg button {
  padding: 6px 8px;
  font-size: 12px;
  color: var(--fg-dim);
  border-radius: calc(var(--radius) - 2px);
  font-weight: 500;
}
.seg button.active {
  background: var(--fg);
  color: var(--bg);
}
.seg button:not(.active):hover { color: var(--fg); }

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  color: var(--fg-dim);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.check-row:hover { color: var(--fg); }
.check-row input {
  appearance: none;
  width: 14px; height: 14px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--bg-raised);
  cursor: pointer;
  display: grid; place-items: center;
  margin: 0;
}
.check-row input:checked {
  background: var(--fg);
  border-color: var(--fg);
}
.check-row input:checked::after {
  content: "";
  width: 6px; height: 6px;
  background: var(--bg);
  clip-path: polygon(14% 44%, 0 60%, 40% 100%, 100% 20%, 84% 6%, 40% 70%);
}

.range-row {
  display: flex; align-items: center; gap: 8px;
}
.range-row input[type="number"] {
  flex: 1 1 0; min-width: 0;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 5px 7px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.range-row input:focus { outline: none; border-color: var(--fg-dim); }

.summary-card {
  margin-top: 28px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-raised);
}
.summary-card .kpi {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 4px 0;
}
.summary-card .kpi + .kpi { border-top: 1px dashed var(--line); margin-top: 4px; padding-top: 8px; }
.summary-card .kpi .label {
  font-size: 12px; color: var(--fg-dim);
}
.summary-card .kpi .val {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
}
.summary-card .kpi .val.bad { color: var(--accent); }

/* ——— center column ——— */
.center-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 16px;
}
.center-head h1 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 26px;
  letter-spacing: -0.015em;
  line-height: 1.1;
}
.center-head .crumbs {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}
.center-head .actions { display: flex; gap: 8px; }

/* ——— board + eval ——— */
.board-shell {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 20px;
  align-items: start;
  margin-bottom: 24px;
}
.board-wrap {
  width: 380px;
  aspect-ratio: 1;
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
}

.board-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
  width: 380px;
}
.lichess-link-btn {
  justify-content: center;
  text-align: center;
  text-decoration: none;
}

/* ——— simplified layout ——— */
.simple-main {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 0;
  min-height: 0;
  flex: 1;
}
.leaks-col {
  border-right: 1px solid var(--line);
  background: var(--bg-inset);
  padding: 20px 16px 24px;
  max-height: calc(100vh - 58px);
  overflow-y: auto;
}
.board-panel {
  padding: 28px 32px 40px;
  min-width: 0;
}

.leaks-head {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.leaks-head h2 {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 500;
  margin-bottom: 4px;
}
.leaks-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
  letter-spacing: 0.04em;
}
.leaks-sub .bad { color: var(--accent); font-weight: 600; }
.leaks-loading {
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 24px 8px;
  text-align: center;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 18px;
  padding: 12px 24px 14px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
}
.filter-bar .fb-group { display: flex; flex-direction: column; gap: 4px; }
.filter-bar .fb-lbl {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.filter-bar .seg { min-width: 0; }
.filter-bar input[type="number"] {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 7px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: inherit;
}

.board-panel-inner {
  display: grid;
  grid-template-columns: minmax(420px, 520px) minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}
.board-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.cg-wrap {
  width: 100%;
  max-width: 520px;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
  position: relative;
}
.cg-host { width: 100%; height: 100%; }
/* Chessground generates cg-wrap + cg-container inside; height flows from parent */
.cg-host cg-container, .cg-host cg-board { width: 100% !important; height: 100% !important; }

.board-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.board-controls .btn { padding: 7px 12px; }
.board-controls .lichess-link-btn { margin-left: auto; }

.info-side {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.eval-badge {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  font-family: var(--font-mono);
}
.eval-badge .e-v { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.eval-badge .e-src {
  font-size: 10px; color: var(--fg-muted);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.eval-badge.loading { color: var(--fg-muted); font-size: 12px; }
.eval-badge.neutral .e-v,
.eval-badge.neutral { color: var(--fg-muted); font-size: 13px; }
.eval-badge.even .e-v { color: var(--fg); }
.eval-badge.white-small .e-v, .eval-badge.white-big .e-v { color: var(--good); }
.eval-badge.black-small .e-v, .eval-badge.black-big .e-v { color: var(--accent); }

.move-line-box {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-raised);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
}
.move-line-box .tok {
  display: inline-block;
  padding: 1px 4px;
  border-radius: 3px;
  cursor: pointer;
}
.move-line-box .tok:hover { background: var(--bg); }
.move-line-box .tok.hl { color: var(--accent); font-weight: 600; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 20px;
}
.stat {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-raised);
}
.stat-lbl {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-muted);
  margin-bottom: 4px;
}
.stat-val {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.stat-val.bad { color: var(--accent); }

.empty-board {
  display: grid;
  place-items: center;
  min-height: 440px;
  padding: 40px;
  text-align: center;
  color: var(--fg-muted);
  font-size: 14px;
}
.empty-board .empty-sub { max-width: 360px; line-height: 1.5; }

.sync-pill.analyzing .dot { background: var(--warn); animation: pulse 1.4s ease-in-out infinite; }

/* responsive: stack on narrow */
@media (max-width: 1080px) {
  .simple-main { grid-template-columns: 1fr; }
  .leaks-col { max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .board-panel-inner { grid-template-columns: 1fr; }
}
.eval-tape {
  width: 18px;
  height: 380px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}
.eval-tape .white {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--fg);
  transition: height .35s cubic-bezier(.2,.7,.3,1);
}
.eval-tape .zero {
  position: absolute; left: -2px; right: -2px; top: 50%;
  height: 1px; background: var(--accent);
}
.eval-tape .label {
  position: absolute; left: 100%; margin-left: 6px;
  font-family: var(--font-mono); font-size: 11px; color: var(--fg-dim);
  white-space: nowrap;
}

.board-meta {
  flex: 1;
  min-width: 0;
}
.board-meta .move-line {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--fg-dim);
  margin-bottom: 12px;
  line-height: 1.7;
  word-break: break-word;
}
.board-meta .move-line .hl {
  color: var(--accent);
  font-weight: 600;
}
.board-meta .move-line .tok {
  display: inline-block;
  padding: 1px 4px;
  border-radius: 3px;
}
.board-meta .move-line .tok:hover { background: var(--bg-raised); cursor: pointer; }

.callout {
  border-left: 2px solid var(--accent);
  padding: 8px 12px;
  margin-top: 16px;
  background: color-mix(in oklab, var(--accent) 6%, transparent);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 14px;
  color: var(--fg);
  line-height: 1.5;
}
.callout .src {
  display: block;
  font-family: var(--font-mono);
  font-style: normal;
  font-size: 11px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 6px;
}

/* ——— tree ——— */
.tree-section {
  border-top: 1px solid var(--line);
  padding-top: 20px;
}
.tree-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}
.tree-head h2 {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 500;
}
.tree-head .legend {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
}
.legend-bar {
  display: inline-block;
  width: 120px; height: 8px;
  background: linear-gradient(to right,
    color-mix(in oklab, var(--fg) 10%, var(--bg-raised)),
    color-mix(in oklab, var(--accent) 50%, var(--bg-raised)),
    var(--accent));
  border-radius: 2px;
  border: 1px solid var(--line);
}

.tree-scroll {
  overflow-x: auto;
  padding-bottom: 10px;
}
.tree-scroll::-webkit-scrollbar { height: 8px; }
.tree-scroll::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }

/* flow tree */
.flow {
  display: flex;
  gap: 28px;
  align-items: stretch;
  min-width: fit-content;
  padding: 4px 2px 2px;
}
.flow-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 120px;
  position: relative;
}
.flow-col-head {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: 4px;
  padding-left: 2px;
}
.node {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-raised);
  cursor: pointer;
  position: relative;
  transition: transform .1s, border-color .15s;
  min-width: 120px;
}
.node::before {
  /* severity bar */
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--sev-color, transparent);
  border-radius: var(--radius) 0 0 var(--radius);
}
.node:hover { border-color: var(--fg-dim); }
.node.active { border-color: var(--fg); background: var(--bg); box-shadow: 0 0 0 1px var(--fg); }
.node .mv {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.01em;
  color: var(--fg);
}
.node .cnt {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-dim);
  align-self: center;
}
.node .drop {
  grid-column: 1 / -1;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--sev-color, var(--fg-muted));
  display: flex;
  justify-content: space-between;
  letter-spacing: 0.02em;
}
.node .wr { color: var(--fg-muted); }
.node.dim { opacity: .42; }

/* indented tree */
.indent {
  font-family: var(--font-mono);
  font-size: 13px;
}
.indent-row {
  display: grid;
  grid-template-columns: 28px 1fr 64px 64px 64px;
  align-items: center;
  gap: 10px;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.indent-row:hover { background: var(--bg-raised); }
.indent-row.active { background: var(--bg-raised); outline: 1px solid var(--fg); }
.indent-row .tw { color: var(--fg-muted); }
.indent-row .mv { font-weight: 600; }
.indent-row .mv .muted { color: var(--fg-muted); font-weight: 400; }
.indent-row .val { font-size: 11.5px; text-align: right; color: var(--fg-dim); }
.indent-row .val.bad { color: var(--accent); }
.indent-head {
  display: grid;
  grid-template-columns: 28px 1fr 64px 64px 64px;
  gap: 10px;
  padding: 5px 8px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-muted);
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}
.indent-head .val { text-align: right; }

/* ——— right panel: worst openings ——— */
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
}
.panel-head h2 {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 500;
}
.panel-head .count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.worst-item {
  display: grid;
  grid-template-columns: 16px 48px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
}
.worst-item:hover { background: var(--bg-raised); }
.worst-item.active {
  background: var(--bg-raised);
  border-color: var(--line-strong);
}
.worst-item .rank {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
  text-align: right;
}
.worst-item .mini {
  width: 48px; height: 48px;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.worst-item .name {
  font-family: var(--font-serif);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  color: var(--fg);
}
.worst-item .meta {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 3px;
}
.worst-item .metric {
  text-align: right;
  font-family: var(--font-mono);
}
.worst-item .metric .big {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -0.01em;
  line-height: 1;
}
.worst-item .metric .sub {
  font-size: 10.5px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
}

.sort-bar {
  display: flex;
  gap: 4px;
  padding: 6px 0 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
}
.sort-bar button {
  padding: 4px 8px;
  border-radius: 4px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.sort-bar button:hover { color: var(--fg); }
.sort-bar button.on { background: var(--bg-raised); color: var(--fg); }

/* ——— tweaks panel ——— */
.tweaks-panel {
  position: fixed;
  bottom: 20px; right: 20px;
  width: 280px;
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 50px rgba(0,0,0,.5);
  z-index: 50;
  overflow: hidden;
  font-size: 13px;
}
.tweaks-panel .head {
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
}
.tweaks-panel .head .t {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 500;
}
.tweaks-panel .head .k {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.tweaks-panel .body { padding: 12px 14px 14px; }
.tweaks-panel .group { margin-bottom: 14px; }
.tweaks-panel .group:last-child { margin-bottom: 0; }
.tweaks-panel .lbl {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-muted);
  margin-bottom: 6px;
}

/* chessboard */
.cb {
  width: 100%; height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
}
.cb .sq {
  position: relative;
  display: grid;
  place-items: center;
}
.cb .sq.l { background: var(--board-light); }
.cb .sq.d { background: var(--board-dark); }
.cb .sq.hi { background: var(--board-hi); }
.cb .sq.from { background: var(--board-sel); }
.cb .sq .coord {
  position: absolute;
  font-family: var(--font-mono);
  font-size: 9px;
  color: color-mix(in oklab, var(--board-dark) 60%, transparent);
  pointer-events: none;
}
.cb .sq.l .coord { color: color-mix(in oklab, var(--board-dark) 80%, transparent); }
.cb .sq.d .coord { color: color-mix(in oklab, var(--board-light) 70%, transparent); }
.cb .sq .coord.f { bottom: 1px; right: 3px; }
.cb .sq .coord.r { top: 1px; left: 3px; }
.cb .piece {
  width: 86%; height: 86%;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.25));
  z-index: 1;
}

/* arrow overlay */
.cb-arrow-layer {
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 2;
}

/* mini board simpler */
.mini .cb .sq .coord { display: none; }
.mini .cb .piece { width: 90%; height: 90%; filter: none; }

/* footer spacer for tweak panel */
.main { padding-bottom: 0; }

/* scrollbars */
.col-right { overflow-y: auto; max-height: calc(100vh - 58px); }
.col-filters { overflow-y: auto; max-height: calc(100vh - 58px); }

/* tooltip */
.tip {
  position: fixed;
  pointer-events: none;
  background: var(--bg-inset);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg);
  z-index: 100;
  max-width: 220px;
  box-shadow: 0 8px 20px rgba(0,0,0,.4);
  line-height: 1.5;
}
.tip .row { display: flex; justify-content: space-between; gap: 14px; }
.tip .row + .row { margin-top: 3px; }
.tip .k { color: var(--fg-muted); }
.tip .v.bad { color: var(--accent); }

/* overview grid up top of center */
.overview {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow: hidden;
}
.ov-cell {
  background: var(--bg);
  padding: 12px 14px;
}
.ov-cell .l {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}
.ov-cell .v {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.ov-cell .v.bad { color: var(--accent); }
.ov-cell .v .unit {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
  margin-left: 3px;
  letter-spacing: 0;
}

.spark {
  display: flex; gap: 2px; align-items: flex-end;
  height: 22px; margin-top: 4px;
}
.spark .b {
  flex: 1;
  background: var(--fg-dim);
  opacity: .4;
  border-radius: 1px 1px 0 0;
}
.spark .b.hot { background: var(--accent); opacity: .9; }
