/* ---------- Tokens ---------- */
:root {
  --bg: #000000;
  --card: #0a0a0a;
  --raise: #141414;
  --ink: #ededed;
  --muted: #8a8a8a;
  --line: #222222;
  --line-strong: #4a4a4a;
  --water: #46586a;      /* same water tone as the map */
  --sheet: #f2f2f0;      /* paper behind scanned pages */

  --radius: 10px;
  --font: "Geist Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  color-scheme: dark;
}

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

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 400 14px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* ---------- Header ---------- */
.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px 32px;
  padding: 26px clamp(16px, 3vw, 32px) 18px;
  border-bottom: 1px solid var(--line);
}

.brand h1 {
  margin: 0;
  font: 600 clamp(1.6rem, 3.6vw, 2.5rem)/1.05 var(--font);
  letter-spacing: -0.05em;
}

.brand h1 a { color: inherit; text-decoration: none; }
.brand h1 a:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 6px; text-decoration-color: var(--line-strong); }

.sub {
  margin: 10px 0 0;
  max-width: 52ch;
  color: var(--muted);
  font-size: .85rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  flex: 1 1 560px;
  justify-content: flex-end;
}

.search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 260px;
  max-width: 420px;
}

.search svg {
  position: absolute;
  left: 12px;
  width: 16px; height: 16px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}

