:root {
  --bg: #0c0e13;
  --ink: #e8e4d8;
  --ink-dim: #9a968c;
  --ink-faint: #928d81;      /* AA-readable secondary text on --bg */
  --amber: #e8b04a;
  --cyan: #7fd4e6;
  --red: #e0605e;
  --blue: #5b8fd9;
  --panel: rgba(15, 17, 23, 0.92);
  --panel-line: rgba(255, 255, 255, 0.08);
  --serif: ui-serif, Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  --sans: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

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

/* visible keyboard focus for all interactive controls */
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
#twins li:focus-visible, #hof-list li:focus-visible, #search-results li:focus-visible {
  outline: 2px solid var(--cyan); outline-offset: -2px;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
}

canvas#base, canvas#overlay {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
}
canvas#base { cursor: grab; }
canvas#base.dragging { cursor: grabbing; }
canvas#base.hovering { cursor: pointer; }
canvas#overlay { pointer-events: none; }

/* ---- top-left: title ---- */
#hud-tl {
  position: fixed;
  top: 26px;
  left: 32px;
  pointer-events: none;
  user-select: none;
  z-index: 3;
  max-width: 420px;
}
#title {
  font-family: var(--serif);
  font-size: clamp(30px, 4.4vw, 52px);
  font-weight: 500;
  letter-spacing: 0.01em;
  line-height: 0.98;
  color: var(--ink);
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.6);
}
#title::first-letter { color: var(--amber); }
#sub {
  margin-top: 10px;
  font-size: clamp(12px, 1.4vw, 14.5px);
  color: var(--ink-dim);
  line-height: 1.45;
  letter-spacing: 0.01em;
  max-width: 360px;
}

/* ---- top-right: controls ---- */
#hud-tr {
  position: fixed;
  top: 24px;
  right: 24px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  z-index: 5;
}
#modes { display: flex; gap: 5px; }
.chip, #weights-btn, #share-btn, #hof-btn, #hof-close, #card-close, .wp-btn {
  font-family: var(--sans);
}
.chip, #weights-btn, #share-btn {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 8px 13px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  color: var(--ink-dim);
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: color 0.2s, border-color 0.2s, background 0.2s;
  white-space: nowrap;
}
.chip:hover, #weights-btn:hover, #share-btn:hover { color: var(--ink); border-color: rgba(255,255,255,0.22); }
.chip.active { color: var(--bg); background: var(--ink); border-color: var(--ink); font-weight: 600; }
#share-btn { font-size: 15px; padding: 7px 12px; }

/* ---- weights popover ---- */
#weights-wrap { position: relative; }
#weights-pop {
  position: absolute;
  top: 42px;
  right: 0;
  width: 270px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 14px;
  padding: 14px 16px 15px;
  backdrop-filter: blur(12px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
  z-index: 20;
}
.wp-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink);
  margin-bottom: 12px;
}
#weights-reset {
  background: none; border: none; color: var(--ink-faint); cursor: pointer;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em;
}
#weights-reset:hover { color: var(--amber); }
.slider-row { margin-bottom: 11px; }
.slider-row:last-child { margin-bottom: 0; }
.slider-row .sl-top { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 3px; }
.slider-row .sl-name { color: var(--ink); }
.slider-row .sl-val { color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.slider-row input[type=range] {
  width: 100%;
  accent-color: var(--amber);
  height: 16px;
  cursor: pointer;
}
.wp-note { margin-top: 13px; font-size: 10.5px; line-height: 1.4; color: var(--ink-faint); }

/* ---- search ---- */
#search-wrap { position: relative; }
#search {
  width: 190px;
  padding: 8px 14px;
  font-size: 13px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  color: var(--ink);
  outline: none;
  backdrop-filter: blur(6px);
}
#search:focus { border-color: rgba(232, 176, 74, 0.55); }
#search::placeholder { color: var(--ink-faint); }
#search-results {
  position: absolute;
  top: 42px;
  right: 0;
  width: 250px;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  overflow: hidden;
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  z-index: 20;
}
#search-results li {
  padding: 9px 14px;
  font-size: 13px;
  color: var(--ink-dim);
  cursor: pointer;
}
#search-results li.sel, #search-results li:hover { background: rgba(232, 176, 74, 0.14); color: var(--ink); }

