/* --- Base Styles --- */
:root {
    --globe-center-x: 50vw;
    --globe-center-y: 50vh;
    --globe-diameter: min(50vw, 72vh);
}

body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    height: 100dvh;
    width: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: #374151;
    background: #fff;
    position: relative;
    z-index: 0;
}

* { box-sizing: border-box; }
button, input, select { font-family: inherit; }
button, a, input, select { touch-action: manipulation; }
[hidden] { display: none !important; }
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
    outline: 2px solid #2c3e50;
    outline-offset: 2px;
}

.skip-link { position: fixed; top: -100px; left: 20px; z-index: 2000; background: #fff; padding: 12px; }
.skip-link:focus { top: 10px; }

/* --- Geomodern Background --- */
#geomodern-background {
    position: fixed;
    inset: 0;
    z-index: 0;
    background-color: #10131a;
    background-position: center;
    background-repeat: repeat;
    pointer-events: none;
    opacity: var(--background-pattern-opacity, 0.2);
    transition: opacity 180ms ease;
}
#geomodern-background.is-hidden { opacity: 0; }

/* --- Map Container --- */
#map {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    background-color: transparent;
    outline: none;
}

#map, #map canvas, .maplibregl-canvas, .maplibregl-canvas-container, .maplibregl-map {
    background: transparent !important;
    background-color: transparent !important;
}

/* --- Left Controls Column --- */
/* The column fills the viewport and the paper list absorbs the slack, so the only scrollbar
   lives inside a panel. If a short window forces the column itself to scroll, it does so
   without drawing a bar beside the panels. */
#controls-column {
    position: absolute;
    top: 72px;
    left: 50px;
    width: 350px;
    height: calc(100vh - 90px);
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 10;
    overflow-y: auto;
    scrollbar-width: none;
}
#controls-column::-webkit-scrollbar { display: none; }
#search-container { flex: 1 1 auto; min-height: 180px; }

/* --- Control Panels --- */
.panel {
    width: 100%;
    background: rgba(255, 255, 255, 0.97);
    padding: 15px;
    border-radius: 4px;
    border: 1px solid #d1d5db;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex-shrink: 0;
}

/* --- Wordmark: floats over the map above the column, outside any panel --- */
#masthead {
    position: absolute;
    top: 10px;
    left: 52px;
    z-index: 11;
    margin: 0;
    pointer-events: none;
    user-select: none;
}
.masthead-copy { pointer-events: none; }
.masthead-about,
.sheet-handle { display: none; }
#wordmark {
    margin: 0;
    font-family: "Segoe UI Black", "Arial Black", "Helvetica Neue", "Franklin Gothic Heavy", Arial, sans-serif;
    font-size: 26px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    line-height: 1;
    color: #1f2d3a;
    text-shadow: none;
}
#wordmark span {
    color: #4b5563;
}
#wordmark-sub {
    margin: 6px 0 0;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #4b5563;
    line-height: 1.2;
}
#title-container .subtitle {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
    color: #4b5563;
}
.stat-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-top: 1px solid #e5e7eb;
    padding-top: 10px;
}
.stat-row strong {
    display: block;
    font-size: 19px;
    font-weight: 600;
    color: #2c3e50;
    font-variant-numeric: tabular-nums;
}
.stat-row span {
    display: block;
    font-size: 12px;
    color: #6b7280;
    margin-top: 2px;
}

/* --- Buttons & Select --- */
.control-button, .doi-link {
    display: block;
    width: 100%;
    padding: 9px 16px;
    background-color: #2c3e50;
    color: white;
    border: none;
    border-radius: 2px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    text-decoration: none;
    transition: background-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}
