/* The shell: CSS grid, system fonts, light and dark, no framework. */

:root {
    --bg: #ffffff;
    --fg: #1a1d21;
    --muted: #5c6470;
    --line: #dfe3e8;
    --surface: #f7f8fa;
    --accent: #1f6feb;
    --error: #b3261e;
    --shadow: 0 6px 24px rgba(16, 24, 40, 0.12);
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1216;
        --fg: #e6eaf0;
        --muted: #98a2b3;
        --line: #2a313a;
        --surface: #161b22;
        --accent: #6ea8fe;
        --error: #f2857c;
        --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
    }
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
}

body {
    display: grid;
    grid-template-rows: auto 1fr auto;
    background: var(--bg);
    color: var(--fg);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
}

/* ── Header ───────────────────────────────────────────────────────────────── */

header.top {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 16px;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

header.top h1 {
    margin: 0;
    font-size: 16px;
    font-weight: 650;
    letter-spacing: -0.01em;
}

/* The title is the way back to the atlas, so it has to look like a link. */
header.top h1 a {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid transparent;
}

header.top h1 a:hover { border-bottom-color: currentColor; }

.spacer { flex: 1 1 auto; }

button, input[type="search"] {
    font: inherit;
    color: inherit;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 6px 10px;
}

button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button[aria-pressed="true"] {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.layers { display: flex; gap: 6px; }

.search-wrap { position: relative; }
input[type="search"] { width: min(46vw, 320px); }

#results {
    position: absolute;
    z-index: 20;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 50vh;
    overflow-y: auto;
    margin: 0;
    padding: 4px;
    list-style: none;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
}

#results button {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    width: 100%;
    border: 0;
    background: none;
    text-align: left;
    padding: 6px 8px;
    border-radius: 6px;
}

#results button:hover { background: var(--surface); }
.result-meta { color: var(--muted); font-size: 13px; }

/* ── Map ──────────────────────────────────────────────────────────────────── */

main {
    position: relative;
    display: grid;
    grid-template-columns: 1fr auto;
    min-height: 0;
}

/* The canvas is taken out of flow: it is sized in pixels from its parent, so if it
   stayed in flow a measurement taken before layout settled could make the parent grow
   to match, push the footer off the page and clip whatever sits at the bottom — which
   is what happened to the legend inside the landing page's iframe. */
#map-wrap { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#map { position: absolute; inset: 0; display: block; touch-action: none; }

#legend {
    position: absolute;
    left: 12px;
    bottom: 12px;
    margin: 0;
    padding: 8px 10px;
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    max-width: min(90%, 640px);
    /* Never taller than a third of the map, whatever the archive count. */
    max-height: 33%;
    overflow-y: auto;
    font-size: 12px;
    color: var(--muted);
    background: color-mix(in srgb, var(--bg) 80%, transparent);
    border: 1px solid var(--line);
    border-radius: 8px;
}

#legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
#legend li.legend-caption { display: block; color: var(--muted); flex-basis: 100%; }

/* Specific enough to beat `#legend li`, which lays the other entries out
   as rows: the scale is a block, its bar above its labels. */
#legend li.legend-scale {
    flex-basis: 100%;
    display: block;
    width: 100%;
    min-width: 280px;
}

.legend-bar {
    display: block;
    width: 100%;
    height: 10px;
    border-radius: 3px;
}

.legend-ends {
    display: flex;
    width: 100%;
    justify-content: space-between;
    margin-top: 3px;
    color: var(--fg);
    font-size: 11px;
}

.legend-ends span:nth-child(2) { color: var(--muted); }
.panel-heat { margin-top: 4px; }

#tooltip {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    padding: 6px 10px;
    max-width: 320px;
    font-size: 13px;
    line-height: 1.35;
    background: var(--fg);
    color: var(--bg);
    border-radius: 6px;
}

#tooltip .tooltip-title { font-weight: 600; }
#tooltip .tooltip-line { opacity: 0.8; font-size: 12px; }

#error {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    max-width: min(90%, 640px);
    padding: 10px 14px;
    background: var(--bg);
    color: var(--error);
    border: 1px solid var(--error);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

#explainer {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 25;
    width: min(420px, calc(100% - 24px));
    max-height: calc(100% - 24px);
    overflow-y: auto;
    padding: 16px 18px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
    font-size: 13px;
}

