:root {
  --bg-dark: #070b14;
  --bg-panel: #0f1626;
  --bg-card: #141e33;
  --bg-hud: rgba(12, 19, 34, 0.84);
  --border-subtle: rgba(148, 163, 184, 0.16);
  --border-active: rgba(56, 189, 248, 0.55);
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent-cyan: #38bdf8;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-coral: #f43f5e;
  --accent-purple: #a855f7;
  --accent-yellow: #facc15;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

html, body {
  width: 100%;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

/* Top Navigation & Toolbar */
.topbar {
  height: 54px;
  background: linear-gradient(90deg, #0b1120 0%, #111a2e 100%);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
}

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

.brand-badge {
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: #fff;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 11px;
  padding: 5px 8px;
  border-radius: 6px;
  letter-spacing: 0.04em;
  box-shadow: 0 2px 10px rgba(14, 165, 233, 0.35);
}

.brand h1 {
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #f8fafc;
}

.brand .subtitle {
  font-size: 11px;
  color: var(--text-muted);
}

.camera-toolbar,
.layer-toolbar {
  display: flex;
  align-items: center;
  gap: 5px;
}

.toolbar-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.btn-chip,
.btn-toggle {
  background: rgba(30, 41, 59, 0.75);
  color: #cbd5e1;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-chip:hover,
.btn-toggle:hover {
  background: rgba(51, 65, 85, 0.85);
  color: #fff;
}

.btn-chip.active {
  background: rgba(14, 165, 233, 0.22);
  border-color: var(--accent-cyan);
  color: #38bdf8;
  font-weight: 600;
}

.btn-toggle.active {
  background: rgba(16, 185, 129, 0.18);
  border-color: rgba(16, 185, 129, 0.6);
  color: #34d399;
}

/* Main Workspace Layout */
.workspace {
  display: grid;
  grid-template-columns: 1fr 540px;
  height: calc(100vh - 54px);
  gap: 10px;
  padding: 10px;
}

/* Left Column: 3D Viewport + Scrubber */
.viewport-column {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  height: 100%;
}

.viewport-container {
  position: relative;
  flex: 1;
  background: radial-gradient(circle at 50% 35%, #162238 0%, #090e1a 80%);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  overflow: hidden;
  min-height: 0;
}

#three-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* HUD Overlays inside 3D Viewport */
.hud-card {
  position: absolute;
  background: var(--bg-hud);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 10px 12px;
  pointer-events: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.hud-phase-card {
  top: 12px;
  left: 12px;
  max-width: 470px;
}

.hud-phase-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.p-badge {
  background: linear-gradient(135deg, #38bdf8, #2563eb);
  color: #fff;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15px;
  padding: 4px 10px;
  border-radius: 6px;
  min-width: 48px;
  text-align: center;
}

.hud-phase-title {
  font-weight: 700;
  font-size: 13.5px;
  color: #f8fafc;
}

.hud-phase-group {
  font-size: 11px;
  color: #38bdf8;
  font-weight: 500;
}

.hud-time-readout {
  margin-left: auto;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: #e2e8f0;
}

.hud-time-readout small {
  display: block;
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
}

.hud-phase-desc {
  font-size: 11.5px;
  line-height: 1.42;
  color: #cbd5e1;
  margin-bottom: 8px;
}

.hud-sequence-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.seq-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(148, 163, 184, 0.2);
  padding: 3px 7px;
  border-radius: 5px;
  font-size: 10.5px;
  color: #cbd5e1;
  transition: all 0.15s ease;
}

.seq-pill.peak-active {
  border-color: #f8fafc;
  background: rgba(56, 189, 248, 0.18);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.35);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}
.dot-purple { background: #a855f7; box-shadow: 0 0 6px #a855f7; }
.dot-yellow { background: #facc15; box-shadow: 0 0 6px #facc15; }
.dot-blue { background: #38bdf8; box-shadow: 0 0 6px #38bdf8; }

/* Top-Right HUD: Speeds */
.hud-speeds-card {
  top: 12px;
  right: 12px;
  width: 280px;
}

.hud-card-title {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.speed-row {
  display: grid;
  grid-template-columns: 88px 68px 1fr;
  align-items: center;
  padding: 3px 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
  font-size: 11px;
}
.speed-row:last-child {
  border-bottom: none;
}

.speed-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  display: inline-block;
}
.swatch-pelvis { background: #10b981; }
.swatch-thorax { background: #38bdf8; }
.swatch-arm { background: #f59e0b; }
.swatch-club { background: #f43f5e; }

.speed-val {
  font-family: var(--font-mono);
  font-weight: 700;
  color: #f8fafc;
  text-align: right;
  padding-right: 8px;
}

.speed-peak {
  font-size: 9.8px;
  color: var(--text-muted);
  text-align: right;
}

/* Bottom-Left Legend */
.hud-legend-card {
  bottom: 12px;
  left: 12px;
  display: flex;
  gap: 12px;
  padding: 7px 12px;
  font-size: 11px;
  color: #cbd5e1;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.line-swatch {
  width: 12px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
}

/* Timeline & P1-P9 Keyframe Controls */
.timeline-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.btn-primary {
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 14px;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 82px;
  justify-content: center;
}

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

.btn-icon {
  background: var(--bg-card);
  color: #e2e8f0;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 11px;
  cursor: pointer;
}

.btn-icon:hover {
  border-color: var(--accent-cyan);
}

.speed-select-group {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.speed-select-group select {
  background: var(--bg-card);
  color: #f1f5f9;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11.5px;
}

.window-badges {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.win-badge {
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid var(--border-subtle);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 11px;
  color: #cbd5e1;
}

.win-badge.highlight {
  border-color: rgba(244, 63, 94, 0.45);
  background: rgba(244, 63, 94, 0.12);
  color: #fda4af;
}

.scrubber-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent-cyan);
  cursor: pointer;
  height: 6px;
}

.p-buttons-row {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 5px;
}

.p-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 5px 4px;
  color: #cbd5e1;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: all 0.14s ease;
}

.p-btn strong {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: #f8fafc;
}

.p-btn span {
  font-size: 9.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.p-btn:hover {
  border-color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.12);
}

.p-btn.active {
  background: linear-gradient(180deg, rgba(14, 165, 233, 0.28), rgba(37, 99, 235, 0.22));
  border-color: var(--accent-cyan);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.25);
}

/* Right Column: Graphs & Telemetry */
.telemetry-column {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  overflow-y: auto;
  padding-right: 2px;
}

.panel-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 9px;
  padding: 9px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-header h2 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #e2e8f0;
}

.panel-tag {
  font-size: 10.5px;
  color: var(--accent-cyan);
  font-family: var(--font-mono);
}

.chart-wrap {
  width: 100%;
  background: #0a0f1d;
  border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: 6px;
  overflow: hidden;
}

.chart-wrap canvas {
  width: 100%;
  height: auto;
  display: block;
  cursor: ew-resize;
}

/* Telemetry Grid + CoP Pad */
.telemetry-split {
  display: grid;
  grid-template-columns: 1fr 155px;
  gap: 8px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;
}

.metric-box {
  background: var(--bg-card);
  border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: 6px;
  padding: 5px 8px;
}

.metric-label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
}

.metric-val {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: #38bdf8;
  margin: 1px 0;
}

.metric-target {
  font-size: 9.5px;
  color: #64748b;
}

.cop-box {
  background: #0a0f1d;
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 6px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
}

.cop-title {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
}

#cop-canvas {
  border-radius: 4px;
  background: #070b14;
}

.weight-bars {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 10px;
}

.w-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.w-bar {
  height: 5px;
  background: #1e293b;
  border-radius: 3px;
  overflow: hidden;
}

.w-fill.lead {
  height: 100%;
  background: #38bdf8;
}

.w-fill.trail {
  height: 100%;
  background: #a855f7;
}

/* Curve Tuning Sliders */
.sliders-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 12px;
}

.slider-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.slider-item.full-width {
  grid-column: span 2;
}

.slider-item label {
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  color: #cbd5e1;
}

.slider-item label span {
  font-family: var(--font-mono);
  color: var(--accent-cyan);
  font-weight: 600;
}

.slider-item input[type="range"] {
  width: 100%;
  accent-color: var(--accent-emerald);
  height: 5px;
  cursor: pointer;
}

.btn-mini {
  background: var(--bg-card);
  color: #cbd5e1;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 10.5px;
  cursor: pointer;
}

.btn-mini:hover {
  border-color: var(--accent-cyan);
  color: #fff;
}
