:root {
  --bg: #0e1116;
  --panel: #171c24;
  --panel-2: #1f2630;
  --text: #d7dde6;
  --muted: #8a94a3;
  --accent: #6ea8fe;
  --border: #2a313c;
  --error: #ff8a8a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header {
  padding: 2rem 1.5rem 1rem;
  max-width: 1000px;
  margin: 0 auto;
}

h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.5px;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

.crumb {
  margin: 0 0 0.5rem;
}

.crumb a {
  color: var(--muted);
  text-decoration: none;
}

.crumb a:hover {
  color: var(--accent);
}

main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
}

form {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.row label {
  width: 120px;
  color: var(--muted);
  flex: none;
}

input[type="text"],
select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  font: inherit;
  min-width: 220px;
}

input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  background: var(--accent);
  color: #0b1020;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1.1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.6rem;
}

button:hover {
  filter: brightness(1.08);
}

.actions {
  margin-top: 0.25rem;
}

.status {
  color: var(--muted);
  overflow-wrap: anywhere; /* the full request URL must not force the page wider than a phone */
}

.status.error {
  color: var(--error);
}

@media (max-width: 600px) {
  /* Let the fields shrink into the card, and drop the status under the buttons. */
  input[type="text"],
  select {
    min-width: 0;
  }

  .actions {
    flex-wrap: wrap;
  }

  .status {
    flex-basis: 100%;
  }
}

section#result {
  margin-top: 1.5rem;
}

/* Hover card: headline facts for the orrery body under the pointer (a tap pins it on touch).
   Positioned within #rendered rather than the orrery card, whose overflow would clip it. */
#rendered {
  position: relative;
}

.orrery-body {
  cursor: pointer;
}

.orrery-body:hover {
  filter: brightness(1.15);
}

.hover-card {
  position: absolute;
  z-index: 5;
  max-width: 320px;
  padding: 0.5rem 0.7rem 0.55rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  font-size: 0.8rem;
}

.hover-card .hc-actions {
  margin-top: 0.4rem;
}

/* The card's action, styled as a link. */
.hc-open {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

.hc-open:hover {
  text-decoration: underline;
  filter: none;
}

/* A glyph whose record is being hovered in the fold-out. */
.orrery-body.lit {
  filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.85)) brightness(1.25);
}

/* A record just jumped to from the map. */
@keyframes node-flash {
  from {
    background: rgba(110, 168, 254, 0.28);
  }
  to {
    background: transparent;
  }
}

.node.flash > .node-head {
  animation: node-flash 1.6s ease-out;
  border-radius: 6px;
}

.hover-card .hc-title {
  margin-bottom: 0.3rem;
}

.hover-card .hc-kind {
  color: var(--muted);
  margin-left: 0.4rem;
}

.hover-card .grid {
  font-size: 0.78rem;
  gap: 0.05rem 0.7rem;
}

.hover-card .comp {
  min-width: 170px;
  margin: 0.2rem 0 0.1rem;
}

.hover-card .comp-key {
  font-size: inherit;
  gap: 0 0.6rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

/* Traveller system hex: an inline SVG centred in the card. */
.hex-card {
  display: flex;
  justify-content: center;
}

.hex-svg {
  width: 100%;
  max-width: 360px;
  height: auto;
  color: var(--text);
}

/* Traveller UWP status line under the hex: the world profile string, shown verbatim/monospaced. */
.uwp {
  margin: 0.75rem 0 0;
  text-align: center;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.04em;
  color: var(--text);
}

/* Name + download controls under the traveller hex. */
.hex-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.75rem 0 0.5rem;
}

.hex-controls label {
  color: var(--muted);
}

.hex-controls input {
  min-width: 200px;
}

.hex-controls button {
  margin-left: auto;
}

@media (max-width: 600px) {
  .hex-controls input {
    min-width: 0;
  }
}

/* System orrery: a schematic map of the generated system, drawn as inline SVG. It scales down to
   the card's width (app.js splits wide systems into rows so the scale never drops below 0.72); the
   overflow-x is a last resort that should not trigger, kept so the page body can never scroll
   sideways. Centred with margin:auto rather than .hex-card's flex, because centring an over-wide
   flex item makes its leading overflow unreachable to the scroll container. */
.orrery-card {
  overflow-x: auto;
  padding: 0.5rem;
}

.orrery-svg {
  display: block;
  margin: 0 auto;
  width: 100%; /* scales down to the card; the inline max-width stops it scaling up */
  height: auto;
  color: var(--text);
}

/* Legend: an "ⓘ Legend" pill at the bottom right of the orrery card that unfolds the legend (only
   the marks this system uses, in the orrery's own colours) as a panel beneath itself. The panel is
   in the page flow, not floated, so an open legend never covers the map. */
.legend-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin: 0.3rem 0.25rem 0;
}

.legend-wrap > summary {
  list-style: none;
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--muted);
  padding: 0.1rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
}

.legend-wrap > summary::-webkit-details-marker {
  display: none;
}

.legend-wrap[open] > summary,
.legend-wrap > summary:hover {
  color: var(--text);
}

