/* Wetterstation Niederweidbach – Mobile first */

/*
 * Farben und Flaechen kommen aus shared/css/tokens.css. Die alten Namen
 * bleiben als Verweis bestehen, damit der Rest der Datei unveraendert
 * weiterlaeuft - und die Seite dem hellen wie dem dunklen Design folgt.
 *
 * Die Messgroessen behalten ihre eigenen Farben: Temperatur orange, Regen
 * blau, Wind violett, Druck gruen. Im hellen Design sind sie kraeftiger,
 * damit sie auf weisser Flaeche lesbar bleiben.
 */
:root {
    --seiten-hintergrund: var(--c-page);
    --kopf-hintergrund: var(--c-card);

    --surface: var(--c-card);
    --surface-strong: var(--c-card-alt);
    --border: var(--c-border);

    --text: var(--c-text);
    --muted: var(--c-text-muted);
    --faint: var(--c-text-muted);

    --temp: #c2410c;
    --rain: #0369a1;
    --wind: #6d28d9;
    --press: #047857;
    --ok: var(--c-success);
    --warn: var(--c-warning);
    --danger: var(--c-danger);

    /* Zarte Schleier fuer Innenflaechen und Trennlinien - im hellen Design
       dunkel auf hell, im dunklen umgekehrt. */
    --schleier-1: rgba(0, 0, 0, 0.035);
    --schleier-2: rgba(0, 0, 0, 0.06);
    --schleier-linie: rgba(0, 0, 0, 0.10);

    --radius: var(--radius-lg);
    --radius-sm: 10px;

    --gap: 12px;
    --pad: 14px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --seiten-hintergrund: linear-gradient(175deg, #050a16 0%, #0d1526 60%, #0a1120 100%);
        --kopf-hintergrund: rgba(6, 11, 22, 0.82);

        --temp: #fb923c;
        --rain: #38bdf8;
        --wind: #a78bfa;
        --press: #34d399;

        --schleier-1: rgba(255, 255, 255, 0.055);
        --schleier-2: rgba(255, 255, 255, 0.085);
        --schleier-linie: rgba(255, 255, 255, 0.10);
    }
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--seiten-hintergrund);
    background-attachment: fixed;
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.45;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* Farbschleier im Hintergrund, ohne zusaetzliche Elemente im DOM */
body::before,
body::after {
    content: "";
    position: fixed;
    width: 60vmax;
    height: 60vmax;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.16;
    pointer-events: none;
    z-index: 0;
}

body::before {
    background: var(--rain);
    top: -25vmax;
    left: -20vmax;
}

body::after {
    background: #f97316;
    bottom: -30vmax;
    right: -20vmax;
}

/* ---------------------------------------------------------------- Kopf */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: calc(8px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-left)) 8px max(12px, env(safe-area-inset-right));
    background: var(--kopf-hintergrund);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}

.topbar__home,
.topbar__reload {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    text-decoration: none;
    cursor: pointer;
}

.topbar__home:active,
.topbar__reload:active {
    background: var(--surface-strong);
}

.topbar__title {
    flex: 1;
    min-width: 0;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
}

.topbar__title small {
    display: block;
    font-weight: 400;
    font-size: 12px;
    color: var(--muted);
}

.topbar__reload[data-busy="1"] svg {
    animation: spin 0.9s linear infinite;
}

.topbar__reload svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
}

/* --------------------------------------------------------------- Rahmen */

.wrap {
    position: relative;
    z-index: 1;
    max-width: 1180px;
    margin: 0 auto;
    padding: 14px max(12px, env(safe-area-inset-left)) calc(28px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-right));
}

.live {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 14px;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
}

.live__dot {
    width: 9px;
    height: 9px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--ok);
    box-shadow: 0 0 10px var(--ok);
    animation: pulse 2s infinite;
}

.live[data-state="stale"] .live__dot {
    background: var(--warn);
    box-shadow: 0 0 10px var(--warn);
}

