/* Same palette and type as the main site */
:root {
  --bg: #0d0d0c;
  --bg-2: #161614;
  --ink: #ecebe6;
  --muted: #8b8a84;
  --line: rgba(236, 235, 230, 0.14);
  --accent: #ff5b1f;
  --cool: #5aa0e6;
  --pad: clamp(16px, 3vw, 32px);
  --panel: 380px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --sans: "Inter Tight", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Instrument Serif", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

h1, h2, p { margin: 0; }
a { color: inherit; }

.mono { font-family: var(--mono); font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; }
.small { color: var(--muted); font-size: 13px; line-height: 1.55; }

#scene {
  position: fixed;
  inset: 0 var(--panel) 0 0;
  width: calc(100% - var(--panel));
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#scene:active { cursor: grabbing; }
#scene.pointing { cursor: pointer; }

.loading {
  position: fixed;
  top: 50%;
  left: calc((100% - var(--panel)) / 2);
  color: var(--muted);
  transform: translate(-50%, -50%);
}

/* ---------- Header ---------- */
.top {
  position: fixed;
  top: 0;
  left: 0;
  right: var(--panel);
  z-index: 5;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: var(--pad);
  pointer-events: none;
}
.top > * { pointer-events: auto; }

.back { position: absolute; top: var(--pad); left: var(--pad); color: var(--muted); text-decoration: none; transition: color 0.3s; }
.back:hover { color: var(--ink); }

.title { margin-top: 36px; text-shadow: 0 2px 24px rgba(13, 13, 12, 0.9); pointer-events: none; }
.kicker { color: var(--muted); margin-bottom: 8px; }
.title h1 { font-size: clamp(36px, 5vw, 64px); font-weight: 500; line-height: 0.95; letter-spacing: -0.04em; transition: font-size 0.6s var(--ease); }
.in-tunnel .title h1 { font-size: clamp(26px, 2.6vw, 34px); }
.title em { font-style: normal; font-weight: 400; color: var(--accent); }

/* ---------- Bottom dock: switch views ---------- */
.dock {
  position: fixed;
  left: calc((100% - var(--panel)) / 2);
  bottom: 24px;
  z-index: 7;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(20, 20, 19, 0.88);
  backdrop-filter: blur(12px);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
  transform: translateX(-50%);
}
.dock-back {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--muted);
  font-size: 18px;
  text-decoration: none;
  transition: color 0.3s, background 0.3s;
}
.dock-back:hover { color: var(--ink); background: var(--bg-2); }
.dock-modes { display: flex; gap: 4px; padding: 3px; border-radius: 999px; background: var(--bg); }
.dock-modes button {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 20px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font: 500 15px var(--sans);
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.35s var(--ease), color 0.35s;
}
.dock-modes button:hover { color: var(--ink); }
.dock-modes button[aria-selected="true"] { background: var(--ink); color: var(--bg); }
.dock-modes svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.dock-action {
  padding: 11px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  color: var(--ink);
  font: 500 14px var(--sans);
  cursor: pointer;
  transition: border-color 0.3s;
}
.dock-action:hover { border-color: var(--ink); }

/* "Click me!" tag on the Parts button until it's been tried once */
.click-me {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 12px);
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--bg);
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-50%);
  animation: nudge 1.6s var(--ease) infinite;
}
.click-me::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  border: 6px solid transparent;
  border-top-color: var(--accent);
  transform: translateX(-50%);
}
@keyframes nudge {
  0%, 100% { transform: translate(-50%, 0); }
  50% { transform: translate(-50%, -6px); }
}
.dock-modes button[aria-selected="true"] .click-me { display: none; }

/* ---------- Side panel ---------- */
.panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 22px;
  width: var(--panel);
  padding: 28px 26px;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: #121211;
  scrollbar-width: thin;
}

.specs { display: grid; grid-template-columns: repeat(4, auto); justify-content: space-between; margin: 0; padding: 0 0 20px; list-style: none; color: var(--muted); border-bottom: 1px solid var(--line); }
.specs b { display: block; margin-bottom: 2px; color: var(--ink); font: 500 20px var(--sans); letter-spacing: -0.02em; text-transform: none; }

.view { display: flex; flex-direction: column; gap: 24px; }
.view[hidden] { display: none; }
.hint { color: var(--muted); font-size: 14px; }

.group { display: grid; gap: 14px; padding-top: 20px; border-top: 1px solid var(--line); }
.group-title { color: var(--accent); font-weight: 500; }
.row { display: flex; gap: 10px; }

