/* ┌──────────────────────────────────────────────────────────────────────────────┐
 * │  File:         style.css                                                     │
 * │  Author:       Amey Thakur                                                   │
 * │  Profile:      https://github.com/Amey-Thakur                                │
 * │  Repository:   https://github.com/Amey-Thakur/ADAPTIVE-CRUISE-CONTROL        │
 * │                                                                              │
 * │  Description:  Complete stylesheet for the Adaptive Cruise Control web       │
 * │                simulation. Defines the dark and light theme color systems,   │
 * │                loading screen animation, layout grid, road and vehicle       │
 * │                rendering, instrument panel styling, interactive controls,    │
 * │                serial monitor aesthetics, cinematic overlay effects, and     │
 * │                responsive breakpoints for tablet and mobile viewports.       │
 * │                                                                              │
 * │  Technology:   CSS3, Custom Properties, Flexbox, Grid, Keyframe Animations   │
 * │  Released:     September 08, 2023                                            │
 * │  License:      MIT                                                           │
 * └──────────────────────────────────────────────────────────────────────────────┘ */

/* Dark Theme: Primary color palette applied when data-theme="dark" is set.
   Defines all CSS custom properties for backgrounds, text, accents, and
   component-specific colors used throughout the simulation interface. */
[data-theme="dark"] {
  --bg: #080d1a;
  --bg2: #0f1628;
  --bg3: #151d32;
  --surface: #1a2340;
  --border: rgba(255, 255, 255, 0.06);
  --border-h: rgba(255, 255, 255, 0.12);
  --text: #f1f5f9;
  --text2: #94a3b8;
  --text3: #64748b;
  --text4: #3b4660;
  --accent: #3b82f6;
  --cyan: #06b6d4;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --purple: #a855f7;
  --lcd-bg: #0a2a0a;
  --lcd-text: #39ff14;
  --lcd-glow: rgba(57, 255, 20, 0.2);
  --gauge-track: #1e293b;
  --gauge-fill: #3b82f6;
  --road-bg: linear-gradient(180deg, #0e1525, #080d18);
  --road-edge: #d97706;
  --road-dash: rgba(255, 255, 255, 0.4);
  --serial-bg: #060a14;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  --btn-bg: #151d32;
  --btn-hover: #1e2845;
  --kbd-bg: rgba(255, 255, 255, 0.06);
  --kbd-text: #4b5a74;
  --car-ego: #3b82f6;
  --car-ego-d: #1d4ed8;
  --car-ego-glow: rgba(59, 130, 246, 0.25);
  --car-lead: #6b7280;
  --car-lead-d: #4b5563;
}

/* Light Theme: Alternate color palette for data-theme="light".
   Overrides all custom properties with lighter values while maintaining
   the same variable names for seamless theme switching. */
[data-theme="light"] {
  --bg: #eef2f7;
  --bg2: #ffffff;
  --bg3: #f1f5f9;
  --surface: #ffffff;
  --border: rgba(0, 0, 0, 0.07);
  --border-h: rgba(0, 0, 0, 0.13);
  --text: #0f172a;
  --text2: #475569;
  --text3: #94a3b8;
  --text4: #cbd5e1;
  --accent: #2563eb;
  --cyan: #0891b2;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --purple: #7c3aed;
  --lcd-bg: #0f3a0f;
  --lcd-text: #39ff14;
  --lcd-glow: rgba(57, 255, 20, 0.25);
  --gauge-track: #e2e8f0;
  --gauge-fill: #2563eb;
  --road-bg: linear-gradient(180deg, #374151, #1f2937);
  --road-edge: #f59e0b;
  --road-dash: rgba(255, 255, 255, 0.55);
  --serial-bg: #0f172a;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.06), 0 2px 12px rgba(0, 0, 0, 0.03);
  --btn-bg: #f8fafc;
  --btn-hover: #e2e8f0;
  --kbd-text: #94a3b8;
  --kbd-bg: #1e293b;

  /* Cinematic overlay colors (shared across both themes) */
  --hl-glow: #22d3ee;
  --hl-text: rgba(34, 211, 238, 0.9);
  --blueprint-bg: rgba(6, 18, 36, 0.95);
  --car-ego: #3b82f6;
  --car-ego-d: #2563eb;
  --car-ego-glow: rgba(59, 130, 246, 0.3);
  --car-lead: #9ca3af;
  --car-lead-d: #6b7280;
}

/* Loading Screen: Full-viewport overlay shown during initial page load.
   Contains a CSS-rendered car animation, gradient progress bar, project title,
   and author attribution. Fades out once the simulation engine initializes. */
#loader-screen {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: #030712;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.8s ease, visibility 0.8s ease;
}

#loader-screen.fade {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

/* Car Track: Container for the animated car on the loading screen. */
.loader-car-track {
  width: 420px;
  height: 60px;
  position: relative;
}

.loader-car {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 80px;
  height: 36px;
  animation: carDrive 3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes carDrive {
  0% {
    left: 0;
  }

  100% {
    left: calc(100% - 80px);
  }
}

/* Car Body Parts: CSS-rendered vehicle components — body, roof, windows,
   wheels, headlight, and taillight. Proportions are designed for the
   loading screen only; the main simulation has its own car styles. */
.lc-body {
  position: absolute;
  bottom: 8px;
  left: 4px;
  right: 4px;
  height: 18px;
  background: linear-gradient(180deg, #ef4444, #b91c1c);
  border-radius: 5px 5px 4px 4px;
  box-shadow: 0 0 18px rgba(239, 68, 68, 0.35);
}

.lc-top {
  position: absolute;
  bottom: 22px;
  left: 22%;
  width: 52%;
  height: 16px;
  background: linear-gradient(180deg, #fca5a5, #ef4444);
  border-radius: 10px 10px 0 0;
  border: 1px solid rgba(255, 255, 255, .15);
  border-bottom: none;
}

.lc-window {
  position: absolute;
  bottom: 24px;
  height: 11px;
  background: rgba(148, 200, 255, 0.3);
  border-radius: 5px 4px 0 0;
  border: 1px solid rgba(148, 200, 255, 0.2);
  border-bottom: none;
  z-index: 2;
}

.lc-w1 {
  left: 24%;
  width: 18%;
}

.lc-w2 {
  left: 46%;
  width: 16%;
}

.lc-wheel {
  position: absolute;
  bottom: 0;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #3a3a4a, #111);
  border: 2px solid #2a2a3a;
  z-index: 3;
  animation: wheelSpin 0.4s linear infinite;
}

.lc-wh-f {
  right: 6px;
}

.lc-wh-r {
  left: 6px;
}

@keyframes wheelSpin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

.lc-headlight {
  position: absolute;
  right: 0;
  bottom: 12px;
  width: 6px;
  height: 8px;
  border-radius: 2px;
  background: #fef08a;
  box-shadow: 0 0 8px #fef08a, 0 0 20px rgba(254, 240, 138, 0.4);
  z-index: 3;
  animation: blinkLight 0.5s ease infinite;
}

.lc-taillight {
  position: absolute;
  left: 1px;
  bottom: 12px;
  width: 5px;
  height: 7px;
  border-radius: 2px;
  background: #ff3c3c;
  box-shadow: 0 0 8px #ff3c3c, 0 0 16px rgba(255, 60, 60, 0.4);
  z-index: 3;
  animation: blinkLight 0.6s ease infinite;
}

@keyframes blinkLight {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.2;
  }
}

/* Progress Bar: Horizontal bar below the car, filling left to right.
   Width is animated via JavaScript from 0% to 100%. */
.loader-bar-wrap {
  width: 420px;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
}

.loader-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #ef4444, #f97316, #3b82f6);
  border-radius: 3px;
  transition: width 0.1s linear;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.5);
}

/* Title: "Adaptive Cruise Control" displayed below the progress bar. */
.loader-title {
  font-family: 'Play', -apple-system, sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: #f1f5f9;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.9;
}

/* Author Footer: Positioned at the bottom of the loading screen. */
.loader-footer {
  position: absolute;
  bottom: 32px;
  font-family: 'Play', -apple-system, sans-serif;
  font-size: 0.8rem;
  color: #64748b;
  letter-spacing: 0.04em;
}

.loader-footer strong {
  color: #94a3b8;
}

/* Responsive adjustments for loading screen on small viewports. */
@media (max-width: 480px) {

  .loader-car-track,
  .loader-bar-wrap {
    width: 280px;
  }

  .loader-title {
    font-size: 1.1rem;
  }
}

/* Global Reset: Removes default margins, padding, and sets border-box
   sizing on all elements for consistent layout calculations. */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box
}

