:root {
  --bg-base: #0A0E14;
  --bg-panel: #131922;
  --border: #232B38;
  --accent: #FFB454;
  --text-primary: #E8EAED;
  --text-muted: #626C7A;
  --font: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }

html { height: 100%; overflow: hidden; overscroll-behavior: none; }

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg-base);
  font-family: var(--font);
  color: var(--text-primary);
}

#globeViz { width: 100vw; height: 100vh; height: 100dvh; touch-action: none; }

#topBar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-base);
  z-index: 20;
}
#topBar .brand { font-weight: 600; font-size: 13px; letter-spacing: 0.02em; }
#topBar .clock { font-size: 13px; color: var(--accent); }

#passesToggle {
  display: none;
  height: 30px; padding: 0 12px;
  border: 1px solid var(--border); background: transparent; color: var(--text-primary);
  font-family: var(--font); font-weight: 500; font-size: 12px; cursor: pointer;
}
#passesToggle[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
#passesToggle:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }

#search {
  position: absolute;
  left: 50%; top: 7px;
  transform: translateX(-50%);
  width: 320px;
}
#searchInput {
  width: 100%; height: 30px; padding: 0 10px;
  border: 1px solid var(--border); background: var(--bg-panel);
  color: var(--text-primary); font-family: var(--font); font-size: 12px;
}
#searchInput::placeholder { color: var(--text-muted); }
#searchInput:focus-visible { outline: 1px solid var(--accent); border-color: var(--accent); }
#searchResults {
  position: absolute; top: 34px; left: 0; right: 0;
  max-height: 241px; overflow-y: auto;
  background: var(--bg-panel); border: 1px solid var(--border);
}
#searchResults[hidden] { display: none; }
.search-option {
  display: flex; justify-content: space-between; gap: 12px;
  height: 30px; padding: 0 10px; align-items: center;
  font-size: 12px; cursor: pointer;
}
.search-option + .search-option { border-top: 1px solid var(--border); }
.search-option .norad { color: var(--text-muted); font-size: 11px; }
.search-option:hover { background: rgba(255,255,255,0.03); }
.search-option[aria-selected="true"] { background: var(--border); color: var(--accent); }
.search-empty { height: 30px; padding: 0 10px; display: flex; align-items: center; font-size: 11px; color: var(--text-muted); }

.panel {
  position: fixed;
  width: 260px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 16px;
  z-index: 10;
}

#controls {
  top: 60px; left: 16px;
  max-height: calc(100dvh - 60px - 48px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
#controls h3 { margin: 0 0 14px 0; font-size: 11px; font-weight: 600; color: var(--text-muted); }
#controls label { display: block; font-size: 11px; color: var(--text-muted); margin-bottom: 12px; }
#controls input {
  display: block; width: 100%; margin-top: 5px; padding: 7px 8px;
  border: 1px solid var(--border); background: var(--bg-base);
  color: var(--text-primary); font-family: var(--font); font-size: 13px;
}
#controls input:focus-visible { outline: 1px solid var(--accent); border-color: var(--accent); }
#controls button {
  width: 100%; margin-top: 2px; padding: 9px;
  border: 1px solid var(--accent); background: transparent; color: var(--accent);
  font-family: var(--font); font-weight: 600; font-size: 12px;
  cursor: pointer; transition: background 0.1s ease, color 0.1s ease;
}
#controls button:hover { background: var(--accent); color: var(--bg-base); }
#controls button:focus-visible { outline: 1px solid var(--text-primary); outline-offset: 2px; }
#controls button.secondary { border-color: var(--border); color: var(--text-primary); font-weight: 500; margin-bottom: 8px; }
#controls button.secondary:hover { border-color: var(--text-muted); background: transparent; color: var(--text-primary); }
#locationStatus { font-size: 11px; color: var(--text-muted); line-height: 1.4; margin-bottom: 10px; }
#locationStatus:empty { display: none; }

#passResults { margin-top: 14px; max-height: 280px; overflow-y: auto; }
.pass { padding: 8px 0; border-top: 1px solid var(--border); cursor: pointer; }
.pass:hover { background: rgba(255,255,255,0.03); }
.pass strong { font-size: 12px; font-weight: 600; }
.pass .meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

