/* Themes ported from the original Expo app (src/styles/theme.js on legacy-expo). */
:root, [data-theme="original"] {
  --background: #ffffff; --surface: #f5f5f5; --card: #ffffff;
  --text: #333333; --text-secondary: #666666; --text-muted: #999999;
  --primary: #0055aa; --accent: #cc0000;
  --tab-active: #ffffff; --tab-inactive: #e9e9e9; --tab-border: #cccccc;
  --header-bg: #ffffff; --header-text: #333333; --header-border: 2px; --header-size: 18px;
  --copyright-bg: #f0f0f0; --radar-border: #cccccc; --radar-border-width: 1px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --xs: 4px; --sm: 8px; --md: 16px; --lg: 24px; --xl: 32px;
  --radius-sm: 4px; --radius-md: 8px;
  --chant: #ff0000; --chant-shadow: transparent; --chant-scale: 1;
}
[data-theme="bom"] {
  --background: #f1f1f1; --surface: #e6e6e6; --card: #ffffff;
  --text: #000000; --text-secondary: #333333; --text-muted: #666666;
  --primary: #003366; --accent: #cd0000;
  --tab-active: #ffffff; --tab-inactive: #d9d9d9; --tab-border: #999999;
  --header-bg: #003366; --header-text: #ffffff; --header-border: 5px; --header-size: 22px;
  --copyright-bg: #cccccc; --radar-border: #666666; --radar-border-width: 2px;
  --font: 'Times New Roman', Times, serif;
  --xs: 2px; --sm: 4px; --md: 12px; --lg: 20px; --xl: 28px;
  --radius-sm: 0; --radius-md: 0;
}
[data-theme="memphis"] {
  --background: #fff9f0; --surface: #ffe5df; --card: #ffffff;
  --text: #2d3436; --text-secondary: #636e72; --text-muted: #b2bec3;
  --primary: #6c5ce7; --accent: #00cec9;
  --tab-active: #fab1a0; --tab-inactive: #ffffff; --tab-border: #2d3436;
  --header-bg: #55efc4; --header-text: #2d3436;
  --copyright-bg: #81ecec; --radar-border: #2d3436;
  --xs: 6px; --sm: 10px; --md: 20px; --lg: 30px; --xl: 40px;
  --radius-sm: 12px; --radius-md: 24px;
  --chant: #fd79a8; --chant-shadow: #6c5ce7; --chant-scale: 1.15;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; display: flex; flex-direction: column; overflow: hidden;
  background: var(--background); color: var(--text); font-family: var(--font);
}
button, select { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--primary); }
button:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Keep navigation and the version footer visible while content scrolls. */
.header, .tabs, .controls, .copyright { flex-shrink: 0; }

/* Header */
.header {
  background: var(--header-bg); border-bottom: var(--header-border) solid var(--primary);
  padding: var(--md) var(--lg); text-align: center;
}
.header h1 { margin: 0; color: var(--header-text); font-size: var(--header-size); font-weight: bold; }

/* Navigation tabs */
.tabs { display: flex; background: var(--tab-inactive); border: 1px solid var(--tab-border); }
.tabs button {
  flex: 1; border: 0; border-right: 1px solid var(--tab-border); border-radius: 0;
  background: var(--tab-inactive); color: var(--primary); padding: var(--sm); font-size: 14px; font-weight: 500;
}
.tabs button[data-tab="spending"] { flex: 1.6; }
.tabs button[aria-pressed="true"] { background: var(--tab-active); color: var(--text); font-weight: bold; }

/* Capital city quick bar */
.capitals { display: flex; flex-wrap: wrap; gap: var(--xs); padding: var(--xs); background: var(--card); border-bottom: 1px solid var(--tab-border); }
.capitals button {
  flex: 1 1 auto; padding: 6px var(--sm); font-size: 12px; white-space: nowrap;
  border: 1px solid var(--tab-border); border-radius: var(--radius-sm); background: var(--surface);
}
.capitals button[aria-pressed="true"] { background: var(--tab-active); font-weight: bold; }

