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; }

#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;
}
#view-menu summary, #help-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 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; }

.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; }
#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, #scenario-select {
  flex: 1; background: #0d1530; color: #dde6ff; border: 1px solid #3b4f8f; border-radius: 4px;
  padding: 3px 6px; font: inherit;
}
#scenario-select { min-width: 0; }
#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; }
#scenario-status { font-size: 11px; overflow-wrap: anywhere; }
#scenario-status.error { color: #ffb3b3; }
#reload-scenarios { margin-bottom: 4px; font-size: 11px; }
#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; }
button {
  background: #22305a; color: #dde6ff; border: 1px solid #3b4f8f;
  border-radius: 4px; padding: 5px 8px; cursor: pointer;
}
button:hover { background: #2e3f75; }

#details { top: 52px; right: 12px; width: 260px; }
#details h2 { margin: 0 0 8px; font-size: 17px; }
#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; }
#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; }
#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;
}
#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; } }