/* Parts list */
.part-list { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.part-list button {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: baseline;
  width: 100%;
  padding: 12px 4px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  color: var(--ink);
  font: 500 15px var(--sans);
  text-align: left;
  cursor: pointer;
  transition: color 0.25s, padding 0.4s var(--ease);
}
.part-list .num, .part-list .size { color: var(--muted); }
.part-list button:hover,
.part-list button.active { color: var(--accent); padding-left: 12px; }
.part-list button.active .num { color: var(--accent); }

.detail { padding: 14px 16px; border-left: 2px solid var(--accent); background: var(--bg-2); }
.detail-size { margin-bottom: 6px; color: var(--accent); }
.detail-about { font-size: 14px; }

.btn {
  align-self: flex-start;
  padding: 12px 22px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font: 500 14px var(--sans);
  cursor: pointer;
  transition: background 0.3s, border-color 0.3s, color 0.3s;
}
.btn:hover { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.btn.ghost { padding: 9px 16px; border-color: var(--line); background: none; color: var(--ink); font-size: 13px; }
.btn.ghost:hover { border-color: var(--ink); background: none; color: var(--ink); }

/* Tunnel controls */
.slider { display: grid; gap: 10px; font-size: 14px; }
.slider span { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); }
.slider output { color: var(--ink); font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.slider input { width: 100%; accent-color: var(--accent); }

.roll { display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: end; }
.compass {
  position: relative;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 50%;
}
.compass::before { content: ""; position: absolute; inset: 6px; border-radius: 50%; border: 1px dashed var(--line); }
.compass-needle {
  position: absolute;
  left: 50%;
  top: 4px;
  width: 2px;
  height: 16px;
  margin-left: -1px;
  border-radius: 2px;
  background: var(--accent);
  transform-origin: 50% 16px;
  transition: transform 0.2s;
}

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); padding: 3px; border: 1px solid var(--line); border-radius: 999px; }
.segmented button {
  padding: 8px 6px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font: 500 13px var(--sans);
  cursor: pointer;
  transition: background 0.3s var(--ease), color 0.3s;
}
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

.colorbar { display: grid; gap: 6px; }
.colorbar-title { color: var(--muted); }
.colorbar canvas { width: 100%; height: 10px; border-radius: 999px; image-rendering: auto; }
.colorbar-ticks { display: flex; justify-content: space-between; color: var(--ink); }

.toggles { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.chart { position: relative; height: 92px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.chart canvas { width: 100%; height: 100%; display: block; }
.chart-key { position: absolute; top: 8px; left: 10px; display: flex; gap: 14px; color: var(--muted); }
.chart-key b { color: var(--ink); font-weight: 500; }
.key-drag::before, .key-lift::before { content: ""; display: inline-block; width: 10px; height: 2px; margin-right: 6px; vertical-align: middle; }
.key-drag::before { background: var(--accent); }
.key-lift::before { background: var(--cool); }

.readouts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; }
.readouts div { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.readouts dt { margin-bottom: 4px; color: var(--muted); font-size: 10px; }
.readouts dd { margin: 0; font-size: 16px; font-weight: 500; letter-spacing: -0.02em; }

.cp-value { font-size: 22px; font-weight: 500; letter-spacing: -0.02em; }
.cp-value span { color: var(--muted); font-size: 14px; font-weight: 400; letter-spacing: 0; }
.cg { display: grid; gap: 12px; }
.cg[hidden] { display: none; }
.stability { font-size: 16px; font-weight: 500; }
.stability.good { color: #7fd99a; }
.stability.warn { color: var(--accent); }


/* ---------- Callouts over the 3D view ---------- */
.leaders { position: fixed; inset: 0; z-index: 3; width: 100%; height: 100%; pointer-events: none; opacity: 0; transition: opacity 0.25s; }
.leaders.on { opacity: 1; }
.leader { fill: none; stroke: var(--accent); stroke-width: 1.2; }
.leader-dot { fill: var(--accent); }

.callout {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 4;
  display: grid;
  gap: 4px;
  width: 250px;
  padding: 14px 16px;
  border: 1px solid rgba(255, 91, 31, 0.45);
  border-radius: 12px;
  background: rgba(18, 18, 17, 0.88);
  backdrop-filter: blur(10px);
  pointer-events: none;
  animation: pop 0.3s var(--ease);
}
.callout[hidden] { display: none; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }
.callout-num { color: var(--accent); }
.callout-name { font-size: 18px; font-weight: 500; letter-spacing: -0.02em; }
.callout-size { color: var(--muted); }
.callout-about { margin-top: 4px; color: var(--muted); font-size: 13px; line-height: 1.5; }

.badges { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
.badge {
  position: absolute;
  top: 0;
  left: 0;
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(18, 18, 17, 0.85);
  color: var(--ink);
}
.badge[hidden] { display: none; }

.ring-label {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 4;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--bg);
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
}
.ring-label[data-ring="cg"] { background: var(--ink); }
.ring-label[hidden] { display: none; }

/* ---------- Phones and small tablets ---------- */
@media (max-width: 860px) {
  :root { --panel: 0px; }
  body { overflow: auto; }
  #scene { position: fixed; inset: 0 0 auto 0; width: 100%; height: 58svh; }
  .loading { left: 50%; top: 29svh; }
  .top { right: 0; padding: 16px; }
  .title { margin-top: 30px; }
  .title h1 { font-size: 34px; }
  .in-tunnel .title h1 { font-size: 22px; }
  .in-tunnel .kicker { display: none; }
  .dock { left: 50%; top: calc(58svh - 70px); bottom: auto; gap: 4px; padding: 4px; }
  .dock-back { width: 38px; height: 38px; }
  .dock-modes button { padding: 9px 13px; font-size: 14px; }
  .dock-action { padding: 9px 12px; font-size: 13px; }
  .panel {
    position: relative;
    top: 58svh;
    width: 100%;
    min-height: 42svh;
    overflow: visible;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
  .callout, .leaders, .badges { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  .part-list button, .dock-modes button, .btn, .segmented button, .callout, .click-me { transition: none; animation: none; }
}
