/* Night palette, shared with scripts/map_clusters.py (NIGHT, DIM, LIGHT, TEXT). */
:root {
  --bg: #0b1a2a;
  --surface: #11263b;
  --line: #24405c;
  --dim: #3a5068;
  --ink: #e8edf2;
  --ink-2: #b4c2d0;
  --muted: #8396aa;
  --accent: #ffd75e;
  --note-bg: rgba(255, 215, 94, 0.07);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --text-width: 48rem;   /* prose column, including its 16px side padding */
  --map-width: 60rem;    /* signal map on wide screens */
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.65 var(--font);
}

/* --- document ------------------------------------------------------------------------- */
.doc {
  max-width: var(--text-width);
  margin: 0 auto;
  padding: 3rem 16px 6rem;
}
.doc h1 { font-size: 2.3rem; line-height: 1.2; margin: 0 0 1.5rem; letter-spacing: -0.01em; }
.doc h2 {
  font-size: 1.5rem; margin: 3.5rem 0 1rem; padding-top: 1rem;
  border-top: 1px solid var(--line); scroll-margin-top: 1rem;
}
.doc h3 { font-size: 1.15rem; margin: 2rem 0 0.5rem; color: var(--accent); scroll-margin-top: 1rem; }
.doc p, .doc li { color: var(--ink-2); }
.doc a { color: var(--accent); }
.doc strong { color: var(--ink); }
.doc img {
  display: block; max-width: 100%; height: auto; margin: 1.25rem auto;
  border-radius: 6px;
}
.doc code {
  font: 0.88em var(--mono); background: var(--surface);
  padding: 0.1em 0.35em; border-radius: 4px;
}
.doc pre { background: var(--surface); padding: 1rem; border-radius: 6px; overflow-x: auto; }
.doc pre code { padding: 0; background: none; }
.doc blockquote {
  margin: 1rem 0; padding: 0.25rem 1rem;
  border-left: 3px solid var(--line); color: var(--ink-2);
}
/* Unfinished parts of the write-up ("> NOTE: ..." in the README). */
.doc blockquote.draft-note {
  border-left: 3px dashed var(--accent); background: var(--note-bg);
  font-size: 0.9rem;
}
.doc table {
  display: block; overflow-x: auto; border-collapse: collapse;
  margin: 1.25rem 0; font-size: 0.9rem;
}
.doc th, .doc td { padding: 0.4rem 0.75rem; border-bottom: 1px solid var(--line); text-align: left; }
.doc th { color: var(--ink); font-weight: 600; }
.doc td { color: var(--ink-2); }

/* --- live Wikidata query cards (<!-- query: name --> in the README) ---------------------- */
.wdq {
  margin: 1.25rem 0; padding: 0.75rem 1rem;
  border: 1px solid var(--line); border-radius: 8px; font-size: 0.9rem;
}
.wdq-about { color: var(--ink-2); margin-bottom: 0.6rem; }
.wdq-about:empty { display: none; }
.wdq-about > :first-child { margin-top: 0; }
.wdq-about > :last-child { margin-bottom: 0; }
.wdq-bar { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; }
.wdq-run {
  font: inherit; font-weight: 600; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; padding: 0.35rem 0.7rem; cursor: pointer;
}
.wdq-run:hover { border-color: var(--muted); }
.wdq-run:disabled { color: var(--muted); cursor: progress; }
.wdq-run:focus-visible, .wdq summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.wdq-sparql { margin-top: 0.6rem; }
.wdq-sparql summary { color: var(--muted); cursor: pointer; }
.wdq-sparql pre { margin: 0.5rem 0 0; font-size: 0.85rem; }
.wdq-note { margin: 0.6rem 0 0; color: var(--muted); font-size: 0.85rem; }
/* About 5 rows under the sticky header (each row ~2.25rem); the rest scrolls. */
.wdq-table { max-height: 13.5rem; overflow: auto; margin-top: 0.5rem; }
.wdq-table table { display: table; margin: 0; width: 100%; font-size: 0.85rem; }
.wdq-table th { position: sticky; top: 0; background: var(--bg); }
.wdq-table td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Section list, only where there's room beside the wide signal map (--map-width + 2 x 14rem;
   media queries can't read variables, so update 88rem if --map-width changes). */
