html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #dde6ff;
}

#canvas-container { position: fixed; inset: 0; }
#canvas-container canvas { display: block; touch-action: none; }

#loading-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: #000; color: #dde6ff; font-size: 14px;
  transition: opacity 0.35s ease;
}
#loading-overlay.fade-out { opacity: 0; pointer-events: none; }
#loading-overlay p { margin: 0; text-align: center; padding: 0 16px; }
#loading-progress { width: min(320px, calc(100vw - 48px)); height: 12px; accent-color: #8fb4ff; }
#loading-detail { color: #aebbdc; font-size: 12px; }
.loading-spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid #3b4f8f; border-top-color: #dde6ff;
  animation: loading-spin 0.9s linear infinite;
}
@keyframes loading-spin { to { transform: rotate(360deg); } }

#toggle-controls, #close-controls, .touch-hints { display: none; }
.sidebar-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#focus-selected { margin-bottom: 8px; }
.view-from-controls {
  display: flex; flex-direction: column; gap: 6px; flex: none;
  margin-bottom: 8px; padding: 8px; border: 1px solid #2c3a66; border-radius: 4px; font-size: 12px;
}
.view-from-heading { display: flex; align-items: flex-start; gap: 8px; }
.view-from-heading h2, .view-from-heading h3 { flex: none; margin: 0; font-size: 14px; }
#view-from-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #aebbdc; }
#view-from-search, #view-toward-search {
  box-sizing: border-box; width: 100%; background: #0d1530; color: #dde6ff;
  border: 1px solid #3b4f8f; border-radius: 4px; padding: 5px 8px; font: inherit;
}
#view-from-results, #view-toward-results {
  list-style: none; margin: 0; padding: 0; max-height: 112px; overflow-y: auto;
}
.view-from-results:empty { display: none; }
.view-from-results button {
  display: block; width: 100%; overflow: hidden; text-align: left; text-overflow: ellipsis;
  white-space: nowrap; padding: 4px 6px; background: transparent; border-color: transparent;
}
.view-from-results button:hover { background: rgba(120, 150, 255, 0.15); }
#view-from-options { display: flex; flex-direction: column; gap: 6px; }
#view-from-options[hidden] { display: none; }
#view-from-panel[hidden] { display: none; }
#view-from-preset {
  max-width: 100%; background: #0d1530; color: #dde6ff; border: 1px solid #3b4f8f;
  border-radius: 4px; padding: 5px; font: inherit;
}
#view-from-options label { display: flex; justify-content: space-between; gap: 8px; }
#view-from-magnitude { width: 100%; }
#view-from-count, #view-from-options small { margin: 0; color: #aebbdc; font-size: 12px; line-height: 1.4; }

