/* ─── ACCESSIBILITY UTILITIES ───────────────────────────────────────────────── */

/* Screen-reader only — visually hidden but readable by assistive tech */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* Skip-to-content link — invisible until focused */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  background: var(--accent);
  color: #020408;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.5rem 1rem;
  border-radius: 0 0 6px 6px;
  z-index: 9999;
  text-decoration: none;
  transition: top 0.2s;
}
.skip-link:focus { top: 0; }

/* Global focus ring — visible for keyboard users, hidden for mouse */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 3px;
}
:focus:not(:focus-visible) { outline: none; }

/* Reduced motion — kill all animations for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .dot { animation: none; opacity: 1; }
}

/* ─── RESET & BASE ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent:        #4db8ff;
  --accent-hover:  #7dcfff;
  --bg-night:      #020408;
  --bg-day:        #1a6bbf;
  --glass-bg:      rgba(2, 4, 8, 0.75);
  --glass-border:  rgba(77, 184, 255, 0.2);
  --text-primary:  #e8f4fd;
  --text-muted:    rgba(180, 210, 255, 0.75);  /* was 0.6 — bumped for WCAG AA */
  --text-faint:    rgba(180, 210, 255, 0.55);  /* was 0.35 — bumped for WCAG AA */
  --font-mono:     'Space Mono', monospace;
  --font-sans:     'Inter', sans-serif;
  --radius-pill:   999px;
  --radius-card:   10px;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-night);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  height: 100dvh;   /* track the dynamic viewport so mobile browser chrome doesn't clip the UI */
  width: 100vw;
  cursor: crosshair;
}

/* ─── SPLASH ────────────────────────────────────────────────────────────────── */
#splash {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 80%, #0a1628 0%, #020408 70%);
  z-index: 100;
  gap: 0;
}

#splash-stars {
  position: absolute; inset: 0;
  pointer-events: none;
}

.splash-title {
  font-family: var(--font-mono);
  font-size: clamp(2.5rem, 6vw, 5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
  position: relative; z-index: 1;
  margin-bottom: 0.5rem;
}
.splash-title span { color: var(--accent); }

.splash-sub {
  font-size: 1rem;
  color: rgba(200, 220, 255, 0.55);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 3.5rem;
  position: relative; z-index: 1;
  font-weight: 300;
}

.input-row {
  display: flex;
  width: min(560px, 90vw);
  position: relative; z-index: 1;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(77, 184, 255, 0.3);
  background: rgba(5, 15, 35, 0.8);
  backdrop-filter: blur(12px);
}

#addr-input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 1rem 1.25rem;
  font-family: var(--font-sans);
  font-size: 1rem;
  color: var(--text-primary);
  outline: none;
}
#addr-input::placeholder { color: var(--text-faint); }

#go-btn {
  background: var(--accent);
  border: none;
  padding: 0 1.5rem;
  color: #020408;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}
#go-btn:hover { background: var(--accent-hover); }

.or-line {
  position: relative; z-index: 1;
  color: rgba(200, 220, 255, 0.3);
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  margin: 1.25rem 0;
  display: flex; align-items: center; gap: 1rem;
  width: min(560px, 90vw);
}
.or-line::before, .or-line::after {
  content: ''; flex: 1;
  height: 1px; background: rgba(200, 220, 255, 0.12);
}

#loc-btn {
  position: relative; z-index: 1;
  background: transparent;
  border: 1px solid rgba(77, 184, 255, 0.25);
  color: var(--text-muted);
  padding: 0.7rem 1.5rem;
  border-radius: 6px;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex; align-items: center; gap: 0.5rem;
}
#loc-btn:hover { border-color: var(--accent); color: var(--accent); }

#splash-error {
  position: relative; z-index: 1;
  color: #ff7070;
  font-size: 0.85rem;
  margin-top: 1rem;
  min-height: 1.2rem;
  text-align: center;
}

/* ─── MAIN APP ──────────────────────────────────────────────────────────────── */
#app {
  display: none;
  position: fixed; inset: 0;
}

