:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #6f6d68;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --s-blue: #2a78d6;
  --s-orange: #eb6834;
  --s-aqua: #1baf7a;
  --s-violet: #4a3aa7;
  --critical: #d03b3b;
  --seq-blue: #cde2fb, #9ec5f4, #6da7ec, #3987e5, #256abf, #184f95, #0d366b;
  --seq-orange: #fde3d6, #f9c0a5, #f39a73, #eb6834, #c9501f, #a03e15, #76290a;
  --empty: #ecebe7;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262624;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #9a988f;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --s-blue: #3987e5;
    --s-orange: #d95926;
    --s-aqua: #199e70;
    --s-violet: #9085e9;
    --seq-blue: #13243a, #143a66, #184f95, #256abf, #3987e5, #6da7ec, #b7d3f6;
    --seq-orange: #2e1a10, #5a2a12, #8a3a15, #b84a1c, #d95926, #f08a5d, #f9c0a5;
    --empty: #232321;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #262624;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #9a988f;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --s-blue: #3987e5;
  --s-orange: #d95926;
  --s-aqua: #199e70;
  --s-violet: #9085e9;
  --seq-blue: #13243a, #143a66, #184f95, #256abf, #3987e5, #6da7ec, #b7d3f6;
  --seq-orange: #2e1a10, #5a2a12, #8a3a15, #b84a1c, #d95926, #f08a5d, #f9c0a5;
  --empty: #232321;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main, .top, footer { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
h1 { font-size: 1.35rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: 0.95rem; margin: 0 0 4px; font-weight: 600; }
section { margin: 28px 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.error { background: color-mix(in srgb, var(--critical) 12%, var(--surface)); border: 1px solid var(--critical); padding: 10px 14px; border-radius: 8px; }

.top { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; padding-top: 18px; }
.top p { margin: 2px 0 0; font-size: 0.85rem; }
.controls { display: flex; gap: 8px; align-items: center; }

button, select, input {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; min-height: 34px;
}
button { cursor: pointer; }
button:hover { background: var(--surface-2); }
button:focus-visible, select:focus-visible, input:focus-visible, rect:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ghost { background: transparent; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; padding: 2px; background: var(--surface); flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 4px 10px; min-height: 30px; border-radius: 7px; color: var(--text-2); }
.seg button[aria-checked="true"] { background: var(--surface-2); color: var(--text); font-weight: 600; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }

/* Now */
#now { display: grid; grid-template-columns: minmax(300px, 1fr) 2fr; gap: 12px; margin-top: 16px; }
.hero { display: flex; gap: 18px; align-items: center; }
.hero-temp { font-size: 4rem; font-weight: 600; letter-spacing: -0.03em; line-height: 1; }
.hero-cond { font-weight: 600; font-size: 1.05rem; }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.tile .label { font-size: 0.8rem; color: var(--muted); }
.tile .value { white-space: nowrap; font-size: 1.45rem; font-weight: 600; letter-spacing: -0.01em; }
.tile .sub { font-size: 0.8rem; color: var(--text-2); }
.tile .row { display: flex; align-items: center; gap: 10px; }
.compass { width: 44px; height: 44px; flex: none; }
.stale { color: var(--critical); }

/* Forecast */
.forecast { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(112px, 1fr); gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.fday { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; font-size: 0.85rem; }
.fday .d { font-weight: 600; }
.fday .c { color: var(--text-2); min-height: 2.6em; }
.fday .t { font-size: 1rem; font-weight: 600; }
.fday .t span { color: var(--muted); font-weight: 400; }
.pbar { height: 4px; background: var(--surface-2); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.pbar i { display: block; height: 100%; background: var(--s-blue); border-radius: 2px; }

/* Explore */
.sec-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.sec-head h2 { margin-bottom: 8px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.range { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.range input { min-width: 0; }
.range .ghost { padding: 6px 10px; }
#download { margin-left: auto; }
#zoom button { min-width: 40px; font-size: 1.15rem; line-height: 1; }
button:disabled { opacity: 0.4; cursor: default; }
#zoom-hint { margin: -4px 0 10px; }
/* One finger scrolls the page up and down. Sideways drag pans the chart, two fingers zoom it. */
.chart-card .u-over { touch-action: pan-y; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; }
.stat .label { font-size: 0.8rem; color: var(--muted); }
.stat .value { font-size: 1.25rem; font-weight: 600; }
.stat .sub { font-size: 0.78rem; color: var(--text-2); }
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; transition: opacity .15s; }
.charts.loading { opacity: 0.45; }
.chart-card { min-width: 0; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.8rem; color: var(--text-2); }
.legend .k { display: inline-block; width: 14px; height: 2px; border-radius: 1px; vertical-align: middle; margin-right: 5px; }
.legend .k.box { height: 10px; width: 10px; border-radius: 2px; }
.chart-card .plot { width: 100%; }
.empty-note { color: var(--muted); font-size: 0.85rem; padding: 40px 0; text-align: center; }

.uplot, .uplot * { font-family: inherit; }
.u-legend { display: none; }
.u-select { background: color-mix(in srgb, var(--accent) 15%, transparent); }

.rose-card { margin-top: 12px; }
.rose-wrap { display: flex; flex-wrap: wrap; gap: 20px; align-items: center; }
#rose { width: min(340px, 100%); height: auto; }
#rose-legend { flex-direction: column; gap: 6px; }

/* History */
.cal-wrap { overflow-x: auto; }
#calendar { display: block; min-width: 720px; width: 100%; height: auto; }
#calendar rect.day { stroke: var(--surface); stroke-width: 2; cursor: pointer; }
#calendar rect.day:hover { stroke: var(--text); stroke-width: 1.5; }
#calendar text { fill: var(--muted); font-size: 10px; }
.cal-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.scale { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--muted); }
.scale .sw { display: flex; }
.scale .sw i { width: 18px; height: 10px; display: block; }
.table-card { margin-top: 12px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 6px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 500; }
td a { color: var(--accent); cursor: pointer; text-decoration: none; }
td a:hover { text-decoration: underline; }

.tip {
  position: fixed; z-index: 10; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 0.8rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15); min-width: 120px; font-variant-numeric: tabular-nums;
}
.tip .tt { color: var(--muted); margin-bottom: 4px; }
.tip .r { display: flex; align-items: center; gap: 6px; }
.tip .r b { margin-left: auto; padding-left: 10px; }
.tip .k { width: 12px; height: 2px; display: inline-block; border-radius: 1px; }

footer { padding: 20px 16px 40px; }

@media (max-width: 860px) {
  #now { grid-template-columns: 1fr; }
  .charts { grid-template-columns: 1fr; }
  #download { margin-left: 0; }
}
@media (max-width: 480px) {
  .hero-temp { font-size: 3.2rem; }
  .hero { gap: 12px; }
  .hero-side { font-size: 0.9rem; min-width: 0; }
  .hero-side > div { text-wrap: balance; }
  .tiles, .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile .value { font-size: 1.25rem; }
  #records th, #records td { padding: 6px 5px; }
  #records th:first-child, #records td:first-child { padding-left: 0; }
  #records th:last-child, #records td:last-child { padding-right: 0; }
  /* Keep the arrows and both dates on one row. */
  .range { flex-wrap: nowrap; width: 100%; gap: 4px; }
  .range label { flex: 1 1 0; min-width: 0; }
  .range input { width: 100%; padding: 6px 4px; font-size: 14px; text-align: center; }
  .range .ghost { flex: none; padding: 6px 9px; }
}

@media (max-width: 340px) {
  #records { font-size: 0.78rem; }
  #records th, #records td { padding: 6px 2px; }
}
