/* Layout: status strip -> Hovmöller (the thesis) -> map + station stack sharing one time cursor -> station table. */
:root {
  --bg: #f4f6f9;          /* cool off-white */
  --surface: #ffffff;
  --ink: #111a26;
  --ink-2: #4f5b69;
  --ink-3: #8a95a3;
  --line: #dbe2ea;
  --grid: #edf1f5;
  --accent: #1c5cab;      /* sequential blue 550 */
  --obs: #2a78d6;         /* series 1 */
  --pred: #eb6834;        /* series 2 */
  --anom: #4a3aa7;        /* series 7, net anomaly line */
  /* ocean-signal ramp: grey midpoint, then 8 stops per arm, even OKLCH lightness steps (about 0.08); the positive arm
     also turns 22° of hue per stop, yellow -> orange -> red -> crimson -> magenta -> purple. Dark theme: the
     arms run dark to light, so the positive hues run the other way. */
  --mid: #f0efec;
  --ramp-neg: #bbd8fe #8ebffe #5da5fe #258afa #0371da #025bb2 #02468b #013266;
  --ramp-pos: #dfd98b #eeb009 #eb8603 #ea500f #ce2749 #a80164 #790071 #4c006e;
  --good: #0ca30c; --warn: #fab219; --crit: #d03b3b;
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --surface: #171d26; --ink: #f1f4f8; --ink-2: #b4bec9; --ink-3: #7f8a97;
    --line: #2a3340; --grid: #202833; --accent: #5598e7; --obs: #3987e5; --pred: #d95926; --anom: #9085e9;
    --mid: #383835;
    --ramp-neg: #334d69 #23629c #0576ca #188ceb #43a4fe #79bbfe #a7d2ff #d1e7ff;
    --ramp-pos: #5d3b74 #9c1e92 #c92f7e #ee4962 #ff7649 #fea655 #fecd6c #fff465;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141b; --surface: #171d26; --ink: #f1f4f8; --ink-2: #b4bec9; --ink-3: #7f8a97;
  --line: #2a3340; --grid: #202833; --accent: #5598e7; --obs: #3987e5; --pred: #d95926; --anom: #9085e9;
  --mid: #383835;
  --ramp-neg: #334d69 #23629c #0576ca #188ceb #43a4fe #79bbfe #a7d2ff #d1e7ff;
  --ramp-pos: #5d3b74 #9c1e92 #c92f7e #ee4962 #ff7649 #fea655 #fecd6c #fff465;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 14px; line-height: 1.45; }
body { padding-block: 20px 48px; padding-inline: clamp(16px, 3vw, 40px); }
h1, h2, h3 { margin: 0; text-wrap: balance; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; }
p { margin: 0; max-width: 68ch; }
a { color: var(--accent); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.eyebrow { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); font-weight: 500; }
.back { font-size: 0.8rem; }

/* Header grid: title and logo share the first row; intro and stamp run under the title.
   On small screens the logo shrinks and sits beside the title; intro and stamp span the full width. */
header { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "title stats brand" "intro stats brand" "stamp stats brand"; column-gap: 32px; align-items: start; margin-bottom: 18px; }
.title { grid-area: title; }
.brand { grid-area: brand; justify-self: end; }
.intro { grid-area: intro; color: var(--ink-2); }
.stamp { grid-area: stamp; }
.logo { display: block; height: 90px; width: auto; border-radius: 8px; border: 0px solid var(--line); background: #fff; }
@media (max-width: 820px) {
  header { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "title brand" "intro intro" "stamp stamp" "stats stats"; column-gap: 12px; }
  .brand { align-self: center; }
  .logo { height: 36px; border-radius: 6px; }
  .intro { margin-top: 6px; }
}
@media (max-width: 480px) { .logo { height: 32px; } }
.stamp { color: var(--ink-3); font-size: 0.8rem; margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
#stamp { display: inline-flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.seg.small button { padding: 2px 8px; font-size: 0.75rem; }

.tiles { grid-area: stats; display: flex; flex-direction: column; gap: 10px; align-self: center; padding-left: 16px; border-left: 1px solid var(--line); min-width: 220px; }
.tile { min-width: 0; }
.tile .v { font-size: 1.35rem; font-weight: 500; line-height: 1.1; margin-top: 2px; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.tile .s { color: var(--ink-2); font-size: 0.78rem; font-family: var(--font); font-weight: 400; }
@media (max-width: 820px) {
  .tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 2px; padding: 0; border: 0; min-width: 0; }
  .tile { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
  .tile .eyebrow { font-size: 0.62rem; }
  .tile .v { font-size: 1.1rem; display: block; }
  .tile .s { display: none; }
}
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 0.75rem; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-2); }
.pill i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.controls { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; margin: 0 0 10px; }
.controls label { color: var(--ink-2); font-size: 0.8rem; display: inline-flex; align-items: center; gap: 6px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); color: var(--ink-2); padding: 4px 10px; font: inherit; font-size: 0.8rem; cursor: pointer; white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.seg button:focus-visible, input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=range] { width: min(100%, 420px); accent-color: var(--accent); }
.cursor-bar { margin-bottom: 8px; }
.cursorLabel { white-space: nowrap; }
.play { width: 28px; height: 28px; padding: 0; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: 0 0 auto; }
.play svg { width: 12px; height: 12px; fill: currentColor; }
.play .ico-pause, .play[aria-pressed="true"] .ico-play { display: none; }
.play[aria-pressed="true"] .ico-pause { display: block; }
.play[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.speed { height: 28px; padding: 0 9px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font: inherit; font-size: 0.75rem; font-weight: 500; cursor: pointer; flex: 0 0 auto; margin-left: -10px; }
.speed[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.cursor-bar input[type=range] { flex: 1 1 160px; }

section { margin-bottom: 26px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px; min-width: 0; }
.panel-head { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.panel-head p { color: var(--ink-2); font-size: 0.85rem; }
.canvas-wrap { position: relative; width: 100%; }
canvas { display: block; width: 100%; height: auto; }
.tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); font-size: 0.78rem; padding: 6px 8px; border-radius: 4px; white-space: nowrap; transform: translate(-50%, -115%); opacity: 0; transition: opacity .12s; z-index: 2; }
.tip.on { opacity: 1; }
.tip .num { color: inherit; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; font-size: 0.78rem; color: var(--ink-2); margin-top: 8px; }
.legend .ramp { width: 160px; height: 10px; border-radius: 2px; border: 1px solid var(--line); }
/* colour bar with ticks under it at the ends, ±half and 0; the end ticks align to the bar's ends */
.ramp-legend { align-items: flex-start; }
.ramp-legend > span:first-child { line-height: 12px; }
.ramp-scale { display: flex; flex-direction: column; gap: 2px; }
.ramp-ticks { position: relative; height: 12px; font-size: 10px; line-height: 12px; color: var(--ink-3); }
.ramp-ticks span { position: absolute; top: 0; transform: translateX(-50%); }
.ramp-ticks span:first-child { transform: none; }
.ramp-ticks span:last-child { transform: translateX(-100%); }
/* Hovmöller controls: toggles with the colour bar to their right; right-aligned if they wrap under the title */
.hov-ctl { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px 18px; margin-left: auto; }
.hov-ctl .controls { margin: 0; flex-wrap: nowrap; }
.ramp-legend { margin-top: 0; flex-wrap: nowrap; gap: 8px; white-space: nowrap; }
@media (min-width: 821px) { .hov-cursor { display: none; } }   /* beside the map, its slider would be a duplicate */
@media (max-width: 820px) {
  /* phones: both toggles on one line, colour bar on the next */
  .hov-ctl { justify-content: flex-start; gap: 6px 10px; }
  .hov-ctl .controls { gap: 8px 10px; }
  .hov-ctl .seg button { padding: 4px 7px; font-size: 0.75rem; }
  .hov-ctl .seg .u { display: none; }                       /* unit is on the colour bar beside them */
  .ramp-legend .ramp { width: 150px; }   /* room for five ticks */
}
.legend .sw, .defs .sw { display: inline-block; width: 28px; height: 8px; vertical-align: middle; margin-right: 4px; }   /* inline SVG: shows the line's dash and weight */
/* definitions of the series, full width under the panels (overview and full view) */
.defs { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px 28px; margin: 16px 0 0; font-size: 0.8rem; color: var(--ink-2); }
.defs dt { color: var(--ink); font-weight: 500; }
.defs dt .sw { margin-right: 8px; }
.defs dd { margin: 2px 0 0; }

/* Desktop: row 1 = coast profile | Hovmöller (the Hovmöller needs width, the coast needs height);
   row 2 = station list | detail charts. */
.cols { display: grid; gap: 16px; align-items: start; }
.cols-1 { grid-template-columns: minmax(300px, 3fr) 7fr; }
.cols-2 { grid-template-columns: minmax(320px, 9fr) 11fr; }
.cols-simple { grid-template-columns: var(--map-col, 400px) minmax(0, 1fr); }   /* overview: coast map (no profile) | chain chart; renderMap sets --map-col to the map's width */
.detail > .panel-head:first-child { margin-top: 0 !important; }
@media (max-width: 820px) {
  /* Single column: tiles, map, Hovmöller, station stack, detail, definitions, method link. The rows dissolve so their
     panels become direct flex children of #app and can be ordered independently. */
  #app { display: flex; flex-direction: column; }
  .cols { display: contents; }
  .cols > .panel { margin-bottom: 26px; }
  .tiles { order: 0; } #mapPanel { order: 1; } #hovSec { order: 2; } #stackPanel { order: 3; } #detailPanel { order: 4; } #chainPanel { order: 2; } #defs { order: 5; } #methodLink { order: 6; }
}
@media (max-width: 600px) {
  .intro .more { display: none; }
  .tiles { grid-template-columns: repeat(2, 1fr); }   /* phones: drop the station count */
  .tile-stations { display: none; }
}

.stack { display: flex; flex-direction: column; gap: 2px; }
.row { display: grid; grid-template-columns: 150px 1fr 64px; gap: 10px; align-items: center; padding: 3px 6px; border-radius: 4px; cursor: pointer; border: 1px solid transparent; }
.row:hover { background: var(--grid); }
.row[aria-pressed="true"] { border-color: var(--accent); background: var(--grid); }
.row .nm { font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.row .nm small { color: var(--ink-3); font-size: 0.72rem; }
.row .val { text-align: right; font-size: 0.85rem; }
.row svg { width: 100%; height: 30px; display: block; }
@media (max-width: 480px) { .row { grid-template-columns: 110px 1fr 56px; } }

.detail svg { width: 100%; height: auto; display: block; }
.detail .legend { margin-top: 4px; }
.pick { color: var(--ink-2); font-size: 0.8rem; display: inline-flex; align-items: center; gap: 6px; }
.pick select { border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); padding: 3px 6px; font: inherit; font-size: 0.8rem; }
.pick select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

table { border-collapse: collapse; width: 100%; font-size: 0.82rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--ink-3); font-weight: 500; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; }
td.r, th.r { text-align: right; }
.tbl-wrap { overflow-x: auto; }
.note { color: var(--ink-3); font-size: 0.78rem; margin-top: 10px; }
.err { background: var(--surface); border: 1px solid var(--crit); border-radius: 6px; padding: 14px 16px; }
footer.credit { margin-top: 28px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--ink-3); font-size: 0.78rem; }
@media (prefers-reduced-motion: reduce) { .tip { transition: none; } }