#sky-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  /* Treat a quick double-tap as two taps (no zoom-delay), but keep pinch-zoom
     available for low-vision users who want to zoom into the sky. */
  touch-action: manipulation;
}

/* ─── CENTRE CROSSHAIR ──────────────────────────────────────────────────────── */
#crosshair {
  position: absolute;
  top: 50%; left: 50%;
  width: 160px; height: 160px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  user-select: none;
  z-index: 9;
}
.ch-arm {
  position: absolute;
  background: rgba(77, 184, 255, 0.35);
  box-shadow: 0 0 8px rgba(77, 184, 255, 0.4);
}
/* Vertical and horizontal arms, leaving a gap at the centre */
.ch-v {
  top: 0; bottom: 0; left: 50%;
  width: 1.5px; transform: translateX(-50%);
}
.ch-h {
  left: 0; right: 0; top: 50%;
  height: 1.5px; transform: translateY(-50%);
}
.ch-dot {
  position: absolute;
  top: 50%; left: 50%;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: rgba(77, 184, 255, 0.8);
  box-shadow: 0 0 10px rgba(77, 184, 255, 0.7);
  transform: translate(-50%, -50%);
}
.ch-dir {
  position: absolute;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.6);
  text-shadow: 0 0 10px rgba(77, 184, 255, 0.5);
}
.ch-n { top: -1.1rem;    left: 50%; transform: translateX(-50%); }
.ch-s { bottom: -1.1rem; left: 50%; transform: translateX(-50%); }
.ch-e { right: -1.1rem;  top: 50%;  transform: translateY(-50%); }
.ch-w { left: -1.1rem;   top: 50%;  transform: translateY(-50%); }

/* Projector mode mirrors the sky E↔W, so the crosshair E/W labels swap sides. */
body.projector-mode .ch-e { right: auto; left: -1.1rem; }
body.projector-mode .ch-w { left: auto; right: -1.1rem; }
body.day-mode #crosshair .ch-dir { color: rgba(0,20,60,0.6); text-shadow: none; }
body.day-mode .ch-arm { background: rgba(0,40,90,0.3); box-shadow: none; }
body.day-mode .ch-dot { background: rgba(0,40,90,0.6); box-shadow: none; }

/* ─── TOP BAR ───────────────────────────────────────────────────────────────── */
#topbar {
  position: absolute;
  top: 1.5rem; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 1rem;
  background: rgba(2, 4, 8, 0.7);
  backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  padding: 0.5rem 1.25rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.05em;
  z-index: 10;
  white-space: nowrap;
}
#topbar .sep      { color: rgba(77, 184, 255, 0.3); }
#topbar #loc-display {
  color: rgba(180, 210, 255, 0.9);
  text-decoration: none;
  cursor: pointer;
  transition: color 0.15s;
}
#topbar #loc-display:hover { color: var(--accent); text-decoration: underline; }

/* ─── HAMBURGER MENU ────────────────────────────────────────────────────────── */
#menu-btn {
  position: absolute;
  top: 1.5rem; right: 1.5rem;
  width: 38px; height: 38px;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  cursor: pointer;
  z-index: 30;
  transition: border-color 0.2s;
}
#menu-btn:hover { border-color: var(--accent); }
#menu-btn span {
  display: block;
  width: 14px; height: 1.5px;
  background: var(--text-muted);
  border-radius: 2px;
  transition: all 0.25s;
}
#menu-btn.open span:nth-child(1) { transform: translateY(5.5px) rotate(45deg); }
#menu-btn.open span:nth-child(2) { opacity: 0; transform: scaleX(0); }
#menu-btn.open span:nth-child(3) { transform: translateY(-5.5px) rotate(-45deg); }

/* ─── SLIDE-OUT MENU PANEL ──────────────────────────────────────────────────── */
#menu-panel {
  position: absolute;
  top: 1.5rem; right: 5rem;
  width: 280px;
  background: rgba(2, 6, 18, 0.96);
  backdrop-filter: blur(24px);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  z-index: 29;
  overflow-y: auto;
  max-height: calc(100vh - 3rem);
  transform: scale(0.92) translateY(-8px);
  transform-origin: top right;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
