/* How's the Bite? — styles
   Plain CSS, no framework. Theme tokens first, then layout top to bottom. */

/* ---------- Tokens ---------- */

:root {
    color-scheme: light;

    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-2: #475569;
    --muted: #64748b;
    --primary: #1d4ed8;
    --primary-soft: #dbeafe;
    --focus: #2563eb;
    --shadow: 0 1px 2px rgb(15 23 42 / 0.06), 0 4px 16px rgb(15 23 42 / 0.06);

    --header-bg: linear-gradient(135deg, #2563eb, #1e3a8a);

    /* Factor ratings (always paired with a text label) */
    --rating-excellent: #15803d;
    --rating-good: #65a30d;
    --rating-fair: #d97706;
    --rating-poor: #dc2626;

    /* Chart series, validated for colour-vision deficiency against --surface */
    --series-pressure: #2563eb;
    --series-air: #d97706;
    --series-water: #0d9488;
    --series-level: #7c3aed;

    --notice-error-bg: #fef2f2;
    --notice-error-border: #fecaca;
    --notice-info-bg: #eff6ff;
    --notice-info-border: #bfdbfe;

    --radius: 14px;
    --radius-sm: 10px;
    --nav-height: 60px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
    color-scheme: dark;

    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #273449;
    --border: #334155;
    --border-strong: #475569;
    --text: #f1f5f9;
    --text-2: #cbd5e1;
    --muted: #94a3b8;
    --primary: #93c5fd;
    --primary-soft: #1e3a8a;
    --focus: #93c5fd;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 4px 16px rgb(0 0 0 / 0.25);

    --header-bg: linear-gradient(135deg, #1e40af, #0f172a);

    --rating-excellent: #22c55e;
    --rating-good: #a3e635;
    --rating-fair: #f59e0b;
    --rating-poor: #f87171;

    --series-pressure: #3b82f6;
    --series-air: #d97706;
    --series-water: #0ea597;
    --series-level: #8b5cf6;

    --notice-error-bg: #3b1114;
    --notice-error-border: #7f1d1d;
    --notice-info-bg: #172554;
    --notice-info-border: #1e40af;
}

/* ---------- Base ---------- */

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

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
    scroll-padding-top: 76px;
}

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
    padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom));
}

h1, h2, h3, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: var(--primary); }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    border-radius: 6px;
}

.wrap {
    width: 100%;
    max-width: 1120px;
    margin-inline: auto;
    padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
}

.muted { color: var(--muted); font-weight: 400; }

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.skip-link {
    position: absolute;
    left: 12px;
    top: -60px;
    z-index: 100;
    padding: 10px 14px;
    background: var(--surface);
    color: var(--text);
    border-radius: 8px;
    box-shadow: var(--shadow);
}
.skip-link:focus { top: 12px; }

.icon-sprite { position: absolute; }

.icon {
    width: 20px;
    height: 20px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

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

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: 999px;
    background: none;
    font-weight: 600;
    font-size: 0.9375rem;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s;
}
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-icon { flex: none; width: 44px; padding: 0; }
.btn-small { min-height: 36px; padding: 0 14px; font-size: 0.875rem; }
.btn-small.btn-icon { width: 36px; padding: 0; }

.btn-ghost { color: #fff; background: rgb(255 255 255 / 0.14); }
.btn-ghost:hover { background: rgb(255 255 255 / 0.24); }

.btn-outline { border-color: var(--border-strong); background: var(--surface); color: var(--text-2); }
.btn-outline:hover { background: var(--surface-2); }

.btn-solid { background: #fff; color: #1e3a8a; }
.btn-solid:hover { background: #e0e7ff; }

.btn.is-busy .icon { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Header ---------- */

.app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--header-bg);
    color: #fff;
    padding-top: env(safe-area-inset-top);
}

.header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 60px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.01em;
    text-decoration: none;
    white-space: nowrap;
}
.brand-icon { width: 26px; height: 26px; }

.header-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- Location bar ---------- */

.location-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding-block: 16px;
}

