/* ---------- Tokens ---------- */

:root {
  color-scheme: light;
  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-body: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --surface: rgba(255, 255, 255, 0.78);
  --surface-solid: #ffffff;
  --surface-sunken: rgba(15, 23, 42, 0.06);
  --border: rgba(255, 255, 255, 0.6);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --on-sky: #0f172a;

  --winter: #2a78d6;
  --summer: #e2601f;
  --warning-ink: #8a5a00;
  --warning-bg: #fff4d6;
  --accent: #2a78d6;

  --chart-weekly: #2a78d6;
  --chart-daily: #94a3b8;
  --chart-grid: rgba(15, 23, 42, 0.08);
  --chart-cold-zone: rgba(42, 120, 214, 0.08);
  --chart-warm-zone: rgba(235, 104, 52, 0.07);
  --chart-forecast-zone: rgba(15, 23, 42, 0.04);
  --tooltip-bg: #0f172a;
  --tooltip-text: #f8fafc;

  --radius-lg: 28px;
  --radius-md: 16px;
  --shadow: 0 1px 1px rgba(15, 23, 42, 0.04), 0 12px 40px -12px rgba(15, 23, 42, 0.25);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface: rgba(17, 24, 39, 0.72);
    --surface-solid: #111827;
    --surface-sunken: rgba(255, 255, 255, 0.07);
    --border: rgba(255, 255, 255, 0.08);
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --on-sky: #f1f5f9;

    --winter: #6da7ec;
    --summer: #f28a52;
    --warning-ink: #fcd34d;
    --warning-bg: rgba(250, 178, 25, 0.14);
    --accent: #3987e5;

    --chart-weekly: #6da7ec;
    --chart-daily: #7c8a9d;
    --chart-grid: rgba(255, 255, 255, 0.08);
    --chart-cold-zone: rgba(57, 135, 229, 0.12);
    --chart-warm-zone: rgba(217, 89, 38, 0.1);
    --chart-forecast-zone: rgba(255, 255, 255, 0.04);
    --tooltip-bg: #f1f5f9;
    --tooltip-text: #0f172a;

    --shadow: 0 1px 1px rgba(0, 0, 0, 0.2), 0 16px 48px -16px rgba(0, 0, 0, 0.6);
  }
}

