:root {
  --bg: #070b12;
  --panel: #101725;
  --panel-alt: #162033;
  --border: rgba(148, 163, 184, 0.16);
  --border-hi: rgba(148, 163, 184, 0.32);
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --text-muted: #64748b;
  --cyan: #38bdf8;
  --orange: #f97316;
  --gold: #fbbf24;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 7px;
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.app-3d {
  min-height: 100vh;
  max-width: 1560px;
  margin: 0 auto;
  padding: 10px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ===== Top Header ===== */
.topbar-3d {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: linear-gradient(180deg, rgba(22, 32, 51, 0.94), rgba(14, 21, 36, 0.94));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.35);
  flex-wrap: wrap;
}

.brand-3d {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-badge {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  color: #fff;
  background: linear-gradient(135deg, #0284c7, #f97316);
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.35);
  flex-shrink: 0;
}

.brand-3d h1 {
  font-size: 1.02rem;
  font-weight: 700;
  color: #f8fafc;
}

.brand-3d .sub {
  font-size: 0.68rem;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  margin-top: 2px;
}

.top-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.seg-group {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  background: rgba(7, 11, 18, 0.85);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.seg-btn {
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s ease;
}

.seg-btn:hover {
  color: var(--text);
}

.seg-btn.active {
  background: rgba(56, 189, 248, 0.2);
  border-color: rgba(56, 189, 248, 0.5);
  color: #f0f9ff;
}

.pill-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
  font-size: 0.76rem;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  transition: all 0.16s ease;
}

.pill-toggle input {
  display: none;
}

.pill-toggle .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #475569;
}

.pill-toggle:has(input:checked) {
  background: rgba(249, 115, 22, 0.16);
  border-color: rgba(249, 115, 22, 0.5);
  color: #ffedd5;
}

.pill-toggle:has(input:checked) .dot {
  background: #fb923c;
  box-shadow: 0 0 8px rgba(251, 146, 60, 0.9);
}

.nav-link-2d {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid var(--border-hi);
  color: #e2e8f0;
  font-size: 0.76rem;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.16s ease;
}

.nav-link-2d:hover {
  background: rgba(56, 189, 248, 0.18);
  border-color: var(--cyan);
  color: #fff;
}

/* ===== Main Workspace ===== */
.workspace-3d {
  display: grid;
  grid-template-columns: minmax(0, 1.42fr) minmax(365px, 0.78fr);
  gap: 12px;
  flex: 1;
  min-height: 0;
}

/* ===== 3D Viewport Stage ===== */
.viewport-wrap {
  position: relative;
  min-height: 620px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  background: radial-gradient(circle at 50% 42%, #182438 0%, #090e18 68%, #05080f 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 16px 38px rgba(0, 0, 0, 0.45);
}

#webglCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#webglCanvas:active {
  cursor: grabbing;
}

/* Top-Left Telemetry HUD */
.hud-3d {
  position: absolute;
  top: 12px;
  left: 12px;
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 4px 16px;
  padding: 7px 13px;
  border-radius: var(--radius-md);
  background: rgba(8, 12, 20, 0.78);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  pointer-events: none;
}

.hud-cell {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.hud-cell .lbl {
  font-size: 0.64rem;
  color: var(--text-muted);
}

.hud-cell .val {
  font-size: 0.88rem;
  font-weight: 700;
  color: #f8fafc;
}

.hud-cell .val small {
  font-size: 0.68rem;
  color: var(--text-dim);
  font-weight: 500;
}

.hud-cell .accent-gold {
  color: var(--gold);
}

/* Top-Right Camera Presets */
.camera-presets {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.cam-btn {
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(8, 12, 20, 0.76);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  text-align: right;
  transition: all 0.16s ease;
}

.cam-btn:hover {
  border-color: var(--border-hi);
  color: #fff;
}

.cam-btn.active {
  background: rgba(56, 189, 248, 0.2);
  border-color: var(--cyan);
  color: #e0f2fe;
}

/* Bottom-Left I4 Firing Strip */
.i4-hud-strip {
  position: absolute;
  left: 12px;
  bottom: 38px;
  width: min(460px, calc(100% - 24px));
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: rgba(8, 12, 20, 0.8);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.i4-hud-strip[hidden] {
  display: none;
}

.i4-hud-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.69rem;
}

.i4-hud-header .title {
  font-weight: 700;
  color: #e2e8f0;
}

.i4-hud-header .crank-tag {
  color: var(--text-muted);
  font-size: 0.66rem;
}

.i4-hud-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.i4-mini-card {
  position: relative;
  padding: 5px 7px;
  border-radius: 7px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
  color: var(--text-dim);
  text-align: left;
  cursor: pointer;
  transition: all 0.14s ease;
}

.i4-mini-card:hover {
  border-color: var(--border-hi);
}

.i4-mini-card.focused {
  border-color: var(--cyan);
  background: rgba(14, 165, 233, 0.16);
}

.i4-mini-card.firing {
  border-color: var(--orange);
  box-shadow: 0 0 12px rgba(249, 115, 22, 0.45);
}

.i4-mini-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  font-weight: 700;
  color: #f8fafc;
}

.i4-mini-stroke {
  font-size: 0.72rem;
  font-weight: 700;
  margin-top: 2px;
  color: var(--c, #38bdf8);
}

/* Tooltip & Orbit Hint */
.tooltip-3d {
  position: absolute;
  pointer-events: none;
  z-index: 20;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(56, 189, 248, 0.55);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5);
  font-size: 0.76rem;
  color: #f8fafc;
  white-space: nowrap;
  transform: translate(14px, -50%);
}

.tooltip-3d .sub {
  display: block;
  font-size: 0.67rem;
  color: var(--text-dim);
  margin-top: 1px;
}

.orbit-hint {
  position: absolute;
  bottom: 9px;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(8, 12, 20, 0.76);
  border: 1px solid rgba(148, 163, 184, 0.14);
  font-size: 0.7rem;
  color: var(--text-dim);
  white-space: nowrap;
  pointer-events: none;
}

/* ===== Right Inspector Panel ===== */
.side-panel-3d {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.card-3d {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.card-grow {
  flex: 1;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.eyebrow {
  font-size: 0.63rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 1px;
}

.card-head h2 {
  font-size: 0.96rem;
  font-weight: 700;
  color: #f8fafc;
}

.card-head h2 .en {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-dim);
  margin-left: 4px;
}

.pill-badge {
  font-size: 0.71rem;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.32);
  color: #7dd3fc;
  white-space: nowrap;
}

.btn-play {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px;
  border-radius: 8px;
  border: 1px solid rgba(56, 189, 248, 0.5);
  background: linear-gradient(180deg, #0284c7, #0369a1);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-play:hover {
  filter: brightness(1.1);
}

/* Sliders */
.slider-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.slider-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.74rem;
  color: var(--text-dim);
}

.val-accent {
  color: #fb923c;
  font-weight: 700;
}

.angle-step-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
}

.mini-btn {
  padding: 4px 7px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 0.72rem;
  cursor: pointer;
}

.mini-btn:hover {
  border-color: var(--border-hi);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: #1e293b;
  border: 1px solid var(--border);
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #f8fafc;
  border: 2px solid var(--cyan);
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.7);
}

#explodeSlider::-webkit-slider-thumb {
  border-color: var(--orange);
  box-shadow: 0 0 8px rgba(249, 115, 22, 0.75);
}

