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

:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-hover: rgba(255, 255, 255, 0.08);
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.6);
  --text-muted: rgba(255, 255, 255, 0.35);
  --accent: #6c63ff;
  --accent-glow: rgba(108, 99, 255, 0.25);
  --border: rgba(255, 255, 255, 0.06);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  --error-bg: rgba(255, 71, 87, 0.15);
  --error-text: #ff4757;
  --glass-border: rgba(255, 255, 255, 0.08);
  --scrollbar-bg: rgba(255, 255, 255, 0.05);
  --scrollbar-thumb: rgba(255, 255, 255, 0.15);
  --precip: #60a5fa;
  --warm: #fb923c;
  --cold: #60a5fa;
  --aqi-1: #22c55e;
  --aqi-2: #eab308;
  --aqi-3: #f97316;
  --aqi-4: #ef4444;
  --aqi-5: #a855f7;
  --fav: #fbbf24;
}

[data-theme="light"] {
  --bg-primary: #f5f5fa;
  --bg-secondary: #ffffff;
  --bg-card: rgba(0, 0, 0, 0.03);
  --bg-card-hover: rgba(0, 0, 0, 0.06);
  --text-primary: #1a1a2e;
  --text-secondary: rgba(0, 0, 0, 0.55);
  --text-muted: rgba(0, 0, 0, 0.3);
  --accent: #6c63ff;
  --accent-glow: rgba(108, 99, 255, 0.15);
  --border: rgba(0, 0, 0, 0.06);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.06);
  --error-bg: rgba(255, 71, 87, 0.1);
  --error-text: #e03131;
  --glass-border: rgba(0, 0, 0, 0.06);
  --scrollbar-bg: rgba(0, 0, 0, 0.03);
  --scrollbar-thumb: rgba(0, 0, 0, 0.12);
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  transition: background 0.6s ease, color 0.4s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body::before {
  content: '';
  position: fixed;
  top: -50%;
  right: -50%;
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse at 70% 20%, rgba(108, 99, 255, 0.08) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
  transition: background 0.8s ease;
}

.bg-clear::before { background: radial-gradient(ellipse at 60% 30%, rgba(251, 191, 36, 0.1) 0%, transparent 50%); }
.bg-clouds::before { background: radial-gradient(ellipse at 50% 20%, rgba(200, 200, 220, 0.06) 0%, transparent 50%); }
.bg-rain::before { background: radial-gradient(ellipse at 50% 30%, rgba(96, 165, 250, 0.1) 0%, transparent 50%); }
.bg-drizzle::before { background: radial-gradient(ellipse at 50% 30%, rgba(147, 197, 253, 0.08) 0%, transparent 50%); }
.bg-thunderstorm::before { background: radial-gradient(ellipse at 50% 30%, rgba(120, 80, 200, 0.12) 0%, transparent 50%); }
.bg-snow::before { background: radial-gradient(ellipse at 50% 30%, rgba(255, 255, 255, 0.06) 0%, transparent 50%); }
.bg-atmosphere::before { background: radial-gradient(ellipse at 50% 30%, rgba(200, 200, 210, 0.06) 0%, transparent 50%); }

.app-container {
  position: relative;
  z-index: 1;
  max-width: 900px;
  margin: 0 auto;
  padding: 0 20px;
  min-height: 100vh;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 0 14px;
}

.header-left {
  display: flex;
  align-items: center;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo {
  font-size: 1.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.kb-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}

.kb-hint kbd {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: inherit;
  font-size: 0.65rem;
}

.unit-toggle {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.3s ease;
  color: var(--text-muted);
  font-family: inherit;
  font-weight: 600;
  line-height: 1;
}

.unit-toggle:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
  color: var(--text-primary);
}

.unit-divider {
  color: var(--text-muted);
  font-weight: 300;
  opacity: 0.3;
}

.unit-label {
  padding: 2px 4px;
  border-radius: 6px;
  transition: all 0.3s ease;
}

.unit-label.active {
  background: var(--accent);
  color: #fff;
}

.theme-toggle {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.3s ease;
  color: var(--text-secondary);
}

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

[data-theme="dark"] .icon-sun { display: inline; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: inline; }

.main-content {
  padding: 24px 0 60px;
}

.search-section {
  margin-bottom: 20px;
}

.search-container {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.search-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: stretch;
}

