/* Base reset and typography */
:root {
    /* Semantic color tokens (Apple system style, light by default) */
    --bg: #F2F2F7;          /* systemGroupedBackground (light) */
    --surface: #FFFFFF;     /* systemBackground (card) */
    --text: #000000;        /* label */
    --muted: rgba(60, 60, 67, 0.6); /* secondaryLabel (light) */
    /* Accent/status colors */
    --systemBlue: #0A84FF;    /* Apple systemBlue */
    --systemYellow: #FFD60A;  /* Apple systemYellow */
    --systemGreen: #34C759;   /* Apple systemGreen */
    --systemOrange: #FF9F0A;  /* Apple systemOrange */
    --systemRed: #FF3B30;     /* Apple systemRed */
    --systemPurple: #AF52DE;  /* Apple systemPurple */

    /* Ink (readable) text variants for light mode */
    --inkBlue: color-mix(in oklab, var(--systemBlue) 74%, black);
    --inkGreen: color-mix(in oklab, var(--systemGreen) 75%, black);
    --inkYellow: color-mix(in oklab, var(--systemYellow) 68%, black);
    --inkOrange: color-mix(in oklab, var(--systemOrange) 74%, black);
    --inkRed: color-mix(in oklab, var(--systemRed) 74%, black);
    --inkPurple: color-mix(in oklab, var(--systemPurple) 75%, black);
    color-scheme: light dark; /* native form control theming */
}

/* Auto dark mode if user prefers */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;            /* systemGroupedBackground (dark) */
    --surface: #1C1C1E;       /* systemBackground (card, dark) */
    --text: #FFFFFF;          /* label */
    --muted: rgba(235, 235, 245, 0.6); /* secondaryLabel (dark) */
  }
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* Prevent iOS Safari from inflating text sizes (notably in iPhone landscape) */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /* Ensure root background matches body so iOS Safari doesn't show white chrome/overscroll */
    background: var(--bg);
}

header,
footer {
        padding: 0.75rem 1rem;
        text-align: center;
}

/* Header layout with flag on the left */
header {
    display: grid;
    grid-template-columns: auto 1fr auto; /* flag | title | clock */
    gap: 0.5rem;
    align-items: center;
}

.header-flag {
    width: 44px;
    height: auto;
    max-width: none; /* override global img width */
    justify-self: start;
}

.header-clock {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.5px;
    color: var(--muted);
    justify-self: end;
}

h1 {
    margin: 0.25rem 0 0;
    font-size: clamp(1.25rem, 2.5vw, 1.75rem);
}

/* Layout: stack by default (mobile-first) */
main {
    display: grid;
    grid-template-columns: 1fr; /* 1 column on small screens */
    grid-template-areas:
        "weather"
        "schedule"
        "news";
    gap: 1rem;
    padding: 0 1rem;
    align-items: start;
}

section {
  background: var(--surface);
  border-radius: 1rem;
  padding: 0.75rem;
    min-width: 0; /* prevent overflow in grid items */
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

/* Map sections to grid areas */
section#weather { grid-area: weather; }
section#schedule { grid-area: schedule; }
section#news { grid-area: news; }

/* Make embeds responsive */
img,
iframe,
video {
    max-width: 100%;
    width: 100%;
    height: auto;
}

/* Vessel map container sizing */
#vessel-map {
    margin-top: 0.75rem;
    /* Default height similar to requested 300px on mobile */
    height: 300px;
}
#weather-map {
    /* Radar map container */
    height: 300px;
    border-radius: 0.5rem;
    overflow: hidden;
    position: relative;
}
@media (min-width: 1024px) {
    #weather-map { height: 100%; margin-top: 0; }
}
#weather-map.spinner::after {
    content: "";
    box-sizing: border-box;
    position: absolute;
    top: 50%; left: 50%;
    width: 48px; height: 48px;
    margin: -24px 0 0 -24px;
    border-radius: 50%;
    border: 6px solid rgba(180,180,180,.9);
    border-top-color: rgba(0,0,0,.9);
    animation: spinner 0.7s linear infinite;
}
@keyframes spinner { to { transform: rotate(360deg); } }