html {
  font-size: 18px;
  height: 100%
}

body {
  font-family: 'Play', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background .3s, color .3s;
}

::-webkit-scrollbar {
  width: 5px
}

::-webkit-scrollbar-track {
  background: transparent
}

::-webkit-scrollbar-thumb {
  background: var(--text4);
  border-radius: 3px
}


/* Header Bar: Fixed top navigation containing the project branding (icon, title,
   subtitle), active mode badge, theme toggle button, and GitHub link. */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .55rem 1.5rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 100;
  flex-shrink: 0;
  transition: background .3s, border-color .3s;
}

.h-left {
  display: flex;
  align-items: center;
  gap: .6rem
}

.h-icon {
  font-size: 1.5rem
}

#header h1 {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text), var(--text2));
  -webkit-background-clip: text;
  background-clip: text;
  cursor: pointer;
  transition: all 0.3s;
}

#header h1:hover {
  text-shadow: 0 0 15px rgba(255, 255, 255, 0.4);
}

/* Cinematic Overlay: Full-screen layer for the Easter egg holographic
   algorithm animation. Appears above all content when activated. */
#cinematic-layer {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 7, 18, 0.75);
  opacity: 0;
  transition: opacity 0.6s;
}

#cinematic-layer.on {
  opacity: 1;
  pointer-events: auto;
}