#explainer dl { margin: 0; }
#explainer dt { font-weight: 650; margin-top: 12px; }
#explainer dt:first-of-type { margin-top: 0; }
#explainer dd { margin: 2px 0 0; color: var(--muted); }

.explainer-close {
    float: right;
    border: 0;
    background: none;
    font-size: 20px;
    line-height: 1;
    padding: 0 4px;
    margin: -4px -4px 0 0;
}

/* ── Panel ────────────────────────────────────────────────────────────────── */

#panel {
    width: min(420px, 92vw);
    overflow-y: auto;
    padding: 16px 20px 32px;
    border-left: 1px solid var(--line);
    background: var(--surface);
}

.panel-header { position: relative; }
.panel-header h2 { margin: 0 28px 4px 0; font-size: 18px; }

.panel-back {
    display: inline-block;
    margin: 0 0 10px;
    padding: 4px 8px;
    font-size: 13px;
}

ol.cluster-list {
    margin: 14px 0 0;
    padding: 0;
    list-style: none;
}

ol.cluster-list li { border-bottom: 1px solid var(--line); }

ol.cluster-list button {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    width: 100%;
    padding: 8px 6px;
    border: 0;
    border-radius: 6px;
    background: none;
    text-align: left;
}

ol.cluster-list button:hover { background: var(--bg); }
.panel-meta { margin: 0; color: var(--muted); font-size: 13px; }
.panel-description { margin: 8px 0 0; }

.panel-close {
    position: absolute;
    top: -4px;
    right: 0;
    border: 0;
    background: none;
    font-size: 22px;
    line-height: 1;
    padding: 2px 6px;
}

.panel-share { margin-top: 10px; font-size: 13px; }

.panel-terms { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 4px; }
.term {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--line);
    color: var(--muted);
}

.panel-section { margin-top: 22px; }
.panel-section h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

.papers-order { display: flex; gap: 6px; margin-bottom: 10px; }
.papers-order button { font-size: 12px; padding: 3px 8px; }

ol.papers { margin: 0; padding-left: 18px; }
ol.papers li { margin-bottom: 10px; }
ol.papers a { color: var(--accent); text-decoration: none; }
ol.papers a:hover { text-decoration: underline; }
.paper-meta { display: block; color: var(--muted); font-size: 12px; }
.papers-note { list-style: none; margin-left: -18px; color: var(--muted); font-size: 12px; }

/* New claims: quiet by default, because most rows have none and a hundred-row list has
   to stay readable. No colour of its own — heat already owns that channel (ADR 0016). */
.paper-claims { margin-top: 2px; font-size: 12px; color: var(--muted); }
.paper-claims > summary { cursor: pointer; }
.paper-claims ul { margin: 4px 0 0; padding-left: 18px; }
.paper-claims li { margin: 2px 0; }
.paper-claims-total { margin: 4px 0 0; font-style: italic; }

.error { color: var(--error); }

/* ── Embedded in another page ─────────────────────────────────────────────── */

body.embedded { grid-template-rows: 1fr; }
body.embedded header.top,
body.embedded footer.bottom { display: none; }

#embed-credit {
    position: fixed;
    right: 10px;
    bottom: 8px;
    z-index: 30;
    font-size: 12px;
    text-decoration: none;
    color: var(--muted);
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 2px 8px;
}

#embed-credit:hover { color: var(--fg); }

/* ── Footer ───────────────────────────────────────────────────────────────── */

footer.bottom {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    align-items: center;
    padding: 8px 16px;
    border-top: 1px solid var(--line);
    background: var(--surface);
    color: var(--muted);
    font-size: 13px;
}

footer.bottom a { color: var(--accent); }

/* ── Small screens ────────────────────────────────────────────────────────── */

@media (max-width: 720px) {
    main { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
    #panel {
        width: auto;
        max-height: 55vh;
        border-left: 0;
        border-top: 1px solid var(--line);
    }
    input[type="search"] { width: 100%; }
    .search-wrap { flex: 1 1 100%; order: 3; }
    #legend { display: none; }
}

/* Novelty coverage: which clusters have been scored. Text and texture only — hue is
   taken twice over, by heat on the fill and by the archive on the outline. */
.coverage-filter {
    margin-top: 6px;
    font-size: 0.85rem;
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}
.coverage-filter[aria-pressed='true'] { color: var(--fg); border-color: var(--fg); }
.coverage-mark {
    display: block;
    font-size: 0.78rem;
    color: var(--muted);
    font-variant: all-small-caps;
    letter-spacing: 0.04em;
}