.search input {
  width: 100%;
  height: 40px;
  padding: 0 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.search input::placeholder { color: var(--muted); }
.search input:focus { border-color: var(--line-strong); outline: none; }

.search kbd {
  position: absolute;
  right: 10px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  font: 400 12px/1.5 var(--font);
}

.search input:not(:placeholder-shown) + kbd { display: none; }

.select select {
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.views {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.views button {
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.views button:hover { color: var(--ink); }

.views button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
}

.about-btn {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
}

.about-btn:hover { color: var(--ink); border-color: var(--line-strong); }

/* ---------- About dialog ---------- */
.about {
  width: min(460px, calc(100% - 32px));
  padding: 22px 24px 20px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--raise);
  color: var(--ink);
}

.about::backdrop { background: rgba(0, 0, 0, .7); }

.about h2 {
  margin: 0 0 12px;
  font: 500 1.1rem/1.3 var(--font);
  letter-spacing: -0.02em;
}

.about p { margin: 0 0 10px; color: var(--muted); font-size: .85rem; max-width: 52ch; }
.about a { color: var(--ink); text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
.about-copy { padding-top: 12px; border-top: 1px solid var(--line); }

.about-close {
  margin-top: 6px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

.about-close:hover { background: var(--ink); color: var(--bg); }

/* ---------- Layout ---------- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 42%);
}

.layout[data-view="panels"],
.layout[data-view="map"] { grid-template-columns: minmax(0, 1fr); }
.layout[data-view="panels"] .mapwrap { display: none; }
.layout[data-view="map"] .panels     { display: none; }

/* tools and writings have no map: panels take the full width */
.layout[data-kind="writing"],
.layout[data-kind="tool"] { grid-template-columns: minmax(0, 1fr); }
.layout[data-kind="writing"] .mapwrap,
.layout[data-kind="tool"] .mapwrap { display: none; }
.layout[data-kind="writing"] .panels,
.layout[data-kind="tool"] .panels { display: block; }
.views[hidden] { display: none; }

.panels {
  min-height: 0;
  overflow: auto;
  padding: 18px clamp(16px, 3vw, 32px) 48px;
}

.mapwrap {
  position: relative;
  min-height: 0;
  border-left: 1px solid var(--line);
  background: #2b2b2b;
}

#map { position: absolute; inset: 0; }

.status {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: .82rem;
}

.status.is-error {
  padding: 12px 14px;
  border: 1px solid #5a2323;
  border-radius: 8px;
  background: #160909;
  color: var(--ink);
}

.mapnote,
.credit {
  position: absolute;
  z-index: 2;
  margin: 0;
  pointer-events: none;
}

.mapnote {
  left: 12px;
  bottom: 10px;
  max-width: 50%;
  color: var(--muted);
  font-size: .75rem;
}

/* map credit: plain white letters, no background, no links */
.credit {
  right: 10px;
  bottom: 8px;
  max-width: 48%;
  color: #ffffff;
  font-size: 10px;
  line-height: 1.3;
  text-align: right;
  opacity: .75;
}

/* ---------- Panels ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}

.layout[data-view="panels"] .grid { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }

.card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: inherit;
  text-decoration: none;
  transition: border-color .15s ease;
}

.card[hidden] { display: none; }

.card:hover,
.card.is-active { border-color: var(--line-strong); }

.preview {
  --s: .2;
  position: relative;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: var(--raise);
}

.fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.initials {
  color: var(--line-strong);
  font: 500 2.4rem/1 var(--font);
  letter-spacing: -0.06em;
}

.preview .shot {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview iframe {
  position: absolute;
  top: 0; left: 0;
  width: 1280px;
  height: 800px;
  border: 0;
  background: #000;
  transform: scale(var(--s));
  transform-origin: 0 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s ease;
}

.preview iframe.is-loaded { opacity: 1; }

.meta {
  display: grid;
  gap: 2px;
  padding: 12px 14px 14px;
}

.title {
  margin: 0;
  font: 500 .98rem/1.3 var(--font);
  letter-spacing: -0.02em;
}

/* place line and "Tool" read as normal text */
.place {
  margin: 0;
  color: var(--muted);
  font-size: .8rem;
  font-variant-numeric: tabular-nums;
}

.place .coords { display: block; }

.desc {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: .8rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- Writings as a list (Writings view) ---------- */
.card .w-outlet,
.card .w-authors,
.card .w-year,
.list-head { display: none; }

.layout[data-kind="writing"] .grid { display: block; }

.layout[data-kind="writing"] .card {
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}

.layout[data-kind="writing"] .card .preview,
.layout[data-kind="writing"] .card .place,
.layout[data-kind="writing"] .card .desc { display: none; }

.layout[data-kind="writing"] .card .meta,
.layout[data-kind="writing"] .list-head {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, .8fr) minmax(0, 1fr) 6ch;
  gap: 4px 28px;
  align-items: baseline;
  padding: 13px 6px;
}

.layout[data-kind="writing"] .list-head {
  padding-top: 4px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: .75rem;
}

.layout[data-kind="writing"] .list-head span:last-child,
.layout[data-kind="writing"] .card .w-year { text-align: right; }

.layout[data-kind="writing"] .card .w-outlet,
.layout[data-kind="writing"] .card .w-authors,
.layout[data-kind="writing"] .card .w-year {
  display: block;
  color: var(--muted);
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
}

.layout[data-kind="writing"] .card[href]:hover { background: var(--card); }
.layout[data-kind="writing"] .card[href]:hover .title { text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 1px; }
.layout[data-kind="writing"] .card:not([href]) .title { color: var(--muted); }   /* listed, nothing to open yet */
.layout[data-kind="writing"] .card:hover { border-color: var(--line); }
.layout[data-kind="writing"] .group-head { margin-top: 24px; padding-left: 6px; }

@media (max-width: 700px) {
  .layout[data-kind="writing"] .card .meta,
  .layout[data-kind="writing"] .list-head { grid-template-columns: minmax(0, 1fr) 6ch; }
  .layout[data-kind="writing"] .card .w-outlet { grid-row: 2; grid-column: 1 / -1; }
  .layout[data-kind="writing"] .card .w-authors { grid-row: 3; grid-column: 1 / -1; }
  .layout[data-kind="writing"] .list-head span:nth-child(2),
  .layout[data-kind="writing"] .list-head span:nth-child(3) { display: none; }
}

/* ---------- Folder of earlier writings ---------- */
.group-head {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-top: 10px;
  padding: 14px 0 4px;
  border-top: 1px solid var(--line-strong);
}

.group-head[hidden] { display: none; }
.group-title { margin: 0; font: 500 .98rem/1.3 var(--font); letter-spacing: -0.02em; }
.group-sub { margin: 2px 0 0; color: var(--muted); font-size: .8rem; }
.group-toggle[hidden] { display: none; }

/* ---------- Writings on the panels ---------- */
.preview.is-doc { background: var(--raise); }

/* the first page sits like a sheet on a table, cut off by the panel edge */
.preview.is-doc .sheet {
  position: absolute;
  top: 14px;
  left: 50%;
  width: 62%;
  height: auto;
  transform: translateX(-50%);
  background: var(--sheet);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .4);
}

/* ---------- Reader ---------- */
.reader {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--bg);
  color: var(--ink);
}

.reader[open] { display: flex; flex-direction: column; }
.reader::backdrop { background: var(--bg); }

.reader-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  padding: 14px clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
}

.reader-head { min-width: 0; flex: 1 1 320px; }

.reader-head h2 {
  margin: 0;
  font: 500 1.05rem/1.3 var(--font);
  letter-spacing: -0.02em;
}

.reader-head p { margin: 2px 0 0; color: var(--muted); font-size: .8rem; }
.reader-head .reader-authors { margin-top: 4px; color: var(--ink); }
.reader-head p:empty { display: none; }

.reader-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.reader-page {
  min-width: 11ch;
  color: var(--muted);
  font-size: .8rem;
  font-variant-numeric: tabular-nums;
}

.reader-btn {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.reader-btn[hidden] { display: none; }

.reader-pages {
  --sheet-width: 800px;
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 24px clamp(12px, 3vw, 32px) 64px;
  outline: none;
}

.reader-pages:focus-visible { box-shadow: inset 0 0 0 2px var(--line-strong); }

.sheet-slot {
  width: var(--sheet-width);
  margin: 0 auto 18px;
  background: var(--sheet);
}

/* while a page is still being drawn */
.sheet-slot:empty { background: var(--raise); border: 1px solid var(--line); }
.sheet-slot[data-error]::after {
  content: "This page could not be drawn.";
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--muted);
  font-size: .8rem;
}

.sheet-slot canvas { display: block; width: 100%; height: auto; }

/* two pages side by side; the cover stands alone on the right, like a book */
.reader-pages.is-spread {
  display: grid;
  grid-template-columns: repeat(2, var(--sheet-width));
  justify-content: safe center;
  align-content: start;
  align-items: start;
  column-gap: 6px;
}

.reader-pages.is-spread .sheet-slot { margin: 0 0 18px; }
.reader-pages.is-spread .sheet-slot:first-child { grid-column: 2; }
.reader-pages.is-spread .reader-error { grid-column: 1 / -1; }

.reader-error {
  max-width: 52ch;
  margin: 40px auto;
  padding: 12px 14px;
  border: 1px solid #5a2323;
  border-radius: 8px;
  background: #160909;
  font-size: .85rem;
}

/* ---------- Landing ---------- */
/* One screen: the text on the left, the live stations on the right,
   the graph behind both along the bottom, the footer as the water body. */
body.landing {
  display: grid;
  grid-template-rows: 1fr auto;
  height: auto;
  min-height: 100%;
  min-height: 100dvh;
}

.stage {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 24px clamp(24px, 4vw, 64px);
  align-items: start;
  padding: clamp(18px, 4.5vh, 72px) clamp(16px, 5vw, 64px) clamp(28px, 5vh, 72px);
}

.intro,
.gauge-panel {
  position: relative;
  z-index: 1;
  text-shadow: 0 0 6px var(--bg), 0 0 2px var(--bg);   /* keeps text readable over the lines */
}

.intro {
  display: grid;
  align-content: start;
  gap: clamp(14px, 2.6vh, 32px);
}

.intro-head h1 {
  margin: 0;
  font: 600 clamp(2.6rem, min(8vw, 11vh), 8rem)/0.92 var(--font);
  letter-spacing: -0.065em;
}

.intro-head h1 span { display: block; }

.intro-sub {
  margin: clamp(8px, 1.6vh, 20px) 0 0;
  max-width: 44ch;
  color: var(--muted);
  font-size: clamp(.95rem, min(1.5vw, 2.1vh), 1.15rem);
  line-height: 1.45;
}

.intro-text { max-width: 64ch; }
.intro-text p { margin: 0 0 8px; }
.intro-text p:last-child { margin-bottom: 0; color: var(--muted); }
.intro-text a,
.intro-foot a { color: inherit; text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.intro-text a:hover,
.intro-foot a:hover { text-decoration-color: currentColor; }

/* the menu: three lines under the text */
.entries {
  display: grid;
  max-width: 64ch;
  border-top: 1px solid var(--line-strong);
}

.entry {
  display: grid;
  grid-template-columns: 11ch minmax(0, 1fr);
  gap: 2px 16px;
  align-items: baseline;
  padding: clamp(7px, 1.3vh, 12px) 0;
  border-bottom: 1px solid var(--line-strong);
  color: inherit;
  text-decoration: none;
}

.entry-name { font-size: 1.05rem; font-weight: 500; letter-spacing: -0.02em; }
.entry-desc { color: var(--muted); font-size: .82rem; }
.entry:hover .entry-name { text-decoration: underline; text-underline-offset: 5px; text-decoration-thickness: 1px; }
.entry:hover .entry-desc { color: var(--ink); }

/* short screens: slightly smaller text keeps everything on one screen */
@media (max-height: 820px) and (min-width: 821px) {
  .intro { gap: 12px; }
  .intro-head h1 { font-size: clamp(2.4rem, min(8vw, 10vh), 8rem); }
  .intro-text { font-size: 13px; line-height: 1.45; }
  .intro-text p { margin-bottom: 4px; }
}

/* ---------- Live stations (right) ---------- */
.gauge-panel {
  display: grid;
  gap: 12px;
  justify-items: end;
  text-align: right;
}

.gauge-tools {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  width: 100%;
}

.gauge-search { position: relative; flex: 1; max-width: 300px; }

.gauge-search input {
  width: 100%;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font-size: .78rem;
}

.gauge-search input::placeholder { color: var(--muted); }
.gauge-search input:focus { border-color: var(--line-strong); outline: none; }
.gauge-search input:disabled { opacity: .5; }

.gauge-results {
  position: absolute;
  z-index: 5;
  right: 0;
  top: calc(100% + 4px);
  width: max(100%, 320px);
  max-height: min(340px, 50vh);
  margin: 0;
  padding: 4px;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--raise);
  list-style: none;
  text-align: left;
  text-shadow: none;
}

.gauge-results li {
  display: grid;
  gap: 1px;
  padding: 7px 9px;
  border-radius: 5px;
  font-size: .8rem;
  cursor: pointer;
}

.gauge-results li small { color: var(--muted); font-size: .72rem; }
.gauge-results li[aria-selected="true"],
.gauge-results li:hover { background: var(--line); }
.gauge-results .gauge-empty { color: var(--muted); cursor: default; }
.gauge-results .gauge-empty:hover { background: none; }

.gauge-next {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--muted);
  font-size: .78rem;
  cursor: pointer;
  white-space: nowrap;
}