.desc-text {
  font-size: 0.79rem;
  line-height: 1.48;
  color: #cbd5e1;
}

.mini-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.mf {
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mf .k {
  font-size: 0.64rem;
  color: var(--text-muted);
}

.mf .v {
  font-size: 0.74rem;
  font-weight: 600;
  color: #e2e8f0;
}

/* Chips & Detail */
.chips-3d {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chip-3d {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
  color: #cbd5e1;
  font-size: 0.73rem;
  cursor: pointer;
  transition: all 0.14s ease;
}

.chip-3d:hover {
  border-color: var(--border-hi);
  color: #fff;
}

.chip-3d.active {
  background: rgba(56, 189, 248, 0.16);
  border-color: var(--cc, #38bdf8);
  color: #fff;
  font-weight: 600;
}

.chip-3d .cdot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cc, #38bdf8);
}

.part-detail-3d {
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.92), rgba(10, 15, 26, 0.98));
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex: 1;
}

.pd-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.pd-title-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.pd-title-row h3 {
  font-size: 0.96rem;
  font-weight: 700;
}

.sys-tag {
  font-size: 0.66rem;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.14);
  border: 1px solid rgba(148, 163, 184, 0.25);
  color: #cbd5e1;
}

.pd-en {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--border);
  font-size: 0.71rem;
  font-weight: 600;
}

.status-badge .sdot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan);
}

.pd-short {
  font-size: 0.8rem;
  line-height: 1.45;
  color: #e2e8f0;
  font-weight: 500;
  padding-left: 9px;
  border-left: 3px solid var(--cyan);
}

.pd-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.pd-list li {
  position: relative;
  padding-left: 12px;
  font-size: 0.75rem;
  line-height: 1.46;
  color: var(--text-dim);
}

.pd-list li::before {
  content: "•";
  position: absolute;
  left: 2px;
  color: var(--cyan);
  font-weight: 700;
}

.pd-mat {
  margin-top: auto;
  padding-top: 7px;
  border-top: 1px dashed var(--border);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.72rem;
}

.pd-mat .k {
  color: var(--text-muted);
}

.pd-mat .v {
  color: #cbd5e1;
  text-align: right;
  font-weight: 500;
}

/* ===== Responsive ===== */
@media (max-width: 1120px) {
  .workspace-3d {
    grid-template-columns: 1fr;
  }

  .viewport-wrap {
    min-height: 540px;
  }
}

@media (max-width: 720px) {
  .hud-3d {
    grid-template-columns: repeat(2, auto);
  }

  .camera-presets {
    display: none;
  }

  .orbit-hint {
    display: none;
  }
}