.location-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.location-title h1 {
    font-size: clamp(1.25rem, 1rem + 1.2vw, 1.75rem);
    line-height: 1.2;
    letter-spacing: -0.01em;
    overflow-wrap: anywhere;
}
.location-title p { font-size: 0.875rem; }

.search { position: relative; }

.search-icon {
    position: absolute;
    left: 14px;
    top: 14px;
    color: var(--muted);
    pointer-events: none;
}

.search input {
    width: 100%;
    height: 48px;
    padding: 0 14px 0 44px;
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    background: var(--surface-2);
    font-size: 1rem;
}
.search input::placeholder { color: var(--muted); }
.search input:focus-visible { outline-offset: 0; border-radius: 12px; }

.search-results {
    position: absolute;
    inset: calc(100% + 6px) 0 auto 0;
    z-index: 40;
    max-height: min(60vh, 360px);
    overflow-y: auto;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgb(15 23 42 / 0.2);
}

.search-option {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 2px 12px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
}
.search-option .muted { font-size: 0.8125rem; }
.search-option:hover, .search-option[aria-selected="true"] { background: var(--primary-soft); }
.search-message { padding: 12px; color: var(--text-2); }

.chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
}
.chips-label {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}
.chip {
    min-height: 36px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 0.875rem;
    cursor: pointer;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }

/* ---------- Notice ---------- */

.notice {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    margin-top: 16px;
    padding: 12px 16px;
    border: 1px solid var(--notice-error-border);
    border-radius: var(--radius-sm);
    background: var(--notice-error-bg);
    font-size: 0.9375rem;
}
.notice[data-tone="info"] { border-color: var(--notice-info-border); background: var(--notice-info-bg); }
.notice .btn { border-color: var(--border-strong); background: var(--surface); color: var(--text); }

/* ---------- Sections ---------- */

.section { margin-top: 28px; }
#conditions { margin-top: 20px; }

.section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 10px 16px;
    margin-bottom: 12px;
}
.section-head h2 { font-size: 1.25rem; letter-spacing: -0.01em; }
.section-head p { font-size: 0.9375rem; max-width: 62ch; }

/* ---------- Score + factors ---------- */

.hero { display: grid; gap: 16px; }

