:root {
  --bg: rgba(10, 16, 30, 0.82);
  --bg2: rgba(30, 41, 59, 0.7);
  --line: rgba(148, 163, 184, 0.22);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --red: #ef4444;
  --orange: #f97316;
  --yellow: #eab308;
  --blue: #3b82f6;
  --green: #22c55e;
  --cyan: #22d3ee;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b1220; }
body { font-family: 'Kanit', 'Leelawadee UI', system-ui, sans-serif; color: var(--text); font-size: 14px; font-weight: 300; }
b, h1, h2 { font-weight: 500; }
button { font: inherit; color: inherit; cursor: pointer; }
kbd { font-family: inherit; font-size: 11px; padding: 0 5px; border-radius: 4px; border: 1px solid var(--line); background: rgba(255,255,255,.08); margin-left: 4px; }

#stage, #stage canvas { position: fixed; inset: 0; }
.labels { position: fixed !important; inset: 0; pointer-events: none; }

/* ---------- 3D labels ---------- */
.lbl { background: rgba(15, 23, 42, .78); color: #fff; padding: 2px 8px; border-radius: 6px; font-size: 12px; white-space: nowrap; border: 1px solid rgba(255,255,255,.15); }
.sos-lbl { text-align: center; line-height: 1.25; font-size: 12px; border-color: #facc15; }
.sos-lbl.active { background: rgba(185, 28, 28, .9); border-color: #fecaca; animation: pulse 1s infinite; }
.road-lbl { font-size: 11px; opacity: .85; }
.road-lbl.jam { background: rgba(220, 38, 38, .9); }
.road-lbl.clear { background: rgba(22, 163, 74, .85); }
.qr-lbl { font-size: 10px; padding: 1px 5px; background: rgba(255,255,255,.9); color: #111; }
.drone-lbl { font-size: 11px; border-width: 2px; }
.base-lbl { font-size: 12px; }
.coord-lbl { display: none; font-size: 10px; background: rgba(124, 58, 237, .85); font-family: ui-monospace, monospace; }
body.show-coords .coord-lbl { display: block; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); } 0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, .7); } }

/* ---------- HUD layout ---------- */
.hud { position: fixed; z-index: 10; }
.panel { background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 12px; backdrop-filter: blur(8px); box-shadow: 0 8px 30px rgba(0,0,0,.35); }
h2 { font-size: 14px; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; color: #cbd5e1; }
h2 .btn { margin-left: auto; }

.top { top: 10px; left: 10px; right: 10px; height: 58px; display: flex; align-items: center; gap: 16px; padding: 0 14px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 14px; backdrop-filter: blur(8px); }
.brand { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 28px; }
.brand h1 { font-size: 16px; margin: 0; letter-spacing: 1px; color: #fff; }
.brand small { color: var(--cyan); font-size: 11px; letter-spacing: 1px; }
.stats { display: flex; gap: 6px; margin: 0 auto; }
.stats div { background: var(--bg2); border-radius: 10px; padding: 3px 12px; text-align: center; min-width: 74px; }
.stats small { display: block; font-size: 10px; color: var(--muted); }
.stats b { font-size: 17px; color: #fff; font-variant-numeric: tabular-nums; }
.tools { display: flex; gap: 8px; align-items: center; }
.seg { display: flex; background: var(--bg2); border-radius: 10px; padding: 3px; }
.seg button { background: none; border: 0; padding: 4px 10px; border-radius: 8px; color: var(--muted); font-size: 13px; }
.seg button.on { background: var(--blue); color: #fff; }
.icon { background: var(--bg2); border: 0; border-radius: 10px; width: 36px; height: 34px; }

.left { top: 78px; left: 10px; bottom: 96px; width: 350px; display: flex; flex-direction: column; }
.left .scroll { overflow-y: auto; flex: 1; margin: 0 -4px; padding: 0 4px; }
.right { top: 78px; right: 10px; bottom: 10px; width: 380px; display: flex; flex-direction: column; gap: 8px; }
.right .grow { flex: 1; min-height: 80px; display: flex; flex-direction: column; }
.opt { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-bottom: 8px; cursor: pointer; }
.badge { background: var(--red); color: #fff; border-radius: 99px; padding: 0 8px; font-size: 12px; }

/* ---------- buttons ---------- */
.btn { border: 0; border-radius: 10px; padding: 7px 14px; background: var(--blue); color: #fff; font-weight: 500; transition: filter .15s, transform .1s; }
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(.97); }
.btn.go { background: linear-gradient(135deg, #16a34a, #22c55e); box-shadow: 0 4px 14px rgba(34,197,94,.35); }
.btn.ghost { background: rgba(255,255,255,.06); border: 1px solid var(--line); color: var(--text); font-weight: 400; }
.btn.tiny { padding: 2px 8px; font-size: 11px; border-radius: 7px; }
.btn.big { font-size: 18px; padding: 12px 34px; border-radius: 14px; }

/* ---------- incidents ---------- */
.empty { text-align: center; color: var(--muted); padding: 40px 0; line-height: 1.8; }
.inc { background: var(--bg2); border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: 12px; padding: 10px; margin-bottom: 8px; animation: slide .3s ease-out; }
@keyframes slide { from { transform: translateX(-20px); opacity: 0; } }
.inc.s-new { border-left-color: var(--red); background: rgba(127, 29, 29, .35); }
.inc.s-queued { border-left-color: var(--yellow); }
.inc.s-dispatched, .inc.s-enroute, .inc.s-returning { border-left-color: var(--blue); }
.inc.s-onscene { border-left-color: var(--orange); }
.inc.s-completed { border-left-color: var(--green); opacity: .85; }
.inc.s-cancelled { opacity: .5; }
.inc-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.inc-id { color: var(--muted); font-size: 12px; }
.zone { color: var(--muted); font-size: 12px; }
.pill { margin-left: auto; font-size: 11px; padding: 1px 8px; border-radius: 99px; background: rgba(255,255,255,.1); }
.s-new .pill { background: var(--red); color: #fff; animation: pulse 1s infinite; }
.s-onscene .pill { background: var(--orange); color: #fff; }
.s-completed .pill { background: var(--green); color: #052e16; }
.steps { display: flex; gap: 2px; margin: 8px 0 4px; }
.steps span { flex: 1; font-size: 9.5px; text-align: center; padding: 2px 0; border-radius: 4px; background: rgba(255,255,255,.06); color: var(--muted); }
.steps .done { background: rgba(34,197,94,.25); color: #86efac; }
.steps .now { background: var(--blue); color: #fff; }
.assess { display: flex; gap: 10px; align-items: center; margin-top: 8px; padding: 8px; border-radius: 10px; background: color-mix(in srgb, var(--c) 18%, transparent); border: 1px solid var(--c); }
.assess .big { font-size: 30px; }
.assess .sev { color: var(--c); font-weight: 500; }
.assess code { font-size: 10px; color: var(--muted); }
.assess .qr { width: 46px; height: 46px; margin-left: auto; image-rendering: pixelated; border-radius: 4px; }
.pending { margin-top: 8px; font-size: 12px; color: var(--cyan); animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .45; } }
.snap { margin-top: 8px; position: relative; }
.snap img { width: 100%; border-radius: 8px; display: block; border: 1px solid var(--line); }
.snap span { position: absolute; left: 6px; bottom: 6px; font-size: 10px; background: rgba(0,0,0,.6); padding: 1px 6px; border-radius: 4px; }
.meta { font-size: 11px; color: var(--muted); margin-top: 6px; }
.actions { display: flex; gap: 6px; margin-top: 8px; align-items: center; flex-wrap: wrap; }
.hint { font-size: 11px; color: var(--yellow); flex: 1; }
.history { margin-top: 6px; color: var(--muted); font-size: 12px; max-height: 30%; overflow-y: auto; }
.history summary { cursor: pointer; margin-bottom: 6px; }

/* ---------- FPV ---------- */
.fpv { padding: 8px; }
.fpv-head { display: flex; align-items: center; gap: 8px; font-size: 12px; margin-bottom: 6px; }
.rec { color: var(--red); font-weight: 600; animation: blink 1s infinite; }
.tabs { margin-left: auto; display: flex; gap: 2px; }
.tabs button { background: var(--bg2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 8px; font-size: 11px; color: var(--muted); }
.tabs button.on { background: var(--cyan); color: #083344; border-color: var(--cyan); }
#fpv-view { position: relative; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; background: #000; }
#fpv-view canvas { display: block; width: 100% !important; height: 100% !important; }
.osd { position: absolute; font-size: 11px; color: #a7f3d0; text-shadow: 0 1px 2px #000; font-family: ui-monospace, Consolas, monospace; }
.osd b { color: #fff; font-weight: 500; }
.tl { top: 6px; left: 8px; font-family: inherit; color: #fff; }
.tr { top: 6px; right: 8px; display: flex; align-items: center; gap: 4px; }
.bl { bottom: 6px; left: 8px; }
.br { bottom: 6px; right: 8px; }
#fpv-bat.low { color: var(--red); }
.led-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; border: 1px solid rgba(255,255,255,.4); }
.cross { position: absolute; left: 50%; top: 50%; width: 30px; height: 30px; transform: translate(-50%, -50%); border: 1px solid rgba(255,255,255,.35); border-radius: 50%; }
.cross::before, .cross::after { content: ''; position: absolute; background: rgba(255,255,255,.35); }
.cross::before { left: 50%; top: -8px; bottom: -8px; width: 1px; }
.cross::after { top: 50%; left: -8px; right: -8px; height: 1px; }
.standby { position: absolute; inset: 0; display: grid; place-items: center; color: rgba(255,255,255,.7); font-size: 13px; letter-spacing: 2px; background: rgba(0,0,0,.25); }
.standby[hidden], #scan-box[hidden] { display: none; }
#scan-box { position: absolute; width: 70px; height: 70px; transform: translate(-50%, -50%); transition: left .1s, top .1s; }
#scan-box i { position: absolute; inset: 0; border: 2px solid #22c55e; border-radius: 6px; box-shadow: 0 0 12px #22c55e; animation: scan .5s ease-out; }
@keyframes scan { from { transform: scale(2); opacity: 0; } }
#scan-text { position: absolute; top: 74px; left: 50%; transform: translateX(-50%); white-space: nowrap; background: #16a34a; color: #fff; font-size: 10px; padding: 1px 6px; border-radius: 4px; font-family: ui-monospace, monospace; }

/* ---------- drones / traffic / log ---------- */
.drone { display: flex; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 10px; background: var(--bg2); margin-bottom: 6px; cursor: pointer; border: 1px solid transparent; }
.drone.sel { border-color: var(--cyan); }
.drone .led { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.d-main { flex: 1; }
.d-state { font-size: 11px; color: var(--muted); }
.bat { position: relative; height: 14px; background: rgba(255,255,255,.08); border-radius: 7px; overflow: hidden; margin-top: 3px; }
.bat i { position: absolute; inset: 0 auto 0 0; border-radius: 7px; transition: width .3s; }
.bat span { position: relative; font-size: 10px; padding-left: 6px; color: #fff; text-shadow: 0 1px 1px #000; }
.road { padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.road:last-child { border: 0; }
.chip { font-size: 10.5px; padding: 0 6px; border-radius: 99px; margin-left: 4px; }
.chip.unk { background: rgba(255,255,255,.08); color: var(--muted); }
.chip.jam { background: rgba(239,68,68,.25); color: #fca5a5; }
.chip.ok { background: rgba(34,197,94,.2); color: #86efac; }
.suggest { color: var(--yellow); font-size: 12px; margin-top: 2px; }
.by { color: var(--muted); font-size: 10.5px; }
.log { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; font-size: 12px; }
.log li { display: flex; gap: 6px; padding: 3px 0; border-bottom: 1px solid var(--line); }
.log time { color: #64748b; font-variant-numeric: tabular-nums; flex: none; }
.log .alert { color: #fca5a5; }
.log .warn { color: #fde68a; }

/* ---------- SOS bar ---------- */
.sosbar { left: 10px; right: 400px; bottom: 10px; height: 76px; display: flex; align-items: center; gap: 10px; padding: 0 14px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 14px; backdrop-filter: blur(8px); }
.sos-title { font-size: 12px; color: var(--muted); writing-mode: horizontal-tb; max-width: 60px; line-height: 1.2; }
.sos { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 118px; height: 58px; border-radius: 14px; border: 2px solid #fecaca;
  background: radial-gradient(circle at 50% 30%, #f87171, #b91c1c); box-shadow: 0 4px 0 #7f1d1d, 0 6px 16px rgba(239,68,68,.4); color: #fff; line-height: 1.1; transition: transform .08s, box-shadow .08s; }
.sos:active { transform: translateY(3px); box-shadow: 0 1px 0 #7f1d1d; }
.sos b { font-size: 16px; letter-spacing: 1px; }
.sos small { font-size: 10.5px; opacity: .9; }
.sos kbd { position: absolute; margin: -44px 0 0 92px; }
.sos { position: relative; }
.sosbar .opt { margin: 0 0 0 auto; }

/* ---------- toasts ---------- */
#toasts { position: fixed; top: 80px; left: 50%; transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { background: rgba(15,23,42,.95); border: 1px solid var(--line); padding: 8px 18px; border-radius: 12px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.4); animation: drop .3s ease-out; transition: opacity .4s, transform .4s; }
.toast.alert { background: linear-gradient(135deg, #b91c1c, #ef4444); border-color: #fecaca; font-weight: 500; }
.toast.warn { background: linear-gradient(135deg, #a16207, #ca8a04); }
.toast.ok { background: linear-gradient(135deg, #15803d, #22c55e); }
.toast.out { opacity: 0; transform: translateY(-10px); }
@keyframes drop { from { transform: translateY(-20px); opacity: 0; } }

/* ---------- intro ---------- */
#intro { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: radial-gradient(ellipse at center, rgba(15,23,42,.75), rgba(2,6,23,.95)); transition: opacity .6s; }
#intro.hide { opacity: 0; pointer-events: none; }
.intro-card { max-width: 640px; text-align: center; padding: 32px 40px; background: var(--bg); border: 1px solid var(--line); border-radius: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.intro-logo { font-size: 56px; animation: hover 2s ease-in-out infinite; }
@keyframes hover { 50% { transform: translateY(-8px); } }
.intro-card h1 { margin: 6px 0 2px; font-size: 30px; color: #fff; letter-spacing: 1px; }
.sub { color: var(--cyan); margin: 0 0 18px; }
.flow { text-align: left; list-style: none; padding: 0; margin: 0 0 22px; display: grid; gap: 8px; }
.flow li { display: flex; gap: 10px; align-items: flex-start; background: var(--bg2); border-radius: 10px; padding: 7px 12px; font-size: 14px; }
.flow span { width: 22px; text-align: center; flex: none; }
.flow b { color: #fff; }
.keys { color: var(--muted); font-size: 12px; margin: 16px 0 0; }

@media (max-width: 1280px) {
  .left { width: 300px; }
  .right { width: 320px; }
  .sosbar { right: 340px; }
  .stats div:nth-child(5) { display: none; }
  .sos { width: 96px; }
}