#top-menu {
  position: fixed; top: 0; left: 0; right: 0; height: 40px; z-index: 10;
  display: flex; align-items: center; gap: 16px; padding: 0 12px;
  background: #0a1020; border-bottom: 1px solid #3b4f8f; font-size: 13px;
}
#top-menu summary { cursor: pointer; padding: 6px; }
#top-menu details { position: relative; }
#top-menu .menu-commands { left: 0; top: calc(100% + 4px); }
.menu-commands kbd { float: right; margin-left: 16px; }
.menu-commands {
  position: absolute; top: 38px; left: 12px; min-width: 170px;
  display: flex; flex-direction: column; gap: 4px; padding: 6px;
  background: #0a1020; border: 1px solid #3b4f8f; border-radius: 4px;
}
.menu-commands button { text-align: left; }
.menu-commands a {
  display: block; padding: 5px 8px; border: 1px solid #3b4f8f; border-radius: 4px;
  background: #22305a; color: #dde6ff; text-decoration: none;
}
.menu-commands a:hover { background: #2e3f75; }
.menu-commands hr { width: 100%; margin: 2px 0; border: 0; border-top: 1px solid #3b4f8f; }
#advanced-filter-status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: 0.8; }
#filter-dialog {
  position: fixed; z-index: 11; box-sizing: border-box;
  color: #dde6ff; background: #0a1020; border: 1px solid #3b4f8f; border-radius: 8px;
  width: min(780px, calc(100vw - 48px)); max-height: calc(100dvh - 64px); padding: 18px; overflow: auto;
}
#filter-dialog h2 { margin: 0; }
.filter-heading { display: flex; align-items: center; gap: 12px; }
#filter-title { flex: 1; cursor: grab; touch-action: none; user-select: none; }
#filter-title.dragging { cursor: grabbing; }
#filter-apply-status { font-size: 12px; color: #aebbdc; }
#filter-apply-status:empty { display: none; }
#filter-help, #filter-dialog small, .filter-footer span { font-size: 12px; color: #aebbdc; }
#filter-dialog input:not([type="checkbox"]), #filter-dialog select {
  background: #0d1530; color: #dde6ff; border: 1px solid #3b4f8f; border-radius: 4px;
  padding: 5px; font: inherit; min-width: 0; max-width: 100%; box-sizing: border-box;
}
#filter-rules { margin-top: 12px; }
.filter-group { border: 1px solid #3b4f8f; border-radius: 6px; margin: 8px 0; min-width: 0; }
.filter-actions, .filter-footer { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.filter-condition {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin: 10px 0; padding: 10px; background: #151f3b; border-radius: 4px;
}
.filter-condition input[type="number"] { width: 110px; }
.filter-condition small { flex-basis: 100%; }
.filter-footer { margin-top: 12px; }
.filter-footer span { flex: 1; }
#filter-error { color: #ffb3b3; }
#filter-error:empty { display: none; }
#filter-text-section { margin-top: 8px; font-size: 12px; color: #aebbdc; }
#filter-text-section summary { cursor: pointer; color: #dde6ff; }
#filter-text {
  box-sizing: border-box; width: 100%; resize: vertical; font: 11px/1.4 ui-monospace, Consolas, monospace;
  background: #0d1530; color: #dde6ff; border: 1px solid #3b4f8f; border-radius: 4px; padding: 4px;
}
#filter-text-status:empty { display: none; }
button:disabled { opacity: 0.5; cursor: default; }
:focus-visible { outline: 2px solid #9bb0ff; outline-offset: 2px; }

body.about-page { height: auto; min-height: 100%; overflow: auto; background: #070c1a; }
.about-content {
  box-sizing: border-box; max-width: 960px; margin: auto; padding: 32px 24px 48px;
  line-height: 1.7; overflow-wrap: anywhere;
}
.about-content h1 { font-size: clamp(28px, 5vw, 42px); line-height: 1.2; margin-bottom: 16px; }
.about-content h2 { line-height: 1.3; color: #fff; }
.about-content a { color: #a7d8ff; }
.about-intro { font-size: 19px; color: #bac9ed; }
.about-nav { display: flex; flex-wrap: wrap; gap: 8px 20px; padding: 16px 0; }
.about-nav a { padding: 8px 0; }
.about-content section { border-top: 1px solid #2c3a66; padding: 16px 0; scroll-margin-top: 16px; }
.about-content li { margin-bottom: 10px; }
.about-content dt { font-weight: 600; color: #bac9ed; margin-top: 16px; }
.about-content dd { margin: 4px 0 16px; }
.about-content footer { border-top: 1px solid #2c3a66; padding-top: 20px; }
#about-dialog {
  position: fixed; inset: 0; margin: auto; z-index: 12; box-sizing: border-box;
  width: min(920px, calc(100vw - 32px)); height: min(680px, calc(100dvh - 64px));
  max-width: 100vw; max-height: 100dvh; padding: 0; overflow: hidden; resize: both;
  color: #dde6ff; background: #070c1a; border: 1px solid #3b4f8f; border-radius: 14px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.7);
}
#about-dialog[open] { display: flex; flex-direction: column; }
.about-heading { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid #2c3a66; }
#about-title { flex: 1; margin: 0; font-size: 18px; cursor: grab; touch-action: none; user-select: none; }
#about-title.dragging { cursor: grabbing; }
#about-dialog .about-content { width: 100%; min-height: 0; overflow-y: auto; padding-top: 12px; }

.panel {
  position: fixed;
  background: rgba(10, 16, 32, 0.82);
  border: 1px solid rgba(120, 150, 255, 0.25);
  border-radius: 8px;
  padding: 12px 14px;
  backdrop-filter: blur(4px);
  font-size: 13px;
}

.hidden { display: none; }

#sidebar {
  top: 52px; left: 12px; width: 220px; max-height: calc(100% - 216px);
  display: flex; flex-direction: column;
}
#sidebar h1 { font-size: 18px; margin: 0 0 2px; letter-spacing: 1px; }
#orientation-widget {
  bottom: 12px; left: 12px; width: 250px; height: 114px; box-sizing: border-box;
  display: flex; align-items: center; gap: 6px; padding: 4px 8px;
  pointer-events: none;
}
#orientation-canvas { width: 104px; height: 104px; flex: none; }
#orientation-widget h2 { font-size: 12px; margin: 0 0 6px; }
#orientation-legend { font-size: 10px; line-height: 1.4; }
#orientation-legend div + div { margin-top: 3px; }
#orientation-views { display: flex; gap: 4px; margin-top: 5px; pointer-events: auto; }
#orientation-views button { padding: 2px 5px; font-size: 11px; }
#star-count { opacity: 0.6; font-size: 12px; margin-bottom: 8px; }
.load-distance {
  display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; padding: 8px;
  border: 1px solid #2c3a66; border-radius: 4px; font-size: 12px;
}
.load-distance label { display: flex; align-items: center; gap: 6px; }
.load-distance select { flex: 1; min-width: 0; }
.load-distance small { color: #aebbdc; }
#catalogue-menu .load-distance {
  width: 260px; box-sizing: border-box; margin: 0;
  max-height: calc(100dvh - 72px); overflow-y: auto;
}
#catalogue-menu label { flex-direction: column; align-items: stretch; }
#catalogue-menu select {
  background: #0d1530; color: #dde6ff; border: 1px solid #3b4f8f;
  border-radius: 4px; padding: 5px 8px; font: inherit;
}
#star-panel {
  top: 52px; left: 268px; width: 250px; height: min(520px, calc(100% - 200px)); min-height: 180px;
  box-sizing: border-box; display: flex; flex-direction: column; z-index: 5;
}
#star-panel.hidden { display: none; }
.star-panel-heading { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
#star-panel-title { flex: 1; margin: 0; font-size: 15px; cursor: grab; touch-action: none; user-select: none; }
#star-panel-title.dragging { cursor: grabbing; }
#close-star-panel { padding: 0 6px; background: none; border: none; font-size: 18px; }
#star-search {
  background: #0d1530; color: #dde6ff; border: 1px solid #3b4f8f; border-radius: 4px;
  padding: 5px 8px; margin-bottom: 8px; font: inherit;
}
#star-list { list-style: none; margin: 0 0 10px; padding: 0; overflow-y: auto; flex: 1 1 auto; min-height: 60px; }
#list-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; opacity: 0.6; margin-bottom: 4px; }
#star-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px; border-radius: 4px; cursor: pointer;
}
#star-list li .swatch { flex: none; margin-right: 0; }
#star-list li .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#star-list li .dist { margin-left: auto; opacity: 0.55; font-size: 11px; font-variant-numeric: tabular-nums; }
#star-list li:hover { background: rgba(120, 150, 255, 0.15); }
#star-list li.selected { background: rgba(120, 150, 255, 0.3); }
#star-list li.neutron .swatch { border-radius: 2px; transform: rotate(45deg) scale(0.8); }
#star-list li.neutron .name { color: #cdb4ff; }
#star-list li.blackhole .swatch { background: #000 !important; border: 2px solid #ff9d3c; width: 8px; height: 8px; }
#star-list li.blackhole .name { color: #ffc27a; }
#star-list li.centre .name::after { content: " \2316"; opacity: 0.8; }

.toolbar { display: flex; flex-direction: column; gap: 6px; min-height: 0; overflow-y: auto; }
.toolbar .buttons { display: flex; gap: 6px; }
.toolbar .buttons button { flex: 1; }
.distance-row, .frame-row { display: flex; align-items: center; gap: 6px; }
#frame-select, #colour-mode {
  flex: 1; background: #0d1530; color: #dde6ff; border: 1px solid #3b4f8f; border-radius: 4px;
  padding: 3px 6px; font: inherit;
}
#dataset-status { font-size: 11px; overflow-wrap: anywhere; }
#dataset-status.error { color: #ffb3b3; }
#sovereignty-legend { display: flex; flex-direction: column; gap: 4px; padding-left: 4px; }
#sovereignty-legend[hidden] { display: none; }
#sovereignty-list { list-style: none; margin: 0; padding: 0; max-height: 160px; overflow-y: auto; }
#sovereignty-list li {
  display: flex; align-items: center; gap: 6px; padding: 2px 4px; border-radius: 4px; cursor: pointer;
}
#sovereignty-list li:hover { background: #22305a; }
#sovereignty-list li .swatch { flex: none; margin-right: 0; border-radius: 3px; }
#sovereignty-list li .name { flex: 1; }
#sovereignty-list li .count { font-size: 11px; opacity: 0.6; }
#sovereignty-list li.off { opacity: 0.4; }
#distance-filter {
  width: 70px; background: #0d1530; color: #dde6ff; border: 1px solid #3b4f8f; border-radius: 4px;
  padding: 3px 6px; font: inherit;
}
#distance-status { font-size: 11px; opacity: 0.6; }
#class-filter, #nebula-filter { display: flex; flex-wrap: wrap; gap: 3px; padding-left: 20px; }
.class-chip {
  padding: 1px 6px; min-width: 22px; font-size: 11px; border-radius: 10px;
  background: transparent; color: #8a93ad; border: 1px solid #3b4f8f;
}
.class-chip.on { color: #0b1020; background: var(--chip); border-color: var(--chip); font-weight: 600; }
.class-chip.all { color: #dde6ff; }
.class-chip:hover { filter: brightness(1.15); }
#distance-status:empty { display: none; }
#subspace-controls { min-width: 0; margin: 4px 0; border: 1px solid #3b4f8f; border-radius: 6px; }
#motion-dialog {
  position: fixed; left: 16px; top: 65px; margin: 0; z-index: 35;
  width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 90px);
  overflow: auto; box-sizing: border-box; padding: 16px;
  color: #e5ecff; background: #111a30; border: 1px solid #536ba7; border-radius: 10px;
}
#motion-dialog p { font-size: 12px; color: #bac8e6; line-height: 1.5; }
#motion-dialog label { display: block; margin: 10px 0; }
#motion-dialog fieldset { min-width: 0; border: 1px solid #536ba7; margin-top: 12px; }
#motion-years { width: 100%; }
#motion-offset { width: 100px; }
#motion-error { color: #ffb6b6 !important; }
#motion-banner {
  position: fixed; top: 54px; left: 50%; transform: translateX(-50%);
  max-width: calc(100vw - 24px); box-sizing: border-box; padding: 7px 12px;
  background: #243855; color: #f0d99b; border: 1px solid #b69a50; border-radius: 6px;
  z-index: 5; font-size: 12px; pointer-events: none; text-align: center;
}
#d-motion { max-width: 230px; white-space: normal; font-size: 12px; }
.swatch.motion-incomplete { background: transparent !important; border: 1px solid #87909e; box-sizing: border-box; }
#subspace-dialog {
  position: fixed; top: 56px; left: 280px; right: auto; margin: 0; z-index: 11;
  box-sizing: border-box; width: min(380px, calc(100vw - 16px)); max-height: calc(100dvh - 72px);
  overflow: auto; padding: 14px; color: #dde6ff; background: #0a1020;
  border: 1px solid #3b4f8f; border-radius: 8px; font-size: 13px;
}
#subspace-dialog .filter-heading { margin-bottom: 14px; }
#subspace-title { flex: 1; margin: 0; font-size: 17px; cursor: grab; touch-action: none; user-select: none; }
#subspace-title.dragging { cursor: grabbing; }
#subspace-controls[hidden], #subspace-selected[hidden], #subspace-camera[hidden] { display: none; }
#subspace-controls label { display: flex; justify-content: space-between; }
#subspace-controls input { box-sizing: border-box; width: 100%; margin: 4px 0 8px; }
#subspace-seed { background: #0d1530; color: #dde6ff; border: 1px solid #3b4f8f; padding: 6px; font: inherit; }
#subspace-controls p { font-size: 11px; line-height: 1.4; }
#subspace-error { color: #ffb3b3; }
#subspace-error:empty { display: none; }
#shape-dialog {
  position: fixed; top: 56px; left: 280px; right: auto; margin: 0; z-index: 11;
  box-sizing: border-box; width: min(460px, calc(100vw - 16px)); max-height: calc(100dvh - 72px);
  max-width: calc(100vw - 16px); min-width: min(280px, calc(100vw - 16px));
  overflow: auto; resize: both; padding: 14px; color: #dde6ff; background: #0a1020;
  border: 1px solid #3b4f8f; border-radius: 8px; font-size: 13px;
}
#shape-title { flex: 1; margin: 0; font-size: 17px; cursor: grab; touch-action: none; user-select: none; }
#shape-title.dragging { cursor: grabbing; }
#shape-dialog label { display: block; margin: 6px 0; }
#shape-dialog input:not([type="checkbox"]), #shape-dialog select {
  box-sizing: border-box; width: 100%; min-width: 0; margin-top: 4px; padding: 6px;
  background: #0d1530; color: #dde6ff; border: 1px solid #3b4f8f; border-radius: 4px; font: inherit;
}
#shape-dialog input[type="color"] { height: 34px; padding: 2px; }
#shape-dialog fieldset { min-width: 0; margin: 10px 0; border: 1px solid #3b4f8f; border-radius: 6px; }
.shape-fields { display: flex; flex-wrap: wrap; gap: 8px; }
.shape-fields > label { flex: 1; min-width: 80px; }
.shape-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
#shape-help, #shape-dialog small { font-size: 12px; color: #aebbdc; }
#shape-error { color: #ffb3b3; }
#shape-error:empty, #shape-status:empty { display: none; }
@media (max-width: 1024px) {
  #shape-dialog { left: 8px; }
  #shape-dialog input:not([type="checkbox"]), #shape-dialog select { font-size: 16px; }
}
#subspace-selected, #subspace-camera { color: #a7d8ff; font-size: 12px; }
button {
  background: #22305a; color: #dde6ff; border: 1px solid #3b4f8f;
  border-radius: 4px; padding: 5px 8px; cursor: pointer;
}
button:hover { background: #2e3f75; }
#return-milky-way { position: fixed; top: 52px; left: 50%; transform: translateX(-50%); z-index: 12; }
#return-milky-way[hidden] { display: none; }

#details { top: 52px; right: 12px; width: 260px; max-height: calc(100dvh - 170px); overflow-y: auto; }
#details h2 { margin: 0 0 8px; font-size: 17px; }
#details .view-from-controls { margin-top: 8px; }
#details .view-from-controls label { display: flex; justify-content: space-between; gap: 8px; }
#details table { width: 100%; border-collapse: collapse; }
#details th { text-align: left; font-weight: normal; opacity: 0.7; padding: 2px 6px 2px 0; }
#details td { text-align: right; padding: 2px 0; }
#d-stellar-source { max-width: 160px; overflow-wrap: anywhere; font-size: 12px; }
#close-details {
  position: absolute; top: 6px; right: 8px; padding: 0 6px;
  background: none; border: none; font-size: 18px;
}

