:root {
  --bg: #f5ede1;
  --surface: #fbf6ee;
  --surface-2: #f3e9da;
  --ink: #33261d;
  --ink-2: #6e5c4e;
  --muted: #a08e7e;
  --line: #e6d9c7;
  --accent: #cf6a40;
  --accent-soft: #f2d9c6;
  --sun: #e2a13a;
  --cloud: #9c8b7d;
  --rain: #6f8fa6;
  --shadow: 0 1px 0 rgba(80, 55, 35, 0.04), 0 8px 24px -12px rgba(80, 55, 35, 0.18);

  --font-display: "Fraunces", Georgia, serif;
  --font-ui: "Outfit", system-ui, sans-serif;
  --font-hand: "Caveat", "Comic Sans MS", cursive;

  /* sky behind the page */
  --sky-top: #b3d1ea;
  --sky-mid: #dde6e4;
  --cloud-rim: #fdfbec;
  --cloud-body: #d4d9d8;
  --cloud-opacity: 0.95;
  --field: #fffcf7;
  color-scheme: light;
}

/* Dark tokens apply after sunset at the place shown (app.js sets data-theme), or
   before the first forecast loads when the OS prefers dark. Keep the two blocks identical. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1713;
    --surface: #28201a;
    --surface-2: #30271f;
    --ink: #f3e8da;
    --ink-2: #c8b6a3;
    --muted: #8d7a69;
    --line: #3a2f27;
    --accent: #e58a5e;
    --accent-soft: #4a3226;
    --sun: #ebb456;
    --cloud: #b3a291;
    --rain: #8fb0c6;
    --shadow: 0 8px 24px -12px rgba(0, 0, 0, 0.6);
    --sky-top: #262c3b;
    --sky-mid: #221f22;
    --cloud-rim: #3b3d48;
    --cloud-body: #2c2e37;
    --cloud-opacity: 0.8;
    --field: #322923;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1d1713;
  --surface: #28201a;
  --surface-2: #30271f;
  --ink: #f3e8da;
  --ink-2: #c8b6a3;
  --muted: #8d7a69;
  --line: #3a2f27;
  --accent: #e58a5e;
  --accent-soft: #4a3226;
  --sun: #ebb456;
  --cloud: #b3a291;
  --rain: #8fb0c6;
  --shadow: 0 8px 24px -12px rgba(0, 0, 0, 0.6);
  --sky-top: #262c3b;
  --sky-mid: #221f22;
  --cloud-rim: #3b3d48;
  --cloud-body: #2c2e37;
  --cloud-opacity: 0.8;
  --field: #322923;
  color-scheme: dark;
}

/* At sunrise/sunset the whole page cross-fades between themes as one picture
   (see app.js), so text never fades out of step with its background. */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 1.2s;
  animation-timing-function: ease;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button { font: inherit; color: inherit; }
h1, h2, p, ol, ul { margin: 0; padding: 0; }

.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 20px 24px 40px;
}

/* ---------- sky ---------- */
/* Fixed behind everything: soft sky fading into the page color, slow drifting clouds. */
.sky {
  position: fixed;
  inset: 0;
  z-index: -2;
  overflow: hidden;
  pointer-events: none;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 38%, var(--bg) 72%);
}
.cloud { position: absolute; height: auto; opacity: var(--cloud-opacity); overflow: visible; }
.c1 { top: 12%; right: 2%;  width: clamp(200px, 26vw, 360px); aspect-ratio: 200 / 110; animation: drift 70s ease-in-out infinite alternate; }
.c2 { top: 30%; left: -2%;  width: clamp(170px, 22vw, 300px); aspect-ratio: 175 / 95;  animation: drift 90s ease-in-out -30s infinite alternate-reverse; }
.c3 { top: 14%; left: 22%;  width: clamp(80px, 9vw, 130px);   aspect-ratio: 110 / 80;  animation: drift 60s ease-in-out -10s infinite alternate; }
.c4 { top: 58%; right: -4%; width: clamp(200px, 24vw, 340px); aspect-ratio: 200 / 110; animation: drift 100s ease-in-out -50s infinite alternate-reverse; opacity: calc(var(--cloud-opacity) * 0.7); }
.c5 { top: 72%; left: 6%;   width: clamp(160px, 18vw, 260px); aspect-ratio: 175 / 95;  animation: drift 80s ease-in-out -20s infinite alternate; opacity: calc(var(--cloud-opacity) * 0.6); }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.wordmark {
  font-family: var(--font-display);
  font-variation-settings: "SOFT" 100;
  font-weight: 400;
  font-size: 22px;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--ink-2);
}
.wordmark span { color: var(--accent); font-style: italic; }

