/* ===================================
   KL Weather — Clean, data-driven UI
   =================================== */

:root {
  --accent: #F5A623;
  --accent-glow: rgba(245, 166, 35, 0.2);
  --bg: #0B1120;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-hover: rgba(255, 255, 255, 0.07);
  --text: #F0F4F8;
  --text-muted: #7B8BA5;
  --text-dim: #4A5568;
  --border: rgba(255, 255, 255, 0.06);
  --danger: #FC5C65;
  --success: #2ED573;
  --rain-color: #5B9CF6;
  --bar-track: rgba(255,255,255,0.06);
  --uv-knob: #fff;
  --uv-knob-shadow: rgba(255,255,255,0.5);
  --now-bg: rgba(245, 166, 35, 0.08);
  --font: 'Space Grotesk', system-ui, sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --radius: 16px;
  --radius-sm: 10px;
}

/* ---- Light theme ---- */
:root.light {
  --accent: #E89400;
  --accent-glow: rgba(232, 148, 0, 0.15);
  --bg: #F4F7FA;
  --bg-card: #FFFFFF;
  --bg-card-hover: #F0F4F8;
  --text: #1A2332;
  --text-muted: #64748B;
  --text-dim: #94A3B8;
  --border: rgba(0, 0, 0, 0.07);
  --danger: #E53E3E;
  --success: #16A34A;
  --rain-color: #2563EB;
  --bar-track: rgba(0,0,0,0.05);
  --uv-knob: #334155;
  --uv-knob-shadow: rgba(0,0,0,0.3);
  --now-bg: rgba(232, 148, 0, 0.07);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---- Background gradient ---- */
.bg-gradient {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 50% at 20% 0%, rgba(245, 166, 35, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(56, 97, 251, 0.06) 0%, transparent 60%);
}

:root.light .bg-gradient {
  background:
    radial-gradient(ellipse 80% 50% at 20% 0%, rgba(232, 148, 0, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(37, 99, 235, 0.04) 0%, transparent 60%);
}

/* ---- Version badge ---- */
.version-badge {
  position: fixed;
  top: 0.5rem;
  left: 0.75rem;
  z-index: 60;
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-dim);
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  pointer-events: none;
  user-select: none;
}

/* ---- Header ---- */
.header {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(24px) saturate(1.6);
  -webkit-backdrop-filter: blur(24px) saturate(1.6);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 1.05rem;
  white-space: nowrap;
}

.logo-icon { width: 28px; height: 28px; flex-shrink: 0; }

.header-meta {
  flex: 1;
  text-align: right;
}

.header-loc {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.header-loc-sub {
  display: block;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.refresh-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, transform 0.3s;
}

.refresh-btn:hover {
  background: var(--bg-card-hover);
  color: var(--accent);
}

.refresh-btn.spinning svg {
  animation: spin 0.8s linear;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ---- Main ---- */
.main {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* ---- Loading ---- */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding: 6rem 0;
  color: var(--text-muted);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.hidden { display: none !important; }

/* ---- Error ---- */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 6rem 0;
  text-align: center;
}

.error-state h3 {
  font-size: 1.2rem;
  color: var(--danger);
}

.error-state p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.btn-retry {
  margin-top: 0.5rem;
  padding: 0.6rem 1.8rem;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 100px;
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-retry:hover { opacity: 0.85; }

/* ---- Current ---- */
.current {
  text-align: center;
  padding: 3rem 0 2.5rem;
}

.current-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.current-temp-wrap {
  display: flex;
  align-items: flex-start;
}

.current-temp {
  font-size: clamp(5rem, 14vw, 9rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.04em;
  background: linear-gradient(180deg, var(--text) 30%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.current-temp-unit {
  font-size: 1.8rem;
  font-weight: 300;
  color: var(--text-muted);
  margin-top: 0.8rem;
}

.current-icon svg {
  filter: drop-shadow(0 0 20px var(--accent-glow));
}

.current-condition {
  font-size: 1.25rem;
  font-weight: 500;
  margin-top: 0.5rem;
}

.current-feels {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

.current-updated {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.2rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}

.pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ---- Metric grid ---- */
.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-top: 2rem;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  transition: background 0.2s;
}

.metric-card:hover {
  background: var(--bg-card-hover);
}

.metric-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.metric-value {
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text);
}

/* ---- Section title ---- */
.section-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* ---- Hourly ---- */
.hourly-section {
  margin-top: 3rem;
}

.hourly-track {
  display: flex;
  gap: 0.6rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding-bottom: 0.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--text-dim) transparent;
}

.hourly-track::-webkit-scrollbar { height: 3px; }
.hourly-track::-webkit-scrollbar-thumb { background: var(--text-dim); border-radius: 2px; }

.hourly-card {
  flex: 0 0 72px;
  scroll-snap-align: start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  transition: background 0.2s, border-color 0.2s;
}

.hourly-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

.hourly-card.now {
  border-color: var(--accent);
  background: var(--now-bg);
}

.hourly-time {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.hourly-icon svg {
  width: 28px;
  height: 28px;
}

.hourly-temp {
  font-weight: 600;
  font-size: 0.95rem;
}

.hourly-rain {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--rain-color);
}

/* ---- Daily ---- */
.daily-section {
  margin-top: 3rem;
}

.daily-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.daily-row {
  display: grid;
  grid-template-columns: 120px 36px 1fr 60px;
  align-items: center;
  gap: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  transition: background 0.2s;
}

.daily-row:hover {
  background: var(--bg-card-hover);
}

.daily-day {
  font-size: 0.88rem;
  font-weight: 500;
}

.daily-day-sub {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.daily-icon svg {
  width: 28px;
  height: 28px;
}

.daily-bar-wrap {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.daily-temp-lo {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text-dim);
  width: 32px;
  text-align: right;
}

.daily-bar {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--bar-track);
  position: relative;
  overflow: hidden;
}

.daily-bar-fill {
  position: absolute;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, #5B9CF6, var(--accent), var(--danger));
}

.daily-temp-hi {
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 600;
  width: 32px;
}

.daily-rain {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--rain-color);
  text-align: right;
}

/* ---- Extra grid ---- */
.extra-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 3rem;
}

.extra-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.extra-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}

.sun-times {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.sun-time {
  text-align: center;
}

.sun-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
}

.sun-value {
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 500;
}

.uv-display {
  text-align: center;
  margin-bottom: 1rem;
}

.uv-value {
  font-size: 2.5rem;
  font-weight: 700;
  display: block;
  background: linear-gradient(180deg, var(--text) 40%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.uv-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  display: block;
}

.uv-bar {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--success), var(--accent), var(--danger), #9B59B6);
  position: relative;
}

.uv-bar-fill {
  position: absolute;
  top: -3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--uv-knob);
  box-shadow: 0 0 8px var(--uv-knob-shadow);
  transition: left 0.6s ease;
}

/* ---- Theme toggle ---- */
.theme-toggle {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.theme-toggle:hover {
  background: var(--bg-card-hover);
  color: var(--accent);
}

.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
:root.light .theme-toggle .icon-sun { display: block; }
:root.light .theme-toggle .icon-moon { display: none; }

/* ---- Footer ---- */
.footer {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer-sub {
  margin-top: 0.3rem;
  font-size: 0.68rem;
  color: var(--text-dim);
  opacity: 0.6;
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .extra-grid { grid-template-columns: 1fr; }
  .header-meta { display: none; }
  .daily-row { grid-template-columns: 90px 28px 1fr 50px; gap: 0.6rem; padding: 0.8rem 1rem; }
  .current-temp { font-size: 5rem; }
}