.hologram-title {
  text-align: center;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
  padding: 2rem;
}

.hologram-title h2 {
  font-size: 3rem;
  margin: 0;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 40px rgba(59, 130, 246, 0.5);
}

.hologram-title .holo-sub {
  font-size: 1.15rem;
  font-family: 'Play', sans-serif;
  letter-spacing: 0.04em;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.85);
}

.hologram-title .holo-tip {
  max-width: 560px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  color: #94ecbe;
  background: rgba(34, 197, 94, 0.08);
  padding: 14px 22px;
  border-radius: 8px;
  border: 1px solid rgba(34, 197, 94, 0.2);
  text-align: center;
  line-height: 1.65;
}

body.cinematic-active #main {
  transition: filter 0.8s;
}

/* Blueprint State: Applied to the ACC vehicle during the cinematic
   sequence, transforming it into a glowing wireframe schematic. */
.ego-blueprint .car-body::before {
  background: transparent !important;
  border: 2px solid var(--hl-glow) !important;
  box-shadow: 0 0 25px var(--hl-glow), inset 0 0 15px var(--hl-glow) !important;
  animation: blueprintPulse 1s infinite alternate !important;
}

@keyframes blueprintPulse {
  from {
    opacity: 0.6;
    transform: scale(1);
  }

  to {
    opacity: 1;
    transform: scale(1.02);
  }
}

.ego-blueprint .headlight {
  background: var(--hl-glow) !important;
  box-shadow: 0 0 30px var(--hl-glow) !important;
}

.supersonic #lane-strip {
  --road-speed: 0.05s !important;
}

.h-left h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.2
}

.h-sub {
  font-size: .58rem;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .08em;
  display: block;
  margin-top: 1px
}

.h-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%)
}

.h-right {
  display: flex;
  align-items: center;
  gap: .5rem
}

.mode-badge {
  font-size: .7rem;
  font-weight: 700;
  padding: .25rem .9rem;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: .08em;
  background: rgba(34, 197, 94, .1);
  color: var(--green);
  border: 1px solid rgba(34, 197, 94, .2);
  transition: all .3s;
  white-space: nowrap;
}

.mode-badge.cruise {
  background: rgba(59, 130, 246, .1);
  color: var(--accent);
  border-color: rgba(59, 130, 246, .2)
}

.mode-badge.adaptive {
  background: rgba(168, 85, 247, .1);
  color: var(--purple);
  border-color: rgba(168, 85, 247, .2)
}