.actions { position: relative; display: flex; gap: 10px; }

.icon-btn {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  background: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, transform 0.15s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg .fill { fill: currentColor; stroke: none; }
.icon-btn.busy svg { animation: spin 1s linear infinite; }
.icon-btn .dot {
  position: absolute;
  top: 6px;
  right: 7px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--bg);
}

.bell-wrap { position: relative; }
.popover {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  width: min(300px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 16px 18px;
  z-index: 10;
}
.popover-title {
  font-family: var(--font-hand);
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 6px;
}
.popover ul { list-style: none; display: grid; gap: 10px; }
.popover li { display: flex; gap: 10px; font-size: 14px; color: var(--ink-2); }
.popover li b { color: var(--ink); font-weight: 500; }
.popover li .ico { flex: none; width: 22px; height: 22px; }

/* place picker */
.place-search {
  width: 100%;
  margin-top: 4px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--field);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.place-search::placeholder { color: var(--muted); }
.place-search::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.place-search:focus { outline: none; border-color: var(--muted); box-shadow: 0 0 0 3px var(--line); }
.place-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 12px 4px 2px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.place-label[hidden] { display: none; }
.place-clear {
  padding: 2px 4px;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}
.place-clear:hover, .place-clear:focus-visible { color: var(--accent); outline: none; }
.popover .place-results { gap: 2px; margin-top: 6px; }
.popover .place-results:empty { display: none; }
.place-results li { display: flex; align-items: center; border-radius: 10px; }
.place-results li:hover { background: var(--surface-2); }
.place-results li button { min-width: 0; }
.place-results li:hover button { background: none; }
/* × to forget a recent place */
.place-results .forget {
  flex: none;
  width: 30px;
  justify-content: center;
  align-items: center;
  margin-right: 4px;
  padding: 4px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  opacity: 0.55;
}
.place-results li:hover .forget, .place-results .forget:focus-visible { opacity: 1; }
.place-results .forget:hover, .place-results .forget:focus-visible { color: var(--accent); }
.place-results button,
.place-here {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
  cursor: pointer;
}
.place-results button:hover,
.place-results button:focus-visible,
.place-here:hover,
.place-here:focus-visible { background: var(--surface-2); outline: none; }
.place-results .name { color: var(--ink); font-weight: 500; font-size: 15px; }
.place-results .where { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.place-results .note { padding: 8px 10px; font-size: 14px; color: var(--muted); }
.place-here {
  align-items: center;
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  border-radius: 0 0 10px 10px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
}
.place-here svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.place-here svg .fill { fill: currentColor; stroke: none; }

/* ---------- place ---------- */
.place { text-align: center; margin-top: 28px; }
.place h1 {
  font-family: var(--font-ui);
  font-weight: 300;
  font-size: clamp(40px, 7vw, 68px);
  line-height: 1;
  letter-spacing: -0.01em;
}
.place p {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-2);
}

/* ---------- hero ---------- */
.hero {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: 24px;
  margin: 12px 0 28px;
}

.duck-side {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.duck-rig {
  position: relative;
  width: min(300px, 100%);
  /* breathing: a slow stretch up from the feet (same as the portfolio duck) */
  transform-origin: 50% 95%;
  animation: breathe 1.8s cubic-bezier(0.37, 0, 0.63, 1) infinite alternate;
}
/* the pop-in when the duck changes wraps the image and its eyes, so they move together */
.duck-pop { position: relative; transform-origin: 50% 100%; }
.duck-pop.swap { animation: swap 0.45s ease both; }
.duck {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 14px 12px rgba(80, 55, 35, 0.16));
}
.duck:not([src]) { visibility: hidden; }

/* Eyes layer, like the portfolio duck: face-colored lids cover the drawn eyes and
   copies of the eyes sit exactly on top; a blink squashes just the copies.
   Built and played by app.js. */
.blink { position: absolute; inset: 0; pointer-events: none; }
.blink .lid { position: absolute; border-radius: 50%; }
.blink .eye { position: absolute; inset: 0; width: 100%; height: auto; display: block; }

.dateline {
  display: flex;
  gap: 32px;
  margin-top: 18px;
  /* same style as the area name under the city */
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.now { text-align: center; }
.temp {
  font-family: var(--font-display);
  font-variation-settings: "SOFT" 100, "opsz" 144;
  font-weight: 300;
  font-size: clamp(110px, 17vw, 190px);
  line-height: 0.9;
  letter-spacing: -0.04em;
  display: flex;
  justify-content: center;
}
/* the digits are centered on their own; the ° hangs off to the right */
.temp-num { position: relative; }
.temp .deg { position: absolute; left: 100%; margin-left: 0.1em; top: 0.12em; font-size: 0.45em; line-height: 1; color: var(--accent); }

.feel {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 30px;
}
.cond-icon { width: 34px; height: 34px; display: inline-grid; }
.cond {
  margin-top: 6px;
  /* same style as the area name under the city */
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.hilo {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 28px;
  margin-top: 14px;
  font-size: 17px; /* the "H:" and "L:" labels */
  font-weight: 300;
  color: var(--ink-2);
}
.hilo b { font-size: 22px; color: var(--ink); font-weight: 400; }

/* ---------- cards ---------- */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 18px;
  align-items: stretch;
}
.stack { display: grid; gap: 18px; grid-template-rows: 1fr auto auto; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 18px 20px 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.card h2 svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.row-head { display: flex; justify-content: space-between; align-items: baseline; }
.big {
  font-family: var(--font-display);
  font-variation-settings: "SOFT" 100;
  font-size: 40px;
  line-height: 1.1;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.big small { font-family: var(--font-ui); font-size: 15px; color: var(--ink-2); font-weight: 400; }
.small .big { margin-top: 10px; }
.sub { margin-top: 8px; font-size: 14px; color: var(--ink-2); }
.arrow { display: inline-block; transition: transform 0.6s ease; color: var(--accent); font-weight: 600; }

/* forecast */
.forecast { display: flex; flex-direction: column; }
.forecast h2 { padding-bottom: 14px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.forecast ol { list-style: none; display: grid; gap: 10px; flex: 1; grid-auto-rows: minmax(52px, 1fr); }
.forecast li { display: flex; }
.day {
  flex: 1;
  width: 100%;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
  display: grid;
  grid-template-columns: 58px 30px 34px 1fr 34px;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-2);
  font-variant-numeric: tabular-nums;
}
.day:hover { background: var(--line); }
.day:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.day.selected { background: var(--accent-soft); }
.day .name { font-weight: 500; }
.day .ico { width: 28px; height: 28px; }
.day .lo { color: var(--muted); text-align: right; }
.day .hi { font-weight: 600; }
.range { position: relative; height: 6px; border-radius: 3px; background: var(--line); }
.range span {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 3px;
  background: linear-gradient(90deg, #8fb0c6, var(--sun) 60%, var(--accent));
}

/* hourly chart */
.hourly { display: flex; flex-direction: column; }
.chart { position: relative; flex: 1; min-height: 190px; margin-top: 8px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .axis { font-size: 12px; fill: var(--muted); font-family: var(--font-ui); }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart .now-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .cross { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hover-dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.tip {
  position: absolute;
  top: 0;
  transform: translate(-50%, -110%);
  padding: 4px 10px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 10px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
}

/* meters */
.meter {
  position: relative;
  height: 8px;
  border-radius: 4px;
  margin-top: 14px;
}
.aqi-meter { background: linear-gradient(90deg, #9bb07a 0%, #e2c15a 17%, #e59a4c 33%, #d9674a 50%, #a8506b 67%, #7a3f4f 100%); }
.uv-meter { background: linear-gradient(90deg, #9bb07a 0%, #e2c15a 25%, #e59a4c 50%, #d9674a 70%, #9a5d9a 100%); }
.knob {
  position: absolute;
  top: 50%;
  left: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--ink);
  transform: translate(-50%, -50%);
  transition: left 0.8s cubic-bezier(0.3, 1.3, 0.5, 1);
}

/* ---------- footer ---------- */
.foot { margin-top: 28px; text-align: center; font-size: 13px; color: var(--muted); }

/* ---------- loading ---------- */
body.loading .temp, body.loading .big, body.loading .hilo b { opacity: 0.35; }

/* ---------- motion ---------- */
@keyframes breathe { from { transform: translateY(0) scaleY(1); } to { transform: translateY(-0.6%) scaleY(1.012); } }
@keyframes swap { from { opacity: 0; transform: scale(0.9) translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes drift { from { translate: -40px 0; } to { translate: 40px 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  .page { padding: 16px 16px 32px; }
  .sky { --cloud-opacity: 0.6; } /* clouds sit behind text on narrow screens, so keep them faint */
  .hero { grid-template-columns: 1fr; gap: 8px; }
  .duck-rig { width: min(230px, 70vw); }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .forecast ol { grid-auto-rows: auto; }
  .chart { min-height: 170px; }
}
@media (max-width: 380px) {
  .pair { grid-template-columns: 1fr; }
  .day { grid-template-columns: 48px 26px 30px 1fr 30px; gap: 8px; padding: 10px 12px; }
}
