:root {
  color-scheme: light dark;
  --bg: #f2f5f9;
  --surface: #ffffff;
  --text: #1c2331;
  --muted: #5b6472;
  --accent: #2f6fed;
  --border: #e1e6ee;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10141c;
    --surface: #1a212e;
    --text: #eef1f6;
    --muted: #96a1b3;
    --accent: #6fa1ff;
    --border: #2a3242;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body.modal-open {
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
  min-height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0 1rem;
}

.app-header h1 {
  font-size: 1.4rem;
  margin: 0;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 2.25rem;
  height: 2.25rem;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text);
}

.search-bar {
  display: flex;
  gap: 0.5rem;
  position: relative;
  margin-bottom: 0.5rem;
}

.quick-link {
  display: inline-block;
  background: none;
  border: none;
  padding: 0;
  margin: 0 0 1rem;
  color: var(--accent);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  text-decoration: underline;
}

.search-bar input {
  flex: 1;
  padding: 0.65rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}

.search-bar input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.search-results {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  overflow: hidden;
}

.search-results li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-radius: 0.5rem;
  cursor: pointer;
}

.search-results li:hover,
.search-results li:focus {
  background: var(--bg);
}

.search-results li .result-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.star-btn {
  flex: 0 0 auto;
  background: none;
  border: none;
  padding: 0.15rem;
  font-size: 1.15rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}

.star-btn.active {
  color: #f2b400;
}

.location {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.favorites-menu {
  position: relative;
}

.favorites-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  width: 15rem;
  max-height: 20rem;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  padding: 0.5rem;
  z-index: 6;
}

.favorites-dropdown[hidden] {
  display: none;
}

.favorites-empty {
  margin: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.favorites-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.favorites-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-radius: 0.5rem;
}

.favorites-list li:hover {
  background: var(--bg);
}

.favorites-list .favorite-select {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  text-align: left;
  padding: 0.6rem 0.25rem;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.favorites-list .favorite-remove {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
}

.search-results .result-name { font-weight: 600; }
.search-results .result-detail { color: var(--muted); font-size: 0.85rem; margin-left: 0.4rem; }
.search-results .result-empty { color: var(--muted); cursor: default; }

.state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

.primary-btn {
  margin-top: 1rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
}

.primary-btn:active { opacity: 0.85; }

.content { display: flex; flex-direction: column; gap: 1.5rem; }

.current {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.5rem;
  text-align: center;
}

.location {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

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

.current-icon { font-size: 3rem; }
.current-temp { font-size: 3rem; font-weight: 600; }

.current-desc {
  margin: 0.25rem 0 0;
  font-size: 1.1rem;
}

.current-feels {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.current-details {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.current-details div {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.current-details span {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.current-details strong { font-size: 1rem; }

h2 {
  font-size: 1rem;
  margin: 0 0 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.hourly-scroll {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.hour-card {
  flex: 0 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  text-align: center;
  min-width: 4.5rem;
}

.hour-card .time { font-size: 0.8rem; color: var(--muted); }
.hour-card .icon { font-size: 1.5rem; margin: 0.35rem 0; }
.hour-card .temp { font-weight: 600; }
.hour-card .pop { font-size: 0.75rem; color: var(--accent); }

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

.day-row {
  display: grid;
  grid-template-columns: 5rem 2rem 1fr auto;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.6rem 1rem;
}

.day-row .day { font-size: 0.9rem; }
.day-row .icon { font-size: 1.3rem; text-align: center; }
.day-row .pop { font-size: 0.8rem; color: var(--accent); }
.day-row .temps { font-size: 0.9rem; white-space: nowrap; }
.day-row .temps .max { font-weight: 600; }
.day-row .temps .min { color: var(--muted); }

.day-row {
  cursor: pointer;
  border: 1px solid var(--border);
  text-align: left;
  width: 100%;
  font-family: inherit;
  color: inherit;
}

.day-row:hover,
.day-row:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}

.modal-overlay[hidden] {
  display: none;
}

@media (min-width: 640px) {
  .modal-overlay {
    align-items: center;
  }
}

.modal {
  background: var(--surface);
  color: var(--text);
  border-radius: 1rem 1rem 0 0;
  padding: 1.5rem;
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
}

@media (min-width: 640px) {
  .modal {
    border-radius: 1rem;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.modal-main {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.modal-icon { font-size: 2.75rem; }

.modal-desc {
  margin: 0 0 0.2rem;
  font-size: 1.05rem;
}

.modal-temps {
  margin: 0;
  font-size: 0.95rem;
}

.modal-temps .max { font-weight: 600; }
.modal-temps .min { color: var(--muted); }

.modal-details {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.modal-details div {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.modal-details span {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.modal-details strong { font-size: 0.95rem; }

.modal h3 {
  font-size: 1rem;
  margin: 0 0 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.install-banner {
  position: fixed;
  left: 0.75rem;
  right: 0.75rem;
  bottom: 0.75rem;
  z-index: 9;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 0.85rem 1rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  max-width: 640px;
  margin: 0 auto;
}

.install-banner[hidden] {
  display: none;
}

.install-icon { font-size: 1.6rem; }

.install-banner p {
  flex: 1;
  margin: 0;
  font-size: 0.9rem;
}

.install-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.primary-btn.small {
  margin-top: 0;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  white-space: nowrap;
}

.radar-view {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.radar-view[hidden] {
  display: none;
}

.radar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.radar-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.radar-map {
  flex: 1;
  min-height: 0;
}

.radar-legend {
  padding: 0.6rem 1rem 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.radar-legend-title {
  margin: 0 0 0.4rem;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.radar-legend-bar {
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    #0a4a6e 0%,
    #1bafe2 22%,
    #7fe0c8 38%,
    #ffee00 55%,
    #ff8b00 72%,
    #ff4400 86%,
    #ff62ff 100%
  );
}

.radar-legend-labels {
  display: flex;
  justify-content: space-between;
  margin: 0.3rem 0 0;
  font-size: 0.7rem;
  color: var(--muted);
}

.radar-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.radar-controls input[type='range'] {
  flex: 1;
}

.radar-time {
  font-size: 0.85rem;
  color: var(--muted);
  min-width: 3.5rem;
  text-align: right;
  white-space: nowrap;
}

.radar-time.is-forecast {
  color: var(--accent);
  font-weight: 600;
}
