/* Hyperspace Explorer. Layout: 3D stage + timeline on the left, tabbed instrument panel on the right; one column on phones. */
:root {
  color-scheme: dark;
  --bg: #100d1f;
  --panel: #17132b;
  --panel-2: #1d1836;
  --line: #2a2448;
  --line-2: #3a325f;
  --fg: #e4e1f0;
  --muted: #958fb3;
  --dim: #655f86;
  --canvas: #0b0918;
  --cyan: #4fd3e3;
  --cyan-soft: rgba(79, 211, 227, .14);
  --amber: #f1b24a;
  --amber-soft: rgba(241, 178, 74, .14);
  --emerald: #3ddc97;
  --red: #ef6b5b;
  --display: "Literata", "Iowan Old Style", Georgia, serif;
  --sans: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r: 6px;
}
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 var(--sans); }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.app { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 12px; padding-block: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; }
.eyebrow { font: 500 11px/1.2 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h1 { margin: 4px 0 0; font: 600 25px/1.15 var(--display); text-wrap: balance; }
h1 span { display: block; margin-top: 3px; font: 400 13px/1.3 var(--sans); color: var(--muted); }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.controls label { font: 500 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
select, .btn, input[type=number] { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--r); padding: 6px 10px; min-height: 32px; }
.btn { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; transition: border-color .15s; white-space: nowrap; }
.btn:hover { border-color: var(--cyan); }
.btn svg { width: 14px; height: 14px; flex: none; }
.btn.primary { background: var(--cyan-soft); border-color: rgba(79,211,227,.5); color: var(--cyan); }
.btn.icon { padding: 6px 8px; }
.btn.sm { min-height: 26px; padding: 3px 9px; font-size: 12px; }
.btn[aria-pressed=true] { border-color: var(--red); color: var(--red); background: rgba(239,107,91,.12); }

.work { min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 12px; }
.stage-col { min-width: 0; min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: 10px; }
.stage { position: relative; min-height: 360px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--canvas); }
.stage canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; touch-action: none; }
.stage-note { position: absolute; left: 12px; top: 10px; max-width: min(440px, calc(100% - 220px)); font-size: 12.5px; color: var(--muted); pointer-events: none; }
.stage-note b { color: var(--fg); font-weight: 500; }
.status-pill { position: absolute; right: 12px; top: 10px; display: inline-flex; align-items: center; gap: 8px; padding: 5px 10px; border-radius: 999px; font: 600 11.5px var(--mono); letter-spacing: .04em; background: rgba(11,9,24,.85); border: 1px solid var(--line-2); }
.status-pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-pill.ok i { background: var(--emerald); box-shadow: 0 0 8px var(--emerald); }
.status-pill.run i { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.status-pill.bad i { background: var(--red); box-shadow: 0 0 8px var(--red); }
.legend { position: absolute; left: 12px; bottom: 10px; display: flex; flex-wrap: wrap; gap: 4px 12px; font: 11px var(--mono); color: var(--muted); pointer-events: none; max-width: calc(100% - 300px); }
@media (max-width: 1240px) { .cam-hint { display: none; } .legend { max-width: calc(100% - 24px); } }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: 3px; }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; vertical-align: -1px; }
.tip { position: absolute; pointer-events: none; padding: 5px 8px; border-radius: 4px; background: rgba(11,9,24,.92); border: 1px solid var(--line-2); font: 11.5px var(--mono); white-space: nowrap; transform: translate(12px, -50%); }
.cam-hint { position: absolute; right: 12px; bottom: 10px; max-width: 260px; white-space: normal; font: 11px var(--mono); color: var(--dim); pointer-events: none; text-align: right; }

.timeline { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 10px 12px; display: grid; gap: 8px; }
.tl-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.tl-read { font: 500 13px var(--mono); font-variant-numeric: tabular-nums; min-width: 100px; }
.tl-read b { color: var(--cyan); }
.spacer { flex: 1; }
.coef { font: 11.5px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.coef b { color: var(--fg); font-weight: 500; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; background: transparent; height: 18px; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: var(--cyan); border: 2px solid var(--bg); box-shadow: 0 0 0 1px var(--cyan); }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--cyan); border: 2px solid var(--bg); }
#scrub::-webkit-slider-runnable-track { background: linear-gradient(90deg, var(--cyan) var(--p, 0%), var(--line-2) var(--p, 0%)); }
.tele { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.spark { min-width: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r); padding: 6px 8px; display: grid; gap: 2px; }
.spark-h { display: flex; justify-content: space-between; gap: 8px; font: 11px var(--mono); color: var(--muted); }
.spark-h b { font-weight: 600; font-variant-numeric: tabular-nums; }
.spark canvas { width: 100%; height: 38px; display: block; }

