:root {
  --bg: #0d1424;
  --panel: rgba(18, 26, 46, 0.92);
  --line: rgba(140, 170, 230, 0.18);
  --text: #e8eefc;
  --muted: #93a3c4;
  --accent: #4f8cff;
  --accent2: #b57cff;
  --good: #3ddc84;
  --bad: #ff5a3c;
  --gold: #ffd34d;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
canvas#map { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; cursor: grab; }
.hidden { display: none !important; }
button { font: inherit; color: var(--text); background: rgba(255,255,255,0.06); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; cursor: pointer; }
button:hover { background: rgba(255,255,255,0.12); }
button.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.alt { border-color: rgba(181,124,255,0.6); }
button.ghost { background: none; border: none; color: var(--muted); }
button:disabled { opacity: 0.45; cursor: default; }

.screen { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(ellipse at center, rgba(13,20,36,0.55), rgba(13,20,36,0.92)); padding: 16px; z-index: 5; }
.menu-card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px; width: min(440px, 100%); text-align: center; backdrop-filter: blur(6px); max-height: 92vh; overflow: auto; }
.menu-card.wide { width: min(620px, 100%); }
.menu-card h1 { margin: 0; font-size: 38px; letter-spacing: 1px; }
.menu-card .sub { color: var(--muted); margin: 4px 0 22px; }
button.big { display: block; width: 100%; text-align: left; padding: 16px 18px; margin: 10px 0; border-radius: 14px; background: linear-gradient(135deg, rgba(79,140,255,0.25), rgba(79,140,255,0.08)); }
button.big.alt { background: linear-gradient(135deg, rgba(181,124,255,0.25), rgba(181,124,255,0.08)); }
button.big span { display: block; font-size: 18px; font-weight: 700; }
button.big small { color: var(--muted); }
.attrib { color: var(--muted); font-size: 11px; margin-top: 14px; }