.icon-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .2s, background .2s;
  text-decoration: none;
}

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


/* Status Bar: Horizontal bar below the header showing real-time system messages.
   Contains a pulsing dot indicator that reflects operational state. */
#status-bar {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .35rem 1.5rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  font-size: .68rem;
  color: var(--text2);
  flex-shrink: 0;
  transition: background .3s, border-color .3s;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
  box-shadow: 0 0 6px var(--green);
  animation: pulse 2s ease infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1
  }

  50% {
    opacity: .3
  }
}

.status-dot.warning {
  background: var(--amber);
  box-shadow: 0 0 6px var(--amber)
}

.status-dot.danger {
  background: var(--red);
  box-shadow: 0 0 6px var(--red)
}


/* Main Container: Primary flex column holding the road section and
   the two-column content grid (instruments + serial monitor). */
#main {
  flex: 1;
  padding: .4rem .6rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
  min-height: 0;
  overflow: auto;
}


/* Road Section: Single-lane road visualization with animated lane markers,
   orange edge lines, CSS-rendered vehicles, and a distance label overlay. */
#road-section {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
  flex-shrink: 0;
  transition: background .3s, border-color .3s;
}

#road {
  position: relative;
  width: 100%;
  height: 135px;
  background: var(--road-bg);
  overflow: hidden;
}

#road::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(255, 255, 255, .006) 2px, rgba(255, 255, 255, .006) 4px);
  pointer-events: none;
  z-index: 1;
}

.road-edge {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 2
}

.road-edge.top {
  top: 8px;
  background: var(--road-edge);
  box-shadow: 0 0 8px rgba(217, 119, 6, .3)
}

.road-edge.bottom {
  bottom: 8px;
  background: var(--road-edge);
  box-shadow: 0 0 8px rgba(217, 119, 6, .3)
}

.lane-markers {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  transform: translateY(-50%);
  overflow: hidden;
  pointer-events: none;
}

.lane-strip {
  position: absolute;
  top: 0;
  left: 0;
  width: calc(100% + 57px);
  height: 100%;
  background-image: linear-gradient(90deg,
      var(--road-dash) 0px,
      var(--road-dash) 35px,
      transparent 35px,
      transparent 57px);
  background-size: 57px 100%;
  background-repeat: repeat-x;
  animation: scrollDash var(--road-speed, 1s) linear infinite;
  animation-play-state: paused;
  will-change: transform;
}

@keyframes scrollDash {
  from {
    transform: translateX(0);
  }

  to {
    transform: translateX(-57px);
  }
}

/* Vehicle Rendering: CSS-built car components including body, roof, windows,
   wheels, headlights, and tail lights. Both ACC (ego) and lead vehicles
   share the same structural classes with different color overrides. */
.car {
  position: absolute;
  top: 50%;
  transform: translate(0, -50%);
  z-index: 5;
  text-align: center;
  transition: left .3s ease;
}

#lead-car {
  left: 72%
}

#ego-car {
  left: 18%
}

.car-body {
  position: relative;
  width: 125px;
  height: 50px;
  cursor: pointer;
}

.car-body::before {
  content: '';
  position: absolute;
  bottom: 6px;
  left: 6px;
  right: 6px;
  height: 26px;
  border-radius: 7px 7px 6px 6px;
  z-index: 1;
}

.car-body.lead::before {
  background: linear-gradient(180deg, var(--car-lead), var(--car-lead-d));
  border: 1px solid rgba(255, 255, 255, .06)
}

.car-body.ego::before {
  background: linear-gradient(180deg, var(--car-ego), var(--car-ego-d));
  border: 1px solid rgba(255, 255, 255, .15);
  box-shadow: 0 0 14px var(--car-ego-glow)
}

.car-top {
  position: absolute;
  bottom: 26px;
  left: 22%;
  width: 56%;
  height: 22px;
  border-radius: 16px 16px 0 0;
  z-index: 2
}

