:root {
    --bg: #0e1310;
    --panel: rgba(14, 19, 16, 0.92);
    --ink: #f3efe4;
    --muted: #b7b0a0;
    --line: rgba(243, 239, 228, 0.12);
    --gold: #e2b657;
    --danger: #e07a6a;
    --ok: #7dca8a;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
    --sans: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    --mono: "Cascadia Mono", "Consolas", "SFMono-Regular", monospace;
    --tap: 44px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    height: 100dvh;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--sans);
    overflow: hidden;
}

.app-body {
    display: grid;
    grid-template-rows: auto 1fr auto;
    height: 100%;
    height: 100dvh;
}

.map-stage {
    grid-row: 2;
    position: relative;
    min-height: 0;
}

#map {
    height: 100%;
    min-height: 0;
    background: #1a211c;
}

.heat-legend {
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 500;
    width: 196px;
    padding: 10px 11px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
    pointer-events: none;
}

.heat-legend-title {
    margin: 0 0 2px;
    font-size: 11px;
    font-weight: 650;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--gold);
}

.heat-legend-unit {
    margin: 0 0 8px;
    font-size: 10px;
    color: var(--muted);
    line-height: 1.3;
}

.heat-legend-bar {
    height: 10px;
    border-radius: 999px;
    background: linear-gradient(to right, #2a4bff 0%, #2a4bff 20%, #00d5d5 40%, #3dcf3d 60%, #e6d000 80%, #e02424 100%);
}

.heat-legend-scale {
    display: flex;
    justify-content: space-between;
    margin: 5px 0 8px;
    font-size: 10px;
    color: var(--muted);
}

.heat-legend-swatches {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 3px;
    font-size: 11px;
    color: var(--ink);
}

.heat-legend-swatches li {
    display: flex;
    align-items: center;
    gap: 7px;
}

.swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex: 0 0 10px;
}