#level-list { display: grid; gap: 10px; margin: 16px 0; text-align: left; }
.level { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,0.04); }
.level .num { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); font-weight: 700; flex: none; }
.level.locked { opacity: 0.45; }
.level.locked .num { background: #3a4560; }
.level .info { flex: 1; }
.level .info b { display: block; }
.level .info small { color: var(--muted); }
.level .stars { color: var(--gold); letter-spacing: 2px; }

#topbar { position: fixed; top: 10px; left: 10px; right: 10px; display: flex; gap: 8px; align-items: center; z-index: 3; pointer-events: none; }
#topbar > * { pointer-events: auto; }
#topbar .icon { width: 40px; height: 40px; padding: 0; background: var(--panel); font-size: 18px; }
#clock { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 16px; }
#speed { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
#speed button { border: none; border-radius: 0; background: none; padding: 8px 11px; }
#speed button.on { background: var(--accent); }


.field { display: block; margin: 10px 0; color: var(--muted); font-size: 12px; }
.field .row { display: flex; gap: 10px; align-items: center; margin-top: 4px; }
.field input[type=range] { flex: 1; accent-color: var(--accent); }
.field output { color: var(--text); font-weight: 700; font-size: 14px; min-width: 70px; text-align: right; font-variant-numeric: tabular-nums; }
.field select { display: block; width: 100%; margin-top: 4px; background: #1a2440; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.check { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; margin: 8px 0; }
.trips-note { font-size: 12px; color: var(--muted); background: rgba(255,255,255,0.04); border-radius: 8px; padding: 8px; margin: 8px 0; }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.btns button { font-size: 12px; padding: 8px 6px; }
.live { display: grid; gap: 4px; background: rgba(255,255,255,0.04); border-radius: 10px; padding: 8px 10px; margin: 8px 0; font-size: 13px; }
.live div { display: flex; justify-content: space-between; }
.live span { color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 14px; height: 4px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

.result-big { text-align: center; padding: 12px; border-radius: 12px; background: linear-gradient(135deg, rgba(61,220,132,0.18), rgba(61,220,132,0.04)); border: 1px solid rgba(61,220,132,0.4); margin: 8px 0; }
.result-big.worse { background: linear-gradient(135deg, rgba(255,90,60,0.18), rgba(255,90,60,0.04)); border-color: rgba(255,90,60,0.4); }
.result-big b { display: block; font-size: 34px; }
table.cmp { width: 100%; border-collapse: collapse; font-size: 12px; margin: 8px 0; }
table.cmp th, table.cmp td { padding: 5px 4px; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
table.cmp th:first-child, table.cmp td:first-child { text-align: left; color: var(--muted); font-weight: normal; }
td.good { color: var(--good); }
td.bad { color: var(--bad); }
canvas.chart { width: 100%; height: 150px; display: block; background: rgba(255,255,255,0.03); border-radius: 8px; }
.note { color: var(--muted); font-size: 11px; }

#modal { position: fixed; inset: 0; background: rgba(5,8,16,0.6); display: grid; place-items: center; z-index: 10; padding: 16px; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 24px; width: min(420px, 100%); text-align: center; max-height: 90vh; overflow: auto; }
.modal-card h2 { margin: 0 0 8px; }
.modal-card .stars { font-size: 40px; color: var(--gold); letter-spacing: 6px; }
.modal-card .btns { margin-top: 16px; }
.modal-card p { color: var(--muted); }
.modal-card .goal { color: var(--text); background: rgba(79,140,255,0.12); border-radius: 10px; padding: 10px; }

#popup { position: fixed; z-index: 6; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; width: 230px; font-size: 13px; box-shadow: 0 8px 30px rgba(0,0,0,0.4); }
#popup h4 { margin: 0 0 4px; font-size: 14px; }
#popup .row { display: flex; justify-content: space-between; color: var(--muted); }
#popup .row b { color: var(--text); }
#popup button { width: 100%; margin-top: 8px; }

#loading { position: fixed; inset: 0; z-index: 20; display: grid; place-content: center; justify-items: center; gap: 12px; background: rgba(5,8,16,0.7); }
.spinner { width: 40px; height: 40px; border: 4px solid rgba(255,255,255,0.15); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Phase 1: Tugjee bridge levels ---------- */
.icon { width: 40px; height: 40px; padding: 0; background: var(--panel); font-size: 18px; }
#hud-br { position: fixed; inset: 0; pointer-events: none; z-index: 3; }
#hud-br button { pointer-events: auto; }
.br-card { position: absolute; left: 12px; top: 12px; width: 250px; pointer-events: auto; background: rgba(255,255,255,0.94); color: #1d2433; border-radius: 18px; padding: 10px 12px 12px; box-shadow: 0 10px 30px rgba(20,40,20,0.25); }
.br-card .icon { background: #eef1f6; color: #1d2433; border: none; }
.br-head { display: flex; gap: 10px; align-items: center; }
.br-head b { display: block; font-size: 15px; }
.br-head small { color: #6a7487; font-variant-numeric: tabular-nums; font-weight: 700; }
.br-gauge { margin: 10px 0 8px; }
.br-track { position: relative; height: 14px; border-radius: 7px; background: repeating-linear-gradient(90deg, #dfe4ec 0 10px, #e9edf3 10px 20px); }
#br-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 7px; background: linear-gradient(90deg, #ff6a3d, #ffc23d); transition: width 0.3s; }
#br-fill.ok { background: linear-gradient(90deg, #26b36a, #5fe39b); }
#br-car { position: absolute; top: -9px; transform: translateX(-50%) scaleX(-1); font-size: 20px; transition: left 0.3s; }
.br-flag { position: absolute; right: -6px; top: -10px; font-size: 18px; }
.br-gauge small { display: block; margin-top: 4px; font-weight: 800; color: #3a4457; font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; }
.br-stats { display: grid; grid-template-columns: 1.5fr 1fr 1fr; gap: 6px; }
.br-stats > div { background: #f2f5f9; border-radius: 12px; padding: 6px 8px; }
.br-stats label { display: block; font-size: 10px; color: #6a7487; text-transform: uppercase; font-weight: 700; }
.br-stats b { font-size: 16px; font-variant-numeric: tabular-nums; }
.br-stats small { display: block; font-size: 10px; color: #26a362; font-weight: 700; }
.br-toast { position: absolute; top: 18px; left: 50%; transform: translateX(-50%); background: #1d2433; color: #fff; font-weight: 800; padding: 10px 18px; border-radius: 999px; box-shadow: 0 8px 24px rgba(0,0,0,0.3); }
.br-dock { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; padding: 6px; border-radius: 999px; background: rgba(255,255,255,0.94); box-shadow: 0 10px 30px rgba(20,40,20,0.3); pointer-events: auto; }
.dock-btn { display: grid; justify-items: center; gap: 1px; min-width: 72px; padding: 6px 10px; border-radius: 999px; background: #f2f5f9; border: none; color: #1d2433; }
.dock-btn:hover { background: #e3e9f2; }
.dock-btn .ico { font-size: 20px; line-height: 1.1; }
.dock-btn .lbl { font-size: 11px; font-weight: 700; white-space: nowrap; }
.br-sheet { position: absolute; right: 16px; bottom: 90px; width: 270px; pointer-events: auto; background: #fff; color: #1d2433; border-radius: 18px; padding: 14px; box-shadow: 0 14px 40px rgba(0,0,0,0.3); }
.br-sheet h4 { margin: 0 24px 4px 0; font-size: 15px; }
.br-sheet .x { position: absolute; right: 8px; top: 8px; background: #f2f5f9; color: #1d2433; border: none; border-radius: 50%; width: 28px; height: 28px; padding: 0; }
.sheet-state { font-weight: 700; margin-bottom: 8px; }
.sheet-row { display: flex; justify-content: space-between; color: #6a7487; font-size: 13px; padding: 3px 0; }
.sheet-row b { color: #1d2433; }
.build-btn { width: 100%; margin-top: 10px; padding: 12px; border: none; border-radius: 14px; font-weight: 900; font-size: 15px; color: #fff; background: linear-gradient(180deg, #2f8cff, #1764d8); box-shadow: 0 4px 0 #0f4aa6; }
.build-btn span { display: block; font-size: 13px; font-weight: 700; opacity: 0.9; }
.build-btn:disabled { background: #b9c2d0; box-shadow: 0 4px 0 #8f99a8; }
.dock-btn.main { background: linear-gradient(180deg, #2f8cff, #1764d8); color: #fff; min-width: 84px; }
.dock-btn.main.on { background: linear-gradient(180deg, #ffcf3d, #f0a91c); color: #1d2433; }
.draw-help { background: #f2f5f9; border-radius: 10px; padding: 8px 10px; font-size: 12px; color: #3a4457; margin: 6px 0; }
.lane-pick { margin: 8px 0; font-size: 12px; color: #6a7487; }
.chips { display: flex; gap: 6px; margin-top: 5px; }
.chip { flex: 1; padding: 7px 0; border-radius: 10px; border: 2px solid #dfe4ec; background: #fff; color: #1d2433; font-weight: 800; }
.chip.on { border-color: #2f8cff; background: #e8f1ff; color: #1764d8; }
.ic-q { font-size: 13px; color: #1d2433; background: #fff7df; border: 1px solid #ffe08a; border-radius: 10px; padding: 8px 10px; margin: 6px 0; }
.ic-q .btns { margin-top: 6px; grid-template-columns: 1fr 1fr; }
.br-sheet .btns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.br-sheet .btns button { background: #f2f5f9; color: #1d2433; border: none; }
.br-sheet b.bad { color: #e5402c; }
.br-sheet .btns .chip { border: 2px solid #dfe4ec; background: #fff; }
.br-sheet .btns .chip.on { border-color: #2f8cff; background: #e8f1ff; color: #1764d8; }
.br-sheet { max-height: calc(100vh - 120px); overflow: auto; }
.lv-badge { display: inline-block; background: var(--accent); color: #fff; font-weight: 900; letter-spacing: 1px; border-radius: 999px; padding: 4px 14px; font-size: 12px; }
.lv-badge.win { background: var(--good); }
.lv-badge.lose { background: var(--bad); }
.modal-card .mn { margin-top: -4px; }
.goal-chip { display: inline-block; background: rgba(255,211,77,0.15); border: 1px solid rgba(255,211,77,0.5); border-radius: 999px; padding: 6px 14px; margin: 4px 0; }
.big-cta { font-weight: 900; letter-spacing: 1px; }
.modal-card .stars .off { color: rgba(255,255,255,0.15); }
.res-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; text-align: left; }
.res-grid > div { background: rgba(255,255,255,0.05); border-radius: 12px; padding: 8px 10px; }
.res-grid label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; }
.res-grid b { font-size: 22px; }
.res-grid b.good { color: var(--good); }
.res-grid b.bad { color: var(--bad); }
.res-grid small { display: block; color: var(--muted); font-size: 11px; }

#hud-map { position: fixed; left: 10px; top: 10px; z-index: 3; }
.map-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; width: 300px; }
.map-card small { display: block; color: var(--muted); margin: 4px 0 8px; }

/* ---------- Phase 2: city bridge planner ---------- */
#panel-big { position: fixed; right: 10px; top: 10px; bottom: 10px; width: 330px; display: flex; flex-direction: column; gap: 10px; overflow: auto; z-index: 3; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; }
.b-cars label { color: var(--muted); font-size: 12px; }
.b-cars input { width: 100%; font: 700 22px system-ui; background: #1a2440; color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; margin: 4px 0; }
.b-cars small { color: var(--muted); font-size: 12px; }
.b-cars details { margin-top: 6px; font-size: 12px; color: var(--muted); }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kpi { background: rgba(255,255,255,0.05); border-radius: 12px; padding: 10px; text-align: center; }
.kpi label { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.kpi b { display: block; font-size: 28px; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); font-size: 11px; }
.kpi.big.good { background: rgba(61,220,132,0.15); border: 1px solid rgba(61,220,132,0.45); }
.kpi.big.good b { color: var(--good); }
.kpi.big.bad { background: rgba(255,90,60,0.15); border: 1px solid rgba(255,90,60,0.45); }
.kpi.big.bad b { color: var(--bad); }
.calc { font-size: 12px; color: var(--muted); }
.calc .bar { height: 6px; margin-top: 4px; }
#b-tools { display: grid; gap: 8px; }
#b-tools button { width: 100%; }
#b-tools .btns { margin: 0; }
.b-km { font-weight: 700; }
#b-drawbar { background: rgba(255,211,77,0.1); border: 1px solid rgba(255,211,77,0.5); border-radius: 12px; padding: 10px; font-size: 13px; }
#b-drawbar small { color: var(--muted); }

@media (max-width: 700px) {
  #panel-big { top: auto; left: 10px; right: 10px; width: auto; height: 48vh; }
  .br-card { width: calc(100vw - 24px); }
  .br-sheet { left: 12px; right: 12px; width: auto; bottom: 86px; }
  .dock-btn { min-width: 0; padding: 6px 8px; }
}

.loading-note { max-width: 320px; text-align: center; font-size: 13px; color: var(--muted); background: rgba(255,255,255,0.06); border-radius: 12px; padding: 10px 14px; }