#menu-panel.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

.menu-section {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(77, 184, 255, 0.08);
}
.menu-section:last-child { border-bottom: none; }

.menu-section-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: rgba(77, 184, 255, 0.45);
  margin-bottom: 0.75rem;
}

/* Sky mode toggle row */
.mode-row {
  display: flex; gap: 0.35rem;
}
.mode-chip, .orient-chip {
  flex: 1;
  background: transparent;
  border: 1px solid rgba(77, 184, 255, 0.15);
  border-radius: var(--radius-pill);
  padding: 0.4rem 0;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.18s;
  text-align: center;
}
.mode-chip:hover, .orient-chip:hover { border-color: var(--accent); color: var(--text-primary); }
.mode-chip.active, .orient-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #020408;
}
.orient-hint {
  margin-top: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  line-height: 1.5;
  color: var(--text-muted);
  opacity: 0.7;
}

/* Satellite tier dropdown */
.menu-select {
  width: 100%;
  background: rgba(5, 15, 35, 0.8);
  border: 1px solid rgba(77, 184, 255, 0.2);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  transition: border-color 0.18s;
}
.menu-select:hover, .menu-select:focus { border-color: var(--accent); }
.menu-select option { background: #050f23; color: var(--text-primary); }

/* Toggle switch (deep-sky objects) */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.toggle-row .menu-section-label { margin-bottom: 0; }
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; inset: 0; cursor: pointer;
  background: rgba(77, 184, 255, 0.15);
  border: 1px solid rgba(77, 184, 255, 0.25);
  border-radius: var(--radius-pill);
  transition: background 0.2s, border-color 0.2s;
}
.switch-slider::before {
  content: ''; position: absolute;
  height: 16px; width: 16px; left: 2px; top: 2px;
  background: #9fb6d8; border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.switch input:checked + .switch-slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); background: #021018; }
.switch input:focus-visible + .switch-slider { outline: 2px solid var(--accent); outline-offset: 2px; }

/* About section */
.about-body {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.65;
}
.about-body strong {
  color: var(--text-primary);
  font-weight: 500;
}
.about-tip {
  margin-top: 0.6rem;
  padding: 0.6rem 0.75rem;
  background: rgba(77, 184, 255, 0.06);
  border-left: 2px solid rgba(77, 184, 255, 0.35);
  border-radius: 0 6px 6px 0;
  font-size: 0.74rem;
  color: rgba(180, 210, 255, 0.55);
  line-height: 1.55;
}

/* Coffee link */
.coffee-link {
  display: flex; align-items: center; gap: 0.6rem;
  text-decoration: none;
  color: rgba(255, 210, 120, 0.8);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 189, 89, 0.2);
  transition: all 0.2s;
}
.coffee-link:hover {
  color: #ffbd59;
  border-color: rgba(255, 189, 89, 0.5);
  background: rgba(255, 189, 89, 0.06);
}

/* ─── STATUS BAR ────────────────────────────────────────────────────────────── */
#status-bar {
  position: absolute;
  bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 1rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: rgba(180, 210, 255, 0.45);
  z-index: 10;
  letter-spacing: 0.05em;
  pointer-events: none;
}
.dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 2s infinite;
  flex-shrink: 0;
}
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.3; } }

/* ─── BOTTOM-LEFT CONTROLS ──────────────────────────────────────────────────── */
#bottom-left {
  position: absolute;
  bottom: 1.5rem; left: 1.5rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  z-index: 10;
}

.ui-btn {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  padding: 0.4rem 0.9rem;
  display: flex; align-items: center; gap: 0.5rem;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  transition: all 0.2s;
  user-select: none;
  text-decoration: none;
  white-space: nowrap;
}
.ui-btn:hover { border-color: var(--accent); color: var(--text-primary); }

