:root {
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --text: #1f2937;
  --text-dim: #6b7280;
  --border: #e2e6ec;
  --accent: #3b74c9;
  --status-red: #d64545;
  --status-yellow: #e0a021;
  --status-green: #2f9e6e;
  --status-neutral: #b4bcc8;
  --stale-text: #b45309;
}

* {
  box-sizing: border-box;
}

body {
  max-width: 820px;
  margin: 0 auto;
  font-family: "Noto Sans Thai", "Sarabun", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 16px;
}

h1 {
  font-size: 1.25rem;
  margin: 0 0 4px;
}

.subtitle {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0 0 20px;
}

.station-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
  padding: 16px;
  margin-bottom: 16px;
}

.station-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.station-name {
  font-weight: 600;
  font-size: 1.05rem;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  flex-shrink: 0;
  background: var(--status-neutral);
}

.status-dot[data-status="red"] {
  background: var(--status-red);
}

.status-dot[data-status="yellow"] {
  background: var(--status-yellow);
}

.status-dot[data-status="green"] {
  background: var(--status-green);
}

.station-level {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.1;
}

.station-level .unit {
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-dim);
}

.station-meta {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-top: 4px;
}

.station-meta[data-stale="true"] {
  color: var(--stale-text);
}

.chart-empty {
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 24px 0;
  text-align: center;
}

.station-role {
  color: var(--text-dim);
  font-size: 0.75rem;
  margin-left: 6px;
}

.section-title {
  font-size: 1.1rem;
  margin: 28px 0 4px;
}

.reservoir-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  margin-top: 8px;
  font-weight: 600;
}

.reservoir-stats .unit {
  font-weight: 400;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.stat-label {
  color: var(--text-dim);
  font-weight: 400;
  font-size: 0.85rem;
  margin-right: 4px;
}

.notice {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--stale-text);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 24px 0 0;
  font-size: 0.9rem;
  line-height: 1.5;
}


.flow {
  list-style: none;
  margin: 0 0 20px;
  padding: 0 0 0 22px;
  position: relative;
}

.flow::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--accent);
  opacity: 0.35;
  border-radius: 2px;
}

.flow-node {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 10px;
}

.flow-node::before {
  content: "";
  position: absolute;
  left: -22px;
  top: 16px;
  width: 11px;
  height: 11px;
  border-radius: 999px;
  background: var(--accent);
  border: 2px solid var(--bg);
}

.flow-gap {
  border-style: dashed;
  background: transparent;
}

.flow-gap::before {
  background: var(--status-neutral);
}

.flow-you {
  border-color: var(--accent);
}

.flow-you::before {
  background: var(--status-red);
}

.flow-name {
  font-weight: 600;
}

.flow-branch {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0 7px;
  margin-right: 4px;
}

.flow-role {
  color: var(--text-dim);
  font-size: 0.75rem;
  font-weight: 400;
}

.flow-value {
  font-size: 1.3rem;
  font-weight: 700;
  margin-top: 2px;
}

.flow-label {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-dim);
}

.flow-value .unit {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-dim);
}

.flow-meta {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-top: 2px;
}

.flow-meta[data-stale="true"] {
  color: var(--stale-text);
}

.trend[data-dir="rising"] {
  color: #b45309;
  font-weight: 600;
}

.trend[data-dir="falling"] {
  color: #0f766e;
  font-weight: 600;
}

.trend[data-dir="steady"] {
  color: var(--text);
  font-weight: 600;
}

.howto {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0 0 20px;
}

.howto summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
}

.legend {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 0 0 14px;
  font-size: 0.85rem;
  line-height: 1.5;
}

.legend > div + div {
  margin-top: 6px;
}

.flow-type {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}

.flow-stale {
  border-color: var(--border);
}

.stale-badge {
  color: var(--stale-text);
  font-weight: 700;
  margin-left: 4px;
}

.detail-section {
  margin-top: 8px;
}

.detail-section summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 12px;
}

.branches {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 16px;
}

@media (min-width: 760px) {
  .branches {
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
  }

  .branch {
    display: flex;
    flex-direction: column;
  }

  .branch .flow {
    flex: 1;
  }
}

.branch-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--accent);
  margin: 0 0 8px;
}

/* ---- river line: one colour per river, lines run continuously into the merge ---- */
.flow {
  --line: var(--accent);
}

