/* Poolen -- public water status view.
   Design: dark "deep water" hero with animated SVG caustics; adaptive foam
   cards below. Mono for data readouts, humanist sans for prose. AA in both
   light and dark. */

:root {
  color-scheme: light dark;

  --bg: #e9f3f4;
  --surface: #ffffff;
  --surface-2: #f2f9fa;
  --line: #d3e4e6;
  --ink: #072830;
  --ink-muted: #45646d;

  --accent: #0b6f7c;
  --accent-strong: #075661;
  --on-accent: #f2fdff;

  --good-fg: #0a6446;
  --good-bg: #d4efe2;
  --low-fg: #8a5300;
  --low-bg: #f9e6c8;
  --high-fg: #a11d24;
  --high-bg: #fadfe0;
  --none-fg: #4b5b60;
  --none-bg: #e5edee;

  --chart-line: #0b6f7c;
  --chart-fill: rgba(11, 111, 124, 0.16);
  --chart-grid: #dde9ea;

  --radius: 18px;
  --radius-s: 11px;
  --shadow: 0 1px 2px rgba(7, 40, 48, 0.06), 0 10px 30px rgba(7, 40, 48, 0.07);
  --wrap: 62rem;

  /* hero is always deep water -- guarantees light text contrast in any mode */
  --hero-top: #0a4453;
  --hero-bot: #052029;
  --hero-ink: #f4fcfd;
  --hero-muted: #a9cdd4;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #04181e;
    --surface: #0b2a33;
    --surface-2: #103740;
    --line: #1c4650;
    --ink: #e9f4f5;
    --ink-muted: #9cbdc4;

    --accent: #45d3db;
    --accent-strong: #45d3db;
    --on-accent: #04181e;

    --good-fg: #58d8a5;
    --good-bg: rgba(35, 120, 88, 0.28);
    --low-fg: #f0b967;
    --low-bg: rgba(150, 96, 20, 0.30);
    --high-fg: #ff9297;
    --high-bg: rgba(150, 40, 46, 0.32);
    --none-fg: #9fb8bf;
    --none-bg: rgba(120, 150, 158, 0.16);

    --chart-line: #45d3db;
    --chart-fill: rgba(69, 211, 219, 0.16);
    --chart-grid: #17434d;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 34px rgba(0, 0, 0, 0.36);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin-inline: auto;
  padding-inline: clamp(1rem, 4vw, 2rem);
}

/* data / instrument register */
.eyebrow, .badge, .card-label, .value-unit, .stamp, .temp-unit, .temp-cap,
.section-note, .status-pill, .cta, .foot-cta {
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono",
    Menlo, Consolas, monospace;
}

a { color: var(--accent); }

.skip {
  position: absolute;
  left: 0.5rem;
  top: -3rem;
  z-index: 20;
  background: var(--surface);
  color: var(--ink);
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-s);
  box-shadow: var(--shadow);
  transition: top 0.15s ease;
}
.skip:focus { top: 0.5rem; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(9px);
  border-bottom: 1px solid var(--line);
}
.topbar-in {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.7rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.brand-mark { width: 1.35rem; height: 1.35rem; color: var(--accent); }

.cta {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--accent-strong);
  color: var(--on-accent);
  text-decoration: none;
  font-size: 0.86rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: transform 0.12s ease, filter 0.12s ease;
}
.cta span { font-size: 1.05em; line-height: 0; }
.cta:hover { filter: brightness(1.08); transform: translateY(-1px); }