/* ─── INFO PANEL ────────────────────────────────────────────────────────────── */
#info-panel {
  position: absolute;
  background: rgba(2, 8, 20, 0.92);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(77, 184, 255, 0.3);
  border-radius: var(--radius-card);
  padding: 1rem 1.25rem;
  min-width: 200px;
  max-width: 280px;
  z-index: 20;
  pointer-events: none;
  font-family: var(--font-sans);
  /* Smooth fade/scale in-out instead of a hard show. */
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px) scale(0.98);
  transform-origin: top left;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
}
#info-panel.visible { opacity: 1; visibility: visible; transform: none; }
#info-panel h3 {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
  font-weight: 700;
  display: flex; align-items: center; gap: 0.5rem;
}
.panel-name { flex: 1; min-width: 0; word-break: break-word; }
.panel-actions { display: inline-flex; gap: 0.3rem; flex-shrink: 0; }
.panel-icon {
  pointer-events: auto;            /* re-enabled on the click-through panel */
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  border: none; padding: 0;
  background: rgba(77, 184, 255, 0.08);
  border-radius: 6px;
  color: var(--accent);
  cursor: pointer; text-decoration: none;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.panel-icon:hover { background: rgba(77, 184, 255, 0.2); color: var(--accent-hover); }
.panel-icon:active { transform: scale(0.9); }
.panel-icon.copied { color: #6ee7a0; background: rgba(110, 231, 160, 0.16); }
.info-row {
  display: flex; justify-content: space-between;
  font-size: 0.78rem;
  padding: 0.18rem 0;
  border-bottom: 1px solid rgba(77, 184, 255, 0.08);
  gap: 1rem;
}
.info-row:last-child { border-bottom: none; }
.info-label { color: rgba(180, 210, 255, 0.45); }
.info-val   { color: var(--text-primary); font-weight: 500; text-align: right; }

/* Telescope-coords reveal (hover on desktop / tap on touch). The info panel is
   click-through (pointer-events:none); this control re-enables itself so it can
   be hovered/tapped without blocking clicks on objects behind the rest of the panel. */
.scope-coords {
  position: relative;
  margin-top: 0.6rem;
  display: inline-flex; align-items: center; gap: 0.35rem;
  background: none; border: none; padding: 0.1rem 0;
  font-family: var(--font-mono); font-size: 0.66rem; letter-spacing: 0.04em;
  color: var(--accent);
  cursor: pointer;
  pointer-events: auto;
}
.scope-coords:hover { color: var(--accent-hover); }
.scope-tip {
  position: absolute;
  bottom: calc(100% + 8px); left: 0;
  min-width: 175px;
  display: flex; flex-direction: column; gap: 0.12rem;
  background: rgba(2, 10, 24, 0.98);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  opacity: 0; visibility: hidden; transform: translateY(4px);
  transition: opacity 0.14s ease, transform 0.14s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  z-index: 5;
}
.scope-coords:hover .scope-tip,
.scope-coords:focus-visible .scope-tip,
.scope-coords.show .scope-tip { opacity: 1; visibility: visible; transform: translateY(0); }
.scope-row { display: flex; justify-content: space-between; gap: 1.25rem; font-size: 0.74rem; }
.scope-row span:first-child  { color: rgba(180, 210, 255, 0.5); }
.scope-row span:last-child   { color: var(--text-primary); font-weight: 500; }
.scope-epoch { margin-top: 0.3rem; font-size: 0.56rem; letter-spacing: 0.06em; color: rgba(180, 210, 255, 0.4); text-align: right; }

/* ─── CHANGE LOCATION MODAL ─────────────────────────────────────────────────── */
#loc-modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(2, 4, 8, 0.82);
  backdrop-filter: blur(8px);
  z-index: 50;
  align-items: center; justify-content: center;
}
#loc-modal-backdrop.open { display: flex; }

#loc-modal {
  background: #050f23;
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 2rem;
  width: min(460px, 90vw);
  display: flex; flex-direction: column; gap: 1rem;
}
#loc-modal h2 {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.05em;
}
#loc-modal p {
  font-size: 0.82rem;
  color: rgba(180, 210, 255, 0.5);
  line-height: 1.5;
}
.modal-input-row {
  display: flex;
  border-radius: 6px; overflow: hidden;
  border: 1px solid rgba(77, 184, 255, 0.3);
  background: rgba(5, 15, 35, 0.8);
}
#modal-addr-input {
  flex: 1; background: transparent; border: none;
  padding: 0.75rem 1rem;
  font-family: var(--font-sans); font-size: 16px;   /* 16px avoids iOS focus-zoom */
  color: var(--text-primary); outline: none;
}
#modal-addr-input::placeholder { color: rgba(180, 210, 255, 0.3); }
#modal-go-btn {
  background: var(--accent); border: none;
  padding: 0 1.1rem;
  color: #020408;
  font-family: var(--font-mono);
  font-size: 0.78rem; font-weight: 700;
  cursor: pointer; transition: background 0.2s;
}
#modal-go-btn:hover { background: var(--accent-hover); }

