/* Custom Design System & CSS resets */
:root {
  --bg-primary: #080a0f;
  --bg-panel: rgba(18, 22, 33, 0.65);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-color-focus: rgba(28, 150, 232, 0.4);
  
  /* Text colors */
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  
  /* BMW M Power Inspired Colors */
  --m-blue: #008cdb;
  --m-darkblue: #002c77;
  --m-red: #e7222e;
  
  /* System / Component colors */
  --color-engine: #f59e0b; /* Orange */
  --color-clutch: #10b981; /* Green */
  --color-trans: #3b82f6;  /* Blue */
  --color-driveshaft: #8b5cf6; /* Purple */
  --color-diff: #ec4899;   /* Pink */
  --color-wheel: #6366f1;  /* Indigo */
  
  --font-sans: 'Outfit', sans-serif;
  --font-mono: 'Roboto Mono', monospace;
  
  --shadow-main: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* Glassmorphism Background Graphic */
.glass-bg {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -1;
  background: 
    radial-gradient(circle at 10% 20%, rgba(0, 140, 219, 0.1) 0%, transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(231, 34, 46, 0.08) 0%, transparent 45%),
    linear-gradient(135deg, #090c13 0%, #040508 100%);
  background-attachment: fixed;
}

/* App Container Layout */
.app-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  padding: 20px;
  gap: 20px;
}

/* Header styling */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  background: var(--bg-panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: var(--shadow-main);
}

.logo-area {
  display: flex;
  flex-direction: column;
}

.bmw-colors {
  display: flex;
  height: 4px;
  width: 60px;
  margin-bottom: 6px;
  border-radius: 2px;
  overflow: hidden;
}

.bmw-colors span {
  flex: 1;
}
.color-blue { background-color: var(--m-blue); }
.color-darkblue { background-color: var(--m-darkblue); }
.color-red { background-color: var(--m-red); }

.app-header h1 {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: 1px;
  background: linear-gradient(to right, #ffffff, #d1d5db);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* STATUS LED */
.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.3);
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
}

.status-indicator .dot {
  width: 8px;
  height: 8px;
  background-color: #ef4444; /* red when off */
  border-radius: 50%;
  box-shadow: 0 0 8px #ef4444;
  transition: all 0.3s ease;
}

.status-indicator.active .dot {
  background-color: #10b981; /* green when on */
  box-shadow: 0 0 10px #10b981;
}

.status-text {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* BUTTONS */
.btn {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  letter-spacing: 0.5px;
}

.btn-ignition {
  background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
  color: white;
  box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.btn-ignition:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.45);
}

.btn-ignition:active {
  transform: translateY(1px);
}

.btn-ignition.running {
  background: linear-gradient(135deg, #10b981 0%, #047857 100%);
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.btn-ignition.running:hover {
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.45);
}

/* Dashboard Grid Layout */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr 0.9fr;
  gap: 20px;
  flex: 1;
}

@media (max-width: 1280px) {
  .dashboard-grid {
    grid-template-columns: 1.2fr 1fr;
  }
  .control-panel {
    grid-column: span 2;
  }
}

@media (max-width: 900px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
  .visualizer-panel, .telemetry-panel, .control-panel {
    grid-column: span 1;
  }
  .app-header {
    flex-direction: column;
    gap: 15px;
    align-items: stretch;
    text-align: center;
  }
  .logo-area {
    align-items: center;
  }
  .header-status {
    justify-content: center;
  }
}

/* Glass Panels */
.panel {
  background: var(--bg-panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow-main);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
}

.panel-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.5px;
}

.panel-tag {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.05);
  padding: 4px 8px;
  border-radius: 4px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

/* PANEL 1: CANVAS VISUALIZER */
.canvas-container {
  position: relative;
  flex: 1;
  min-height: 400px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

#drivetrain-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.canvas-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(8, 10, 15, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  transition: opacity 0.5s ease;
  pointer-events: none;
  padding: 20px;
  text-align: center;
}

