/* Periodic Orbits site: app shell with a sidebar of choices, the 3D view with its member
   scrubber, and a lower row with the family diagram and the orbit card. */
:root {
  --bg: #e9edf2; --panel: #ffffff; --panel-2: #f4f6f9; --ink: #172130; --muted: #5a6577;
  --rule: #d4dae3; --accent: #1f7a83; --accent-ink: #ffffff; --sel: #e0353b;
  --warn: #a8440f; --warn-bg: #fbeee4;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --radius-s: 4px; --radius-m: 8px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1219; --panel: #141b25; --panel-2: #1a2330; --ink: #e3e8f0; --muted: #93a0b3;
    --rule: #263142; --accent: #45b3a8; --accent-ink: #08201e; --sel: #ff5a5f; --warn: #f5a35b; --warn-bg: #33241a; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1219; --panel: #141b25; --panel-2: #1a2330; --ink: #e3e8f0; --muted: #93a0b3;
  --rule: #263142; --accent: #45b3a8; --accent-ink: #08201e; --sel: #ff5a5f; --warn: #f5a35b; --warn-bg: #33241a; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.4 var(--sans);
  font-variant-numeric: tabular-nums;
}
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Shell */
.app { display: grid; grid-template-rows: auto 1fr; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding-block: 0.6rem; padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--panel); border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 0.6rem; margin: 0; font-size: 1.05rem; font-weight: 600; letter-spacing: 0.01em; }
.brand svg { width: 28px; height: 28px; flex: none; }
.topbar .spacer { flex: 1; }
.body { display: grid; grid-template-columns: 290px minmax(0, 1fr); min-height: 0; }

/* Sidebar */
.side {
  background: var(--panel); border-right: 1px solid var(--rule); overflow-y: auto;
  padding: 1rem; display: flex; flex-direction: column; gap: 1.4rem; min-width: 0;
}
.side h2 { margin: 0 0 0.5rem; font-size: 0.8rem; font-weight: 600; color: var(--muted); letter-spacing: 0.02em; }
.group { display: flex; flex-direction: column; gap: 0.6rem; }

/* Segmented controls */
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: var(--radius-m); overflow: hidden; background: var(--panel-2); }
.seg button {
  border: 0; background: transparent; padding: 0.35rem 0.75rem; cursor: pointer; white-space: nowrap;
}
.seg button + button { border-left: 1px solid var(--rule); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg button:disabled { color: var(--muted); opacity: 0.45; cursor: default; }
.seg.points { display: grid; grid-template-columns: repeat(6, 1fr); width: 100%; }
.seg.points button { padding: 0.35rem 0; }

/* Family list */
.families { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.families button {
  width: 100%; text-align: left; border: 0; background: transparent; padding: 0.4rem 0.6rem;
  border-radius: var(--radius-s); cursor: pointer; display: flex; justify-content: space-between; gap: 0.5rem;
}
.families button:hover { background: var(--panel-2); }
.families button[aria-current="true"] { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; }

.variant { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.6rem; background: var(--panel-2); border-radius: var(--radius-m); }
.vrow { display: grid; grid-template-columns: 4rem minmax(0, 1fr); gap: 0.75rem; align-items: center; }
.vrow[hidden] { display: none; }
.vrow select { width: 100%; border: 1px solid var(--rule); border-radius: var(--radius-s); background: var(--panel); padding: 0.25rem 0.4rem; }
.variant[hidden] { display: none; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--rule); border-radius: var(--radius-m); background: var(--panel); width: max-content; }
.stepper button { border: 0; background: transparent; width: 2rem; height: 1.9rem; cursor: pointer; font-size: 1.05rem; }
.stepper output { min-width: 2.2rem; text-align: center; font-weight: 600; }

/* Fields and switches */
.field { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0.75rem; }
.field select, select.small {
  border: 1px solid var(--rule); border-radius: var(--radius-s); background: var(--panel); padding: 0.25rem 0.4rem;
}
.field input[type=range] { width: 8.5rem; margin: 0; accent-color: var(--accent); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; cursor: pointer; }
.switch input { appearance: none; width: 34px; height: 20px; border-radius: 10px; background: var(--rule); position: relative; cursor: pointer; flex: none; margin: 0; transition: background 0.15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--panel); transition: transform 0.15s; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(14px); }

/* Main area */
.main { display: grid; grid-template-rows: minmax(320px, 1fr) 320px; gap: 1px; background: var(--rule); min-width: 0; min-height: 0; }
.viewport { position: relative; background: var(--panel); min-height: 0; display: flex; flex-direction: column; }
.stage { position: relative; flex: 1; min-height: 0; }
#view3d { position: absolute; inset: 0; }
.caption { position: absolute; top: 0.8rem; left: 1rem; z-index: 2; pointer-events: none; }
.caption h2 { margin: 0; font-size: 1.15rem; font-weight: 600; }
.caption p { margin: 0.1rem 0 0; color: var(--muted); }
.status { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); z-index: 3; pointer-events: none; }
.status[hidden] { display: none; }

