:root {
  --bg: #07080c;
  --panel: #10131a;
  --line: #1d2430;
  --text: #e8eef6;
  --muted: #8b97a8;
  --cyan: #3ec6ff;
  --amber: #f0b429;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Tesla", "Inter", "SF Pro Display", system-ui, sans-serif;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}
body { display: flex; flex-direction: column; }

#library, #hud { flex: 1; min-height: 0; }
#library { display: flex; flex-direction: column; padding: 28px 36px 24px; }
#library.hidden, #hud.hidden { display: none; }

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 22px;
}
.brand { font-size: 13px; letter-spacing: 0.28em; text-transform: uppercase; color: var(--muted); }
.brand strong { color: var(--text); letter-spacing: 0.12em; font-weight: 650; }
.hint { font-size: 14px; color: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  flex: 1;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px 22px 18px;
  text-align: left;
  color: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 150px;
  position: relative;
  overflow: hidden;
}
.card:before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--accent, var(--cyan));
}
.card h2 { margin: 0; font-size: 22px; font-weight: 600; }
.card p { margin: 0; color: var(--muted); font-size: 14px; }
.card .meta { margin-top: auto; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.card:active { transform: scale(0.985); }

#hud { display: grid; grid-template-rows: auto 1fr auto; padding: 16px 28px 18px; }
.hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.back, .chip {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  height: 40px;
  padding: 0 16px;
  font-size: 14px;
}
.pack-title { text-align: center; }
.pack-title .name {
  font-size: 13px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--amber);
}
.pack-title .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.stage {
  position: relative;
  display: grid;
  place-items: center;
}
#spark {
  position: absolute;
  inset: 8% 6%;
  width: calc(100% - 12%);
  height: 84%;
  pointer-events: none;
}
.tach {
  width: min(42vh, 340px);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  position: relative;
  background:
    conic-gradient(from 220deg, var(--ring, var(--cyan)) var(--arc, 8%), #161b24 0);
  z-index: 1;
}
.tach-inner {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  background: #0b0e14;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.speed {
  font-size: 84px;
  font-weight: 620;
  line-height: 0.9;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.unit { color: var(--muted); font-size: 14px; margin-top: 4px; letter-spacing: 0.16em; }
.rpm { margin-top: 10px; color: var(--amber); font-size: 16px; letter-spacing: 0.08em; font-variant-numeric: tabular-nums; }

.gear-box {
  position: absolute;
  right: 7%;
  top: 50%;
  transform: translateY(-50%);
  text-align: center;
  z-index: 1;
}
.gear-n { font-size: 64px; font-weight: 620; color: var(--cyan); line-height: 1; }
.gear-l { font-size: 11px; letter-spacing: 0.22em; color: var(--muted); }

.hud-bottom {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  gap: 16px;
  align-items: stretch;
}
.side {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.btn {
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #121722;
  color: var(--text);
  font-size: 14px;
}
.btn.on { border-color: var(--cyan); color: var(--cyan); }
.pedal {
  height: 92px;
  border: 0;
  border-radius: 18px;
  background: #151b26;
  color: var(--text);
  font-size: 18px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.pedal.down { background: #243044; }
.status { font-size: 12px; color: var(--muted); min-height: 16px; }
input[type="range"] { width: 100%; accent-color: var(--cyan); }

#load {
  position: fixed; inset: 0;
  background: rgba(7,8,12,0.72);
  display: grid; place-items: center;
  font-size: 18px;
  letter-spacing: 0.12em;
  z-index: 5;
}
#load.hidden { display: none; }

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .speed { font-size: 64px; }
  .hud-bottom { grid-template-columns: 1fr; }
}