.legend-panel {
  margin-top: 6px;
  max-width: 100%;
  padding: 0.45rem 0.75rem 0.4rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.1rem 0.9rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.legend li {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.swatch {
  flex: none;
}

.legend-note {
  margin: 0.3rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

/* The folded-away per-body detail under the orrery. Deeply nested records with wide grids can
   exceed a phone's width; they scroll inside the fold-out rather than widening the page. */
.tree-wrap {
  overflow-x: auto;
}

.tree-wrap > summary {
  margin-bottom: 0.5rem;
}

/* Summary strip: what the map cannot answer at a glance, as chips above it in the orrery card. */
.summary {
  list-style: none;
  margin: 0.15rem 0 0.4rem;
  padding: 0 0.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem 0.15rem 0.3rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
}

.chip strong {
  color: var(--text);
  font-weight: 600;
}

.chip-fact {
  padding-left: 0.55rem;
}

.unit {
  color: var(--muted);
  margin-left: 0.15rem;
}

/* Hub landing page: shared API-base config + a card per generator. */
.hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.75rem 0 0;
}

code {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05rem 0.3rem;
  font-size: 0.9em;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.gcard {
  display: block;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  color: inherit;
  text-decoration: none;
}

.gcard:hover {
  border-color: var(--accent);
}

.gcard h2 {
  margin: 0 0 0.4rem;
  font-size: 1.1rem;
}

.gcard p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

/* Result tree: each body is a node with collapsible-looking nested children. */
.tree,
.children {
  list-style: none;
  margin: 0;
  padding: 0;
}

.children {
  margin-left: 1rem;
  padding-left: 1rem;
  border-left: 2px solid var(--border);
}

.node {
  margin: 0.6rem 0;
}

.node-head {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* The record's portrait: the orrery glyph at icon size, beside the badge. */
.portrait {
  flex: none;
  align-self: center;
}

.node-title {
  font-weight: 600;
}

.node-id {
  color: var(--muted);
  font-size: 0.85rem;
}

/* A record id that links back up to its glyph in the map. */
.node-id-link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
}

.node-id-link:hover {
  color: var(--accent);
  text-decoration: underline;
  filter: none;
}

/* A glyph just jumped to from its record. */
@keyframes glyph-pulse {
  from {
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.95)) brightness(1.6);
  }
  to {
    filter: none;
  }
}

.orrery-body.pulse {
  animation: glyph-pulse 1.6s ease-out;
}

.node-orbit {
  color: var(--muted);
  font-size: 0.9rem;
  margin-left: auto;
}

.badge {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.badge-star {
  color: #ffd479;
  border-color: #5a4a1f;
}

.badge-planet {
  color: var(--accent);
  border-color: #2c4a78;
}

.badge-moon {
  color: #9fd6c2;
  border-color: #2a5448;
}

.badge-asteroidBelt,
.badge-ring,
.badge-moonlet {
  color: #c2a8e0;
  border-color: #463058;
}

.node-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin: 0.4rem 0 0;
}

.sect {
  min-width: 200px;
}

.sect h4 {
  margin: 0 0 0.25rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 700;
}

/* A definition-list grid used for orbit/core and every nested record. */
.grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.15rem 0.9rem;
  margin: 0;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.grid dt {
  color: var(--muted);
}

.grid dd {
  margin: 0;
}

/* Atmosphere composition: a stacked bar plus a key, in place of a grid of numbers. */
.comp {
  min-width: 200px;
  margin: 0.15rem 0 0.35rem;
}

.comp-bar {
  display: flex;
  height: 10px;
  border-radius: 5px;
  overflow: hidden;
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.comp-bar span {
  display: block;
  height: 100%;
  min-width: 2px; /* a trace gas still shows as a sliver */
}

.comp-key {
  list-style: none;
  margin: 0.25rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.1rem 0.8rem;
  font-size: 0.85rem;
}

.comp-key li::before {
  content: "";
  display: inline-block;
  width: 0.6em;
  height: 0.6em;
  border-radius: 50%;
  background: var(--c);
  margin-right: 0.35em;
  vertical-align: 0.05em;
}

/* Moon strip: a planet's satellites on a log axis, above their folded records. */
.moon-strip {
  display: block;
  width: 100%;
  max-width: 640px;
  height: auto;
  margin: 0.35rem 0 0.1rem;
  color: var(--text);
}

.moons-wrap {
  margin-top: 0.1rem;
}

.moons-wrap > summary {
  font-size: 0.85rem;
}

/* Nested grids (e.g. an AoW world's climate/atmosphere) indent slightly for legibility. */
.grid dd > .grid {
  margin: 0.15rem 0 0.35rem;
  padding-left: 0.6rem;
  border-left: 1px solid var(--border);
}

.list {
  margin: 0;
  padding-left: 1.1rem;
}

details {
  margin-top: 0.5rem;
}

summary {
  cursor: pointer;
  color: var(--muted);
}

pre {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.82rem;
}

/* Book reference under a generator page's title, and the "differences from the book" pages. */
.source {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.source a,
.about a {
  color: var(--accent);
}

.about h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.about p {
  margin: 0 0 0.5rem;
}

.about ul {
  margin: 0;
  padding-left: 1.2rem;
}

.about li + li {
  margin-top: 0.4rem;
}

.facts {
  margin: 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.4rem 1rem;
}

.facts dt {
  color: var(--muted);
}

.facts dd {
  margin: 0;
}

@media (max-width: 600px) {
  .facts {
    grid-template-columns: 1fr;
    gap: 0.1rem;
  }

  .facts dd {
    margin-bottom: 0.5rem;
  }
}
