:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series: #2a78d6;
  --accent: #1c5cab;
  --accent-wash: #e6f0fc;
  --error: #b42b2b;
  --error-wash: #fbeaea;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #9a988f;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series: #3987e5;
    --accent: #86b6ef;
    --accent-wash: #16273d;
    --error: #f09090;
    --error-wash: #3a1a1a;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  line-height: 1.4;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
a { color: var(--accent); }
.muted { color: var(--muted); margin: 0; font-size: 0.9rem; }
button, input { font: inherit; }

button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
  min-height: 44px;
}
button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--border); }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-box {
  width: 100%; max-width: 360px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 24px;
  display: grid; gap: 12px;
}
.login-box form { display: grid; gap: 14px; }
.login-box label { display: grid; gap: 4px; font-size: 0.95rem; color: var(--ink-2); }
.login-box input {
  padding: 10px 12px; border-radius: 8px; border: 1px solid var(--axis);
  background: var(--page); color: var(--ink); font-size: 1rem; min-height: 44px;
}
.form-error { margin: 0; padding: 8px 12px; border-radius: 8px; background: var(--error-wash); color: var(--error); }

/* ---------- layout ---------- */
.top {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 16px; max-width: 1100px; margin: 0 auto;
}
.top-actions { display: flex; gap: 8px; }
.top-actions form { margin: 0; }
main#app { max-width: 1100px; margin: 0 auto; padding: 0 16px 32px; display: grid; gap: 20px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; min-width: 0;
}
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.banner { padding: 10px 14px; border-radius: 8px; background: var(--error-wash); color: var(--error); font-size: 0.9rem; }

/* ---------- weather ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 10px; }
@media (max-width: 480px) {
  .card { padding: 12px; }
  .tile { padding: 10px; }
  .tile .value { font-size: 1.4rem; }
}
.tile { border: 1px solid var(--border); border-radius: 10px; padding: 12px; min-width: 0; }
.tile .label { font-size: 0.85rem; color: var(--ink-2); }
.tile .value { font-size: 1.6rem; font-weight: 600; margin: 2px 0; }
.tile .value small { font-size: 0.9rem; font-weight: 400; color: var(--ink-2); }
.tile .sub { font-size: 0.85rem; color: var(--muted); }
.arrow { display: inline-block; font-weight: 700; }

.chart-block { margin-top: 16px; }
.chart-title { font-size: 0.9rem; color: var(--ink-2); margin-bottom: 4px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.8rem; color: var(--ink-2); margin-top: 4px; }
.legend-key { display: inline-block; width: 22px; height: 0; border-top: 2px solid var(--series); vertical-align: middle; margin-right: 6px; }
.legend-key.dashed { border-top-style: dashed; }

.table-scroll { overflow-x: auto; margin-top: 16px; }
table.hours { border-collapse: collapse; width: 100%; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
table.hours th, table.hours td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.hours th:first-child, table.hours td:first-child { text-align: left; }
table.hours th { color: var(--ink-2); font-weight: 500; }
table.hours tr.day-row th { text-align: left; color: var(--ink); font-weight: 600; padding-top: 12px; }
@media (max-width: 480px) {
  table.hours th, table.hours td { padding: 6px 4px; font-size: 0.85rem; }
}
.more-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.more-row [hidden] { display: none; }

/* ---------- river ---------- */
.toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 14px; }
.toggle button { border-radius: 0; background: transparent; color: var(--ink); padding: 10px 8px; }
.toggle button[aria-pressed="true"] { background: var(--accent-wash); color: var(--accent); font-weight: 600; }
.toggle button small { display: block; font-weight: 400; font-size: 0.8rem; color: var(--ink-2); }

.stations { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.station-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.station-head a { font-size: 0.85rem; }
.metric { padding: 10px 0; border-top: 1px solid var(--grid); }
.metric:first-of-type { border-top: 0; }
.metric-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.metric .label { color: var(--ink-2); font-size: 0.9rem; }
.metric .value { font-size: 1.45rem; font-weight: 600; }
.metric .value small { font-size: 0.85rem; font-weight: 400; color: var(--ink-2); }
.metric .changes { font-size: 0.85rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.metric .foot { font-size: 0.8rem; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.not-measured { font-size: 0.9rem; color: var(--ink-2); }

#other-stations { margin: 18px 0 0; }
.others { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; margin-top: 14px; }
details.card > summary { list-style: none; cursor: pointer; }
details.card > summary::-webkit-details-marker { display: none; }
.summary-line { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.summary-vals { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.9rem; color: var(--ink-2); margin-top: 6px; font-variant-numeric: tabular-nums; }
.summary-vals b { color: var(--ink); font-weight: 600; }
.open-hint { font-size: 0.85rem; color: var(--accent); }
details[open] .open-hint::after { content: " ▲"; }
details:not([open]) .open-hint::after { content: " ▼"; }
details[open] > summary { margin-bottom: 8px; }

/* ---------- charts ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; touch-action: pan-y; }
.chart .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.dashed { stroke-dasharray: 5 4; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .nowline { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .axis-text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .cross { stroke: var(--axis); stroke-width: 1; }
.chart .dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; }
.tooltip {
  position: absolute; top: -6px; transform: translate(-50%, -100%); pointer-events: none;
  background: var(--ink); color: var(--page); font-size: 0.8rem; padding: 4px 8px; border-radius: 6px;
  white-space: nowrap; z-index: 2;
}
.tooltip[hidden] { display: none; }

.sources { font-size: 0.8rem; color: var(--muted); display: grid; gap: 4px; }
.sources b { color: var(--ink-2); font-weight: 500; }
