:root {
  --bg-dark: #0f1115;
  --bg-surface: #181b22;
  --bg-card: #20242e;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #e82127;
  
  --tesla-red: #e82127;
  --tesla-red-glow: rgba(232, 33, 39, 0.4);
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;

  --light-white-glow: 0 0 15px rgba(255, 255, 255, 0.9), 0 0 30px rgba(180, 220, 255, 0.6);
  --light-amber-glow: 0 0 15px rgba(255, 170, 0, 0.9), 0 0 30px rgba(255, 130, 0, 0.6);
  --light-red-glow: 0 0 15px rgba(255, 20, 20, 0.9), 0 0 30px rgba(220, 0, 0, 0.7);
  --light-fog-glow: 0 0 12px rgba(230, 245, 255, 0.8);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.app-header {
  height: 60px;
  background: rgba(24, 27, 34, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-logo {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  fill: var(--tesla-red);
  filter: drop-shadow(0 0 4px var(--tesla-red));
}

.header-title {
  font-weight: 800;
  letter-spacing: 2px;
  font-size: 0.95rem;
  color: var(--text-main);
}

.badge {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 3px 8px;
  border-radius: 4px;
}

.universal-badge {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.btn-text {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  transition: color 0.2s;
}

.btn-text:hover {
  color: #fff;
}

/* Phones: keep the header on one screen width */
@media (max-width: 640px) {
  .app-header {
    padding: 0 12px;
    gap: 8px;
  }
  .logo-area {
    gap: 8px;
    min-width: 0;
  }
  .app-logo {
    width: 20px;
    height: 20px;
  }
  .header-title {
    font-size: 0.8rem;
    letter-spacing: 1px;
    line-height: 1.2;
  }
  .universal-badge {
    display: none;
  }
  .btn-text {
    font-size: 0.75rem;
    text-align: right;
  }
}

/* Main Grid Layout */
.main-content {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  padding: 20px;
  flex: 1;
}

@media (max-width: 1024px) {
  .main-content {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel h2 {
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
}

/* Dropzone */
.dropzone {
  border: 2px dashed rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 24px 16px;
  text-align: center;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--tesla-red);
  background: rgba(232, 33, 39, 0.05);
}

.upload-icon {
  width: 36px;
  height: 36px;
  color: var(--tesla-red);
}

.dropzone-text {
  font-size: 0.95rem;
}

.dropzone-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.file-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-card);
  border-radius: 6px;
  font-size: 0.85rem;
}

.tag {
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
}

/* Preset Cards */
.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.preset-card-wide {
  grid-column: 1 / -1;
}

.preset-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.2s ease;
}

.preset-card input {
  display: none;
}

.preset-card:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

.preset-card.active {
  border-color: var(--tesla-red);
  background: rgba(232, 33, 39, 0.1);
}

.preset-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
}

.preset-desc {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.2;
}

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

.slider-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.slider-val {
  font-family: 'JetBrains Mono', monospace;
  color: #fff;
  font-weight: 600;
}

input[type="range"] {
  accent-color: var(--tesla-red);
  width: 100%;
  cursor: pointer;
}

/* Toggles */
.toggle-control {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.toggle-control input {
  display: none;
}

.toggle-switch {
  width: 36px;
  height: 20px;
  background: #374151;
  border-radius: 10px;
  position: relative;
  transition: background 0.2s;
}

.toggle-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-control input:checked + .toggle-switch {
  background: var(--tesla-red);
}

.toggle-control input:checked + .toggle-switch::after {
  transform: translateX(16px);
}

.toggle-label {
  font-size: 0.85rem;
  font-weight: 600;
}

.toggle-note {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  font-family: inherit;
}

.btn-primary {
  background: var(--tesla-red);
  color: #fff;
  padding: 12px 20px;
  font-size: 0.95rem;
  box-shadow: 0 4px 15px var(--tesla-red-glow);
}

.btn-primary:hover:not(:disabled) {
  background: #c81a20;
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  padding: 8px 14px;
  font-size: 0.8rem;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-block {
  width: 100%;
}

.validator-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.75rem;
  color: #10b981;
  background: rgba(16, 185, 129, 0.1);
  padding: 6px;
  border-radius: 4px;
  margin-top: 8px;
}

/* Visualizer Panel */
.visualizer-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  /* Size to its own content; stretching to the taller settings column left empty bands around the cars */
  align-self: start;
}

.vis-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.playback-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stat-pill {
  background: var(--bg-card);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-muted);
}

.stat-pill strong {
  color: #fff;
}

