:root {
  --paper: #eef1f5;
  --paper-2: #e2e7ee;
  --ink: #1e2632;
  --ink-soft: #5a6575;
  --accent: #2f6fed;
  --accent-soft: #7aa5f5;
  --green: #2f8f6b;
  --panel: rgba(255, 255, 255, 0.86);
  --line: rgba(30, 38, 50, 0.12);
  --shadow: 0 14px 34px rgba(30, 46, 70, 0.14);
  --radius: 16px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Noto Sans SC", -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--paper);
  color: var(--ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
#scene { position: fixed; inset: 0; display: block; }
.vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 1;
  background: radial-gradient(ellipse at 50% 42%, transparent 55%, rgba(30, 46, 70, 0.12) 100%);
}

/* ---------- header ---------- */
header { position: fixed; top: 18px; left: 22px; display: flex; align-items: center; gap: 12px; z-index: 10; }
header .logo {
  width: 46px; height: 46px; border-radius: 13px; background: var(--panel);
  border: 1px solid var(--line); box-shadow: var(--shadow); display: grid; place-items: center;
}
header h1 { font-family: "Baloo 2", "Noto Sans SC", sans-serif; font-size: 21px; font-weight: 800; letter-spacing: 0.4px; }
header p { font-size: 11.5px; color: var(--ink-soft); margin-top: 1px; }

.top-actions { position: fixed; top: 18px; right: 22px; display: flex; gap: 10px; z-index: 10; }
.icon-btn {
  height: 42px; min-width: 42px; padding: 0 14px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 6px 18px rgba(30, 46, 70, 0.10);
  font: 700 13px "Noto Sans SC", sans-serif; color: var(--ink);
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 7px;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}
.icon-btn:hover { transform: translateY(-1px); }
.icon-btn:active { transform: scale(0.96); }
.icon-btn.active { background: var(--ink); color: var(--paper); }

/* ---------- route panel ---------- */
#routePanel {
  position: fixed; left: 22px; top: 108px; width: 238px; z-index: 9;
  background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px;
}
#routePanel h2 {
  font-size: 10.5px; letter-spacing: 2px; color: var(--ink-soft); font-weight: 700;
  margin: 2px 4px 10px; display: flex; justify-content: space-between;
}
#routeList { display: flex; flex-direction: column; gap: 6px; max-height: calc(100vh - 270px); overflow-y: auto; overflow-x: hidden; scrollbar-width: none; -ms-overflow-style: none; }
#routeList::-webkit-scrollbar { display: none; }
.route-item {
  display: grid; grid-template-columns: 58px 1fr; gap: 10px; align-items: center;
  padding: 7px; border-radius: 12px; border: 1px solid transparent; background: transparent;
  cursor: pointer; text-align: left; font: inherit; color: inherit; transition: all 0.18s;
}
.route-item:hover { background: rgba(255, 255, 255, 0.72); }
.route-item.active { background: #f4f7fb; border-color: var(--line); box-shadow: 0 6px 16px rgba(30, 46, 70, 0.10); }
.route-item canvas { width: 58px; height: 44px; border-radius: 8px; background: var(--paper-2); }
.route-item .rn { font: 700 13.5px "Baloo 2", "Noto Sans SC", sans-serif; display: flex; gap: 6px; align-items: baseline; }
.route-item .rn .no { font-size: 10px; color: var(--ink-soft); font-weight: 700; }
.route-item .rd { font-size: 10.5px; color: var(--ink-soft); margin-top: 1px; line-height: 1.35; }

/* ---------- driving deck ---------- */
#deck {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 10;
  display: flex; align-items: center; gap: 16px;
  background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); padding: 12px 18px;
}
.deck-route {
  font: 800 13px "Baloo 2", "Noto Sans SC", sans-serif; white-space: nowrap;
  padding-right: 16px; border-right: 1px solid var(--line);
}
.seg { display: flex; background: var(--paper-2); border-radius: 11px; padding: 3px; }
.seg button {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 9px;
  font: 700 12.5px "Noto Sans SC", sans-serif; color: var(--ink-soft); cursor: pointer; transition: all 0.18s;
}
.seg button.active { background: var(--ink); color: var(--paper); box-shadow: 0 3px 8px rgba(0, 0, 0, 0.18); }
.throttle-wrap { display: flex; flex-direction: column; gap: 4px; }
.throttle-wrap label { font-size: 9.5px; letter-spacing: 1.5px; color: var(--ink-soft); font-weight: 700; display: flex; justify-content: space-between; gap: 12px; }
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 170px; height: 6px; border-radius: 3px;
  background: linear-gradient(to right, var(--accent) var(--fill, 40%), var(--paper-2) var(--fill, 40%));
  outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: #f4f7fb; border: 2px solid var(--accent); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2); cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: #f4f7fb; border: 2px solid var(--accent); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2); cursor: pointer;
}
input[type="range"]:disabled { opacity: 0.35; cursor: default; }
.big-btn {
  border: 0; border-radius: 12px; height: 44px; min-width: 62px; padding: 0 15px;
  font: 700 13px "Noto Sans SC", sans-serif; cursor: pointer; transition: transform 0.1s, filter 0.15s;
}
.big-btn:active { transform: scale(0.94); }
#btnBrake { background: var(--accent); color: #fff; }
#btnBrake.on { filter: brightness(0.82); transform: scale(0.94); }
#btnHorn { background: var(--accent-soft); color: var(--ink); }
.deck-divider { width: 1px; height: 38px; background: var(--line); }
.readout { text-align: right; min-width: 86px; }
.readout .speed { font-family: "Baloo 2", "Noto Sans SC", sans-serif; font-size: 30px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.readout .unit { font-size: 11px; color: var(--ink-soft); margin-left: 2px; }
.readout .grade { font-size: 11px; color: var(--ink-soft); margin-top: 3px; font-variant-numeric: tabular-nums; }
.readout .grade b { color: var(--ink); }

/* ---------- help overlay ---------- */
#helpOverlay {
  position: fixed; inset: 0; z-index: 30; display: none; align-items: center; justify-content: center;
  background: rgba(46, 40, 30, 0.35); backdrop-filter: blur(3px);
}
#helpOverlay.show { display: flex; }
.help-card {
  width: min(430px, 90vw); background: var(--paper); border-radius: 20px; padding: 26px 28px;
  box-shadow: var(--shadow); border: 1px solid var(--line);
}
.help-card h3 { font-family: "Baloo 2", "Noto Sans SC", sans-serif; font-size: 19px; margin-bottom: 12px; }
.help-card table { width: 100%; border-collapse: collapse; font-size: 13px; }
.help-card td { padding: 7px 0; border-bottom: 1px dashed var(--line); color: var(--ink-soft); }
.help-card td:first-child { width: 150px; color: var(--ink); }
kbd {
  display: inline-block; min-width: 20px; text-align: center; padding: 2px 7px; margin-right: 4px;
  border-radius: 6px; background: #f4f7fb; border: 1px solid var(--line); border-bottom-width: 2px;
  font: 700 11.5px "Baloo 2", monospace; color: var(--ink);
}
.help-tip { font-size: 12px; color: var(--ink-soft); margin: 14px 0 4px; line-height: 1.6; }
.help-close { margin-top: 12px; width: 100%; background: var(--ink); color: var(--paper); }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%) translateY(8px); z-index: 11;
  background: var(--ink); color: var(--paper); font-size: 12.5px; font-weight: 600;
  padding: 9px 18px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: all 0.3s; box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25); white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- loading ---------- */
#loading {
  position: fixed; inset: 0; z-index: 50; background: var(--paper);
  display: grid; place-items: center; transition: opacity 0.6s;
}
#loading.hide { opacity: 0; pointer-events: none; }
.load-inner { text-align: center; }
.load-ring { width: 72px; height: 72px; animation: spin 1.1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.load-inner p { margin-top: 14px; font-size: 13px; color: var(--ink-soft); letter-spacing: 2px; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  #routePanel { left: 12px; right: 12px; top: 82px; width: auto; padding: 10px; }
  #routeList { flex-direction: row; overflow-x: auto; max-height: none; }
  .route-item { grid-template-columns: 1fr; gap: 4px; min-width: 92px; padding: 6px; }
  .route-item canvas { width: 100%; height: 40px; }
  .route-item .rd { display: none; }
  #deck { gap: 10px; padding: 10px 12px; bottom: 12px; max-width: 96vw; flex-wrap: wrap; justify-content: center; }
  .deck-route { display: none; }
  input[type="range"] { width: 120px; }
  header h1 { font-size: 17px; }
  header p { display: none; }
  .readout { min-width: 70px; }
  .readout .speed { font-size: 24px; }
}