.panel { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); border: 1px solid var(--line); border-radius: 8px; background: var(--panel); overflow: hidden; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; background: none; border: 0; padding: 10px 4px; cursor: pointer; font: 500 12px var(--mono); letter-spacing: .05em; text-transform: uppercase; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button[aria-selected=true] { color: var(--fg); border-bottom-color: var(--cyan); }
.pane { overflow: auto; padding: 14px; display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: 16px; }
.pane > * { min-width: 0; }
.sec-h { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 0 0 8px; font: 500 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.sec-h em { font-style: normal; text-transform: none; letter-spacing: 0; color: var(--dim); }
.readout { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 14px; font: 12.5px var(--mono); font-variant-numeric: tabular-nums; background: var(--canvas); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; }
.readout span { color: var(--muted); }
.readout b { font-weight: 500; text-align: right; word-break: break-word; }
.vec { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.vec div { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r); padding: 6px 8px; font: 12px var(--mono); }
.vec div span { display: block; font-size: 10.5px; color: var(--muted); }
.vec div b { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.callout { font-size: 12.5px; padding: 8px 10px; border-radius: var(--r); border: 1px solid; }
.callout.warn { border-color: rgba(241,178,74,.45); background: var(--amber-soft); color: #f6d9a3; }
.callout.ok { border-color: rgba(61,220,151,.4); background: rgba(61,220,151,.1); color: #bdf1d8; }

.field { display: grid; gap: 4px; }
.field > span { display: flex; justify-content: space-between; font: 500 10.5px var(--mono); letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.field > span output { color: var(--fg); letter-spacing: 0; }
.cons { display: grid; gap: 8px; }
.con { border: 1px solid var(--line); border-left: 3px solid var(--c, var(--line-2)); border-radius: var(--r); background: var(--panel-2); padding: 8px 10px; display: grid; gap: 6px; }
.con.off { opacity: .55; }
.con-top { display: flex; align-items: center; gap: 8px; }
.con-top input[type=text] { flex: 1; min-width: 0; background: transparent; border: 0; border-bottom: 1px dashed var(--line-2); padding: 2px 0; font-size: 13px; }
.con-eq { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto minmax(0, 1fr); gap: 4px; align-items: center; font: 12px var(--mono); }
.con-eq input { width: 100%; min-height: 26px; padding: 2px 5px; font: 12px var(--mono); }
.con-eq em { font-style: normal; color: var(--muted); text-align: center; }
.con-meta { font: 11px var(--mono); color: var(--muted); }
.con-meta.viol { color: var(--red); }
.chk { display: inline-flex; gap: 8px; align-items: center; font-size: 13px; cursor: pointer; }
.chk input { accent-color: var(--cyan); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.prose { font-size: 13.5px; color: #c5c0dc; }
.prose p { margin: 0 0 10px; }
.prose h3 { font: 600 17px var(--display); color: var(--fg); margin: 6px 0 6px; }
.prose code { font: 12px var(--mono); color: #b9d7dc; }

@media (max-width: 960px) {
  html, body { height: auto; }
  .app { height: auto; }
  .work { grid-template-columns: minmax(0, 1fr); }
  .stage { height: 60vh; min-height: 380px; }
  .pane { overflow: visible; }
}
@media (max-width: 560px) {
  h1 { font-size: 22px; }
  .stage-note { display: none; }
  .cam-hint { display: none; }
  .tele { grid-template-columns: minmax(0, 1fr); }
  .coef { display: none; }
}
.pg-embedded .top > div:first-child { display: none; }
.pg-embedded .top { justify-content: flex-start; }
@media (prefers-reduced-motion: reduce) { .btn { transition: none; } }