/* Location + range row */
.controls {
  display: flex; gap: var(--xs); align-items: center; padding: var(--xs);
  background: var(--card); border-bottom: 1px solid var(--tab-border);
}
.control {
  display: flex; align-items: center; min-width: 0; padding: var(--xs) var(--sm);
  background: var(--card); border: 1px solid var(--tab-border); border-radius: var(--radius-sm);
}
.location-control { flex: 1.35; }
.range-control { flex: 1; justify-content: space-between; }
.control label, .control-title { font-size: 12px; font-weight: bold; margin-right: var(--xs); white-space: nowrap; }
.control select {
  flex: 1; min-width: 0; height: 34px; color: var(--text);
  background: var(--surface); border: 1px solid var(--tab-border); border-radius: var(--radius-sm);
}
.home-button {
  margin-left: var(--xs); padding: 4px var(--sm); min-width: 40px; white-space: nowrap;
  border: 1px solid var(--primary); border-radius: var(--radius-sm); background: var(--card);
  color: var(--primary); font-size: 11px; font-weight: bold;
}
#home { min-width: 76px; }
.home-button[aria-pressed="true"] { background: var(--primary); color: #ffffff; }
.range-control button {
  border: 0; background: transparent; color: var(--primary); font-size: 12px;
  text-decoration: underline; padding: 2px 4px; margin: 0 2px; border-radius: var(--radius-sm); white-space: nowrap;
}
.range-control button[aria-pressed="true"] { background: var(--tab-inactive); color: var(--text); font-weight: bold; text-decoration: none; }
.location-status { margin: 0; padding: 0 var(--sm); font-size: 11px; color: var(--text-secondary); text-align: center; }
.location-status:empty { display: none; }

/* Main content */
.content {
  flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; align-items: center;
  padding: var(--md);
}
#radar-panel { display: flex; flex-direction: column; align-items: center; width: 100%; }
.chant {
  margin: var(--md) 0; color: var(--chant); font-weight: 900; text-align: center; line-height: 1.1;
  font-size: calc(48px * var(--chant-scale)); letter-spacing: 10px;
  text-shadow: 4px 4px 1px var(--chant-shadow);
}
.radar-wrapper {
  width: min(680px, calc(100vw - 32px), max(280px, calc(100vh - 420px)));
  border: var(--radar-border-width) solid var(--radar-border); border-radius: var(--radius-md);
  overflow: hidden; background: var(--card);
}
.radar { position: relative; width: 100%; aspect-ratio: 1; background: var(--surface); overflow: hidden; }
.radar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.radar img:not([src]) { visibility: hidden; }
.radar-status {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--md); padding: var(--lg); text-align: center; color: var(--text-secondary); font-size: 14px;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
}
.radar-status.error { color: var(--accent); font-weight: bold; }
.radar-status.error .spinner { display: none; }
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--tab-border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.frame-counter { margin: var(--xs) 0 0; min-height: 14px; font-size: 11px; color: var(--text-secondary); }

/* Rain legend (BOM colours) */
.rain-legend { padding: var(--sm) var(--md); background: var(--card); border-top: 1px solid var(--header-bg); }
.legend-title { margin: 0 0 var(--xs); font-size: 12px; font-weight: bold; }
.legend-row { display: flex; justify-content: center; align-items: flex-start; }
.legend-section { display: flex; flex-direction: column; align-items: center; }
.swatches { display: flex; }
.swatches i { width: 15px; height: 12px; }
.legend-section span { margin-top: 4px; font-size: 10px; color: var(--text-secondary); }
.radar-extras { display: flex; flex-wrap: wrap; justify-content: center; align-items: stretch; gap: var(--md); margin-top: var(--xs); }