.modal-actions {
  display: flex; justify-content: space-between; align-items: center;
}
#modal-loc-btn {
  background: transparent;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  padding: 0.35rem 0.9rem;
  color: var(--text-muted);
  font-family: var(--font-sans); font-size: 0.8rem;
  cursor: pointer; transition: all 0.2s;
  display: flex; align-items: center; gap: 0.4rem;
}
#modal-loc-btn:hover { border-color: var(--accent); color: var(--accent); }
#modal-cancel-btn {
  background: transparent; border: none;
  color: rgba(180, 210, 255, 0.35);
  font-family: var(--font-mono); font-size: 0.72rem;
  letter-spacing: 0.05em; cursor: pointer;
  transition: color 0.2s;
}
#modal-cancel-btn:hover { color: var(--text-muted); }
#modal-error { color: #ff7070; font-size: 0.8rem; min-height: 1rem; }

/* ─── SEARCH ────────────────────────────────────────────────────────────────── */
#search-btn {
  position: absolute;
  top: 1.5rem; left: 1.5rem;
  width: 38px; height: 38px;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  z-index: 30;
  transition: border-color 0.2s, color 0.2s;
}
#search-btn:hover { border-color: var(--accent); color: var(--accent); }

#fit-btn {
  position: absolute;
  bottom: 1.5rem; right: 1.5rem;
  width: 38px; height: 38px;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  z-index: 30;
  transition: border-color 0.2s, color 0.2s;
}
#fit-btn:hover, #fit-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