/* Text colour that sits directly on the sky, per scene. */
body[data-scene="snow"] { --on-sky: #f1f5f9; --accent: #2a78d6; }
body[data-scene="sun"] { --accent: #e2601f; }
body[data-scene="leaves"] { --accent: #b45309; }
body[data-scene="rain"] { --accent: #475569; }

@media (prefers-color-scheme: dark) {
  body[data-scene="sun"] { --accent: #f28a52; }
  body[data-scene="leaves"] { --accent: #f59e0b; }
  body[data-scene="rain"] { --accent: #64748b; }
  body[data-scene="snow"] { --accent: #6da7ec; }
}

/* ---------- Base ---------- */

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #e8eef6;
  color: var(--text-primary);
  font: 16px/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased;
}

@media (prefers-color-scheme: dark) {
  body {
    background: #0b1220;
  }
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Sky ---------- */

.sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.sky__layer {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 1.2s ease;
}

body[data-scene="calm"] [data-layer="calm"],
body[data-scene="snow"] [data-layer="snow"],
body[data-scene="sun"] [data-layer="sun"],
body[data-scene="leaves"] [data-layer="leaves"],
body[data-scene="rain"] [data-layer="rain"] {
  opacity: 1;
}

[data-layer="calm"] { background: linear-gradient(180deg, #dfe8f3 0%, #eef2f6 55%, #f5f3ef 100%); }
[data-layer="snow"] { background: radial-gradient(120% 80% at 50% 0%, #3f6ea8 0%, #1d3a63 55%, #0f2140 100%); }
[data-layer="sun"] { background: radial-gradient(90% 70% at 85% 0%, #ffe7a3 0%, #ffc778 30%, #ffa86b 60%, #f6d2b8 100%); }
[data-layer="leaves"] { background: linear-gradient(180deg, #f6dfb5 0%, #eecf9f 45%, #e7d6c0 100%); }
[data-layer="rain"] { background: linear-gradient(180deg, #8d9aab 0%, #aeb9c6 50%, #c9d0d8 100%); }

@media (prefers-color-scheme: dark) {
  [data-layer="calm"] { background: linear-gradient(180deg, #0b1220 0%, #111a2c 100%); }
  [data-layer="snow"] { background: radial-gradient(120% 80% at 50% 0%, #1f3d66 0%, #0e1f3a 55%, #070f1f 100%); }
  [data-layer="sun"] { background: radial-gradient(90% 70% at 85% 0%, #7a3d17 0%, #4a2412 40%, #1f120c 100%); }
  [data-layer="leaves"] { background: linear-gradient(180deg, #2b1d10 0%, #1f160e 60%, #15100b 100%); }
  [data-layer="rain"] { background: linear-gradient(180deg, #1a212b 0%, #141a22 60%, #0f141a 100%); }
}

.sky__particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.sun {
  position: absolute;
  top: -90px;
  right: -90px;
  width: 360px;
  height: 360px;
  opacity: 0;
  transform: scale(0.6) translateY(-40px);
  transition: opacity 1.2s ease, transform 1.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

body[data-scene="sun"] .sun {
  opacity: 1;
  transform: none;
}

.sun__core {
  position: absolute;
  inset: 110px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #fffbe8 0%, #ffe48a 45%, #ffc34d 100%);
  box-shadow: 0 0 60px 20px rgba(255, 214, 110, 0.65), 0 0 140px 60px rgba(255, 190, 90, 0.35);
}

.sun__rays {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, rgba(255, 236, 170, 0.55) 0deg 6deg, transparent 6deg 20deg);
  -webkit-mask: radial-gradient(circle, transparent 28%, #000 32%, transparent 70%);
  mask: radial-gradient(circle, transparent 28%, #000 32%, transparent 70%);
  animation: spin 60s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}

/* ---------- Layout ---------- */

.page {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  backdrop-filter: blur(18px) saturate(1.3);
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 0;
  color: var(--on-sky);
  transition: color 0.8s ease;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand__mark {
  width: 40px;
  height: 40px;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.25));
  transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.brand:hover .brand__mark {
  transform: rotate(-200deg);
}

.brand__name {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  transition: transform 0.2s ease;
}

.icon-button:hover {
  transform: translateY(-2px);
}

.icon-button svg {
  width: 20px;
  height: 20px;
}

/* ---------- Hero ---------- */

.hero {
  padding: 20px;
}

.hero__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 8px 12px 8px 10px;
  border: 0;
  border-radius: 999px;
  background: var(--surface-sunken);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.chip:hover {
  background: color-mix(in srgb, var(--surface-sunken), var(--accent) 12%);
}

.chip svg {
  width: 18px;
  height: 18px;
  flex: none;
  color: var(--accent);
}

.chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip .chip__caret {
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.chip[aria-expanded="true"] .chip__caret {
  transform: rotate(180deg);
}

.toggle {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface-sunken);
}

.toggle__option {
  padding: 7px 14px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}

.toggle__option[aria-pressed="true"] {
  background: var(--surface-solid);
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.15);
}

/* ---------- Search ---------- */

.search {
  margin-top: 14px;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  animation: drop-in 0.3s ease;
}

.search__hint {
  margin: 0 0 10px;
  color: var(--text-secondary);
  font-size: 15px;
}

.search__form {
  display: flex;
  gap: 8px;
}

.search__form input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--surface-solid);
  color: var(--text-primary);
  font: inherit;
}

.search__form input:focus {
  outline: none;
  border-color: var(--accent);
}

.search__results {
  list-style: none;
  margin: 8px 0;
  padding: 0;
}

.search__result {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
  cursor: pointer;
}

.search__result:hover,
.search__result:focus-visible {
  background: var(--surface-solid);
}

.search__result span,
.search__status {
  color: var(--text-muted);
}

.search__status {
  padding: 10px 12px;
}

.text-button {
  padding: 6px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

.text-button:hover {
  text-decoration: underline;
}

/* ---------- Verdict ---------- */

.verdict {
  padding: 28px 4px 8px;
  text-align: center;
}

.verdict__question {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(22px, 5vw, 28px);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-secondary);
}

.verdict__answer-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: clamp(110px, 30vw, 170px);
}

.verdict__answer {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(110px, 32vw, 184px);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -0.06em;
  color: var(--text-primary);
}

.verdict[data-state="yes-winter"] .verdict__answer {
  background: linear-gradient(180deg, #6da7ec 0%, #2a78d6 55%, #1c5cab 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.verdict[data-state="yes-summer"] .verdict__answer {
  background: linear-gradient(180deg, #ffb347 0%, #f27b2c 55%, #d9501a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.verdict[data-state="idle"] .verdict__answer {
  color: var(--text-muted);
}

.verdict.is-revealed .verdict__answer {
  animation: pop-in 0.7s cubic-bezier(0.2, 0.9, 0.25, 1.2);
}

.verdict.is-revealed .verdict__explanation,
.verdict.is-revealed .gauge,
.verdict.is-revealed .quip,
.verdict.is-revealed .verdict__actions {
  animation: rise-in 0.6s ease both;
}

.verdict.is-revealed .gauge { animation-delay: 0.1s; }
.verdict.is-revealed .quip { animation-delay: 0.2s; }
.verdict.is-revealed .verdict__actions { animation-delay: 0.3s; }

@keyframes pop-in {
  0% { opacity: 0; transform: scale(0.7); filter: blur(10px); }
  100% { opacity: 1; transform: none; filter: none; }
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

@keyframes drop-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

.loader {
  display: none;
  width: 72px;
  height: 72px;
}

.verdict[data-state="loading"] .loader {
  display: block;
  animation: roll 1.6s ease-in-out infinite alternate;
}

.loader svg {
  width: 100%;
  height: 100%;
  animation: spin 0.8s linear infinite;
}

@keyframes roll {
  from { transform: translateX(-60px); }
  to { transform: translateX(60px); }
}

.verdict__explanation {
  max-width: 480px;
  margin: 8px auto 0;
  font-size: 17px;
  color: var(--text-secondary);
}

/* ---------- Gauge ---------- */

.gauge {
  --pos: 50%;
  --threshold: 48%;
  max-width: 440px;
  margin: 40px auto 0;
}

.gauge__track {
  position: relative;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #1c5cab 0%, #6da7ec calc(var(--threshold) - 8%), #e6edf5 var(--threshold), #ffc778 calc(var(--threshold) + 10%), #e2601f 100%);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
}

.gauge__threshold {
  position: absolute;
  top: -6px;
  bottom: -6px;
  left: var(--threshold);
  width: 2px;
  background: var(--text-primary);
  border-radius: 2px;
}

.gauge__threshold span {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
}

.gauge__marker {
  position: absolute;
  top: 50%;
  left: var(--pos);
  width: 24px;
  height: 24px;
  border: 4px solid var(--surface-solid);
  border-radius: 50%;
  background: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transform: translate(-50%, -50%);
}

.gauge__value {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--text-primary);
  color: var(--surface-solid);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.gauge__legend {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------- Quip, pills, actions ---------- */

.pill {
  display: inline-block;
  margin: 18px 0 0;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
}

.pill--warning {
  background: var(--warning-bg);
  color: var(--warning-ink);
}

.quip {
  display: block;
  max-width: 480px;
  margin: 22px auto 0;
  padding: 0;
  border: 0;
  background: none;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--text-primary);
  cursor: pointer;
}

.quip:hover {
  color: var(--accent);
}

.quip.is-swapped {
  animation: rise-in 0.4s ease;
}

.verdict__actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
}

.verdict__forecast {
  margin: 0;
  font-size: 14px;
  color: var(--text-muted);
}

.button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 24px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 20px -8px var(--accent);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.8s ease;
}

.button:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px -8px var(--accent);
}

.button:active {
  transform: translateY(0);
}

.button svg {
  width: 18px;
  height: 18px;
}

.button--small {
  padding: 10px 16px;
  box-shadow: none;
}

/* ---------- Chart ---------- */

.chart-card {
  padding: 20px 16px 16px;
}

.chart-card__head {
  padding: 0 4px;
}

.chart-card__head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: -0.02em;
}

.chart-card__head p {
  margin: 2px 0 12px;
  font-size: 14px;
  color: var(--text-secondary);
}

.chart-card__canvas {
  position: relative;
  height: 300px;
}

.chart-card__table {
  margin: 12px 4px 0;
  font-size: 14px;
}

.chart-card__table summary {
  cursor: pointer;
  color: var(--text-secondary);
}

.chart-card__table table {
  width: 100%;
  margin-top: 8px;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.chart-card__table th,
.chart-card__table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--chart-grid);
  text-align: right;
}

.chart-card__table th:first-child,
.chart-card__table td:first-child {
  text-align: left;
}

/* ---------- Facts ---------- */

.facts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.fact {
  padding: 18px;
  border-radius: 22px;
}

.fact p {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.fact .fact__big {
  margin-bottom: 4px;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

@media (max-width: 620px) {
  .facts {
    grid-template-columns: 1fr;
  }

  .hero__controls {
    justify-content: center;
  }
}

/* ---------- Footer & toast ---------- */

.footer {
  padding: 4px 8px;
  color: var(--on-sky);
  font-size: 14px;
  text-align: center;
  opacity: 0.85;
  transition: color 0.8s ease;
}

.footer p {
  margin: 0 0 6px;
}

.footer a {
  color: inherit;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 10;
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 20px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .verdict[data-state="loading"] .loader {
    animation: none;
  }
}
