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

:root {
  --bg: #eef2f7;
  --header-bg: #0f2744;
  --header-text: #ffffff;
  --card-bg: #ffffff;
  --card-border: #dde4ee;
  --card-shadow: rgba(15, 39, 68, 0.08);
  --accent: #1d4ed8;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --temp-hot: #dc2626;
  --temp-cold: #2563eb;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --error-text: #b91c1c;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Header ── */

.site-header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 14px 24px;
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.site-title {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.refresh-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #ffffff;
  padding: 7px 18px;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
}

.refresh-btn:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.46);
}

.refresh-btn:active {
  background: rgba(255, 255, 255, 0.08);
}

.refresh-btn:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

/* ── Main content ── */

.main-content {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
}

/* ── Loading state ── */

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 80px 16px;
  color: var(--text-secondary);
  font-size: 0.9375rem;
}

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

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

/* ── Whole-page error state ── */

.error-state {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
}

.error-state .error-message {
  font-weight: 600;
  color: var(--error-text);
  overflow: hidden;
  text-overflow: ellipsis;
}

.error-state .error-hint {
  margin-top: 8px;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ── Weather grid ── */

.weather-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}

/* ── City card ── */

.city-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 2px 10px var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.city-card--error {
  background: var(--error-bg);
  border-color: var(--error-border);
}

.city-name {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Current weather ── */

.current-weather {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.current-main {
  display: flex;
  align-items: center;
  gap: 10px;
}

.wx-icon {
  flex-shrink: 0;
  color: var(--accent);
}

.current-temp {
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.current-condition {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.current-details {
  display: flex;
  gap: 20px;
  margin-top: 4px;
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.detail-label {
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

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

/* ── Forecast strip ── */

.forecast-strip {
  border-top: 1px solid var(--card-border);
  padding-top: 14px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--card-border) transparent;
}

.forecast-strip::-webkit-scrollbar {
  height: 3px;
}

.forecast-strip::-webkit-scrollbar-thumb {
  background: var(--card-border);
  border-radius: 2px;
}

.forecast-day {
  flex: 1;
  min-width: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
}

.forecast-date {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.forecast-condition {
  font-size: 0.6875rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.forecast-temps {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
}

.temp-max {
  color: var(--temp-hot);
}

.temp-sep {
  color: var(--text-secondary);
  font-weight: 400;
}

.temp-min {
  color: var(--temp-cold);
}

/* ── Per-card error ── */

.card-error {
  flex: 1;
}

.card-error-msg {
  font-size: 0.875rem;
  color: var(--error-text);
  line-height: 1.4;
  max-height: 4.2em;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Responsive ── */

@media (max-width: 640px) {
  .main-content {
    padding: 16px;
  }

  .weather-grid {
    grid-template-columns: 1fr;
  }

  .site-title {
    font-size: 1.125rem;
  }
}

@media (min-width: 641px) and (max-width: 1023px) {
  .weather-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
