:root {
  color-scheme: dark;

  /* Type */
  --font-body: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-display: Oxanium, var(--font-body);

  /* Palette: charcoal + off-white + Porsche Guards Red accent + amber warning */
  --bg: #0c0d0f;
  --bg-elev: #141619;
  --surface: #1a1d21;
  --surface-2: #202428;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);

  --text: #f2f3f5;
  --muted: #9aa0a8;
  --faint: #6b7178;

  --accent: #d5001c;        /* Guards Red */
  --accent-soft: rgba(213, 0, 28, 0.16);
  --amber: #f0a500;
  --tick: rgba(255, 255, 255, 0.45);
  --tick-major: #d8dde2;

  --radius: 18px;
  accent-color: var(--accent);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(900px 500px at 50% -10%, #1a1c20 0%, transparent 60%),
    var(--bg);
  display: grid;
  place-items: start center;
  padding: 32px 24px 56px;
  line-height: 1.5;
}

.app-shell {
  width: min(100%, 1040px);
  display: grid;
  gap: 28px;
}

/* ---------- Header ---------- */
.app-header {
  text-align: center;
}

.eyebrow {
  display: inline-block;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 12px;
}

.app-header h1 {
  font-family: var(--font-display);
  font-weight: 800;
  margin: 0 0 10px;
  font-size: clamp(1.8rem, 4vw, 2.9rem);
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.app-header p {
  margin: 0 auto;
  max-width: 52ch;
  color: var(--muted);
  text-wrap: pretty;
}

/* ---------- Cluster (hero gauges) ---------- */
.cluster {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  background: linear-gradient(180deg, var(--bg-elev), var(--surface));
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: 32px 24px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.45);
}

.gauge-card {
  display: grid;
  justify-items: center;
  gap: 14px;
}

.gauge-caption {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.gauge {
  position: relative;
  width: min(330px, 100%);
  aspect-ratio: 1 / 1;
}

.gauge-face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 255, 255, 0.10), transparent 42%),
    radial-gradient(circle at 50% 50%, #16191d 46%, #0a0b0d 100%);
  border: 8px solid #0a0b0d;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.05),
    inset 0 18px 40px rgba(0, 0, 0, 0.6),
    0 12px 30px rgba(0, 0, 0, 0.5);
}

/* Tick marks (generated in JS) */
.gauge-ticks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.tick {
  position: absolute;
  left: 50%;
  bottom: 50%;
  width: 2px;
  height: 46%;
  transform-origin: bottom center;
  background: linear-gradient(to top, transparent 86%, var(--tick) 86%);
}

.tick.major {
  width: 3px;
  background: linear-gradient(to top, transparent 80%, var(--tick-major) 80%);
}

.tick.redline {
  background: linear-gradient(to top, transparent 80%, var(--accent) 80%);
}

.tick-num {
  position: absolute;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--muted);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.tick-num.redline {
  color: var(--accent);
}

/* Needle */
.needle {
  position: absolute;
  left: 50%;
  bottom: 50%;
  width: 4px;
  height: 44%;
  transform-origin: bottom center;
  transform: translateX(-50%) rotate(-90deg);
  border-radius: 999px;
  z-index: 2;
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.25, 1);
}