/* ---------- hero ---------- */
.hero {
  position: relative;
  overflow: hidden;
  margin-top: clamp(1rem, 3vw, 1.8rem);
  border-radius: calc(var(--radius) + 6px);
  background: linear-gradient(158deg, var(--hero-top), var(--hero-bot));
  color: var(--hero-ink);
  box-shadow: var(--shadow);
  isolation: isolate;
}
.caustics {
  position: absolute;
  inset: -8%;
  width: 116%;
  height: 116%;
  z-index: -1;
  opacity: 0.5;
  mix-blend-mode: screen;
  transition: opacity 0.6s ease;
}
/* status recolours the water */
.hero.is-alert { background: linear-gradient(158deg, #6a4410, #2c1704); }
.hero.is-alert .caustics {
  opacity: 0.42;
  filter: sepia(1) saturate(2.4) hue-rotate(-18deg);
}

.hero-in {
  position: relative;
  padding: clamp(1.6rem, 5vw, 2.8rem);
}
.eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.74rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--hero-muted);
}
h1 {
  margin: 0 0 1.1rem;
  font-size: clamp(1.7rem, 5.4vw, 2.5rem);
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0;
  padding: 0.45rem 0.95rem 0.45rem 0.7rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: var(--hero-ink);
}
.badge-dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: #cfe9ee;
  box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.5);
}
.badge[data-state="bra"] { background: rgba(30, 220, 150, 0.16); border-color: rgba(90, 235, 180, 0.5); }
.badge[data-state="bra"] .badge-dot { background: #57f0b4; animation: pulse 2.6s ease-out infinite; }
.badge[data-state="alert"] { background: rgba(255, 180, 70, 0.18); border-color: rgba(255, 190, 90, 0.55); }
.badge[data-state="alert"] .badge-dot { background: #ffbf6b; animation: pulse 1.8s ease-out infinite; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.45); }
  70% { box-shadow: 0 0 0 0.55rem rgba(255, 255, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
}

.temp {
  margin: 1.6rem 0 0;
}
.temp-read {
  display: flex;
  align-items: flex-start;
  gap: 0.15rem;
  line-height: 0.9;
}
.temp-val {
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  font-size: clamp(4.2rem, 20vw, 7rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.temp-unit {
  font-size: clamp(1.4rem, 5vw, 2.1rem);
  font-weight: 600;
  margin-top: 0.5em;
  color: var(--hero-muted);
}
.temp-cap {
  margin: 0.1rem 0 0;
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--hero-muted);
}
.temp-spark {
  margin-top: 0.9rem;
  max-width: 22rem;
  height: 46px;
}
.temp-spark svg { width: 100%; height: 100%; display: block; }
.temp-spark .empty { color: var(--hero-muted); }

.stamp {
  margin: 1.5rem 0 0;
  font-size: 0.82rem;
  color: var(--hero-muted);
  letter-spacing: 0.01em;
}
.stamp b { color: var(--hero-ink); font-weight: 600; }

/* ---------- params ---------- */
.params { margin-top: clamp(2rem, 6vw, 3.2rem); }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  margin-bottom: 1rem;
}
h2 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.section-note {
  margin: 0;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: clamp(0.8rem, 2vw, 1.1rem);
  grid-template-columns: 1fr;
}
@media (min-width: 34rem) {
  .grid { grid-template-columns: repeat(2, 1fr); }
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem 1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 12.5rem;
}
.card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  border-radius: var(--radius) 0 0 var(--radius);
  background: var(--pill-fg, var(--accent));
  opacity: 0.85;
}
.card.is-skeleton { min-height: 12.5rem; }
.card .sk {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-s);
  background: linear-gradient(100deg, var(--surface-2), var(--line), var(--surface-2));
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  min-height: 10rem;
}
@keyframes shimmer {
  to { background-position: -200% 0; }
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}
.card-label {
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0;
}
.value-unit {
  margin: 0.35rem 0 0;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.value-unit .num { font-size: 2.15rem; }
.value-unit .unit { font-size: 0.95rem; color: var(--ink-muted); margin-left: 0.25rem; font-weight: 600; }
.value-unit.is-none .num { color: var(--none-fg); font-size: 1.6rem; }

.status-pill {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--pill-fg);
  background: var(--pill-bg);
}
.status-pill::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
}
.card[data-status="bra"]  { --pill-fg: var(--good-fg); --pill-bg: var(--good-bg); }
.card[data-status="lågt"] { --pill-fg: var(--low-fg);  --pill-bg: var(--low-bg); }
.card[data-status="högt"] { --pill-fg: var(--high-fg); --pill-bg: var(--high-bg); }
.card[data-status="saknas"] { --pill-fg: var(--none-fg); --pill-bg: var(--none-bg); }
.card[data-status="saknas"]::before { opacity: 0.4; }

.card-msg {
  margin: 0.65rem 0 0;
  font-size: 0.9rem;
  color: var(--ink-muted);
  flex: 1;
}
.card-msg.is-none { font-style: italic; opacity: 0.85; }

.chart {
  margin-top: 0.85rem;
  height: 58px;
}
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .empty {
  display: flex;
  align-items: center;
  height: 100%;
  font-size: 0.78rem;
  color: var(--ink-muted);
  border-top: 1px dashed var(--line);
  padding-top: 0.4rem;
}

/* chart draw-in */
.chart-line, .spark-line {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: draw 1.1s ease forwards;
}
@keyframes draw { to { stroke-dashoffset: 0; } }
.chart-dot, .spark-dot { animation: pop 0.4s 0.9s ease both; transform-origin: center; }
@keyframes pop { from { opacity: 0; transform: scale(0); } to { opacity: 1; transform: scale(1); } }

/* ---------- error + footer ---------- */
.error {
  margin: 1.5rem 0 0;
  padding: 1rem 1.1rem;
  border-radius: var(--radius-s);
  background: var(--high-bg);
  color: var(--high-fg);
  border: 1px solid color-mix(in srgb, var(--high-fg) 35%, transparent);
  font-size: 0.92rem;
}

.foot {
  margin-top: clamp(2.5rem, 7vw, 4rem);
  border-top: 1px solid var(--line);
  padding-block: 1.6rem 2.4rem;
}
.foot .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.8rem;
}
.foot p { margin: 0; font-size: 0.85rem; color: var(--ink-muted); max-width: 34rem; }
.foot-cta {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1.5px solid currentColor;
  padding-bottom: 1px;
}

/* ---------- focus + motion ---------- */
a:focus-visible, .cta:focus-visible, .foot-cta:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}
.skip:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .chart-line, .spark-line { stroke-dashoffset: 0; }
  .cta:hover { transform: none; }
}