.gauge-next:hover:not(:disabled) { color: var(--ink); border-color: var(--line-strong); }
.gauge-next:disabled { opacity: .5; cursor: default; }

.gauge-range {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  text-shadow: none;
}

.gauge-range button {
  height: 26px;
  padding: 0 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: .75rem;
  cursor: pointer;
}

.gauge-range button:hover { color: var(--ink); }
.gauge-range button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

.gauge-note { margin: 0; max-width: 40ch; color: var(--muted); font-size: .76rem; }
.gauge-note[hidden] { display: none; }

.gauge-stations {
  display: grid;
  gap: 14px;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

.station { display: grid; gap: 7px; justify-items: end; }

.station-head {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 10px;
}

.station-swatch {
  flex: none;
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--c);
}

.station-name { margin: 0; font: 500 .95rem/1.3 var(--font); letter-spacing: -0.02em; }
.station-meta,
.station-theme { margin: 1px 0 0; color: var(--muted); font-size: .74rem; }
.station-theme { color: var(--c); }

.station-remove {
  flex: none;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--muted);
  font-size: .85rem;
  line-height: 1;
  cursor: pointer;
}

.station-remove:hover { color: var(--ink); border-color: var(--line-strong); }

.station-series {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}

.gauge-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 26px;
  padding: 0 9px;
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  background: rgba(0, 0, 0, .6);
  color: var(--ink);
  font-size: .72rem;
  text-shadow: none;
  cursor: pointer;
}