#satDetails {
  top: 60px; right: 16px;
  transform: translateX(120%);
  transition: transform 0.2s ease;
}
#satDetails.open { transform: translateX(0); }
#satDetails::before, #satDetails::after {
  content: ''; position: absolute; width: 14px; height: 14px;
  border: 2px solid var(--accent); pointer-events: none;
}
#satDetails::before { top: -2px; left: -2px; border-right: none; border-bottom: none; }
#satDetails::after { bottom: -2px; right: -2px; border-left: none; border-top: none; }
#closeDetails {
  position: absolute; top: 10px; right: 12px; background: none; border: none;
  color: var(--text-muted); font-family: var(--font); font-size: 15px; cursor: pointer;
}
#closeDetails:hover { color: var(--text-primary); }
#satDetails h3 { margin: 2px 0 8px 0; font-size: 15px; font-weight: 700; }
#satDetails p { font-size: 11px; color: var(--text-muted); line-height: 1.5; margin: 0 0 14px 0; }
#satDetails .stat { display: flex; justify-content: space-between; font-size: 12px; padding: 5px 0; border-top: 1px solid var(--border); }
#satDetails .stat .label { color: var(--text-muted); }

#statsBar {
  position: fixed; bottom: 0; left: 0; right: 0; height: 32px;
  display: flex; align-items: center; justify-content: center; gap: 22px;
  background: var(--bg-base); border-top: 1px solid var(--border); z-index: 10;
}
#statsBar .metric { font-size: 10px; color: var(--text-muted); display: flex; gap: 6px; }
#statsBar .metric b { font-weight: 600; color: var(--accent); }
/* --- Mobile: two-row top bar, panels become bottom sheets --- */

@media (max-width: 768px) {
  #topBar {
    height: auto;
    display: grid;
    grid-template-columns: 1fr auto auto;
    grid-template-areas: "brand passes clock" "search search search";
    align-items: center;
    column-gap: 12px;
    padding: max(6px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  }
  #topBar .brand { grid-area: brand; line-height: 44px; }
  #topBar .clock { grid-area: clock; }
  #passesToggle { display: block; grid-area: passes; }

  #search {
    grid-area: search;
    position: relative;
    left: auto; top: auto; transform: none;
    width: auto;
  }
  #searchInput { height: 36px; font-size: 16px; }
  #searchResults { top: calc(100% + 4px); max-height: min(241px, 45dvh); }

  /* Sheets sit above the stats bar so it stays visible. */
  .panel {
    top: auto; bottom: calc(32px + env(safe-area-inset-bottom)); left: 0; right: 0;
    width: auto;
    max-height: 50dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    border-left: none; border-right: none;
    z-index: 15;
    transform: translateY(100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }
  .panel.open {
    transform: translateY(0);
    visibility: visible;
    transition: transform 0.2s ease, visibility 0s;
  }
  #controls { top: auto; left: 0; max-height: 50dvh; }
  #passResults { max-height: none; overflow-y: visible; }
  #controls input { font-size: 16px; }

  #satDetails {
    top: auto; right: 0;
    transform: translateY(100%);
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }
  #satDetails.open { transform: translateY(0); transition: transform 0.2s ease, visibility 0s; }
  #satDetails::before { top: 0; left: 0; }
  #satDetails::after { display: none; }
  /* Sticky so it stays reachable while the sheet scrolls. */
  #closeDetails {
    position: sticky; top: 0; float: right;
    width: 44px; height: 44px; margin: -12px -12px 0 0;
  }

  #statsBar {
    height: calc(32px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    white-space: nowrap;
  }
  #statsBar .metric:nth-child(n+3) { display: none; }
}

/* --- Touch: 44px minimum tap targets --- */

@media (pointer: coarse) {
  #controls input, #controls button, #searchInput, #passesToggle { min-height: 44px; }
  .search-option, .search-empty { height: 44px; }
  #searchResults { max-height: min(353px, 45dvh); }
  .pass { min-height: 44px; }
  #closeDetails { min-width: 44px; min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  #satDetails, #satDetails.open, .panel, .panel.open, #controls button { transition: none; }
}
