:root {
  color-scheme: light dark;
  --bg: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #86857f;
  --good: #008300;
  --bad: #e34948;
  --accent: #2a78d6;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 1px 8px rgba(0, 0, 0, .04);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131312;
    --surface-1: #1f1f1d;
    --surface-2: #262624;
    --border: #34342f;
    --text-primary: #f4f4f0;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e84;
    --good: #33a852;
    --bad: #e66767;
    --accent: #3987e5;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text-primary);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--text-muted); }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: .2px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-muted); flex: 0 0 auto; }
.dot.ok { background: var(--good); }
.dot.bad { background: var(--bad); }
.updated { font-size: 13px; color: var(--text-secondary); }

main { max-width: 1080px; margin: 0 auto; padding: 20px; }

/* ---- current conditions ---- */
.now {
  display: grid; grid-template-columns: minmax(200px, 260px) minmax(150px, 180px) 1fr; gap: 16px;
  margin-bottom: 26px;
}
@media (max-width: 900px) { .now { grid-template-columns: 1fr 1fr; } .now .tiles { grid-column: 1 / -1; } }
.hero {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px; display: flex; flex-direction: column; justify-content: center;
}
.hero-temp { font-size: 64px; font-weight: 300; line-height: 1; letter-spacing: -2px; }
.hero-temp .unit { font-size: 26px; color: var(--text-secondary); margin-left: 4px; }
.hero-sub { margin-top: 12px; display: flex; flex-direction: column; gap: 3px; font-size: 14px; }

/* wind compass */
.compass {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
}
.compass-svg { width: 100%; max-width: 150px; height: auto; }
.compass-svg .c-ring { fill: none; stroke: var(--border); stroke-width: 2; }
.compass-svg .c-tick { stroke: var(--text-muted); stroke-width: 1.5; }
.compass-svg .c-card { fill: var(--text-secondary); font-size: 11px; font-weight: 600; text-anchor: middle; dominant-baseline: middle; }
.compass-svg .c-n { fill: var(--bad); }
.compass-svg .c-needle { fill: var(--accent); transition: transform .5s cubic-bezier(.2,.7,.2,1); transform-origin: 60px 60px; }
.compass-svg #compassNeedle { transition: transform .5s cubic-bezier(.2,.7,.2,1); transform-origin: 60px 60px; }
.compass-svg .c-hub { fill: var(--text-secondary); }
.c-readout { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.c-readout #compassDir { font-size: 17px; font-weight: 600; }
.c-readout #compassSpd { font-size: 12px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 4px;
}
.tile .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; }
.tile .value { font-size: 24px; font-weight: 450; }
.tile .value .u { font-size: 14px; color: var(--text-secondary); font-weight: 400; margin-left: 2px; }
.tile .sub { font-size: 12px; color: var(--text-secondary); }

/* wind compass arrow */
.arrow { display: inline-block; transition: transform .4s ease; }

/* ---- history ---- */
.history-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.history-head h2 { font-size: 16px; margin: 0; font-weight: 600; }
.ranges { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.ranges button {
  border: 0; background: transparent; color: var(--text-secondary);
  font: inherit; font-size: 13px; padding: 5px 12px; border-radius: 8px; cursor: pointer;
}
.ranges button:hover { color: var(--text-primary); }
.ranges button.active { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow); font-weight: 550; }

/* wind rose */
.rose-card { margin-bottom: 16px; }
.rose-body { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; justify-content: center; }
.rose-plot { flex: 0 0 auto; }
.rose-svg { width: 260px; max-width: 100%; height: auto; }
.rose-svg .rose-ring { fill: none; stroke: var(--border); stroke-width: 1; }
.rose-svg .rose-pct { fill: var(--text-muted); font-size: 9px; }
.rose-svg .rose-card { fill: var(--text-secondary); font-size: 12px; font-weight: 600; }
.rose-svg .rose-petal { stroke: var(--surface-1); stroke-width: 1; }
.rose-empty { padding: 40px 10px; text-align: center; }
.rose-legend { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.rose-legend .rl-item { display: flex; align-items: center; gap: 7px; color: var(--text-secondary); }
.rose-legend .rl-sw { width: 14px; height: 14px; border-radius: 3px; flex: 0 0 auto; }

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 16px 10px; min-width: 0;
}
.card h3 { font-size: 14px; margin: 0 0 2px; font-weight: 600; }
.card .card-unit { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.card .uplot { width: 100% !important; }

.foot { max-width: 1080px; margin: 0 auto; padding: 4px 20px 30px; font-size: 12px; }

/* uPlot tooltip */
.u-tip {
  position: absolute; z-index: 10; pointer-events: none;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 2px 12px rgba(0,0,0,.14);
  padding: 7px 10px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -120%);
  color: var(--text-primary);
}
.u-tip .t-time { color: var(--text-muted); margin-bottom: 3px; }
.u-tip .t-row { display: flex; align-items: center; gap: 6px; }
.u-tip .t-swatch { width: 9px; height: 9px; border-radius: 2px; flex: 0 0 auto; }
.u-tip .t-val { font-weight: 600; margin-left: auto; }

/* uPlot theme tweaks */
.u-legend { font-size: 12px; }
.u-title { display: none; }

@media (max-width: 620px) {
  .now { grid-template-columns: 1fr; }
  .hero { align-items: center; text-align: center; }
}
