:root {
  color-scheme: dark;
  --bg: #0b0c0e;
  --surface: #16181c;
  --surface-2: #1f2228;
  --line: #2c3038;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #8d8c86;
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --good: #2fb36b;
  --warn: #e0a400;
  --bad: #e66767;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, "Noto Sans TC", "PingFang TC", sans-serif; -webkit-tap-highlight-color: transparent; }
body { padding-bottom: env(safe-area-inset-bottom); overflow-x: hidden; }
h1 { font-size: 22px; line-height: 1.3; margin: 0 0 12px; }
h2 { font-size: 17px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.fine { font-size: 12px; color: var(--muted); margin-top: 12px; }
.warn { color: var(--warn); }
[hidden] { display: none !important; }

.top { position: sticky; top: 0; z-index: 1000; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 16px 8px; background: rgba(11, 12, 14, .92); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.logo { width: 20px; height: 20px; border-radius: 6px; background: radial-gradient(circle at 30% 35%, #3987e5 0 3px, transparent 4px), radial-gradient(circle at 70% 40%, #d95926 0 3px, transparent 4px), radial-gradient(circle at 45% 72%, #199e70 0 3px, transparent 4px), var(--surface-2); }
.chip { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; background: var(--surface); color: var(--text); border: 1px solid var(--line); font: inherit; font-size: 13px; max-width: 62vw; }
.chip span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--good); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }

.screen { padding: 12px 16px 24px; max-width: 760px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 16px; }
.lead { font-size: 16px; }
.promise { padding-left: 20px; margin: 0 0 14px; color: var(--text-2); }
.promise li { margin-bottom: 6px; }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; color: var(--text-2); }
.check input { width: 20px; height: 20px; margin-top: 2px; flex: none; accent-color: var(--accent); }

.btn { appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font: inherit; padding: 10px 14px; border-radius: 10px; min-height: 44px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; width: 100%; margin-top: 8px; }
.btn.ghost { background: transparent; }
.btn.danger { border-color: var(--bad); color: var(--bad); background: transparent; }
.btn.small { min-height: 36px; padding: 6px 10px; }
.btn:disabled { opacity: .45; }
.btn.file { position: relative; }
.row { display: flex; gap: 8px; margin: 10px 0; }
.row > .btn { flex: 1; }
.row.wrap { flex-wrap: wrap; }
.row.wrap > .btn { flex: 1 1 calc(50% - 8px); }

.steps { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0 0 10px; counter-reset: s; }
.steps li { flex: 1; text-align: center; font-size: 13px; padding: 6px 4px; border-radius: 8px; background: var(--surface); color: var(--muted); counter-increment: s; }
.steps li::before { content: counter(s) " "; font-weight: 700; }
.steps li.on { background: var(--surface-2); color: var(--text); outline: 1px solid var(--accent); }
.steps li.done { color: var(--text-2); }

.stage { --ar: 4 / 3; position: relative; width: min(100%, calc(62vh * var(--ar))); margin: 0 auto; aspect-ratio: var(--ar); background: #000; border-radius: var(--radius); overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.stage video { width: 100%; height: 100%; object-fit: contain; display: block; transform-origin: 0 0; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; transform-origin: 0 0; }
.stage-hint { position: absolute; left: 8px; right: 8px; bottom: 8px; font-size: 12px; color: #fff; background: rgba(0, 0, 0, .55); padding: 4px 8px; border-radius: 6px; pointer-events: none; }
.stage-hint:empty { display: none; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.kv { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.kv span { display: block; font-size: 12px; color: var(--text-2); }
.kv b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.field { display: block; margin: 10px 0; color: var(--text-2); font-size: 13px; }
.field input, .field select { display: block; width: 100%; margin-top: 4px; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font: inherit; font-size: 15px; }
.slider { display: grid; grid-template-columns: 44px 1fr 56px; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); margin: 4px 0; }
.slider input { width: 100%; accent-color: var(--accent); }
.slider output { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; margin-bottom: 10px; }
.seg button { flex: 1; border: 0; background: transparent; color: var(--text-2); font: inherit; padding: 8px; border-radius: 8px; min-height: 40px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.minimap { height: 230px; border-radius: 10px; margin-top: 10px; overflow: hidden; }

.zones { list-style: none; padding: 0; margin: 0 0 8px; max-height: 260px; overflow: auto; }
.zones li { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.zones li input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.zones .sw { width: 14px; height: 14px; border-radius: 3px; flex: none; }
.zones .nm { flex: 1; min-width: 0; }
.zones .tp { font-size: 12px; color: var(--text-2); }
.zones button { border: 0; background: none; color: var(--text-2); font: inherit; font-size: 13px; padding: 6px; }
.drawbar { display: flex; align-items: center; gap: 8px; background: var(--surface-2); padding: 8px; border-radius: 10px; }
.drawbar span { flex: 1; font-size: 13px; }

.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tabs button { flex: 1; border: 1px solid var(--line); background: var(--surface); color: var(--text-2); font: inherit; padding: 8px; border-radius: 10px; min-height: 40px; }
.tabs button.on { background: var(--surface-2); color: var(--text); border-color: var(--accent); }
.runmap { position: relative; height: 56vh; min-height: 300px; border-radius: var(--radius); overflow: hidden; }
#runMap { position: absolute; inset: 0; background: #111; }
#pcanvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 500; }
.leaflet-tile-pane.darkmap { filter: invert(1) hue-rotate(180deg) brightness(.75) contrast(.9); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; margin: 8px 2px; font-size: 13px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; margin-right: 5px; vertical-align: -1px; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 8px 0; }
@media (max-width: 480px) { .cards { grid-template-columns: repeat(2, 1fr); } }
.peek { margin-top: 10px; }

.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--text-2); font-weight: 600; }
td.num, th.num { text-align: right; }

.chartbox { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
#shopChart { width: 100%; display: block; }
.tip { position: absolute; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 12px; pointer-events: none; white-space: nowrap; }

.black { position: fixed; inset: 0; z-index: 5000; background: #000; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #555; }
.black p { color: #444; }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 4000; background: var(--surface-2); border: 1px solid var(--line); padding: 10px 14px; border-radius: 10px; font-size: 14px; }
.leaflet-container { font: inherit; }
.num-ic { background: var(--accent); color: #fff; border-radius: 50%; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; border: 2px solid #fff; }

#scr-setup .stage { position: sticky; top: 58px; z-index: 900; }

/* v0.12 4 點校正：地圖十字、較高的小地圖 */
.minimap { position: relative; }
.minimap.pts { height: 45vh; }
.minimap .cross { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; pointer-events: none; z-index: 800; }
.minimap .cross::before, .minimap .cross::after { content: ''; position: absolute; background: #ff3b3b; box-shadow: 0 0 0 1px #000; }
.minimap .cross::before { left: 21px; top: 0; width: 2px; height: 44px; }
.minimap .cross::after { top: 21px; left: 0; height: 2px; width: 44px; }
.minimap .cross { border: 2px solid rgba(255,59,59,.6); border-radius: 50%; }
.resid-bad { color: #e66767; font-weight: 600; }
.num-ic.sg { background: #ff9f1c; color: #000; }
