:root {
  --bg: #000;
  --panel: rgba(14, 18, 30, 0.88);
  --line: rgba(255, 255, 255, 0.12);
  --text: #e6e9f2;
  --muted: #8a93a8;
  --accent: #7cc4ff;
  --warn: #ffb36b;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}

canvas#sky {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  touch-action: none;
}

.icon-btn {
  position: fixed;
  top: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  display: grid;
  place-items: center;
  padding: 0;
  line-height: 0;
  cursor: pointer;
  z-index: 20;
}
.icon-btn.small {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
}

.panel {
  position: fixed;
  top: 12px;
  right: 60px;
  width: 360px;
  max-width: calc(100vw - 76px);
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  z-index: 10;
}
.panel { transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s; }
.panel.closed { opacity: 0; transform: translateX(8px); visibility: hidden; pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s 0.2s; }
.panel h1 { margin: 0 0 12px; font-size: 16px; letter-spacing: 0.04em; }
.panel section { padding: 10px 0; border-top: 1px solid var(--line); }
.panel section > label:first-child {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.row { display: flex; gap: 6px; align-items: center; }
.row + .row, .row + button, form + button { margin-top: 6px; }

input[type="text"], select {
  flex: 1;
  width: 100%;
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
}

button {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--accent);
  color: #06121f;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button.secondary {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-weight: 500;
}

.check { display: flex; gap: 8px; align-items: center; margin: 4px 0; cursor: pointer; }
.inline-label { color: var(--muted); min-width: 76px; }

