:root {
  --page-bg: #0f1021;
  --bg-dark: #0f1021;
  --bg-panel: #1a1c3a;
  --bg-panel-light: #262a54;
  --accent: #7ef9a0;
  --accent2: #ffd54f;
  --accent3: #ff6b6b;
  --accent4: #5ec8ff;
  --text: #e8e8ff;
  --text-dim: #8a8cc4;
  --border: #4a4d8f;
  --blob1: #1e2050;
  --blob2: #251b45;
  --scan-opacity: 0.15;

  /* constant colors for the always-dark "LCD screen" tiles */
  --screen-dim: #8a8cc4;
  --screen-muted: #4a4d8f;

  /* shell/bezel accents — sit directly on the themed page/card background */
  --shell-warm: #ffd54f;
  --shell-warm-shadow: #7a5c00;
  --shell-cool: #5ec8ff;
  --shell-danger: #ff6b6b;
}

:root[data-theme="light"] {
  --page-bg: #dfe3f5;
  --bg-panel: #f4f5ff;
  --bg-panel-light: #f8f9ff;
  --text: #23244a;
  --text-dim: #5d5f96;
  --border: #9ea3e0;
  --blob1: #c9cef2;
  --blob2: #dccdf0;
  --scan-opacity: 0.05;

  --shell-warm: #9a6a0d;
  --shell-warm-shadow: rgba(255, 255, 255, 0.6);
  --shell-cool: #1f6fa8;
  --shell-danger: #c23a3a;
}

* {
  box-sizing: border-box;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--page-bg);
  background-image:
    radial-gradient(circle at 20% 20%, var(--blob1) 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, var(--blob2) 0%, transparent 45%);
  font-family: "Press Start 2P", monospace;
  color: var(--text);
  display: flex;
  align-items: safe center;
  justify-content: safe center;
  min-height: 100vh;
  padding: 16px;
  transition: background-color 0.2s ease;
}

.crt {
  position: relative;
  width: 100%;
  max-width: 460px;
}

.scanlines {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,var(--scan-opacity)) 0px,
    rgba(0,0,0,var(--scan-opacity)) 1px,
    transparent 1px,
    transparent 3px
  );
  z-index: 5;
  border-radius: 4px;
}

.app {
  position: relative;
  background: var(--bg-panel);
  border: 4px solid var(--border);
  box-shadow:
    0 0 0 4px var(--bg-dark),
    0 0 0 8px var(--border),
    8px 8px 0 0 rgba(0,0,0,0.5);
  padding: 16px;
  border-radius: 2px;
  transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.titlebar {
  text-align: center;
  margin-bottom: 16px;
}

.titlebar h1 {
  font-size: 12px;
  color: var(--shell-warm);
  text-shadow: 2px 2px 0 var(--shell-warm-shadow);
  margin: 0;
  letter-spacing: 1px;
}

.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

#cityInput {
  flex: 1;
  min-width: 0;
  font-family: "Press Start 2P", monospace;
  font-size: 9px;
  padding: 10px 8px;
  background: var(--bg-dark);
  border: 3px solid var(--border);
  color: var(--accent);
  outline: none;
}

#cityInput::placeholder {
  color: var(--screen-dim);
}

#cityInput:focus {
  border-color: var(--accent4);
}

.btn {
  font-family: "Press Start 2P", monospace;
  font-size: 10px;
  padding: 10px 12px;
  background: var(--accent);
  color: #0a3d1f;
  border: 3px solid #3a7a52;
  cursor: pointer;
  box-shadow: 3px 3px 0 0 #0a3d1f;
  transition: transform 0.05s ease;
  white-space: nowrap;
}

.btn:active {
  transform: translate(3px, 3px);
  box-shadow: 0 0 0 0 #0a3d1f;
}

#locBtn {
  background: var(--accent4);
  border-color: #2a6a8f;
  box-shadow: 3px 3px 0 0 #2a6a8f;
  padding: 10px;
}

#locBtn:active {
  box-shadow: 0 0 0 0 #2a6a8f;
}

#themeToggle {
  background: #c77dff;
  border-color: #6a3d99;
  box-shadow: 3px 3px 0 0 #6a3d99;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#themeToggle:active {
  box-shadow: 0 0 0 0 #6a3d99;
}

.theme-icon {
  width: 16px;
  height: 16px;
  image-rendering: pixelated;
  display: block;
}