.live[data-state="error"] .live__dot {
    background: var(--danger);
    box-shadow: 0 0 10px var(--danger);
    animation: none;
}

/* ------------------------------------------------------------- Zustaende */

.loading {
    padding: 60px 20px;
    text-align: center;
    color: var(--muted);
}

.spinner {
    width: 44px;
    height: 44px;
    margin: 0 auto 16px;
    border: 4px solid var(--schleier-linie);
    border-top-color: var(--rain);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.banner {
    margin-bottom: 14px;
    padding: 12px 14px;
    border: 1px solid var(--c-danger);
    border-radius: var(--radius-sm);
    background: var(--c-danger-soft);
    color: var(--c-danger);
    font-size: 14px;
}

.banner[hidden] {
    display: none;
}

/* --------------------------------------------------------------- Warnungen */

.alerts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}

.alerts:empty {
    display: none;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border: 1px solid currentColor;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
}

.chip span {
    color: var(--text);
    font-weight: 500;
}

.chip--danger { color: var(--danger); background: rgba(248, 113, 113, 0.12); }
.chip--warn   { color: var(--warn);   background: rgba(251, 191, 36, 0.12); }
.chip--info   { color: var(--rain);   background: rgba(56, 189, 248, 0.12); }
.chip--ok     { color: var(--ok);     background: rgba(74, 222, 128, 0.12); }

/* ------------------------------------------------------------------ Hero */

.hero {
    display: grid;
    gap: var(--gap);
    margin-bottom: 18px;
}

/* Grid- und Flex-Kinder duerfen nicht von ihrem Mindestinhalt aufgeblasen
   werden – sonst sprengen die grossen Zahlen auf schmalen Displays das Raster. */
.hero > *,
.hero__tiles > *,
.grid > * {
    min-width: 0;
}

.hero__main {
    min-width: 0;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: linear-gradient(150deg, rgba(251, 146, 60, 0.14), var(--surface) 55%);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.hero__temp {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 10px;
    font-size: clamp(42px, 13vw, 72px);
    font-weight: 700;
    line-height: 1.05;
    letter-spacing: -0.02em;
    color: var(--temp);
}

.hero__temp small {
    font-size: 0.34em;
    font-weight: 500;
    color: var(--muted);
    white-space: nowrap;
}

.hero__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    margin-top: 12px;
    color: var(--muted);
    font-size: 14px;
}

.hero__meta b {
    color: var(--text);
    font-weight: 600;
}

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

.tile {
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.tile__label {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.tile__value {
    margin-top: 6px;
    font-size: clamp(22px, 6.5vw, 30px);
    font-weight: 700;
    line-height: 1.1;
    word-break: break-word;
}

.tile__sub {
    margin-top: 4px;
    color: var(--faint);
    font-size: 12px;
}

.tile--rain  .tile__value { color: var(--rain); }
.tile--wind  .tile__value { color: var(--wind); }
.tile--press .tile__value { color: var(--press); }
.tile--fire  .tile__value { color: var(--ok); }

.tile--fire[data-active="1"] {
    border-color: rgba(248, 113, 113, 0.45);
    background: rgba(248, 113, 113, 0.12);
}

.tile--fire[data-active="1"] .tile__value {
    color: var(--danger);
}

/* --------------------------------------------------------------- Bereiche */

.card {
    margin-bottom: 16px;
    padding: var(--pad);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.card > h2 {
    margin: 0 0 12px;
    color: var(--rain);
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.card__note {
    margin: 12px 0 0;
    color: var(--faint);
    font-size: 12px;
    line-height: 1.5;
}

.card__note[hidden] {
    display: none;
}

/* 124px sorgt dafuer, dass auch auf 320-px-Displays noch zwei Spalten passen. */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 124px), 1fr));
    gap: 10px;
}

.stat {
    padding: 11px 12px;
    border: 1px solid var(--schleier-2);
    border-radius: var(--radius-sm);
    background: var(--schleier-1);
    min-width: 0;
}

.stat__title {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.3;
}

