:root {
    --bg: #0f172a;
    --bg-2: #111c33;
    --card: #ffffff;
    --ink: #0f172a;
    --muted: #64748b;
    --accent: #ef4444;
    --ring: rgba(239, 68, 68, .25);
    --radius: 16px;
    --shadow: 0 10px 30px rgba(15, 23, 42, .08);

    /* Surface tokens that flip with theme */
    --surface-page:     #f8fafc;
    --surface-topbar:   rgba(255, 255, 255, .85);
    --surface-inset:    #f8fafc;   /* forecast day tiles, gauge center bg sources */
    --border-soft:      #e2e8f0;
    --border-dashed:    #e5e7eb;
    --chart-grid:       #eef2f7;
    --chart-tick:       #64748b;
    --hero-base-start:  #ffffff;
    --hero-base-end:    #f8fafc;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --card:             #111c33;
    --ink:              #e2e8f0;
    --muted:            #94a3b8;
    --shadow:           0 10px 30px rgba(0, 0, 0, .45);

    --surface-page:     #070c17;
    --surface-topbar:   rgba(11, 18, 32, .85);
    --surface-inset:    #0b1220;
    --border-soft:      #1e293b;
    --border-dashed:    #1e293b;
    --chart-grid:       rgba(148, 163, 184, .18);
    --chart-tick:       #94a3b8;
    --hero-base-start:  #0b1220;
    --hero-base-end:    #070c17;
}

/* Per-view page tint — light pastel in day mode, subtle hue-shift in dark mode
   so visitors feel a visual shift between Heat / Climate / Satellite / Air Quality. */