.status {
  min-height: 16px;
  font-size: 9px;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 8px;
  line-height: 1.6;
}

.status.error {
  color: var(--shell-danger);
}

.card {
  background: var(--bg-panel-light);
  border: 3px solid var(--border);
  padding: 16px;
  animation: pop-in 0.15s steps(3) both;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.card.hidden {
  display: none;
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.location {
  text-align: center;
  font-size: 10px;
  color: var(--shell-cool);
  margin-bottom: 12px;
  letter-spacing: 0.5px;
}

.now-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 16px;
}

.pixel-icon {
  width: 80px;
  height: 80px;
  image-rendering: pixelated;
  filter: drop-shadow(3px 3px 0 rgba(0,0,0,0.4));
}

.temp-block {
  text-align: left;
}

.temp {
  font-size: 28px;
  color: var(--shell-warm);
  text-shadow: 2px 2px 0 var(--shell-warm-shadow);
  line-height: 1;
  margin-bottom: 8px;
}

.desc {
  font-size: 8px;
  color: var(--text-dim);
  line-height: 1.4;
}

.section-title {
  font-size: 7px;
  color: var(--shell-warm);
  letter-spacing: 1px;
  margin: 14px 0 6px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 4px;
}

.section-title:first-of-type {
  margin-top: 0;
}

.stats-row-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}

.stats-row-3 .stat {
  padding: 8px 4px;
  background: var(--bg-dark);
  border: 2px solid var(--border);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  flex: 1;
}

.stat-icon {
  width: 20px;
  height: 20px;
  image-rendering: pixelated;
}

.stat-label {
  font-size: 6px;
  color: var(--screen-dim);
  text-align: center;
}

.stat-value {
  font-size: 8px;
  color: var(--accent);
  text-align: center;
}

.gauge-wrap {
  position: relative;
  width: 22px;
  height: 22px;
}

.gauge-wrap .gauge-dial {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.needle {
  position: absolute;
  left: 50%;
  width: 0;
  height: 0;
  border-left: 2px solid transparent;
  border-right: 2px solid transparent;
  filter: drop-shadow(0 0 2px rgba(0,0,0,0.6));
}

.needle-center {
  top: 50%;
  border-bottom: 9px solid var(--accent2);
  margin-left: -2px;
  margin-top: -9px;
  transform-origin: 50% 100%;
}

.needle-gauge {
  bottom: 3px;
  border-bottom: 8px solid var(--accent3);
  margin-left: -2px;
  transform-origin: 50% 100%;
}

.uv-bar {
  display: flex;
  gap: 2px;
  height: 10px;
  align-items: flex-end;
}

.uv-seg {
  width: 6px;
  height: 6px;
  background: var(--screen-muted);
  border: 1px solid var(--bg-dark);
}

.uv-seg.filled {
  height: 10px;
}

.sun-arc {
  display: block;
  width: 100%;
  height: 56px;
  margin-bottom: 8px;
  image-rendering: pixelated;
  background: var(--bg-dark);
  border: 2px solid var(--border);
}

.lungs-icon {
  width: 20px;
  height: 20px;
  image-rendering: pixelated;
}

.aqi-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  padding: 10px 8px;
  background: var(--bg-dark);
  border: 2px solid var(--border);
  align-items: center;
}

.aqi-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 64px;
  height: 72px;
  flex-shrink: 0;
  border: 2px solid var(--border);
  background: var(--bg-dark);
}

.aqi-value {
  font-size: 16px;
  color: var(--accent);
}

.aqi-label {
  font-size: 6px;
  color: var(--screen-dim);
  text-align: center;
}

.aqi-details {
  display: flex;
  gap: 6px;
  flex: 1;
}

.forecast {
  display: flex;
  justify-content: space-between;
  gap: 4px;
  margin-bottom: 12px;
}

.fday {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 2px;
  background: var(--bg-dark);
  border: 2px solid var(--border);
}

.fday .fname {
  font-size: 6px;
  color: var(--screen-dim);
}

.fday canvas {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
}

.fday .ftemp {
  font-size: 7px;
  color: var(--accent2);
}

.fday .fprecip {
  font-size: 6px;
  color: var(--accent4);
}

.footer-note {
  text-align: center;
  font-size: 6px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

@media (max-width: 420px) {
  .titlebar h1 { font-size: 10px; }
  #cityInput { font-size: 8px; }
  .temp { font-size: 22px; }
  .aqi-details { flex-direction: column; }
}
