* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  border: none;
  outline: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

:root {
  --bg-grad-start: #7c6bf0;
  --bg-grad-end: #2a2265;
  --card-bg: rgba(255, 255, 255, 0.9);
  --card-border: rgba(255, 255, 255, 0.6);
  --text-main: #1c1a33;
  --text-muted: #6b6b80;
  --accent: #6d5bd0;
  --accent-contrast: #ffffff;
  --field-bg: #eef0fb;
  --shadow: 0 20px 60px rgba(30, 20, 80, 0.35);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --danger: #dc2626;
  --danger-bg: rgba(220, 38, 38, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-grad-start: #2a2454;
    --bg-grad-end: #0f0d24;
    --card-bg: rgba(28, 25, 56, 0.75);
    --card-border: rgba(255, 255, 255, 0.08);
    --text-main: #f2f1fa;
    --text-muted: #a7a4c2;
    --accent: #8b7bf2;
    --accent-contrast: #14122b;
    --field-bg: rgba(255, 255, 255, 0.06);
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    --danger: #f87171;
    --danger-bg: rgba(248, 113, 113, 0.15);
  }
}

body {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 16px;
  background: radial-gradient(circle at top, var(--bg-grad-start), var(--bg-grad-end));
  color: var(--text-main);
  transition: background 0.6s ease;
}

.container {
  width: min(94vw, 440px);
  max-width: 100%;
  height: min-content;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow);
  transition: width 0.2s ease;
}

.search-box {
  width: 100%;
  display: flex;
  gap: 10px;
  align-items: center;
}

.search-box input {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  color: var(--text-main);
  background-color: var(--field-bg);
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  transition: box-shadow 0.15s ease;
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.search-box input:focus {
  box-shadow: 0 0 0 2px var(--accent);
}

.icon-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--field-bg);
  color: var(--text-main);
  border-radius: 50%;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.icon-btn:hover {
  color: var(--accent-contrast);
  background-color: var(--accent);
}

.icon-btn:active {
  transform: scale(0.94);
}

.history {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.history:empty {
  margin-top: 0;
}

.history-chip {
  font-size: 13px;
  color: var(--text-muted);
  background-color: var(--field-bg);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  text-transform: capitalize;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.history-chip:hover {
  color: var(--accent-contrast);
  background-color: var(--accent);
}

.error-banner {
  display: none;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background-color: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
}

.error-banner.is-visible {
  display: flex;
}

.loading-state {
  margin-top: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
}

.loading-state.is-visible {
  display: flex;
}

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

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

.weather-body {
  justify-content: center;
  align-items: stretch;
  flex-direction: column;
  gap: 20px;
  margin-block: 20px;
  display: none;
}

.hero-card {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.place-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.place-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: capitalize;
}

.unit-toggle {
  display: flex;
  background-color: var(--field-bg);
  border-radius: 999px;
  padding: 3px;
}

.unit-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.unit-btn.is-active {
  background-color: var(--accent);
  color: var(--accent-contrast);
}

.weather-body img.weather-img {
  width: 50%;
  max-width: 160px;
  margin-top: 4px;
}

.weather-box {
  margin-block: 8px;
  text-align: center;
}

.weather-box .temperature {
  font-size: 48px;
  font-weight: 800;
  position: relative;
}

.weather-box .temperature sup {
  font-size: 20px;
  position: absolute;
  font-weight: 600;
  margin-left: 4px;
}

.weather-box .description {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: capitalize;
}

.weather-box .feels-like {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.weather-box .feels-like:empty {
  display: none;
}

.weather-details {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.detail {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  background-color: var(--field-bg);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.detail[hidden] {
  display: none;
}

.detail .text {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 0;
}

.detail .text span {
  display: block;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.forecast {
  width: 100%;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.forecast-day {
  flex: 1 0 auto;
  min-width: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  background-color: var(--field-bg);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.forecast-day:hover {
  background-color: var(--accent);
}

.forecast-day:hover .day-label,
.forecast-day:hover .day-temp {
  color: var(--accent-contrast);
}

.forecast-day:active {
  transform: scale(0.96);
}

.forecast-day.is-today {
  background-color: var(--accent);
  cursor: default;
}

.forecast-day.is-today .day-label,
.forecast-day.is-today .day-temp {
  color: var(--accent-contrast);
}

.forecast-day .day-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: capitalize;
}

.forecast-day img {
  width: 32px;
  height: 32px;
}

.forecast-day .day-temp {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
}

.map-card {
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--card-border);
  aspect-ratio: 16 / 9;
}

.map-card[hidden] {
  display: none;
}

.map-frame {
  width: 100%;
  height: 100%;
  display: block;
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 30, 0.55);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-overlay.is-open {
  display: flex;
}

.modal {
  width: 380px;
  max-width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
  color: var(--text-main);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
  text-transform: capitalize;
}

.modal-summary {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-top: 8px;
}

.modal-summary img {
  width: 90px;
  height: 90px;
}

.modal-summary-temps {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.modal-temp {
  font-size: 36px;
  font-weight: 800;
}

.modal-minmax {
  font-size: 14px;
  color: var(--text-muted);
}

.modal-desc {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: capitalize;
  margin-top: 4px;
}

.modal-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 20px;
}

.modal-stat {
  background-color: var(--field-bg);
  border-radius: var(--radius-sm);
  padding: 10px 10px;
  min-width: 0;
}

.modal-stat .stat-label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
}

.modal-stat .stat-value {
  display: block;
  font-size: 15px;
  font-weight: 700;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-chart {
  margin-top: 20px;
}

.modal-chart:empty {
  display: none;
}

.hourly-chart-svg {
  width: 100%;
  height: 90px;
  display: block;
}

.chart-area {
  fill: var(--accent);
  opacity: 0.15;
  stroke: none;
}

.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-dot {
  fill: var(--accent);
}

.modal-hourly {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.modal-hour {
  flex: 1 0 auto;
  min-width: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 6px;
  background-color: var(--field-bg);
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.modal-hour img {
  width: 26px;
  height: 26px;
}

.modal-hour .hour-temp {
  font-weight: 700;
  font-size: 13px;
}

.location-not-found {
  margin-top: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
}

.location-not-found h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-muted);
  margin-block-end: 15px;
}

.location-not-found img {
  width: 60%;
  max-width: 220px;
}

@media only screen and (max-width: 25em) {
  .container {
    padding: 18px;
  }

  .weather-box .temperature {
    font-size: 36px;
  }
}

@media (min-width: 640px) {
  .container {
    width: min(90vw, 620px);
  }

  .weather-details {
    grid-template-columns: repeat(3, 1fr);
  }

  .modal {
    width: 480px;
  }

  .modal-stats {
    grid-template-columns: repeat(4, 1fr);
  }

  .modal-stat .stat-value {
    font-size: 16px;
  }
}

@media (min-width: 1024px) {
  .container {
    width: min(78vw, 760px);
    padding: 36px;
  }

  .weather-body img.weather-img {
    max-width: 180px;
  }

  .weather-box .temperature {
    font-size: 56px;
  }
}