/* ---- Hall of Fame ---- */
#hof-btn {
  position: fixed;
  bottom: 26px;
  left: 32px;
  z-index: 4;
  font-size: 12px;
  letter-spacing: 0.06em;
  padding: 9px 15px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  color: var(--ink-dim);
  cursor: pointer;
  backdrop-filter: blur(6px);
}
#hof-btn:hover { color: var(--ink); border-color: rgba(255,255,255,0.22); }
#hof {
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  width: 340px;
  background: var(--panel);
  border-right: 1px solid var(--panel-line);
  backdrop-filter: blur(14px);
  padding: 22px 20px 26px;
  overflow-y: auto;
  z-index: 8;
  animation: drawerIn 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
  scrollbar-width: thin;
}
@keyframes drawerIn { from { transform: translateX(-60px); opacity: 0; } to { transform: none; opacity: 1; } }
#hof-head { display: flex; justify-content: space-between; align-items: center; }
#hof h2 { font-family: var(--serif); font-size: 24px; font-weight: 500; }
#hof-close, #card-close {
  background: none; border: none; color: var(--ink-dim); font-size: 26px; cursor: pointer; line-height: 1;
}
#hof-close:hover, #card-close:hover { color: var(--ink); }
#hof-sub { font-size: 12px; color: var(--ink-dim); line-height: 1.45; margin: 8px 0 16px; }
#hof-list { list-style: none; }
#hof-list li {
  padding: 11px 12px;
  margin: 0 -12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}
#hof-list li:hover { background: rgba(255, 255, 255, 0.05); }
.hof-pair { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.hof-pair .hof-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hof-vs { color: var(--ink-faint); font-size: 11px; }
.hof-meta { font-size: 10.5px; color: var(--ink-faint); margin-top: 4px; letter-spacing: 0.02em; }
.hof-rank { color: var(--ink-faint); font-variant-numeric: tabular-nums; width: 20px; }

/* ---- county / comparison card ---- */
#card {
  position: fixed;
  top: 0; right: 0;
  height: 100vh;
  width: 360px;
  background: var(--panel);
  border-left: 1px solid var(--panel-line);
  backdrop-filter: blur(14px);
  padding: 24px 22px 30px;
  overflow-y: auto;
  z-index: 6;
  animation: cardIn 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
  scrollbar-width: thin;
}
@keyframes cardIn { from { transform: translateX(60px); opacity: 0; } to { transform: none; opacity: 1; } }
#card-close { position: absolute; top: 12px; right: 14px; }
#card h2 {
  font-family: var(--serif);
  font-size: 25px;
  font-weight: 500;
  padding-right: 26px;
  line-height: 1.15;
}
#card-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 6px; }