.lead .car-top {
  background: linear-gradient(180deg, #7d8694, var(--car-lead));
  border: 1px solid rgba(255, 255, 255, .1);
  border-bottom: none
}

.ego .car-top {
  background: linear-gradient(180deg, #93c5fd, var(--car-ego));
  border: 1px solid rgba(255, 255, 255, .18);
  border-bottom: none
}

.car-window {
  position: absolute;
  bottom: 30px;
  left: 26%;
  width: 22%;
  height: 15px;
  background: rgba(148, 200, 255, .28);
  border-radius: 8px 6px 0 0;
  z-index: 3;
  border: 1px solid rgba(148, 200, 255, .2);
  border-bottom: none
}

.car-body::after {
  content: '';
  position: absolute;
  bottom: 30px;
  left: 52%;
  width: 20%;
  height: 15px;
  background: rgba(148, 200, 255, .22);
  border-radius: 6px 8px 0 0;
  z-index: 3;
  border: 1px solid rgba(148, 200, 255, .15);
  border-bottom: none
}

.car-wheel {
  position: absolute;
  bottom: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #3a3a4a, #111);
  border: 2px solid #2a2a3a;
  z-index: 4;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .6);
}

.car-wheel::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #777
}




.car-wheel.front {
  right: 7px
}

.car-wheel.rear {
  left: 7px
}

.tail-light {
  position: absolute;
  width: 6px;
  height: 10px;
  border-radius: 2px;
  background: #3a1010;
  z-index: 4;
  transition: all .24s;
  left: 2px;
}

.tail-light.l {
  bottom: 20px;
}

.tail-light.r {
  bottom: 10px;
}

.tail-light.on {
  background: #ff3c3c;
  box-shadow: 0 0 10px #ff3c3c, 0 0 22px rgba(255, 60, 60, .4)
}

.headlight {
  position: absolute;
  width: 8px;
  height: 10px;
  border-radius: 2px;
  background: rgba(255, 253, 220, .08);
  z-index: 4;
  transition: all .24s;
  right: 2px;
}

.headlight.l {
  bottom: 21px;
}

.headlight.r {
  bottom: 12px;
}

.headlight.on {
  background: #fffef0;
  box-shadow: 0 0 8px #fffef0, 0 0 18px rgba(255, 254, 240, .4)
}

.headlight.flash {
  background: #fff !important;
  box-shadow: 0 0 20px #fff, 0 0 40px rgba(255, 255, 255, 1) !important;
  transition: none !important;
}

.car-tag {
  display: block;
  margin-top: 1px;
  font-size: .44rem;
  color: var(--text4);
  text-transform: uppercase;
  letter-spacing: .1em;
  font-weight: 600
}

.sensor-cone {
  position: absolute;
  right: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 18px solid transparent;
  border-bottom: 18px solid transparent;
  border-left: 90px solid rgba(6, 182, 212, .06);
  opacity: 0;
  z-index: 0;
  transition: opacity .3s;
}

.sensor-cone.on {
  opacity: 1;
  animation: conePulse 1.2s ease-in-out infinite
}

@keyframes conePulse {

  0%,
  100% {
    opacity: .7
  }

  50% {
    opacity: .15
  }
}

.sensor-cone.danger {
  border-left-color: rgba(239, 68, 68, .1)
}

#dist-label {
  position: absolute;
  top: 8px;
  left: 28%;
  right: 28%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .3s;
  z-index: 8
}

#dist-label.show {
  opacity: 1
}

#dist-label::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: repeating-linear-gradient(90deg, var(--cyan), var(--cyan) 4px, transparent 4px, transparent 8px);
  opacity: .4
}

#dist-label-val {
  position: relative;
  background: rgba(6, 182, 212, .12);
  color: var(--cyan);
  font-family: 'JetBrains Mono', monospace;
  font-size: .55rem;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 3px;
  border: 1px solid rgba(6, 182, 212, .2);
}


/* Content Row: Two-column grid layout. The left column (1.15fr) holds
   instrument panels and controls; the right column (0.85fr) holds the
   serial monitor. Collapses to single column on mobile. */
#content-row {
  flex: 1;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: .4rem;
  padding: .2rem .75rem;
  min-height: 0;
  overflow: visible;
}

#left-col {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  min-height: 0;
  overflow: visible;
}

#instruments-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
}

#instruments-bottom {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
}

