:root {
    --bg: #f4f0e8;
    --panel: rgba(255, 250, 242, 0.96);
    --panel-strong: #fffaf2;
    --border: rgba(53, 45, 35, 0.14);
    --text: #201913;
    --muted: #6c5f52;
    --shadow: 0 18px 40px rgba(42, 28, 14, 0.14);
    --base-line: #c1c7c7;
    --highlight: #0f766e;
    --map-bg: #ebe7dd;
    --font-display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
    --font-body: "Avenir Next", "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    background:
        radial-gradient(circle at top left, rgba(214, 183, 114, 0.22), transparent 28%),
        radial-gradient(circle at bottom right, rgba(85, 129, 112, 0.18), transparent 24%),
        var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    overflow: hidden;
}

body {
    min-height: 100dvh;
}

.app-shell {
    display: grid;
    grid-template-columns: minmax(340px, 420px) 1fr;
    height: 100dvh;
    gap: 14px;
    padding: 14px;
}

.side-panel,
.map-panel {
    min-height: 0;
}

.side-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: var(--shadow);
    padding: 18px;
    backdrop-filter: blur(10px);
    overflow-x: hidden;
    overflow-y: auto;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
}

.eyebrow {
    margin: 0 0 6px;
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

.panel-header h1 {
    margin: 0;
    font-family: var(--font-display);
    font-size: clamp(23px, 2.3vw, 31px);
    line-height: 0.95;
    font-weight: 600;
}

.ghost-button {
    appearance: none;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.56);
    color: var(--text);
    border-radius: 999px;
    padding: 10px 14px;
    font: inherit;
    cursor: pointer;
    transition: transform 120ms ease, background 120ms ease;
}

.ghost-button:hover {
    transform: translateY(-1px);
    background: rgba(255, 255, 255, 0.88);
}

.panel-copy,
.legend-note,
.overlay-copy,
.status-meta {
    margin: 0;
    color: var(--muted);
    line-height: 1.45;
    font-size: 14px;
}

.intro-hint {
    padding: 10px 12px;
    border: 1px dashed rgba(53, 45, 35, 0.18);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.34);
    color: var(--muted);
    line-height: 1.4;
    font-size: 13px;
}

.intro-hint.is-hidden {
    display: none;
}

.status-card,
.legend-card,
.overlay-card,
.credits-card {
    background: var(--panel-strong);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 14px;
}

.status-label,
.legend-title,
.overlay-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 8px;
}

#hover-title {
    font-weight: 700;
}

.legend-title--subsection {
    margin-top: 18px;
}

.status-value {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 6px;
}

.status-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.status-toggle-label {
    font-size: 12px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.segmented-toggle {
    display: inline-flex;
    align-items: center;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.5);
}

.segmented-toggle__button {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--muted);
    border-radius: 999px;
    padding: 6px 12px;
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease;
}

.segmented-toggle__button.is-active {
    background: rgba(32, 25, 19, 0.9);
    color: #fffaf2;
}

.sankey-panel {
    flex: 0 0 auto;
    min-height: clamp(620px, 78vh, 1100px);
    border-radius: 18px;
    border: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(248, 243, 235, 0.95), rgba(255, 255, 255, 0.92));
    overflow: hidden;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    margin-bottom: 8px;
}

.credits-card {
    margin-top: auto;
}

.repo-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    color: var(--muted);
    font-size: 12px;
}

.repo-footer__spacer {
    flex: 1;
}

.github-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: inherit;
    text-decoration: none;
    line-height: 1;
    transition: color 120ms ease, opacity 120ms ease;
}

.github-link:hover {
    color: var(--text);
}

.github-link--icon {
    opacity: 0.82;
}

.github-link--icon:hover {
    opacity: 1;
}

.credits-copy {
    margin: 0;
    color: var(--muted);
    line-height: 1.45;
    font-size: 13px;
}

.credits-copy a {
    color: var(--text);
    text-decoration-color: rgba(32, 25, 19, 0.28);
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

.credits-copy a:hover {
    text-decoration-color: rgba(32, 25, 19, 0.7);
}

.credits-copy--sources {
    margin-top: 10px;
    font-size: 12px;
}

.credits-copy--sources-meta {
    margin-top: 6px;
    font-size: 12px;
    opacity: 0.9;
}

.legend-swatch {
    width: 18px;
    height: 18px;
    border-radius: 999px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    flex: 0 0 auto;
}

.legend-swatch--base {
    background: var(--base-line);
}

.legend-swatch--highlight {
    background: var(--highlight);
}

.map-panel {
    position: relative;
    border-radius: 28px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--map-bg);
    box-shadow: var(--shadow);
}

#map {
    width: 100%;
    height: 100%;
}

.map-overlay {
    position: absolute;
    z-index: 2;
    pointer-events: none;
}

.map-overlay.top-left {
    top: 14px;
    left: 14px;
}

.map-overlay.bottom-right {
    right: 14px;
    bottom: 14px;
}

.overlay-card {
    max-width: 320px;
    pointer-events: auto;
}

.hover-card {
    min-width: 250px;
}

.hover-card.is-hidden {
    display: none;
}

.mono {
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 13px;
}

.hover-detail-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 10px;
    font-size: 13px;
    margin: 0;
}

.hover-detail-grid dt {
    color: var(--muted);
}

.hover-detail-grid dd {
    margin: 0;
    color: var(--text);
    text-align: right;
}

.popup-grid dd {
    margin: 0;
}

@media (max-width: 1024px) {
    html,
    body {
        overflow: auto;
    }

    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(280px, 42dvh) minmax(0, 1fr);
        height: auto;
        min-height: 100dvh;
    }

    .side-panel {
        overflow: auto;
    }

    .sankey-panel {
        min-height: 520px;
    }

    #map {
        min-height: 58dvh;
    }
}

@media (max-width: 720px) {
    .app-shell {
        gap: 10px;
        padding: 10px;
    }

    .side-panel {
        padding: 14px;
        border-radius: 20px;
    }

    .map-panel {
        border-radius: 20px;
    }

    .panel-header {
        flex-direction: column;
    }
}