.toc { display: none; }
@media (min-width: 88rem) {
  .toc {
    display: block; position: fixed; top: 3rem; left: calc(50% - var(--map-width) / 2 - 14rem);
    width: 12rem; font-size: 0.85rem;
  }
  .toc a { display: block; padding: 0.25rem 0; color: var(--muted); text-decoration: none; }
  .toc a:hover, .toc a.active { color: var(--ink); }
}

/* --- signal map ----------------------------------------------------------------------- */
.signal-map {
  /* Wider than the text column, up to --map-width, still with a 16px gutter on phones. */
  width: min(var(--map-width), calc(100vw - 32px));
  margin: 2rem 0 2.5rem;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
}
.sm-controls {
  display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center;
  margin-bottom: 0.75rem; font-size: 0.85rem;
}
.signal-map button, .signal-map select {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; padding: 0.35rem 0.7rem; cursor: pointer;
}
.signal-map button:hover { border-color: var(--muted); }
.signal-map button:focus-visible, .signal-map select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
/* k-means types on the left, k-modes families on the right; stacked on narrow screens.
   Both groups use the same 4-column grid, so every button is the same size. */
.sm-filters {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem 2rem; margin-bottom: 0.75rem;
  font-size: 0.85rem;
}
@media (max-width: 900px) { .sm-filters { grid-template-columns: 1fr; } }
.sm-filter-label {
  display: flex; align-items: baseline; gap: 0.4rem; margin: 0 0 0.35rem;
  color: var(--ink); font-weight: 600;
}
.sm-filter-label span { color: var(--muted); font-weight: 400; }
.signal-map .sm-clear {
  margin-left: auto; padding: 0; border: none; background: none;
  color: var(--accent); font-size: 0.8rem; font-weight: 400;
}
.signal-map .sm-clear:hover { text-decoration: underline; }
.sm-clear[hidden] { display: none; }
.sm-chips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.35rem; }
@media (max-width: 480px) { .sm-chips { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.signal-map .sm-chips button {
  display: flex; flex-direction: column; gap: 0.1rem; text-align: left;
  padding: 0.35rem 0.55rem; color: var(--ink); min-width: 0;
}
.chip-top { display: flex; justify-content: space-between; gap: 0.4rem; }
.sm-chips .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.chip-sub {
  font: 0.72rem var(--mono); color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.signal-map .sm-chips button[aria-pressed="true"] {
  color: var(--bg); background: var(--ink); border-color: var(--ink);
}
.sm-chips button[aria-pressed="true"] .n,
.sm-chips button[aria-pressed="true"] .chip-sub { color: var(--line); }
.sm-reset { margin-left: auto; }

.sm-stage {
  position: relative; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  background: var(--bg);
}
.sm-stage canvas { display: block; width: 100%; touch-action: none; cursor: grab; }
.sm-stage canvas.dragging { cursor: grabbing; }
.sm-tooltip {
  position: absolute; pointer-events: none; z-index: 2; max-width: 18rem;
  background: rgba(17, 38, 59, 0.96); border: 1px solid var(--line); border-radius: 6px;
  padding: 0.5rem 0.65rem; font-size: 0.82rem; line-height: 1.4; color: var(--ink-2);
}
.sm-tooltip .code { font: 600 1rem var(--mono); color: var(--ink); display: block; }
.sm-tooltip .name { color: var(--ink); }

.sm-detail {
  display: flex; gap: 1rem; align-items: center; margin-top: 0.75rem; padding: 0.75rem 1rem;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
.sm-detail[hidden] { display: none; }
.sm-lamp {
  flex: none; width: 3.25rem; height: 3.25rem; border-radius: 50%;
  background: var(--dim); border: 1px solid var(--line);
}
.sm-detail-text { flex: 1; min-width: 0; }
.sm-detail-text p { margin: 0; font-size: 0.88rem; color: var(--ink-2); }
.sm-detail-name { color: var(--ink) !important; font-weight: 600; }
.sm-detail-code { font: 600 1.05rem var(--mono); color: var(--ink) !important; }
.sm-detail-close { align-self: flex-start; }
/* One column, the map's full width. */
.sm-caption { font-size: 0.82rem; color: var(--muted); margin: 0.75rem 0 0; }
