/* topothesis — understated academic style (after tjards.github.io / Hugo PaperMod).
   All colors live here as custom properties; change them in one place. */

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --text: #1f1f1f;
  --text-muted: #6c6c6c;
  --heading: #1e1e1e;
  --border: #eeeeee;
  --border-strong: #d6d6d6;
  --link: #1e1e1e;
  --link-underline: #b8b8b8;
  --accent: #b07d2b;          /* candidate markers (subdued ochre) */
  --seed-outline: #1e1e1e;    /* researcher's own papers */
  --code-bg: #f5f5f5;
  --note-bg: #faf8f3;
  --error: #9b2c2c;
  --ok: #2f6f4f;
  /* Muted cluster palette (blue/teal family first). */
  --c0: #4e79a7; --c1: #59a1a0; --c2: #8aa6c1; --c3: #6b8e7f; --c4: #9c8fb8;
  --c5: #7f9fb5; --c6: #a3b18a; --c7: #b5a07f; --c8: #6f8fa8; --c9: #94a3a3;
  --c10: #7a8cb0; --c11: #8fb3a6; --c12: #b0a3b8; --c13: #a7b6c9; --c14: #87a58d;
  --noise: #d4d4d4;

  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell,
    "Open Sans", "Helvetica Neue", sans-serif;
  --font-mono: Menlo, Monaco, Consolas, "Courier New", monospace;
  --measure: 720px;
  --wide: 1180px;
  --gap: 24px;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1e20;
    --surface: #2e2e33;
    --text: #c4c4c5;
    --text-muted: #9b9c9d;
    --heading: #dadadb;
    --border: #333333;
    --border-strong: #4a4a4f;
    --link: #dadadb;
    --link-underline: #6c6c6c;
    --accent: #d4a85a;
    --seed-outline: #f0f0f0;
    --code-bg: #2a2b2e;
    --note-bg: #26272a;
    --error: #e08a8a;
    --ok: #8ccfa9;
    --noise: #4a4a4f;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.6;
}
a { color: var(--link); text-decoration: underline; text-decoration-color: var(--link-underline);
    text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--link); }
h1, h2, h3 { color: var(--heading); line-height: 1.25; font-weight: 700; }
h1 { font-size: 2rem; margin: 0 0 0.6em; }
h2 { font-size: 1.35rem; margin: 1.8em 0 0.6em; }
h3 { font-size: 1.05rem; margin: 1.4em 0 0.4em; }
p { margin: 0 0 1em; }
small, .muted { color: var(--text-muted); }
.cite-block { position: relative; border: 1px solid var(--border); border-radius: var(--radius);
               background: var(--code-bg); padding: 12px 84px 12px 14px; margin: 0 0 14px; }
.cite-block p { margin: 0; }
.cite-block pre { margin: 0; font-family: var(--font-mono); font-size: 0.82rem; white-space: pre; overflow-x: auto; }
.cite-block .copy { position: absolute; top: 8px; right: 8px; margin: 0; }
code { font-family: var(--font-mono); font-size: 0.85em; background: var(--code-bg);
       padding: 0.1em 0.35em; border-radius: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- layout */
.header { border-bottom: 1px solid var(--border); }
.nav { max-width: var(--wide); margin: 0 auto; padding: 0 var(--gap); display: flex;
       align-items: center; justify-content: space-between; min-height: 60px; flex-wrap: wrap; gap: 8px; }
.logo { display: inline-flex; align-items: center; padding: 8px 0; text-decoration: none; }
.logo img { display: block; height: 46px; width: auto; }
@media (prefers-color-scheme: dark) { .logo img { filter: invert(1); } }  /* black mark -> white on dark */
.menu { list-style: none; margin: 0 0 0 auto; padding: 0; display: flex; gap: 20px; }  /* right, even without a logo */
.hero-logo { text-align: center; margin: 4px 0 28px; }
.hero-logo img { height: 96px; width: auto; }
@media (prefers-color-scheme: dark) { .hero-logo img { filter: invert(1); } }
.menu a { text-decoration: none; color: var(--text); }
.menu a[aria-current="page"] { border-bottom: 2px solid currentColor; }
main { padding: 32px var(--gap) 64px; }
.narrow { max-width: var(--measure); margin: 0 auto; }
.wide { max-width: var(--wide); margin: 0 auto; }
footer { border-top: 1px solid var(--border); color: var(--text-muted); font-size: 0.85rem;
         padding: 20px var(--gap); text-align: center; }
footer a { text-decoration: none; }

/* ---------- home */
.tagline { color: var(--text-muted); margin-top: -0.4em; }
blockquote { margin: 1.6em 0; padding: 0 0 0 1em; border-left: 3px solid var(--border-strong);
             color: var(--text); font-style: italic; }
blockquote footer, blockquote .cite { border: 0; padding: 0; text-align: left; font-style: normal;
                                      font-size: 0.9rem; color: var(--text-muted); margin-top: 0.4em; }
form.start { margin: 2em 0 1em; display: flex; gap: 10px; flex-wrap: wrap; padding: 18px 20px 14px;
             border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); }