#search-modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(2, 4, 8, 0.82);
  backdrop-filter: blur(8px);
  z-index: 60;
  align-items: flex-start; justify-content: center;
}
#search-modal-backdrop.open { display: flex; }
#search-modal {
  margin-top: 8vh;
  background: #050f23;
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  padding: 1.5rem;
  width: min(520px, 92vw);
  max-height: 84vh;
  overflow-y: auto;                /* whole modal scrolls if content is tall */
  display: flex; flex-direction: column; gap: 1rem;
}
.search-head { display: flex; align-items: center; justify-content: space-between; }
.search-head h2 { font-family: var(--font-mono); font-size: 1rem; color: var(--accent); letter-spacing: 0.05em; }
#search-close { background: none; border: none; color: var(--text-muted); font-size: 1.05rem; cursor: pointer; line-height: 1; }
#search-close:hover { color: var(--text-primary); }
#search-input {
  width: 100%;
  background: rgba(5, 15, 35, 0.8);
  border: 1px solid rgba(77, 184, 255, 0.3);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  color: var(--text-primary);
  font-family: var(--font-sans); font-size: 16px;   /* 16px avoids iOS focus-zoom */
  outline: none;
}
#search-input:focus { border-color: var(--accent); }
#search-input::placeholder { color: var(--text-faint); }
#search-results { display: flex; flex-direction: column; gap: 0.25rem; overflow-y: auto; max-height: 34vh; }
.search-hint, .search-loading { color: var(--text-muted); font-size: 0.8rem; text-align: center; padding: 0.5rem; }
.search-section {
  font-family: var(--font-mono); font-size: 0.6rem; letter-spacing: 0.12em;
  text-transform: uppercase; color: rgba(77, 184, 255, 0.45); margin-top: 0.5rem;
}
.search-row {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.1rem;
  background: rgba(77, 184, 255, 0.04);
  border: 1px solid transparent; border-radius: 8px;
  padding: 0.5rem 0.7rem; cursor: pointer; text-align: left; width: 100%;
  transition: background 0.15s, border-color 0.15s;
}
.search-row:hover { background: rgba(77, 184, 255, 0.12); border-color: rgba(77, 184, 255, 0.3); }
.search-row-name { color: var(--text-primary); font-size: 0.85rem; }
.search-row-sub  { color: var(--text-muted); font-size: 0.68rem; font-family: var(--font-mono); }
#search-detail:empty { display: none; }
.search-card { background: rgba(2, 8, 20, 0.6); border: 1px solid var(--glass-border); border-radius: 10px; padding: 1rem; }
.search-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.6rem; }
.search-card-head h3 { font-family: var(--font-mono); color: var(--accent); font-size: 0.95rem; }
.search-class { font-size: 0.68rem; color: var(--text-muted); flex-shrink: 0; }
.search-drow {
  display: flex; justify-content: space-between; gap: 1rem;
  font-size: 0.8rem; padding: 0.22rem 0;
  border-bottom: 1px solid rgba(77, 184, 255, 0.08);
}
.search-drow:last-of-type { border-bottom: none; }
.search-drow span:first-child { color: rgba(180, 210, 255, 0.5); }
.search-drow span:last-child  { color: var(--text-primary); text-align: right; }
.search-link { display: inline-block; margin-top: 0.7rem; color: var(--accent); font-family: var(--font-mono); font-size: 0.75rem; text-decoration: none; }
.search-link:hover { color: var(--accent-hover); text-decoration: underline; }
.search-target {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  width: 100%; margin-top: 0.85rem;
  background: var(--accent); border: none; border-radius: 8px;
  padding: 0.6rem; cursor: pointer;
  color: #021018; font-family: var(--font-mono); font-size: 0.78rem; font-weight: 700;
  letter-spacing: 0.03em;
  transition: background 0.18s, transform 0.1s;
}
.search-target:hover { background: var(--accent-hover); }
.search-target:active { transform: scale(0.98); }