.speedo-needle {
  background: linear-gradient(180deg, #ffffff, #c7ccd2);
  box-shadow: 0 0 18px rgba(255, 255, 255, 0.35);
}

.tach-needle {
  background: linear-gradient(180deg, var(--accent), #ff3b54);
  box-shadow: 0 0 20px rgba(213, 0, 28, 0.55);
}

.gauge-center {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 26px;
  height: 26px;
  background: radial-gradient(circle at 40% 35%, #3a3f45, #15171a);
  border-radius: 50%;
  border: 3px solid #0a0b0d;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.06);
  z-index: 3;
}

/* Center digital readout */
.gauge-readout {
  position: absolute;
  left: 50%;
  top: 66%;
  transform: translate(-50%, -50%);
  display: grid;
  justify-items: center;
  gap: 2px;
  text-align: center;
  z-index: 1;
}

.gauge-big {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.2rem, 4vw, 3rem);
  line-height: 1;
  letter-spacing: -0.02em;
}

.gauge-unit-top,
.gauge-unit-bottom,
.gauge-sub {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.gauge-sub {
  color: var(--faint);
}

/* Redline warning state */
.tach.redline-active .tach-needle {
  box-shadow: 0 0 26px rgba(213, 0, 28, 0.9);
}

.tach.redline-active #rpmValue,
.tach.redline-active #rpmStatus {
  color: var(--accent);
}

.tach.redline-active {
  animation: redline-pulse 0.6s ease-in-out infinite alternate;
}

@keyframes redline-pulse {
  from { filter: drop-shadow(0 0 0 transparent); }
  to { filter: drop-shadow(0 0 14px rgba(213, 0, 28, 0.35)); }
}

/* ---------- Controls ---------- */
.controls {
  display: grid;
  gap: 24px;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.control-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 24px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.card-head h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  margin: 0;
  letter-spacing: 0.02em;
}

.card-head h3 {
  margin: 0;
}

.rpm-chip,
.ratio-chip {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--text);
}

.ratio-chip strong {
  color: var(--accent);
}

.rpm-chip.redline {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

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

/* Sound toggle */
.sound-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.8rem;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.sound-toggle:hover {
  color: var(--text);
  border-color: var(--muted);
}

.sound-toggle .sound-icon {
  display: inline-flex;
}

.sound-toggle .icon-sound {
  display: none;
}

.sound-toggle.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.sound-toggle.active .icon-muted {
  display: none;
}

.sound-toggle.active .icon-sound {
  display: inline;
}

.sound-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* RPM stepper */
.rpm-stepper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.step-btn {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.step-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.step-btn:active {
  transform: scale(0.94);
}

input[type="range"] {
  flex: 1 1 auto;
  width: 100%;
  height: 8px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent) var(--fill, 0%), var(--surface-2) var(--fill, 0%));
  border-radius: 999px;
  border: 1px solid var(--line);
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  cursor: pointer;
}

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

.hint {
  margin: 12px 0 0;
  font-size: 0.82rem;
  color: var(--faint);
}

/* Power / torque cards */
.power-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 20px 0 16px;
}

.power-card {
  padding: 16px;
  border-radius: 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  text-align: center;
}

.power-title {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
}

.power-card strong {
  display: block;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 2rem;
  line-height: 1;
}

.power-unit {
  display: block;
  color: var(--faint);
  margin-top: 6px;
  font-size: 0.85rem;
}

/* Power curve */
.power-curve-card {
  padding: 16px;
  border-radius: 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.power-curve-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.power-curve-label {
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
}

.power-curve-legend {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--faint);
  font-size: 0.82rem;
}

.curve-key {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  display: inline-block;
  margin-right: 4px;
}

.hp-key { background: var(--accent); }
.tq-key { background: var(--amber); }

.power-curve-graph {
  width: 100%;
  height: 130px;
  overflow: visible;
}

.power-curve-graph path { stroke-linecap: round; }
.power-curve-graph circle { transition: transform 0.15s ease; }

/* ---------- Shift knob ---------- */
.shift-gate {
  position: relative;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  place-items: center;
  width: min(100%, 300px);
  aspect-ratio: 1 / 1;
  margin: 8px auto 14px;
  padding: 22% 18%;
  border-radius: 50%;
  /* glossy black knob face with a top highlight */
  background: radial-gradient(circle at 50% 30%, #45484e 0%, #212429 38%, #0b0c0e 100%);
  border: 2px solid #050506;
  box-shadow:
    /* polished white bezel ring */
    0 0 0 7px #e9e9ec,
    0 0 0 9px #050506,
    /* inner gloss + vignette */
    inset 0 8px 22px rgba(255, 255, 255, 0.10),
    inset 0 -26px 50px rgba(0, 0, 0, 0.55),
    /* drop shadow */
    0 20px 44px rgba(0, 0, 0, 0.5);
}

/* Number sits inside a small engraved circle */
.gate-slot {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #303338 0%, #16181b 70%, #0a0b0d 100%);
  color: #f6f6f8;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 2px 5px rgba(255, 255, 255, 0.12), inset 0 -3px 6px rgba(0, 0, 0, 0.5);
  transition: color 0.18s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

.gate-slot:hover {
  transform: translateY(-1px);
  color: #fff;
  border-color: #fff;
  box-shadow: inset 0 2px 5px rgba(255, 255, 255, 0.12), 0 0 12px rgba(255, 255, 255, 0.35);
}

.gate-slot.selected {
  border-color: #fff;
  background: radial-gradient(circle at 50% 40%, #ff3147, var(--accent));
  color: #fff;
  box-shadow:
    inset 0 2px 5px rgba(255, 255, 255, 0.2),
    0 6px 18px rgba(213, 0, 28, 0.6);
}

/* ---------- Details ---------- */
.details {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.details h3 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 14px;
}

.details ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.details li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.92rem;
}

.details li span {
  color: var(--faint);
}

.details li strong {
  font-family: var(--font-display);
  font-weight: 600;
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .cluster {
    grid-template-columns: 1fr;
    gap: 32px;
    padding: 24px 18px;
  }
}

@media (max-width: 480px) {
  body { padding: 20px 14px 40px; }
  .control-card { padding: 18px; }
}