/* Frame selector styling (exactly as in sample) */
/* Ensure our control styling wins over OpenLayers defaults (loaded after) */
.ol-control.frame-selector {
    left: 25px;
    bottom: 25px;
    background-color: #000000aa;
    padding: 6px;
}
.ol-control.frame-selector h3 {
    color: #eeeeee;
    font-size: 1rem;
    margin: 0;
    margin-top: 0;
    margin-bottom: 0;
    text-align: center;
}
.ol-control.frame-selector img {
    /* Override global img rules so icon keeps natural aspect ratio */
    width: auto;
    max-width: none;
    height: 1rem;
    vertical-align: middle;
    cursor: pointer;
    margin-right: .5rem;
    margin-left: .25rem;
}
/* Align slider with the icon baseline */
.ol-control.frame-selector input[type="range"] { vertical-align: middle; }
#vessel-map iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    border-radius: 0.5rem;
}

/* Desktop-only: fill viewport and avoid page scrolling */
/* Wide screens: three columns, one section per column */
@media (min-width: 1024px) {
    body {
        min-height: 100svh;
        display: grid;
        grid-template-rows: auto 1fr auto; /* header | main | footer */
        overflow: hidden; /* prevent page scroll */
    }

    main {
        height: 100%;
        align-items: stretch;
        min-height: 0;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        grid-template-areas: "schedule weather news";
        gap: 1.25rem;
        padding: 0 1.25rem;
    }

    section {
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden; /* manage overflow inside sections */
    }

    /* Desktop: image gets fixed 40% of the news section; text uses remaining space */
    /* Make the news article itself a flex column that fills the section */
    .news-item {
        display: flex;
        flex-direction: column;
        flex: 1 1 auto;
        min-height: 0;
    }
    .news-image {
        flex: 0 0 40%;
        min-height: 0;
        overflow: hidden;    /* crop overflow */
        margin-top: 0;       /* avoid margin affecting the 40% allocation */
    }
    /* Ensure the actual image covers and crops within the 40% slot */
    .news-image img,
    img.news-image {
        display: block;
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
    
    /* The container must have height; otherwise the absolutely positioned
       news-content will cause it to collapse to 0 and hide all text */
    .scroll-container {
        position: relative;
        overflow: hidden;     /* crop animated text */
        flex: 1 1 auto;       /* take remaining space below image */
        min-height: 0;        /* allow flex child to shrink as needed */
        container-type: size; /* enable cqh units for scroll distance */
        border-radius: 0.5rem;
    }

    /* Desktop: keep header title centered visually */
    header { grid-template-columns: auto 1fr auto; }
    header h1 { grid-column: 2; justify-self: center; }

    /* Default (no scrolling): place text statically so it's visible when it fits */
    .scroll-container .news-content {
        position: static;
        will-change: auto;
        animation: none;
    }

    /* Only when scrolling is enabled via class */
    .scroll-container.is-scrolling .news-content {
        position: absolute;
        top: 100%; /* start just below the container */
        left: 0;
        right: 0;
        width: 100%;
        display: block;
        will-change: transform; /* smoother on many browsers */
    }

    @keyframes scroll-up {
        0%   { transform: translateY(0); }
        100% { transform: translateY(calc(-100% - 100cqh)); }
    }

    /* Water section: push tiles to the bottom */
    section#weather .water-container { margin-top: 0; margin-bottom: 0.5rem; }

    /* Schedule column: keep Events compact; push large gap below Today down to the vessel map */
    section#schedule #events { flex: 0 0 auto; }
    /* On desktop, let the vessel map fill remaining vertical space */
    section#schedule #vessel-map {
        margin-top: 0.75rem; /* keep standard spacing from previous block */
        height: auto;        /* override fixed mobile height */
        min-height: 0;       /* allow flex sizing without overflow */
        flex: 1 1 auto;      /* take the remaining space in the column */
    }
    /* Ensure the vessel-info container itself can grow and hosts a flex column */
    section#schedule #vessel-info {
        display: flex;
        flex-direction: column;
        flex: 1 1 auto;
        min-height: 0; /* allow children to size/shrink correctly */
    }
    /* Keep a smaller gap below the Schiffe title and let the map flex to fill */
    section#schedule #vessel-info .vessel-title + #vessel-map {
        margin-top: 0.5rem; /* overrides the generic 0.75rem above */
        flex: 1 1 auto;
    }
    /* Keep a smaller gap below the Schiffe title even on desktop */
    section#schedule .vessel-title + #vessel-map {
        margin-top: 0.5rem;
    }
}

