:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  background: #050a11;
  color: #edf4ff;
  --panel: rgba(10, 20, 34, 0.94);
  --line: rgba(173, 199, 229, 0.16);
  --muted: #8ea2b9;
  --accent: #4fd4ff;
  --orange: #ff7b36;
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; height: 100%; margin: 0; overflow: hidden; }
button, input { font: inherit; }

#app { display: grid; grid-template-columns: minmax(0, 1fr) 340px; }
#viewport { position: relative; min-width: 0; overflow: hidden; background: radial-gradient(circle at 50% 42%, #14243a 0, #08111d 45%, #03070c 100%); }
#scene { display: block; width: 100%; height: 100%; touch-action: none; }

.brand { position: absolute; top: 28px; left: 32px; pointer-events: none; text-shadow: 0 2px 18px #000; }
.brand h1 { margin: 4px 0 2px; font-size: clamp(24px, 2.4vw, 38px); letter-spacing: -0.04em; }
.brand p { margin: 0; color: #b7c7d9; }
.eyebrow { color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: 0.15em; }

#loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; background: rgba(3, 8, 14, 0.78); backdrop-filter: blur(8px); z-index: 5; transition: opacity 0.3s; }
#loading.done { opacity: 0; pointer-events: none; }
.spinner { width: 42px; height: 42px; border: 3px solid rgba(255,255,255,.14); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#hover-readout { position: absolute; left: 32px; bottom: 62px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; background: rgba(5, 13, 23, 0.78); color: #c6d6e7; font-size: 12px; pointer-events: none; }
.hint { position: absolute; left: 32px; bottom: 22px; color: #8ca0b8; font-size: 12px; }
kbd { padding: 2px 6px; border: 1px solid #52677e; border-bottom-width: 2px; border-radius: 4px; background: #142033; color: #eaf4ff; }

.legend { position: absolute; right: 24px; top: 50%; transform: translateY(-50%); display: grid; justify-items: center; gap: 7px; color: #dfeafa; font-size: 11px; }
.colorbar { width: 13px; height: min(42vh, 320px); border-radius: 8px; border: 1px solid rgba(255,255,255,.22); background: linear-gradient(to top, #0a0723, #57106e, #bb3754, #f98e09, #fcffa4); box-shadow: 0 4px 24px #000; }

#panel { overflow-y: auto; padding: 26px 24px; background: var(--panel); border-left: 1px solid var(--line); box-shadow: -12px 0 40px rgba(0,0,0,.24); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.panel-heading h2 { margin: 4px 0 0; font-size: 25px; }
.badge { margin-top: 3px; padding: 5px 9px; border-radius: 999px; background: rgba(79,212,255,.12); color: var(--accent); border: 1px solid rgba(79,212,255,.28); font-size: 11px; }

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 22px 0; }
.metrics div { padding: 11px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.025); }
.metrics span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; }
.metrics strong { font-size: 15px; }

.toggle-row { position: relative; display: flex; align-items: center; justify-content: space-between; margin: 18px 0; cursor: pointer; }
.toggle-row input { position: absolute; opacity: 0; }
.switch { width: 43px; height: 23px; border-radius: 999px; background: #2a394b; transition: .2s; }
.switch::after { content: ""; display: block; width: 17px; height: 17px; margin: 3px; border-radius: 50%; background: white; transition: .2s; }
.toggle-row input:checked + .switch { background: var(--orange); }
.toggle-row input:checked + .switch::after { transform: translateX(20px); }

.control { display: block; margin: 19px 0; }
.control > span { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 7px; font-size: 13px; }
.control output { color: var(--muted); font-variant-numeric: tabular-nums; }
.control input[type="range"] { width: 100%; accent-color: var(--orange); }
.control.compact { margin: 12px 0; }
details { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 12px 0; }
summary { color: #c7d5e5; cursor: pointer; font-size: 13px; }

.axis-panel { margin: 20px 0; padding: 14px; border: 1px solid rgba(79,212,255,.22); border-radius: 11px; background: rgba(79,212,255,.035); }
.axis-title { display: grid; gap: 3px; margin-bottom: 13px; }
.axis-title b { font-size: 13px; }
.axis-title small { color: var(--muted); font-size: 10px; }
.axis-control + .axis-control { margin-top: 12px; }
.axis-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 5px; }
.axis-heading > b { width: 18px; color: var(--accent); font-size: 13px; }
.axis-number-group { display: grid; grid-template-columns: 28px 1fr 28px; gap: 5px; width: 190px; }
.axis-number-group input { min-width: 0; width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; color: #e9f4ff; background: #0b1726; text-align: center; font: 11px ui-monospace, SFMono-Regular, Consolas, monospace; }
.axis-nudge { padding: 2px 0; border-radius: 6px; color: var(--accent); background: #13263a; font-weight: 800; }
.axis-control > input[type="range"] { width: 100%; accent-color: var(--accent); }

.buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 24px 0 18px; }
button { border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; color: #e9f2fc; background: #17263a; cursor: pointer; }
button:hover { border-color: #56718f; background: #1c3048; }
button.primary { color: #06121b; background: var(--accent); border-color: transparent; font-weight: 700; }

.physics { padding: 12px; border-radius: 9px; background: rgba(0,0,0,.22); color: #91a6bd; font: 11px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-line; }
#error { padding: 10px; border: 1px solid #a83c47; border-radius: 8px; color: #ffb7bd; background: rgba(123,25,36,.25); font-size: 12px; }

@media (max-width: 800px) {
  #app { grid-template-columns: 1fr; grid-template-rows: minmax(52vh, 1fr) auto; overflow-y: auto; }
  html, body, #app { overflow: auto; }
  #panel { overflow: visible; border-left: 0; border-top: 1px solid var(--line); }
  .brand { top: 18px; left: 18px; }
  .hint, #hover-readout { left: 18px; }
  .legend { right: 12px; }
}