/* ─── DAY MODE ──────────────────────────────────────────────────────────────── */
body.day-mode { background: var(--bg-day); color: #001a33; }
body.day-mode #topbar {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.3);
  color: rgba(0,30,80,0.7);
}
body.day-mode #topbar #loc-display { color: rgba(0,20,60,0.95); }
body.day-mode #menu-btn,
body.day-mode #search-btn,
body.day-mode #fit-btn {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.3);
  color: rgba(0,30,80,0.8);
}
body.day-mode #menu-btn span { background: rgba(0,30,80,0.7); }
body.day-mode #status-bar { color: rgba(0,30,80,0.45); }
body.day-mode .dot { background: #fff; }
body.day-mode .ui-btn {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.3);
  color: rgba(0,30,80,0.8);
}
body.day-mode .ui-btn:hover { border-color: #003060; color: #003060; }
body.day-mode #info-panel { background: rgba(0,20,60,0.9); border-color: rgba(255,255,255,0.3); }
body.day-mode #info-panel h3 { color: #fff; }
body.day-mode .info-val { color: var(--text-primary); }

/* ─── RESPONSIVE / MOBILE ────────────────────────────────────────────────────── */
/* Keep clear of the iPhone notch + home indicator on every edge-anchored control. */
#topbar     { top: calc(1.5rem + env(safe-area-inset-top, 0px)); }
#menu-btn   { top: calc(1.5rem + env(safe-area-inset-top, 0px)); right: calc(1.5rem + env(safe-area-inset-right, 0px)); }
#search-btn { top: calc(1.5rem + env(safe-area-inset-top, 0px)); left:  calc(1.5rem + env(safe-area-inset-left, 0px)); }
#menu-panel { top: calc(1.5rem + env(safe-area-inset-top, 0px)); }
#bottom-left{ bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px)); left: calc(1.5rem + env(safe-area-inset-left, 0px)); }
#fit-btn    { bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px)); right: calc(1.5rem + env(safe-area-inset-right, 0px)); }
#status-bar { bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px)); }

/* Phones / small tablets (portrait and landscape). The old fixed layout let the
   centred topbar slide under the menu button and the bottom controls collide —
   here each control is re-anchored to its own corner and the menu becomes a
   scrollable sheet so nothing overlaps on an iPhone 13 or similar. */
@media (max-width: 768px) {
  /* Topbar spans from the left edge to just short of the menu button, never under
     it; content wraps and shrinks instead of forcing a fixed-width pill. */
  #topbar {
    left: calc(3.7rem + env(safe-area-inset-left, 0px));   /* clear the search button */
    right: calc(3.7rem + env(safe-area-inset-right, 0px)); /* clear the menu button */
    top: calc(0.6rem + env(safe-area-inset-top, 0px));
    transform: none;
    justify-content: center;
    flex-wrap: wrap;
    white-space: normal;
    gap: 0.2rem 0.55rem;
    font-size: 0.6rem;
    padding: 0.4rem 0.7rem;
  }

  #menu-btn   { top: calc(0.6rem + env(safe-area-inset-top, 0px)); right: calc(0.6rem + env(safe-area-inset-right, 0px)); }
  #search-btn { top: calc(0.6rem + env(safe-area-inset-top, 0px)); left:  calc(0.6rem + env(safe-area-inset-left, 0px)); }

  /* Bump the glass icon buttons from 38px to the 44px minimum comfortable touch
     target (WCAG 2.5.5 / Apple HIG). The hamburger→X animation keys off the bar
     spacing, not the button size, so it still lines up. */
  #menu-btn, #search-btn, #fit-btn { width: 44px; height: 44px; }

  /* Full-width scrollable sheet so the panel never runs off a short screen. */
  #menu-panel {
    top: calc(3.4rem + env(safe-area-inset-top, 0px));
    left: calc(0.6rem + env(safe-area-inset-left, 0px));
    right: calc(0.6rem + env(safe-area-inset-right, 0px));
    width: auto;
    max-height: calc(100dvh - 4.2rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }

  /* Bottom controls in opposite corners, compact. The status bar is non-interactive
     (pointer-events:none) and right-aligned with a width cap so it can't sit on top
     of the Change-location button. */
  #bottom-left { bottom: calc(0.6rem + env(safe-area-inset-bottom, 0px)); left: calc(0.6rem + env(safe-area-inset-left, 0px)); }
  #fit-btn     { bottom: calc(0.6rem + env(safe-area-inset-bottom, 0px)); right: calc(0.6rem + env(safe-area-inset-right, 0px)); }
  .ui-btn { font-size: 0.66rem; padding: 0.45rem 0.8rem; }

  /* Status bar lifts to a centered row ABOVE the bottom-corner buttons, so it
     can't overlap Change-location (left) or the fit toggle (right). */
  #status-bar {
    left: 50%; right: auto;
    bottom: calc(3.4rem + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    justify-content: center;
    text-align: center;
    max-width: 92vw;
    font-size: 0.58rem;
    gap: 0.5rem;
  }

  #info-panel { max-width: min(280px, calc(100vw - 1.2rem)); }
  #crosshair  { width: 120px; height: 120px; }

  /* Modals: nearly full-width, less inset, snug to the top. */
  #search-modal {
    margin-top: calc(0.8rem + env(safe-area-inset-top, 0px));
    width: calc(100vw - 1.2rem);
    max-height: calc(100dvh - 1.6rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    padding: 1.1rem;
  }
  #search-results { max-height: 28vh; }
  #loc-modal { padding: 1.5rem; }
}

/* Short landscape (e.g. phone on its side): make sure menus/modals can scroll. */
@media (max-height: 480px) {
  #menu-panel    { max-height: calc(100dvh - 4.2rem); }
  #search-modal  { margin-top: 2vh; max-height: 94vh; }
  #search-results { max-height: 30vh; }
}