/* margin + info chips */
.mchip {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.mchip.r { background: rgba(224, 96, 94, 0.16); color: var(--red); }
.mchip.b { background: rgba(91, 143, 217, 0.16); color: var(--blue); }
.mchip.none { background: rgba(255,255,255,0.06); color: var(--ink-dim); }
.mchip.pop { background: rgba(255,255,255,0.05); color: var(--ink-dim); }

/* section headers */
.sect-h {
  margin-top: 20px;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
}
.sect-sub { display: block; font-size: 10.5px; color: var(--ink-faint); text-transform: none; letter-spacing: 0.02em; margin-top: 2px; font-weight: 400; }

/* twins list */
#twins { list-style: none; margin-top: 10px; }
#twins li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  margin: 0 -10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}
#twins li:hover, #twins li.active { background: rgba(127, 212, 230, 0.08); }
.twin-sim { font-size: 12.5px; color: var(--cyan); font-variant-numeric: tabular-nums; width: 34px; }
.twin-name { flex: 1; font-size: 13.5px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.twin-dist { font-size: 11px; color: var(--ink-faint); font-variant-numeric: tabular-nums; width: 58px; text-align: right; }

/* verdict */
#verdict {
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.4;
  color: var(--ink);
  margin: 14px 0 4px;
  padding: 14px 16px;
  background: rgba(255,255,255,0.035);
  border-left: 2px solid var(--amber);
  border-radius: 0 8px 8px 0;
}
#verdict .weak { display: block; font-family: var(--sans); font-size: 12px; color: var(--ink-dim); margin-bottom: 6px; }

/* diff panel */
#diff { margin-top: 14px; }
.diff-note { font-size: 10.5px; color: var(--ink-faint); margin-bottom: 8px; }
.diff-row {
  display: grid;
  grid-template-columns: 1fr 128px;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-top: 1px solid rgba(255,255,255,0.04);
}
.diff-label { font-size: 12px; color: var(--ink); }
.diff-label .grp { color: var(--ink-faint); font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.04em; margin-left: 5px; }
.diff-vals { font-size: 11px; color: var(--ink-dim); font-variant-numeric: tabular-nums; margin-top: 1px; }
.diff-vals .a { color: var(--amber); }
.diff-vals .b.r { color: var(--red); }
.diff-vals .b.b { color: var(--blue); }
.diff-bar { position: relative; height: 16px; }
.diff-bar .axis { position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: rgba(255,255,255,0.14); }
.diff-bar .fill { position: absolute; top: 3px; height: 10px; border-radius: 2px; }
.diff-bar .fill.left { right: 50%; background: var(--amber); }
.diff-bar .fill.right { left: 50%; }
.diff-bar .fill.right.r { background: var(--red); }
.diff-bar .fill.right.b { background: var(--blue); }
.diff-bar .tick { position: absolute; top: 1px; bottom: 1px; width: 2px; background: var(--ink); opacity: 0.7; }

.est-badge {
  font-size: 9px;
  color: var(--amber);
  border: 1px solid rgba(232, 176, 74, 0.4);
  border-radius: 4px;
  padding: 0 4px;
  margin-left: 5px;
  vertical-align: 1px;
}

.nomirror {
  margin-top: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink-dim);
}
.nomirror b { color: var(--ink); font-weight: 600; }
#nomirror-btn {
  margin-top: 14px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 8px 14px;
  background: none;
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  color: var(--ink);
  cursor: pointer;
}
#nomirror-btn:hover { border-color: var(--cyan); color: var(--cyan); }

/* ---- misc ---- */
#tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12.5px;
  z-index: 10;
  white-space: nowrap;
  backdrop-filter: blur(6px);
}
#tooltip .tt-margin.r { color: var(--red); }
#tooltip .tt-margin.b { color: var(--blue); }
#toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  padding: 9px 18px;
  border-radius: 999px;
  z-index: 11;
  max-width: 80vw;
  text-align: center;
}
#hint {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11.5px;
  color: var(--ink-faint);
  letter-spacing: 0.06em;
  z-index: 2;
  transition: opacity 1.2s;
}
#hint.gone { opacity: 0; }
#credit {
  position: fixed;
  bottom: 10px;
  right: 12px;
  font-size: 10.5px;
  color: var(--ink-faint);
  text-decoration: none;
  z-index: 2;
}
#credit:hover { color: var(--ink-dim); }

/* ---- mobile ---- */
@media (max-width: 680px) {
  #hud-tl { top: 14px; left: 16px; max-width: 62vw; }
  #sub { display: none; }
  #hud-tr {
    top: auto;
    bottom: 84px;
    right: 10px;
    left: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
  }
  #search { width: 140px; }
  #search-results { bottom: 44px; top: auto; }
  #weights-pop { top: auto; bottom: 44px; }
  #hof-btn { bottom: 16px; left: 10px; font-size: 11px; padding: 8px 12px; }
  #hof {
    top: auto; bottom: 0; left: 0;
    height: auto; max-height: 66vh; width: 100vw;
    border-right: none; border-top: 1px solid var(--panel-line);
    border-radius: 18px 18px 0 0;
    animation: sheetIn 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  #card {
    top: auto; bottom: 0; right: 0;
    height: auto; max-height: 70vh; width: 100vw;
    border-left: none; border-top: 1px solid var(--panel-line);
    border-radius: 18px 18px 0 0;
    animation: sheetIn 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  @keyframes sheetIn { from { transform: translateY(80px); opacity: 0; } to { transform: none; opacity: 1; } }
  #hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #card, #hof { animation: none; }
}
