:root {
  color-scheme: dark;
  --bg: #111318;
  --panel: #1c222b;
  --panel-soft: #252d37;
  --line: #3d4654;
  --text: #f4f7fb;
  --muted: #a7b0bd;
  --amber: #ffbd45;
  --green: #47d18c;
  --red: #ff6b6b;
  --blue: #58a6ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: radial-gradient(circle at 30% 10%, #263341 0, #111318 42%, #0b0d11 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  user-select: none;
  touch-action: none;
}

button {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: linear-gradient(180deg, #303947, #202733);
  color: var(--text);
  font: inherit;
  min-height: 42px;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 8px 18px rgba(0, 0, 0, 0.22);
}

button:active,
button.is-active {
  border-color: var(--amber);
  background: linear-gradient(180deg, #473823, #2a241b);
  color: #ffe2a8;
}

.sim-shell {
  display: grid;
  grid-template-rows: 54px minmax(0, 1fr) 112px;
  height: 100%;
  min-width: 320px;
}

.topbar,
.bottom-panel {
  background: rgba(14, 17, 22, 0.86);
  backdrop-filter: blur(10px);
  border-color: rgba(255, 255, 255, 0.08);
}

.topbar {
  display: grid;
  grid-template-columns: 1.2fr auto 1.3fr;
  gap: 12px;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand {
  display: flex;
  gap: 10px;
  align-items: baseline;
  min-width: 0;
}

.brand strong {
  font-size: 17px;
  white-space: nowrap;
}

.brand span,
.stats span,
.task-panel small,
.gear-panel span,
.progress-head {
  color: var(--muted);
}

.route-tabs,
.stats,
.action-row,
.mode-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.tab {
  min-height: 36px;
  padding: 0 14px;
}

.stats {
  justify-content: flex-end;
  font-size: 14px;
  white-space: nowrap;
}

.stats b {
  color: var(--amber);
  font-size: 18px;
}

.stage {
  display: grid;
  grid-template-columns: minmax(120px, 15vw) minmax(0, 1fr) minmax(154px, 19vw);
  gap: 10px;
  min-height: 0;
  padding: 10px;
}

.left-console,
.right-console {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.mirror-card,
.gear-box,
.wheel-zone {
  background: rgba(28, 34, 43, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
}

.mirror-card {
  padding: 8px;
}

.mirror-card span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

#mirrorCanvas {
  display: block;
  width: 100%;
  height: 72px;
  border-radius: 6px;
  background: #0c1015;
}

.pedals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  flex: 1;
  min-height: 120px;
}

.pedal {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  font-weight: 800;
  letter-spacing: 2px;
  transform-origin: bottom center;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.pedal.is-pressed {
  transform: perspective(420px) rotateX(11deg) translateY(5px) scale(0.96);
  filter: brightness(1.28);
}

.pedal-icon {
  position: relative;
  display: block;
  width: 34px;
  height: 54px;
  border: 3px solid rgba(255, 255, 255, 0.58);
  border-radius: 12px 12px 18px 18px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.18) 0 3px, transparent 3px 8px),
    rgba(0, 0, 0, 0.18);
}

.brake .pedal-icon {
  width: 46px;
}

.accel .pedal-icon {
  height: 66px;
  transform: skewX(-5deg);
}

.brake {
  background: linear-gradient(180deg, #4a2528, #251517);
}

.accel {
  background: linear-gradient(180deg, #1d4b35, #14251d);
}

.signal {
  position: absolute;
  bottom: 0;
  width: min(86px, 42%);
  height: 54px;
  font-weight: 900;
}

.signal-left {
  left: 0;
}

.signal-right {
  right: 0;
}

.signal.blinking {
  border-color: #ffd66b;
  background: #6b4812;
  animation: blink 0.7s infinite;
}

@keyframes blink {
  50% {
    filter: brightness(1.7);
  }
}

.road-wrap {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: #151a21;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

#roadCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.windshield-frame {
  position: absolute;
  inset: 14px 18px 46px;
  pointer-events: none;
  border: 4px solid rgba(9, 12, 16, 0.42);
  border-bottom-width: 28px;
  border-radius: 44px 44px 16px 16px / 26px 26px 12px 12px;
  box-shadow: inset 0 -28px 50px rgba(0, 0, 0, 0.36);
}

.hud {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.task-panel,
.gear-panel {
  max-width: min(460px, 62%);
  background: rgba(10, 13, 18, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 10px 12px;
}

.task-panel strong,
.task-panel span {
  display: block;
}

.task-panel strong {
  margin: 2px 0 4px;
  font-size: 20px;
}

.task-panel span {
  color: #dce5ef;
  font-size: 13px;
  line-height: 1.35;
}

.gear-panel {
  min-width: 74px;
  text-align: center;
}

.gear-panel strong {
  display: block;
  color: var(--green);
  font-size: 30px;
}

.tool-btn {
  flex: 1;
  min-height: 38px;
  font-size: 14px;
}

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

.gear {
  min-height: 44px;
  font-weight: 800;
}

.wheel-zone {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  gap: 8px;
  align-items: center;
  justify-items: center;
  flex: 1;
  min-height: 170px;
  padding: 10px 8px;
}

.steer-key {
  width: 42px;
  height: 92px;
  font-size: 38px;
}

.wheel {
  position: relative;
  width: min(160px, 100%);
  aspect-ratio: 1;
  border: 13px solid #0d1015;
  border-radius: 50%;
  background: radial-gradient(circle, #2e3744 0 20%, #151a21 21% 100%);
  box-shadow: inset 0 0 0 4px #323b49, 0 14px 28px rgba(0, 0, 0, 0.35);
  transition: transform 0.1s linear;
  cursor: grab;
  touch-action: none;
}

.wheel:active {
  cursor: grabbing;
}

.wheel-spoke,
.wheel-core {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  background: #0d1015;
}

.wheel-spoke {
  width: 78%;
  height: 10px;
  border-radius: 10px;
  box-shadow: 0 40px 0 -1px #0d1015;
}

.wheel-core {
  width: 36%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #202733;
  border: 4px solid #0d1015;
}

.bottom-panel {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) auto minmax(280px, 1.3fr);
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.progress-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 13px;
}

.progress-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #0c1015;
}

#progressFill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--amber));
}

.primary {
  min-width: 118px;
  background: linear-gradient(180deg, #2f6d4d, #1c3f31);
}

.event-list {
  display: flex;
  gap: 6px;
  align-items: center;
  overflow: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  scrollbar-width: thin;
}

.event-list li {
  flex: 0 0 auto;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.event-list li.done {
  color: #c8f6dc;
  border-color: rgba(71, 209, 140, 0.45);
}

.event-list li.current {
  color: #ffe2a8;
  border-color: rgba(255, 189, 69, 0.72);
  background: rgba(255, 189, 69, 0.12);
}

dialog {
  width: min(980px, 92vw);
  height: min(82vh, 780px);
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: #151a21;
  color: var(--text);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

#mapImage {
  display: block;
  width: 100%;
  height: calc(100% - 58px);
  object-fit: contain;
  background: #eef0f1;
}

@media (max-width: 860px), (max-height: 520px) {
  .sim-shell {
    grid-template-rows: 44px minmax(0, 1fr) 82px;
  }

  .topbar {
    grid-template-columns: auto 1fr auto;
    gap: 6px;
    padding: 5px 6px;
  }

  .brand strong {
    display: none;
  }

  .route-tabs {
    justify-content: center;
  }

  .tab,
  .tool-btn,
  .gear,
  button {
    min-height: 34px;
    font-size: 12px;
  }

  .stats {
    gap: 5px;
    font-size: 12px;
  }

  .stats b {
    font-size: 14px;
  }

  .stage {
    grid-template-columns: 96px minmax(0, 1fr) 130px;
    gap: 6px;
    padding: 6px;
  }

  .mirror-card {
    display: none;
  }

  .pedals {
    min-height: 0;
  }

  .pedal {
    letter-spacing: 1px;
    gap: 6px;
    overflow: hidden;
    font-size: 11px;
  }

  .pedal-icon {
    width: 26px;
    height: 42px;
    border-width: 2px;
  }

  .brake .pedal-icon {
    width: 34px;
  }

  .accel .pedal-icon {
    height: 50px;
  }

  .wheel-zone {
    grid-template-columns: 32px 1fr 32px;
    min-height: 110px;
    padding: 6px;
  }

  .steer-key {
    width: 32px;
    height: 74px;
  }

  .wheel {
    border-width: 9px;
  }

  .hud {
    left: 8px;
    right: 8px;
    top: 8px;
  }

  .task-panel,
  .gear-panel {
    padding: 7px 8px;
  }

  .task-panel strong {
    font-size: 15px;
  }

  .task-panel span,
  .task-panel small {
    font-size: 11px;
  }

  .gear-panel strong {
    font-size: 22px;
  }

  .bottom-panel {
    grid-template-columns: minmax(130px, 1fr) auto;
    padding: 6px;
  }

  .event-list {
    display: none;
  }

  .action-row {
    gap: 5px;
  }

  .action-row button {
    padding: 0 8px;
  }
}