.seg { display: flex; gap: 4px; margin-bottom: 6px; }
.seg button {
  flex: 1;
  padding: 6px 0;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-weight: 500;
}
.seg button.active { background: var(--accent); color: #06121f; font-weight: 600; }

.status { margin: 6px 0 0; color: var(--muted); font-size: 12px; min-height: 1em; }
.status.error { color: var(--warn); }
.hint { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
kbd, code {
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 11px;
  background: rgba(255, 255, 255, 0.06);
}

.info {
  position: fixed;
  left: 12px;
  bottom: 12px;
  width: 340px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  z-index: 10;
}
.info { transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s; }
.info.closed { opacity: 0; transform: translateY(8px); visibility: hidden; pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s 0.2s; }
.info h2 { display: flex; align-items: center; gap: 8px; margin: 0 64px 10px 0; font-size: 15px; }
.spinner {
  flex: none; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; transition: opacity 0.25s ease;
}
.spinner.done { opacity: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.fresh { animation: fresh-in 0.35s ease-out both; }
@keyframes fresh-in { from { opacity: 0; transform: translateY(-3px); } }
.group-list { display: grid; gap: 2px; }
.check.group { margin: 2px 0; }
.check.group .count { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  .spinner { animation: none; }
}
.info .sep { grid-column: 1 / -1; height: 1px; margin: 4px 0; background: var(--line); }
.info dd.help { color: var(--muted); font-size: 12px; font-style: italic; }
.info-extract { margin: 10px 0 0; padding-top: 8px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.info-extract[hidden] { display: none; }
.icon-btn.help-btn { right: 42px; }
.icon-btn.help-btn[aria-pressed="true"] { background: var(--accent); color: #06121f; border-color: var(--accent); }
.info dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 3px 12px; margin: 0; font-size: 13px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

body.kiosk .icon-btn,
body.kiosk .panel,
body.kiosk .info { display: none !important; }

a { color: var(--accent); }

/* Settings panel layout */
.field-grid { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 6px 10px; align-items: center; margin: 8px 0 4px; }
.field-grid .inline-label { min-width: 0; }
.panel section > label:first-child { display: flex; justify-content: space-between; align-items: baseline; }
.label-value { color: var(--text); font-size: 13px; text-transform: none; letter-spacing: 0; font-variant-numeric: tabular-nums; }

/* Detent sliders: tick labels sit under each stop */
.slider { flex: 1; min-width: 0; margin: 2px 0 8px; transition: opacity 0.2s ease; }
.slider.disabled { opacity: 0.35; pointer-events: none; }
.slider input[type="range"] { width: 100%; margin: 4px 0 2px; accent-color: var(--accent); cursor: pointer; }
.ticks { display: flex; justify-content: space-between; padding: 0 8px; }
.ticks span { width: 0; display: flex; justify-content: center; white-space: nowrap; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.slider-row { display: flex; gap: 14px; align-items: flex-start; }
.slider-row > .check { margin-top: 5px; flex: none; }
.slider-field { align-items: start; }
.slider-field .inline-label { padding-top: 5px; }

/* Time-offset tooltip under the HUD clock glyph */
.hud-tip {
  position: fixed; z-index: 30; transform: translate(-50%, 4px);
  padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 12px; white-space: nowrap;
  font-variant-numeric: tabular-nums; pointer-events: none;
  opacity: 0; transition: opacity 0.15s ease, transform 0.15s ease;
}
.hud-tip.show { opacity: 1; transform: translate(-50%, 0); }
body.kiosk .hud-tip { display: none; }

/* Satellite category tiles */
.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cat {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: rgba(255, 255, 255, 0.06); color: var(--text);
  font: inherit; font-weight: 500; text-align: left; cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.cat:hover { border-color: rgba(255, 255, 255, 0.25); }
.cat svg { flex: none; }
.cat-name { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.cat .count { font-size: 11px; font-weight: 400; opacity: 0.7; font-variant-numeric: tabular-nums; min-height: 1.2em; }
.cat-all .cat-text { align-items: center; }
.cat[aria-pressed="true"] { background: var(--accent); color: #06121f; border-color: var(--accent); }
.cat-all { width: 100%; justify-content: center; }

/* Recommended / Custom */
.mode-seg { margin-bottom: 8px; }
.cat-grid { transition: opacity 0.2s ease; }

/* End tick labels grow inward so they never overflow the slider */
.ticks span:first-child { justify-content: flex-start; }
.ticks span:last-child { justify-content: flex-end; }

/* Animated collapse: grid rows animate between 1fr and 0fr, so height needs no measuring */
.collapse {
  display: grid; grid-template-rows: 1fr; opacity: 1;
  transition: grid-template-rows 0.28s ease, opacity 0.22s ease;
}
.collapse.closed { grid-template-rows: 0fr; opacity: 0; }
.collapse-inner { min-height: 0; overflow: hidden; display: grid; gap: 6px; align-content: start; }
#custom-wrap > .collapse-inner, #rec-wrap > .collapse-inner { padding-bottom: 2px; }
#more-wrap > .collapse-inner { gap: 6px; }

.more-toggle {
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 6px 2px; border: 0; background: none; color: var(--muted);
  font: inherit; font-weight: 500; cursor: pointer;
}
.more-toggle:hover { color: var(--text); }
.more-toggle svg { transition: transform 0.25s ease; }
.more-toggle[aria-expanded="true"] svg { transform: rotate(90deg); }
.more-note { margin: 0; color: var(--muted); font-size: 12px; }

.geo-check { margin: 0 0 8px; }

/* Space-Track button (top-left) and its panel */
.icon-btn.st-btn { left: 12px; right: auto; }
.st-dot {
  position: absolute; top: 2px; right: 2px; width: 9px; height: 9px; border-radius: 50%;
  border: 2px solid var(--bg); background: transparent; transition: background 0.2s ease;
}
.st-dot.ok { background: #4ade80; }
.st-dot.syncing { background: #ffb36b; }
.st-dot.error { background: #ff6b6b; }
.panel.st-panel { left: 60px; right: auto; width: 320px; transform-origin: top left; }
.panel.st-panel.closed { transform: translateX(-8px); }
.st-form { display: grid; gap: 6px; margin-top: 10px; }
.st-form label { color: var(--muted); font-size: 12px; }
.st-form button { margin-top: 6px; }
.st-form[hidden], .st-signed[hidden] { display: none; }
.st-signed p { margin: 10px 0; }
body.kiosk .st-btn, body.kiosk .st-panel { display: none !important; }

/* Chooser for satellites stacked on the same spot */
.pick-menu {
  position: fixed; z-index: 25; display: grid; gap: 2px; min-width: 180px; max-width: 220px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; backdrop-filter: blur(8px);
  opacity: 0; transform: translateY(-4px); visibility: hidden; pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0s 0.15s;
}
.pick-menu.open { opacity: 1; transform: none; visibility: visible; pointer-events: auto; transition: opacity 0.15s ease, transform 0.15s ease; }
.pick-menu button {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px; border: 0; border-radius: 6px;
  background: transparent; color: var(--text); font: inherit; font-weight: 500; text-align: left; cursor: pointer;
}
.pick-menu button:hover { background: rgba(255, 255, 255, 0.08); }
.pick-dot { flex: none; width: 9px; height: 9px; border-radius: 50%; }
body.kiosk .pick-menu { display: none !important; }

/* Feature-flagged controls (e.g. Space-Track off on the hosted version) */
.icon-btn[hidden] { display: none; }

/* Planets / Constellations rows with a "Hide Names" option on the right */
.check-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.check.sub { color: var(--muted); font-size: 13px; transition: opacity 0.2s ease; }
.check.sub.disabled { opacity: 0.4; pointer-events: none; }

/* Time: rewind / play-pause / fast-forward */
.media { display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 6px; margin: 4px 0 8px; }
.media-btn {
  display: grid; place-items: center; height: 40px; padding: 0;
  border: 1px solid var(--line); border-radius: 10px; background: rgba(255, 255, 255, 0.06); color: var(--text);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.media-btn:hover { border-color: rgba(255, 255, 255, 0.25); }
.media-btn[aria-pressed="true"], .media-btn.play { background: var(--accent); color: #06121f; border-color: var(--accent); }
#now-wrap > .collapse-inner { padding-bottom: 2px; }

/* Satellite counter text box (under its "More") */
#count-wrap > .collapse-inner { padding-left: 26px; }
#count-more-wrap > .collapse-inner { gap: 6px; padding-bottom: 4px; }
#count-text { width: 100%; }

/* Corner buttons: settings top-left, search top-right, account bottom-left; card bottom-right */
#toggle-panel { left: 12px; right: auto; }
.icon-btn.st-btn { top: auto; bottom: 12px; left: 12px; right: auto; }
.panel:not(.st-panel):not(.search-panel) { left: 60px; right: auto; }
.panel:not(.st-panel):not(.search-panel).closed { transform: translateX(-8px); }
.panel.st-panel { top: auto; bottom: 12px; }
.info { left: auto; right: 12px; }

/* Search */
.panel.search-panel { left: auto; right: 60px; width: 320px; }
.search-results { display: grid; gap: 2px; margin-top: 8px; }
.search-results:empty { display: none; }
.search-results button {
  display: flex; justify-content: space-between; gap: 10px; width: 100%; padding: 7px 8px;
  border: 0; border-radius: 6px; background: transparent; color: var(--text); font: inherit; font-weight: 500; text-align: left; cursor: pointer;
}
.search-results button:hover, .search-results button:focus-visible { background: rgba(255, 255, 255, 0.08); outline: none; }
.search-results .sid { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 400; }
.follow-chip {
  position: fixed; top: 60px; right: 12px; z-index: 20; display: flex; align-items: center; gap: 8px;
  padding: 6px 6px 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel);
  backdrop-filter: blur(8px); font-size: 13px; color: var(--muted);
}
.follow-chip strong { color: var(--text); font-weight: 600; }
.follow-chip[hidden] { display: none; }
.follow-chip button {
  display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); color: var(--text); font-size: 15px; line-height: 1;
}
body.kiosk .search-btn, body.kiosk .search-panel, body.kiosk .follow-chip { display: none !important; }

/* Custom dropdowns (the native <select> stays hidden underneath as the source of truth) */
.dd { position: relative; min-width: 0; }
.dd-native { display: none; }
.dd-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%;
  padding: 7px 10px 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: rgba(255, 255, 255, 0.06); color: var(--text); font: inherit; font-weight: 400; text-align: left; cursor: pointer;
}
.dd-btn:hover { border-color: rgba(255, 255, 255, 0.25); }
.dd-btn .dd-label { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dd-btn svg { flex: none; margin-right: 2px; opacity: 0.7; transition: transform 0.2s ease; }
.dd-btn[aria-expanded="true"] svg { transform: rotate(180deg); }
.dd-menu {
  position: fixed; z-index: 40; display: grid; gap: 2px; padding: 5px; max-height: 50vh; overflow-y: auto;
  background: #1a2032; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  opacity: 0; transform: translateY(-4px); visibility: hidden; pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0s 0.15s;
}
.dd-menu.open { opacity: 1; transform: none; visibility: visible; pointer-events: auto; transition: opacity 0.15s ease, transform 0.15s ease; }
.dd-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px 7px 8px; border: 0; border-radius: 6px;
  background: transparent; color: var(--text); font: inherit; font-weight: 400; text-align: left; cursor: pointer; white-space: nowrap;
}
.dd-item:hover, .dd-item:focus-visible { background: rgba(255, 255, 255, 0.08); outline: none; }
.dd-item .tick { width: 14px; color: var(--accent); visibility: hidden; }
.dd-item[aria-selected="true"] .tick { visibility: visible; }

/* No title: the first section needs no divider above it */
#panel > section:first-of-type { border-top: 0; padding-top: 0; }

/* Account button under the settings button; its panel opens beside it */
.icon-btn.st-btn { top: 60px; bottom: auto; }
.panel.st-panel { top: 60px; bottom: auto; }

/* Center coordinates, stacked, bottom-left */
.coords {
  position: fixed; left: 14px; bottom: 12px; z-index: 5; display: grid; gap: 1px;
  font-size: 12px; line-height: 1.35; color: var(--muted); font-variant-numeric: tabular-nums;
  pointer-events: none; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}
.coords span:empty { display: none; }

/* While following, the chip takes the search button's place */
.follow-chip { top: 12px; height: 40px; box-sizing: border-box; padding: 0 7px 0 14px; }
body.following .search-btn, body.following .search-panel { display: none; }

/* Follow button on info cards, left of "?" */
.icon-btn.follow-btn { right: 76px; }
.icon-btn.follow-btn[hidden] { display: none; }
.info.can-follow h2 { margin-right: 98px; }


/* iPhone: text boxes under 16px make Safari zoom in on focus */
@media (pointer: coarse) {
  input[type="text"], input[type="password"], #search-input, #count-text { font-size: 16px; }
}

/* Phone-width screens: panels fit between / below the corner buttons */
@media (max-width: 560px) {
  .panel, .panel.st-panel, .panel:not(.st-panel):not(.search-panel) { /* settings + account: below both left buttons */
    top: 108px; bottom: auto; left: 12px; right: 12px; width: auto; max-height: calc(100dvh - 120px);
  }
  .panel.search-panel { top: 6px; left: 60px; right: 60px; width: auto; padding: 8px; } /* between the gear and the search button */
  .panel.closed, .panel:not(.st-panel):not(.search-panel).closed, .panel.st-panel.closed { transform: translateY(-6px); }
  .info { left: 12px; right: 12px; width: auto; }
}