.panel {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .5rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 105px;
  /* Top instrument row: LCD and speedometer side by side. */
  transition: background .3s, border-color .3s;
  overflow: hidden;
}

#info-panel,
#hw-panel {
  height: 140px;
  /* Bottom instrument row: Telemetry and Arduino panels, slightly taller. */
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .2rem;
  flex-shrink: 0
}

.panel-title {
  font-size: .55rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text3)
}

.panel-pin {
  font-family: 'JetBrains Mono', monospace;
  font-size: .48rem;
  color: var(--text4)
}

.com-on {
  color: var(--green) !important;
  font-weight: 600
}

#lcd {
  background: var(--lcd-bg);
  border-radius: 3px;
  padding: 6px 10px;
  box-shadow: inset 0 0 20px rgba(57, 255, 20, .05);
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
  border: 1px solid rgba(57, 255, 20, 0.08);
}

.lcd-line {
  font-family: 'JetBrains Mono', monospace;
  font-size: .85rem;
  font-weight: 700;
  color: var(--lcd-text);
  text-shadow: 0 0 6px var(--lcd-glow);
  letter-spacing: .08em;
  white-space: nowrap;
  overflow: hidden;
  min-height: 1.25em;
  line-height: 1.4;
}

#gauge {
  display: flex;
  justify-content: center;
  flex: 1;
  align-items: center;
  min-height: 0
}

#gauge-svg {
  width: 100%;
  max-width: 125px;
  margin-top: -5px;
  flex: 1;
}

.gauge-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 26px;
  font-weight: 800;
  fill: var(--text)
}

.gauge-unit {
  font-family: 'Play', sans-serif;
  font-size: 8px;
  fill: var(--text3);
  font-weight: 700;
  text-transform: uppercase;
}

#info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
  flex: 1;
  min-height: 0;
  padding: .2rem 0;
}

.info-cell {
  background: var(--bg3);
  border-radius: 6px;
  padding: .5rem .5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
  flex: 1;
}

.info-label {
  display: block;
  font-size: .55rem;
  color: var(--text4);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 600;
  margin-bottom: 4px;
}

.info-val {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

.info-val.mono {
  font-family: 'JetBrains Mono', monospace
}

#hw-grid {
  display: flex;
  justify-content: space-around;
  align-items: center;
  flex: 1;
  padding: .4rem 0;
}

.led-pair {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 40px
}

.led-pair span {
  font-family: 'JetBrains Mono', monospace;
  font-size: .5rem;
  color: var(--text4);
  text-transform: uppercase;
  white-space: nowrap
}

.hw-led {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg3);
  border: 1px solid var(--border);
  transition: all .2s;
  margin-bottom: 2px;
}

.hw-led.green.on {
  background: var(--green);
  border-color: var(--green);
  box-shadow: 0 0 6px var(--green), 0 0 14px rgba(34, 197, 94, .2)
}

.hw-led.red.on {
  background: var(--red);
  border-color: var(--red);
  box-shadow: 0 0 6px var(--red), 0 0 14px rgba(239, 68, 68, .2)
}

.hw-led.cyan.on {
  background: var(--cyan);
  border-color: var(--cyan);
  box-shadow: 0 0 6px var(--cyan), 0 0 14px rgba(6, 182, 212, .2)
}

#pin-bars {
  display: flex;
  gap: 4px
}

.pbar {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px
}

.pbar span {
  font-family: 'JetBrains Mono', monospace;
  font-size: .48rem;
  color: var(--text3);
  font-weight: 700;
  margin-bottom: 2px;
}

.pbar-fill {
  width: 100%;
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  position: relative;
  overflow: hidden
}

.pbar-fill::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 0%;
  background: var(--amber);
  border-radius: 2px;
  transition: width .15s
}

.pbar-fill.on::after {
  width: 85%;
  background: var(--green);
}

#controls-area {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

#arrow-grid {
  display: flex;
  gap: .5rem;
}

.arrow-group {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .4rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .25rem;
  transition: background .3s, border-color .3s;
  height: 75px;
  justify-content: center;
}

.arrow-title {
  font-size: .6rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--text3);
  margin-bottom: 2px;
}