/* Scrubber */
.scrubber {
  display: grid; grid-template-columns: auto auto auto minmax(0, 1fr) auto; align-items: center; gap: 0.5rem;
  padding: 0.55rem 1rem; border-top: 1px solid var(--rule); background: var(--panel);
}
.icon { border: 1px solid var(--rule); background: var(--panel-2); width: 2rem; height: 2rem; border-radius: var(--radius-s); cursor: pointer; display: grid; place-items: center; padding: 0; }
.icon svg { width: 14px; height: 14px; fill: currentColor; }
.icon.play[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.track { position: relative; height: 2rem; display: flex; align-items: center; }
.track .ramp { position: absolute; left: 0; right: 0; height: 8px; border-radius: 4px; }
.track input[type=range] { position: relative; width: 100%; margin: 0; appearance: none; background: transparent; height: 2rem; cursor: pointer; }
.track input[type=range]::-webkit-slider-runnable-track { height: 8px; background: transparent; }
.track input[type=range]::-moz-range-track { height: 8px; background: transparent; }
.track input[type=range]::-webkit-slider-thumb { appearance: none; width: 6px; height: 22px; margin-top: -7px; border-radius: 3px; background: var(--sel); border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--sel); }
.track input[type=range]::-moz-range-thumb { width: 4px; height: 18px; border-radius: 3px; background: var(--sel); border: 2px solid var(--panel); }
.readout { min-width: 6.5rem; text-align: right; color: var(--muted); white-space: nowrap; }
.readout b { color: var(--ink); font-weight: 600; }

/* Lower row */
.lower { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 1px; min-height: 0; }
.panel { background: var(--panel); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.panel header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.6rem 1rem 0; }
.panel header h2 { margin: 0; font-size: 0.95rem; font-weight: 600; }
#view2d { flex: 1; min-height: 0; }
.card { padding: 0.6rem 1rem 1rem; overflow-y: auto; display: flex; flex-direction: column; gap: 0.8rem; }
.values { display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 1rem; margin: 0; }
.values dt { color: var(--muted); }
.values dd { margin: 0; text-align: right; }
.values dd small { color: var(--muted); margin-left: 0.4rem; }
.state { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 0.15rem 0.6rem; margin: 0; padding: 0.6rem 0.75rem; background: var(--panel-2); border-radius: var(--radius-s); font: 0.8rem/1.5 var(--mono); }
.state dt { color: var(--muted); }
.state dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.actions { display: flex; align-items: center; gap: 0.75rem; }
.button { border: 1px solid var(--accent); background: transparent; color: var(--ink); padding: 0.35rem 0.8rem; border-radius: var(--radius-s); cursor: pointer; }
.button:hover { background: var(--accent); color: var(--accent-ink); }
.note { color: var(--muted); font-size: 0.85rem; }

/* About dialog */
dialog { border: 1px solid var(--rule); border-radius: var(--radius-m); background: var(--panel); color: var(--ink); max-width: min(34rem, calc(100vw - 32px)); padding: 1.2rem 1.4rem; }
dialog::backdrop { background: rgba(10, 15, 25, 0.45); }
dialog h2 { margin: 0 0 0.6rem; font-size: 1.05rem; }
dialog p { margin: 0 0 0.6rem; line-height: 1.5; }
dialog table { border-collapse: collapse; margin: 0.4rem 0 0.8rem; width: 100%; }
dialog th, dialog td { text-align: left; padding: 0.2rem 0.6rem 0.2rem 0; border-bottom: 1px solid var(--rule); }
dialog td { text-align: right; }

/* Narrow screens: one column that scrolls. */
@media (max-width: 900px) {
  .app { height: auto; }
  .body { grid-template-columns: minmax(0, 1fr); }
  .side { border-right: 0; border-bottom: 1px solid var(--rule); order: 2; overflow: visible; }
  .main { order: 1; grid-template-rows: auto auto; }
  .viewport { height: 62vh; min-height: 340px; }
  .topbar { display: grid; grid-template-columns: 1fr auto; }
  .topbar .spacer { display: none; }
  .topbar #systems { grid-row: 2; grid-column: 1 / -1; width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); }
  .state { grid-template-columns: auto 1fr; }
  .lower { grid-template-columns: minmax(0, 1fr); }
  #view2d { height: 280px; flex: none; }
  .topbar { gap: 0.75rem; }
  .readout { min-width: 0; }
}
@media (prefers-reduced-motion: reduce) { .switch input, .switch input::after { transition: none; } }
#view3d .modebar-btn svg { width: 16px; height: 16px; }

/* Family note, warnings and the families that meet at an event. */
.caption .blurb { max-width: 38ch; font-size: 0.85rem; margin-top: 0.3rem; }
.caption a { pointer-events: auto; color: var(--accent); }
.warn { margin: 0; padding: 0.45rem 0.7rem; border-radius: var(--radius-s); background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.warn[hidden] { display: none; }
.actions { flex-wrap: wrap; }
.panel { position: relative; }
.links {
  position: absolute; z-index: 5; display: flex; flex-direction: column; align-items: stretch; gap: 0.35rem;
  max-width: min(22rem, calc(100% - 8px)); padding: 0.6rem 2.2rem 0.7rem 0.75rem; font-size: 0.85rem;
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-m); box-shadow: 0 4px 14px rgba(10, 15, 25, 0.18);
}
.links p { margin: 0; font-weight: 600; }
.links p.note { font-weight: 400; }
.links .button { text-align: left; }
.links .icon.close { position: absolute; top: 0.4rem; right: 0.4rem; }
.links[hidden] { display: none; }
.button.small { padding: 0.15rem 0.55rem; font-size: 0.85rem; }
.icon.close { width: 1.6rem; height: 1.6rem; font-size: 1rem; line-height: 1; }
dialog a { color: var(--accent); }
.tools { display: flex; align-items: center; gap: 0.5rem; }
