/* SkyNode Weather
   Layout: one centred column (max 1080px); a sticky search bar, then "now", a 48 h chart
   with an hour strip, and a 10-day table. Temperatures use the meteorological convention:
   warm colour at or above 0 °C, cold colour below. */
:root {
  --bg: #F2F5F8;
  --surface: #FFFFFF;
  --surface-2: #E9EEF3;
  --ink: #102030;
  --muted: #566778;
  --line: #D8E0E8;
  --accent: #1F5FBF;
  --warm: #C2412A;
  --cold: #1D68C9;
  --rain: #3B8EE8;
  --rain-soft: #3B8EE833;
  --focus: #1F5FBF;

  --f-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --f-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --f-data: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0C131A; --surface: #131D27; --surface-2: #1A2633; --ink: #E7EEF5; --muted: #93A5B6;
    --line: #243443; --accent: #79AEFF; --warm: #FF7B5E; --cold: #6DB3FF; --rain: #4EA2FF;
    --rain-soft: #4EA2FF40; --focus: #79AEFF; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0C131A; --surface: #131D27; --surface-2: #1A2633; --ink: #E7EEF5; --muted: #93A5B6;
  --line: #243443; --accent: #79AEFF; --warm: #FF7B5E; --cold: #6DB3FF; --rain: #4EA2FF;
  --rain-soft: #4EA2FF40; --focus: #79AEFF; color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.5 var(--f-body);
}
img { max-width: 100%; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap {
  max-width: 1080px;
  margin-inline: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-inner {
  max-width: 1080px;
  margin-inline: auto;
  padding-block: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  color: var(--ink); text-decoration: none;
  font: 600 19px/1 var(--f-display);
  letter-spacing: -0.01em;
}
.brand b { font-weight: 400; color: var(--muted); }
.brand svg { color: var(--accent); }

.search {
  position: relative;
  flex: 1 1 280px;
  min-width: 0;
  display: flex; align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding-inline: 14px 6px;
}
.search:focus-within { border-color: var(--accent); }
.search-icon { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search input {
  flex: 1; min-width: 0;
  border: 0; background: transparent; color: var(--ink);
  font: 400 16px var(--f-body);
  padding: 10px 10px;
}
.search input:focus { outline: none; }
.search-go {
  flex: none; border: 0; border-radius: 999px; cursor: pointer;
  background: var(--accent); color: var(--surface);
  font: 600 14px var(--f-body); padding: 8px 14px; margin-right: 4px;
}
.search-go:hover { filter: brightness(1.08); }
.icon-btn {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

.results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px);
  margin: 0; padding: 6px; list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 32px #0000001f;
  max-height: 60vh; overflow-y: auto;
}
.results li {
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  display: flex; flex-direction: column;
}
.results li small { color: var(--muted); font-size: 13px; }
.results li[aria-selected="true"], .results li:hover { background: var(--surface-2); }
.results .empty { color: var(--muted); cursor: default; }

.units { display: flex; gap: 4px; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.seg {
  border: 0; background: transparent; color: var(--ink);
  font: 500 14px var(--f-data);
  padding: 6px 12px; min-width: 52px; border-radius: 999px; cursor: pointer;
}
.seg:hover { background: var(--surface-2); }

.recent {
  max-width: 1080px; margin-inline: auto;
  padding-bottom: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
}
.recent:empty { display: none; }
.chip {
  flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 4px 6px 4px 12px; font: 500 13px var(--f-body); cursor: pointer;
}
.chip .t { font-family: var(--f-data); }
.chip .name { border: 0; background: none; color: inherit; font: inherit; padding: 0; cursor: pointer; }
.chip .x { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 999px; font-size: 14px; line-height: 1; }
.chip .x:hover { background: var(--surface-2); color: var(--ink); }
.chip[aria-current="true"] { border-color: var(--accent); }

/* ---------- main ---------- */
main { display: flex; flex-direction: column; gap: 20px; padding-block: 24px 8px; }
.status { color: var(--muted); margin: 8px 0; }
.status.error { color: var(--warm); }

.now {
  display: flex; flex-direction: column; gap: 18px;
  padding: 24px 0 4px;
}
.now-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.now h1 {
  margin: 0;
  font: 700 clamp(32px, 6vw, 52px)/1 var(--f-display);
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.place-sub { margin: 6px 0 0; color: var(--muted); }
.clock { margin: 0; color: var(--muted); font: 400 14px var(--f-data); }

.now-body {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: center;
}
.now-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.now-icon { width: clamp(88px, 16vw, 132px); height: auto; flex: none; }
.now-temp {
  margin: 0;
  font: 400 clamp(72px, 13vw, 128px)/0.9 var(--f-display);
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.now-temp .deg { font-size: 0.45em; vertical-align: 0.9em; margin-left: 2px; color: var(--muted); letter-spacing: 0; }
.warm { color: var(--warm); }
.cold { color: var(--cold); }
.now-desc { margin: 8px 0 0; font: 600 20px var(--f-display); }
.now-feels { margin: 2px 0 0; color: var(--muted); }

.now-stats {
  margin: 0;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.now-stats > div { background: var(--surface); padding: 12px 16px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.now-stats dt { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.now-stats dd { margin: 0; font: 500 18px var(--f-data); display: flex; align-items: center; gap: 8px; }
.now-stats dd small { font: 400 13px var(--f-body); color: var(--muted); }
.arrow { width: 18px; height: 18px; color: var(--accent); flex: none; }

.nowcast {
  margin: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--surface-2);
}
.nowcast .drop { width: 18px; height: 18px; color: var(--rain); flex: none; }

/* ---------- panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  display: flex; flex-direction: column; gap: 14px;
  min-width: 0;
}
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.panel h2 { margin: 0; font: 600 20px var(--f-display); text-wrap: balance; }
.legend { margin: 0; color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.key { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }
.key-temp { background: var(--warm); }
.key-rain { background: var(--rain); height: 10px; width: 8px; margin-left: 8px; border-radius: 2px; }

.chart-wrap { min-width: 0; }
#chart { display: block; width: 100%; height: 200px; }
#chart text { font: 400 11px var(--f-data); fill: var(--muted); }
#chart .now-line { stroke: var(--accent); stroke-dasharray: 3 4; }

.hours {
  display: grid; grid-auto-flow: column; grid-auto-columns: 64px;
  overflow-x: auto; gap: 2px;
  padding-bottom: 6px;
  scrollbar-width: thin;
}
.hour {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 0; border-radius: 10px;
  font-variant-numeric: tabular-nums;
}
.hour:first-child { background: var(--surface-2); }
.hour .h { font: 500 13px var(--f-data); color: var(--muted); }
.hour img { width: 36px; height: 36px; }
.hour .t { font: 600 16px var(--f-data); }
.hour .p { font: 400 12px var(--f-data); color: var(--rain); min-height: 1.2em; }
.hour .w { font: 400 12px var(--f-data); color: var(--muted); display: flex; align-items: center; gap: 2px; }
.hour .w svg { width: 12px; height: 12px; }

/* ---------- days table ---------- */
.days-scroll { overflow-x: auto; }
.days { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; min-width: 560px; }
.days th {
  text-align: left; font: 500 12px var(--f-body); text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); padding: 0 8px 8px; border-bottom: 1px solid var(--line);
}
.days td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.days tr:last-child td { border-bottom: 0; }
.days .num { text-align: right; }
.days .day { font-weight: 600; white-space: nowrap; }
.days .day small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }
.periods { display: flex; gap: 4px; }
.periods img, .periods span { width: 34px; height: 34px; }
.periods span { display: inline-block; }
.range { display: flex; align-items: center; gap: 8px; font: 500 15px var(--f-data); min-width: 170px; }
.range .bar { position: relative; flex: 1; height: 6px; border-radius: 3px; background: var(--surface-2); min-width: 60px; }
.range .fill { position: absolute; top: 0; bottom: 0; border-radius: 3px; background: linear-gradient(90deg, var(--cold), var(--warm)); }
.days .rain { color: var(--rain); font-family: var(--f-data); }
.days .wind { font-family: var(--f-data); white-space: nowrap; }

/* ---------- footer ---------- */
.foot { padding-block: 24px 40px; color: var(--muted); font-size: 13px; }
.foot p { margin: 0 0 6px; max-width: 72ch; }

/* ---------- small screens ---------- */
@media (max-width: 600px) {
  .days { min-width: 0; }
  .days .wind, .periods-h, #days-panel .legend { display: none; }
  .periods { gap: 0; }
  .periods span, .periods img:not(.main) { display: none; }
  .range { min-width: 0; gap: 6px; font-size: 14px; }
  .range .bar { min-width: 36px; }
  .days td { padding: 8px 4px; }
  .days .num { white-space: nowrap; font-size: 13px; }
}
@media (max-width: 720px) {
  .now-body { grid-template-columns: minmax(0, 1fr); }
  .units { margin-left: auto; }
  .brand { order: 0; }
  .search { order: 2; flex-basis: 100%; }
  .panel { padding: 16px 14px; }
}
@media (prefers-reduced-motion: no-preference) {
  .now, .panel { animation: rise 320ms ease-out both; }
  .panel { animation-delay: 60ms; }
}
@keyframes rise { from { transform: translateY(6px); } to { transform: none; } }