/* Tweak spacing for inner blocks */
section > * + *,
section .scroll-container.is-scrolling {
    margin-top: 0.75rem;
}

/* Match spacing below "Veranstaltungen" directly under the Wetter headline */
section#weather > .weather-title + * { margin-top: 0; }
/* Also apply when alerts are hidden and the next block becomes the first sibling */
section#weather #weather-alerts[hidden] + * { margin-top: 0 !important; }
/* When there are no alerts, don't reserve space for the alerts container */
section#weather #weather-alerts[hidden] { display: none !important; }

/* News section */
.news-title {
    font-size: 1.25rem;
    font-weight: bold;
    /* Match spacing below "Veranstaltungen" */
    margin: 0 0 0.5rem 0;
}

.news-date {
    font-size: 0.875rem;
    color: var(--muted);
}

.news-content {
    margin-top: 0.5rem;
}

.news-image {
    margin-top: 0.5rem;
    max-width: 100%;
    border-radius: 0.5rem;
}

/* Footer styling */
footer {
    display: flex;
    flex-wrap: wrap;                 /* allow wrapping when space is tight */
    gap: 0.5rem 1rem;                /* row and column gaps */
    align-items: center;
    justify-content: space-between;  /* evenly distribute on a single line */
    color: var(--muted);
}

/* Items should size to content and not stretch */
footer > * { flex: 0 1 auto; }

footer a {
    color: inherit;
    text-decoration: none; /* no text decorations */
}

footer a:hover {
    opacity: 0.85;
}

/* Events styling */
#events { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
#events-list { flex: 1 1 auto; min-height: 0; display: grid; gap: 0.5rem; align-content: start; }
/* Heute section uses same heading style */
#today { flex: 0 0 auto; display: flex; flex-direction: column; }
#today-list.today-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
}
/* Legend layout under Heute */
.today-legend { margin-top: 0.5rem; display: flex; flex-wrap: wrap; gap: 0.5rem; }
/* Make legend chips smaller variants of event chips */
.legend-chip { padding: 0.35rem 0.5rem 0.35rem 0.6rem; }
.legend-chip::before { top: 0.35rem; bottom: 0.35rem; }
.legend-chip .event-title { font-weight: 600; }
@media (max-width: 520px) {
    #today-list.today-grid { grid-template-columns: 1fr; }
}

.events-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 0.5rem 0;
}

.weather-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

/* Water title: match other section titles */
.water-title {
    font-size: 1.1rem;
    font-weight: 600;
    /* Spacing inside .water-container is handled by grid gap */
    margin: 0;
}

/* Schiffe title: match other headlines, with larger space above and smaller below */
.vessel-title {
    font-size: 1.1rem;
    font-weight: 600;
    /* Larger gap above the title, small gap below */
    margin: 1rem 0 0;
}
/* Ensure a smaller gap between the title and the map than the default */
.vessel-title + #vessel-map {
    margin-top: 0.5rem;
}