.canvas-overlay.hidden {
  opacity: 0;
}

.canvas-overlay p {
  font-size: 1.1rem;
  color: var(--text-muted);
  font-weight: 300;
  letter-spacing: 0.5px;
  animation: pulse 2s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.visualizer-legend {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  font-size: 0.75rem;
  background: rgba(0, 0, 0, 0.15);
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}
.color-eng { background-color: var(--color-engine); }
.color-clu { background-color: var(--color-clutch); }
.color-tra { background-color: var(--color-trans); }
.color-ds { background-color: var(--color-driveshaft); }
.color-dif { background-color: var(--color-diff); }
.color-wh { background-color: var(--color-wheel); }

/* PANEL 2: TELEMETRY & DIALS */
.dials-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.dial-card {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.dial-card h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 1px;
}

.dial-container {
  position: relative;
  width: 140px;
  height: 140px;
}

.gauge-svg {
  width: 100%;
  height: 100%;
}

.gauge-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.05);
  stroke-width: 6;
  stroke-linecap: round;
}

.gauge-fill {
  fill: none;
  stroke: var(--m-blue);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 236; /* Only fill a 270 deg arc (270/360 * 314 = 236) */
  stroke-dashoffset: 236;
  transition: stroke-dashoffset 0.05s linear;
}

#tacho-fill {
  stroke: rgba(245, 158, 11, 0.15); /* Subtle glowing amber fill track */
}

#speedo-fill {
  stroke: rgba(245, 158, 11, 0.15);
}

/* E46 Dial Markings & Amber backlighting style */
.dial-tick {
  stroke: rgba(245, 158, 11, 0.45);
  stroke-width: 0.8px;
}
.dial-tick.major {
  stroke: rgba(245, 158, 11, 0.85);
  stroke-width: 1.2px;
}
.dial-tick.redline {
  stroke: #ff3b30;
  stroke-width: 1.2px;
}
.dial-num {
  font-family: var(--font-sans);
  font-size: 7px;
  font-weight: 700;
  fill: rgba(245, 158, 11, 0.8);
  text-shadow: 0 0 2px rgba(245, 158, 11, 0.35);
  text-anchor: middle;
  dominant-baseline: central;
}
.dial-num.redline-text {
  fill: #ff3b30;
  text-shadow: 0 0 2px rgba(255, 59, 48, 0.35);
}

.gauge-center {
  fill: #0c0c0f;
  stroke: rgba(255, 255, 255, 0.15);
  stroke-width: 1;
}

.dial-label-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.dial-val {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 700;
  color: #fff;
  line-height: 1;
  margin-top: 20px;
}

.dial-unit {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 4px;
}

/* Telemetry Readout Cards */
.telemetry-readouts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 600px) and (max-width: 1280px) {
  .telemetry-readouts {
    grid-template-columns: repeat(3, 1fr);
  }
}

.readout-card {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.readout-card h4 {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 6px;
  margin-bottom: 2px;
}

.readout-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
}

.readout-row span:first-child {
  color: var(--text-muted);
}

.mono {
  font-family: var(--font-mono);
  font-weight: 600;
}

.status-badge {
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 600;
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.25);
  transition: all 0.3s ease;
}