form.start label { flex-basis: 100%; font-size: 0.9rem; color: var(--text-muted); }
input[type="text"], input[type="search"], input[type="password"], textarea, select {
  font: inherit; font-size: 0.95rem; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 8px 10px; }
form.start input[type="text"] { flex: 1 1 320px; min-width: 0; }
form.start label.checkbox { flex-basis: auto; }
/* Basic / Premium switch above the search box */
.tier { flex-basis: 100%; display: flex; margin: 0 0 4px; padding: 0; border: 0; min-width: 0; }
form.start .tier label { flex-basis: auto; position: relative; padding: 4px 14px; font-size: 0.85rem; cursor: pointer;
              color: var(--text-muted); border: 1px solid var(--border-strong); }
.tier label:first-of-type { border-radius: 999px 0 0 999px; }
.tier label:last-of-type { border-radius: 0 999px 999px 0; border-left: 0; }
.tier input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.tier label:has(input:checked) { background: var(--heading); border-color: var(--heading); color: var(--bg); }
.tier label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.premium-code { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 6px; }
.premium-code input { flex: 0 1 260px; min-width: 0; }
.tier-note { flex-basis: 100%; margin: 2px 0 0; font-size: 0.85rem; color: var(--text-muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; vertical-align: baseline; }
button, .button {
  font: inherit; font-size: 0.95rem; cursor: pointer; color: var(--bg); background: var(--heading);
  border: 1px solid var(--heading); border-radius: var(--radius); padding: 8px 16px; text-decoration: none;
  display: inline-block; }
button.secondary, .button.secondary { background: transparent; color: var(--text); border-color: var(--border-strong); }
button.small { font-size: 0.8rem; padding: 3px 10px; margin-left: auto; }
button:disabled { opacity: 0.5; cursor: default; }
.checkbox { font-size: 0.9rem; color: var(--text-muted); display: inline-flex; gap: 6px; align-items: center; }

/* ---------- generic pieces */
.note { background: var(--note-bg); border: 1px solid var(--border); border-radius: var(--radius);
        padding: 12px 16px; font-size: 0.9rem; margin: 1em 0; }
.error { color: var(--error); }
.stats { display: flex; flex-wrap: wrap; gap: 6px 22px; font-size: 0.9rem; color: var(--text-muted);
         margin: 0 0 1em; padding: 0; list-style: none; }
.stats b { color: var(--text); font-weight: 600; }
table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-muted); font-weight: 600; }
table.tools td:first-child { white-space: nowrap; }
@media (max-width: 600px) { table.tools td:first-child { white-space: normal; } }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.demo { margin: 1.6em 0; text-align: center; }
.demo img { display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid var(--border);
            border-radius: var(--radius); }
.demo figcaption { margin-bottom: 6px; font-size: 0.9rem; }
.runs { list-style: none; padding: 0; margin: 0; }
.runs li { padding: 8px 0; border-bottom: 1px solid var(--border); display: flex; gap: 12px; align-items: baseline; }
.runs .run-actions { margin-left: auto; flex: none; display: flex; gap: 6px; align-items: baseline; }
.runs .run-actions button.small { margin-left: 0; }
/* Basic / Premium label: same size as the small buttons, coloured from the plot palette */
.tier-badge { display: inline-block; font-size: 0.8rem; padding: 3px 10px; border-radius: var(--radius);
              border: 1px solid; color: var(--text); text-decoration: none; }
a.tier-badge:hover { color: var(--heading); filter: brightness(0.95); }
form.start { scroll-margin-top: 24px; }
form.start.off { opacity: 0.45; pointer-events: none; user-select: none; }   /* builds temporarily off */
#buildsOff { margin-bottom: 0; }   /* /#start: leave a little room above the options */
.tier-badge.basic { border-color: var(--c0); background: color-mix(in srgb, var(--c0) 16%, transparent); }
.nowrap { white-space: nowrap; }
.tier-badge.premium { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, transparent); }
.new-run { margin: 1.2em 0 0; }
.narrow-list { max-width: var(--measure); }
[hidden] { display: none !important; }
.tag { display: inline-block; font-size: 0.75rem; padding: 1px 6px; border: 1px solid var(--border-strong);
       border-radius: 3px; color: var(--text-muted); vertical-align: middle; }
.tag.seed { border-color: var(--seed-outline); color: var(--text); }
details summary { cursor: pointer; color: var(--text-muted); font-size: 0.9rem; }