.event-chip {
    display: grid;
    grid-template-columns: 0.25rem 1fr;
    grid-auto-rows: auto;
    gap: 0.25rem 0.5rem;
    align-items: start;
    padding: 0.6rem 0.6rem 0.6rem 0.6rem;
    background: color-mix(in oklab, var(--systemGreen) 12%, transparent);
    border-radius: 0.5rem;
    position: relative;
    overflow: hidden; /* clip the bar to rounded corners */
    /* Tighter line height specifically for event text */
    --event-line-height: 1.15;
}
.event-chip::before {
    content: '';
    position: absolute;
    left: 0.6rem;   /* align with inner padding */
    top: 0.6rem;    /* match top padding */
    bottom: 0.6rem; /* match bottom padding */
    width: 0.25rem;
    background: var(--systemGreen);
    border-radius: 0.25rem;
}
.event-chip > * { grid-column: 2; }
.today-chip { padding-right: 0.75rem; }
/* Single-line clamp with ellipsis for long titles */
.line-clamp-1 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.event-title {
    /* Darker Apple green for title in light mode */
    color: color-mix(in oklab, var(--systemGreen) 75%, black);
    font-weight: 700;
    line-height: var(--event-line-height);
}
.event-date {
    color: var(--systemGreen);
    opacity: 0.95;
    line-height: var(--event-line-height);
}
@media (prefers-color-scheme: dark) {
    /* Keep standard Apple green in dark mode for contrast */
    .event-title { color: var(--systemGreen); }
    .event-date { color: var(--systemGreen); opacity: 0.9; }
}
.event-time {
    color: var(--systemGreen);
    opacity: 0.9;
    line-height: var(--event-line-height);
}
@media (prefers-color-scheme: dark) {
    .event-time { color: var(--systemGreen); opacity: 0.85; }
}
.event-empty { color: var(--muted); }

