:root {
    --cream: #fff6e6;
    --paper: rgba(255, 251, 242, 0.92);
    --paper-solid: #fffbf2;
    --line: rgba(59, 42, 32, 0.14);
    --ink: #3b2a20;
    --ink-soft: #6f5747;
    --ink-faint: #a08a78;
    --green: #8cc63f;
    --green-deep: #5c9a2a;
    --green-soft: #e4f3cf;
    --blue: #5bc8f0;
    --blue-deep: #1e8fcf;
    --blue-soft: #dcf2fc;
    --blush: #f3a9c4;
    --tube-red: #dc241f;
    --tube-blue: #1c3f94;
    --sun: #ffc93c;
    --radius: 20px;
    --font-ui: 'Nunito', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    background: var(--cream);
    color: var(--ink);
    font-family: var(--font-ui);
    overflow: hidden;
}

#scene {
    position: fixed;
    inset: 0;
    background: linear-gradient(180deg, #7fd0f5 0%, #c9ecfa 55%, #fff4e0 100%);
}

#scene canvas { display: block; }

/* CSS2DRenderer z-indexes every label; the stacking context keeps them under the UI. */
.label-layer {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
}

.tower-label {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--paper-solid);
    border: 1.5px solid rgba(59, 42, 32, 0.35);
    box-shadow: 0 2px 0 rgba(59, 42, 32, 0.15);
    color: var(--ink-soft);
    font-size: 10.5px;
    font-weight: 700;
    white-space: nowrap;
    transform: translateY(-6px);
    transition: color 0.3s, border-color 0.3s, background 0.3s;
}

.tower-label .tl-rank { color: var(--ink-faint); font-weight: 800; }
.tower-label.is-top { color: var(--ink); background: var(--green-soft); border-color: var(--green-deep); }
.tower-label.is-top .tl-rank { color: var(--green-deep); }

.topbar {
    position: fixed;
    top: 18px;
    left: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 10;
    pointer-events: none;
}

/* London Underground roundel: red ring with a blue name bar across it. */
.logo {
    position: relative;
    display: flex;
    align-items: center;
    height: 44px;
    padding-left: 22px;
}

.roundel {
    position: absolute;
    left: 0;
    top: 0;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 8px solid var(--tube-red);
    background: var(--paper-solid);
    box-shadow: 0 3px 0 rgba(59, 42, 32, 0.2);
}

.logo-bar {
    position: relative;
    padding: 4px 14px 4px 12px;
    background: var(--tube-blue);
    color: #fff;
    font-family: var(--font-ui);
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    box-shadow: 0 3px 0 rgba(59, 42, 32, 0.2);
}



.badge {
    padding: 5px 12px;
    border-radius: 999px;
    background: var(--paper-solid);
    border: 1.5px solid var(--green-deep);
    color: var(--green-deep);
    font-size: 0.74rem;
    font-weight: 800;
    box-shadow: 0 2px 0 rgba(59, 42, 32, 0.12);
}

.panel {
    position: fixed;
    z-index: 10;
    background: var(--paper);
    border: 2px solid var(--ink);
    border-radius: var(--radius);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 6px 0 rgba(59, 42, 32, 0.18), 0 18px 40px rgba(59, 42, 32, 0.12);
}

.panel-left {
    top: 80px;
    left: 24px;
    width: 300px;
    padding: 18px 20px 14px;
}

/* Tube station name board. */
.panel-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 3px 12px 3px 4px;
    border-radius: 999px;
    background: var(--tube-blue);
    color: #fff;
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.panel-title::before {
    content: '';
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 3.5px solid var(--tube-red);
    background: #fff;
}

.panel-sub {
    margin: 6px 0 14px;
    font-size: 0.86rem;
    font-weight: 700;
    color: var(--ink-soft);
}

.slider-group { margin-bottom: 14px; }

.slider-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 6px;
    font-size: 0.86rem;
    font-weight: 700;
    color: var(--ink);
}

.slider-row small { color: var(--ink-faint); font-size: 0.7rem; font-weight: 600; margin-left: 2px; }
.slider-row strong { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 900; }

.info-wrap { position: relative; display: inline-block; }

.info-icon {
    display: inline-grid;
    place-items: center;
    width: 15px;
    height: 15px;
    margin-left: 2px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(59, 42, 32, 0.1);
    color: var(--ink-faint);
    font-size: 0.6rem;
    font-style: normal;
    line-height: 1;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    vertical-align: middle;
}