.arrow-pair {
  display: flex;
  gap: .6rem;
}

.btn-arrow-key {
  width: 65px;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--btn-bg);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  user-select: none;
  transition: all .15s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-arrow-key kbd {
  font-family: 'JetBrains Mono', monospace;
  font-size: .52rem;
  color: var(--kbd-text);
  font-weight: 600;
  opacity: 0.8;
}

.btn-arrow-key:hover {
  background: var(--btn-hover);
  border-color: var(--border-h)
}

.btn-arrow-key:active,
.btn-arrow-key.pressed {
  transform: scale(.95)
}

.btn-arrow-key.accel {
  color: var(--green)
}

.btn-arrow-key.accel:hover,
.btn-arrow-key.accel.pressed {
  border-color: var(--green);
  box-shadow: 0 0 10px rgba(34, 197, 94, .1)
}

.btn-arrow-key.brake {
  color: var(--red)
}

.btn-arrow-key.brake:hover,
.btn-arrow-key.brake.pressed {
  border-color: var(--red);
  box-shadow: 0 0 10px rgba(239, 68, 68, .1)
}

.btn-arrow-key.dist-close {
  color: var(--amber)
}

.btn-arrow-key.dist-close:hover,
.btn-arrow-key.dist-close.pressed {
  border-color: var(--amber);
  box-shadow: 0 0 10px rgba(245, 158, 11, .1)
}

.btn-arrow-key.dist-far {
  color: var(--cyan)
}

.btn-arrow-key.dist-far:hover,
.btn-arrow-key.dist-far.pressed {
  border-color: var(--cyan);
  box-shadow: 0 0 10px rgba(6, 182, 212, .1)
}

#mode-row {
  display: flex;
  gap: .4rem;
  padding: 0;
}

.btn {
  flex: 1;
  padding: .55rem .8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--btn-bg);
  color: var(--text);
  font-family: 'Play', sans-serif;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  user-select: none;
  white-space: nowrap;
  transition: all .15s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn:hover {
  background: var(--btn-hover);
  border-color: var(--border-h)
}

.btn:active {
  transform: scale(.97)
}

.btn kbd {
  font-family: 'JetBrains Mono', monospace;
  font-size: .58rem;
  padding: 2px 4px;
  border-radius: 3px;
  background: var(--kbd-bg);
  color: var(--kbd-text);
  font-weight: 600;
  opacity: 0.8;
}

.mode-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: .7rem;
  font-weight: 800;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--kbd-bg);
  color: var(--text3);
  transition: all .2s;
}

.btn-mode.active {
  border-width: 1.5px
}

.btn-mode.m0-active {
  border-color: var(--green);
  box-shadow: 0 0 8px rgba(34, 197, 94, .08)
}

.btn-mode.m0-active .mode-num {
  background: var(--green);
  color: white
}

.btn-mode.m1-active {
  border-color: var(--accent);
  box-shadow: 0 0 8px rgba(59, 130, 246, .08)
}

.btn-mode.m1-active .mode-num {
  background: var(--accent);
  color: white
}

.btn-mode.m2-active {
  border-color: var(--purple);
  box-shadow: 0 0 8px rgba(168, 85, 247, .08)
}

.btn-mode.m2-active .mode-num {
  background: var(--purple);
  color: white
}

#slider-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .4rem .6rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: background .3s, border-color .3s;
}

.slider-head {
  display: flex;
  justify-content: space-between;
  font-size: .75rem;
  color: var(--text2);
  font-weight: 600;
  margin-bottom: 5px;
}

.slider-val {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: var(--cyan)
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  background: linear-gradient(90deg, var(--red) 0%, var(--red) 30%, var(--amber) 30%, var(--amber) 35%, var(--green) 35%, var(--green) 100%);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  border: 3px solid var(--cyan);
  box-shadow: 0 0 10px rgba(6, 182, 212, .5);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  border: 3px solid var(--cyan);
  cursor: pointer;
}

.slider-labels {
  position: relative;
  height: 12px;
  font-family: 'JetBrains Mono', monospace;
  font-size: .55rem;
  color: var(--text4);
  margin-top: 4px;
}

