/* ============================================================
   Weatherican — Brisa
   El tiempo de Puerto Rico. Mobile-first, zero web fonts.
   ============================================================ */

:root {
  /* Brand / light palette */
  --azul-brisa: #0A6CA8;
  --mar-claro: #3BA7D6;
  --arena: #F7F4EC;
  --tinta: #10212B;
  --gris-concreto: #5C6B73;
  --borde-arena: #E6E2D6;
  --sol-uv: #E8821E;
  --sol-uv-text: #B85E0A; /* naranja más oscuro para texto sobre superficies claras (AA) */
  --rojo-calor: #C8401B;
  --verde-aguacero: #16775E; /* verde para texto sobre claro (AA); decorativo usa el mismo */

  /* Night palette */
  --noche: #0B2A3A;
  --indigo-coqui: #101A3D;
  --flamboyan: #FF6B4A;
  --arena-noche: #16242C;
  --texto-noche: #EAF1F4;

  /* Theme-driven tokens (defaults = día) */
  --bg: var(--arena);
  --surface: #FFFFFF;
  --surface-2: #FCFAF4;
  --text: var(--tinta);
  --text-soft: var(--gris-concreto);
  --border: var(--borde-arena);
  --accent: var(--azul-brisa);
  --sky-top: var(--azul-brisa);
  --sky-bottom: var(--mar-claro);
  --hero-text: #FFFFFF;
  --hero-text-soft: rgba(255, 255, 255, 0.9);

  --radius: 18px;
  --radius-sm: 12px;
  --maxw: 540px;
  --shadow: 0 1px 2px rgba(16, 33, 43, 0.06), 0 6px 18px rgba(16, 33, 43, 0.06);

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
}

/* --- Themes --------------------------------------------------- */
[data-theme="crepusculo"] {
  --sky-top: var(--flamboyan);
  --sky-bottom: var(--azul-brisa);
  --accent: var(--rojo-calor);
}

[data-theme="noche"] {
  --bg: var(--noche);
  --surface: var(--arena-noche);
  --surface-2: #1B2C35;
  --text: var(--texto-noche);
  --text-soft: #9DB0BA;
  --border: #24373F;
  --accent: var(--mar-claro);
  --sky-top: var(--noche);
  --sky-bottom: var(--indigo-coqui);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.35);
  /* sobre superficies oscuras, el naranja/verde brillantes ya pasan AA */
  --sol-uv-text: var(--sol-uv);
  --verde-aguacero: #42C49F;
}

/* --- Reset / base -------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.5s ease, color 0.5s ease;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent); }

h1, h2, p { margin: 0; }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

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

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--surface);
  color: var(--text);
  padding: 0.6rem 1rem;
  z-index: 50;
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

main, .topbar, .footer { max-width: var(--maxw); margin-inline: auto; }
main { padding: 0 1rem 2rem; }

/* --- Topbar -------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: max(0.7rem, env(safe-area-inset-top)) 1rem 0.7rem;
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  -webkit-backdrop-filter: saturate(1.4) blur(8px);
}

.municipio-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.7rem;
  min-height: 44px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--text);
  max-width: 70vw;
}
.municipio-btn__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.municipio-btn__pin { font-size: 0.9rem; }
.municipio-btn__chevron { color: var(--text-soft); font-size: 0.8rem; }

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  text-decoration: none;
  color: var(--text-soft);
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.01em;
}
.wordmark__star { color: var(--sol-uv); font-size: 0.95rem; }
.wordmark__text { white-space: nowrap; }

/* --- Status banner ------------------------------------------ */
.status {
  margin: 0.5rem 0;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-soft);
  font-size: 0.9rem;
}
.status--error {
  border-color: color-mix(in srgb, var(--rojo-calor) 50%, var(--border));
  color: var(--rojo-calor);
  background: color-mix(in srgb, var(--rojo-calor) 8%, var(--surface));
}
/* aviso solo para lectores de pantalla (no visible) */
.status--sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --- Hero ---------------------------------------------------- */
.hero {
  position: relative;
  margin-top: 0.5rem;
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--hero-text);
  background: linear-gradient(160deg, var(--sky-top), var(--sky-bottom));
  box-shadow: var(--shadow);
  transition: background 0.6s ease;
}
.hero::before {
  /* scrim persistente: garantiza contraste AA del texto blanco sobre el azul más claro */
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 45%, rgba(11, 25, 35, 0.35));
  pointer-events: none;
  z-index: 0;
}
.hero::after {
  /* condition overlay (rain/storm darken slightly) */
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent, rgba(11, 25, 35, 0));
  pointer-events: none;
  transition: background 0.6s ease;
}
.hero[data-sky="cloud"]::after { background: linear-gradient(180deg, rgba(40,55,65,0.12), rgba(40,55,65,0.22)); }
.hero[data-sky="rain"]::after { background: linear-gradient(180deg, rgba(20,35,45,0.20), rgba(20,35,45,0.34)); }
.hero[data-sky="storm"]::after { background: linear-gradient(180deg, rgba(12,20,30,0.32), rgba(12,20,30,0.48)); }