.flow::before {
  background: var(--line);
  opacity: 0.6;
}

.flow-node::before {
  background: var(--line);
}

.flow-you::before {
  background: var(--status-red);
}

.branch .flow {
  margin-bottom: 4px;
}

.branch .flow::before {
  bottom: 14px;
}

.flow-end {
  position: relative;
  color: var(--line);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0 0 8px 4px;
}

.flow-end::before {
  content: "";
  position: absolute;
  left: -22px;
  top: 4px;
  width: 11px;
  height: 11px;
  border-radius: 999px;
  background: var(--line);
  border: 2px solid var(--bg);
}

.flow-merge {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 10px;
  font-size: 0.85rem;
  line-height: 1.5;
}

.flow-merge::before {
  content: "";
  position: absolute;
  left: -22px;
  top: 14px;
  width: 11px;
  height: 11px;
  border-radius: 999px;
  background: var(--accent);
  border: 2px solid var(--bg);
}

.flow-main {
  margin-top: 0;
}

.flow-main::before {
  top: -14px;
}

.branch:last-child .flow {
  margin-bottom: 0;
}

.branch:last-child .flow::before {
  bottom: -14px;
}

/* phones: comfortable tap/reading sizes, nothing wider than the screen */
@media (max-width: 480px) {
  body {
    padding: 12px;
  }

  h1 {
    font-size: 1.15rem;
  }

  .flow {
    padding-left: 20px;
  }

  .flow-node {
    padding: 10px 12px;
  }

  .flow-value {
    font-size: 1.25rem;
  }

  .legend,
  .notice {
    font-size: 0.85rem;
  }
}

/* wide screens: a real join — both branch lines run down and meet the trunk */
@media (min-width: 760px) {
  .branches {
    position: relative;
    padding-bottom: 18px;
  }

  .branch .flow::before {
    bottom: -18px;
  }

  .branches::after {
    content: "";
    position: absolute;
    left: 8px;
    right: calc(50% - 16px);
    bottom: 0;
    height: 3px;
    background: var(--accent);
    opacity: 0.6;
    border-radius: 2px;
  }

  .flow-main::before {
    top: -18px;
  }
}

/* ---- node layout: text left, trend charts right (stacked below on phones) ---- */
.flow-body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px 16px;
}

@media (min-width: 620px) {
  .flow-body {
    grid-template-columns: 1fr 230px;
    /* A wide column gap keeps the text column (bank bar, its labels) clear of the chart's ticks. */
    gap: 8px 40px;
    align-items: start;
  }
}