.gauge-chip .chip-value { color: var(--muted); font-variant-numeric: tabular-nums; }
.gauge-chip:hover { border-color: var(--ink); }
.gauge-chip[aria-pressed="false"] { border-style: dashed; color: var(--muted); }
.gauge-chip[aria-pressed="false"] .chip-swatch { opacity: .3; }

/* the swatch repeats the line style of each measurement, in the station's colour */
.chip-swatch {
  flex: none;
  width: 16px;
  height: 0;
  border-top: 2px solid var(--c);
}

.m-flow .chip-swatch {
  height: 2px;
  border: 0;
  background: repeating-linear-gradient(90deg, var(--c) 0 6px, transparent 6px 8px, var(--c) 8px 10px, transparent 10px 12px);
}
.m-wtemp .chip-swatch { border-top-style: dotted; }
.m-air .chip-swatch { border-top-width: 1px; border-top-style: dashed; }
.m-rain .chip-swatch { height: 8px; border: 0; background: var(--c); opacity: .55; }

/* ---------- Live graph (behind) ---------- */
.gauge-plot {
  position: absolute;
  z-index: auto;   /* no own layer, so the readout can rise above the text and the panel */
  left: 0;
  right: 0;
  bottom: 0;
  height: clamp(200px, 56%, 680px);
}