.control-button:hover, .doi-link:hover {
    background-color: #34495e;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
.control-button.active {
    background-color: #1f2d3a;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.35);
}
.control-button:disabled { opacity: 0.55; cursor: default; }

.control-button.secondary {
    background-color: white;
    color: #2c3e50;
    border: 1px solid #d1d5db;
}
.control-button.secondary:hover { background-color: #f8f9fa; border-color: #adb5bd; }

.link-button {
    background: none;
    border: none;
    padding: 0;
    color: #1d4ed8;
    font-size: 12px;
    text-decoration: underline;
}
.link-button:hover { color: #1e40af; }

.control-select {
    display: block;
    width: 100%;
    padding: 9px 30px 9px 16px;
    background-color: white;
    color: #2c3e50;
    border: 1px solid #d1d5db;
    border-radius: 2px;
    font-size: 14px;
    cursor: pointer;
    appearance: none;
    background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%232c3e50%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E');
    background-repeat: no-repeat;
    background-position: right 10px top 50%;
    background-size: .65em auto;
}
.control-select:hover { border-color: #adb5bd; background-color: #f8f9fa; }

.control-label {
    display: block;
    font-weight: 600;
    color: #374151;
    font-size: 14px;
}
.control-label strong { color: #2c3e50; }

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #374151;
    cursor: pointer;
}
.checkbox-row input { accent-color: #2c3e50; width: 15px; height: 15px; cursor: pointer; }

.button-row { display: flex; gap: 6px; }
.button-row .control-button { padding-left: 8px; padding-right: 8px; font-size: 13px; }
.label-short { display: none; }

.layer-group {
    border-top: 1px solid #e5e7eb;
    padding-top: 8px;
}
.layer-group summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #6b7280;
}
.layer-group summary::-webkit-details-marker { display: none; }
.layer-group summary::before {
    content: "";
    width: 5px;
    height: 5px;
    border-right: 1.5px solid #6b7280;
    border-bottom: 1.5px solid #6b7280;
    transform: rotate(-45deg);
    transition: transform 0.15s ease;
}
.layer-group[open] summary::before { transform: rotate(45deg); }
.layer-group summary:hover { color: #2c3e50; }
.layer-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px 10px;
    padding-top: 10px;
}
.layer-group .checkbox-row { font-size: 13px; }
.layer-group .checkbox-row:has(input:disabled) { opacity: 0.5; }

/* --- Timeline Slider --- */
#year-slider {
    width: 100%;
    accent-color: #2c3e50;
    cursor: pointer;
    margin: 0;
}
.year-ticks {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #6b7280;
    margin-top: -4px;
}

/* --- Search & Paper List --- */
#search {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 2px;
    font-size: 14px;
    transition: border-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}
#search:focus {
    border-color: #2c3e50;
    outline: none;
    box-shadow: 0 0 0 3px rgba(44, 62, 80, 0.15);
}
.results-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    color: #6b7280;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 8px;
}
.paper-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #adb5bd #f1f3f5;
    margin: 0 -15px;
    padding: 0 15px;
}
.paper-list::-webkit-scrollbar { width: 6px; }
.paper-list::-webkit-scrollbar-track { background: #f1f3f5; }
.paper-list::-webkit-scrollbar-thumb { background-color: #adb5bd; border-radius: 3px; }

.paper-card {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    border-bottom: 1px solid #e5e7eb;
    padding: 12px 0;
    transition: background-color 0.15s ease-in-out, opacity 0.15s ease-in-out;
}
.paper-card:last-child { border-bottom: none; }
.paper-card:hover, .paper-card:focus-visible { background-color: #f3f4f6; }
.paper-card.selected { background-color: #eef2f7; }
.paper-card.dimmed { opacity: 0.38; }
.paper-card.dimmed:hover, .paper-card.dimmed:focus-visible, .paper-card.dimmed.selected { opacity: 1; }
.card-top {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #6b7280;
}
.theme-dot { width: 8px; height: 8px; background: var(--color); border-radius: 50%; flex-shrink: 0; }
.card-number { margin-left: auto; color: #9ca3af; }
.paper-card h3 {
    margin: 6px 0 4px;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    color: #1f2937;
}
.card-place { font-size: 12px; color: #4b5563; line-height: 1.4; }
.card-bottom { font-size: 12px; color: #6b7280; margin-top: 6px; }
.empty-state { font-size: 13px; line-height: 1.6; color: #6b7280; padding: 16px 0; margin: 0; }

/* --- Detail Panel --- */
.detail-panel {
    position: absolute;
    top: 60px;
    right: 60px;
    width: 380px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    z-index: 12;
    display: block;
    padding: 25px;
    scrollbar-width: thin;
    scrollbar-color: #adb5bd #f1f3f5;
}
.detail-panel::-webkit-scrollbar { width: 6px; }
.detail-panel::-webkit-scrollbar-track { background: #f1f3f5; }
.detail-panel::-webkit-scrollbar-thumb { background-color: #adb5bd; border-radius: 3px; }

.close-button {
    position: absolute;
    top: 10px;
    right: 12px;
    width: 26px;
    height: 26px;
    border: 1px solid #d1d5db;
    border-radius: 2px;
    background: white;
    color: #4b5563;
    font-size: 18px;
    line-height: 1;
    z-index: 1;
}
.close-button:hover { background: #f3f4f6; }

.detail-theme { font-size: 12px; color: #6b7280; padding-right: 30px; }
.detail-panel h2 {
    margin: 8px 0 10px;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.35;
    color: #1f2937;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 10px;
}
.detail-panel h3 {
    margin: 20px 0 8px;
    font-size: 14px;
    font-weight: 600;
    color: #2c3e50;
}
.detail-authors { margin: 0 0 8px; font-size: 12px; line-height: 1.5; color: #4b5563; }
.detail-summary { font-size: 14px; line-height: 1.6; color: #4b5563; }
.finding {
    padding: 12px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-left: 3px solid #2c3e50;
    border-radius: 2px;
    font-size: 14px;
    line-height: 1.6;
    color: #374151;
}
.evidence { margin-top: 10px; }
.evidence summary { font-size: 12px; color: #1d4ed8; cursor: pointer; }
.evidence blockquote {
    margin: 10px 0 0;
    padding-left: 12px;
    border-left: 2px solid #e5e7eb;
    font-size: 13px;
    line-height: 1.6;
    color: #4b5563;
}
.location-item, .river-item { border-bottom: 1px solid #e5e7eb; padding: 10px 0; }
.location-item:last-child, .river-item:last-child { border-bottom: none; }
.location-item strong, .river-item strong { display: block; font-size: 14px; color: #1f2937; }
.location-item small, .river-item small { display: block; font-size: 12px; color: #6b7280; line-height: 1.5; margin-top: 3px; }
.location-item.unresolved strong:after {
    content: "unmapped";
    margin-left: 8px;
    font-size: 11px;
    font-weight: 500;
    color: #92400e;
    background: #fef3c7;
    border: 1px solid #fde68a;
    border-radius: 2px;
    padding: 1px 5px;
    vertical-align: middle;
}
.location-focus, .river-focus {
    background: none;
    border: none;
    padding: 6px 0 0;
    font-size: 12px;
    color: #1d4ed8;
    text-decoration: underline;
}
.topic-list { display: flex; flex-wrap: wrap; gap: 5px; }
.topic {
    padding: 4px 8px;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 2px;
    font-size: 12px;
    color: #4b5563;
}
.related-paper {
    display: block;
    width: 100%;
    text-align: left;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 2px;
    padding: 10px;
    margin-top: 8px;
    font-size: 13px;
    line-height: 1.4;
    color: #1f2937;
}
.related-paper:hover { background: #f3f4f6; }
.related-paper small { display: block; font-size: 11px; color: #6b7280; margin-bottom: 5px; }
.related-paper .edge-label { margin-right: 6px; transform: none; vertical-align: middle; max-width: 100%; }
.related-paper.active { border-color: #b45309; background: #fff7ed; }
.related-paper .reason-note { margin: 5px 0 0; font-style: italic; line-height: 1.45; }
.detail-note, .fine-print { font-size: 12px; line-height: 1.5; color: #6b7280; }
.paper-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 15px 0; }
.paper-actions a {
    padding: 7px 14px;
    background-color: #34495e;
    color: white;
    border-radius: 2px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
}
.paper-actions a:hover { background-color: #2c3e50; }
.paper-actions a.secondary { background: white; color: #2c3e50; border: 1px solid #d1d5db; }
.paper-actions a.secondary:hover { background: #f8f9fa; }

/* --- Title Splash --- */
#title-overlay {
    position: absolute;
    top: var(--globe-center-y, 50%);
    left: var(--globe-center-x, 50%);
    transform: translate(-50%, -50%);
    z-index: 1001;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 90vw;
    max-height: 80vh;
    cursor: pointer;
    transition: opacity 0.5s ease-out;
}
#title-overlay img {
    display: block;
    width: auto;
    height: auto;
    max-width: min(90vw, 520px, calc(var(--globe-diameter) * 0.82));
    max-height: min(56vh, calc(var(--globe-diameter) * 0.82));
    object-fit: contain;
    aspect-ratio: 1;
    filter: drop-shadow(0 4px 20px rgba(16, 19, 26, 0.25));
}
#title-overlay .splash-subhead {
    margin: 12px 0 0;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: #1f2d3a;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}
#title-overlay.fading { opacity: 0; }

/* --- Map Legend, Explainer & Messages --- */
.map-legend {
    position: absolute;
    right: 60px;
    bottom: 76px;
    width: 380px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid #d1d5db;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    font-size: 12px;
    color: #4b5563;
}
.map-legend span { display: flex; align-items: center; gap: 8px; }
.key { width: 20px; flex-shrink: 0; }
.key-named { height: 0; border-top: 3px solid #92400e; }
.key-context { height: 10px; width: 18px; background: rgba(147, 180, 228, 0.45); border: 1px solid #93b4e4; }
.key-shared { height: 0; border-top: 2px solid #b45309; }
.key-connectivity { height: 0; border-top: 2px dashed #b45309; }
.key-topical { height: 0; border-top: 2px dotted #6b7280; }
.key-hydro { height: 0; border-top: 4px solid #d97706; opacity: 0.85; }
.key-basin { height: 10px; width: 18px; background: rgba(44, 62, 80, 0.14); border: 1px solid rgba(44, 62, 80, 0.5); }
.key-density { height: 10px; width: 18px; border-radius: 2px; background: linear-gradient(90deg, #ffffb3, #7fcdbb, #2c7fb8, #253494); }
.key-site { height: 9px; width: 9px; border-radius: 50%; background: #6b8f6b; border: 1.5px solid white; box-shadow: 0 0 0 1px #9ca3af; }

/* --- Relationship labels on curves --- */
.edge-label {
    display: inline-block;
    max-width: 210px;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid #d1d5db;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    font-size: 11px;
    line-height: 1.3;
    font-weight: 500;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    transform: translateY(-1px);
}
.edge-label.river, .edge-label.hydrology { border-color: #f1d3b0; color: #7c2d12; }
.edge-label.topical { color: #4b5563; }
.edge-label.citation { color: #1e3a8a; border-color: #c7d2fe; }
.maplibregl-marker.edge-label-marker { z-index: 5; }

#map-explainer {
    position: absolute;
    left: 420px;
    bottom: 30px;
    z-index: 10;
    width: 400px;
    max-width: calc(100vw - 500px);
    padding: 14px 16px;
    gap: 8px;
}
/* Hover-only content must not steal the pointer from the map feature that opened it. */
#map-explainer.hover-preview { pointer-events: none; }
#map-explainer h2 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #2c3e50;
}
#map-explainer p { margin: 0; font-size: 13px; line-height: 1.5; color: #4b5563; }
#map-explainer .reason { display: flex; gap: 9px; align-items: baseline; }
#map-explainer .reason .key { margin-top: 6px; align-self: flex-start; }
#map-explainer strong { color: #1f2937; font-weight: 600; }
#map-explainer .caveat { font-size: 12px; color: #6b7280; font-style: italic; }
#map-explainer h2 {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 4px;
}
#map-explainer .summary { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
#map-explainer .summary .link-button { font-size: 12px; }
#map-explainer .summary-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    font-size: 12px;
    color: #4b5563;
}
#map-explainer .summary-list li { display: flex; align-items: center; gap: 6px; }
#map-explainer .summary-list .key { width: 14px; }

.connect-heading {
    margin: 14px 0 2px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #6b7280;
}

.map-message {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    padding: 9px 16px;
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid #d1d5db;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    font-size: 13px;
    color: #374151;
    max-width: 80%;
}
.map-message.error { color: #991b1b; border-color: #fca5a5; background: #fef2f2; }

/* --- Welcome and General Information Panels --- */
.info-panel { z-index: 13; }
.info-panel h2 { padding-right: 28px; }
.info-panel p {
    margin: 0 0 12px;
    font-size: 13px;
    line-height: 1.6;
    color: #4b5563;
}
.info-panel .fine-print { margin: 16px 0; font-size: 12px; color: #6b7280; }
.info-list {
    display: flex;
    flex-direction: column;
    gap: 11px;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 13px;
    line-height: 1.45;
    color: #4b5563;
}
.info-list li { display: flex; align-items: flex-start; gap: 9px; }
.info-list .key { flex: 0 0 auto; margin-top: 5px; }
.info-list strong { color: #1f2937; }

/* --- About Dialog --- */
dialog {
    width: 90%;
    max-width: 650px;
    max-height: 80vh;
    padding: 30px;
    background-color: white;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    color: #374151;
    overflow-y: auto;
}
dialog::backdrop { background: rgba(16, 19, 26, 0.45); }
dialog h2 {
    margin: 0 0 20px;
    font-size: 22px;
    font-weight: 600;
    color: #2c3e50;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 15px;
}
dialog p { margin: 0 0 18px; font-size: 15px; line-height: 1.65; color: #4b5563; }
dialog a { color: #1d4ed8; text-decoration: none; border-bottom: 1px dotted #1d4ed8; }
dialog a:hover { color: #1e40af; border-bottom-style: solid; }
#close-about { margin-top: 10px; }

/* --- MapLibre overrides --- */
.maplibregl-ctrl-bottom-right { bottom: 20px; z-index: 9; }
.maplibregl-ctrl-attrib { font-size: 11px !important; }
.maplibregl-popup { max-width: 320px !important; }
.maplibregl-popup-content {
    padding: 12px 14px !important;
    border-radius: 4px !important;
    border: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
    background: rgba(255, 255, 255, 0.95) !important;
    font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
    color: #374151;
}
.maplibregl-popup-content strong { display: block; font-size: 14px; font-weight: 600; color: #1f2937; margin-bottom: 4px; }
.maplibregl-popup-content small { display: block; font-size: 12px; color: #4b5563; line-height: 1.45; }
.maplibregl-popup-content .popup-place { display: block; font-size: 13px; font-weight: 500; color: #2c3e50; margin: 2px 0 3px; }
.maplibregl-popup-content .popup-method {
    display: inline-block;
    margin-top: 6px;
    padding: 1px 6px;
    border: 1px solid #e5e7eb;
    border-radius: 2px;
    background: #f9fafb;
    font-size: 11px;
    color: #6b7280;
}
.maplibregl-popup.selected-site-popup {
    z-index: 7;
    transition: opacity 160ms ease;
}
.selected-site-popup .maplibregl-popup-content {
    padding: 7px 9px !important;
    border: 1px solid rgba(44, 62, 80, 0.28);
    border-radius: 5px !important;
    box-shadow: 0 2px 7px rgba(15, 23, 42, 0.2) !important;
    pointer-events: none;
}
.selected-site-label {
    max-width: 185px;
    line-height: 1.25;
}
.selected-site-label strong,
.selected-site-label span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.selected-site-label strong {
    margin: 0 0 2px;
    font-size: 11px;
    font-weight: 650;
    color: #1f2937;
}
.selected-site-label span {
    font-size: 10px;
    font-weight: 500;
    color: #526579;
}

/* --- Tiny Background Controls --- */
#background-controls {
    position: fixed;
    right: 6px;
    bottom: 5px;
    z-index: 12;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    opacity: 0.13;
    transition: opacity 160ms ease;
}
#background-controls:hover,
#background-controls:focus-within { opacity: 0.88; }
.background-button-row { display: flex; gap: 2px; }
.background-icon {
    width: 17px;
    height: 17px;
    display: grid;
    place-items: center;
    padding: 0;
    color: rgba(255, 255, 255, 0.92);
    background: rgba(12, 18, 24, 0.62);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
}
.background-icon:hover,
.background-icon:focus-visible {
    color: #fff;
    background: rgba(12, 18, 24, 0.9);
    border-color: rgba(255, 255, 255, 0.72);
    outline: none;
}
.background-icon svg {
    width: 9px;
    height: 9px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.7;
}
#background-fade {
    width: 69px;
    height: 8px;
    margin: 0;
    cursor: pointer;
    accent-color: rgba(255, 255, 255, 0.92);
}

@media (pointer: coarse) {
    #background-controls { opacity: 0.28; }
}

/* --- Responsive --- */
@media (max-width: 1200px) {
    #masthead { top: 6px; left: 22px; }
    #wordmark { font-size: 21px; }
    #controls-column { top: 58px; left: 20px; width: 320px; height: calc(100vh - 78px); }
    .detail-panel { top: 20px; right: 20px; width: 340px; max-height: calc(100vh - 40px); }
    .map-legend { right: 20px; bottom: 66px; width: 340px; }
    #map-explainer { left: 360px; bottom: 20px; width: 360px; max-width: calc(100vw - 400px); }
}

@media (max-width: 960px) {
    #masthead {
        top: max(8px, env(safe-area-inset-top));
        left: 12px;
        right: auto;
        max-width: calc(100vw - 176px);
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
        pointer-events: none;
    }
    #wordmark {
        font-size: 15px;
        letter-spacing: 0.04em;
        line-height: 1.05;
    }
    #wordmark span {
        display: block;
        font-size: 11px;
        letter-spacing: 0.08em;
        margin-bottom: 2px;
    }
    #wordmark-sub { font-size: 10px; margin-top: 4px; }
    .masthead-about {
        display: inline;
        pointer-events: auto;
        padding: 6px 8px;
        font-size: 12px;
        font-weight: 600;
        text-decoration: none;
        color: #1f2d3a;
        background: rgba(255, 255, 255, 0.92);
        border: 1px solid #d1d5db;
        border-radius: 4px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    }
    .masthead-about:hover { color: #1f2d3a; }

    .sheet-handle {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 6px;
        width: 100%;
        padding: 8px 8px 2px;
        border: 0;
        background: none;
        color: #4b5563;
        font-size: 12px;
        font-weight: 600;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        order: -1;
    }
    .sheet-handle-bar {
        width: 36px;
        height: 4px;
        border-radius: 999px;
        background: #d1d5db;
    }

    #controls-column {
        top: auto;
        left: 10px;
        right: 10px;
        bottom: max(10px, env(safe-area-inset-bottom));
        width: auto;
        height: 196px;
        max-height: 196px;
        min-height: 0;
        gap: 0;
        overflow: hidden;
        background: rgba(255, 255, 255, 0.97);
        border: 1px solid #d1d5db;
        border-radius: 12px;
        box-shadow: 0 8px 24px rgba(16, 19, 26, 0.16);
        transition: max-height 180ms ease, height 180ms ease;
    }
    body.sheet-expanded #controls-column {
        height: calc(100dvh - 56px - env(safe-area-inset-top));
        max-height: calc(100dvh - 56px - env(safe-area-inset-top));
        overflow: hidden;
    }
    body.welcome-open #controls-column,
    body.detail-open #controls-column {
        display: none;
    }

    #title-container,
    #slider-container { display: none; }
    body.sheet-expanded #slider-container { display: flex; }

    #visualization-controls {
        height: 0;
        min-height: 0;
        padding: 0;
        border: 0;
        box-shadow: none;
        background: transparent;
        overflow: visible;
        gap: 0;
    }
    #visualization-controls .control-label,
    #visualization-controls .control-select,
    #visualization-controls .layer-group { display: none; }
    body.sheet-expanded #visualization-controls {
        height: auto;
        padding: 4px 15px 12px;
        border: 0;
        box-shadow: none;
        background: transparent;
        gap: 10px;
    }
    body.sheet-expanded #visualization-controls .control-label { display: block; }
    body.sheet-expanded #visualization-controls .control-select { display: block; }
    body.sheet-expanded #visualization-controls .layer-group { display: block; }

    #search-container,
    #slider-container {
        border: 0;
        box-shadow: none;
        background: transparent;
    }
    #map-tools {
        position: fixed;
        top: max(8px, env(safe-area-inset-top));
        right: max(12px, env(safe-area-inset-right));
        left: auto;
        width: auto;
        z-index: 16;
        display: flex;
        visibility: visible;
        pointer-events: auto;
        gap: 4px;
        padding: 4px;
        background: rgba(255, 255, 255, 0.97);
        border: 1px solid #d1d5db;
        border-radius: 4px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }
    #map-tools .control-button {
        width: auto;
        padding: 8px 8px;
        font-size: 11px;
    }
    .label-short { display: inline; }
    .label-full { display: none; }

    #search-container {
        min-height: 0;
        flex: 1 1 auto;
        order: 2;
        padding-top: 4px;
        overflow: hidden;
    }
    #search-container .control-label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
    }
    #slider-container { order: 0; padding: 8px 15px 10px; }
    #play-button { display: none; }
    #visualization-controls { order: 1; }
    .paper-list {
        max-height: none;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .edge-label { display: none; }
    .selected-site-label { max-width: 145px; }
    .map-legend,
    #map-explainer,
    #general-info,
    #background-controls { display: none !important; }

    .detail-panel {
        top: auto;
        left: 10px;
        right: 10px;
        bottom: max(10px, env(safe-area-inset-bottom));
        width: auto;
        max-height: min(58vh, calc(100dvh - 88px - env(safe-area-inset-top)));
        padding: 18px 16px 16px;
        border-radius: 12px;
    }
    #welcome-popup {
        max-height: min(48vh, calc(100dvh - 96px));
    }
    .info-panel h2 { font-size: 16px; }
    .close-button {
        width: 36px;
        height: 36px;
        top: 8px;
        right: 8px;
        font-size: 22px;
    }

    #map-message {
        top: max(52px, calc(env(safe-area-inset-top) + 44px));
        left: 12px;
        right: 12px;
        transform: none;
        max-width: none;
        text-align: center;
    }

    #title-overlay img {
        max-width: min(78vw, 320px, calc(var(--globe-diameter) * 0.82));
        max-height: min(42vh, calc(var(--globe-diameter) * 0.82));
    }
    #title-overlay .splash-subhead { font-size: 12px; }

    .maplibregl-ctrl-bottom-right {
        top: max(56px, calc(env(safe-area-inset-top) + 48px));
        bottom: auto;
        right: 8px;
    }
    .maplibregl-ctrl-bottom-left { display: none; }

    dialog {
        width: calc(100% - 24px);
        max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        padding: 20px 16px;
        margin: auto;
    }
}

@media (max-width: 960px) and (max-height: 500px) {
    #controls-column { height: 32vh; max-height: 32vh; }
    body.sheet-expanded #controls-column {
        height: calc(100dvh - 44px - env(safe-area-inset-top));
        max-height: calc(100dvh - 44px - env(safe-area-inset-top));
    }
    .detail-panel { max-height: 68vh; padding: 14px; }
    #wordmark { font-size: 14px; }
    #title-overlay img { max-height: min(36vh, calc(var(--globe-diameter) * 0.82)); }
}

@media (pointer: coarse) {
    .control-button,
    .control-select,
    #search { min-height: 44px; }
    .paper-card { padding: 14px 0; }
    .checkbox-row { min-height: 32px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *:before, *:after { animation: none !important; transition: none !important; }
}