/* Per-calendar color accents for Heute chips */
.today-chip.color-blue::before { background: #0A84FF; }
.today-chip.color-yellow::before { background: #FFD60A; }
.today-chip.color-orange::before { background: #FF9F0A; }
.today-chip.color-blue { background: color-mix(in oklab, #0A84FF 12%, transparent); }
.today-chip.color-yellow { background: color-mix(in oklab, #FFD60A 18%, transparent); }
.today-chip.color-orange { background: color-mix(in oklab, #FF9F0A 16%, transparent); }

/* Legend chips share the same color palette */
/* Legend color variants reuse today-chip palette */
.legend-chip.color-blue { background: color-mix(in oklab, #0A84FF 12%, transparent); }
.legend-chip.color-yellow { background: color-mix(in oklab, #FFD60A 18%, transparent); }
.legend-chip.color-orange { background: color-mix(in oklab, #FF9F0A 16%, transparent); }
.legend-chip.color-blue::before { background: #0A84FF; }
.legend-chip.color-yellow::before { background: #FFD60A; }
.legend-chip.color-orange::before { background: #FF9F0A; }
.legend-chip.color-blue .event-title,
.legend-chip.color-yellow .event-title,
.legend-chip.color-orange .event-title { color: inherit; }

/* Match Heute text colors to each calendar accent */
.today-chip.color-blue .event-title,
.today-chip.color-blue .event-time,
.today-chip.color-blue .event-date { color: #0A84FF; }

.today-chip.color-yellow .event-title,
.today-chip.color-yellow .event-time,
.today-chip.color-yellow .event-date { color: #FFD60A; }

.today-chip.color-orange .event-title,
.today-chip.color-orange .event-time,
.today-chip.color-orange .event-date { color: #FF9F0A; }

/* Light mode: use darker, more readable variants for event text */
@media (prefers-color-scheme: light) {
    /* Blue */
    .today-chip.color-blue .event-title {
        color: var(--inkBlue);
    }
    .today-chip.color-blue .event-time,
    .today-chip.color-blue .event-date {
        color: var(--systemBlue);
    }

    /* Green */
    .today-chip.color-green .event-title {
        color: var(--inkGreen);
    }
    .today-chip.color-green .event-time,
    .today-chip.color-green .event-date {
        color: var(--systemGreen);
    }

    /* Yellow */
    .today-chip.color-yellow .event-title,
    .today-chip.color-yellow .event-time,
    .today-chip.color-yellow .event-date {
        color: var(--inkYellow);
    }

    /* Amber/Orange */
    .today-chip.color-amber .event-title,
    .today-chip.color-orange .event-title {
        color: var(--inkOrange);
    }
    .today-chip.color-amber .event-time,
    .today-chip.color-amber .event-date,
    .today-chip.color-orange .event-time,
    .today-chip.color-orange .event-date {
        color: var(--systemOrange);
    }

    /* Red */
    .today-chip.color-red .event-title {
        color: var(--inkRed);
    }
    .today-chip.color-red .event-time,
    .today-chip.color-red .event-date {
        color: var(--systemRed);
    }
}

/* Water warnings + measurements wrapper */
.water-container { display: grid; gap: 0.75rem; }
.water-warning.is-amber,
.water-warning.is-red {
    /* Keep container neutral when items provide their own color */
    background: none;
    border: 0;
    color: inherit;
}

/* Warning list styling */
.water-warning-list {
    list-style: none;
    margin: 0;
    padding-left: 0;
    display: grid;
    gap: 0.25rem;
}
.water-warning-item {
    line-height: 1.25;
    padding: 0.375rem 0.5rem;
    border-radius: 0.375rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: bold;
}
.water-warning-item.red {
    background: color-mix(in oklab, var(--systemRed) 18%, transparent);
    color: var(--systemRed);
}
.water-warning-item.amber {
    background: color-mix(in oklab, var(--systemOrange) 18%, transparent);
    color: var(--systemOrange);
}

/* Warning icon (inherits severity color) */
.water-warning-icon {
    width: 1em;
    height: 1em;
    flex: 0 0 auto;
    background-color: currentColor;
    -webkit-mask: url('img/warning.svg') no-repeat center / contain;
    mask: url('img/warning.svg') no-repeat center / contain;
}

/* Water section: three tiles side-by-side */
.water-measurements { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; min-height: 0; }
.water-measurements > div {
    min-width: 0;
    display: flex;
    padding: 0.5rem;
    border-radius: 0.5rem;
    overflow: hidden;
}

/* Sun cards: single tile (Sunrise/Sunset) */
#weather-sun {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    align-items: stretch;
}
#weather-sun > div {
    min-width: 0;
    display: flex;
    padding: 0.5rem;
    border-radius: 0.5rem;
    overflow: hidden;
}
/* No responsive override needed; remains single-column */

/* Sunrise/Sunset compact tile */
.sun-tile {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between; /* sunrise left, sunset right */
    gap: 0; /* no extra gap; space-between handles spacing */
    flex-direction: row;
    flex-wrap: nowrap;
}
.sun-block {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
/* Prevent overflow inside each block */
.sun-block { flex: 0 0 auto; min-width: 0; white-space: nowrap; }
.sun-text { min-width: 0; }
.sun-icon {
    display: inline-block;
    width: 3em;  /* scale with text */
    height: 3em;
    background-color: currentColor;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-position: center;
    mask-position: center;
}
.sun-text {
    display: flex;
    flex-direction: column;
    text-align: right;
    align-items: flex-end;
}
.sun-time-main {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    font-size: clamp(1.1rem, 3.4vw, 1.3rem);
    /* Use inherited accent (ink in light via container override) */
    color: currentColor;
}
.sun-time-civil {
    font-variant-numeric: tabular-nums;
    color: currentColor; /* colored in system color (container accent) */
    opacity: 0.92;
}

/* Dark mode: align sun civil time colors with water tile relative time */
@media (prefers-color-scheme: dark) {
    #weather-sun > div.bg-green .sun-time-civil { color: color-mix(in oklab, var(--systemGreen) 75%, black); }
    #weather-sun > div.bg-amber .sun-time-civil { color: color-mix(in oklab, var(--systemOrange) 78%, black); }
    #weather-sun > div.bg-red   .sun-time-civil { color: color-mix(in oklab, var(--systemRed) 78%, black); }
    #weather-sun > div.bg-yellow .sun-time-civil { color: color-mix(in oklab, var(--systemYellow) 80%, black); }
}

/* Make the sun tile inherit the same accent text color rules as water tiles */
#weather-sun > div.bg-green { color: var(--systemGreen); }
#weather-sun > div.bg-amber { color: var(--systemOrange); }
#weather-sun > div.bg-red   { color: var(--systemRed); }
#weather-sun > div.bg-yellow { color: var(--systemYellow); }

@media (prefers-color-scheme: light) {
    #weather-sun > div.bg-green { color: var(--inkGreen); }
    #weather-sun > div.bg-amber { color: var(--inkOrange); }
    #weather-sun > div.bg-red   { color: var(--inkRed); }
    #weather-sun > div.bg-yellow { color: var(--inkYellow); }

    /* Civil times use vivid system color in light mode for contrast */
    #weather-sun > div.bg-green .sun-time-civil { color: var(--systemGreen); }
    #weather-sun > div.bg-amber .sun-time-civil { color: var(--systemOrange); }
    #weather-sun > div.bg-red   .sun-time-civil { color: var(--systemRed); }
    #weather-sun > div.bg-yellow .sun-time-civil { color: var(--systemYellow); }
}

/* Water tiles layout and typography */
.water-measurements > div { align-items: stretch; }
/* Translucent backgrounds for water tiles (match calendar chip style) */
.water-measurements > div.bg-green { background: color-mix(in oklab, var(--systemGreen) 18%, transparent); }
.water-measurements > div.bg-amber { background: color-mix(in oklab, var(--systemOrange) 20%, transparent); }
.water-measurements > div.bg-red   { background: color-mix(in oklab, var(--systemRed) 20%, transparent); }
.water-measurements > div.bg-yellow { background: color-mix(in oklab, var(--systemYellow) 22%, transparent); }

/* Allow these backgrounds on #weather-sun children as well */
#weather-sun > div.bg-green { background: color-mix(in oklab, var(--systemGreen) 18%, transparent); }
#weather-sun > div.bg-amber { background: color-mix(in oklab, var(--systemOrange) 20%, transparent); }
#weather-sun > div.bg-red   { background: color-mix(in oklab, var(--systemRed) 20%, transparent); }
#weather-sun > div.bg-yellow { background: color-mix(in oklab, var(--systemYellow) 22%, transparent); }
/* Avoid long-word overflow in water content */
.water-station,
.water-unit,
.water-row { min-width: 0; }

.water-tile {
    display: grid;
    grid-template-rows: 1.6em auto; /* station (1 line) | value */
    gap: 0.25rem;
    width: 100%;
    min-width: 0; /* allow wrapping */
}
.water-station {
    font-weight: 600;
    color: var(--muted);
    /* Single-line, no wrap with ellipsis */
    min-width: 0; /* ensure ellipsis works inside grid/flex */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.water-row {
    display: flex;
    gap: 0.35rem;
    align-items: baseline;
    white-space: nowrap; /* keep single line for alignment */
    overflow: hidden;
    min-width: 0;
    /* Share value size with icon so they stay proportionate */
    --water-value-size: clamp(1.25rem, 3.5vw, 1.6rem);
}
.water-right { display: inline-flex; align-items: baseline; gap: 0.35rem; }
.water-value {
    font-size: var(--water-value-size);
    line-height: 1;
    white-space: nowrap;
    font-weight: bold;
}
.water-spacer { flex: 1 1 auto; min-width: 0.25rem; }
/* Icon: override global img width and scale with value size */
.water-row .water-icon {
    display: inline-block;
    height: calc(var(--water-value-size) * 1.1);
    width: calc(var(--water-value-size) * 1.1);
    flex: 0 0 auto;
    background-color: currentColor; /* icon adopts text/accent color */
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-position: center;
    mask-position: center;
}
.water-unit {
    opacity: 0.9;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Mobile: stack tiles into separate rows */
@media (max-width: 400px) {
    .water-measurements { grid-template-columns: 1fr; gap: 0.6rem; }
    .water-measurements > div { padding: 0.6rem; }
    .water-tile { gap: 0.15rem; grid-template-rows: 1.5em auto; }
    .water-row { gap: 0.25rem; }
}

/* Accent-colored text inside water tiles (match status color) */
.water-measurements > div.bg-green { color: var(--systemGreen); }
.water-measurements > div.bg-amber { color: var(--systemOrange); }
.water-measurements > div.bg-red   { color: var(--systemRed); }
.water-measurements > div.bg-yellow { color: var(--systemYellow); }

/* Make station and series full accent, not subtle */
.water-measurements > div.bg-green .water-station { color: var(--systemGreen); }
.water-measurements > div.bg-amber .water-station { color: var(--systemOrange); }
.water-measurements > div.bg-red .water-station { color: var(--systemRed); }
.water-measurements > div.bg-yellow .water-station { color: var(--systemYellow); }

/* sun tile doesn't use water-* labels */

/* Light mode: use darker ink variants for better readability on light surfaces */
@media (prefers-color-scheme: light) {
    /* Water tiles (value/unit/icon inherit from container color) */
    .water-measurements > div.bg-green { color: var(--inkGreen); }
    .water-measurements > div.bg-amber { color: var(--inkOrange); }
    .water-measurements > div.bg-red   { color: var(--inkRed); }
    .water-measurements > div.bg-yellow { color: var(--inkYellow); }

    /* (deduped above) */

    /* Station headings within tiles */
    .water-measurements > div.bg-green .water-station { color: var(--inkGreen); }
    .water-measurements > div.bg-amber .water-station { color: var(--inkOrange); }
    .water-measurements > div.bg-red .water-station { color: var(--inkRed); }
    .water-measurements > div.bg-yellow .water-station { color: var(--inkYellow); }

    /* Warning messages list */
    .water-warning-item.red { color: var(--inkRed); }
    .water-warning-item.amber { color: var(--inkOrange); }
}

/* Weather Alerts */
#weather-alerts { display: grid; gap: 0.5rem; }
.alert-card {
    border-radius: 0.5rem;
    padding: 0.6rem;
    background-clip: padding-box;
}
/* Alert background colors (translucent) */
.alert-card.bg-yellow { background: color-mix(in oklab, var(--systemYellow) 22%, transparent); }
.alert-card.bg-amber  { background: color-mix(in oklab, var(--systemOrange) 20%, transparent); }
.alert-card.bg-red    { background: color-mix(in oklab, var(--systemRed) 20%, transparent); }
.alert-card.bg-purple { background: color-mix(in oklab, var(--systemPurple) 20%, transparent); }
.alert-card.bg-gray   { background: color-mix(in oklab, var(--muted) 18%, transparent); }

/* Alert headline row */
.alert-head {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.alert-icon {
    width: 1.1em;
    height: 1.1em;
    flex: 0 0 auto;
    background-color: currentColor;
    -webkit-mask: url('img/warning.svg') no-repeat center / contain;
    mask: url('img/warning.svg') no-repeat center / contain;
}
.alert-headline { font-weight: 800; }
.alert-desc { margin-top: 0.25rem; line-height: 1.25; white-space: pre-wrap; font-size: small; }

/* Alerts: main text inherits accent like water tiles */
.alert-card.bg-yellow { color: var(--systemYellow); }
.alert-card.bg-amber  { color: var(--systemOrange); }
.alert-card.bg-red    { color: var(--systemRed); }
.alert-card.bg-purple { color: var(--systemPurple); }
.alert-card.bg-gray   { color: var(--muted); }

/* Alert description tinting like water-time secondary lines (dark/default) */
.alert-card.bg-yellow .alert-desc { color: color-mix(in oklab, var(--systemYellow) 80%, black); }
.alert-card.bg-amber  .alert-desc { color: color-mix(in oklab, var(--systemOrange) 78%, black); }
.alert-card.bg-red    .alert-desc { color: color-mix(in oklab, var(--systemRed) 78%, black); }
.alert-card.bg-purple .alert-desc { color: color-mix(in oklab, var(--systemPurple) 78%, black); }
.alert-card.bg-gray   .alert-desc { color: var(--muted); }

@media (prefers-color-scheme: light) {
    /* Use darker ink variants for main text in light mode */
    .alert-card.bg-yellow { color: var(--inkYellow); }
    .alert-card.bg-amber  { color: var(--inkOrange); }
    .alert-card.bg-red    { color: var(--inkRed); }
    .alert-card.bg-purple { color: var(--inkPurple); }
    .alert-card.bg-gray   { color: var(--muted); }
    /* Civil/relative-style vivid colors for descriptions in light mode */
    .alert-card.bg-yellow .alert-desc { color: var(--inkYellow); }
    .alert-card.bg-amber  .alert-desc { color: var(--systemOrange); }
    .alert-card.bg-red    .alert-desc { color: var(--systemRed); }
    .alert-card.bg-purple .alert-desc { color: var(--systemPurple); }
    .alert-card.bg-gray   .alert-desc { color: var(--muted); }
}

/* Current weather card */
#weather-current { margin-top: 0.5rem; margin-bottom: 0.75rem; }
.weather-current-card {
    display: grid;
    grid-template-columns: 1fr auto; /* left content | big condition icon */
    align-items: center;
    gap: 0.5rem 0.75rem;
    padding: 0.75rem;
    border-radius: 0.5rem;
    background: var(--systemBlue); /* solid blue background (fallback) */
    color: white;         /* always white text */
    position: relative;   /* containing block for bg image */
    overflow: hidden;     /* crop bg image to card (including rounded corners) */
}
/* Apply drop shadows to everything inside the current weather card */
.weather-current-card * {
    /* subtle text depth on white text */
    text-shadow: 0 1px 2px rgba(0,0,0,0.28);
}
.weather-current-card .wc-bg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    /* Start with a reasonable default; JS will size to max(width,height) */
    width: 100%;
    height: auto;
    pointer-events: none; /* don't block interactions */
    z-index: 0; /* behind content */
}
.weather-current-card .wc-main,
.weather-current-card .wc-icon,
.weather-current-card .wc-header,
.weather-current-card .wc-details,
.weather-current-card .wc-temp { position: relative; z-index: 1; }
.weather-current-card img,
.weather-current-card svg {
    /* shape-aware shadow for icons/images */
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.25));
}
.weather-current-card .wc-bg { filter: none; }
.weather-current-card .wc-icon {
    width: auto;
    height: 3rem;
    display: block;
}
.weather-current-card .wc-main { display: grid; gap: 0.5rem; }
.wc-header { justify-content: space-between; display: flex; }
.wc-temp {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}
.wc-temp-icon {
    width: auto;
    height: 3rem;
}
.wc-temp-value {
    font-size: 3rem;
    font-weight: 600;
    line-height: 1;
}
.wc-temp-unit { font-size: 3rem; font-weight: 500; opacity: 0.8;}
.wc-details {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
     /* Responsive column gap that scales with viewport and is always wider
         than the internal icon→value gap used in .wc-detail */
     --wc-inner-gap: 0.35rem; /* shared with .wc-detail */
     row-gap: 0.5rem;
     column-gap: max(calc(var(--wc-inner-gap) + 0.5rem), clamp(1rem, 8vw, 12rem));
}
.wc-detail {
    display: grid;
    /* Fixed icon column so icons can be centered and vertically align per column */
    grid-template-columns: 1.6rem 1fr auto; /* icon (fixed) | value | unit */
    align-items: center;
    /* Use shared inner gap with a safe fallback */
    gap: var(--wc-inner-gap, 0.35rem);
}
.wc-detail-icon { height: 1rem; width: auto; display: block; justify-self: center; }
.wc-detail-value {
  font-weight: 700;
  text-align: right; /* align value text to the right edge of the middle column */
}
.wc-detail-unit { opacity: 0.9; }

/* PWA / Standalone specific adjustments */
html.standalone, html.standalone body {
  height: 100%;
  min-height: 100dvh; /* modern dynamic viewport */
  background-color: var(--bg);
}
html.standalone body {
    /* Use safe-area insets for iOS notch */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
}
html.standalone body header { padding-top: calc(0.75rem + env(safe-area-inset-top)); }
html.standalone body footer { padding-bottom: calc(0.75rem + env(safe-area-inset-bottom)); }

/* Prevent overscroll bounce revealing address bar area when installed */
html.standalone body { overscroll-behavior: contain; }

/* Hide any default scrollbars for a more app-like feel on iOS (content sections still scroll internally) */
html.standalone body { -webkit-overflow-scrolling: touch; }

/* When in standalone on narrow screens, ensure main fills remaining height */
@media (max-width: 1023px) {
  html.standalone body { display: flex; flex-direction: column; }
  html.standalone body main { flex: 1 1 auto; }
}

/* iOS PWA: status bar background in portrait standalone mode */
@media (orientation: portrait) {
  html.standalone::before {
    content: '';
    display: block;
    position: fixed;
    z-index: 9999;
    top: 0;
    left: 0;
    right: 0;
    height: env(safe-area-inset-top, 20px);
    background: var(--bg, #F2F2F7);
    pointer-events: none;
  }
}