.gauge-svg {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.water-fill { fill: var(--water); opacity: .45; transition: opacity 1.2s ease .4s; }
.water-mean { stroke: var(--line-strong); stroke-width: 1; stroke-dasharray: 2 6; vector-effect: non-scaling-stroke; }

.g-line {
  fill: none;
  stroke: var(--c);
  stroke-width: 1.25;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  transition: opacity 1.2s ease .3s;
}

.g-line.m-level { stroke-width: 2; }
.g-line.m-flow { stroke-width: 1.4; stroke-dasharray: 10 3 2 3; }
.g-line.m-wtemp { stroke-width: 1.6; stroke-dasharray: 0.5 4; }
.g-line.m-air { stroke-width: 1.1; stroke-dasharray: 6 4; }
.g-bar { fill: var(--c); opacity: .4; transition: opacity 1.2s ease .2s; }

.gauge-plot.is-revealing .water-fill,
.gauge-plot.is-revealing .g-bar,
.gauge-plot.is-revealing .g-line:not(.m-level) { opacity: 0; transition: none; }

.gauge-dot {
  --c: var(--ink);
  position: absolute;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border-radius: 50%;
  background: var(--c);
  pointer-events: none;
}

.gauge-dot::after {
  content: "";
  position: absolute;
  inset: -6px;
  border: 1px solid var(--c);
  border-radius: 50%;
  opacity: 0;
  animation: gauge-pulse 2.4s ease-out infinite;
}

@keyframes gauge-pulse {
  0% { transform: scale(.4); opacity: .8; }
  100% { transform: scale(1.6); opacity: 0; }
}

.gauge-cursor {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--line-strong);
  pointer-events: none;
}

.gauge-readout {
  position: absolute;
  z-index: 4;
  top: 8px;
  display: grid;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--raise);
  font-size: .74rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}

.gauge-readout[hidden] { display: none; }
.readout-time { color: var(--muted); }
.readout-station { display: grid; gap: 2px; }
.readout-name { color: var(--c); font-weight: 500; }
.readout-row { display: flex; align-items: center; gap: 7px; }

.gauge-scale {
  position: absolute;
  inset: auto clamp(16px, 5vw, 64px) 6px;
  display: flex;
  justify-content: space-between;
  margin: 0;
  color: var(--ink);
  font-size: .72rem;
  opacity: .75;
  pointer-events: none;
}

.intro-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 24px;
  padding: 12px clamp(16px, 5vw, 64px) 16px;
  background: color-mix(in srgb, var(--water) 45%, var(--bg));
  color: var(--ink);
  font-size: .78rem;
}

.intro-foot p { margin: 0; }
.intro-foot p:nth-child(2) { opacity: .7; }

/* phones and narrow windows: only the title, text and menu, with the live graph behind them.
   The station panel and the reading on touch are left out. */
@media (max-width: 820px) {
  .stage {
    grid-template-columns: minmax(0, 1fr);
    padding: 22px 18px 14px;
  }
  .gauge-panel,
  .gauge-readout,
  .gauge-cursor { display: none !important; }
  .gauge-plot { height: 58%; }
  .gauge-scale { inset: auto 16px 6px; }
  .intro { gap: 14px; }
  .intro-head h1 { font-size: clamp(2.5rem, 12.5vw, 4.5rem); }
  .intro-sub { margin-top: 8px; font-size: .9rem; }
  .intro-text { font-size: 12.5px; line-height: 1.45; }
  .intro-text p { margin-bottom: 6px; }
  .entry { grid-template-columns: 1fr; gap: 0; padding: 7px 0; }
  .entry-desc { font-size: .74rem; }
  .intro-foot { gap: 2px 16px; padding: 9px 18px 12px; font-size: .72rem; }
}