/* "You are here" pin; its tip marks the location. Magenta is not in BOM's rain scale. */
.user-pin {
  position: absolute; z-index: 2; width: 22px; height: 29px; transform: translate(-50%, -100%);
  pointer-events: none; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
}
.user-pin svg { display: block; width: 100%; height: 100%; }
.user-pin path { fill: #e6007e; stroke: #ffffff; stroke-width: 1.5; }
.user-pin circle { fill: #ffffff; }
.radar-status { z-index: 3; }

/* Nearby radars compass (as on BOM loop pages) */
.nearby { padding: var(--sm) var(--md); background: var(--card); border-top: 1px solid var(--header-bg); text-align: center; }
.compass { display: grid; grid-template-columns: repeat(3, 30px); grid-template-rows: repeat(3, 30px); gap: 3px; justify-content: center; }
.compass-arrow {
  position: relative; display: flex; align-items: center; justify-content: center; padding: 0;
  background: var(--surface); color: var(--primary); border: 1px solid var(--tab-border); border-radius: var(--radius-sm);
}
.compass-arrow svg { width: 18px; height: 18px; fill: currentColor; transform: rotate(var(--rot, 0deg)); }
.compass-arrow[data-dir="NE"] { --rot: 45deg; }
.compass-arrow[data-dir="E"] { --rot: 90deg; }
.compass-arrow[data-dir="SE"] { --rot: 135deg; }
.compass-arrow[data-dir="S"] { --rot: 180deg; }
.compass-arrow[data-dir="SW"] { --rot: 225deg; }
.compass-arrow[data-dir="W"] { --rot: 270deg; }
.compass-arrow[data-dir="NW"] { --rot: 315deg; }
.compass-arrow:not(:disabled):hover { background: var(--primary); color: #ffffff; border-color: var(--primary); }
.compass-arrow:disabled { color: var(--tab-border); background: transparent; cursor: default; }
.compass-centre { justify-self: center; align-self: center; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
/* Wide screens: sit the compass beside the radar, like BOM's side panel, keeping the radar centred. */
@media (min-width: 1000px) {
  #radar-panel { display: grid; grid-template-columns: 1fr auto 1fr; justify-items: center; column-gap: var(--lg); }
  #radar-panel > * { grid-column: 2; }
  #radar-panel .radar-extras { display: contents; }
  #radar-panel .rain-legend { grid-column: 2; margin-top: var(--xs); }
  #radar-panel .nearby { grid-column: 3; grid-row: 2; justify-self: start; align-self: start; }
}
/* Tooltip naming the radar an arrow goes to, e.g. "Rainbow, 319km" */
.compass-arrow[data-tip]:not(:disabled):hover::after,
.compass-arrow[data-tip]:not(:disabled):focus-visible::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  z-index: 10; padding: 3px 7px; white-space: nowrap; pointer-events: none;
  background: rgba(0, 0, 0, 0.85); color: #ffffff; border-radius: 3px; font-size: 12px; font-weight: normal;
}

.refresh-button {
  margin-top: var(--sm); padding: 6px var(--lg); background: var(--card); color: var(--primary);
  border: 1px solid var(--primary); border-radius: var(--radius-md); font-size: 13px; font-weight: 500;
}
.refresh-button:disabled { opacity: 0.6; color: var(--text-muted); cursor: default; }

/* Where could the money have gone? ($92M) tab */
.spending {
  width: 100%; max-width: 600px; padding: var(--md); background: var(--card);
  border: 1px solid var(--tab-border); border-radius: var(--radius-md);
}
.spending h2 { margin: 0 0 var(--lg); color: var(--accent); font-size: 24px; text-align: center; }
.spending-intro { margin: calc(-1 * var(--sm)) 0 var(--lg); font-size: 16px; font-weight: bold; text-align: center; }
.spending ul { list-style: none; margin: 0; padding: 0; }
.spending li {
  margin-bottom: var(--md); padding-bottom: var(--sm); border-bottom: 1px solid var(--tab-border);
  font-size: 18px; font-weight: bold;
}
.spending-footer { margin: var(--xl) 0 0; padding-bottom: var(--xl); font-size: 14px; font-style: italic; color: var(--text-muted); text-align: center; }

/* City pages: short intro under the radar */
.city-intro { max-width: 640px; margin: var(--lg) auto 0; font-size: 13px; color: var(--text-secondary); text-align: left; }
.city-intro h2 { margin: 0 0 var(--sm); font-size: 16px; color: var(--text); text-align: center; }
.city-intro p { margin: 0 0 var(--sm); line-height: 1.5; }

/* Footer */
.copyright { background: var(--copyright-bg); padding: var(--sm) var(--md); text-align: center; font-size: 11px; color: var(--text-secondary); }
.copyright p { margin: 0 0 6px; }
.copyright nav { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--md); margin-bottom: 6px; }
.copyright .meta { margin: 0; font-size: 10px; color: var(--text-muted); }
.copyright .site-version { margin: 6px 0 0; font-size: 10px; color: var(--text-secondary); overflow-wrap: anywhere; }

/* Compact screens, matching the old isCompactScreen breakpoints */
@media (max-width: 430px), (max-height: 820px) {
  .tabs button { padding: var(--xs); font-size: 12px; }
  .content { padding: 8px 10px; }
  .chant { margin: 8px 0; font-size: calc(34px * var(--chant-scale)); letter-spacing: 6px; }
  .radar-wrapper { width: min(680px, calc(100vw - 20px), max(280px, calc(100vh - 380px))); }
  .swatches i { width: 12px; height: 10px; }
  .legend-section span { font-size: 9px; margin-top: 2px; }
  .legend-title { font-size: 11px; }
}
@media (max-width: 430px) {
  .capitals { display: grid; grid-template-columns: repeat(4, 1fr); }
  .capitals button { padding: 6px 2px; }
  .controls { flex-direction: column; align-items: stretch; }
  .location-control, .range-control { flex: none; }
}
