@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,700&family=Manrope:wght@400;500;700&display=swap');

:root {
    --sky-1: #d2e7ff;
    --sky-2: #9cc8f4;
    --sky-3: #6ca3d2;
    --ink-1: #102133;
    --ink-2: #2b4761;
    --card-bg: rgba(244, 250, 255, 0.62);
    --card-border: rgba(255, 255, 255, 0.65);
    --accent: #e66d41;
    --accent-soft: rgba(230, 109, 65, 0.18);
    --shadow: 0 18px 42px rgba(16, 33, 51, 0.14);
    --radius-lg: 22px;
    --radius-md: 16px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: 'Manrope', sans-serif;
    color: var(--ink-1);
    background: linear-gradient(120deg, var(--sky-1), var(--sky-2) 55%, var(--sky-3));
    position: relative;
    overflow-x: hidden;
}

.weather-app {
    position: relative;
    z-index: 5;
    padding: 1.25rem 1rem 2.25rem;
}

/* ---- Dynamic sky: time-of-day base layers + barometer mood veil ---- */
.sky-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
}

/* One full-screen gradient per phase; the active phase fades in (gradients
   can't crossfade, so we stack them and animate opacity instead). */
.sky-layer {
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity 1.6s ease;
}

.sky-layer-day {
    background:
        radial-gradient(circle at 20% 12%, rgba(255, 255, 255, 0.38) 0 20%, transparent 52%),
        linear-gradient(120deg, #d2e7ff, #9cc8f4 55%, #6ca3d2);
}

.sky-layer-dawn {
    background: linear-gradient(160deg, #fde0c0 0%, #f7b58a 38%, #9fb4d8 100%);
}

.sky-layer-dusk {
    background: linear-gradient(160deg, #ff9d72 0%, #d18bb0 45%, #4b4f8e 100%);
}

.sky-layer-night {
    background: linear-gradient(160deg, #0a1730 0%, #122144 55%, #1d2b4d 100%);
}

.phase-day .sky-layer-day,
.phase-dawn .sky-layer-dawn,
.phase-dusk .sky-layer-dusk,
.phase-night .sky-layer-night {
    opacity: 1;
}

/* Faint starfield, only at twilight/night. */
.sky-stars {
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity 1.6s ease;
    background-image:
        radial-gradient(1px 1px at 12% 18%, #fff, transparent),
        radial-gradient(1px 1px at 32% 42%, rgba(255, 255, 255, 0.8), transparent),
        radial-gradient(1.4px 1.4px at 58% 22%, #fff, transparent),
        radial-gradient(1px 1px at 73% 51%, rgba(255, 255, 255, 0.7), transparent),
        radial-gradient(1.2px 1.2px at 86% 30%, #fff, transparent),
        radial-gradient(1px 1px at 47% 12%, rgba(255, 255, 255, 0.85), transparent),
        radial-gradient(1px 1px at 22% 64%, rgba(255, 255, 255, 0.7), transparent),
        radial-gradient(1.3px 1.3px at 91% 60%, #fff, transparent);
}

.phase-night .sky-stars { opacity: 0.9; }
.phase-dusk .sky-stars { opacity: 0.35; }

/* Sun: JS sets its position via translate3d (compositor-only). */
.sky-sun {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1;
    width: clamp(120px, 22vw, 220px);
    height: clamp(120px, 22vw, 220px);
    border-radius: 999px;
    background: radial-gradient(circle, #fff6da 0%, #ffd166 58%, rgba(255, 200, 80, 0) 72%);
    box-shadow: 0 0 90px 30px rgba(255, 213, 128, 0.45);
    transform: translate3d(70vw, 14vh, 0);
    transition: transform 2s linear, opacity 1.4s ease;
    will-change: transform;
    pointer-events: none;
}

.phase-night .sky-sun { opacity: 0; }

/* Moon: fixed in the upper sky, shown at night/dusk. */
.sky-moon {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1;
    width: clamp(90px, 13vw, 150px);
    height: clamp(90px, 13vw, 150px);
    filter: drop-shadow(0 0 6px rgba(232, 238, 250, 0.8))
            drop-shadow(0 0 20px rgba(198, 210, 235, 0.4));
    transform: translate3d(80vw, 30vh, 0);
    opacity: 0;
    transition: opacity 1.4s ease, transform 2s linear;
    pointer-events: none;
}

.sky-moon svg {
    display: block;
}

/* A daytime moon is pale chalk against blue, not a glowing orb -- dial the
   glow right down so it doesn't read as a light leak. */
.phase-day .sky-moon {
    filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.45));
}


/* Barometer mood veil over the sky (below the dashboard content). */
.sky-weather {
    position: fixed;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    background: transparent;
    transition: background 1.6s ease;
}

.mood-change .sky-weather { background: rgba(225, 230, 236, 0.16); }
.mood-rain .sky-weather { background: rgba(120, 131, 143, 0.34); }
.mood-stormy .sky-weather { background: rgba(38, 46, 60, 0.5); }

.glass-panel {
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow);
}

.weather-topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.1rem;
    padding: 1rem 1.2rem;
    animation: panel-enter 480ms ease-out;
}

.weather-topbar h1 {
    margin: 0;
    font-family: 'Fraunces', serif;
    font-size: clamp(1.65rem, 3vw, 2.25rem);
    line-height: 1.15;
    letter-spacing: 0.01em;
}

.topbar-time {
    margin: 0;
    color: var(--ink-2);
    font-size: 0.95rem;
    font-weight: 600;
    padding-top: 0.55rem;
}

.eyebrow {
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.11em;
    font-size: 0.72rem;
    font-weight: 700;
    color: #325269;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 0.95rem;
    align-items: stretch;
}

.hero-card {
    grid-column: span 12;
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    animation: panel-enter 500ms ease-out;
}

.hero-temp-wrap {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    margin-top: 0.7rem;
}

.hero-temp-value {
    margin: 0;
    font-family: 'Fraunces', serif;
    font-size: clamp(2.2rem, 9vw, 4.25rem);
    line-height: 1;
    color: var(--ink-1);
}

.hero-temp-value span {
    font-size: 0.48em;
    margin-left: 0.15em;
    color: var(--ink-2);
}

.hero-temp-date {
    margin: 0;
    font-size: 0.92rem;
    color: var(--ink-2);
    font-weight: 600;
}

.hero-delta {
    margin: 0.7rem 0 0;
    font-size: 0.9rem;
    font-weight: 700;
}

.hero-delta.is-up   { color: #c0532b; }
.hero-delta.is-down { color: #2f6db0; }
.hero-delta.is-flat { color: var(--ink-2); }

.stat-card {
    grid-column: span 12;
    padding: 1rem;
    animation: panel-enter 560ms ease-out;
}

.extremes-card {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.7rem;
}

.extremes-row {
    display: grid;
    grid-template-columns: 3.4rem 1fr 1fr;
    align-items: center;
    gap: 0.55rem;
}

.extremes-rowlabel {
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.74rem;
    font-weight: 700;
    line-height: 1.15;
    color: var(--ink-2);
}

.extremes-collabel {
    margin: 0;
    padding-left: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.11em;
    font-size: 0.72rem;
    font-weight: 700;
    color: #325269;
}

.extreme-item .stat-value {
    margin-top: 0;
}

.extreme-item {
    border-radius: 14px;
    padding: 0.75rem 0.85rem;
    background: rgba(255, 255, 255, 0.42);
    border: 1px solid rgba(255, 255, 255, 0.62);
}

.extreme-high {
    box-shadow: inset 0 0 0 1px rgba(230, 109, 65, 0.08);
}

.extreme-low {
    box-shadow: inset 0 0 0 1px rgba(68, 114, 196, 0.08);
}

.stat-value {
    margin: 0.48rem 0 0;
    font-size: clamp(1.25rem, 4vw, 2rem);
    font-weight: 700;
    color: var(--ink-1);
}

.stat-meta {
    margin: 0.2rem 0 0;
    color: var(--ink-2);
    font-size: 0.88rem;
    font-weight: 600;
}

.chart-card {
    grid-column: span 12;
    padding: 1rem;
    min-height: 360px;
    animation: panel-enter 620ms ease-out;
}

.chart-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 0.65rem;
}

.chart-subtitle {
    margin: 0;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--ink-2);
    background: var(--accent-soft);
    border-radius: 999px;
    padding: 0.25rem 0.65rem;
}

.chart-canvas-wrap {
    position: relative;
    height: 300px;
}

#history {
    width: 100% !important;
    height: 100% !important;
    min-height: 0;
    display: block;
}

@keyframes panel-enter {
    from {
        opacity: 0;
        transform: translateY(14px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* The cards play a one-time slide-up (panel-enter) on first page load. After an
   in-place refresh they are brand-new DOM nodes, so the browser would re-run
   that slide every time and the cards would bounce. Suppress it on refreshed
   content (#dashboard gains .refreshed after the first swap), so a refresh only
   changes the numbers in place and lets the charts do their own redraw. */
#dashboard.refreshed .hero-card,
#dashboard.refreshed .stat-card,
#dashboard.refreshed .chart-card {
    animation: none;
}

@media (min-width: 768px) {
    .weather-app {
        padding: 1.5rem 1.5rem 2.8rem;
    }

    .hero-card {
        grid-column: span 6;
        padding: 1.45rem;
    }

    .stat-card {
        grid-column: span 6;
    }

    .extremes-row {
        grid-template-columns: 5rem 1fr 1fr;
        gap: 0.7rem;
    }

    .chart-card {
        grid-column: span 12;
        padding: 1.2rem;
    }

    .chart-canvas-wrap {
        height: 340px;
    }
}

@media (min-width: 1120px) {
    .hero-card {
        grid-column: span 5;
    }

    .stat-card {
        grid-column: span 7;
    }

    .chart-card {
        grid-column: span 12;
    }

    .chart-canvas-wrap {
        height: 430px;
    }
}
/* --- Hero secondary stats (humidity / pressure) --- */
.hero-secondary {
    display: flex;
    gap: 1.5rem;
    margin-top: 1.1rem;
    padding-top: 1.1rem;
    border-top: 1px solid rgba(31, 88, 118, 0.12);
}

.hero-stat {
    flex: 1;
}

.hero-stat-label {
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.11em;
    font-size: 0.72rem;
    font-weight: 700;
    color: #325269;
}

.hero-stat-value {
    margin: 0.3rem 0 0;
    font-size: clamp(1.3rem, 5vw, 1.9rem);
    font-weight: 700;
    color: var(--ink-1);
}

.hero-stat-value span {
    font-size: 0.5em;
    margin-left: 0.2em;
    color: var(--ink-2);
}

.hero-stat-delta {
    margin: 0.35rem 0 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.7rem;
    font-size: 0.8rem;
    font-weight: 700;
}

.hero-stat-delta .is-up { color: #c0532b; }
.hero-stat-delta .is-down { color: #2f6db0; }
.hero-stat-delta .is-flat { color: var(--ink-2); }

/* --- Extremes: per-metric sections --- */
.extremes-title {
    margin: 0 0 0.5rem;
    font-family: 'Fraunces', serif;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--ink-1);
}

.extremes-metric + .extremes-metric {
    margin-top: 0.5rem;
    padding-top: 0.85rem;
    border-top: 1px solid rgba(31, 88, 118, 0.10);
}

.extremes-nodata {
    margin: 0.2rem 0 0.4rem;
    font-size: 0.85rem;
    color: var(--ink-2);
}

/* --- Compact extremes: period -> metric rows -> high/low columns --- */
.extremes-period + .extremes-period {
    margin-top: 0.55rem;
    padding-top: 0.85rem;
    border-top: 1px solid rgba(31, 88, 118, 0.10);
}

.ex-grid {
    display: grid;
    grid-template-columns: 5.6rem 1fr 1fr;
    gap: 0.4rem 0.5rem;
    align-items: center;
}

.ex-collabel {
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #325269;
    padding-left: 0.55rem;
}

.ex-rowlabel {
    font-size: 0.74rem;
    font-weight: 700;
    color: var(--ink-2);
    line-height: 1.1;
}

.ex-cell {
    border-radius: 10px;
    padding: 0.38rem 0.55rem;
    background: rgba(255, 255, 255, 0.42);
    border: 1px solid rgba(255, 255, 255, 0.62);
    display: flex;
    flex-direction: column;
}

.ex-high { box-shadow: inset 0 0 0 1px rgba(230, 109, 65, 0.10); }
.ex-low  { box-shadow: inset 0 0 0 1px rgba(68, 114, 196, 0.10); }

.ex-val {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--ink-1);
    line-height: 1.05;
}

.ex-time {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--ink-2);
    margin-top: 0.12rem;
}

/* --- Stale-data warning banner --- */
.alert-banner {
    margin: 0 0 1rem;
    padding: 0.85rem 1.15rem;
    border-radius: 16px;
    background: rgba(200, 60, 55, 0.12);
    border: 1px solid rgba(200, 60, 55, 0.38);
    color: #962522;
    font-weight: 700;
    font-size: 0.95rem;
    line-height: 1.4;
}

/* Amber variant: a fault the station is still trying to recover from by
   itself. Red is reserved for "recovery gave up, this needs you". */
.alert-banner.is-warning {
    background: rgba(190, 130, 30, 0.13);
    border-color: rgba(190, 130, 30, 0.42);
    color: #85570f;
}

/* Neutral variant: something already dealt with, kept on screen as a record
   rather than as an alarm. */
.alert-banner.is-info {
    background: rgba(31, 88, 118, 0.09);
    border-color: rgba(31, 88, 118, 0.30);
    color: #23576f;
}

/* --- Sensor recovery history box (sits under the sun/moon lines) --- */
/* Separator matching the one above the barometer, so the hero card keeps one
   consistent rhythm of hairline-divided sections. */
.hero-incidents {
    margin-top: 1.1rem;
    padding-top: 1.1rem;
    border-top: 1px solid rgba(31, 88, 118, 0.12);
    /* The hero card is a centred flex column: without this the box is shrunk
       below its content height and the list escapes the card. */
    flex: 0 0 auto;
}

.incident-box {
    margin: 0;
    /* The rounded border must clip its own scrolling list, whatever it holds. */
    overflow: hidden;
    padding: 0.8rem 0.95rem;
    font-size: 0.85rem;
    font-weight: 500;
}

.incident-title {
    margin: 0;
    font-weight: 700;
    font-size: 0.82rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.incident-summary {
    margin: 0.35rem 0 0;
    line-height: 1.4;
}

.incident-list {
    margin: 0.55rem 0 0;
    padding: 0;
    list-style: none;
    /* A long trail scrolls inside the box rather than stretching the card. */
    max-height: 11rem;
    overflow-y: auto;
}

.incident-item {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    align-items: baseline;
    padding: 0.22rem 0;
    border-top: 1px solid rgba(31, 88, 118, 0.14);
}

.incident-when {
    font-variant-numeric: tabular-nums;
    opacity: 0.75;
    min-width: 6.5rem;
}

.incident-what {
    font-weight: 700;
}

.incident-item.is-recovered .incident-what {
    font-weight: 500;
    opacity: 0.8;
}

.incident-vals {
    opacity: 0.7;
    font-size: 0.78rem;
}

.incident-concern {
    margin: 0.6rem 0 0;
    font-weight: 700;
    color: #8a4a12;
    line-height: 1.35;
}

.incident-clear {
    margin-top: 0.7rem;
    padding: 0.34rem 0.95rem;
    border-radius: 999px;
    border: 1px solid rgba(31, 88, 118, 0.38);
    background: rgba(255, 255, 255, 0.55);
    color: #23576f;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
}

.incident-clear:hover,
.incident-clear:focus-visible {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(31, 88, 118, 0.6);
}

.incident-clear[disabled] {
    opacity: 0.55;
    cursor: default;
}

/* --- Barometer outlook (hero) --- */
.hero-barometer {
    margin-top: 1.1rem;
    padding-top: 1.1rem;
    border-top: 1px solid rgba(31, 88, 118, 0.12);
}

.hero-baro-word {
    margin: 0.25rem 0 0;
    font-family: 'Fraunces', serif;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--ink-1);
}

.baro-trend {
    font-family: system-ui, sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    margin-left: 0.35rem;
    vertical-align: middle;
}

.baro-trend.is-up { color: #2f8f7f; }
.baro-trend.is-down { color: #c0532b; }
.baro-trend.is-flat { color: var(--ink-2); }

.hero-baro-forecast {
    margin: 0.2rem 0 0;
    font-family: system-ui, sans-serif;
    font-size: 0.9rem;
    font-style: italic;
    color: var(--ink-2);
}

.hero-astro {
    margin-top: 1.1rem;
    padding-top: 1.1rem;
    border-top: 1px solid rgba(31, 88, 118, 0.12);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.astro-lines {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    min-width: 0;
}

.astro-line {
    margin: 0;
    font-family: system-ui, sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--ink-2);
    font-variant-numeric: tabular-nums;
}

.astro-ico {
    display: inline-block;
    width: 1.5em;
    margin-right: 0.35rem;
    text-align: center;
    color: var(--accent);
}

.astro-sub {
    font-weight: 500;
    color: var(--ink-2);
    opacity: 0.8;
}

.astro-history-btn {
    flex: 0 0 auto;
    width: 2.2rem;
    height: 2.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    border: 1px solid rgba(31, 88, 118, 0.38);
    background: rgba(255, 255, 255, 0.55);
    color: #23576f;
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
}

.astro-history-btn:hover,
.astro-history-btn:focus-visible {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(31, 88, 118, 0.6);
}

/* --- Sun & Moon history modal --- */
.astro-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(10, 20, 35, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.astro-modal {
    width: min(560px, 100%);
    max-height: min(80vh, 640px);
    display: flex;
    flex-direction: column;
    padding: 1.1rem 1.2rem 1.3rem;
    background: rgba(244, 250, 255, 0.97);
}

.astro-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.6rem;
}

.astro-modal-head h2 {
    margin: 0;
    font-family: 'Fraunces', serif;
    font-size: 1.1rem;
    color: var(--ink-1);
}

.astro-modal-close {
    flex: 0 0 auto;
    border: none;
    background: transparent;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--ink-2);
    cursor: pointer;
    padding: 0.1rem 0.4rem;
}

.astro-modal-close:hover,
.astro-modal-close:focus-visible {
    color: var(--ink-1);
}

.astro-modal-body {
    overflow-y: auto;
}

.astro-modal-status {
    margin: 0.6rem 0;
    color: var(--ink-2);
    font-size: 0.9rem;
}

.astro-modal-table-wrap {
    overflow-x: auto;
}

.astro-modal-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.astro-modal-table th,
.astro-modal-table td {
    padding: 0.4rem 0.5rem;
    text-align: left;
    border-bottom: 1px solid rgba(31, 88, 118, 0.12);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.astro-modal-table th {
    color: var(--ink-2);
    font-weight: 700;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.astro-modal-table tr.is-today td {
    background: rgba(230, 109, 65, 0.1);
    font-weight: 700;
}

.astro-modal-moon-cell {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.astro-modal-moon {
    display: inline-block;
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
}

.astro-modal-moon svg {
    display: block;
}