@media (prefers-reduced-motion: reduce) {
  .gauge-dot::after { animation: none; }
}

/* ---------- Map pins, popups, controls ---------- */
.pin-wrap {
  display: grid;
  place-items: center;
  width: 24px; height: 24px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.pin {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--pin, #ffffff);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, .8);
  transition: transform .15s ease;
}

.pin.is-active { transform: scale(1.7); }

.maplibregl-map { font: 13px/1.45 var(--font); }

.maplibregl-popup-tip { display: none; }

.maplibregl-popup-content {
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--raise);
  color: var(--ink);
  box-shadow: none;
}

.pop { display: grid; gap: 2px; min-width: 170px; }
.pop strong { font-weight: 500; }
.pop span { color: var(--muted); font-size: .8rem; }
.pop .links { display: flex; gap: 14px; margin-top: 8px; }
.pop a { color: inherit; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
.pop a:hover { text-decoration-color: var(--ink); }

.maplibregl-ctrl-group {
  border: 1px solid var(--line);
  background: var(--raise);
  box-shadow: none !important;
}

.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line); }
.maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1); opacity: .8; }

/* ---------- Small screens ---------- */
@media (max-width: 820px) {
  .masthead { padding-top: 20px; }
  .controls { justify-content: flex-start; }
  .search { max-width: none; flex-basis: 100%; }

  .layout { grid-template-rows: 40vh minmax(0, 1fr); }
  .layout[data-view="panels"],
  .layout[data-view="map"] { grid-template-rows: minmax(0, 1fr); }

  .mapwrap { order: -1; border-left: 0; border-bottom: 1px solid var(--line); }
  .layout[data-kind="writing"],
  .layout[data-kind="tool"] { grid-template-rows: minmax(0, 1fr); }

  .reader-bar { padding-block: 10px; }
  .reader-page { min-width: 0; }
}

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

/* ---------- Writings: list on the left, diagram on the right (writings-diagram.js) ---------- */
.panels-list { display: contents; }

.diagram {
  display: grid;
  gap: 20px;
  align-content: start;
  margin: 0 0 32px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--line);
}
.diagram[hidden] { display: none; }

@media (min-width: 1000px) {
  .layout[data-kind="writing"] .panels {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
    overflow: hidden;
    padding: 0;
  }
  .layout[data-kind="writing"] .panels-list {
    display: block;
    grid-column: 1;
    grid-row: 1;
    min-height: 0;
    overflow: auto;
    padding: 18px clamp(16px, 2.4vw, 32px) 48px;
  }
  .layout[data-kind="writing"] .diagram {
    grid-column: 2;
    grid-row: 1;
    min-height: 0;
    overflow: auto;
    margin: 0;
    padding: clamp(24px, 3.5vh, 44px) clamp(28px, 4vw, 64px);
    border-bottom: 0;
    border-left: 1px solid var(--line);
    /* the drawing takes whatever height is left, so everything fits the window */
    display: flex;
    flex-direction: column;
    gap: clamp(14px, 2.5vh, 28px);
  }
  .layout[data-kind="writing"] .diagram .dg-figure { flex: 1 1 0; min-height: 160px; display: flex; flex-direction: column; }
  .layout[data-kind="writing"] .diagram .dg-svg { flex: 1 1 0; min-height: 0; width: 100%; height: 100%; max-width: none; }
  .layout[data-kind="writing"] .diagram .dg-zoom { flex: 1 1 0; min-height: 0; grid-template-rows: auto minmax(0, 1fr) auto; }
  .layout[data-kind="writing"] .diagram .dg-stage { min-height: 0; height: 100%; }
  .layout[data-kind="writing"] .diagram .dg-track { height: 100%; }
  .layout[data-kind="writing"] .diagram .dg-slot { height: 100%; }
  .layout[data-kind="writing"] .diagram .dg-panel { width: 100%; height: 100%; }
  .layout[data-kind="writing"] .diagram .dg-side { flex: none; gap: 12px; }
  /* the list is narrower here: title and year on top, outlet and authors below */
  .layout[data-kind="writing"] .card .meta,
  .layout[data-kind="writing"] .list-head { grid-template-columns: minmax(0, 1fr) 6ch; }
  .layout[data-kind="writing"] .card .w-outlet { grid-row: 2; grid-column: 1 / -1; }
  .layout[data-kind="writing"] .card .w-authors { grid-row: 3; grid-column: 1 / -1; }
  .layout[data-kind="writing"] .list-head span:nth-child(2),
  .layout[data-kind="writing"] .list-head span:nth-child(3) { display: none; }
}