.hero__inner { position: relative; z-index: 1; padding: 1.2rem 1.3rem 1.5rem; }

.hero__date {
  color: var(--hero-text-soft);
  font-size: 0.9rem;
  margin-bottom: 0.6rem;
}
.hero__date::first-letter { text-transform: uppercase; }

.hero__main { display: flex; align-items: center; gap: 0.5rem; }
.hero__glyph { font-size: 3.4rem; line-height: 1; filter: drop-shadow(0 2px 6px rgba(0,0,0,0.18)); }
.hero__temps { display: flex; flex-direction: column; }

.hero__temp {
  font-size: clamp(3.5rem, 18vw, 5rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 0.95;
}
.hero__unit { font-weight: 600; opacity: 0.7; }

.hero__feels {
  font-size: 1.4rem;
  font-weight: 700;
  margin-top: 0.25rem;
}
.hero__feels .sens-hot { color: #FFE08A; }
.hero__feels .sens-extreme { color: #FFD2C2; }

.hero__cond { margin-top: 0.7rem; font-size: 1.05rem; font-weight: 600; }
.hero__hilo { margin-top: 0.2rem; color: var(--hero-text-soft); font-size: 0.95rem; }

/* --- Avisos -------------------------------------------------- */
.avisos {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin-top: 0.9rem;
}
.aviso {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.6rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  box-shadow: var(--shadow);
}
.aviso__label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-soft);
}
.aviso__value { font-size: 1.25rem; font-weight: 800; }
.aviso__note { font-size: 0.74rem; color: var(--text-soft); }

.aviso__value[data-level="bajo"], .aviso__value[data-level="moderado"] { color: var(--verde-aguacero); }
.aviso__value[data-level="alto"], .aviso__value[data-level="muy-alto"] { color: var(--sol-uv-text); }
.aviso__value[data-level="extremo"] { color: var(--rojo-calor); }
.aviso__value[data-rain="likely"] { color: var(--verde-aguacero); }

/* --- Blocks -------------------------------------------------- */
.block { margin-top: 1.6rem; }
.block__title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-soft);
  margin-bottom: 0.6rem;
  padding-left: 0.15rem;
}

/* --- Hourly -------------------------------------------------- */
.hourly {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  padding: 0.2rem 0.15rem 0.6rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.hour {
  scroll-snap-align: start;
  flex: 0 0 auto;
  width: 60px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.3rem 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  box-shadow: var(--shadow);
}
.hour--night { background: var(--surface-2); }
.hour__time { font-size: 0.74rem; font-weight: 700; color: var(--text-soft); }
.hour__time--now { color: var(--accent); }
.hour__glyph { font-size: 1.3rem; line-height: 1; }
.hour__temp { font-size: 0.95rem; font-weight: 700; }
.hour__precip {
  width: 8px;
  height: 34px;
  border-radius: 5px;
  background: var(--border);
  position: relative;
  overflow: hidden;
}
.hour__precip-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--mar-claro);
  border-radius: 5px;
}
.hour__precip-fill--likely { background: var(--verde-aguacero); }
.hour__pct { font-size: 0.62rem; color: var(--text-soft); min-height: 0.8em; }