.lbl-danger {
  position: absolute;
  left: 0;
  color: var(--red);
}

.lbl-warn {
  position: absolute;
  left: 30%;
  transform: translateX(-50%);
  color: var(--amber);
}

.lbl-safe {
  position: absolute;
  right: 0;
  color: var(--green);
}

#serial-col {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  transition: background .3s, border-color .3s;
}

.serial-head {
  display: flex;
  justify-content: space-between;
  padding: .35rem .6rem;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  font-size: .52rem;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .06em;
  flex-shrink: 0;
}

.serial-baud {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 400
}

#serial {
  background: var(--serial-bg);
  padding: .35rem .6rem;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: .56rem;
  line-height: 1.5;
  color: #94a3b8;
}

#serial .ts {
  color: #475569
}

#serial .info {
  color: var(--cyan)
}

#serial .success {
  color: var(--green)
}

#serial .warn {
  color: var(--amber)
}

#serial .danger {
  color: var(--red)
}

#serial .sys {
  color: var(--purple)
}

#footer {
  padding: .2rem 1.25rem;
  text-align: center;
  border-top: none;
  background: transparent;
  flex-shrink: 0;
  transition: background .3s, border-color .3s;
}

#footer p {
  font-size: .7rem;
  color: var(--text3);
  line-height: 1.2
}

#footer a {
  color: var(--accent);
  text-decoration: none
}

#footer a:hover {
  text-decoration: underline
}

@media(max-width:1024px) {
  html {
    font-size: 16px;
  }

  body {
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
  }

  #main {
    padding: .5rem;
    height: auto;
    width: 100%;
  }

  #content-row {
    grid-template-columns: 1fr;
    gap: .75rem;
    padding: 0 .5rem;
    width: 100%;
    overflow: visible;
  }

  #left-col {
    overflow: visible;
    gap: .75rem;
    width: 100%;
  }

  #road {
    height: 140px;
    margin: 0 -0.5rem;
    width: calc(100% + 1rem);
  }

  #dist-label {
    left: 10%;
    right: 10%;
    width: 80%;
  }

  #serial-col {
    height: 400px;
    max-height: none;
  }

  #instruments-top,
  #instruments-bottom {
    grid-template-columns: 1fr 1fr;
    gap: .75rem;
  }

  .panel {
    height: auto;
    min-height: 110px;
  }

  #info-panel,
  #hw-panel {
    height: auto;
    min-height: 140px;
  }
}

@media(max-width:768px) {

  #instruments-top,
  #instruments-bottom {
    grid-template-columns: 1fr;
  }

  .h-center {
    display: none;
  }

  #road {
    height: 130px;
  }
}

@media(max-width:640px) {
  html {
    font-size: 15px;
  }

  #header {
    padding: .4rem .75rem;
    flex-direction: column;
    gap: .5rem;
  }

  .nav-stats {
    width: 100%;
    justify-content: space-between;
    gap: .2rem;
  }

  .stat-group {
    padding-right: .4rem;
    border-right: none;
  }

  .h-center {
    position: static;
    transform: none;
    order: -1;
    display: flex;
  }

  #status-bar {
    padding: .4rem .75rem;
    font-size: .65rem;
    height: auto;
    min-height: 40px;
  }

  #main {
    padding: .4rem .4rem;
    gap: .4rem;
  }

  #content-row {
    grid-template-columns: 1fr;
    padding: 0 .4rem;
    gap: .6rem;
  }

  #mode-row {
    flex-direction: row;
    gap: .4rem;
  }

  .btn {
    padding: .5rem .6rem;
    font-size: .9rem;
  }

  #arrow-grid {
    flex-direction: row;
    gap: .4rem;
  }

  .arrow-group {
    height: 80px;
    padding: .4rem;
  }

  .arrow-title {
    font-size: .52rem;
  }

  .btn-arrow-key {
    width: 55px;
    height: 45px;
    font-size: 1.2rem;
  }

  .btn-arrow-key kbd {
    font-size: .45rem;
  }

  #road {
    height: 105px;
  }

  .car-body {
    transform: scale(0.55);
    transform-origin: center bottom;
  }

  #serial-col {
    height: 300px;
  }
}