.search-input {
  flex: 1;
  padding: 14px 48px 14px 18px;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

.search-input::placeholder {
  color: var(--text-muted);
  transition: color 0.3s ease;
}

.search-input:focus {
  border-color: var(--accent);
  background: var(--bg-card-hover);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 10px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-btn:hover {
  color: var(--accent);
  background: var(--accent-glow);
}

.geo-btn {
  padding: 0 18px;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
}

.geo-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

.recent-searches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  min-height: 0;
}

.recent-tag {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.recent-tag:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

.fav-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.fav-tag {
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 6px;
}

.fav-tag::before {
  content: '⭐';
  font-size: 0.75rem;
}

.fav-tag:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

.weather-card {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 32px;
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  transition: all 0.4s ease;
  animation: fadeUp 0.5s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.weather-main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
}

.weather-primary {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.city-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.city-name {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.2;
}

.city-name::after {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  margin-left: 8px;
  vertical-align: super;
  animation: pulse 2s infinite;
}

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

.fav-btn {
  background: transparent;
  border: none;
  font-size: 1.6rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s ease;
  padding: 0;
  line-height: 1;
}

.fav-btn:hover {
  transform: scale(1.2);
}

.fav-btn.is-fav {
  color: var(--fav);
}

.weather-desc {
  color: var(--text-secondary);
  font-size: 1rem;
  text-transform: capitalize;
  font-weight: 400;
}

.temp-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.current-temp {
  font-size: 4rem;
  font-weight: 800;
  letter-spacing: -2px;
  line-height: 1;
  background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.temp-row .weather-icon {
  width: 72px;
  height: 72px;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.15));
}

.temp-range {
  display: flex;
  gap: 16px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  margin-top: 4px;
}

.feels-compare {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 400;
  margin-top: 8px;
  font-style: italic;
}

.weather-details {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  align-content: start;
}

.detail-item {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: all 0.2s ease;
}

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

.detail-label {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

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

.detail-value .aqi-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.detail-value .aqi-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.aqi-1 .aqi-dot { background: var(--aqi-1); }
.aqi-2 .aqi-dot { background: var(--aqi-2); }
.aqi-3 .aqi-dot { background: var(--aqi-3); }
.aqi-4 .aqi-dot { background: var(--aqi-4); }
.aqi-5 .aqi-dot { background: var(--aqi-5); }

.aqi-label { font-weight: 400; font-size: 0.85rem; }

.forecast-section {
  margin-top: 28px;
  animation: fadeUp 0.5s ease 0.1s both;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-secondary);
}

.chart-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 16px;
  overflow: hidden;
}

.temp-chart {
  width: 100%;
  height: auto;
  display: block;
}

.hourly-container {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 8px 4px 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

.hourly-container::-webkit-scrollbar { height: 4px; }
.hourly-container::-webkit-scrollbar-track { background: var(--scrollbar-bg); border-radius: 4px; }
.hourly-container::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }

.hourly-item {
  flex: 0 0 90px;
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 16px 12px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  text-align: center;
}

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

.hourly-item .hourly-time {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.hourly-item .hourly-icon {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.hourly-item .hourly-temp {
  font-size: 1rem;
  font-weight: 700;
}

.hourly-precip {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
}

.hourly-precip.has-precip {
  color: var(--precip);
}

.weekly-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.weekly-item {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 16px 20px;
  display: grid;
  grid-template-columns: 100px 1fr 60px 80px 80px;
  align-items: center;
  gap: 16px;
  transition: all 0.2s ease;
}

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

.weekly-item .weekly-day {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.weekly-item .weekly-desc {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.weekly-item .weekly-desc img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.weekly-item .weekly-precip {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--precip);
  text-align: center;
}

.weekly-item .weekly-temps {
  display: flex;
  gap: 8px;
  font-weight: 600;
  font-size: 0.95rem;
}

.weekly-item .weekly-high { color: var(--warm); }
.weekly-item .weekly-low { color: var(--text-muted); }

.loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 15, 26, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
}

[data-theme="light"] .loading {
  background: rgba(245, 245, 250, 0.6);
}

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

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

.error-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--error-bg);
  border: 1px solid rgba(255, 71, 87, 0.2);
  color: var(--error-text);
  padding: 14px 24px;
  border-radius: 14px;
  font-weight: 500;
  font-size: 0.9rem;
  backdrop-filter: blur(10px);
  z-index: 200;
  animation: slideUp 0.3s ease;
  max-width: 90vw;
  text-align: center;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.hidden { display: none !important; }

@media (max-width: 800px) {
  .weather-details { grid-template-columns: 1fr 1fr; }
  .weekly-item { grid-template-columns: 80px 1fr 50px 60px 60px; gap: 10px; }
}

@media (max-width: 700px) {
  .app-container { padding: 0 16px; }
  .header { padding: 18px 0 12px; }
  .logo { font-size: 1.25rem; }
  .header-right { gap: 6px; }
  .kb-hint { font-size: 0.6rem; }
  .main-content { padding: 20px 0 40px; }
  .weather-card { padding: 24px 20px; }
  .weather-main { grid-template-columns: 1fr; gap: 24px; }
  .city-name { font-size: 1.4rem; }
  .current-temp { font-size: 3rem; }
  .temp-row .weather-icon { width: 56px; height: 56px; }
  .weather-details { grid-template-columns: 1fr 1fr; gap: 8px; }
  .detail-item { padding: 10px 12px; }
  .detail-value { font-size: 0.95rem; }
  .weekly-item { grid-template-columns: 70px 1fr 40px 50px 50px; padding: 14px 16px; gap: 8px; font-size: 0.85rem; }
  .weekly-item .weekly-desc img { width: 28px; height: 28px; }
  .hourly-item { flex: 0 0 76px; padding: 12px 8px 10px; }
  .search-container { flex-direction: row; }
}

@media (max-width: 450px) {
  .weekly-item { grid-template-columns: 60px 1fr 35px 45px 45px; padding: 12px 12px; gap: 6px; font-size: 0.8rem; }
  .weekly-item .weekly-desc img { width: 24px; height: 24px; }
  .weather-details { grid-template-columns: 1fr 1fr; gap: 6px; }
  .detail-item { padding: 8px 10px; }
  .detail-value { font-size: 0.85rem; }
  .detail-label { font-size: 0.65rem; }
  .kb-hint { display: none; }
}