.stat__value {
    margin-top: 4px;
    font-size: clamp(18px, 5vw, 22px);
    font-weight: 700;
    line-height: 1.2;
    word-break: break-word;
}

.stat__sub {
    margin-top: 2px;
    color: var(--faint);
    font-size: 11px;
}

/* ------------------------------------------------------------------ Wind */

.wind {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}

.rose {
    position: relative;
    width: 132px;
    height: 132px;
    flex: 0 0 auto;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: radial-gradient(circle, var(--schleier-linie), rgba(255, 255, 255, 0.02) 70%);
}

.rose::after {
    content: "";
    position: absolute;
    inset: 22px;
    border: 1px dashed var(--schleier-linie);
    border-radius: 50%;
}

.rose__center {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--c-card);
    transform: translate(-50%, -50%);
    z-index: 2;
}

.rose__arrow {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 4px;
    height: 50px;
    border-radius: 999px;
    background: linear-gradient(180deg, var(--danger), #dc2626);
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.6);
    transform-origin: bottom center;
    transform: translate(-50%, -100%) rotate(0deg);
    transition: transform 0.6s ease;
}

.rose__arrow::before {
    content: "";
    position: absolute;
    top: -11px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 14px solid var(--danger);
}

.rose__dir {
    position: absolute;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.rose__dir--n { top: 6px;  left: 50%; transform: translateX(-50%); }
.rose__dir--o { right: 8px; top: 50%; transform: translateY(-50%); }
.rose__dir--s { bottom: 6px; left: 50%; transform: translateX(-50%); }
.rose__dir--w { left: 8px;  top: 50%; transform: translateY(-50%); }

.wind__facts {
    min-width: 0;
}

.wind__speed {
    font-size: clamp(26px, 8vw, 34px);
    font-weight: 700;
    line-height: 1.1;
    color: var(--wind);
}

.wind__line {
    margin-top: 4px;
    color: var(--muted);
    font-size: 13px;
}

.wind__line b {
    color: var(--text);
}

/* -------------------------------------------------------------- Diagramme */

.range {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--schleier-1);
}

.range button {
    flex: 1;
    min-height: 46px;
    padding: 4px 8px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.15;
    cursor: pointer;
}

/* Datenmenge am Schalter – die Station liefert kein gzip, 30 Tage sind 4,5 MB. */
.range button small {
    display: block;
    margin-top: 2px;
    font-size: 10px;
    font-weight: 400;
    color: var(--faint);
}

.range button[aria-pressed="true"] {
    background: var(--surface-strong);
    color: var(--text);
}

.chart {
    position: relative;
    height: 230px;
    margin-bottom: 6px;
}

.chart canvas {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
}

.chart-title {
    margin: 18px 0 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.chart-title:first-of-type {
    margin-top: 0;
}

.charts[data-busy="1"] {
    opacity: 0.45;
    pointer-events: none;
}

.foot {
    margin-top: 22px;
    color: var(--faint);
    font-size: 12px;
    line-height: 1.6;
    text-align: center;
}

/* ------------------------------------------------------------ Animationen */

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

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.35; transform: scale(1.25); }
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}

/* --------------------------------------------------------- Groessere Displays */

@media (min-width: 600px) {

    :root {
        --gap: 14px;
        --pad: 20px;
        --radius: 22px;
    }

    .wrap {
        padding-top: 20px;
    }

    .topbar__title {
        font-size: 17px;
    }

    .hero {
        grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
        align-items: stretch;
    }

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

    .hero__main {
        padding: 24px;
    }

    .grid {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr));
        gap: 12px;
    }

    .rose {
        width: 160px;
        height: 160px;
    }

    .rose__arrow {
        height: 62px;
    }

    .chart {
        height: 280px;
    }
}

@media (min-width: 960px) {

    .hero {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
    }

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

    .card > h2 {
        font-size: 16px;
    }

    .chart {
        height: 320px;
    }

    .range {
        max-width: 420px;
    }
}
