/* ==========================================================================
   Haru Smog — minimal dark theme
   Pure black, hairline surfaces, small precise type, white as the only
   accent besides the air-quality status colours. A quiet starfield canvas
   (starfield_controller.js) sits fixed behind the page.
   ========================================================================== */

:root {
    color-scheme: dark;

    --bg: #000000;
    --surface: #101010;
    --surface-hover: #171717;
    --border: rgba(255, 255, 255, 0.14);
    --border-strong: rgba(255, 255, 255, 0.26);
    --text: #f2f2f2;
    --text-2: #c4c4c4;
    --muted: #8c8c8c;

    /* Air-quality status — the only chroma on the page. */
    --air-green: #2fd08a;
    --air-yellow: #f5c451;
    --air-red: #f26b6b;
    --air-purple: #b58cf6;
    --air-unknown: #6f6f6f;

    /* Dimmed status palette for large fills (chart bars). */
    --pm-green: #2f9e6e;
    --pm-yellow: #b8932f;
    --pm-red: #c25252;
    --pm-purple: #8b62c8;

    --font: "Geist", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;

    --radius: 12px;
    --radius-sm: 8px;
    --content: 1040px;
    --gutter: 24px;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    /* Background on <html> propagates to the canvas, so the fixed .sky layer
       (z-index -1) sits above it and below the content. */
    background: var(--bg);
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

::selection {
    background: rgba(255, 255, 255, 0.24);
}

:focus-visible {
    outline: 1px solid #fff;
    outline-offset: 2px;
    border-radius: 4px;
}

h1,
h2,
p {
    margin: 0;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* --------------------------------------------------------------------------
   Sky
   -------------------------------------------------------------------------- */

.sky {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
    background: var(--bg);
}

/* Soft horizon glow at the top; the rest stays black. */
.sky::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(900px 420px at 50% -120px, rgba(255, 255, 255, 0.07), transparent 70%);
}

.sky__stars {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

/* --------------------------------------------------------------------------
   Masthead — a plain row, no bar
   -------------------------------------------------------------------------- */

.masthead {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 24px;
    padding-top: 24px;
}

.masthead__nav {
    margin-left: auto;
}

.logo {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    letter-spacing: -0.01em;
    color: var(--text);
    text-decoration: none;
}

.logo__mark {
    width: 16px;
    height: 16px;
    flex: none;
    fill: #fff;
}

.masthead__nav {
    display: flex;
    align-items: center;
    gap: 20px;
    font-size: 14px;
}

.nav-link {
    color: var(--text-2);
    text-decoration: none;
    transition: color 0.15s ease;
}

.nav-link:hover,
.nav-link:focus-visible {
    color: var(--text);
}

.locale-switcher {
    display: flex;
    align-items: center;
}

/* Chevron for selects — appearance:none drops the native arrow. */
.locale-switcher__select {
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 7.5l3-3' fill='none' stroke='%23d0d0d0' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
}

.locale-switcher__select {
    border: 0;
    background-color: transparent;
    background-position: right center;
    padding: 4px 16px 4px 0;
    color: var(--text-2);
    font-family: inherit;
    font-size: 14px;
    transition: color 0.15s ease;
}

.locale-switcher__select:hover,
.locale-switcher__select:focus-visible {
    color: var(--text);
}

.locale-switcher__select option {
    background: #0a0a0a;
    color: var(--text);
}

/* --------------------------------------------------------------------------
   Flash
   -------------------------------------------------------------------------- */

/* Flash messages are toasts: fixed at the top centre, small and quiet,
   dismissed by dismiss_controller.js after a few seconds. */
.flash-stack {
    position: fixed;
    /* Under the top bar, right-aligned: clear of the search field and the
       title on desktop. */
    top: 72px;
    right: 24px;
    z-index: 1200;
    width: min(calc(100% - 32px), 400px);
    display: grid;
    gap: 8px;
    pointer-events: none;
}

.flash {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 9px 8px 9px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(14, 14, 14, 0.94);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    font-size: 13px;
    line-height: 1.4;
    color: var(--text);
    pointer-events: auto;
    animation: toast-in 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.flash.is-leaving {
    animation: toast-out 0.22s ease-in both;
}

.flash__icon {
    width: 14px;
    height: 14px;
    flex: none;
    margin-top: 2px;
    color: var(--text-2);
}

.flash--alert .flash__icon {
    color: var(--air-yellow);
}

.flash--notice .flash__icon {
    color: var(--air-green);
}

.flash__text {
    flex: 1;
    margin: 0;
}

.flash__close {
    display: inline-grid;
    place-items: center;
    width: 22px;
    height: 22px;
    flex: none;
    margin-top: -1px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

.flash__close:hover,
.flash__close:focus-visible {
    color: var(--text);
    background: #1c1c1c;
}

.flash__close svg {
    width: 12px;
    height: 12px;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(-12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toast-out {
    to {
        opacity: 0;
        transform: translateY(-8px);
    }
}

/* --------------------------------------------------------------------------
   Page + hero
   -------------------------------------------------------------------------- */

.page {
    max-width: var(--content);
    margin: 0 auto;
    padding: 48px var(--gutter) 72px;
    display: grid;
    /* minmax(0, …): a wide <select> option must not stretch the track. */
    grid-template-columns: minmax(0, 1fr);
    gap: 56px;
}

.hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
}

.hero h1 {
    max-width: 760px;
    font-size: 30px;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.02em;
    text-wrap: balance;
}

.hero__status {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-2);
}

.hero__status strong {
    font-weight: 500;
    color: var(--text);
}

.hero__sep {
    color: var(--muted);
}

.hero__status time {
    font-variant-numeric: tabular-nums;
}

.dot {
    width: 7px;
    height: 7px;
    flex: none;
    border-radius: 50%;
    background: var(--air-unknown);
}

.dot--green { background: var(--air-green); box-shadow: 0 0 8px rgba(47, 208, 138, 0.6); }
.dot--yellow { background: var(--air-yellow); box-shadow: 0 0 8px rgba(245, 196, 81, 0.6); }
.dot--red { background: var(--air-red); box-shadow: 0 0 8px rgba(242, 107, 107, 0.6); }
.dot--purple { background: var(--air-purple); box-shadow: 0 0 8px rgba(181, 140, 246, 0.6); }

/* Searchable station picker (station_picker_controller.js). */
.picker {
    position: relative;
    flex: 1 1 240px;
    max-width: 380px;
}

.picker__field {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 36px;
    padding: 0 8px 0 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    transition: border-color 0.15s ease, background 0.15s ease;
}

.picker__field:hover {
    border-color: rgba(255, 255, 255, 0.22);
}

.picker__field:focus-within {
    border-color: rgba(255, 255, 255, 0.42);
    background: rgba(255, 255, 255, 0.05);
}

.picker__kbd {
    flex: none;
    padding: 1px 6px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 5px;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.4;
    color: var(--muted);
}

.picker__icon {
    width: 16px;
    height: 16px;
    flex: none;
    color: var(--muted);
}

.picker__input {
    flex: 1;
    min-width: 0;
    height: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    outline: none;
}

.picker__input::placeholder {
    color: var(--muted);
}

.picker__list {
    position: absolute;
    z-index: 20;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    max-height: 320px;
    overflow-y: auto;
    margin: 0;
    padding: 6px;
    list-style: none;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: #0f0f0f;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
}

.picker__list[hidden] {
    display: none;
}

.picker__option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 10px;
    border-radius: 6px;
    font-size: 14px;
    color: var(--text);
    cursor: pointer;
}

.picker__option.is-active {
    background: #1d1d1d;
}

.picker__name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.picker__tag {
    flex: none;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}

.picker__option[aria-selected="true"]::after {
    content: "✓";
    flex: none;
    font-size: 12px;
    color: var(--text-2);
}

.picker__empty {
    padding: 10px;
    font-size: 14px;
    color: var(--muted);
}

/* --------------------------------------------------------------------------
   Stats: one segmented row; hairlines between cells, a calm backdrop so the
   stars stay out of the numbers
   -------------------------------------------------------------------------- */

/* Equal columns whatever the count (3–6); wraps to a grid on small screens. */
.stats {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    margin: 0;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: #0e0e0e;
    overflow: hidden;
}

.stat {
    min-width: 0;
    padding: 18px 20px 20px;
    border-left: 1px solid var(--border-strong);
}

.stat:first-child {
    border-left: 0;
}

.stat__label {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 14px;
    color: var(--text-2);
    white-space: nowrap;
}

.stat__value {
    margin: 10px 0 0;
    font-size: 30px;
    font-weight: 500;
    line-height: 1.1;
    letter-spacing: -0.02em;
    color: #fff;
    font-variant-numeric: tabular-nums;
}

.stat__unit {
    margin-left: 6px;
    font-size: 14px;
    font-weight: 400;
    letter-spacing: 0;
    color: var(--text-2);
}

/* --------------------------------------------------------------------------
   Sections (chart, map)
   -------------------------------------------------------------------------- */

.section__head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px 16px;
    margin-bottom: 12px;
}

.section__title {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.section__title h2 {
    font-size: 16px;
    font-weight: 500;
    letter-spacing: -0.01em;
}

.section__title p {
    font-size: 14px;
    color: var(--muted);
}

.legend {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    margin: 0;
    padding: 0;
    font-size: 13px;
    color: var(--text-2);
}

.legend__item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.legend .dot {
    box-shadow: none;
}

/* Legend plus the chart's range switch, on the right of the section head. */
.section__tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 18px;
}

/* Segmented control in the picker's idiom: a hairline pill group where
   only the pressed segment is drawn in full white. */
.segmented {
    display: inline-flex;
    padding: 2px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
}

.segmented__option {
    padding: 3px 9px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.5;
    letter-spacing: 0.02em;
    white-space: nowrap;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

.segmented__option:hover {
    color: var(--text-2);
}

.segmented__option[aria-pressed="true"] {
    color: var(--text);
    background: rgba(255, 255, 255, 0.1);
}

.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.card--chart {
    padding: 20px 20px 12px;
}

/* --------------------------------------------------------------------------
   Chart
   -------------------------------------------------------------------------- */

/* Anchor for the absolutely-positioned hover tooltip. */
.chart-placeholder {
    position: relative;
    min-height: 300px;
}

.pm-chart__svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
}

.pm-chart__grid line {
    stroke: rgba(255, 255, 255, 0.06);
    shape-rendering: crispEdges;
}

.pm-chart__y-axis text,
.pm-chart__x-axis text {
    fill: var(--muted);
    font-family: var(--font-mono);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

.pm-chart__unit {
    fill: var(--muted);
    font-family: var(--font-mono);
    font-size: 10px;
}

.pm-chart__days line {
    stroke: rgba(255, 255, 255, 0.14);
    stroke-dasharray: 2 4;
}

.pm-chart__days text {
    fill: var(--muted);
    font-family: var(--font-mono);
    font-size: 10px;
}

.pm-chart__empty {
    fill: var(--muted);
    font-size: 13px;
}

.pm-chart__bar {
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.pm-chart__bar.is-dimmed {
    opacity: 0.3;
}

.chart-tooltip {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10;
    pointer-events: none;
    min-width: 150px;
    max-width: 240px;
    padding: 10px 12px;
    background: #0a0a0a;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
    font-size: 12px;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.12s ease, transform 0.12s ease;
}

.chart-tooltip.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.chart-tooltip__time {
    margin-bottom: 6px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--muted);
}

/* "average of N readings" under the bucket's span. */
.chart-tooltip__note {
    display: block;
    margin-top: 1px;
    font-family: var(--font);
    color: var(--muted);
}

.chart-tooltip__headline {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.chart-tooltip__pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 8px 2px 6px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text);
}

.chart-tooltip__pill-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--pill, var(--muted));
}

