/* ============================================================
   Self-hosted fonts (Latin subset only)
   ============================================================ */
@font-face {
  font-family: 'Merriweather';
  font-style: normal;
  font-weight: 300 900;
  font-stretch: 100%;
  font-display: swap;
  src: url(fonts/merriweather-latin-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Merriweather';
  font-style: italic;
  font-weight: 300 900;
  font-stretch: 100%;
  font-display: swap;
  src: url(fonts/merriweather-latin-italic.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Merriweather Sans';
  font-style: normal;
  font-weight: 300 800;
  font-display: swap;
  src: url(fonts/merriweather-sans-latin-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ============================================================
   Design tokens
   ============================================================ */
:root {
  --font-serif: 'Merriweather', Georgia, 'Times New Roman', serif;
  --font-sans:  'Merriweather Sans', system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;

  --bg:           #0d0f14;
  --surface:      #161921;
  --surface-alt:  #1c2028;
  --border:       rgba(255, 255, 255, 0.07);
  --text-primary: #f0f2f5;
  --text-muted:   rgba(240, 242, 245, 0.45);
  --text-dim:     rgba(240, 242, 245, 0.25);

  --accent-cold:  #5b8aff;
  --accent-warm:  #ff8c42;
  --accent-precip:#4a9eff;

  --radius:   8px;
  --radius-sm: 4px;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 40px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:           #f2f2f7;
    --surface:      #ffffff;
    --surface-alt:  #f7f7fb;
    --border:       rgba(0, 0, 0, 0.09);
    --text-primary: #1c1c1e;
    --text-muted:   rgba(28, 28, 30, 0.5);
    --text-dim:     rgba(28, 28, 30, 0.28);

    --accent-cold:  #3478f6;
    --accent-warm:  #e05a1a;
    --accent-precip:#2e7dd4;
  }
}

/* ============================================================
   Screen-reader-only utility (USWDS pattern)
   ============================================================ */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sr-only--focusable:focus {
  position: static;
  width: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
  padding: var(--space-sm) var(--space-md);
  background: var(--accent-cold);
  color: #fff;
  font-weight: 600;
  z-index: 1000;
}

/* ============================================================
   Reset & base
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  background-color: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  min-height: 100dvh;
}

/* ============================================================
   App shell
   ============================================================ */
#app {
  max-width: 480px;
  margin: 0 auto;
  padding: var(--space-md);
}

/* ============================================================
   Loading & error states
   ============================================================ */
.state-loading,
.state-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: var(--space-sm);
  color: var(--text-muted);
  font-size: 0.9375rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.state-error {
  color: #ff6b6b;
}

/* ============================================================
   Header
   ============================================================ */
.app-header {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-lg);
}

.location-name {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: bold;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

/* Tappable location name — reset button chrome, keep the same visual */
.location-toggle {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: var(--space-xs);
  text-align: left;
}

.location-caret {
  font-size: 0.9rem;
  font-family: var(--font-sans);
  color: var(--text-muted);
  transition: transform 0.15s ease;
}

.location-toggle[aria-expanded="true"] .location-caret {
  transform: rotate(180deg);
}

/* Picker dropdown — positioned under the header button */
.location-picker {
  position: absolute;
  top: calc(1.5rem + var(--space-xs));   /* align below the title line */
  left: 0;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.location-option {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 1rem;
}

.location-option:hover,
.location-option:focus-visible {
  background: var(--surface-alt);
  outline: none;
}

.location-option-check {
  width: 1em;
  flex-shrink: 0;
  color: var(--accent-cold);
  font-size: 0.9375rem;
}

/* Full-screen backdrop — sits behind the picker, closes it on tap */
.location-picker-backdrop {
  position: fixed;
  inset: 0;
  z-index: 199;
}

.last-updated {
  font-size: 0.8125rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

/* ============================================================
   Section headings
   ============================================================ */
.section-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-md);
}

/* ============================================================
   Right Now section
   ============================================================ */
.section-now {
  margin-bottom: var(--space-xl);
}

.now-primary {
  display: flex;
  align-items: flex-start;
  gap: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.temp-display {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.temp-value {
  font-family: var(--font-serif);
  font-size: 5.5rem;
  font-weight: bold;
  line-height: 1;
  letter-spacing: -0.03em;
}

.temp-condition {
  font-size: 1.1rem;
  color: var(--text-muted);
  margin-top: var(--space-xs);
}

.temp-feels {
  font-size: 0.9375rem;
  color: var(--text-dim);
}

.forecast-text {
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-muted);
  margin-bottom: var(--space-lg);
}

.now-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm) var(--space-lg);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--border);
  margin-bottom: var(--space-lg);
}

.now-details dd {
  margin: 0;
}