.score-card {
    --band-a: #475569;
    --band-b: #334155;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 24px 20px;
    border-radius: var(--radius);
    background: linear-gradient(145deg, var(--band-a), var(--band-b));
    color: #fff;
    text-align: center;
    box-shadow: var(--shadow);
    transition: background 0.3s;
}
.score-card[data-band="exceptional"] { --band-a: #059669; --band-b: #065f46; }
.score-card[data-band="excellent"] { --band-a: #16a34a; --band-b: #166534; }
.score-card[data-band="good"] { --band-a: #0f766e; --band-b: #155e75; }
.score-card[data-band="fair"] { --band-a: #b45309; --band-b: #92400e; }
.score-card[data-band="poor"] { --band-a: #b91c1c; --band-b: #991b1b; }
.score-card[data-band="verypoor"] { --band-a: #991b1b; --band-b: #6b1414; }
.score-card[data-band="terrible"] { --band-a: #7f1d1d; --band-b: #3f1010; }

.score-kicker {
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    opacity: 0.9;
}
.score-number { font-size: clamp(4rem, 3rem + 6vw, 5.5rem); font-weight: 800; line-height: 1; letter-spacing: -0.03em; }
.score-outof { margin-left: 4px; font-size: 1.25rem; font-weight: 600; letter-spacing: 0; opacity: 0.85; }
.score-band { font-size: 1.25rem; font-weight: 700; }
.score-phrase { font-size: 1.0625rem; }
.score-now { margin-top: 10px; font-size: 0.9375rem; opacity: 0.95; }
.score-now:empty { display: none; }

.factors { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

.factor {
    --rating: var(--rating-poor);
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 168px;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.factor[data-rating="excellent"] { --rating: var(--rating-excellent); }
.factor[data-rating="good"] { --rating: var(--rating-good); }
.factor[data-rating="fair"] { --rating: var(--rating-fair); }

.factor.is-placeholder { background: var(--surface-2); box-shadow: none; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

.factor-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-2);
}
.factor-label .icon { width: 18px; height: 18px; color: var(--muted); }
.factor-value { font-size: 1.375rem; font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.factor-note { font-size: 0.875rem; color: var(--text-2); line-height: 1.35; }
.factor-extra { font-size: 0.8125rem; color: var(--muted); line-height: 1.35; }

.factor-foot { display: flex; align-items: center; gap: 10px; margin-top: auto; padding-top: 10px; }
.meter { flex: 1; height: 6px; border-radius: 999px; background: color-mix(in srgb, var(--rating) 22%, var(--surface-2)); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 999px; background: var(--rating); }
.factor-points { display: flex; align-items: baseline; font-size: 0.8125rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.factor-points strong { font-size: 0.9375rem; color: var(--text); }
.rating-tag { margin-left: 8px; font-weight: 600; color: var(--text-2); }

/* ---------- Forecast ---------- */

.forecast {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(136px, 1fr);
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
    scroll-snap-type: x proximity;
}
.forecast-day {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 14px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    scroll-snap-align: start;
}
.forecast-name { font-weight: 700; }
.forecast-name .muted { display: block; font-size: 0.8125rem; }
.forecast-icon { font-size: 2rem; line-height: 1.3; }
.forecast-label { font-size: 0.875rem; color: var(--text-2); min-height: 2.6em; line-height: 1.3; }
.forecast-temps { font-size: 1.125rem; }
.forecast-meta { font-size: 0.8125rem; color: var(--muted); line-height: 1.4; }

/* ---------- Water temperature ---------- */

.segmented {
    display: inline-flex;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
}
.segmented button {
    min-height: 36px;
    padding: 0 16px;
    border: 0;
    border-radius: 999px;
    background: none;
    color: var(--text-2);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--primary); color: var(--surface); }

.level-card { display: grid; gap: 10px; margin-bottom: 12px; padding: 14px 16px; }
.level-card > p { font-size: 0.8125rem; line-height: 1.45; }
.level-stats { display: flex; flex-wrap: wrap; gap: 12px 40px; margin: 0; }
.level-stats:empty { display: none; }
.level-stat dt { font-size: 0.8125rem; font-weight: 600; color: var(--text-2); }
.level-stat dd { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 8px; margin: 0; }
.level-stat strong { font-size: 1.375rem; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.level-stat span { font-size: 0.875rem; color: var(--muted); }

.water-grid { display: grid; gap: 12px; }

.stations {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 380px;
    overflow-y: auto;
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.stations-empty { padding: 20px 12px; color: var(--text-2); text-align: center; }

.station {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 56px;
    padding: 8px 12px 8px 8px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: none;
    text-align: left;
    cursor: pointer;
}
.station:hover { background: var(--surface-2); }
.station[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); }

.station-check { display: grid; place-items: center; width: 22px; height: 22px; flex: none; color: var(--primary); }
.station-check .icon { stroke-width: 3; }
.station-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.station-name { font-weight: 600; line-height: 1.3; }
.station-meta { font-size: 0.8125rem; color: var(--muted); }
.station[aria-pressed="true"] .station-meta { color: var(--text-2); }
.station-temp { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.map-frame {
    min-height: 280px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface-2);
    box-shadow: var(--shadow);
}
.map-frame:has(> .map[hidden]) { display: none; }
.map { width: 100%; height: 100%; min-height: 280px; isolation: isolate; }

/* Leaflet overrides */
.leaflet-container { font: inherit; background: var(--surface-2); }
:root[data-theme="dark"] .leaflet-tile-pane { filter: brightness(0.78) contrast(1.08) saturate(0.85); }
.map-pin {
    border-radius: 50%;
    background: #dc2626;
    border: 3px solid #fff;
    box-shadow: 0 0 0 2px rgb(15 23 42 / 0.35);
}
.map-station { stroke: #fff; stroke-width: 2; fill: #0f766e; fill-opacity: 1; cursor: pointer; }
.map-station.is-selected { fill: #1d4ed8; stroke-width: 3; }

/* ---------- Charts ---------- */

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

.chart-card { padding: 16px 12px 10px 12px; min-width: 0; }
.chart-card h3 { margin: 0 4px 8px; font-size: 1rem; }
.chart-card h3 .muted { font-size: 0.8125rem; }
.chart--pressure { --series: var(--series-pressure); }
.chart--air { --series: var(--series-air); }
.chart--water { --series: var(--series-water); }
.chart--level { --series: var(--series-level); }

.chart-frame { position: relative; }
.chart-plot { display: block; height: 200px; border-radius: 8px; cursor: crosshair; touch-action: pan-y; }
.chart-plot svg { display: block; }

.chart-grid { stroke: var(--border); stroke-width: 1; shape-rendering: crispEdges; }
.chart-tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-area { fill: var(--series); opacity: 0.12; }
.chart-line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.chart-end-label { fill: var(--text); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-crosshair { stroke: var(--border-strong); stroke-width: 1; }

.chart-tooltip {
    position: absolute;
    z-index: 5;
    display: flex;
    flex-direction: column;
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    font-size: 0.8125rem;
    line-height: 1.35;
    white-space: nowrap;
    pointer-events: none;
    transform: translate(12px, -100%);
}
.chart-tooltip[data-side="left"] { transform: translate(calc(-100% - 12px), -100%); }
.chart-tooltip strong { font-size: 0.9375rem; }
.chart-tooltip span { color: var(--muted); }

.chart-empty {
    display: grid;
    place-items: center;
    height: 200px;
    padding: 0 24px;
    color: var(--muted);
    font-size: 0.9375rem;
    text-align: center;
}

.chart-data { margin: 6px 4px 0; font-size: 0.8125rem; }
.chart-data summary { display: inline-block; padding: 6px 0; color: var(--muted); cursor: pointer; }
.chart-data summary:hover { color: var(--text); }
.chart-data table { width: 100%; margin-top: 4px; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.chart-data th, .chart-data td { padding: 5px 4px; border-top: 1px solid var(--border); text-align: left; }
.chart-data th:last-child, .chart-data td:last-child { text-align: right; }

/* ---------- Footer ---------- */

.app-footer {
    display: grid;
    gap: 6px;
    margin-top: 32px;
    padding-block: 20px 28px;
    border-top: 1px solid var(--border);
    font-size: 0.8125rem;
    color: var(--muted);
}

.not-found { display: grid; gap: 10px; padding-block: 18vh; text-align: center; }

.noscript { margin: 24px 16px; padding: 16px; border-radius: 12px; background: var(--notice-error-bg); }

/* ---------- Bottom navigation (phones) ---------- */

.bottom-nav {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
}
.bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    height: var(--nav-height);
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
}
.bottom-nav a[aria-current="true"] { color: var(--primary); }
.bottom-nav a:focus-visible { outline-offset: -4px; }

/* ---------- Install banner ---------- */

.install-banner {
    position: fixed;
    inset: auto 12px calc(var(--nav-height) + env(safe-area-inset-bottom) + 12px) 12px;
    z-index: 35;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 520px;
    margin-inline: auto;
    padding: 10px 10px 10px 16px;
    border-radius: 14px;
    background: #1e3a8a;
    color: #fff;
    box-shadow: 0 12px 32px rgb(15 23 42 / 0.35);
    font-size: 0.9375rem;
}
.install-banner p { flex: 1; }

/* ---------- Wider screens ---------- */

@media (min-width: 620px) {
    .factors { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .wrap { padding-inline: 24px; }
}

@media (min-width: 768px) {
    .charts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    body { padding-bottom: 0; }
    .bottom-nav { display: none; }
    .install-banner { bottom: 16px; }
}

@media (min-width: 900px) {
    .hero { grid-template-columns: minmax(260px, 300px) minmax(0, 1fr); }
    .water-grid { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); }
    .stations, .map-frame { height: 380px; max-height: none; }
}

@media (max-width: 479px) {
    #locateBtn span { display: none; }
    #locateBtn { width: 44px; padding: 0; }
    .brand { font-size: 1.125rem; }
    .factor { min-height: 176px; padding: 12px; }
    .factor-value { font-size: 1.1875rem; }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