.flow-sparks {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.spark-label {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.spark svg {
  width: 100%;
  height: 120px; /* was 56 px: too short to read a trend */
  display: block;
}

.spark-line {
  fill: none;
  stroke: var(--line);
  vector-effect: non-scaling-stroke;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

/* an HTML circle placed over the stretched svg, so it stays round in every browser */
.spark-dot {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--line);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.spark-cap {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.spark-empty {
  font-size: 0.75rem;
  color: var(--text-dim);
  padding: 14px 0;
}

/* dam capacity: font colour only, on the official Royal Irrigation Dept bands.
   More than 80-100% (น้ำมาก) = red; over 100% (เกินความจุเก็บกัก) = brighter red.
   Lower bands are drought categories, shown as plain text. */
.band {
  font-weight: 700;
}

.band[data-band="high"] {
  color: #b91c1c;
}

.band[data-band="over"] {
  color: #e60000;
}

.band .unit {
  color: inherit;
}

.band-tag {
  font-weight: 700;
}

.band-tag[data-band="high"] {
  color: #b91c1c;
}

.band-tag[data-band="over"] {
  color: #e60000;
}

/* the two upstream branches share a row on wide screens, so their cards stay single-column */
.branch .flow-body {
  grid-template-columns: 1fr;
}

.trend-note {
  color: var(--text-dim);
  font-size: 0.8rem;
}

.station-card {
  --line: var(--accent);
}

/* hourly ticker under the gauge charts */
.spark-grid {
  stroke: var(--border);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.spark-axis {
  position: relative;
  height: 1.1rem;
  margin-top: 2px;
}

.tick {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
}

/* phones: keep every hourly tick line, but label every second hour when crowded */
@media (max-width: 480px) {
  .spark-axis.dense .tick:nth-of-type(even) {
    visibility: hidden;
  }
}

/* collector health: one plain line; font colour only when it is not healthy */
.health {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 0 0 12px;
}

.health-warn {
  color: #b91c1c;
  font-weight: 700;
}

/* ---- phones: two rivers must not read as one line ---- */
.merge-diagram {
  margin: 4px 0 12px;
  text-align: center;
  color: var(--accent);
}

.merge-diagram .md-top {
  display: flex;
  justify-content: space-around;
  font-size: 0.8rem;
  font-weight: 700;
}

.merge-diagram svg {
  width: 100%;
  height: 46px;
  display: block;
}

.merge-diagram path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  opacity: 0.6;
  vector-effect: non-scaling-stroke;
}

.merge-diagram .md-bottom {
  font-size: 0.8rem;
  font-weight: 700;
}

@media (max-width: 759px) {
  /* the diagram above already says the two rivers merge; do not repeat it in the text */
  .merge-lead {
    display: none;
  }

  .branch {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 10px 10px 2px;
    margin-bottom: 10px;
  }

  .branch .flow-node {
    background: var(--bg);
  }
}

@media (min-width: 760px) {
  .merge-diagram {
    display: none;
  }
}

/* collapsed reading guide */
.howto {
  margin: 0 0 12px;
}

.howto ul {
  margin: 8px 0;
  padding-left: 20px;
  line-height: 1.55;
}

.stations-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  margin: 8px 0 4px;
}

.stations-table th,
.stations-table td {
  text-align: left;
  vertical-align: top;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
}

.table-note {
  font-size: 0.75rem;
  margin: 0 0 8px;
}

/* ---- situation card: the user's own area first ---- */
.here {
  margin: 0 0 20px;
}

.here-sub {
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 400;
  margin-left: 6px;
}

.here-grid {
  --line: var(--accent);
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 760px) {
  .here-grid {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

.here-grid .flow-node {
  margin: 0;
}

.here-grid .flow-node::before {
  display: none;
}

.here-grid .flow-body {
  grid-template-columns: 1fr;
}

.here-summary {
  font-size: 0.9rem;
  line-height: 1.6;
}

.here-more {
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* ---- hierarchy: the watched area is the main panel; the river line is supporting info ---- */
.here {
  background: var(--card-bg);
  border: 2px solid var(--accent);
  border-radius: 16px;
  padding: 16px;
  margin: 0 0 8px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

.here .section-title {
  font-size: 1.4rem;
  margin: 0 0 12px;
}

.here .here-sub {
  font-size: 0.95rem;
}

.here .flow-node {
  background: var(--bg);
  border: none;
}

.here .flow-name {
  font-size: 1.1rem;
}

.here .flow-value {
  font-size: 2rem;
}

.here-summary {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.context {
  margin-top: 40px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.context-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.context .section-title {
  font-size: 1rem;
  color: var(--text-dim);
  margin-top: 0;
}

/* the panel is filled by script; never show an empty bordered card while loading or on failure */
.here:empty {
  display: none;
}

.site-switch {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
}

/* Daily bar chart (reservoir % of capacity, one bar per day). */
.bars {
  display: flex;
  gap: 6px;
  align-items: flex-end;
}
.bar-col {
  flex: 1;
  min-width: 0;
  max-width: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.bar-track {
  width: 100%;
  height: 56px;
  display: flex;
  align-items: flex-end;
  border-bottom: 1px solid var(--border);
}
.bar {
  width: 100%;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  min-height: 1px;
}
.bar-col:last-child .bar {
  opacity: 1;
}
.bar-col:not(:last-child) .bar {
  opacity: 0.55;
}
.bar-val,
.bar-day {
  font-size: 0.7rem;
  color: var(--text-dim);
  white-space: nowrap;
}
.bar-col:last-child .bar-val {
  color: var(--text);
  font-weight: 600;
}

/* Level against the bank: a pill (text + shape) and a thin position bar. No severity colour. */
.bank-pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1.5px solid var(--text-dim);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.85rem;
}
.bank-pill[data-side="above"],
.bank-pill[data-side="at"] {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}
.bank-bar {
  position: relative;
  height: 8px;
  margin: 8px 0 2px;
  border-radius: 4px;
  background: var(--border);
}
.bank-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 4px;
  background: var(--text-dim);
  opacity: 0.35;
}
.bank-tick {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  margin-left: -1px;
  background: var(--text);
}
.bank-dot {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: var(--text-dim);
  border: 2px solid var(--card-bg);
  box-sizing: border-box;
}
.bank-dot[data-side="above"] {
  background: var(--text);
}
.bank-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: var(--text-dim);
}

/* The page's own alert (level >= 1 m above the bank). Always paired with text saying it is not an official threshold. */
.bank-pill[data-alert="true"] {
  background: var(--status-red);
  border-color: var(--status-red);
  color: #fff;
}
.flow-alert {
  border-color: var(--status-red);
  box-shadow: 0 0 0 1px var(--status-red);
}
.alert-note,
.alert-banner {
  color: var(--status-red);
  font-weight: 600;
  font-size: 0.85rem;
}
.alert-note .unit,
.alert-banner .unit {
  color: var(--text-dim);
  font-weight: 400;
}
.alert-banner {
  border: 1.5px solid var(--status-red);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 10px;
}

/* A subtle, permanent remark: no box, no colour, just small grey text. */
.remark {
  color: var(--text-dim);
  font-size: 0.8rem;
  line-height: 1.4;
  margin: -6px 0 10px;
}

/* Card rhythm: metric groups are spaced apart; explanations sit apart in small grey "remark" text. */
.flow-group {
  margin-top: 10px;
}
.flow-group .flow-meta:first-child {
  margin-top: 0;
}
.flow-remark {
  color: var(--text-dim);
  font-size: 0.75rem;
  line-height: 1.45;
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}
.bank-scale {
  margin-bottom: 4px;
}
.flow-sparks {
  margin-top: 6px;
}

/* Window toggle: stays in view while scrolling so every box can be compared at one span */
.window-toggle {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.wt-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.wt-label {
  font-size: 0.85rem;
  color: var(--text-dim);
}
.wt-buttons {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--card-bg);
}
.wt-btn {
  font: inherit;
  font-size: 0.9rem;
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.wt-btn:last-child {
  border-right: 0;
}
.wt-btn[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}
.wt-note {
  margin: 4px 0 8px;
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* 24 h axes cross midnight: the date label replaces the clock label and its grid line is firmer */
.tick[data-midnight] {
  font-weight: 700;
  color: var(--text);
}
.spark-grid[data-midnight] {
  stroke: var(--text-dim);
}
/* the box has less data than the chosen Window */
.spark-cover {
  font-size: 0.75rem;
  color: var(--stale-text);
}

/* phones: thumb-sized toggle buttons */
@media (max-width: 480px) {
  .wt-btn {
    min-height: 44px;
    padding: 0 16px;
  }
}

/* chart (chart.js): a labelled vertical scale, shaded gaps, a dashed reference line */
.spark-plot {
  margin-left: 2.7rem; /* the left margin carries the scale labels */
}
.spark-canvas {
  position: relative;
}
.spark-ylab,
.spark-yunit {
  position: absolute;
  right: calc(100% + 5px);
  font-size: 0.68rem;
  line-height: 1;
  color: var(--text-dim);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.spark-ylab {
  transform: translateY(-50%);
}
.spark-ylab.ref {
  color: var(--text);
  font-weight: 700;
}
.spark-yunit {
  top: 0.15rem;
}
.spark-hgrid {
  stroke: var(--border);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}
.spark-ref {
  stroke: var(--text);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
  vector-effect: non-scaling-stroke;
}
.spark-gap {
  fill: rgba(180, 83, 9, 0.1);
}
.spark-gaplab {
  position: absolute;
  top: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.72rem;
  color: var(--stale-text);
  pointer-events: none;
}
.spark-dot-small {
  width: 5px;
  height: 5px;
}
.spark-legend {
  margin-top: 2px;
  font-size: 0.75rem;
  color: var(--text-dim);
}
.spark-legend-line {
  display: inline-block;
  width: 1.4rem;
  border-top: 2px dashed var(--text);
  vertical-align: middle;
  margin-right: 6px;
}

/* a unit stays on the line with its number ("2,141 ลบ.ม./วินาที" must not split) */
.flow-value .unit {
  white-space: nowrap;
}

/* the river-flow figure is long ("อัตราการไหลของแม่น้ำ ≈ 2,141 ลบ.ม./วินาที"): label above, number and unit together below */
.flow-q .flow-label {
  display: block;
}

.tick.edge {
  visibility: hidden;
}

/* Photharam's own reference lines (the page's, not official). Yellow, amber, red; each is also named in words. */
.spark-ref[data-level="yellow"] { stroke: #e0a800; }
.spark-ref[data-level="amber"] { stroke: #ef6c00; }
.spark-ref[data-level="red"] { stroke: #d50000; stroke-width: 2.5; }
.spark-ylab.ref[data-level="yellow"] { color: #9a7400; }
.spark-ylab.ref[data-level="amber"] { color: #c25400; }
.spark-ylab.ref[data-level="red"] { color: #d50000; }
.spark-legend-item { white-space: nowrap; margin-right: 8px; }
.spark-legend-line[data-level="yellow"] { border-top-color: #e0a800; }
.spark-legend-line[data-level="amber"] { border-top-color: #ef6c00; }
.spark-legend-line[data-level="red"] { border-top-color: #d50000; border-top-width: 3px; }

/* with reference lines the chart is taller, so the lines and their labels have room */
.spark-plot[data-tall] svg {
  height: 150px;
}

/* the height the chart stands for, printed so steepness is never guessed */
.spark-scale {
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* ==== Look: light glass cards, big numerals, sticky pill, springy motion (see look.js) ====
   Motion deliberately ignores prefers-reduced-motion (maintainer's decision: most people set it to save battery).
   Status colours and Reference line colours are untouched: this is styling only. */
:root {
  --bg: #eaf2f7;
  --card-bg: #ffffff;
  --text: #1c3447;
  --text-dim: #5d7384;
  --border: rgba(24, 66, 92, .10);
  --accent: #1b72a8;
  --ease: cubic-bezier(.32, .72, 0, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --shadow: 0 1px 2px rgba(20, 60, 88, .06), 0 10px 30px -12px rgba(20, 60, 88, .22);
}
html { background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  background: linear-gradient(180deg, #dcebf4 0, #eef5f9 340px, #f5f9fb 100%);
  padding: 0 16px 24px;
}
h1 { font-size: 1.15rem; letter-spacing: -.01em; margin: 14px 0 6px; display: flex; align-items: center; gap: 8px; }

/* live dot */
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: #1f9d6b; flex: none; box-shadow: 0 0 0 0 rgba(31,157,107,.5); }

/* ---- sticky pill: sites + window toggle in ONE bar ---- */
.pill {
  position: sticky; top: 8px; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 0 0 10px; padding: 3px;
  min-height: 48px;
  background: rgba(255,255,255,.78);
  -webkit-backdrop-filter: blur(14px) saturate(1.4); backdrop-filter: blur(14px) saturate(1.4);
  border: 1px solid rgba(255,255,255,.9);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.pill-sites { display: flex; gap: 2px; }
.pill-sites a {
  white-space: nowrap;
  display: grid; place-items: center; min-height: 45px; padding: 0 14px; border-radius: 999px;
  color: var(--text-dim); text-decoration: none; font-size: .92rem; font-weight: 600;
  transition: background .35s var(--ease), color .35s var(--ease);
}
.pill-sites a.on { background: var(--accent); color: #fff; }
.pill .window-toggle { position: static; background: none; border: 0; padding: 0; }
.pill .wt-label { display: none; }
.pill .wt-buttons { border: 0; background: rgba(27,114,168,.08); border-radius: 999px; padding: 2px; }
.pill .wt-btn { white-space: nowrap; min-height: 45px; min-width: 40px; padding: 0 10px; border: 0 !important; border-radius: 999px; font-size: .85rem; transition: background .35s var(--ease), color .35s var(--ease), transform .35s var(--ease); }
.pill .wt-btn:active { transform: scale(.94); }
.pill .wt-btn[aria-pressed="true"] { background: #fff; color: var(--accent); box-shadow: 0 1px 4px rgba(20,60,88,.18); }
.wt-note { font-size: .74rem; }
@media (max-width: 480px) {
  .pill-sites a { padding: 0 11px; font-size: .86rem; }
  .pill .wt-btn { padding: 0 8px; min-width: 38px; font-size: .8rem; }
}
@media (max-width: 340px) {
  /* iPhone SE (1st gen) and older: keep the pill on ONE row */
  .pill { gap: 4px; }
  .pill-sites a { padding: 0 8px; font-size: .8rem; }
  .pill .wt-btn { padding: 0 5px; min-width: 36px; font-size: .74rem; }
}

/* ---- cards ---- */
.here {
  border: 1px solid rgba(255,255,255,.9);
  border-radius: 26px;
  background: rgba(255,255,255,.88);
  box-shadow: var(--shadow);
  padding: 18px 14px 14px;
}
.here .section-title { font-size: 1.5rem; letter-spacing: -.02em; }
.here .flow-node {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 1px 2px rgba(20,60,88,.05);
}
.station-card, .flow-node { border-radius: 20px; border-color: var(--border); }
.station-card { box-shadow: var(--shadow); background: #fff; }
.here .flow-name { font-size: 1.15rem; font-weight: 700; letter-spacing: -.01em; }

/* ---- big numerals; the label shrinks to a caption above ---- */
.here .flow-value, .station-level {
  font-size: 3.4rem;
  font-weight: 800;
  letter-spacing: -.04em;
  line-height: 1.02;
  font-variant-numeric: tabular-nums;
  color: #0e2536;
}
.here .flow-value .flow-label, .flow-value .flow-label {
  display: block; font-size: .8rem; font-weight: 600; letter-spacing: 0; color: var(--text-dim); margin-bottom: 2px;
}
.here .flow-value .unit, .station-level .unit { font-size: .95rem; font-weight: 500; letter-spacing: 0; color: var(--text-dim); }
.here .flow-q.flow-value { font-size: 2.3rem; }
@media (max-width: 480px) {
  .here .flow-value, .station-level { font-size: 3rem; }
  .here .flow-q.flow-value { font-size: 2rem; }
}
.flow-type { letter-spacing: .02em; }
.trend { font-weight: 700; }

/* chart line a touch heavier and rounder */
.spark-line { stroke-width: 2.5; }


/* ---- motion ---- */
@keyframes c-rise { 0% { opacity: 0; transform: translateY(28px) scale(.97); } 60% { opacity: 1; transform: translateY(-4px) scale(1.003); } 100% { transform: none; } }
@keyframes c-wave { from { background-position-x: 0; } to { background-position-x: 320px; } }
@keyframes c-wave2 { from { background-position-x: 0; } to { background-position-x: -320px; } }
@keyframes c-sonar { 0% { transform: translate(-50%,-50%) scale(.4); opacity: .55; } 100% { transform: translate(-50%,-50%) scale(3.2); opacity: 0; } }
@keyframes c-pulse { 0% { box-shadow: 0 0 0 0 rgba(31,157,107,.55); } 70%, 100% { box-shadow: 0 0 0 12px rgba(31,157,107,0); } }
@keyframes c-shimmer { from { transform: translateX(-120%) skewX(-18deg); } to { transform: translateX(260%) skewX(-18deg); } }
@keyframes c-drift { from { transform: translateY(0) translateX(0); opacity: 0; } 15% { opacity: .55; } to { transform: translateY(-110vh) translateX(24px); opacity: 0; } }
@keyframes c-reveal { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes c-pop { 0% { opacity: 0; transform: translate(-50%,-50%) scale(0); } 70% { transform: translate(-50%,-50%) scale(1.8); } 100% { opacity: 1; transform: translate(-50%,-50%) scale(1); } }
@keyframes c-grad { from { background-position: 0% 50%; } to { background-position: 200% 50%; } }

body { background: linear-gradient(180deg, #cfe5f2 0, #e6f1f7 380px, #f4f8fb 100%); }

/* layered waves behind the top of the page */
body::before, body::after {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 190px; pointer-events: none; z-index: 0;
  background-repeat: repeat-x; background-size: 320px 60px; background-position: 0 100%;
}
body::before { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='60' viewBox='0 0 320 60'%3E%3Cpath d='M0 30 Q40 6 80 30 T160 30 T240 30 T320 30 V60 H0Z' fill='%231b72a8' fill-opacity='.10'/%3E%3C/svg%3E"); animation: c-wave 14s linear infinite; }
body::after { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='60' viewBox='0 0 320 60'%3E%3Cpath d='M0 36 Q40 14 80 36 T160 36 T240 36 T320 36 V60 H0Z' fill='%231b72a8' fill-opacity='.14'/%3E%3C/svg%3E"); animation: c-wave2 9s linear infinite; }
body { position: relative; }
h1, .health, .window-toggle, .here, .context, .notice { position: relative; z-index: 1; }

/* drifting bubbles (JS-free: three pseudo layers via radial gradients on html) */
html::before {
  content: ""; position: fixed; left: 0; right: 0; bottom: -20px; height: 24px; pointer-events: none; z-index: 0;
  background:
    radial-gradient(circle 5px at 12% 50%, rgba(27,114,168,.35), transparent 70%),
    radial-gradient(circle 4px at 47% 50%, rgba(27,114,168,.3), transparent 70%),
    radial-gradient(circle 6px at 81% 50%, rgba(27,114,168,.3), transparent 70%);
  animation: c-drift 12s linear infinite;
}

/* springy staggered entrances */
.pill, h1, .health, .here, .context, .notice { animation: c-rise 1s var(--ease-out) both; }
h1 { animation-delay: .02s; } .pill { animation-delay: .1s; } .here { animation-delay: .2s; } .context { animation-delay: .5s; }
.here .flow-node, .station-card, .branch, .here-summary { animation: c-rise 1s var(--ease-out) both; }
.here .flow-node:nth-child(1) { animation-delay: .3s; } .here .flow-node:nth-child(2) { animation-delay: .42s; }
.here-summary { animation-delay: .56s; }
.station-card:nth-child(2) { animation-delay: .1s; } .station-card:nth-child(3) { animation-delay: .2s; } .station-card:nth-child(4) { animation-delay: .3s; }
.flow-node:nth-child(odd) { animation-delay: .05s; }

/* live dot with sonar ring */
.live-dot { position: relative; animation: c-pulse 2s ease-out infinite; }
.live-dot::after { content: ""; position: absolute; left: 50%; top: 50%; width: 10px; height: 10px; border-radius: 50%; border: 2px solid #1f9d6b; animation: c-sonar 2s ease-out infinite; }

/* headline panel breathes; shimmer sweeps once across each card on load */
.here { animation: c-rise 1s var(--ease-out) .2s both; }
.here .flow-node, .station-card { position: relative; overflow: hidden; }
.here .flow-node::after, .station-card::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 40%; pointer-events: none;
  background: linear-gradient(100deg, transparent, rgba(255,255,255,.75), transparent);
  transform: translateX(-120%) skewX(-18deg);
  animation: c-shimmer 1.4s var(--ease) .9s 1 both;
}
.here .flow-node::before { display: none; }

/* big numerals get a flowing blue gradient */
.here .flow-value .num, .station-level .num {
  background: linear-gradient(90deg, #0e2536, #1b72a8, #0e2536); background-size: 200% 100%;
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent;
  animation: c-grad 6s linear infinite;
}

/* chart: draw, then a sonar ping from the newest point */
.spark-plot svg { animation: c-reveal 1.4s var(--ease-out) .5s both; }
.spark-dot { animation: c-pop .7s var(--ease-out) 1.6s both; }
.spark-dot:not(.spark-dot-small)::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 9px; height: 9px; border-radius: 50%;
  border: 2px solid var(--line); animation: c-sonar 2.2s ease-out 2.2s infinite;
}

/* hover/press */
.station-card, .here .flow-node { transition: transform .5s var(--ease), box-shadow .5s var(--ease); }
@media (hover: hover) { .station-card:hover, .here .flow-node:hover { transform: translateY(-4px); } }
.pill-sites a.on { background: linear-gradient(135deg, #1b72a8, #2a93c9); box-shadow: 0 4px 14px -4px rgba(27,114,168,.6); }

/* ---- Below โพธาราม, in the main diagram: RID's distance to the next station, the pooling note. No status colour. ---- */
.flow-link { margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--border); font-size: .8rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.flow-untracked { background: transparent; border-style: dashed; }
.pool-note { margin: 4px 0 6px; font-size: .9rem; line-height: 1.5; color: var(--text); }
.rl-cap { font-size: .78rem; line-height: 1.5; color: var(--text-dim); margin-bottom: 16px; }