/* ---------- progress */
.stages { list-style: none; padding: 0; margin: 1em 0; font-size: 0.95rem; }
.stages li { padding: 4px 0; display: flex; gap: 10px; }
.stages .mark { width: 1.2em; text-align: center; color: var(--text-muted); }
.stages li.running { font-weight: 600; }
.stages li.done .mark { color: var(--ok); }
.stages li.failed .mark { color: var(--error); }

/* ---------- explore */
.explore { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--gap); align-items: start; }
.controls { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; font-size: 0.9rem; margin: 0 0 10px; }
#map { width: 100%; height: 620px; border: 1px solid var(--border); border-radius: var(--radius); }
.panel h2 { margin-top: 0; font-size: 1.1rem; }
.cands { list-style: none; padding: 0; margin: 0; }
.cands li { border-bottom: 1px solid var(--border); }
.cands button { all: unset; display: block; width: 100%; padding: 10px 4px; cursor: pointer; font-size: 0.9rem; }
.cands button:focus-visible { outline: 2px solid var(--accent); }
.cands li.active { background: var(--note-bg); }
.cands .pair { color: var(--heading); }
.cands .scores { color: var(--text-muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.cands .hyp { display: inline-block; margin: 4px 0 2px; font-size: 0.85rem; font-style: italic; line-height: 1.4; }
p.hyp { font-size: 0.92rem; line-height: 1.45; }
.rank { display: inline-block; min-width: 1.6em; color: var(--accent); font-weight: 700; }
.detail { font-size: 0.9rem; margin-top: 14px; }
/* Selected candidate, under the map */
.cand-card { padding: 12px 16px; border: 1px solid var(--border); border-left: 3px solid var(--accent);
             border-radius: var(--radius); background: var(--note-bg); }
.cand-card:empty { display: none; }
.cand-card p { margin: 0 0 8px; }
.cand-card p:last-child { margin-bottom: 0; }
.legend { font-size: 0.8rem; color: var(--text-muted); display: flex; gap: 16px; flex-wrap: wrap; margin-top: 6px; }
.legend .sym { display: inline-block; width: 10px; height: 10px; margin-right: 4px; vertical-align: middle; }
.legend .sym.seed { border: 2px solid var(--seed-outline); border-radius: 50%; }
.legend .sym.doc { background: var(--c0); border-radius: 50%; }
.legend .sym.cand { background: var(--accent); transform: rotate(45deg); }
.paperlist { max-height: 420px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }

/* ---------- candidate */
.scoregrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 1em 0; }
.scoregrid > div { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; }
.scoregrid .k { font-size: 0.75rem; color: var(--text-muted); }
.scoregrid .v { font-variant-numeric: tabular-nums; font-size: 1rem; color: var(--heading); }
.papers { list-style: none; padding: 0; margin: 0; font-size: 0.92rem; }
.papers li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.papers .meta { color: var(--text-muted); font-size: 0.8rem; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
textarea { width: 100%; min-height: 80px; font-family: var(--font-mono); font-size: 0.85rem; }

@media (max-width: 900px) {
  .explore { grid-template-columns: 1fr; }
  #map { height: 460px; }
  .cols { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  body { font-size: 16px; }
  main { padding: 20px 16px 48px; }
  .nav { padding: 0 16px; }
  #map { height: 380px; }
}

/* ---------- map controls (layer switcher, selection) */
.small { font-size: 0.8rem; }
/* Topic-detail zoom: a control overlaid on the map (top-left; Plotly's toolbar is top-right). */
.map-wrap { position: relative; }
.zoom { position: absolute; top: 10px; left: 10px; z-index: 5; display: flex; align-items: center;
        gap: 8px; padding: 5px 10px 5px 6px; border: 1px solid var(--border-strong);
        border-radius: var(--radius); background: color-mix(in srgb, var(--bg) 88%, transparent); }
.zoom input[type="range"] { width: 90px; margin: 0; accent-color: var(--heading); cursor: pointer; }
.zoom-btn { all: unset; cursor: pointer; width: 24px; height: 24px; line-height: 22px; text-align: center;
            font-size: 1rem; border: 1px solid var(--border-strong); border-radius: 50%; color: var(--text);
            background: var(--bg); }
.zoom-btn:hover:not(:disabled) { background: var(--note-bg); }
.zoom-btn:disabled { opacity: 0.35; cursor: default; }
.zoom-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.zoom-label { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.zoom-label b { color: var(--text); font-size: 0.85rem; }
.legend .sym.region { background: var(--accent); opacity: 0.3; border: 1px dashed var(--accent); }
.selbox { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.selbox h3 { margin: 0 0 6px; font-size: 0.95rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { font-size: 0.78rem; border: 1px solid var(--border-strong); border-radius: 12px; padding: 1px 8px; }
.chip .dot { width: 8px; height: 8px; margin-right: 5px; }
