:root {
  --bg: #0d1520;
  --surface: rgba(18, 28, 41, 0.94);
  --surface-2: #1a2738;
  --surface-3: #22334a;
  --line: rgba(148, 178, 210, 0.16);
  --text: #e8eef5;
  --muted: #93a6bb;
  --accent: #4fb3ff;
  --accent-ink: #04131f;
  --ok: #3ccf8e;
  --warn: #f2b84b;
  --bad: #ff6b6b;
  --magenta: #e05cff;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --panel-w: 400px;
  --top-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #e9edf2;
  --surface: rgba(255, 255, 255, 0.96);
  --surface-2: #f1f4f8;
  --surface-3: #e3e9f0;
  --line: rgba(20, 40, 70, 0.12);
  --text: #122033;
  --muted: #5b6b7e;
  --accent: #0a74d6;
  --accent-ink: #ffffff;
  --shadow: 0 8px 24px rgba(20, 40, 70, 0.18);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased; overflow: hidden; overscroll-behavior: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.num { font-variant-numeric: tabular-nums; }

#map { position: fixed; inset: 0; z-index: 0; background: #1b2633; }
:root[data-theme="light"] #map { background: #dfe5ec; }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { font-size: 10px; background: rgba(0,0,0,.35) !important; color: #c6d2de !important; }
.leaflet-control-attribution a { color: #c6d2de !important; }

/* ---------------------------------------------------------------- top bar */
.topbar { position: fixed; z-index: 30; top: calc(10px + var(--safe-t)); left: 10px; right: 10px; height: 44px;
  display: flex; align-items: center; gap: 8px; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 12px 0 8px; border-radius: 22px;
  background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--line); }
.brand img { width: 28px; height: 28px; border-radius: 7px; }
.brand b { font-size: 15px; letter-spacing: .2px; }
.brand small { color: var(--muted); font-size: 12px; }
.chips { display: flex; gap: 6px; flex: 1; min-width: 0; overflow: hidden; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 11px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: 13px; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.iconbtn { width: 44px; height: 44px; border-radius: 22px; border: 1px solid var(--line); background: var(--surface);
  box-shadow: var(--shadow); display: grid; place-items: center; padding: 0; }
.iconbtn svg { width: 20px; height: 20px; }
.account-btn { height: 44px; border-radius: 22px; padding: 0 14px; border: 1px solid var(--line); background: var(--surface);
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 8px; max-width: 46vw; }
.account-btn .avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.account-btn span.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 600; }
.btn { background: var(--surface-3); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; white-space: nowrap; flex: none; }
.btn:disabled, .btn-primary:disabled { opacity: .45; cursor: default; }
.btn.danger { color: var(--bad); }
.btn.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* ---------------------------------------------------------------- map controls */
.mapctl { position: fixed; z-index: 20; right: 10px; top: calc(66px + var(--safe-t)); display: flex; flex-direction: column; gap: 8px; }
.mapctl .iconbtn.on { background: var(--accent); color: var(--accent-ink); }

/* ---------------------------------------------------------------- HUD */
.hud { position: fixed; z-index: 20; display: flex; gap: 2px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; align-items: stretch; }
.hud .cell { padding: 2px 9px; min-width: 62px; text-align: center; }
.hud .cell small { display: block; color: var(--muted); font-size: 11px; letter-spacing: .4px; }
.hud .cell b { font-size: 17px; font-variant-numeric: tabular-nums; }
.hud .pause { border: 0; border-radius: 10px; padding: 0 14px; font-weight: 700; background: var(--warn); color: #261800; }
.hud .pause.resume { background: var(--ok); color: #04210f; }
.hud .pause:disabled { opacity: .4; }

/* ---------------------------------------------------------------- panel */
.panel { position: fixed; z-index: 25; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.panel .grab { display: none; }
.tabs { display: flex; gap: 2px; padding: 6px; border-bottom: 1px solid var(--line); flex: none; }
.tab { flex: 1; border: 0; background: transparent; border-radius: 10px; padding: 7px 2px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; }
.tab svg { width: 20px; height: 20px; }
.tab.active { color: var(--text); background: var(--surface-3); }
.pane { flex: 1; overflow: auto; padding: 14px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.pane h2 { font-size: 17px; margin: 0 0 10px; }
.pane h3 { font-size: 14px; margin: 16px 0 8px; color: var(--muted); font-weight: 600; letter-spacing: .3px; }
.card { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.kv div small { display: block; color: var(--muted); font-size: 12px; }
.kv div b { font-variant-numeric: tabular-nums; font-size: 16px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.list { display: flex; flex-direction: column; gap: 6px; }
.item { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 10px; background: var(--surface-2);
  border: 1px solid var(--line); text-align: left; width: 100%; }
.item .grow { flex: 1; min-width: 0; }
.item .grow div { overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 9px; background: var(--surface-3); color: var(--muted); white-space: nowrap; }
.badge.ok { background: rgba(60,207,142,.15); color: var(--ok); }
.badge.warn { background: rgba(242,184,75,.15); color: var(--warn); }
.route { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.6; word-break: break-word;
  background: var(--surface-3); border-radius: 8px; padding: 8px 10px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field span { font-size: 12px; color: var(--muted); }
.field input, .field select, input.search { background: var(--surface-3); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; outline: none; width: 100%; }
.field input:focus, input.search:focus { border-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; }
.empty b { display: block; color: var(--text); margin-bottom: 6px; font-size: 16px; }
.notice { border-radius: 12px; padding: 11px 12px; margin-bottom: 10px; font-size: 14px; border: 1px solid; }
.notice.info { background: rgba(79,179,255,.1); border-color: rgba(79,179,255,.35); }
.notice.warn { background: rgba(242,184,75,.1); border-color: rgba(242,184,75,.4); }
.notice.bad { background: rgba(255,107,107,.1); border-color: rgba(255,107,107,.4); }
.switch { width: 46px; height: 28px; border-radius: 14px; background: var(--surface-3); border: 1px solid var(--line);
  position: relative; flex: none; padding: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--muted); transition: left .15s, background .15s; }
.switch[aria-checked="true"] { background: rgba(79,179,255,.3); }
.switch[aria-checked="true"]::after { left: 21px; background: var(--accent); }
.progress { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--ok); }

/* checklist */
.phase { margin-bottom: 14px; }
.phase h4 { margin: 0 0 6px; font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: var(--surface-2);
  border: 1px solid var(--line); margin-bottom: 5px; width: 100%; text-align: left; }
.check .box { width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--muted); flex: none; display: grid; place-items: center; }
.check.done { opacity: .62; }
.check.done .box { background: var(--ok); border-color: var(--ok); }
.check.done .box::after { content: "✓"; color: #04210f; font-weight: 800; font-size: 14px; }
.check .t { flex: 1; }
.check .e { color: var(--accent); font-weight: 600; text-align: right; max-width: 45%; }
.check .n { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }

/* landing / signed-out hero */
.hero { position: fixed; z-index: 25; left: 50%; transform: translateX(-50%); bottom: calc(20px + var(--safe-b));
  width: min(520px, calc(100vw - 20px)); background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow); padding: 18px; }
.hero h1 { margin: 0 0 6px; font-size: 20px; }
.hero p { margin: 0 0 12px; color: var(--muted); }
.hero ul { margin: 0 0 14px; padding-left: 18px; color: var(--muted); font-size: 14px; }
.hero .row { gap: 10px; }

/* modal */
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.5); display: grid; place-items: center; padding: 16px; }
.dialog { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 20px; box-shadow: var(--shadow); }
.dialog h2 { margin: 0 0 4px; font-size: 19px; }
.dialog p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* toast */
.toasts { position: fixed; z-index: 80; left: 50%; transform: translateX(-50%); top: calc(64px + var(--safe-t)); display: flex;
  flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 9px 14px; box-shadow: var(--shadow);
  font-size: 14px; max-width: 90vw; }

/* chart viewer */
.viewer { position: fixed; inset: 0; z-index: 50; background: #0b0f14; display: flex; flex-direction: column; }
.viewer header { display: flex; align-items: center; gap: 8px; padding: calc(8px + var(--safe-t)) 10px 8px; background: var(--surface);
  border-bottom: 1px solid var(--line); }
.viewer header .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.viewer header .iconbtn { box-shadow: none; width: 40px; height: 40px; }
.viewer .stage { flex: 1; overflow: auto; touch-action: pan-x pan-y; position: relative; -webkit-overflow-scrolling: touch; }
.viewer .stage .sheet { margin: 0 auto; transform-origin: 0 0; }
.viewer .stage canvas, .viewer .stage img { display: block; background: #fff; }
.viewer.night .stage canvas, .viewer.night .stage img { filter: invert(.92) hue-rotate(180deg) contrast(.95); }
.viewer footer { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 8px 10px calc(8px + var(--safe-b));
  background: var(--surface); border-top: 1px solid var(--line); font-size: 13px; }
.viewer .status { position: absolute; inset: 0; display: grid; place-items: center; color: #9fb1c4; text-align: center; padding: 20px; }

.plane-icon svg { filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.traffic-icon svg { opacity: .9; }
.wpt-label { background: transparent; border: 0; box-shadow: none; color: #fff; font: 600 11px/1 ui-monospace, Menlo, monospace;
  text-shadow: 0 0 3px #000, 0 0 3px #000; }
.wpt-label::before { display: none; }

/* ---------------------------------------------------------------- layouts */
@media (min-width: 900px) {
  .panel { top: calc(64px + var(--safe-t)); left: 10px; bottom: 10px; width: var(--panel-w); border-radius: 18px; }
  .hud { left: calc(var(--panel-w) + 22px); bottom: 14px; }
  body.no-panel .hud { left: 14px; }
  .hero { left: auto; right: 20px; transform: none; bottom: 20px; }
  .leaflet-bottom.leaflet-left { left: calc(var(--panel-w) + 14px); }
}
@media (max-width: 899px) {
  .brand small { display: none; }
  .panel { left: 0; right: 0; bottom: 0; border-radius: 18px 18px 0 0; border-bottom: 0;
    height: var(--sheet-h, 168px); transition: height .22s ease; padding-bottom: var(--safe-b); }
  .panel.dragging { transition: none; }
  .panel .grab { display: block; height: 22px; flex: none; touch-action: none; cursor: grab; }
  .panel .grab::before { content: ""; display: block; width: 42px; height: 5px; border-radius: 3px; background: var(--muted);
    opacity: .5; margin: 9px auto 0; }
  .tabs { order: 3; border-bottom: 0; border-top: 1px solid var(--line); padding-bottom: 4px; }
  .pane { order: 2; padding-top: 4px; }
  .hud { left: 8px; right: 8px; bottom: calc(var(--sheet-h, 168px) + 8px); justify-content: space-between; transition: bottom .22s; }
  .hud .cell { min-width: 0; padding: 2px 4px; flex: 1; }
  .hud .cell b { font-size: 15px; }
  .mapctl { top: calc(62px + var(--safe-t)); }
  .chip.optional { display: none; }
  .leaflet-control-attribution { display: none; }
}
@media (max-width: 420px) {
  .account-btn span.name { display: none; }
  .account-btn { padding: 0 9px; }
}

/* ---------------------------------------------------------------- online traffic */
.traffic-icon { overflow: visible; }
.traffic-icon .ac { width: 24px; height: 24px; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.traffic-icon .cs { position: absolute; left: 50%; top: 24px; transform: translateX(-50%); white-space: nowrap;
  font: 600 11px/1 ui-monospace, Menlo, Consolas, monospace; color: #9fd8ff; text-shadow: 0 0 3px #000, 0 0 3px #000; }
:root[data-theme="light"] .traffic-icon .cs { color: #0b5fa8; text-shadow: 0 0 3px #fff, 0 0 3px #fff; }
.traffic-icon.sel .cs { color: #ff9f1c; }
button.chip { cursor: pointer; color: inherit; }
.src-dot { width: 9px; height: 9px; border-radius: 50%; background: #4fb3ff; flex: none; }
.src-dot.fsd { background: #3ccf8e; }
.grow { flex: 1; min-width: 0; }
.fp { position: fixed; z-index: 35; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.fp header { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 14px; border-bottom: 1px solid var(--line); }
.fp header .cs { font-size: 19px; color: var(--accent); letter-spacing: .3px; }
.fp header .iconbtn { width: 36px; height: 36px; box-shadow: none; }
.fp header .iconbtn.on { background: var(--accent); color: var(--accent-ink); }
.fp-body { flex: 1; overflow: auto; padding: 12px 14px; overscroll-behavior: contain; }
.fp-body h4 { margin: 14px 0 8px; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.fp-body h4::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.fp-phase { text-align: center; color: var(--accent); font-size: 13px; margin-bottom: 4px; }
.fp-od { display: flex; align-items: center; gap: 10px; }
.fp-od b { font-size: 20px; letter-spacing: .5px; }
.fp-od .bar { flex: 1; height: 2px; background: var(--line); position: relative; }
.fp-od .bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); }
.fp-od .bar .ac { position: absolute; top: -11px; width: 22px; height: 22px; margin-left: -11px; color: var(--accent); transform: rotate(90deg); }
.fp-sub { text-align: center; color: var(--muted); font-size: 12px; margin: 8px 0 12px; }
.fp-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.fp-grid div small { display: block; color: var(--muted); font-size: 12px; }
.fp-grid div b { font-variant-numeric: tabular-nums; font-size: 15px; overflow-wrap: anywhere; }
.fp footer { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); }
.fp footer button { background: transparent; border: 0; padding: 10px 4px calc(10px + var(--safe-b)); display: flex; flex-direction: column;
  align-items: center; gap: 4px; font-size: 13px; color: var(--text); }
.fp footer button + button { border-left: 1px solid var(--line); }
.fp footer button svg { width: 20px; height: 20px; }
.fp footer button:disabled { opacity: .35; }
@media (min-width: 900px) {
  .fp { top: calc(64px + var(--safe-t)); right: 64px; width: 380px; max-height: calc(100vh - 84px); border-radius: 16px; }
}
@media (max-width: 899px) {
  .fp { left: 0; right: 0; bottom: 0; max-height: 62vh; border-radius: 18px 18px 0 0; z-index: 45; }
  body.fp-open .hud { display: none; }
}
#chip-online { order: -1; }

/* PRO gate: nothing live on locked pages (signed out / not PRO) */
body.locked .mapctl, body.locked .chips, body.locked .hud { display: none !important; }