.detail-label {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.detail-value {
  font-size: 1rem;
  color: var(--text-primary);
}

/* ============================================================
   Alert banner
   ============================================================ */
.alert-banner {
  margin-top: var(--space-sm);
  margin-bottom: var(--space-md);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid rgba(220, 60, 60, 0.35);
}

.alert-summary {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  background: rgba(220, 60, 60, 0.12);
  color: #ff6060;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.alert-summary::-webkit-details-marker {
  display: none;
}

.alert-icon {
  flex-shrink: 0;
}

.alert-label {
  flex: 1;
}

.alert-chevron {
  margin-left: auto;
  font-style: normal;
  transition: transform 0.18s ease;
}

details[open] .alert-chevron {
  transform: rotate(180deg);
}

.alert-body {
  padding: var(--space-md);
  border-top: 1px solid rgba(220, 60, 60, 0.2);
  background: rgba(220, 60, 60, 0.05);
}

.alert-item + .alert-item {
  border-top: 1px solid rgba(220, 60, 60, 0.18);
  margin-top: var(--space-md);
  padding-top: var(--space-md);
}

.alert-event {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #ff6060;
  margin-bottom: var(--space-xs);
}

.alert-headline {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
  line-height: 1.4;
}

.alert-desc {
  font-size: 0.8125rem;
  color: var(--text-muted);
  white-space: pre-wrap;
  line-height: 1.65;
  max-height: 320px;
  overflow-y: auto;
}

@media (prefers-color-scheme: light) {
  .alert-summary { color: #c0392b; }
  .alert-event   { color: #c0392b; }
  .alert-banner  { border-color: rgba(192, 57, 43, 0.35); }
  .alert-body    { background: rgba(192, 57, 43, 0.05); border-top-color: rgba(192, 57, 43, 0.2); }
}

/* Model spread — subtle comparison row */
.model-spread {
  display: flex;
  gap: var(--space-lg);
  padding: var(--space-sm) var(--space-md);
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.model-spread-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.model-spread-label {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.model-spread-value {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--text-muted);
}

.model-spread-value.is-primary {
  color: var(--text-primary);
}

/* ============================================================
   Next 24 Hours section
   ============================================================ */
.section-hourly {
  margin-bottom: var(--space-xl);
}

/* SVG temperature graph — horizontally scrollable */
.temp-graph-wrap {
  margin-bottom: var(--space-md);
  overflow-x: auto;
  overflow-y: hidden;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.temp-graph-wrap::-webkit-scrollbar {
  display: none;
}

.temp-graph {
  display: block;
  width: 960px;   /* fixed — wider than viewport, enabling scroll */
  height: 168px;
}

/* Scrollable hourly cards */
.hourly-scroll {
  display: flex;
  gap: var(--space-sm);
  overflow-x: auto;
  padding-bottom: var(--space-sm);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.hourly-scroll:focus-visible {
  outline: 2px solid var(--accent-cold);
  outline-offset: 2px;
  border-radius: var(--radius);
}

.hourly-scroll::-webkit-scrollbar {
  display: none;
}

.hourly-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  min-width: 68px;
  flex-shrink: 0;
}

.hourly-time {
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  white-space: nowrap;
}

.hourly-emoji {
  font-size: 1.25rem;
  line-height: 1;
}

.hourly-temp {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--text-primary);
}

.hourly-precip {
  font-size: 0.75rem;
  color: var(--accent-precip);
  opacity: 0.85;
}

.hourly-precip.is-zero {
  opacity: 0;
}

/* ============================================================
   Next 10 Days section
   ============================================================ */
.section-daily {
  margin-bottom: var(--space-xl);
}

.daily-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.daily-row {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  /* Reset button chrome */
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  width: 100%;
}

.daily-row:nth-child(even) {
  background: var(--surface-alt);
}

.daily-row:hover,
.daily-row:focus-visible {
  background: var(--surface-alt);
}

.daily-row:focus-visible {
  outline: 2px solid var(--accent-cold);
  outline-offset: -2px;
  z-index: 1;
}

.daily-row.is-expanded {
  background: var(--surface-alt) !important;
}

.daily-row-main {
  display: grid;
  grid-template-columns: 3fr 4fr 1fr 3fr;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
}

.daily-day {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-primary);
}

.daily-condition {
  font-size: 0.875rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.daily-precip {
  font-size: 0.8125rem;
  color: var(--accent-precip);
  text-align: center;
}

.daily-precip.is-zero {
  color: var(--text-dim);
}

.daily-temps {
  font-family: var(--font-serif);
  font-size: 1rem;
  color: var(--text-primary);
  text-align: right;
  white-space: nowrap;
}

.daily-temps .temp-low {
  color: var(--text-muted);
}

/* Expanded daily row body */
.daily-expanded-body {
  padding: var(--space-xs) var(--space-md) var(--space-sm);
  border-top: 1px solid var(--border);
  font-size: 0.8125rem;
  color: var(--text-primary);
  line-height: 1.45;
}

.expanded-emoji {
  margin-right: 2px;
}

.expanded-range {
  margin-top: 3px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* disagreement badge */
.model-disagree {
  display: inline-block;
  font-size: 0.6rem;
  letter-spacing: 0.05em;
  color: var(--accent-warm);
  vertical-align: middle;
  margin-left: var(--space-xs);
  opacity: 0.7;
}

/* ============================================================
   Source banner — shown at bottom when all sources loaded
   ============================================================ */
.sources-footer {
  padding-top: var(--space-lg);
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  text-align: center;
  line-height: 1.8;
}

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