body[data-view="heat"]      { --surface-page: #fff1e6; }   /* warm peach */
body[data-view="climate"]   { --surface-page: #e6f1fc; }   /* soft sky blue */
body[data-view="satellite"] { --surface-page: #ece9fb; }   /* pale violet */
body[data-view="air"]       { --surface-page: #e7f6ec; }   /* mint green */

html[data-theme="dark"] body[data-view="heat"]      { --surface-page: #1a0d0a; }
html[data-theme="dark"] body[data-view="climate"]   { --surface-page: #0a1322; }
html[data-theme="dark"] body[data-view="satellite"] { --surface-page: #110d1f; }
html[data-theme="dark"] body[data-view="air"]       { --surface-page: #0a1812; }

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--surface-page);
    color: var(--ink);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background .2s ease, color .2s ease;
}

a { color: inherit; }
img { max-width: 100%; display: block; }

/* ───── topbar ───── */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 28px;
    background: var(--surface-topbar);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border-soft);
}
.brand {
    display: inline-flex; align-items: center; gap: 10px;
    font-weight: 700; letter-spacing: -0.01em; text-decoration: none;
}
.brand__dot {
    width: 10px; height: 10px; border-radius: 50%;
    background: linear-gradient(135deg, #f97316, #ef4444);
    box-shadow: 0 0 0 4px rgba(239, 68, 68, .15);
}
.topbar__links {
    display: inline-flex; align-items: center; gap: 10px;
}
.topbar__links a {
    text-decoration: none;
    font-weight: 500;
    padding: 8px 14px;
    border-radius: 999px;
    background: #0f172a;
    color: #fff;
    transition: transform .15s ease;
}
.topbar__links a:hover { transform: translateY(-1px); }
html[data-theme="dark"] .topbar__links a { background: #ef4444; }

/* ── theme toggle ── */
.theme-toggle {
    appearance: none;
    background: transparent;
    border: 1px solid var(--border-soft);
    color: var(--ink);
    width: 36px; height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 999px;
    cursor: pointer;
    padding: 0;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.theme-toggle:hover { background: var(--surface-inset); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle__icon { width: 18px; height: 18px; display: none; }
html:not([data-theme="dark"]) .theme-toggle__icon--moon { display: block; }
html[data-theme="dark"]       .theme-toggle__icon--sun  { display: block; }

/* ───── view tabs ───── */
.viewtabs {
    display: inline-flex;
    background: #f1f5f9;
    padding: 4px;
    border-radius: 999px;
    gap: 2px;
}
html[data-theme="dark"] .viewtabs { background: #1e293b; }
.viewtab {
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 999px;
    color: #475569;
    font-weight: 500;
    font-size: 14px;
    transition: background .15s ease, color .15s ease;
}
html[data-theme="dark"] .viewtab { color: #cbd5e1; }
.viewtab:hover { color: #0f172a; }
html[data-theme="dark"] .viewtab:hover { color: #f1f5f9; }
.viewtab--active {
    background: #0f172a;
    color: #fff;
    box-shadow: 0 2px 8px rgba(15, 23, 42, .18);
}
html[data-theme="dark"] .viewtab--active {
    background: #334155;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .4);
}
@media (max-width: 720px) {
    .topbar { flex-wrap: wrap; gap: 10px; }
    .viewtabs { order: 3; width: 100%; justify-content: center; }
}

/* ───── hero ───── */
.hero {
    position: relative;
    padding: 48px 28px 80px;
    background:
        radial-gradient(1200px 500px at 10% -10%, rgba(239, 68, 68, .18), transparent 70%),
        radial-gradient(900px 500px at 110% 10%, rgba(245, 158, 11, .18), transparent 60%),
        linear-gradient(180deg, var(--hero-base-start) 0%, var(--hero-base-end) 100%);
}
.hero__inner {
    max-width: 1100px;
    margin: 0 auto;
}
.hero__header {
    display: flex; justify-content: space-between; align-items: flex-end;
    flex-wrap: wrap; gap: 24px; margin-bottom: 28px;
}
.eyebrow {
    display: inline-block;
    margin: 0 0 6px;
    padding: 4px 10px;
    font-size: 12px;
    letter-spacing: .1em;
    text-transform: uppercase;
    border-radius: 999px;
    background: var(--hero-accent, #0f172a);
    color: #fff;
    opacity: .9;
}
.hero__title {
    margin: 0;
    font-size: clamp(32px, 4vw, 48px);
    letter-spacing: -0.02em;
    line-height: 1.1;
}
.hero__title .muted { font-weight: 500; color: var(--muted); margin-left: 8px; }
.hero__meta { color: var(--muted); margin: 6px 0 0; font-size: 14px; }

.city-picker { display: flex; flex-direction: column; gap: 6px; min-width: 220px; }
.city-picker label { font-size: 12px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.city-picker select {
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--border-soft);
    background: var(--card);
    color: var(--ink);
    font: inherit;
    box-shadow: var(--shadow);
    cursor: pointer;
}

/* ───── flash ───── */
.flash {
    padding: 14px 18px;
    border-radius: 12px;
    margin-bottom: 20px;
    border: 1px solid transparent;
    font-weight: 500;
}
.flash--success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.flash--error   { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
html[data-theme="dark"] .flash--success { background: #052e22; color: #a7f3d0; border-color: #065f46; }
html[data-theme="dark"] .flash--error   { background: #3b0a0a; color: #fecaca; border-color: #7f1d1d; }

/* ───── grid ───── */
.grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 20px;
}
.card {
    grid-column: span 6;
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-soft);
    transition: background .2s ease, border-color .2s ease;
}
.card h3 { margin: 0 0 14px; font-size: 14px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.card--primary {
    grid-column: span 6;
    display: flex; flex-direction: column; align-items: center; gap: 18px;
    padding: 36px 24px;
}
.card--span { grid-column: span 12; }
.card__head { display:flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.chart-box { position: relative; width: 100%; height: 280px; }
.chart-box--tall { height: 380px; }
.chart-box > canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
.card__advice { text-align: center; max-width: 34ch; color: #334155; margin: 0; }

@media (max-width: 820px) {
    .card, .card--primary { grid-column: span 12; }
}

/* ───── gauge ───── */
.gauge { width: 260px; height: 260px; position: relative; }
.gauge__ring {
    width: 100%; height: 100%;
    border-radius: 50%;
    background:
        conic-gradient(var(--hi-color, #ef4444) 0 var(--hi-pct, 60%), #e5e7eb 0);
    display: flex; align-items: center; justify-content: center;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,.04);
    transition: background .6s ease;
}
.gauge__center {
    width: 78%; height: 78%; border-radius: 50%;
    background: var(--card);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    box-shadow: inset 0 4px 24px rgba(15, 23, 42, .06);
}
html[data-theme="dark"] .gauge__center { box-shadow: inset 0 4px 24px rgba(0, 0, 0, .4); }
.gauge__label { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.gauge__value { font-size: 56px; font-weight: 700; letter-spacing: -0.03em; line-height: 1; margin-top: 4px; }
.gauge__unit  { font-size: 14px; color: var(--muted); margin-top: 4px; }

.chip {
    display: inline-block;
    padding: 6px 16px;
    border-radius: 999px;
    color: #fff;
    font-weight: 600;
    letter-spacing: .02em;
    box-shadow: 0 6px 16px rgba(239, 68, 68, .25);
}

/* ───── stats ───── */
.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    margin: 0;
}
.stat-grid div { padding: 8px 0; border-top: 1px dashed var(--border-dashed); }
.stat-grid div:nth-child(-n+2) { border-top: none; padding-top: 0; }
.stat-grid dt { font-size: 12px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.stat-grid dd { margin: 2px 0 0; font-size: 26px; font-weight: 600; letter-spacing: -0.01em; }

/* ───── forecast ───── */
.forecast {
    list-style: none; margin: 0; padding: 0;
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px;
}
.forecast__day {
    background: var(--surface-inset);
    border-radius: 12px;
    padding: 14px;
    text-align: center;
    border: 1px solid var(--border-soft);
    display: flex; flex-direction: column; gap: 6px;
}
.forecast__date strong { display: block; }
.forecast__hi { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.forecast__meta { font-size: 12px; }
.forecast__chip {
    margin-top: 6px;
    font-size: 11px;
    color: #fff;
    border-radius: 999px;
    padding: 4px 8px;
    font-weight: 600;
}
@media (max-width: 700px) {
    .forecast { grid-template-columns: repeat(2, 1fr); }
}

/* ───── opt-in ───── */
.optin {
    background: linear-gradient(135deg, #0f172a, #1e293b);
    color: #e2e8f0;
    padding: 72px 28px;
}
.optin__inner {
    max-width: 1100px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 48px;
    align-items: center;
}
.optin h2 { font-size: clamp(26px, 3vw, 36px); margin: 0 0 10px; letter-spacing: -0.02em; }
.optin p { color: #cbd5e1; }
.legend { list-style: none; padding: 0; margin: 20px 0 0; display: grid; gap: 8px; font-size: 14px; }
.legend li { display: flex; align-items: center; gap: 10px; }
.legend span {
    width: 14px; height: 14px; border-radius: 4px; display: inline-block;
}
.optin__form {
    display: flex; flex-direction: column; gap: 16px;
    background: #fff; color: var(--ink);
    padding: 28px;
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
.optin__form label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 14px; }
.optin__form input[type=email], .optin__form select {
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    font: inherit;
}
html[data-theme="dark"] .optin__form { background: #0f172a; color: #e2e8f0; box-shadow: 0 20px 60px rgba(0, 0, 0, .55); }
html[data-theme="dark"] .optin__form input[type=email],
html[data-theme="dark"] .optin__form select {
    background: #020617;
    color: #e2e8f0;
    border-color: #334155;
}
.optin__form input[type=email]:focus, .optin__form select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--ring);
}
.slider-wrap { display: flex; align-items: center; gap: 14px; }
.slider-wrap input[type=range] { flex: 1; accent-color: var(--accent); }
.slider-wrap output {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    min-width: 72px;
    text-align: right;
}

.btn {
    appearance: none;
    border: none;
    cursor: pointer;
    padding: 14px 20px;
    border-radius: 10px;
    font: inherit;
    font-weight: 600;
    transition: transform .15s ease, box-shadow .15s ease;
}
.btn--primary {
    background: linear-gradient(135deg, #f97316, #ef4444);
    color: #fff;
    box-shadow: 0 10px 24px rgba(239, 68, 68, .35);
}
.btn--primary:hover { transform: translateY(-1px); box-shadow: 0 14px 28px rgba(239, 68, 68, .4); }

.muted { color: var(--muted); }
.tiny  { font-size: 12px; }

@media (max-width: 820px) {
    .optin__inner { grid-template-columns: 1fr; gap: 28px; }
}

/* ───── footer ───── */
.site-footer {
    padding: 28px;
    text-align: center;
    background: #0f172a;
    color: #94a3b8;
    font-size: 13px;
}
.site-footer a { color: #e2e8f0; }
.site-footer .credit { margin-top: 8px; }
.site-footer .credit a {
    font-weight: 600;
    background: linear-gradient(135deg, #f97316, #ef4444);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-decoration: none;
}
.site-footer .credit a:hover { text-decoration: underline; text-decoration-color: #ef4444; }

/* ───── air quality view ───── */
.hero--air {
    background:
        radial-gradient(1200px 500px at 10% -10%, rgba(34, 197, 94, .18), transparent 70%),
        radial-gradient(900px 500px at 110% 10%, rgba(14, 165, 233, .18), transparent 60%),
        linear-gradient(180deg, var(--hero-base-start) 0%, var(--hero-base-end) 100%);
}
.eyebrow--air { background: var(--hero-accent, #16a34a); }
.pollutants { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.pollutants li {
    display: flex; align-items: baseline; justify-content: space-between;
    padding: 10px 0;
    border-top: 1px dashed var(--border-dashed);
}
.pollutants li:first-child { border-top: none; padding-top: 0; }
.pollutants__label {
    font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.pollutants__value {
    font-size: 20px; font-weight: 600; letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
}
.pollutants__value small { font-weight: 500; margin-left: 6px; font-size: 12px; }
.aqi-legend {
    list-style: none; padding: 0; margin: 0 0 14px;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px;
    font-size: 14px;
}
.aqi-legend li { display: flex; align-items: center; gap: 10px; color: #334155; }
.aqi-legend span { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }

.optin--air .optin__form input[type=email]:focus,
.optin--air .optin__form select:focus {
    border-color: #16a34a;
    box-shadow: 0 0 0 4px rgba(22, 163, 74, .2);
}
.optin--air .slider-wrap input[type=range] { accent-color: #16a34a; }
.btn--air {
    background: linear-gradient(135deg, #0ea5e9, #16a34a);
    color: #fff;
    box-shadow: 0 10px 24px rgba(22, 163, 74, .35);
}
.btn--air:hover { transform: translateY(-1px); box-shadow: 0 14px 28px rgba(22, 163, 74, .4); }

/* ───── confirm pages ───── */
.confirm { padding: 80px 28px; display: flex; justify-content: center; }
.confirm__card {
    max-width: 520px;
    width: 100%;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 36px;
    text-align: center;
    border: 1px solid var(--border-soft);
}
.confirm__card h1 { margin: 0 0 16px; font-size: 28px; letter-spacing: -0.02em; }
.confirm__card p { color: #334155; }
html[data-theme="dark"] .confirm__card p { color: #cbd5e1; }
.confirm__card form { margin-top: 24px; display: inline-flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.btn--ghost {
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--border-soft);
}
.btn--ghost:hover { background: var(--surface-inset); }

/* ───── climate view ───── */
.hero--climate {
    background:
        radial-gradient(1200px 500px at 10% -10%, rgba(56, 189, 248, .18), transparent 70%),
        radial-gradient(900px 500px at 110% 10%, rgba(16, 185, 129, .18), transparent 60%),
        linear-gradient(180deg, var(--hero-base-start) 0%, var(--hero-base-end) 100%);
}
.eyebrow--climate { background: #0ea5e9; }
.stat-hero {
    font-size: 46px;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin: 6px 0 2px;
    line-height: 1;
}
.delta {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}
.delta--up { background: #fee2e2; color: #991b1b; }
.narrative p { color: #334155; max-width: 70ch; }
.narrative a { color: #0ea5e9; }
html[data-theme="dark"] .narrative p { color: #cbd5e1; }
html[data-theme="dark"] .card__advice { color: #cbd5e1; }

/* ───── satellite view ───── */
.hero--satellite {
    background:
        radial-gradient(1200px 500px at 10% -10%, rgba(59, 130, 246, .18), transparent 70%),
        radial-gradient(900px 500px at 110% 10%, rgba(139, 92, 246, .18), transparent 60%),
        linear-gradient(180deg, var(--hero-base-start) 0%, var(--hero-base-end) 100%);
}
.eyebrow--satellite { background: #3b82f6; }
.map-card { padding: 16px; }
.weather-map {
    width: 100%;
    height: 540px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    background: #0f172a;
}
.map-controls {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 4px 2px;
    flex-wrap: wrap;
}
.map-btn {
    min-width: 44px;
    padding: 10px 14px;
    font-size: 18px;
}
#mapScrub { flex: 1; min-width: 160px; accent-color: #3b82f6; }
.map-time {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    min-width: 140px;
    text-align: center;
    padding: 6px 12px;
    border-radius: 999px;
    background: #f1f5f9;
    color: #334155;
    font-size: 13px;
}
.map-time.is-future { background: #fee2e2; color: #991b1b; }
.map-legend { display: flex; gap: 14px; font-size: 13px; color: #64748b; }
.map-legend__item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.swatch--past { background: #3b82f6; }
.swatch--future { background: #ef4444; }
/* Leaflet tweaks */
.weather-map .leaflet-container { background: #0f172a; font-family: inherit; }

/* ───── satellite weather strip ───── */
.weather-strip {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
    padding: 18px 22px;
}
.weather-strip__main {
    display: flex;
    gap: 28px;
    flex-wrap: wrap;
    align-items: baseline;
}
.weather-strip__cond,
.weather-strip__stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 100px;
}
.weather-strip__label {
    font-size: 11px;
    letter-spacing: .5px;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
}
.weather-strip__stat strong,
.weather-strip__cond strong {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.2;
}
.weather-strip__stat .muted {
    font-size: 12px;
    color: var(--muted);
    font-weight: 500;
}
.weather-strip__stat--wind strong {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.wind-arrow {
    display: inline-block;
    transform: rotate(calc(var(--wind-dir, 0deg) + 180deg));
    color: #3b82f6;
    font-size: 18px;
    line-height: 1;
}
.weather-strip__aside {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-end;
}
.tc-hint {
    font-size: 12px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 999px;
    letter-spacing: .2px;
    white-space: nowrap;
}
.tc-hint--calm    { background: #ecfdf5; color: #065f46; }
.tc-hint--watch   { background: #fef9c3; color: #854d0e; }
.tc-hint--warn    { background: #ffedd5; color: #9a3412; }
.tc-hint--high    { background: #fee2e2; color: #991b1b; }
.tc-hint--extreme { background: #450a0a; color: #fecaca; }
html[data-theme="dark"] .tc-hint--calm  { background: #052e22; color: #a7f3d0; }
html[data-theme="dark"] .tc-hint--watch { background: #3b2d05; color: #fde68a; }
html[data-theme="dark"] .tc-hint--warn  { background: #3b1e05; color: #fdba74; }
html[data-theme="dark"] .tc-hint--high  { background: #3b0a0a; color: #fecaca; }
.tc-link {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
}
.tc-link:hover { text-decoration: underline; }
@media (max-width: 640px) {
    .weather-strip__aside { align-items: flex-start; }
}
.map-hint { margin: 10px 4px 0; max-width: 70ch; line-height: 1.4; }