.section-pill {
  background: rgba(232, 33, 39, 0.15);
  border: 1px solid var(--tesla-red);
  color: #fff;
}

.section-pill strong {
  color: #ff4d4d;
  letter-spacing: 0.5px;
}

/* Vehicle Stage */
.vehicle-stage {
  flex: 0 0 auto;
  background: #090a0d;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  justify-content: center;
}

.view-label {
  font-size: 0.7rem;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.car-svg {
  display: block;
  width: 100%;
  height: auto;
}

.front-view,
.rear-view {
  max-height: 380px;
}

.side-view {
  max-height: 360px;
}

.car-body {
  fill: #1a1d24;
  stroke: #2a2f3a;
  stroke-width: 2;
}

.car-window {
  fill: #11141a;
  stroke: #222630;
  stroke-width: 1.5;
}

.car-trim {
  stroke: #2e3440;
  stroke-width: 3;
  fill: none;
}

.car-trim-fill {
  fill: #0f1115;
  stroke: #262b35;
  stroke-width: 1;
}

.car-tire {
  fill: #0a0b0e;
  stroke: #1c1f26;
  stroke-width: 1.5;
}

.car-rim {
  fill: #1c2029;
  stroke: #343a47;
  stroke-width: 1.5;
}

.car-arch {
  fill: #0d0f13;
}

/* Cybertruck: brushed stainless, hard edges */
.vehicle-stage[data-model="cybertruck"] .car-body {
  fill: #23272e;
  stroke: #3c424e;
  stroke-linejoin: miter;
}

.vehicle-stage[data-model="cybertruck"] .car-trim {
  stroke-width: 1.5;
}

/* Light Emitters */
.light-emitter {
  fill: #222834;
  stroke: #2a3140;
  stroke-width: 1;
}

/* ON states. One small drop-shadow per lamp: blur radius drives the GPU cost,
   and stacked 25-35px shadows made the Cybertruck preview drop frames. */
.light-emitter.on-headlight {
  fill: #ffffff !important;
  stroke: #d0e8ff !important;
  filter: drop-shadow(0 0 8px #9bcaff);
}

.light-emitter.on-signature {
  stroke: #ffffff !important;
  stroke-width: 5 !important;
  filter: drop-shadow(0 0 6px #70b4ff);
}

.light-emitter.on-turn {
  fill: #ffaa00 !important;
  stroke: #ffcc00 !important;
  filter: drop-shadow(0 0 7px #ffaa00);
}

.light-emitter.on-fog {
  fill: #d8ecff !important;
  stroke: #ffffff !important;
  filter: drop-shadow(0 0 7px #9ad0ff);
}

.light-emitter.on-tail {
  fill: #ff2222 !important;
  stroke: #ff6666 !important;
  filter: drop-shadow(0 0 7px #ff1111);
}

.light-emitter.on-brake {
  fill: #ff0000 !important;
  stroke: #ffffff !important;
  filter: drop-shadow(0 0 9px #ff0000);
}

.light-emitter.on-reverse {
  fill: #ffffff !important;
  stroke: #ffffff !important;
  filter: drop-shadow(0 0 7px #ffffff);
}

.light-emitter.on-license {
  fill: #e0eaff !important;
  filter: drop-shadow(0 0 4px #ffffff);
}

.light-emitter.on-offroad {
  fill: #ffffff !important;
  stroke: #ffe6a0 !important;
  filter: drop-shadow(0 0 9px #fff2cc);
}

.light-emitter.on-ct-bar {
  fill: #ffffff !important;
  stroke: #cce4ff !important;
  filter: drop-shadow(0 0 8px #a0ccff);
}

.light-emitter.on-ct-rear-bar {
  fill: #ff0022 !important;
  stroke: #ff6677 !important;
  filter: drop-shadow(0 0 8px #ff0022);
}

/* Interior screen/accent colour seen through the glass (fill set per frame in
   app.js), drawn in an overlay on its own layer so it never repaints the car */
/* Set by app.js when playback keeps missing frames (slow GPU): no glows. */
.vehicle-stage.lite-glow .light-emitter,
.vehicle-stage.lite-glow .ct-bar-segment {
  filter: none !important;
}

.tint-host {
  position: relative;
}
.tint-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  will-change: transform;
}
.window-tint {
  pointer-events: none;
  stroke: none;
}

.ct-bar {
  stroke-width: 1.5;
  fill: #111317;
}

.ct-bar-segment {
  shape-rendering: geometricPrecision;
}

.select-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: #fff;
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s;
}

.select-input:hover,
.select-input:focus {
  border-color: var(--tesla-red);
  background: #181b22;
}

.dual-view-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: end;
}

.dual-view-row > * {
  min-width: 0;
}

@media (max-width: 640px) {
  .dual-view-row {
    grid-template-columns: 1fr;
  }
}

/* Playback Deck */
.playback-deck {
  background: var(--bg-card);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.timeline-container {
  position: relative;
  width: 100%;
  height: 60px;
  background: #111317;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
}

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

.playhead {
  position: absolute;
  top: 0;
  left: 0;
  width: 2px;
  height: 100%;
  background: var(--tesla-red);
  box-shadow: 0 0 8px var(--tesla-red);
  pointer-events: none;
}

.deck-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--tesla-red);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  transition: transform 0.1s;
}

.btn-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.btn-circle svg {
  width: 18px;
  height: 18px;
}

.btn-circle:hover {
  transform: scale(1.05);
}

#time-current, #time-total {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal.open {
  display: flex;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  padding: 24px;
}

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

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
}

.guide-steps {
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.guide-steps strong {
  color: #fff;
}

.guide-steps code, .guide-steps pre {
  background: #111317;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  color: #10b981;
}

.guide-steps pre {
  padding: 10px;
  margin-top: 6px;
}

.hidden {
  display: none !important;
}

/* Actuators: trunk / frunk outline follows what the panel is doing */
#actuator-charge-port[data-state="open"] { fill: #3fa9f5 !important; }
#actuator-charge-port[data-state="dance"] { fill: #ff4fd8 !important; animation: closure-dance 0.8s linear infinite; }
#actuator-charge-port[data-state="opening"],
#actuator-charge-port[data-state="closing"] { fill: #1d5d8a !important; }
@keyframes closure-dance { to { filter: hue-rotate(360deg); } }

/* Trunk / frunk openness gauge, overlaid on the front or rear view */
.vehicle-view-container {
  position: relative;
}
.vehicle-view-container:has(.trunk-gauge-box) .view-label {
  padding-right: 150px;
}
.trunk-gauge-box {
  position: absolute;
  top: -6px;
  right: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 4px;
  background: rgba(9, 10, 13, 0.8);
  border: 1px solid var(--border-color);
  font-size: 0.7rem;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-muted);
  pointer-events: none;
}
.trunk-gauge-box strong {
  color: #fff;
  min-width: 4ch;
  text-align: right;
}
.trunk-gauge {
  width: 56px;
  height: 6px;
  border-radius: 3px;
  background: #2a2f3a;
  overflow: hidden;
}
.trunk-gauge-fill {
  display: block;
  height: 100%;
  width: 0;
  background: #f5b642;
}

/* ---- Analytics consent banner ------------------------------------------ */
/* Only ever shown to EEA/UK/CH visitors (see cookie-consent.js). */
.cookie-consent {
  position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 9999;
  max-width: 640px; margin: 0 auto;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
  padding: 16px 18px;
  background: var(--bg-card); color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.16); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .5);
  font-size: 14.5px; line-height: 1.45;
}
.cookie-consent[hidden] { display: none; }
.cookie-consent__text { margin: 0; flex: 1 1 260px; color: var(--text-muted); }
.cookie-consent__actions { display: flex; gap: 10px; flex: 0 0 auto; margin-left: auto; }
.cookie-consent__btn {
  font: inherit; font-weight: 700; cursor: pointer;
  padding: 9px 18px; border-radius: 10px;
  background: var(--tesla-red); color: #fff; border: 1px solid var(--tesla-red);
}
.cookie-consent__btn:hover { background: #c51b20; border-color: #c51b20; }
/* Reject gets the same size and hit area, so declining is no harder than accepting. */
.cookie-consent__btn--ghost {
  background: none; color: var(--text-main); border-color: rgba(255, 255, 255, 0.24);
}
.cookie-consent__btn--ghost:hover { background: var(--bg-surface); border-color: var(--text-muted); }
@media (max-width: 480px) {
  .cookie-consent__actions { margin-left: 0; width: 100%; }
  .cookie-consent__btn { flex: 1 1 0; }
}

/* Local-processing note under the drop zone */
.privacy-note {
  display: flex; align-items: flex-start; gap: 8px;
  margin: 10px 2px 0;
  font-size: 0.78rem; line-height: 1.45; color: var(--text-muted);
}
.privacy-note strong { color: var(--text-main); font-weight: 600; }
.privacy-icon { flex: 0 0 auto; width: 14px; height: 14px; margin-top: 2px; color: #10b981; }