/* --- Daily --------------------------------------------------- */
.daily { display: flex; flex-direction: column; }
.day {
  display: grid;
  grid-template-columns: 2.6rem 1.8rem 3rem 1fr auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.3rem;
  border-bottom: 1px solid var(--border);
}
.day:last-child { border-bottom: none; }
.day__name { font-weight: 700; font-size: 0.92rem; text-transform: capitalize; }
.day__glyph { font-size: 1.25rem; text-align: center; }
.day__rain { font-size: 0.78rem; color: var(--verde-aguacero); font-weight: 700; min-width: 3rem; }
.day__rain--none { color: var(--text-soft); font-weight: 500; }
.day__range {
  height: 6px;
  border-radius: 4px;
  background: var(--border);
  position: relative;
}
.day__range-fill {
  position: absolute;
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--mar-claro), var(--sol-uv));
}
.day__temps { font-size: 0.9rem; font-weight: 600; white-space: nowrap; }
.day__temps .lo { color: var(--text-soft); font-weight: 500; }

/* --- Details ------------------------------------------------- */
.details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}
.detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  box-shadow: var(--shadow);
}
.detail__label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-soft);
}
.detail__value { font-size: 1.15rem; font-weight: 700; }
.detail--sun {
  grid-column: 1 / -1;
  flex-direction: row;
  align-items: center;
  gap: 1rem;
}
.sunarc { color: var(--sol-uv); flex: 0 0 120px; }
.sunarc svg { width: 120px; height: 64px; display: block; }
#sunarc-dot { fill: var(--flamboyan); transition: cx 0.6s ease, cy 0.6s ease; }
.sun-times { display: flex; gap: 1.4rem; }
.sun-time { display: flex; flex-direction: column; gap: 0.2rem; }

/* --- Footer -------------------------------------------------- */
.footer {
  text-align: center;
  padding: 1.5rem 1rem 2.5rem;
  color: var(--text-soft);
  font-size: 0.82rem;
}
.footer p { margin: 0.4rem 0; }
.footer__updated { font-weight: 600; }
.refresh-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.45rem 1rem;
  min-height: 44px;
  font-weight: 600;
  color: var(--text);
  box-shadow: var(--shadow);
}
.footer__disclaimer { font-size: 0.74rem; line-height: 1.5; max-width: 34rem; margin-inline: auto; opacity: 0.9; }

/* --- Dialog (municipio selector) ----------------------------- */
.dialog { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.dialog[hidden] { display: none; }
.dialog__backdrop { position: absolute; inset: 0; background: rgba(11, 25, 35, 0.45); }
.dialog__panel {
  position: relative;
  width: 100%;
  max-width: var(--maxw);
  max-height: 82vh;
  background: var(--bg);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  box-shadow: 0 -8px 30px rgba(0,0,0,0.25);
  animation: sheet-up 0.22s ease;
}
@keyframes sheet-up { from { transform: translateY(12px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }
.dialog__header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.7rem; }
.dialog__title { font-size: 1.05rem; font-weight: 800; }
.dialog__close {
  font-size: 1.1rem;
  color: var(--text-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0.3rem 0.5rem;
}
.dialog__search {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 0.6rem;
}
.dialog__list { list-style: none; margin: 0; padding: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.dialog__list li { list-style: none; margin: 0; }
.dialog__option {
  width: 100%;
  padding: 0.75rem 0.6rem;
  border: 0;
  background: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit;
  font-size: 1rem;
  color: inherit;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.dialog__option:hover { background: var(--surface); }
.dialog__option:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.dialog__option[aria-current="true"] { color: var(--accent); font-weight: 700; }
.dialog__empty { padding: 1rem 0.6rem; color: var(--text-soft); }

/* --- Loading shimmer ---------------------------------------- */
.skeleton-text { opacity: 0.5; }
body.loading .hero { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.82; } }

/* --- Larger screens ----------------------------------------- */
@media (min-width: 600px) {
  main { padding-inline: 0; }
  .hero__main { gap: 1rem; }
}

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