:root {
  --bg: #060a11;
  --panel: #0e1624;
  --panel-alt: #142033;
  --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;
  --emerald: #34d399;
  --orange: #f97316;
  --gold: #fbbf24;
  --violet: #a78bfa;
  --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-motor {
  min-height: 100vh;
  max-width: 1560px;
  margin: 0 auto;
  padding: 10px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

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

.brand-badge-m {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 1.12rem;
  color: #fff;
  background: linear-gradient(135deg, #06b6d4, #10b981);
  box-shadow: 0 0 18px rgba(6, 182, 212, 0.42);
  flex-shrink: 0;
}

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

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

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

.seg-group {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  background: rgba(6, 10, 17, 0.88);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.seg-btn {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.75rem;
  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.52);
  color: #f0f9ff;
}

.seg-btn[data-drive="regen"].active {
  background: rgba(52, 211, 153, 0.2);
  border-color: rgba(52, 211, 153, 0.55);
  color: #d1fae5;
}

.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.75rem;
  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(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.48);
  color: #e0f2fe;
}

.pill-toggle:has(input:checked) .dot {
  background: #38bdf8;
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.9);
}

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

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

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

/* ===== 3D Viewport ===== */
.viewport-m {
  position: relative;
  min-height: 620px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  background: radial-gradient(circle at 50% 42%, #132538 0%, #070e18 68%, #04070d 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 16px 38px rgba(0, 0, 0, 0.48);
}

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

#motorCanvas:active {
  cursor: grabbing;
}

/* Top-Left Telemetry HUD */
.hud-m {
  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(7, 12, 20, 0.8);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  pointer-events: none;
}

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

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

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

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

.accent-gold { color: var(--gold) !important; }
.accent-cyan { color: var(--cyan) !important; }

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

.cam-btn {
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(7, 12, 20, 0.78);
  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 3-Phase Live Bar Meter */
.phase-meter-hud {
  position: absolute;
  left: 12px;
  bottom: 38px;
  width: min(320px, calc(100% - 24px));
  padding: 8px 11px;
  border-radius: var(--radius-md);
  background: rgba(7, 12, 20, 0.82);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.pm-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.68rem;
  color: var(--text-dim);
  font-weight: 600;
}

.pm-bars {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.pm-row {
  display: grid;
  grid-template-columns: 34px 1fr 52px;
  align-items: center;
  gap: 7px;
}

.pm-tag {
  font-size: 0.69rem;
  font-weight: 700;
}
.u-tag { color: #fb923c; }
.v-tag { color: #34d399; }
.w-tag { color: #60a5fa; }

.pm-track {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: rgba(30, 41, 59, 0.9);
  overflow: hidden;
}

.pm-zero {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(255, 255, 255, 0.32);
}

.pm-fill {
  position: absolute;
  top: 1px;
  bottom: 1px;
  border-radius: 999px;
}

.u-fill { background: linear-gradient(90deg, #f97316, #fb923c); }
.v-fill { background: linear-gradient(90deg, #10b981, #34d399); }
.w-fill { background: linear-gradient(90deg, #3b82f6, #60a5fa); }

.pm-val {
  font-size: 0.68rem;
  text-align: right;
  color: #cbd5e1;
}

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

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

.orbit-hint-m {
  position: absolute;
  bottom: 9px;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(7, 12, 20, 0.78);
  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-m {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

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

.card-grow {
  flex: 1;
}

.card-head-m {
  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-m h2 {
  font-size: 0.96rem;
  font-weight: 700;
  color: #f8fafc;
}

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

.badge-m {
  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.34);
  color: #7dd3fc;
  white-space: nowrap;
}

.btn-play-m {
  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, #0891b2, #0e7490);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

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

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

.slider-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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

.hi-orange {
  color: #fb923c;
  font-weight: 700;
}

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);
}

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

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

/* 3-Phase Oscilloscope */
.scope-box {
  background: rgba(6, 10, 17, 0.82);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 7px 9px 5px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.scope-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.68rem;
  color: var(--text-dim);
  font-weight: 600;
}

.scope-legend {
  display: inline-flex;
  gap: 8px;
}

.scope-legend i {
  font-style: normal;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.7rem;
}

.lg-u { color: #fb923c; }
.lg-v { color: #34d399; }
.lg-w { color: #60a5fa; }

.scope-box canvas {
  width: 100%;
  height: auto;
  display: block;
}

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

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

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

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

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

.part-detail-m {
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.92), rgba(9, 14, 24, 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-m {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

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

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

.sys-tag-m {
  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-m {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.status-pill-m {
  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-pill-m .sdot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan);
}

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

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

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

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

.pd-mat-m {
  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-m .k {
  color: var(--text-muted);
}

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

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

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

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

  .cam-presets-m,
  .orbit-hint-m {
    display: none;
  }
}