.info-icon:hover,
.info-icon:focus-visible { color: #fff; background: var(--tube-blue); outline: none; }

.info-tip {
    position: absolute;
    z-index: 25;
    top: 20px;
    left: 0;
    width: 220px;
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--paper-solid);
    border: 1.5px solid var(--ink);
    box-shadow: 0 3px 0 rgba(59, 42, 32, 0.18);
    color: var(--ink-soft);
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.4;
    white-space: normal;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
    pointer-events: none;
}

.info-wrap:hover .info-tip,
.info-wrap:focus-within .info-tip,
.info-wrap.is-open .info-tip {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

input[type=range] {
    --fill: 50%;
    width: 100%;
    height: 10px;
    appearance: none;
    -webkit-appearance: none;
    border-radius: 999px;
    border: 1.5px solid rgba(59, 42, 32, 0.25);
    background: linear-gradient(90deg, var(--blue), var(--green)) 0 / var(--fill) 100% no-repeat, #f1e6d2;
    cursor: pointer;
    outline: none;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    border: 2.5px solid var(--ink);
    box-shadow: 0 2px 0 rgba(59, 42, 32, 0.25), inset 0 -3px 0 var(--blush);
    transition: transform 0.15s;
}

input[type=range]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    border: 2.5px solid var(--ink);
    box-shadow: 0 2px 0 rgba(59, 42, 32, 0.25), inset 0 -3px 0 var(--blush);
}

input[type=range]:active::-webkit-slider-thumb { transform: scale(1.2); }
input[type=range]:focus-visible { box-shadow: 0 0 0 3px var(--blue-soft), 0 0 0 5px var(--blue); }

.sync-status {
    min-height: 1em;
    margin-top: 4px;
    font-size: 0.74rem;
    font-weight: 700;
    color: var(--ink-faint);
}

.sync-status[data-state="ok"] { color: var(--green-deep); }
.sync-status[data-state="warn"] { color: #c98a00; }

.panel-right {
    top: 80px;
    right: 24px;
    bottom: 24px;
    width: 310px;
    padding: 18px 12px 12px;
    display: flex;
    flex-direction: column;
}

.panel-right .panel-title { margin: 0 8px; align-self: flex-start; }
.panel-right .panel-sub { padding: 0 8px; margin-bottom: 10px; }

.leaderboard {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    padding: 2px 2px 2px 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(59, 42, 32, 0.25) transparent;
}

.lb-row {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    margin-bottom: 5px;
    border-radius: 14px;
    border: 1.5px solid transparent;
    cursor: pointer;
    transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1), background 0.2s, border-color 0.2s;
}

.lb-row:hover,
.lb-row:focus-visible { background: var(--blue-soft); outline: none; }
.lb-row.is-top { background: rgba(140, 198, 63, 0.12); }
.lb-row.is-selected { border-color: var(--ink); background: var(--green-soft); box-shadow: 0 3px 0 rgba(59, 42, 32, 0.15); }

.lb-rank {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: #fff;
    border: 2px solid rgba(59, 42, 32, 0.2);
    color: var(--ink-soft);
    font-size: 0.78rem;
    font-weight: 900;
}

.lb-row.is-top .lb-rank { border: 3px solid var(--tube-red); color: var(--tube-blue); }
.lb-row.is-first .lb-rank {
    background: var(--sun);
    border-color: var(--ink);
    color: var(--ink);
    box-shadow: 0 2px 0 rgba(59, 42, 32, 0.3);
}