.swatch-blue { background: #2a4bff; }
.swatch-cyan { background: #00d5d5; }
.swatch-lime { background: #3dcf3d; }
.swatch-yellow { background: #e6d000; }
.swatch-red { background: #e02424; }

.topbar {
    grid-row: 1;
    z-index: 700;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: calc(8px + var(--safe-top)) 12px 8px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(10px);
}

.brand .eyebrow,
.eyebrow {
    margin: 0;
    color: var(--gold);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-size: 10px;
}

.brand strong {
    display: block;
    font-size: 16px;
    font-weight: 650;
    line-height: 1.2;
}

.stats {
    display: flex;
    gap: 14px;
    flex: 1;
    min-width: 0;
}

.stats div span {
    display: block;
    font-family: var(--mono);
    font-size: 16px;
    color: var(--gold);
}

.stats label {
    font-size: 10px;
    color: var(--muted);
}

.top-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.text-link, .button-link {
    color: var(--gold);
    text-decoration: none;
    font-size: 13px;
}

.button-link {
    display: inline-block;
    padding: 12px 16px;
    border: 1px solid var(--gold);
    border-radius: 8px;
}

.ctrl-toggle,
.icon-btn,
.playback button,
.gate-card button {
    border: 0;
    border-radius: 8px;
    background: var(--gold);
    color: #1b1608;
    font-weight: 650;
    cursor: pointer;
    min-height: var(--tap);
}

.ctrl-toggle {
    display: none;
    padding: 0 12px;
    font-size: 13px;
}

.icon-btn {
    width: var(--tap);
    min-width: var(--tap);
    background: transparent;
    color: var(--ink);
    font-size: 28px;
    line-height: 1;
}

.sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 720;
    background: rgba(0, 0, 0, 0.45);
}

.controls {
    position: absolute;
    top: calc(60px + var(--safe-top));
    left: 12px;
    z-index: 730;
    width: 228px;
    padding: 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
    display: grid;
    gap: 8px;
}

.controls-head {
    display: none;
    align-items: center;
    justify-content: space-between;
    font-weight: 650;
}

.controls label,
.gate-card label {
    display: grid;
    gap: 4px;
    font-size: 11px;
    color: var(--muted);
}

.controls select,
.playback select,
.gate-card input,
.gate-card select {
    width: 100%;
    min-height: 40px;
    padding: 8px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #171d19;
    color: var(--ink);
    font: inherit;
}

.controls input[type="range"] {
    width: 100%;
    padding: 8px 0;
    accent-color: var(--gold);
}

.check {
    grid-template-columns: 22px 1fr;
    align-items: center;
    color: var(--ink);
    font-size: 13px;
    min-height: 36px;
}

.check input {
    width: 18px;
    height: 18px;
}

.show-mobile { display: none; }

.timeline-dock {
    grid-row: 3;
    z-index: 700;
    padding: 8px 12px calc(8px + var(--safe-bottom));
    background: var(--panel);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(10px);
}

.dock-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
}

.clock {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 10px;
    font-family: var(--mono);
    font-size: 14px;
    min-width: 0;
}

.clock-sep { color: var(--muted); }

.playback {
    display: grid;
    grid-template-columns: var(--tap) minmax(64px, 1fr) var(--tap) 68px;
    gap: 6px;
    flex: 0 0 auto;
}

.playback button { padding: 0 8px; }
.playback select { min-height: var(--tap); }

.timeline-wrap { position: relative; height: 80px; }

#timeline {
    width: 100%;
    height: 80px;
    display: block;
    cursor: grab;
    touch-action: none;
}

#timeline.dragging { cursor: grabbing; }

.hint {
    margin: 4px 0 0;
    font-size: 11px;
    color: var(--muted);
}

.empty-overlay {
    position: absolute;
    inset: 58px 0 110px;
    z-index: 600;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(8, 10, 9, 0.45);
}

.gate-body {
    min-height: 100%;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 24px;
    overflow: auto;
    background:
        radial-gradient(900px 420px at 10% -10%, rgba(226, 182, 87, 0.16), transparent),
        var(--bg);
}

.gate-card {
    width: min(460px, 100%);
    padding: 24px;
    background: #161c18;
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.gate-card h1 {
    margin: 6px 0 8px;
    font-size: 26px;
}

.lede, .gate-links {
    color: var(--muted);
    line-height: 1.45;
}

.gate-card label { margin-top: 12px; }

.gate-card button {
    width: 100%;
    margin-top: 18px;
}

.gate-card code {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--gold);
}

.flash {
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 13px;
}

.flash.ok { background: rgba(125, 202, 138, 0.12); color: var(--ok); }
.flash.error { background: rgba(224, 122, 106, 0.12); color: var(--danger); }

.leaflet-control-attribution {
    background: rgba(14, 19, 16, 0.7) !important;
    color: #c9c3b6 !important;
    font-size: 10px !important;
}

.leaflet-control-attribution a { color: var(--gold) !important; }
.leaflet-top.leaflet-right { top: 8px; }

@media (max-width: 820px) {
    .brand strong { font-size: 14px; }
    .stat-total { display: none; }
    .stats { flex: 1; justify-content: flex-end; }
    .hide-mobile { display: none; }
    .show-mobile { display: inline-block; margin-top: 8px; }
    .ctrl-toggle { display: inline-flex; align-items: center; }
    .controls-head { display: flex; }

    .controls {
        position: fixed;
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: auto;
        max-height: min(72dvh, 520px);
        border-radius: 16px 16px 0 0;
        padding: 12px 16px calc(16px + var(--safe-bottom));
        transform: translateY(110%);
        transition: transform 0.22s ease;
        overflow: auto;
    }

    body.sheet-open .controls { transform: translateY(0); }

    .clock { font-size: 12px; }
    .dock-row { flex-wrap: wrap; }
    .playback { width: 100%; }
    .timeline-wrap, #timeline { height: 64px; }
    .hint { display: none; }
    .leaflet-control-attribution { max-width: 42vw; }

    .heat-legend {
        left: 8px;
        right: auto;
        bottom: 8px;
        width: min(200px, 64vw);
        padding: 8px 9px;
    }
}

@media (pointer: coarse) {
    .ctrl-toggle, .playback button, .playback select { min-height: var(--tap); }
}