.status-badge.open {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.gear-badge {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  padding: 2px 10px;
  border-radius: 6px;
  color: #fff;
  min-width: 32px;
  text-align: center;
}

.gear-badge.active-drive {
  background: rgba(0, 140, 219, 0.2);
  border-color: var(--m-blue);
  color: #60a5fa;
  box-shadow: 0 0 10px rgba(0, 140, 219, 0.2);
}

.gear-badge.reverse {
  background: rgba(231, 34, 46, 0.2);
  border-color: var(--m-red);
  color: #f87171;
}

/* Progress bar (Clutch Health/Slip) */
.progress-bar-container {
  width: 80px;
  height: 6px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.progress-bar {
  height: 100%;
  background: linear-gradient(to right, #10b981, #34d399);
  border-radius: 3px;
  transition: width 0.1s linear;
}

.slip-bar-container {
  width: 100px;
  height: 8px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.slip-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(to right, #3b82f6, #ef4444);
  border-radius: 4px;
  transition: width 0.05s linear;
}

/* Telemetry Chart */
.telemetry-chart-container {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.telemetry-chart-container h4 {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

#telemetry-chart {
  width: 100%;
  height: 110px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.02);
  display: block;
}

/* PANEL 3: CONTROLS & CONFIG */
.control-group {
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 18px;
}

.control-group:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
}

.control-group h3 {
  font-size: 0.85rem;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 14px;
}

/* Pedals & Sliders */
.pedal-slider {
  margin-bottom: 12px;
}

.pedal-slider:last-child {
  margin-bottom: 0;
}

.slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  margin-bottom: 6px;
  color: var(--text-muted);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  outline: none;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 10px rgba(0,0,0,0.5);
  transition: transform 0.1s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

#input-throttle::-webkit-slider-thumb {
  background: var(--color-engine);
}

#input-clutch::-webkit-slider-thumb {
  background: var(--color-clutch);
}

#input-brake::-webkit-slider-thumb {
  background: var(--m-red);
}

#config-boost::-webkit-slider-thumb {
  background: #60a5fa;
}

/* Gear Shifter Grid */
.gear-selector-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.gear-btn {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.95rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.gear-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.gear-btn.active {
  background: linear-gradient(135deg, var(--m-blue) 0%, #1e40af 100%);
  color: white;
  border-color: var(--m-blue);
  box-shadow: 0 0 12px rgba(28, 150, 232, 0.35);
}

.keyboard-shift-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 10px;
}

/* Custom Select Dropdowns */
.select-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
  margin-top: 10px;
  margin-bottom: 4px;
}

.custom-select {
  width: 100%;
  font-family: var(--font-sans);
  background-color: rgba(0, 0, 0, 0.3);
  color: #fff;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.custom-select:focus {
  border-color: var(--m-blue);
  box-shadow: 0 0 8px rgba(0, 140, 219, 0.2);
}

.custom-select option {
  background-color: var(--bg-primary);
  color: #fff;
}

/* Toggle switches */
.toggle-container {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 22px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.1);
  transition: .3s;
  border-radius: 22px;
  border: 1px solid var(--border-color);
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--m-blue);
}

.toggle-switch input:focus + .toggle-slider {
  box-shadow: 0 0 6px rgba(0, 140, 219, 0.4);
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(22px);
}

.toggle-label {
  font-size: 0.85rem;
  color: var(--text-main);
  font-weight: 600;
}

/* Keyboard legends */
.keyboard-legend {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  padding: 14px;
  font-size: 0.8rem;
}

.keyboard-legend h4 {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 4px;
}

.keyboard-legend ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.keyboard-legend li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-muted);
}

kbd {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  background-color: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-bottom: 2px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
}

/* Footer style */
.app-footer {
  text-align: center;
  padding: 16px 20px;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  margin-top: auto;
}

/* Warnings and Animations */
.clutch-warning {
  color: #ef4444 !important;
  font-weight: bold;
  animation: warning-blink 0.8s infinite alternate;
}

@keyframes warning-blink {
  0% { opacity: 0.5; text-shadow: none; }
  100% { opacity: 1; text-shadow: 0 0 8px rgba(239, 68, 68, 0.8); }
}

.btn-action {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  border: 1px solid var(--border-color);
  padding: 5px 12px;
  border-radius: 6px;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-action:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.btn-action:active {
  transform: scale(0.97);
}

/* Dragy card styles */
.dragy-card {
  border: 1px solid rgba(245, 158, 11, 0.25) !important;
}

.dragy-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.dragy-item {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
}

.dragy-item.col-span-2 {
  grid-column: span 2;
}

.dragy-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.dragy-val {
  font-size: 0.85rem;
  color: #fff;
  font-weight: 700;
  margin-top: 2px;
}