.lb-main { flex: 1; min-width: 0; }
.lb-name { font-size: 0.9rem; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.lb-score {
    font-size: 1rem;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
}



.source-tag {
    display: inline-block;
    margin-top: 3px;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 0.66rem;
    font-weight: 700;
}

.source-live { background: var(--green-soft); color: var(--green-deep); }
.source-fallback { background: #fff0c7; color: #a87400; }

.detail-card {
    left: 50%;
    bottom: 24px;
    width: 340px;
    max-height: calc(100vh - 140px);
    overflow-y: auto;
    padding: 16px 18px 16px;
    transform: translateX(-50%);
    animation: card-in 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
    scrollbar-width: thin;
    scrollbar-color: rgba(59, 42, 32, 0.25) transparent;
}

.detail-card[hidden] { display: none; }

@keyframes card-in {
    from { opacity: 0; transform: translate(-50%, 14px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

.detail-back {
    margin-bottom: 10px;
    padding: 4px 12px;
    border: 1.5px solid rgba(59, 42, 32, 0.3);
    border-radius: 999px;
    background: #fff;
    color: var(--ink-soft);
    font: inherit;
    font-size: 0.74rem;
    font-weight: 700;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.detail-back:hover,
.detail-back:focus-visible { color: var(--ink); border-color: var(--ink); background: var(--blue-soft); outline: none; }

.detail-rank {
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-soft);
}

.detail-name { margin: 2px 0 4px; font-size: 1.4rem; font-weight: 900; line-height: 1.15; }

.bars { margin: 12px 0 10px; display: grid; gap: 8px; }

.bar {
    display: grid;
    grid-template-columns: 104px 1fr 40px;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--ink);
}

.bar strong { text-align: right; font-variant-numeric: tabular-nums; font-size: 0.76rem; font-weight: 900; color: var(--ink-soft); }

.bar-track {
    height: 10px;
    border-radius: 999px;
    background: #f1e6d2;
    border: 1.5px solid rgba(59, 42, 32, 0.18);
    overflow: hidden;
}

.bar-fill {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--blue), var(--green));
    transition: width 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.bar:nth-child(2) .bar-fill { transition-delay: 0.06s; }
.bar:nth-child(3) .bar-fill { transition-delay: 0.12s; }
.bar:nth-child(4) .bar-fill { transition-delay: 0.18s; }
.bar:nth-child(5) .bar-fill { transition-delay: 0.24s; }
.bar:nth-child(6) .bar-fill { transition-delay: 0.30s; }

#sliders .slider-group { margin-bottom: 10px; }

.detail-extras:empty { display: none; }
.dx-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
}
.dx-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px;
    border: 1.5px solid rgba(59, 42, 32, 0.16);
    border-radius: 14px;
    background: #fff;
    animation: dx-in 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}
.dx-cell:nth-child(1) { background: var(--blue-soft); }
.dx-cell:nth-child(2) { background: #fde9f0; animation-delay: 0.08s; }
.dx-cell:nth-child(3) { background: var(--green-soft); animation-delay: 0.16s; }
.dx-wide { grid-column: 1 / -1; }
.dx-label { font-size: 0.68rem; font-weight: 700; color: var(--ink-soft); letter-spacing: 0.02em; }
.dx-label small { font-size: 0.62rem; }
.dx-value { font-size: 1.15rem; font-weight: 900; color: var(--ink); font-variant-numeric: tabular-nums; }
.dx-value small { font-size: 0.68rem; font-weight: 700; color: var(--ink-soft); margin-left: 2px; }
.dx-sub { font-size: 0.66rem; font-weight: 600; color: var(--ink-soft); }
.dx-est {
    padding: 0 6px;
    border-radius: 999px;
    background: #fff0c7;
    color: #a87400;
    font-size: 0.6rem;
}
.dx-trend { font-size: 0.7rem; }
.dx-up { color: var(--green-deep); }
.dx-down { color: var(--tube-red); }
.dx-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.dx-chip {
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.64rem;
    font-weight: 700;
    color: var(--ink-soft);
    border: 1px solid rgba(59, 42, 32, 0.12);
    background: color-mix(in srgb, var(--green) calc(var(--d) * 5%), #fff);
}
.dx-chip b { color: var(--ink); }

@keyframes dx-in {
    from { opacity: 0; transform: translateY(6px); }
}
@media (prefers-reduced-motion: reduce) {
    .dx-cell { animation: none; }
}

.hero {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 5;
    width: min(800px, 90vw);
    text-align: center;
    pointer-events: none;
    transform: translate(-50%, -60%);
    transform-origin: top center;
    animation: hero-in 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
    transition: top 1.1s cubic-bezier(0.65, 0, 0.35, 1), transform 1.1s cubic-bezier(0.65, 0, 0.35, 1);
}

.hero h1 {
    font-size: clamp(2rem, 4.4vw, 3.5rem);
    font-weight: 900;
    letter-spacing: -0.02em;
    line-height: 1.05;
    color: var(--ink);
    text-shadow: 0 2px 0 #fff, 0 0 30px rgba(255, 255, 255, 0.9);
}

.hero p {
    margin-top: 14px;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--ink-soft);
    text-shadow: 0 1px 0 #fff;
    transition: opacity 0.5s;
}

body.is-ready .hero {
    top: 18px;
    transform: translate(-50%, 0) scale(0.5);
}

body.is-ready .hero p { opacity: 0; }

@keyframes hero-in {
    from { opacity: 0; transform: translate(-50%, -45%); }
    to { opacity: 1; transform: translate(-50%, -60%); }
}

.panel-left,
.panel-right {
    opacity: 0;
    transition: opacity 0.6s 0.5s, transform 0.6s 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.panel-left { transform: translateX(-16px); }
.panel-right { transform: translateX(16px); }

body.is-ready .panel-left,
body.is-ready .panel-right {
    opacity: 1;
    transform: none;
}

/* Toolbar + search stack in one column so a wrapping toolbar pushes the search down instead of hiding under it. */
.center-controls {
    position: fixed;
    top: 84px;
    left: 50%;
    z-index: 12;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: max-content;
    max-width: calc(100vw - 700px);
    transform: translateX(-50%);
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    max-width: 100%;
    opacity: 0;
    transition: opacity 0.6s 0.7s;
}

.seg button { white-space: nowrap; }

@media (max-width: 1280px) {
    .badge { display: none; }
    .panel-left { width: 270px; }
    .panel-right { width: 280px; }
    .center-controls { max-width: calc(100vw - 640px); }
    #flatmap .leaflet-control-zoom { margin-left: 310px; }
}

body.is-ready .toolbar { opacity: 1; }

.seg {
    display: flex;
    padding: 3px;
    border-radius: 999px;
    background: var(--paper-solid);
    border: 2px solid var(--ink);
    box-shadow: 0 3px 0 rgba(59, 42, 32, 0.18);
}

.seg button,
.chip {
    padding: 5px 12px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--ink-soft);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 800;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.seg button:hover,
.chip:hover { color: var(--ink); background: var(--blue-soft); }
.seg button.is-on { background: var(--ink); color: #fff; }

.chip {
    background: var(--paper-solid);
    border: 2px solid var(--ink);
    box-shadow: 0 3px 0 rgba(59, 42, 32, 0.18);
}

.chip.is-on { background: var(--green-soft); color: var(--ink); }
.seg button:focus-visible,
.chip:focus-visible { outline: 3px solid var(--blue); outline-offset: 1px; }

.lsoa-domain {
    font-family: var(--font-ui);
    appearance: none;
    -webkit-appearance: none;
    padding-right: 28px;
    background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%);
    background-position: calc(100% - 16px) center, calc(100% - 11px) center;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}

.lsoa-domain[hidden],
#score-filters[hidden],
#toggle-live[hidden] { display: none; }

.search-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 420px;
    max-width: 100%;
    opacity: 0;
    transition: opacity 0.6s 0.8s;
}

body.is-ready .search-wrap { opacity: 1; }

.search-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 6px 8px 6px 14px;
    border-radius: 999px;
    background: var(--paper-solid);
    border: 2px solid var(--ink);
    box-shadow: 0 3px 0 rgba(59, 42, 32, 0.18);
}

.search-icon { font-size: 0.9rem; opacity: 0.7; }

.search-input {
    flex: 1;
    min-width: 0;
    border: 0;
    background: transparent;
    font: inherit;
    font-size: 0.86rem;
    font-weight: 700;
    color: var(--ink);
}

.search-input::placeholder { color: var(--ink-faint); font-weight: 600; }
.search-input:focus { outline: none; }

.search-clear {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border: 0;
    border-radius: 50%;
    background: var(--blue-soft);
    color: var(--ink-soft);
    font-size: 0.75rem;
    font-weight: 800;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.search-clear:hover { background: var(--blush); color: var(--ink); }

.search-feedback {
    max-width: 100%;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--paper-solid);
    border: 1.5px solid var(--line);
    color: var(--ink-soft);
    font-size: 0.78rem;
    font-weight: 700;
    text-align: center;
    box-shadow: 0 2px 0 rgba(59, 42, 32, 0.12);
}

.search-feedback.is-searching { color: var(--ink-soft); }
.search-feedback.is-success { border-color: var(--green-deep); background: var(--green-soft); color: var(--ink); }
.search-feedback.is-error { border-color: var(--blush); background: #fff0f5; color: var(--ink); }

body.leaderboard-hidden .panel-right {
    opacity: 0;
    transform: translateX(24px);
    pointer-events: none;
    transition-delay: 0s;
}

.lb-row.is-filtered { opacity: 0.38; }

#flatmap {
    position: fixed;
    inset: 0;
    z-index: 1;
    background: var(--cream);
}

#flatmap[hidden] { display: none; }
#flatmap .leaflet-tile-pane { filter: sepia(0.22) saturate(0.95) brightness(1.04); }
#flatmap .leaflet-control-zoom { margin: 0 0 24px 340px; }
.leaflet-bottom.leaflet-left { bottom: 0; }

body.mode-map .hero h1 { text-shadow: 0 2px 0 #fff, 0 0 18px #fff, 0 0 30px #fff; }

.map-tooltip {
    padding: 6px 10px;
    border: 2px solid var(--ink);
    border-radius: 12px;
    background: var(--paper-solid);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 0.8rem;
    box-shadow: 0 3px 0 rgba(59, 42, 32, 0.2);
}

.map-tooltip::before { display: none; }

.tower-tooltip {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 7px 12px;
    border-radius: 12px;
    background: var(--paper-solid);
    border: 2px solid var(--ink);
    box-shadow: 0 4px 0 rgba(59, 42, 32, 0.2);
    pointer-events: none;
    font-size: 0.8rem;
    font-weight: 800;
    white-space: nowrap;
}

.tower-tooltip[hidden] { display: none; }
.tower-tooltip span { color: var(--green-deep); font-weight: 900; font-variant-numeric: tabular-nums; }

/* Desktop: the sheet wrapper is layout-neutral, so its children keep their fixed positions. */
.sheet { display: contents; }
.sheet-handle { display: none; }

/* Phones (portrait and landscape): the 3D city fills the screen and the
   controls live in a bottom sheet over it. Collapsed, the sheet peeks just the
   toolbar + search (sheet.js measures that into --sheet-peek); expanded, it
   shows priorities and the leaderboard. The borough detail card is a second
   bottom sheet on top. Keep in sync with STACKED_LAYOUT_QUERY in main.js. */
@media (max-width: 820px), (max-height: 560px) {
    .topbar { top: max(12px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left)); }
    .hero {
        width: 92vw;
        transition: top 1.1s cubic-bezier(0.65, 0, 0.35, 1), transform 1.1s cubic-bezier(0.65, 0, 0.35, 1), opacity 0.3s;
    }
    body.is-ready .hero { top: calc(max(12px, env(safe-area-inset-top)) + 50px); transform: translate(-50%, 0) scale(0.55); }
    body.sheet-open .hero,
    body.has-detail .hero { opacity: 0; }

    .sheet {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 20;
        display: flex;
        flex-direction: column;
        gap: 14px;
        height: min(78vh, calc(100vh - 96px));
        padding: 0 max(14px, env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
        background: var(--paper-solid);
        border: 2px solid var(--ink);
        border-bottom: 0;
        border-radius: var(--radius) var(--radius) 0 0;
        box-shadow: 0 -8px 30px rgba(59, 42, 32, 0.16);
        overflow-y: hidden;
        overscroll-behavior: contain;
        transform: translateY(calc(100% - var(--sheet-peek, 150px)));
        transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    }
    @supports (height: 1svh) {
        .sheet { height: min(78svh, calc(100svh - 96px)); }
    }
    body.sheet-open .sheet { transform: none; overflow-y: auto; }
    body:not(.is-ready) .sheet { transform: translateY(100%); }

    .sheet-handle {
        position: sticky;
        top: 0;
        z-index: 2;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 6px;
        margin: 0 -14px;
        padding: 10px 14px 2px;
        border: 0;
        background: var(--paper-solid);
        color: var(--ink-soft);
        font: inherit;
        font-size: 0.76rem;
        font-weight: 800;
        cursor: pointer;
        touch-action: none;
    }
    .sheet-handle:focus-visible { outline: 3px solid var(--blue); outline-offset: -3px; }
    .sheet-grabber { width: 44px; height: 5px; border-radius: 999px; background: rgba(59, 42, 32, 0.3); }
    body.sheet-open .sheet-hint { display: none; }

    .center-controls {
        position: static;
        width: auto;
        max-width: none;
        align-items: stretch;
        transform: none;
    }
    /* One swipeable row instead of wrapping into a tall block. */
    .toolbar {
        flex-wrap: nowrap;
        justify-content: flex-start;
        margin: 0 -14px;
        padding: 2px 14px 6px;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        scrollbar-width: none;
        /* Fade the right edge to hint that the row scrolls sideways. */
        -webkit-mask-image: linear-gradient(90deg, #000 88%, transparent);
        mask-image: linear-gradient(90deg, #000 88%, transparent);
    }
    .toolbar::-webkit-scrollbar { display: none; }
    .toolbar > * { flex-shrink: 0; }
    .search-wrap { width: 100%; }

    /* Inside the sheet the panels are sections, not floating cards. */
    .panel-left,
    .panel-right {
        position: static;
        display: block;
        width: auto;
        padding: 16px 0 0;
        border: 0;
        border-top: 1.5px dashed var(--line);
        border-radius: 0;
        background: none;
        box-shadow: none;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        transform: none;
    }
    .panel-right .panel-title { margin: 0; }
    .panel-right .panel-sub { padding: 0; }
    .leaderboard { overflow: visible; }
    body.leaderboard-hidden .panel-right { display: none; }

    #flatmap .leaflet-bottom { bottom: var(--sheet-peek, 150px); }
    #flatmap .leaflet-control-zoom { margin: 0 0 12px 12px; }

    /* Source tooltips span the slider row so they can't run off the right edge. */
    .slider-group { position: relative; }
    .info-wrap { position: static; }
    .info-tip { top: 26px; left: 0; right: 0; width: auto; }

    .detail-card {
        position: fixed;
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 30;
        width: auto;
        max-height: 56vh;
        padding: 14px max(16px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
        border-bottom: 0;
        border-radius: var(--radius) var(--radius) 0 0;
        transform: none;
        overscroll-behavior: contain;
        animation: sheet-in 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
    }
    @supports (height: 1svh) {
        .detail-card { max-height: 56svh; }
    }
    .loading {
        bottom: calc(24px + env(safe-area-inset-bottom));
        max-width: calc(100vw - 24px);
        white-space: nowrap;
    }
}

/* Landscape phones: vertical space is what's scarce, so the peek strip is one
   row (toolbar beside search) and the title makes way for the city. */
@media (max-height: 560px) {
    body.is-ready .hero { opacity: 0; }
    .sheet-hint { display: none; }
    .center-controls { flex-direction: row; align-items: center; }
    .toolbar { flex: 1 1 auto; min-width: 0; margin-right: 0; }
    .search-wrap { flex: 0 0 38%; }
}

@keyframes sheet-in {
    from { transform: translateY(100%); }
    to { transform: none; }
}

/* Touch screens: bigger hit areas, and 16px inputs so iOS doesn't zoom in on focus. */
@media (pointer: coarse) {
    button,
    .lb-row { -webkit-tap-highlight-color: transparent; }
    .seg button,
    .chip { min-height: 38px; padding: 8px 14px; }
    .search-input,
    .lsoa-domain { font-size: 16px; }
    .search-clear { width: 32px; height: 32px; }
    .info-icon { width: 22px; height: 22px; font-size: 0.72rem; }
    .detail-back { padding: 8px 14px; font-size: 0.82rem; }
    .lb-row { padding: 10px; }
    input[type=range] { height: 12px; }
    input[type=range]::-webkit-slider-thumb { width: 28px; height: 28px; }
    input[type=range]::-moz-range-thumb { width: 24px; height: 24px; }
}

body.no-webgl {
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 180px 12px 24px;
    max-width: 720px;
    margin: 0 auto;
}

body.no-webgl #scene { display: none; }
body.no-webgl .hero { top: 40px; transform: translate(-50%, 0) scale(0.6); }
body.no-webgl .panel,
body.no-webgl .detail-card { position: relative; inset: auto; width: auto; transform: none; }
body.no-webgl .detail-card { order: -1; animation: none; }
body.no-webgl .leaderboard { overflow: visible; }
body.no-webgl .sheet { display: contents; }
body.no-webgl .sheet-handle { display: none; }

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-delay: 0s !important;
        transition-duration: 0.01ms !important;
        transition-delay: 0s !important;
    }
}

.loading {
    position: fixed;
    left: 50%;
    bottom: 48px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    border-radius: 999px;
    background: var(--paper-solid);
    border: 2px solid var(--ink);
    box-shadow: 0 4px 0 rgba(59, 42, 32, 0.2);
    color: var(--ink-soft);
    font-size: 0.88rem;
    font-weight: 700;
    z-index: 20;
    transition: opacity 0.4s;
}

.loading.is-hidden { opacity: 0; pointer-events: none; }

.spinner {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 3px solid var(--blue-soft);
    border-top-color: var(--green);
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }