:root {
  color-scheme: dark;
  --bg: #1a100b;
  --panel: rgba(29, 18, 13, 0.88);
  --panel-strong: rgba(23, 14, 10, 0.96);
  --line: rgba(255, 194, 112, 0.26);
  --text: #fff6e8;
  --muted: #d6bd9e;
  --accent: #ff8b2c;
  --accent-soft: #ffc46b;
  --good: #78d66b;
  --bad: #ff6b5f;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.42);
  --font: "Inter", "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#stage {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hidden { display: none !important; }

.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: clamp(10px, 1.5vw, 20px);
}

.hud-column {
  display: grid;
  gap: 8px;
  width: min(360px, 38vw);
}

.hud-card {
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.level-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  font-size: 15px;
}

.pill {
  padding: 3px 8px;
  border-radius: 999px;
  color: #251505;
  background: var(--accent-soft);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.objective {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.metrics div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.metrics span {
  color: var(--muted);
  font-size: 10px;
}

.metrics strong {
  font-size: 14px;
  white-space: nowrap;
}

.boost-card { padding-bottom: 8px; }
.boost-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.boost-label strong { color: var(--text); }
.boost-track {
  height: 7px;
  margin-top: 5px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.12);
}
#hud-boost-fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ffd166, #ff7038);
  transition: width 100ms linear;
}
.hint-line { margin-top: 6px; color: rgba(214, 189, 158, 0.75); font-size: 10px; }

.hud-actions {
  pointer-events: auto;
  display: grid;
  gap: 8px;
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 16px;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: clamp(14px, 3vw, 32px);
  background:
    radial-gradient(circle at 50% 20%, rgba(255, 155, 62, 0.16), transparent 38%),
    rgba(16, 9, 6, 0.72);
  backdrop-filter: blur(8px);
}

.panel {
  width: min(920px, 100%);
  max-height: min(92vh, 760px);
  overflow: auto;
  padding: clamp(20px, 3vw, 34px);
  border: 1px solid rgba(255, 200, 120, 0.24);
  border-radius: 20px;
  background: var(--panel-strong);
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.55);
}

.brand {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 22px;
}

.brand-mark {
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  border-radius: 16px;
  background:
    linear-gradient(135deg, #ffb347 0 45%, #ff6738 45% 100%);
  box-shadow: inset 0 0 0 4px rgba(0,0,0,.18), 0 10px 26px rgba(255, 120, 40, .24);
}

h1, h2 { margin: 0; letter-spacing: .04em; }
h1 { font-size: clamp(28px, 4vw, 42px); }
h2 { font-size: clamp(19px, 2.4vw, 24px); }
.brand p { margin: 5px 0 0; color: var(--muted); }

.menu-grid {
  display: grid;
  grid-template-columns: minmax(240px, .75fr) minmax(320px, 1.25fr);
  gap: 20px;
}

.menu-section h2 {
  margin-bottom: 12px;
  font-size: 15px;
  color: var(--accent-soft);
  text-transform: uppercase;
}

.car-options, .level-options { display: grid; gap: 10px; }

.car-option, .level-option {
  width: 100%;
  display: grid;
  gap: 6px;
  padding: 12px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.045);
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}

.car-option:hover, .level-option:hover { transform: translateY(-1px); background: rgba(255,255,255,.075); }
.selected { border-color: var(--accent) !important; background: rgba(255,139,44,.15) !important; }
.locked { opacity: .5; }

.car-title, .level-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  font-weight: 800;
}

.swatch {
  width: 22px;
  height: 12px;
  border-radius: 4px;
  box-shadow: 0 0 0 2px rgba(0,0,0,.2);
}

.car-desc, .level-desc { color: var(--muted); font-size: 12px; line-height: 1.45; }
.tag {
  color: var(--accent-soft);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}
.best { color: var(--good); font-size: 11px; font-weight: 700; }

.assist-toggle {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}
.assist-toggle input { margin-top: 2px; accent-color: var(--accent); }

.menu-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
}

.primary-button, .normal-button, .ghost-button {
  min-height: 46px;
  padding: 12px 22px;
  border-radius: 12px;
  font-weight: 800;
}