.chart-tooltip__value {
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.chart-tooltip__grid {
    display: grid;
    grid-template-columns: auto auto;
    gap: 3px 14px;
    margin: 0;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.chart-tooltip__row {
    display: contents;
}

.chart-tooltip__row dt {
    color: var(--text-2);
}

.chart-tooltip__row dd {
    margin: 0;
    text-align: right;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   Map
   -------------------------------------------------------------------------- */

/* The map closes the page at full width; only its header keeps to the grid. */
.container {
    max-width: var(--content);
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--gutter);
    padding-right: var(--gutter);
}

.section--map .section__head {
    margin-bottom: 16px;
}

.map-frame {
    border-top: 1px solid var(--border);
}

/* Esri's dark canvas is a mid grey; pull the base layer towards black. The
   label layer is a separate container, so text stays untouched. */
.osm-map .tiles-base {
    filter: brightness(0.6) saturate(0);
}

.osm-map {
    /* A popup with the full reading is ~340px, so the floor must fit it. */
    height: clamp(460px, 74vh, 840px);
    width: 100%;
    background: var(--bg);
}

/* Leaflet draws popups white — pull them into the theme. */
.osm-map .leaflet-popup-content-wrapper,
.osm-map .leaflet-popup-tip {
    background: #0a0a0a;
    color: var(--text);
    border: 1px solid var(--border-strong);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
}

.osm-map .leaflet-popup-content-wrapper {
    border-radius: var(--radius-sm);
}

.osm-map .leaflet-popup-content {
    margin: 12px 14px;
    font-family: var(--font);
    font-size: 13px;
    line-height: 1.45;
}

.osm-map .leaflet-popup-close-button {
    color: var(--muted);
}

.osm-map .leaflet-container a.leaflet-popup-close-button:hover {
    color: var(--text);
}

.map-popup__name {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
}

.map-popup__meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 10px;
    margin-bottom: 10px;
    font-size: 12px;
    color: var(--text-2);
}

.map-popup__status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.map-popup__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.map-popup__time--stale {
    font-style: italic;
}

/* Reading source — with two providers in one database it shows where the
   numbers come from and which scale they use. */
.map-popup__source {
    padding: 0 6px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    font-size: 10px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.map-popup__stats {
    display: grid;
    grid-template-columns: auto auto;
    gap: 3px 16px;
    margin: 0;
    padding-top: 9px;
    border-top: 1px solid var(--border);
    font-size: 12px;
}

.map-popup__stats dt {
    color: var(--text-2);
}

.map-popup__stats dd {
    margin: 0;
    text-align: right;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

/* Leaflet's controls are light by default — switch them to the theme. */
.osm-map .leaflet-bar {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

.osm-map .leaflet-bar a {
    background-color: #0a0a0a;
    color: var(--text);
    border-bottom-color: var(--border);
}

.osm-map .leaflet-bar a:hover,
.osm-map .leaflet-bar a:focus {
    background-color: #161616;
    color: #fff;
}

.osm-map .leaflet-bar a.leaflet-disabled {
    background-color: #0a0a0a;
    color: #444;
}

.osm-map .leaflet-control-attribution {
    background: rgba(0, 0, 0, 0.7);
    color: var(--muted);
    font-size: 10px;
}

.osm-map .leaflet-control-attribution a {
    color: var(--text-2);
}

/* --------------------------------------------------------------------------
   Motion + responsive
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    .flash,
    .flash.is-leaving {
        animation: none;
    }
}

@media (max-width: 860px) {
    .stats {
        grid-auto-flow: row;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .stat:nth-child(3n + 1) {
        border-left: 0;
    }

    .stat:nth-child(n + 4) {
        border-top: 1px solid var(--border-strong);
    }
}

@media (max-width: 640px) {
    :root {
        --gutter: 16px;
    }

    .masthead .picker {
        order: 3;
        flex-basis: 100%;
        max-width: none;
    }

    .flash-stack {
        top: 12px;
        right: 16px;
        left: 16px;
        width: auto;
    }

    .picker__kbd {
        display: none;
    }

    .page {
        padding: 32px var(--gutter) 64px;
        gap: 40px;
    }

    .hero h1 {
        font-size: 24px;
    }

    .stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stat {
        padding: 14px 16px 16px;
        border-top: 0;
    }

    .stat:nth-child(3n + 1) {
        border-left: 1px solid var(--border-strong);
    }

    .stat:nth-child(odd) {
        border-left: 0;
    }

    .stat:nth-child(n + 3) {
        border-top: 1px solid var(--border-strong);
    }

    .stats > .stat:last-child:nth-child(odd) {
        grid-column: 1 / -1;
    }

    .stat__value {
        font-size: 24px;
    }

    .section__title {
        flex-direction: column;
        gap: 2px;
    }

    .card--chart {
        padding: 16px 12px 8px;
    }

    .pm-chart__empty {
        font-size: 12px;
    }

    .osm-map {
        height: clamp(400px, 66vh, 600px);
    }
}