.swatch {
  display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  vertical-align: middle; margin-right: 6px; box-shadow: 0 0 6px currentColor;
}

#help { bottom: 12px; left: 50%; transform: translateX(-50%); text-align: center; white-space: nowrap; }
#centre-info, #scale-info, #camera-info { margin-top: 4px; opacity: 0.75; }
#selection-distance { margin-top: 4px; font-variant-numeric: tabular-nums; color: #ffd27a; }
#selection-distance:empty { display: none; }
#camera-info { font-variant-numeric: tabular-nums; white-space: pre; }

@media (max-width: 1100px) {
  #help {
    left: auto; right: 12px; transform: none; box-sizing: border-box;
    max-width: calc(100% - 286px); white-space: normal;
  }
  #camera-info { white-space: pre-wrap; }
}

#labels { position: fixed; inset: 0; overflow: hidden; pointer-events: none; }
#labels[hidden] { display: none; }
.star-label {
  position: absolute; left: 0; top: 0;
  color: #dde6ff;
  font-size: 12px;
  line-height: 16px;
  padding: 0 4px;
  white-space: nowrap;
  text-shadow: 0 0 3px #000, 0 0 6px #000;
  user-select: none;
}
.star-label.catalogue { color: #9aa6c8; }
.star-label.neutron { color: #cdb4ff; font-style: italic; }
.star-label.blackhole { color: #ffc27a; font-style: italic; }
.star-label[hidden] { display: none; }

.star-key { color: #fff4e0; text-shadow: 0 0 6px #ffd9a0; font-size: 10px; }
.blackhole-key { color: #ff9d3c; text-shadow: 0 0 6px #ff9d3c; font-size: 10px; }
.neutron-key { color: #b48cff; text-shadow: 0 0 6px #b48cff; }
.nebula-key { color: #ff7a9a; text-shadow: 0 0 6px #ff5a7a; }
.star-label.nebula { color: #ffb0c4; font-style: italic; }
#star-list li.nebula .swatch { border-radius: 50%; background: transparent !important; border: 2px dashed currentColor; width: 7px; height: 7px; }
#star-list li.nebula .name { color: #ffc6d4; }
.galaxy-key { color: #b8ccff; text-shadow: 0 0 6px #7f9fff; }
.star-label.galaxy { color: #c4d4ff; font-style: italic; }
#star-list li.galaxy .swatch { border-radius: 50%; width: 11px; height: 5px; box-shadow: 0 0 4px currentColor; }
#star-list li.galaxy .name { color: #cdd9ff; }
#d-ids, #d-distref { max-width: 170px; white-space: normal; }
tr[hidden] { display: none; }
#d-notes { max-width: 220px; white-space: normal; }

/* ---------- Planets ---------- */
#planet-legend { display: flex; flex-direction: column; gap: 4px; padding-left: 4px; }
#planet-legend[hidden] { display: none; }
#planet-list { list-style: none; margin: 0; padding: 0; }
#planet-list li { display: flex; align-items: center; gap: 6px; padding: 2px 4px; border-radius: 4px; }
#planet-list li .swatch { flex: none; margin-right: 0; }
#planet-list li .name { flex: 1; }
#planet-list li .count { font-size: 11px; opacity: 0.6; }
#planet-list li.off { opacity: 0.4; }
#d-planets { font-size: 12px; }
#view-system { padding: 1px 6px; font-size: 11px; margin-top: 3px; }
#explore-system { margin-top: 4px; }
#share-dialog {
  color: #dde6ff; background: #0a1020; border: 1px solid #3b4f8f; border-radius: 6px;
  width: min(520px, calc(100vw - 48px)); box-sizing: border-box;
}
#share-dialog textarea { display: block; width: 100%; box-sizing: border-box; margin: 8px 0; overflow-wrap: anywhere; }
#share-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
#explore-system[hidden], #system-explorer[hidden] { display: none; }
#system-explorer {
  position: fixed; inset: 0; z-index: 40; background: #030611; color: #dde6ff;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: 220px minmax(0, 1fr);
}
#system-explorer header {
  grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 10px 14px; background: #0a1020;
}
#system-explorer h2 { margin: 0; font-size: 17px; }
.system-space { position: relative; grid-column: 2; grid-row: 2; min-width: 0; min-height: 0; overflow: hidden; }
.system-space canvas { display: block; }
.system-body-labels { position: absolute; inset: 0; pointer-events: none; }
.system-body-labels button {
  position: absolute; transform: translate(-50%, -140%); pointer-events: auto;
  font-size: 11px; padding: 2px 4px; background: rgba(10, 16, 32, 0.7); white-space: nowrap;
}
.system-body-labels button[hidden] { display: none; }
.system-body-labels button.selected { border-color: #ffd27a; color: #ffd27a; }
.system-explorer-controls { grid-column: 1; grid-row: 2; padding: 10px; overflow-y: auto; background: #0a1020; }
.system-explorer-controls > * { display: block; width: 100%; box-sizing: border-box; margin-bottom: 8px; }
.system-explorer-controls small { font-size: 11px; opacity: 0.75; }
#system-body-list { display: flex; flex-direction: column; gap: 4px; }
#system-body-list button { text-align: left; }
#system-body-list button[aria-pressed="true"] { border-color: #ffd27a; }
#system-explorer footer { grid-column: 1 / -1; padding: 8px 14px; background: #0a1020; font-size: 12px; }
#system-explorer footer p { margin: 0 0 5px; }
#system-explorer-status { opacity: 0.7; }
body.exploring-system #system-panel { z-index: 41; max-width: calc(100vw - 32px); }
@media (max-width: 600px) {
  #system-explorer { grid-template-columns: 140px minmax(0, 1fr); }
  #system-explorer header { padding: 8px; }
  #system-explorer h2 { font-size: 14px; }
  #system-explorer footer { max-height: 25dvh; overflow-y: auto; padding: 6px; }
  .system-explorer-controls { padding: 6px; font-size: 12px; }
}
#row-planets td { white-space: normal; }

#system-panel {
  top: 52px; right: 286px; width: 600px; max-width: calc(100% - 560px); max-height: calc(100% - 170px);
  overflow-y: auto;
}
#system-panel h2 { margin: 0 0 4px; font-size: 17px; padding-right: 20px; }
#s-title { cursor: grab; touch-action: none; user-select: none; }
#s-title.dragging { cursor: grabbing; }
#close-system {
  position: absolute; top: 6px; right: 8px; padding: 0 6px;
  background: none; border: none; font-size: 18px;
}
#s-badge { margin-bottom: 6px; }
.badge {
  display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; margin-right: 4px;
  border: 1px solid currentColor;
}
.badge.confirmed { color: #7fd1ff; }
.badge.simulated { color: #b9a6ff; }
.badge.habitable { color: #3ddc84; }
#s-star, #s-hz { font-size: 12px; opacity: 0.85; margin-bottom: 3px; }
#s-diagram { width: 100%; height: 110px; display: block; margin: 6px 0; }
#s-diagram text { font-size: 10px; fill: #9aa6c8; }
#s-diagram .planet-dot { cursor: pointer; }
#s-table-wrap { overflow-x: auto; }
#s-table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
#s-table th { text-align: right; font-weight: normal; opacity: 0.7; padding: 3px 5px; border-bottom: 1px solid #2c3a66; white-space: nowrap; }
#s-table td { text-align: right; padding: 3px 5px; white-space: nowrap; }
#s-table th:first-child, #s-table td:first-child, #s-table th:nth-child(2), #s-table td:nth-child(2) { text-align: left; }
#s-table tr.planet { cursor: pointer; }
#s-table tr.planet:hover { background: rgba(120, 150, 255, 0.12); }
#s-table tr.planet.hl { background: rgba(120, 150, 255, 0.22); }
#s-table tr.planet.habitable td:first-child { color: #3ddc84; font-weight: 600; }
#s-table tr.planet.hz td:first-child { color: #ffb02e; }
#s-table tr.planet td.desc { white-space: normal; opacity: 0.75; font-size: 11px; }
#s-table tr.moon td { font-size: 11px; opacity: 0.8; }
#s-table tr.moon td:first-child { padding-left: 16px; }
#s-table tr.moon.habitable td:first-child { color: #3ddc84; opacity: 1; }
#s-table tr.detail td { text-align: left; white-space: normal; font-size: 11px; opacity: 0.75; padding: 0 5px 6px 16px; }
#s-table .hz-c { color: #3ddc84; }
#s-table .hz-o { color: #ffb02e; }
#s-notes { font-size: 11px; opacity: 0.6; margin-top: 8px; }

/* ---------- User guide ---------- */
kbd {
  display: inline-block; min-width: 1.1em; padding: 1px 6px; text-align: center;
  font: 600 11px/1.5 ui-monospace, Consolas, monospace; color: #e8eeff;
  background: linear-gradient(#1d2a52, #121b38); border: 1px solid #4a5fa8; border-bottom-width: 2px; border-radius: 4px;
}
#about-dialog, #guide-dialog {
  position: fixed; inset: 0; margin: auto; z-index: 12; box-sizing: border-box;
  width: min(920px, calc(100vw - 32px)); height: min(680px, calc(100dvh - 64px));
  min-width: min(360px, 100vw); min-height: min(260px, 100dvh); max-width: 100vw; max-height: 100dvh;
  resize: both; container-type: size;
  padding: 0; overflow: hidden; display: none; flex-direction: column;
  color: #dde6ff; background: #070c1a; border: 1px solid #3b4f8f; border-radius: 14px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(155, 176, 255, 0.08), 0 0 60px rgba(90, 120, 255, 0.18);
}
#guide-dialog[open] { display: flex; animation: guide-in 0.22s ease-out; }
#guide-dialog::after { /* visible grip over the native resize corner */
  content: ""; position: absolute; right: 3px; bottom: 3px; width: 12px; height: 12px; pointer-events: none;
  background: linear-gradient(135deg, transparent 45%, #8fa6ff 45% 52%, transparent 52% 65%, #8fa6ff 65% 72%, transparent 72%);
  opacity: 0.8;
}
.guide-hero { cursor: grab; touch-action: none; user-select: none; }
.guide-hero.dragging { cursor: grabbing; }
.guide-hero #guide-close { cursor: pointer; }
@keyframes guide-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } }
.guide-hero {
  position: relative; flex: none; display: flex; align-items: flex-start; gap: 16px; padding: 26px 28px 22px;
  background:
    radial-gradient(ellipse at 85% 0%, rgba(255, 170, 90, 0.28), transparent 55%),
    radial-gradient(ellipse at 10% 120%, rgba(110, 90, 255, 0.35), transparent 60%),
    linear-gradient(135deg, #0f1a3d, #0a1128 60%, #120c2c);
  border-bottom: 1px solid #2b3b70; overflow: hidden;
}
.guide-hero > div:not(.guide-hero-stars) { position: relative; flex: 1; max-width: 680px; }
.guide-hero-stars {
  position: absolute; inset: 0; pointer-events: none; opacity: 0.8;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 30%, #fff, transparent), radial-gradient(1px 1px at 28% 72%, #cfe0ff, transparent),
    radial-gradient(1.5px 1.5px at 47% 18%, #ffe9c4, transparent), radial-gradient(1px 1px at 63% 64%, #fff, transparent),
    radial-gradient(2px 2px at 78% 38%, #ffd5a0, transparent), radial-gradient(1px 1px at 91% 78%, #bcd0ff, transparent),
    radial-gradient(1px 1px at 37% 45%, #fff, transparent), radial-gradient(1.5px 1.5px at 85% 12%, #fff, transparent);
}
.guide-kicker { margin: 0 0 4px; font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: #ffc98f; }
#guide-title {
  margin: 0 0 8px; font-size: 26px; font-weight: 600; letter-spacing: 0.5px;
  background: linear-gradient(90deg, #ffffff, #b9c8ff); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.guide-hero p:last-child { margin: 0; font-size: 13.5px; line-height: 1.55; color: #c3cdee; }
#guide-close {
  position: relative; flex: none; width: 32px; height: 32px; padding: 0; font-size: 20px; line-height: 1;
  color: #dde6ff; background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(155, 176, 255, 0.3); border-radius: 50%; cursor: pointer;
}
#guide-close:hover { background: rgba(255, 255, 255, 0.14); }
.guide-body { flex: 1; min-height: 0; display: flex; }
.guide-nav {
  flex: none; width: 190px; padding: 14px 10px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px; background: #0a1022; border-right: 1px solid #1f2b52;
}
.guide-nav a {
  padding: 7px 10px; border-radius: 6px; font-size: 13px; color: #aebbdc; text-decoration: none;
  border-left: 2px solid transparent; transition: background 0.15s, color 0.15s;
}
.guide-nav a:hover { background: #141e3e; color: #fff; }
.guide-nav a.active { background: linear-gradient(90deg, rgba(110, 140, 255, 0.22), transparent); color: #fff; border-left-color: #8fa6ff; }
.guide-content { flex: 1; min-width: 0; overflow-y: auto; padding: 6px 30px 24px; scroll-padding-top: 16px; font-size: 14px; line-height: 1.6; }
.guide-content:focus { outline: none; }
.guide-content section { padding: 18px 0 10px; border-bottom: 1px solid #172246; }
.guide-content section:last-child { border-bottom: 0; min-height: 100%; box-sizing: border-box; } /* lets every section scroll to the top */
.guide-content h3 { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; font-size: 18px; font-weight: 600; color: #fff; }
.guide-icon {
  display: inline-grid; place-items: center; width: 30px; height: 30px; flex: none; font-size: 15px;
  border-radius: 8px; background: linear-gradient(135deg, #2a3d8a, #4b2f8a); box-shadow: 0 0 14px rgba(120, 140, 255, 0.35);
}
.guide-content p { margin: 0 0 10px; color: #c9d3f2; }
.guide-content em { color: #ffd9a8; font-style: normal; }
.guide-content b { color: #fff; }
.guide-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin: 12px 0 14px; }
.guide-card {
  display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border-radius: 10px;
  background: linear-gradient(160deg, #142049, #0d1430); border: 1px solid #263a78; font-size: 13px; color: #b8c4e8;
}
.guide-card b { color: #9fb4ff; }
.guide-table { width: 100%; border-collapse: collapse; margin: 4px 0 12px; font-size: 13px; }
.guide-table td { padding: 8px 10px; border-bottom: 1px solid #172246; vertical-align: top; }
.guide-table td:first-child { width: 42%; white-space: nowrap; }
.guide-table tr:last-child td { border-bottom: 0; }
.guide-mouse { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; color: #e8eeff; background: #22306a; }
.guide-tip, .guide-example {
  padding: 10px 14px; border-radius: 8px; font-size: 13px;
  background: rgba(255, 190, 110, 0.08); border-left: 3px solid #ffb764;
}
.guide-example { margin: 10px 0 12px; background: rgba(120, 150, 255, 0.08); border-left-color: #8fa6ff; }
.guide-example-label { display: block; font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase; color: #8fa6ff; margin-bottom: 4px; }
.guide-example code { padding: 1px 6px; border-radius: 4px; font: 12px ui-monospace, Consolas, monospace; background: #0d1530; color: #cfe0ff; }
.guide-defs { display: grid; grid-template-columns: 130px 1fr; gap: 8px 16px; margin: 4px 0 12px; font-size: 13px; }
.guide-defs dt { font-weight: 600; color: #9fb4ff; }
.guide-defs dd { margin: 0; color: #c9d3f2; }
.guide-list { margin: 0 0 10px; padding-left: 20px; color: #c9d3f2; }
.guide-list li { margin-bottom: 4px; }
.guide-list li::marker { color: #8fa6ff; }
@container (max-width: 640px) {
  .guide-nav { display: none; }
  .guide-content { padding: 6px 18px 24px; }
  .guide-defs { grid-template-columns: 1fr; }
  .guide-table td:first-child { white-space: normal; }
}
@container (max-height: 520px) {
  .guide-hero { padding: 12px 18px; align-items: center; }
  .guide-kicker, .guide-hero p:last-child { display: none; }
  #guide-title { margin: 0; font-size: 20px; }
}
@media (prefers-reduced-motion: reduce) { #guide-dialog[open] { animation: none; } }

@media (pointer: coarse) {
  button, select, input:not([type="checkbox"]), .menu-commands button,
  #orientation-views button, #view-system, #close-details, #close-system, #close-star-panel {
    min-height: 44px;
  }
  button, #orientation-views button { min-width: 44px; }
  .menu-commands a { min-height: 44px; box-sizing: border-box; display: flex; align-items: center; }
  input[type="checkbox"] { width: 20px; height: 20px; vertical-align: middle; }
  .toolbar label, #star-list li, #planet-list li, #sovereignty-list li { min-height: 44px; box-sizing: border-box; }
  .toolbar label { display: flex; align-items: center; gap: 6px; }
  .desktop-hints { display: none; }
  .touch-hints { display: block; }
  #star-search, #distance-filter, #filter-dialog input:not([type="checkbox"]), #filter-dialog select,
  #frame-select, #colour-mode, #subspace-seed, #view-from-search, #view-toward-search,
  #view-from-preset { font-size: 16px; }
}

@media (max-width: 1024px) {
  #top-menu { height: 48px; gap: 8px; padding: 0 8px; }
  #toggle-controls, #close-controls { display: block; }
  #top-menu summary { padding: 12px 6px; }
  #top-menu #catalogue-menu .menu-commands {
    position: fixed; top: 52px; left: 8px; width: min(320px, calc(100vw - 16px));
  }
  #sidebar {
    display: none; z-index: 9; top: 56px; left: 8px; width: min(320px, calc(100vw - 16px));
    max-height: calc(100dvh - 72px); box-sizing: border-box; background: rgba(10, 16, 32, 0.97);
  }
  #sidebar.controls-open { display: flex; }
  #details, #star-panel, #system-panel {
    box-sizing: border-box; z-index: 6; top: 56px !important; left: auto !important; right: 8px !important;
    width: min(400px, calc(100vw - 16px)); max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 190px); overflow-y: auto;
  }
  #details { z-index: 8; }
  #star-panel { height: min(520px, calc(100dvh - 190px)); min-height: 0; z-index: 7; }
  #system-panel { width: min(640px, calc(100vw - 16px)); z-index: 8; }
  #details h2 { padding-right: 36px; overflow-wrap: anywhere; }
  #details td { overflow-wrap: anywhere; }
  #help {
    left: 144px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); max-width: none;
    transform: none; padding: 8px; font-size: 11px; white-space: normal; max-height: 112px; overflow-y: auto;
  }
  #orientation-widget {
    left: 8px; bottom: max(8px, env(safe-area-inset-bottom)); width: 128px; height: 128px;
    padding: 0; flex-direction: column; gap: 0;
  }
  #orientation-canvas { width: 72px; height: 72px; }
  #orientation-widget h2, #orientation-legend { display: none; }
  #orientation-views { gap: 0; margin: 0; }
  #orientation-views button { padding: 4px; min-width: 40px; }
  #subspace-dialog { left: 8px !important; top: 56px !important; }
  #filter-dialog {
    left: 8px !important; top: 56px !important; right: auto; margin: 0; width: calc(100vw - 16px);
    max-height: calc(100dvh - 72px); padding: 12px;
  }
  #guide-dialog {
    left: 8px !important; top: 56px !important; right: auto; bottom: auto; margin: 0;
    width: calc(100vw - 16px) !important; height: calc(100dvh - 72px) !important;
    min-width: 0; min-height: 0; resize: none;
  }
  .filter-group { padding: 8px; margin-left: 0; margin-right: 0; }
}

@media (max-width: 600px) {
  #details, #star-panel, #system-panel { max-height: calc(100dvh - 210px); }
  #star-panel { height: min(420px, calc(100dvh - 210px)); }
  #camera-info { display: none; }
  #help { max-height: 120px; }
}

@media (max-width: 1024px) and (max-height: 500px) {
  #details, #star-panel, #system-panel { max-height: calc(100dvh - 72px); }
  #star-panel { height: calc(100dvh - 72px); }
  #help { max-height: 72px; }
  #camera-info, #scale-info, .desktop-hints, .touch-hints { display: none; }
}