/* Legend and note */
.dg-side { display: grid; gap: 18px; font-size: .8rem; color: var(--muted); }
.dg-note { margin: 0; line-height: 1.55; max-width: 70ch; }
.dg-keys { display: flex; flex-wrap: wrap; gap: 14px 36px; align-items: start; }
.dg-legend, .dg-pubs { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.dg-legend li, .dg-pubs li { display: flex; gap: 10px; align-items: baseline; }
.dg-cases { display: flex; flex-wrap: wrap; gap: 2px 8px; }
.dg-key-sub { display: block; color: var(--muted); }

.dg-key {
  flex: none;
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  transform: translateY(1px);
}
.dg-key.is-published { background: var(--ink); }
.dg-key.is-case { width: 14px; height: 14px; border: 0; background: var(--c); }

.dg-case-btn {
  display: flex; gap: 10px; align-items: baseline;
  margin: 0; padding: 6px 8px;
  border: 1px solid transparent; border-radius: 8px;
  background: none; color: var(--ink);
  font: inherit; text-align: left; cursor: pointer;
}
.dg-case-btn:hover { background: var(--raise); }
.dg-case-btn[aria-pressed="true"] { border-color: var(--c); }

.diagram button:focus-visible,
.dg-pubs a:focus-visible,
.dg-range:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.dg-pubs a { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
.dg-pubs a:hover { text-decoration-color: var(--ink); }
.dg-pubs span:not(.dg-key) { color: var(--muted); }
.dg-pubs { display: none; }   /* the drawing carries the labels on wide screens */

/* Drawings */
.dg-figure { min-width: 0; }
.dg-svg {
  display: block;
  width: 100%;
  max-width: calc(68vh * 1880 / 1720);
  height: auto;
  margin: 0 auto;
  font-family: var(--font);
  overflow: visible;
}
.dg-ring { fill: none; stroke: var(--ink); stroke-width: 7; transition: stroke-width .15s; }
.dg-ring.is-thin { stroke-width: 4; }
.dg-hit { fill: transparent; }
.dg-cross { stroke: var(--ink); stroke-width: 2.5; stroke-dasharray: 22 18; opacity: .75; }
.dg-panel .dg-cross { stroke-width: 1.4; stroke-dasharray: 10 8; }
.dg-arc { fill: none; stroke: var(--ink); stroke-width: 7; }
.dg-arrowhead { fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.dg-field-name { fill: var(--ink); font-size: 44px; font-weight: 600; letter-spacing: -0.01em; }
.dg-center { fill: var(--ink); font-size: 44px; font-weight: 600; }

.dg-field { cursor: pointer; outline: none; }
.dg-field .dg-hit, .dg-field .dg-field-name { transition: fill .15s, opacity .15s; }
.dg-field:hover .dg-ring,
.dg-field:focus-visible .dg-ring { stroke-width: 16; }
.dg-field:hover .dg-hit,
.dg-field:focus-visible .dg-hit { fill: rgba(255, 255, 255, .14); }
.dg-svg:has(.dg-field:hover) .dg-field:not(:hover) { opacity: .45; }

.dg-tri {
  fill: none; stroke: var(--c);
  stroke-width: 8; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 0 16;
}
.dg-tri.is-thin { stroke-width: 4.5; stroke-dasharray: 0 9; }
.dg-node { fill: var(--c); }
.dg-blob { fill: var(--c); fill-opacity: .28; stroke: none; }
.dg-case, .dg-blob { transition: opacity .2s; }
.diagram.has-focus .dg-case:not(.is-on),
.diagram.has-focus .dg-blob:not(.is-on) { opacity: .12; }
.diagram.has-focus .dg-blob.is-on { fill-opacity: .45; }

.dg-dot { fill: var(--bg); stroke: var(--ink); stroke-width: 3.5; }
.dg-dot.is-published { fill: var(--ink); }
.dg-pub-label { fill: var(--ink); font-size: 25px; }
.dg-pub.is-link { cursor: pointer; outline: none; }
.dg-pub.is-link .dg-pub-label { fill: var(--ink); text-decoration: underline; text-decoration-thickness: 2px; }
.dg-pub.is-link:hover .dg-dot,
.dg-pub.is-link:focus-visible .dg-dot { r: 13; }
.dg-pub.is-link:focus-visible .dg-dot,
.dg-pub.is-link:focus-visible .dg-item-ring { stroke-width: 3; }

/* one drawing of a row */
.dg-panel { display: block; width: 100%; height: auto; font-family: var(--font); overflow: visible; }
.dg-axis { fill: var(--ink); font-size: 21px; }
.dg-small { fill: var(--ink); font-size: 12.5px; }
.dg-panel .dg-pub-label { font-size: 12.5px; }
.dg-panel .dg-pub.is-link .dg-pub-label { text-decoration-thickness: 1px; }
.dg-ref-ring { fill: none; stroke: var(--muted); stroke-width: 1.2; }
.dg-item-ring { fill: none; stroke: var(--ink); stroke-width: 1.2; opacity: .8; }

/* row view */
.dg-zoom { display: grid; gap: 14px; }
.dg-bar { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.dg-back { margin: 0; }
.dg-rows { display: flex; flex-wrap: wrap; gap: 4px; }
.dg-row-btn, .dg-stop {
  padding: 6px 10px;
  border: 1px solid transparent; border-radius: 6px;
  background: none; color: var(--muted);
  font: inherit; font-size: .8rem; cursor: pointer;
}
.dg-row-btn:hover, .dg-stop:hover { color: var(--ink); background: var(--raise); }
.dg-row-btn[aria-pressed="true"], .dg-stop[aria-pressed="true"] { color: var(--bg); background: var(--ink); }

.dg-stage { overflow: hidden; touch-action: pan-y; }
.dg-track {
  display: flex;
  width: 300%;
  transition: transform .35s cubic-bezier(.2, .7, .2, 1);
}
.dg-slot { flex: 1 1 0; min-width: 0; }

.dg-slider { display: grid; gap: 6px; width: min(100%, 420px); margin: 0 auto; }
.dg-slider input[type="range"] { width: 100%; accent-color: var(--ink); margin: 0; }
.dg-stops { display: flex; justify-content: space-between; }

@media (max-width: 820px) {
  .dg-pubs { display: grid; }
  .dg-svg { max-width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .dg-case, .dg-blob, .dg-ring, .dg-track, .dg-field .dg-hit, .dg-field .dg-field-name { transition: none; }
}
.dg-blob { pointer-events: none; }

/* compact legend beside the note, so the drawing gets the height */
@media (min-width: 1000px) {
  .layout[data-kind="writing"] .diagram .dg-side {
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    gap: 10px clamp(16px, 2.5vw, 36px);
    align-items: start;
    font-size: .74rem;
  }
  .layout[data-kind="writing"] .diagram .dg-note { line-height: 1.5; }
  .layout[data-kind="writing"] .diagram .dg-keys { flex-direction: column; flex-wrap: nowrap; gap: 6px; }
  .layout[data-kind="writing"] .diagram .dg-legend { gap: 3px; }
  .layout[data-kind="writing"] .diagram .dg-cases { flex-direction: column; gap: 0; }
  .layout[data-kind="writing"] .diagram .dg-case-btn { padding: 3px 6px; margin-left: -6px; align-items: center; }
  .layout[data-kind="writing"] .diagram .dg-case-btn .dg-key { transform: none; }
  .layout[data-kind="writing"] .diagram .dg-key-sub { display: block; }
  .layout[data-kind="writing"] .diagram .dg-case-btn { align-items: baseline; line-height: 1.35; }
  .layout[data-kind="writing"] .diagram .dg-case-btn .dg-key { transform: translateY(1px); }
}
