:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #17202c;
  --muted: #637386;
  --line: #dfe5ed;
  --accent: #2563eb;
  --accent-soft: #e8f0ff;
  --wall: #2b3a4a;
  --free: #f8fafc;
  --start: #16a34a;
  --goal: #dc2626;
  --path: #f59e0b;
  --trace: #2563eb;
  --head: #7c3aed;
  --ok: #0f766e;
  --bad: #b91c1c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 13px;
  line-height: 1.5;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 22px;
  background: #fff; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: .2px; }
.badge {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  border-radius: 9px; background: var(--accent); color: #fff;
  font-weight: 700; font-size: 14px;
}
.meta { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  background: var(--accent-soft); color: #1d4ed8; font-size: 11px;
  border: 1px solid #cfe0ff; white-space: nowrap;
}
.pill-candidate { background: #fff7e6; color: #a16207; border-color: #fde3a7; }
.pill-muted { background: #f1f4f8; color: var(--muted); border-color: var(--line); }

.banner {
  margin: 14px 22px 0; padding: 11px 16px; border-radius: 10px;
  border: 1px solid var(--line); display: flex; gap: 12px; align-items: baseline;
  background: #fff;
}
.banner strong { font-size: 14px; }
.banner span { color: var(--muted); font-size: 12px; }
.banner-idle { border-left: 4px solid var(--accent); }
.banner-running { border-left: 4px solid var(--path); background: #fffdf6; }
.banner-ok { border-left: 4px solid var(--start); background: #f4fcf7; }
.banner-bad { border-left: 4px solid var(--goal); background: #fff5f5; }
.banner-replay { border-left: 4px solid var(--head); background: #faf6ff; }

.layout {
  display: grid; grid-template-columns: 290px minmax(420px, 1fr) 330px;
  gap: 14px; padding: 14px 22px; align-items: start;
}
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px 16px;
  box-shadow: 0 1px 3px rgba(20, 35, 60, .04);
}
.panel h2 { margin: 0 0 12px; font-size: 14px; font-weight: 650; }
.panel h3 {
  margin: 16px 0 8px; font-size: 12px; font-weight: 650;
  color: var(--muted); text-transform: uppercase; letter-spacing: .5px;
}
.field { display: block; margin-bottom: 11px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
/* FINAL_LAYOUT_POLISH: one-line strategy summary under the selector
   (mobile-friendly; reflects the CURRENT selector value). */
.strategy-summary {
  display: block; margin-top: 4px; font-size: 11px; color: #1d4ed8;
  background: var(--accent-soft); border-radius: 6px; padding: 4px 8px;
  line-height: 1.45; word-break: break-word;
}
select, input {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line);
  border-radius: 7px; background: #fff; color: var(--ink); font-size: 13px;
  font-family: inherit;
}
select:focus, input:focus { outline: 2px solid #bfd4ff; border-color: var(--accent); }

.mode-row { display: flex; gap: 6px; }
.btn {
  padding: 7px 10px; border: 1px solid var(--line); background: #fff;
  color: var(--ink); border-radius: 7px; cursor: pointer;
  font-size: 12px; font-family: inherit; transition: .12s;
}
.btn:hover { border-color: #a9bddc; background: #f7faff; }
.btn:active { transform: translateY(1px); }
.btn-mode { flex: 1; }
.btn-mode.active { background: var(--accent-soft); border-color: #a9c6ff; color: #1d4ed8; font-weight: 600; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #1d4ed8; }
.btn-replay { background: #f5f0ff; border-color: #d9c8ff; color: #6d28d9; }
.btn-history { background: #eef7ff; border-color: #bcd8ff; color: #1d4ed8; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 4px; }
/* REPLAY_UI_SIMPLIFY: 回放 / 载入历史探索 sit side-by-side on PC and wrap
   naturally on narrow screens (2-column grid); no full-row span. */
.btn-grid .btn-replay, .btn-grid .btn-history { grid-column: auto; }

.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.kv-stack { grid-template-columns: 1fr; gap: 3px; }
.kv > div {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 4px 7px; background: #f7f9fc; border-radius: 6px;
}
.kv span { color: var(--muted); font-size: 11px; }
.kv b { font-size: 11px; font-weight: 600; font-family: Consolas, "Courier New", monospace;
        word-break: break-all; text-align: right; }

.records { display: grid; gap: 4px; }
.rec { display: flex; align-items: center; gap: 7px; font-size: 11px;
       padding: 4px 6px; background: #f7f9fc; border-radius: 6px; }
.rec span { color: var(--muted); flex: 1; }
.rec b { font-family: Consolas, monospace; font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-req { background: #6d28d9; } .dot-flt { background: var(--path); }
.dot-eff { background: var(--start); }

.hint { color: var(--muted); font-size: 11px; margin: 8px 0 0; }

.stage-head, .events-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stage-head h2, .events-head h2 { margin-bottom: 8px; }
.legend { display: flex; gap: 9px; flex-wrap: wrap; font-size: 11px; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 4px; }
.sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; border: 1px solid rgba(0,0,0,.08); }
.sw-wall { background: var(--wall); } .sw-start { background: var(--start); }
.sw-goal { background: var(--goal); } .sw-path { background: var(--path); }
.sw-trace { background: var(--trace); }

#canvas {
  display: block; width: 440px; max-width: 100%; height: auto;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
  cursor: crosshair;
  margin: 0 auto;               /* FINAL_LAYOUT_POLISH: centre in wide panes */
}
.stage-foot { display: flex; justify-content: space-between; align-items: center;
              margin-top: 10px; font-size: 11px; color: var(--muted); }
code { background: #eef2f7; padding: 2px 5px; border-radius: 4px;
       font-family: Consolas, monospace; color: #1d4ed8; }

.event-list {
  height: 470px; overflow-y: auto; border: 1px solid var(--line);
  border-radius: 8px; background: #fbfcfe; margin-top: 10px;
}
.ev {
  display: grid; grid-template-columns: 30px 1fr auto; gap: 7px;
  padding: 5px 8px; border-bottom: 1px solid #eef1f6; font-size: 11px;
  align-items: center;
}
.ev:last-child { border-bottom: none; }
.ev-id { color: var(--muted); font-family: Consolas, monospace; }
.ev-kind { font-weight: 600; }
.ev-src { font-size: 10px; color: var(--muted); font-family: Consolas, monospace; }
.ev.algorithm .ev-kind { color: #6d28d9; }
.ev.safety .ev-kind { color: #b45309; }
.ev.adapter .ev-kind { color: #0f766e; }
.ev.runner .ev-kind { color: #1d4ed8; }
.ev.active { background: #fff4d6; }
.ev-empty { padding: 14px; color: var(--muted); font-size: 11px; text-align: center; }

.footer {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 22px 22px; color: var(--muted); font-size: 11px;
}
/* ICP filing link (public deployment requirement).*/
.footer-icp a { color: var(--muted); text-decoration: none; }
.footer-icp a:hover { text-decoration: underline; }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr; }
  .event-list { height: 300px; }
}

/* ---------------- L5 LiDAR exploration mode ---------------- */
[hidden] { display: none !important; }
.tabs {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 22px 0; flex-wrap: wrap;
}
.tab {
  padding: 8px 16px; border: 1px solid var(--line); border-bottom: none;
  background: #eef2f7; color: var(--muted); cursor: pointer;
  border-radius: 9px 9px 0 0; font: inherit; font-size: 12px;
}
.tab:hover { background: #e4ebf5; }
.tab.active {
  background: #fff; color: #1d4ed8; font-weight: 650;
  border-color: var(--line); box-shadow: inset 0 2px 0 var(--accent);
}
.tabs-note { margin-left: auto; color: var(--muted); font-size: 11px; }
.layout-lidar { grid-template-columns: 300px minmax(540px, 1fr) 330px; }

#lidar-canvas {
  display: block; width: 720px; max-width: 100%; height: auto;
  border: 1px solid var(--line); border-radius: 8px; background: #e7ecf2;
  image-rendering: pixelated;
  touch-action: manipulation;
  margin: 0 auto;               /* FINAL_LAYOUT_POLISH: centre in wide panes */
}
.lidar-legend { margin-bottom: 8px; }
.sw-unknown { background: #e7ecf2; }
.sw-free { background: #ffffff; }
.sw-ray { background: #f97316; }
.sw-head { background: var(--head); }
.sw-wall { background: var(--wall); }

.field-seek { margin-top: 14px; }
.field-seek input[type="range"] { padding: 0; border: none; }
.progress {
  height: 6px; border-radius: 999px; background: #e9eef5;
  overflow: hidden; margin-top: 2px;
}
.progress > div {
  height: 100%; width: 0; border-radius: 999px;
  background: var(--accent); transition: width .18s ease;
}
.changes {
  margin-top: 8px; max-height: 180px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 8px;
  background: #fbfcfe; padding: 8px; font-size: 11px;
}
.chg { padding: 3px 0; border-bottom: 1px dashed #e9eef5; font-family: Consolas, monospace; }
.chg:last-child { border-bottom: none; }
.chg-empty { color: var(--muted); }

/* ---------------- FINAL_LAYOUT_POLISH: diagnostics workbench ----------- */
/* Right rail: 事件流 / 规划变更 rotate in the SAME panel area (desktop). */
.dx-tabs { display: flex; gap: 4px; }
.dx-tab {
  padding: 4px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: #f1f4f8; color: var(--muted); cursor: pointer;
  font: inherit; font-size: 11px; line-height: 1.4;
}
.dx-tab:hover { background: #e4ebf5; }
.dx-tab.active {
  background: var(--accent-soft); color: #1d4ed8; font-weight: 600;
  border-color: #a9c6ff;
}
/* Compact empty states: one line, small type; never stretch the rail. */
.ev-empty, .chg-empty { padding: 8px 10px; font-size: 11px; line-height: 1.5; }
#dx-changes-wrap .hint { margin: 10px 0 0; }

/* Mobile single-panel switch: hidden on desktop, shown below 640px. */
.mobile-switch { display: none; }

@media (max-width: 1180px) {
  .layout-lidar { grid-template-columns: 1fr; }
}

/* ---------------- F4: collapsible config / stats + responsive --------- */
.lid-config {
  margin: 10px 0; border: 1px solid var(--line);
  border-radius: 8px; background: #fbfcfe; overflow: hidden;
}
.lid-config > summary {
  cursor: pointer; padding: 8px 12px; font-size: 12px; font-weight: 600;
  color: #1d4ed8; background: #f4f7fc; user-select: none;
  list-style: none; display: flex; align-items: center; gap: 6px;
}
.lid-config > summary::-webkit-details-marker { display: none; }
.lid-config > summary::before {
  content: '▸'; display: inline-block; transition: transform .15s; color: var(--muted);
}
.lid-config[open] > summary::before { transform: rotate(90deg); }
.lid-config-body { padding: 10px 12px 12px; border-top: 1px solid var(--line); }
.lid-config-body .field:first-child { margin-top: 4px; }

/* ---------------- UAV_MAZE_V2_2D_WEB_CONTROL_REPLAY_FIX_01 ----------- */
/* Explore-mode selector (realtime / fast): only paces the UI snapshot
   cadence, never the algorithm or runner behaviour. */
.field-mode { margin: 12px 0 4px; }
.field-mode > span { display: block; font-size: 12px; color: var(--muted);
                     margin-bottom: 5px; }
.field-mode .mode-row { margin-bottom: 0; }
.field-mode select {
  font-size: 13px; padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 7px;
  background: #fff; color: var(--ink); font-family: inherit; cursor: pointer;
}
.field-mode select:focus { outline: 2px solid #bfd4ff; border-color: var(--accent); }
#lid-explore-mode-note { margin: 4px 0 0; }

/* REPLAY_UI_SIMPLIFY: the purple replay panel (duplicate 退出回放 button,
   long explanation, run_id input) was REMOVED. The only replay entrance is
   the grid 回放 button; 载入历史探索 is a fixed one-click preset. Playback
   controls (暂停/继续, 倍速, 跳到末帧) live in the seek bar below. */
/* REPLAY_SIMPLIFY_AND_SPEED: 暂停/继续回放 + 倍速 concentrated next to the
   seek bar (one entrance button, one place for playback state). */
.replay-controls {
  display: flex; align-items: center; gap: 10px;
  margin: 8px 0 4px;
}
.btn-replay-mini { flex: 0 0 auto; padding: 5px 12px; font-size: 12px; }
.field-speed-mini {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; margin: 0; color: var(--muted);
}
.field-speed-mini select { width: auto; padding: 4px 6px; font-size: 12px; }
#lid-replay-pause:disabled, #lid-replay-speed:disabled,
#lid-replay-jump-end:disabled { opacity: .45; cursor: not-allowed; }
.btn:disabled {
  opacity: .55; cursor: not-allowed; transform: none;
  background: #e9eef5; border-color: var(--line); color: var(--muted);
}
.btn:disabled:hover { background: #e9eef5; border-color: var(--line); }
.btn:disabled:active { transform: none; }
.btn:disabled.btn-primary { background: #a9c0e8; border-color: #a9c0e8; color: #fff; }

/* F4: mobile portrait — map first, run controls above the fold, config and
   stats one tap away inside collapsibles. No file/JS duplication: grid order
   moves the stage to the first slot and the button grid to the top of the
   control panel; everything else stays in the normal flex order. */
@media (max-width: 640px) {
  body { font-size: 13px; }
  .topbar { padding: 10px 12px; }
  .topbar .meta { display: none; }                       /* pills: desktop only */
  .tabs { padding: 8px 10px 0; gap: 6px; }
  .tabs-note { display: none; }
  .tab { flex: 1; text-align: center; padding: 9px 4px; font-size: 12px; }
  .layout, .layout-lidar { grid-template-columns: 1fr; padding: 10px 10px 0; gap: 10px; }

  /* map first: stage occupies slot 1, controls and events follow */
  .layout > .stage { order: 1; }
  .layout > .controls { order: 2; }
  .layout > .events { order: 3; }

  /* inside the control panel: LENSED to the lidar view so the A* control
     panel keeps its own order. Fixed lanes: title -> main buttons -> switch
     row -> ROTATING 参数/状态/事件 panels -> field-mode -> seek row ->
     the non-rotating collapsibles (scene/ident) at the end (default order 0). */
  #lidar-view > .controls { display: flex; flex-direction: column; }
  #lidar-view .controls > h2,
  #lidar-view .controls > .hint { order: -70; }
  #lidar-view .controls > .btn-grid { order: -60; }
  #lidar-view .controls > .mobile-switch { order: -50; }
  /* the three rotating panels share the SAME order:-40 area right under
     the switch row: config / run-stats / re-hosted events rail */
  #lidar-view .controls > #lid-config,
  #lidar-view .controls > #lid-run-stats,
  #lidar-view .controls > #lid-events-panel { order: -40; }
  #lidar-view .controls > .field-mode { order: -30; }
  #lidar-view .controls > .field-seek { order: -20; }
  #lidar-view .controls > .progress { order: -19; }

  /* FINAL_LAYOUT_POLISH: mobile single-panel switch — the three entry
     buttons 参数/状态/事件 sit right under the button grid; the events rail
     hides on phones (events re-host as the third switch panel, sharing the
     SAME order:-40 area as the config/stats collapsibles). */
  .mobile-switch {
    display: flex; gap: 6px; margin: 8px 0 4px;
  }
  /* the re-hosted events rail shares the rotating slot with the two cards */
  #lidar-view .controls > #lid-events-panel { margin: 10px 0; }
  .ms-btn {
    flex: 1; padding: 8px 6px; font-size: 13px; text-align: center;
    border: 1px solid var(--line); border-radius: 8px; background: #fff;
    color: var(--muted); cursor: pointer; font: inherit;
  }
  .ms-btn.active {
    background: var(--accent-soft); border-color: #a9c6ff;
    color: #1d4ed8; font-weight: 600;
  }
  /* the desktop events rail does not participate in the phone flow */
  .layout > .events { display: none; }

  /* FINAL_LAYOUT_POLISH: on short mobile viewports the L5 map shrinks to a
     centred 340px square so the standing button row stays above the fold
     (verified at 390x844: the 100%-width 348px canvas + scan note pushed
     the main controls below the first screen). The scan note under the map
     hides on phones; the legend and title remain. */
  #canvas { width: 100%; }
  /* 320px keeps the standing button row above the fold on 390px-wide phones:
     340px + hidden note left controls ~726px (past the 85% line at 717px). */
  #lidar-canvas { width: min(100%, 320px); height: auto; margin: 0 auto; display: block; }
  #lid-stage-note { display: none; }
  .stage-foot { flex-direction: column; gap: 4px; align-items: flex-start; }
  .btn-grid .btn { padding: 11px 6px; font-size: 13px; }
  .event-list { height: 260px; }
  .changes { max-height: 140px; }
  .footer { padding: 10px 12px 18px; }
  .lid-config > summary { padding: 10px 12px; font-size: 13px; }
}