.primary-button {
  color: #241204;
  background: linear-gradient(135deg, #ffd166, #ff7326);
  box-shadow: 0 10px 26px rgba(255, 115, 38, .28);
}

.normal-button { background: rgba(255,255,255,.12); border: 1px solid var(--line); }
.ghost-button { color: var(--muted); background: transparent; border: 1px dashed var(--line); }
.primary-button:hover, .normal-button:hover, .ghost-button:hover { filter: brightness(1.07); }

.controls-help {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 11px;
}
.controls-help span {
  padding: 5px 8px;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 7px;
  background: rgba(255,255,255,.04);
}

.compact-panel { width: min(500px, 100%); }
.compact-panel h2 { margin-bottom: 8px; }
.compact-panel p { margin: 0 0 18px; color: var(--muted); }

.vertical-actions { display: grid; gap: 10px; }
.vertical-actions .primary-button, .vertical-actions .normal-button, .vertical-actions .ghost-button { width: 100%; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 0 0 20px;
}
.result-grid div {
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,.05);
}
.result-grid dt { color: var(--muted); font-size: 11px; }
.result-grid dd { margin: 4px 0 0; font-size: 18px; font-weight: 800; }

.medal {
  width: max-content;
  margin-bottom: 12px;
  padding: 7px 14px;
  border-radius: 999px;
  color: #221204;
  background: linear-gradient(135deg, #ffe08a, #ff9f43);
  font-weight: 900;
  letter-spacing: .12em;
}
.medal.failed { color: #fff; background: linear-gradient(135deg, #ff7b6b, #b7352a); }

.touch-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 3;
  display: none;
  justify-content: space-between;
  align-items: end;
  gap: 14px;
  padding: 0 14px;
  pointer-events: none;
}

.touch-controls.active { display: flex; }
.touch-steer, .touch-drive { display: flex; gap: 10px; pointer-events: auto; }
.touch-drive { align-items: end; }

.touch-button {
  width: 69px;
  height: 69px;
  border-radius: 20px;
  border: 1px solid rgba(255, 214, 150, .32);
  background: rgba(29, 18, 13, .78);
  color: var(--text);
  font-size: 19px;
  font-weight: 900;
  box-shadow: 0 10px 24px rgba(0,0,0,.28);
  touch-action: none;
  user-select: none;
}

.touch-button.primary { background: linear-gradient(135deg, #ffd166, #ff772c); color: #231204; }
.touch-button.action { background: rgba(88, 205, 255, .22); border-color: rgba(150, 229, 255, .5); font-size: 14px; }
.touch-button.pressed { transform: translateY(2px) scale(.97); border-color: var(--accent); background: rgba(255,139,44,.36); }

@media (max-width: 760px), (pointer: coarse) {
  .hud { padding: 9px; }
  .hud-column { width: calc(100% - 57px); gap: 6px; }
  .hud-card { padding: 8px 10px; border-radius: 10px; }
  .level-line { font-size: 12px; }
  .objective { font-size: 10px; }
  .metrics { grid-template-columns: repeat(4, 1fr); gap: 4px; }
  .metrics span { font-size: 8px; }
  .metrics strong { font-size: 11px; }
  .boost-card { display: none; }
  .icon-button { width: 38px; height: 38px; font-size: 14px; }

  .panel { max-height: 94vh; padding: 18px; border-radius: 16px; }
  .brand { gap: 10px; margin-bottom: 14px; }
  .brand-mark { width: 42px; height: 42px; border-radius: 12px; }
  h1 { font-size: 24px; }
  .brand p { font-size: 11px; }
  .menu-grid { grid-template-columns: 1fr; gap: 14px; }
  .menu-actions { flex-direction: column; }
  .controls-help { display: none; }
  .result-grid { grid-template-columns: 1fr; }
  .touch-button { width: 62px; height: 62px; border-radius: 17px; font-size: 16px; }
}

@media (max-height: 560px) {
  .hud-column { width: min(300px, 34vw); }
  .objective { display: none; }
}
