:root {
  --bg: #eef0f3; --panel: #fff; --line: #e3e6ea; --line-2: #eef0f3;
  --text: #16202c; --muted: #6b7480; --faint: #9aa2ad;
  --accent: #2f6feb; --accent-dk: #1f57c3; --accent-bg: #eaf1fe;
  --ok: #14713a; --ok-bg: #e6f6ec; --warn: #9a5b00; --warn-bg: #fff6e8; --danger: #cf222e;
  --r: 9px; --r-sm: 6px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 14px rgba(16,24,40,.07);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 13px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text); background: var(--bg); display: flex; flex-direction: column; overflow: hidden; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cdd3da; border-radius: 6px; border: 3px solid transparent; background-clip: content-box; }

/* ---------- topbar ---------- */
.topbar { height: 52px; flex: none; display: flex; align-items: center; gap: 12px; padding: 0 14px; background: #131c29; color: #fff; }
.brand { font-weight: 700; font-size: 16px; }
.chip { display: inline-flex; align-items: center; gap: 7px; max-width: 260px; padding: 4px 11px; border-radius: 999px;
  background: rgba(255,255,255,.09); border: 1px solid rgba(255,255,255,.14); color: #dfe6ee; cursor: pointer; font-size: 12.5px; }
.chip:hover { background: rgba(255,255,255,.16); }
.cache-status { flex: none; border: 1px solid #ffffff30; background: transparent; color: #c8d3e0; border-radius: 6px; padding: 5px 8px; font-size: 11.5px; cursor: pointer; white-space: nowrap; }
.cache-status:hover { background: #ffffff15; }
.cache-status.error { color: #ffcd80; border-color: #ffcd8070; }
.chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-dot { width: 7px; height: 7px; border-radius: 50%; background: #6b7480; flex: none; }
.chip.ready .chip-dot { background: #37d67a; } .chip.warn .chip-dot { background: #ffb020; }
.coach { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; justify-content: center; color: #c8d3e0; font-size: 12.8px; }
.coach span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.coach-dot { width: 8px; height: 8px; border-radius: 50%; background: #4c8dff; box-shadow: 0 0 0 4px rgba(76,141,255,.18); flex: none; }
.coach.done .coach-dot { background: #37d67a; box-shadow: 0 0 0 4px rgba(55,214,122,.18); }
.coach b { color: #fff; }
.topbar-right { display: flex; align-items: center; gap: 7px; }
.divider { width: 1px; height: 20px; background: rgba(255,255,255,.16); }
.icon-btn { width: 30px; height: 30px; border-radius: var(--r-sm); border: 1px solid rgba(255,255,255,.16); background: rgba(255,255,255,.06);
  color: #e6ecf3; cursor: pointer; font-size: 14px; line-height: 1; }
.icon-btn:hover { background: rgba(255,255,255,.16); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.lang-btn { width: auto; min-width: 30px; padding: 0 8px; font-size: 12px; font-weight: 600; }
.dlg-body a { color: var(--accent, #2f6feb); }
.empty a { color: var(--accent); }
#dpiTop { width: auto; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.16); color: #e6ecf3; border-radius: var(--r-sm); padding: 5px 6px; }
#dpiTop option { color: #000; }
.split { display: inline-flex; }
.split .btn:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split .caret { border-top-left-radius: 0; border-bottom-left-radius: 0; padding: 6px 8px; border-left: 1px solid rgba(255,255,255,.3); }
.menu-wrap { position: relative; }
.menu { position: absolute; top: calc(100% + 6px); left: 0; z-index: 60; min-width: 230px; background: #fff; color: var(--text); border-radius: var(--r);
  box-shadow: 0 10px 34px rgba(16,24,40,.24); padding: 5px; }
.menu.right { left: auto; right: 0; }
.menu button, .menu label { display: block; width: 100%; text-align: left; border: none; background: none; padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.menu button:hover, .menu label:hover { background: #f2f5f9; }
.menu small { display: block; color: var(--faint); font-size: 11.5px; margin-top: 1px; }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 12px; border-radius: var(--r-sm);
  border: 1px solid #d3d8de; background: #fff; color: var(--text); cursor: pointer; white-space: nowrap; transition: background-color .12s, border-color .12s, color .12s; }
.btn:hover { border-color: #b9c1ca; background: #fbfcfd; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dk); border-color: var(--accent-dk); }
.btn.ghost { background: transparent; border-color: transparent; color: #cfd8e3; }
.btn.ghost:hover { background: rgba(255,255,255,.1); }
#panel .btn.ghost, .col-head .btn.ghost { color: var(--muted); }
#panel .btn.ghost:hover, .col-head .btn.ghost:hover { background: #f2f4f7; color: var(--text); }
.btn.sm { padding: 4px 9px; font-size: 12.3px; }
.btn.big { padding: 9px 14px; font-size: 13.5px; }
input[type=number], input[type=text], select, textarea { border: 1px solid #d3d8de; border-radius: var(--r-sm); padding: 5px 8px; background: #fff; width: 100%; transition: border-color .12s, box-shadow .12s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
input[type=range] { flex: 1; min-width: 80px; width: 100%; -webkit-appearance: none; height: 4px; border-radius: 3px; background: #dfe3e8; outline: none; box-shadow: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%; background: #fff; border: 1.5px solid var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.2); cursor: pointer; }
input[type=number].num, .num { width: 64px; }
textarea { resize: vertical; }
.switch { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.3px; cursor: pointer; user-select: none; }
.switch input { accent-color: var(--accent); width: 14px; height: 14px; margin: 0; cursor: pointer; }

/* ---------- layout ---------- */
#app { flex: 1; display: flex; min-height: 0; }
#panel { width: 316px; flex: none; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }
#stage { flex: 1; display: flex; min-width: 0; gap: 1px; background: var(--line); }
.pane-col { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #f6f7f9; }
#figCol { flex: 1.15; }
.col-head { flex: none; height: 42px; display: flex; align-items: center; gap: 8px; padding: 0 12px; background: #fff; border-bottom: 1px solid var(--line); }
.col-title { font-weight: 700; font-size: 13px; }
.col-sub { color: var(--faint); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flex { flex: 1; }
.zoomlabel { color: var(--faint); font-size: 11.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }

#editorBox { flex: 1; position: relative; overflow: hidden; outline: none; background:
  linear-gradient(rgba(0,0,0,.035) 1px, transparent 1px) 0 0/22px 22px, linear-gradient(90deg, rgba(0,0,0,.035) 1px, transparent 1px) 0 0/22px 22px, #f7f8fa; }
#editorBox:focus-visible { box-shadow: inset 0 0 0 2px var(--accent-bg); }
#editor { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#dropHint { position: absolute; inset: 22px; border: 2px dashed #c6ccd4; border-radius: 14px; color: var(--faint); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px; pointer-events: none; background: rgba(255,255,255,.55); transition: .15s; }
.dh-icon { font-size: 34px; } .dh-text { font-size: 15px; color: var(--muted); font-weight: 600; } .dh-sub { font-size: 12px; }
body.dragging #dropHint, #editorBox.drag #dropHint { border-color: var(--accent); background: var(--accent-bg); color: var(--accent-dk); }
body.dragging #dropHint.hidden { display: flex !important; z-index: 5; }

#previewBox { flex: 1; position: relative; overflow: auto; display: flex; }
#preview { margin: auto; padding: 24px; }
#preview svg { display: block; background: #fff; box-shadow: 0 2px 16px rgba(16,24,40,.13); }
#preview .ed { cursor: text; }
#preview .ed:hover { filter: drop-shadow(0 0 0.6px #2f6feb) drop-shadow(0 0 0.6px #2f6feb); }
#preview g[data-edit="cond"] { cursor: pointer; }
#preview g[data-edit="arrow"] { cursor: ns-resize; }
#preview .ed.active { filter: drop-shadow(0 0 1px #2f6feb) drop-shadow(0 0 1px #2f6feb); }
#preview.arming image[data-edit="gel"] { cursor: crosshair; }
#preview .ghost-group { pointer-events: none; }
.mode-banner { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); background: #16202c; color: #fff; border-radius: 999px;
  padding: 6px 8px 6px 16px; font-size: 12.5px; display: flex; gap: 10px; align-items: center; box-shadow: var(--shadow); z-index: 4; white-space: nowrap; }
.mode-banner button { border: none; background: rgba(255,255,255,.14); color: #fff; border-radius: 999px; padding: 3px 10px; cursor: pointer; font-size: 12px; }

/* ---------- panel ---------- */
.sec { padding: 14px 16px; border-bottom: 1px solid var(--line-2); }
.sec-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 13.5px; margin-bottom: 10px; }
.sec-n { width: 20px; height: 20px; border-radius: 50%; background: #eef1f5; color: var(--muted); font-size: 11px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.sec.done .sec-n { background: var(--ok-bg); color: var(--ok); }
.sec.done .sec-n::before { content: "✓"; } .sec.done .sec-n { font-size: 0; } .sec.done .sec-n::before { font-size: 11px; }
.sec.todo .sec-n { background: var(--accent); color: #fff; }
.sec-status { margin-left: auto; font-weight: 400; font-size: 11.5px; color: var(--faint); }
.sec-status.warn { color: var(--warn); }
.h3-note { font-weight: 400; color: var(--faint); font-size: 11.5px; margin-left: 4px; }
.lead { color: var(--muted); font-size: 12.3px; margin: 0 0 8px; }
.lead b { color: var(--text); }
.field { margin: 9px 0; }
.field > label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 3px; }
/* a switch inside a field is still a switch: without this the block rule above wins on specificity
   and the checkbox loses its gap and vertical centring */
.field > label.switch { display: inline-flex; font-size: 12.3px; margin-bottom: 0; }
.field b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-label { color: var(--muted); font-size: 12px; display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.range-row { color: var(--muted); font-size: 12.5px; flex-wrap: nowrap; }
.range-row select { width: auto; min-width: 60px; padding: 4px 6px; }
.hint { color: var(--faint); font-size: 11.5px; margin: 6px 0 0; line-height: 1.55; }
.hint code, .lead code { background: #f1f3f6; padding: 1px 4px; border-radius: 4px; }
.adv { margin-top: 8px; }
.adv > summary { cursor: pointer; color: var(--muted); font-size: 12px; list-style: none; padding: 3px 0; }
.adv > summary::-webkit-details-marker { display: none; }
.adv > summary::before { content: "▸"; display: inline-block; width: 12px; color: var(--faint); transition: .15s; }
.adv[open] > summary::before { transform: rotate(90deg); }
.adv.flush { margin: 0; }
.adv > summary.as-summary { color: var(--text); font-size: 13.5px; margin: 0; }
.adv > summary.as-summary::before { display: none; }
#histo { width: 100%; height: 40px; display: block; border-radius: var(--r-sm); background: #f6f8fa; }
.seg { display: inline-flex; background: #f1f3f6; border-radius: 8px; padding: 3px; gap: 2px; }
.seg.full { display: flex; }
.seg.full button { flex: 1; }
.seg button { border: none; background: none; padding: 5px 10px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 12.3px; }
.seg button.on { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(16,24,40,.1); }

.list { display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; margin-top: 6px; }
.item { display: flex; align-items: center; gap: 6px; padding: 3px 6px; border-radius: var(--r-sm); }
.item:hover { background: #f6f8fb; }
.item.sel { background: var(--accent-bg); }
.item.out { opacity: .45; }
.item .idx { width: 22px; text-align: right; color: var(--faint); font-variant-numeric: tabular-nums; font-size: 11.5px; flex: none; }
.item input[type=text] { flex: 1; min-width: 0; border-color: transparent; background: transparent; padding: 3px 6px; }
.item input[type=text]:hover { background: #fff; border-color: #e0e4e9; }
.item .x { border: none; background: none; color: var(--faint); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 3px; border-radius: 4px; }
.item .x:hover { color: var(--danger); background: #fdecee; }
.item .tag { font-size: 10.5px; padding: 1px 6px; border-radius: 999px; background: #eef1f5; color: var(--muted); flex: none; }
.item .tag.ok { background: var(--ok-bg); color: var(--ok); } .item .tag.man { background: #fdf0e0; color: var(--warn); }
#laneList .idx { cursor: pointer; border-radius: 4px; }
#laneList .idx:hover { background: var(--accent-bg); color: var(--accent); }
.item .kind { font-size: 11px; color: var(--faint); flex: none; min-width: 28px; white-space: nowrap; }
#annoList { max-height: none; }

.mk-card { border: 1px solid var(--line); border-radius: var(--r); padding: 8px 10px; margin-bottom: 8px; }
.mk-head { display: flex; align-items: center; gap: 7px; }
.mk-badge { font-size: 11px; font-weight: 600; color: #7a5a00; background: #fff3c4; border-radius: 5px; padding: 1px 7px; flex: none; }
.mk-score { font-size: 11px; color: var(--ok); margin-left: auto; }
.mk-score.low { color: var(--warn); }
.mk-card select { margin-top: 6px; }
.mk-card .row2 { display: flex; gap: 6px; margin-top: 6px; }
.mk-card .row2 select { margin: 0; flex: 1; }
.mk-card .list { max-height: 150px; }

.menu-sep { height: 1px; background: var(--line); margin: 4px 6px; }
.menu .danger { color: var(--danger); }
.menu-check { display: flex !important; align-items: center; gap: 6px; font-size: 12.5px !important; }
.menu-check input { width: auto; margin: 0; accent-color: var(--accent); }
.nowrap { flex-wrap: nowrap; }
.inline.mt { margin-top: 6px; }
.step-btn { padding: 2px 8px; font-size: 14px; line-height: 1; }
.clipline, .dpiline { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.clipline .bad, .dpiline .bad { color: var(--warn); font-weight: 600; }
.clipline .ok, .dpiline .ok { color: var(--ok); }
.suggest { margin-top: 10px; padding: 9px 11px; border-radius: var(--r); background: #fff8e8; border: 1px solid #f4e0b4; font-size: 12.3px; }
.suggest .inline { margin-top: 6px; }
.draft { margin: 12px 0; padding: 10px 12px; border-radius: var(--r); background: var(--accent-bg); text-align: left; font-size: 12.5px; display: flex; flex-direction: column; gap: 8px; }
.item .star { border: none; background: none; cursor: pointer; font-size: 15px; color: #c9a227; padding: 0 3px; }
.item .star.off { color: #c3cad4; }
.fav-row { cursor: pointer; }
.fav-head { font-size: 10.5px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; padding: 6px 6px 1px; }
.fav-row input { accent-color: var(--accent); width: 14px; height: 14px; margin: 0; flex: none; cursor: pointer; }
.fav-row .fav-name { flex: 1; min-width: 0; font-size: 12.3px; color: var(--muted); }
.fav-row.on .fav-name { color: var(--text); font-weight: 600; }
.mk-card .star { border: none; background: none; cursor: pointer; font-size: 16px; color: #c9a227; padding: 0 2px; line-height: 1; }
.mk-card .star.off { color: #c3cad4; }
.mk-notice { font-size: 11.5px; color: var(--warn); background: #fff8e8; border-radius: 6px; padding: 5px 8px; margin-bottom: 8px; }
.expo { flex: none; display: flex; gap: 8px; padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--line); overflow-x: auto; }
.expo-item { flex: none; width: 92px; border: 2px solid transparent; border-radius: 8px; padding: 3px; cursor: pointer; background: #f6f8fa; font-size: 10.5px; color: var(--muted); text-align: center; line-height: 1.35; }
.expo-item:hover { border-color: #c6d4ef; }
.expo-item.on { border-color: var(--accent); background: var(--accent-bg); color: var(--text); }
.expo-item img { display: block; width: 100%; height: 52px; object-fit: cover; border-radius: 5px; background: #000; margin-bottom: 2px; }
.expo-item .best { color: var(--ok); font-weight: 700; }
.expo-item .clip { color: var(--warn); }
.pf { width: 540px; }
.pf-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line-2); font-size: 12.8px; }
.pf-item .lv { flex: none; width: 44px; font-size: 11px; font-weight: 700; border-radius: 4px; text-align: center; padding: 1px 0; }
.pf-item .lv.block { background: #fdecee; color: var(--danger); }
.pf-item .lv.warn { background: var(--warn-bg); color: var(--warn); }
.pf-item .lv.info { background: #eef1f5; color: var(--muted); }
.pf-item .tx { flex: 1; }
.pf-ok { color: var(--ok); padding: 10px 0; }
.pf-actions { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.lane-fix { margin-top: 10px; padding: 9px 11px; border-radius: var(--r); background: #f6f8fb; }
.lane-fix-title { font-size: 12.3px; font-weight: 600; margin-bottom: 6px; }
.lane-fix-step { display: flex; gap: 8px; padding: 7px 0; }
.lane-fix-step + .lane-fix-step { border-top: 1px solid #e6eaf0; }
.step-n { flex: none; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; margin-top: 1px; }
.step-body { flex: 1; min-width: 0; }
.step-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12.3px; }
.step-row b { font-weight: 600; }
.step-body .hint { margin: 3px 0 6px; }
.splice-box { margin-top: 10px; padding: 9px 11px; border-radius: var(--r); background: #f6f8fb; }
.splice-box .seg { margin-top: 6px; }
.tools { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.tool { border: 1px solid var(--line); background: #fff; border-radius: var(--r); padding: 8px 6px; cursor: pointer; text-align: center; font-size: 12.3px; transition: background-color .12s, border-color .12s, color .12s; }
.tool:hover { border-color: var(--accent); background: var(--accent-bg); }
.tool.on { border-color: var(--accent); background: var(--accent); color: #fff; }
.tool.on small { color: rgba(255,255,255,.8); }
.tool .ti { display: block; font-size: 16px; line-height: 1.2; margin-bottom: 2px; }
.tool small { display: block; color: var(--faint); font-size: 10.5px; line-height: 1.3; margin-top: 2px; }

.empty { padding: 40px 24px; text-align: center; }
.empty-icon { font-size: 40px; color: #cfd6de; }
.empty h2 { font-size: 16px; margin: 10px 0 6px; }
.empty p { color: var(--muted); font-size: 12.5px; line-height: 1.7; margin: 0 0 18px; }
.empty .btn { display: flex; width: 100%; margin-bottom: 8px; }
.empty .privacy { font-size: 11.5px; color: var(--faint); margin-top: 14px; }
.legend { margin: 12px 16px 20px; padding: 10px 12px; background: #f6f8fb; border-radius: var(--r); font-size: 11.8px; color: var(--muted); line-height: 1.6; }
.legend:empty { display: none; }
.legend b { color: var(--text); display: block; margin-bottom: 2px; }

/* ---------- floating editor / popover ---------- */
.float-ed { position: fixed; z-index: 70; width: 140px; padding: 4px 8px !important; border: 1.5px solid var(--accent) !important; border-radius: 6px;
  box-shadow: 0 6px 20px rgba(16,24,40,.22) !important; font-size: 13px; background: #fff; resize: none; overflow: hidden; line-height: 1.35; display: block; }
/* under the text editor: size of what is being edited, line break for group labels */
.fed-bar { position: fixed; z-index: 71; display: flex; align-items: center; gap: 4px; padding: 4px 6px; background: #16202c; color: #fff; border-radius: 8px;
  box-shadow: 0 6px 20px rgba(16,24,40,.25); font-size: 12px; white-space: nowrap; }
.fed-bar button { border: none; background: rgba(255,255,255,.13); color: #fff; border-radius: 6px; padding: 3px 8px; font-size: 12px; cursor: pointer; min-height: 0; }
.fed-bar button:hover { background: rgba(255,255,255,.24); }
.fed-lbl { color: #b8c3d1; margin-right: 2px; }
.fed-size { min-width: 38px; text-align: center; font-variant-numeric: tabular-nums; }
.fed-hint { color: #8e9aab; margin-left: 4px; }
.popover { position: fixed; z-index: 70; background: #fff; border-radius: var(--r); box-shadow: 0 10px 34px rgba(16,24,40,.25); padding: 12px; width: 250px; }
.popover h4 { margin: 0 0 8px; font-size: 12.5px; }
.popover .field { margin: 7px 0; }
.popover .est { font-size: 12px; color: var(--muted); margin: 2px 0 6px; }
.popover .est b { color: var(--text); }
.popover .est .warn-t { color: #b45309; }
.popover .actions { display: flex; gap: 6px; margin-top: 10px; }
.popover .actions .btn { flex: 1; }
.popover .danger { color: var(--danger); }

/* ---------- overlays ---------- */
#warnings { position: fixed; right: 18px; bottom: 16px; z-index: 15; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; max-width: 520px; }
#warnings div { background: var(--warn-bg); color: var(--warn); border: 1px solid #f2ddba; border-radius: 10px; padding: 7px 12px; font-size: 12px; box-shadow: var(--shadow); display: flex; gap: 8px; align-items: flex-start; }
#warnings div button { border: none; background: none; color: inherit; cursor: pointer; opacity: .6; font-size: 14px; line-height: 1; padding: 0; }
#toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #16202c; color: #fff; border-radius: 999px; padding: 8px 18px; font-size: 12.5px; box-shadow: 0 8px 24px rgba(16,24,40,.24); animation: toastIn .22s ease; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.dlg { position: fixed; inset: 0; background: rgba(14,20,28,.42); display: flex; align-items: center; justify-content: center; z-index: 90; }
.dlg-body { position: relative; background: #fff; border-radius: 14px; padding: 22px 28px; max-width: 640px; max-height: 86vh; overflow: auto; box-shadow: 0 20px 60px rgba(16,24,40,.3); }
.dlg-body h3 { margin: 14px 0 6px; font-size: 14px; } .dlg-body h3:first-of-type { margin-top: 0; }
.dlg-body li { margin: 4px 0; }
.dlg-x { position: absolute; top: 12px; right: 14px; border: none; background: none; font-size: 22px; color: var(--faint); cursor: pointer; }
.history-body { width: min(640px, calc(100% - 24px)); }
.history-body h3 { padding-right: 32px; }
.history-body .hint { line-height: 1.7; }
.library-card { display: flex; align-items: center; gap: 12px; padding: 14px 10px; border-bottom: 1px solid var(--line); }
.library-card.current { background: var(--accent-bg); border-radius: 8px; }
.project-info { flex: 1; min-width: 0; }
.project-info small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 4px; }
.open-project { text-align: left; overflow-wrap: anywhere; border: 0; background: none; color: var(--accent); font-weight: 600; padding: 0; cursor: pointer; }
.open-project:hover { text-decoration: underline; }
.project-actions, .history-footer { display: flex; flex-wrap: wrap; gap: 8px; }
.project-actions { flex: none; }
.delete-project:not(:disabled) { color: var(--danger); }
.project-actions button:disabled { opacity: .4; cursor: default; }
.history-footer { margin-top: 18px; }
.history-empty { padding: 24px 8px; color: var(--muted); }
.history-error { padding: 10px; border-radius: 6px; background: var(--warn-bg); color: var(--warn); }
.lane-grid-control { padding: 12px; margin: 12px 0; background: var(--accent-bg); border: 1px solid #d9e5fb; border-radius: 10px; }
.lane-count-stepper { display: inline-flex; align-items: center; gap: 4px; margin-left: 8px; }
.lane-count-stepper .num { width: 58px; text-align: center; }
.lane-grid-control .hint { margin: 9px 0; }
.raw-grid-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.raw-grid-row .lane-count-stepper { margin-left: 0; }
.lane-name-link { flex: 1; min-width: 0; border: 0; background: none; color: var(--accent); text-align: left; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.figure-tools { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--line); z-index: 36; }
.figure-tools .h3-note { margin-right: auto; }
.figure-tools .btn.ghost, .figure-names .btn.ghost, .marker-small-pop .btn.ghost { color: var(--muted); }
.figure-tools .btn.ghost:hover, .figure-names .btn.ghost:hover, .marker-small-pop .btn.ghost:hover { background: var(--accent-bg); color: var(--accent); }
.figure-text-menu { position: relative; }
.figure-text-menu summary { cursor: pointer; border: 1px solid var(--line); border-radius: 6px; padding: 5px 9px; list-style: none; }
.figure-text-menu summary::after { content: ' ▾'; color: var(--muted); }
.figure-text-menu[open] summary { background: var(--accent-bg); color: var(--accent); }
.figure-text-fields { position: absolute; right: 0; top: calc(100% + 6px); width: min(320px, calc(100vw - 24px)); max-height: 65vh; overflow: auto; background: #fff; padding: 16px; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); z-index: 62; }
.figure-names { flex: none; padding: 12px; background: #fff; border-bottom: 1px solid var(--line); }
.figure-names textarea { margin: 7px 0; }
.figure-names .inline { flex-wrap: wrap; }
.figure-names .hint { flex: 1; }
.marker-actions { display: flex; flex-wrap: wrap; gap: 5px; margin: 8px 0; }
.marker-lane-select { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 12px; color: var(--muted); }
.marker-lane-select select { flex: 1; min-width: 0; }
#ladderCacheStatus.warn-text { color: var(--warn); }
.marker-reference-card { position: absolute; top: 10px; right: 10px; z-index: 4; width: 170px; max-height: calc(100% - 20px); overflow: auto; padding: 9px; background: rgba(255,255,255,.97); border: 1px solid var(--line); border-radius: 9px; box-shadow: var(--shadow); font-size: 11.5px; }
.marker-ref-head { display: flex; justify-content: space-between; align-items: center; gap: 5px; }
.marker-ref-head button { background: none; border: 0; font-size: 19px; line-height: 1; color: var(--muted); cursor: pointer; padding: 3px; }
.marker-ref-lane { color: var(--muted); margin: 3px 0 6px; }
.marker-reference-card select { font-size: 11.5px; padding: 5px 2px; min-height: 30px; margin-bottom: 7px; }
.marker-ref-note { display: block; font-size: 10.5px; color: var(--muted); line-height: 1.5; margin: 6px 0; }
.marker-ref-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.marker-ref-actions .btn { flex: 1; font-size: 11px; padding: 5px 3px; }
.marker-reference-scroll { max-height: 280px; overflow: auto; overscroll-behavior: contain; }
.ladder-reference { display: block; width: 116px; max-width: 100%; height: auto; margin: 0 auto; }
.ladder-reference [data-size] { cursor: pointer; outline-offset: -2px; }
.ladder-reference [data-size]:hover rect:first-child, .ladder-reference [data-size]:focus rect:first-child { fill: #dbeafe; }
.marker-small-pop { position: fixed; z-index: 85; width: min(280px, calc(100vw - 16px)); max-height: calc(100dvh - 72px); overflow: auto; padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 30px #17223530; }
.marker-pop-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px; gap: 6px; position: sticky; top: -12px; z-index: 1; background: #fff; }
.marker-pop-grip { display: flex; align-items: center; gap: 7px; flex: 1; min-width: 0; min-height: 32px; padding: 4px 0; border: 0; background: none; color: inherit; font: inherit; font-weight: 700; text-align: left; cursor: grab; touch-action: none; user-select: none; }
.marker-pop-grip::before { content: '⠿'; color: var(--faint); font-weight: 400; }
.marker-pop-grip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.marker-small-pop.is-dragging .marker-pop-grip { cursor: grabbing; }
.marker-pop-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 9px; font-size: 12px; }
.marker-pop-bands { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; max-height: 160px; overflow: auto; margin: 8px 0; }
.marker-pop-bands label { padding: 3px; }
.marker-pop-bands .is-deleted { text-decoration: line-through; opacity: .5; }
.marker-small-pop .actions, .marker-selected-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.marker-selected-actions { padding: 8px 0; border-bottom: 1px solid var(--line); }
.marker-selected-actions b { margin-right: auto; }
.marker-size-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.marker-size-grid button { border: 1px solid #d3d8de; background: #fff; border-radius: 5px; padding: 6px 2px; cursor: pointer; }
.marker-size-grid button.reference { color: #b8510c; border-color: #eab080; }
.marker-size-grid button.selected { background: var(--accent-bg); border-color: var(--accent); }
#preview [data-edit="marker"] { cursor: pointer; }
#preview [data-edit="marker"]:hover text { fill: var(--accent); }
.mode-banner { white-space: normal; max-width: calc(100% - 24px); align-items: center; }
.mode-banner > span { min-width: 0; }
.mode-banner > button { flex: none; }
@media (max-width: 600px) {
  .figure-tools { gap: 4px; padding: 6px 8px; }
  .figure-tools .btn { padding: 5px 7px; }
  .figure-text-menu summary { min-height: 34px; display: flex; align-items: center; font-size: 12px; }
  .marker-reference-card { width: 136px; padding: 7px; right: 6px; top: 8px; }
  .marker-reference-scroll { max-height: 210px; }
}
#historyDlg.working .library-card, #historyDlg.working #historyRetry { pointer-events: none; opacity: .65; }
@media (max-width: 600px) {
  .library-card { flex-wrap: wrap; gap: 10px; }
  .project-info { flex-basis: 100%; }
  .project-actions { margin-left: auto; }
  .history-footer .btn { flex: 1; }
}
#busy { position: fixed; inset: 0; background: rgba(247,249,251,.72); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; z-index: 95; }
.spinner { width: 26px; height: 26px; border: 2.5px solid #d7dde4; border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.busy-text { color: var(--muted); }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 11.5px; }
@media (max-width: 1250px) { #panel { width: 280px; } .coach { display: none; } .col-sub { display: none; } }

/* ---------- phone and touch ---------- */

/* the visible height on phones (the browser bars come and go); on a desktop the same as 100% */
html, body { height: 100dvh; }
.m-coach, #mNav { display: none; }

/* desktop = everything outside the phone query below (ui.js phoneMq uses the same query) */
@media (min-width: 901px) and (min-height: 521px), (min-width: 901px) and (pointer: fine), (min-width: 901px) and (pointer: none) {
  .m-only { display: none !important; }
}

/* any touch screen (phones, tablets): finger-sized targets; no page zoom fighting the editors */
@media (pointer: coarse) {
  body { touch-action: pan-x pan-y; }
  #editorBox { touch-action: none; }            /* pinch, pan and drags on the image are handled by hand */
  #editor, #preview svg { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
  #preview svg { touch-action: pan-x pan-y; }   /* taps edit; a swipe scrolls a zoomed figure */
  #preview svg .ed, #preview svg g[data-edit="cond"], #preview svg g[data-edit="arrow"] { cursor: pointer; }
  .btn, .seg button { min-height: 38px; }
  .btn.sm { min-height: 34px; padding: 5px 11px; }
  input[type=number], input[type=text], select, textarea { font-size: 16px; min-height: 36px; }  /* iOS: no zoom on focus */
  input[type=range] { height: 6px; }
  input[type=range]::-webkit-slider-thumb { width: 26px; height: 26px; }
  input[type=range]::-moz-range-thumb { width: 24px; height: 24px; }
  .switch { font-size: 13px; min-height: 30px; }
  .switch input, .fav-row input { width: 20px; height: 20px; }
  .item { padding: 6px; min-height: 40px; }
  .item .x { font-size: 20px; padding: 6px 10px; }
  .item .star, .mk-card .star { font-size: 20px; padding: 4px 8px; }
  .adv > summary { padding: 8px 0; }
  .tool { padding: 11px 6px; }
  #laneList .idx { min-width: 30px; padding: 6px 0; }
}

/* phone layout: one view at a time (Image / Figure / Settings) chosen in a bottom bar */
@media (max-width: 900px), (max-height: 520px) and (pointer: coarse) {
  :root { --top: 48px; --nav: 58px; --kb: 0px; --sb: env(safe-area-inset-bottom, 0px); }
  .d-only { display: none !important; }

  /* top bar: image name, undo / redo, more */
  .topbar { height: var(--top); gap: 8px; padding: 0 max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left)); }
  .brand { font-size: 15px; flex: none; }
  .chip { flex: 0 1 auto; min-width: 0; max-width: none; padding: 6px 12px; }
  .coach, .divider, #dpiTop, .menu-wrap, #btnHelp, #btnLang { display: none !important; }
  .topbar-right { margin-left: auto; gap: 6px; flex: none; }
  .icon-btn { width: 38px; height: 36px; font-size: 18px; }
  body:not(.has-image) #btnUndo, body:not(.has-image) #btnRedo { display: none; }

  /* the next useful step */
  body.has-image .m-coach { display: flex; }
  .m-coach { flex: none; align-items: flex-start; gap: 9px; padding: 7px max(14px, env(safe-area-inset-left)); background: #1b2635; color: #c8d3e0; font-size: 12.5px; line-height: 1.45; }
  .m-coach .coach-dot { margin-top: 5px; }
  .m-coach.done .coach-dot { background: #37d67a; box-shadow: 0 0 0 4px rgba(55,214,122,.18); }
  .m-coach b { color: #fff; }

  /* views: the hidden ones keep their size (the image editor stays fitted) but are out of sight */
  #app { position: relative; overflow: hidden; }
  #panel { position: absolute; inset: 0; z-index: 20; width: 100% !important; border-right: none; overscroll-behavior: contain; }
  body.has-image:not(.view-panel) #panel { display: none; }
  #stage { flex-direction: column; background: transparent; position: relative; }
  .pane-col { position: absolute; inset: 0; }
  body:not(.view-raw) #rawCol, body:not(.view-fig) #figCol { visibility: hidden; pointer-events: none; }
  .col-head { height: 42px; padding: 0 8px; gap: 6px; }
  .col-sub { display: none; }
  .col-head #btnAddLaneM.on { background: var(--accent); border-color: var(--accent); color: #fff; }
  #preview { padding: 12px; }

  /* bottom bar */
  body.has-image #mNav { display: flex; }
  #mNav { flex: none; height: calc(var(--nav) + var(--sb)); padding: 0 env(safe-area-inset-right, 0px) var(--sb) env(safe-area-inset-left, 0px);
    background: #fff; border-top: 1px solid var(--line); }
  #mNav button { flex: 1; border: none; background: none; padding: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: var(--muted); font-size: 11px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
  #mNav svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
  #mNav button.on { color: var(--accent); font-weight: 600; }
  #mNav .m-exp-pill { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 16px 4px; border-radius: 14px; background: var(--accent); color: #fff; font-weight: 600; }
  #mNav .m-exp-pill svg { width: 21px; height: 21px; }
  #mNav .m-export.ready .m-exp-pill { box-shadow: 0 0 0 4px rgba(47,111,235,.2); }

  /* tool instructions (moved to <body> by mobile.js so the Image tab shows them too) */
  body > #modeBanner { position: fixed; top: calc(var(--top) + 90px); left: 10px; right: 10px; transform: none; z-index: 45; white-space: normal;
    justify-content: space-between; border-radius: 12px; padding: 8px 8px 8px 14px; font-size: 13px; line-height: 1.4; }
  body > #modeBanner button { flex: none; padding: 7px 12px; }

  /* lane-name editor docked at the top (clear of the keyboard); popovers above the bottom bar or keyboard */
  #floatEd { left: 10px !important; right: 10px !important; width: auto !important; top: calc(var(--top) + 8px) !important; padding: 10px 12px !important; border-radius: 10px; font-size: 16px; }
  #fedBar { left: 10px !important; right: 10px !important; padding: 6px 8px; gap: 6px; }
  #fedBar button { padding: 7px 11px; font-size: 13px; }
  #popover { left: 8px !important; right: 8px !important; width: auto !important; top: auto !important; bottom: calc(max(var(--nav) + var(--sb), var(--kb)) + 8px) !important;
    max-height: calc(100dvh - var(--top) - 24px - max(var(--nav) + var(--sb), var(--kb))); overflow-y: auto; border-radius: 14px; padding: 14px; z-index: 75; }
  #popover h4 { font-size: 14px; }

  /* messages: toasts above the bottom bar (clear of a warning or the selection bar), one warning on the Figure tab */
  #toasts { bottom: calc(var(--nav) + var(--sb) + 76px); width: calc(100vw - 32px); }
  .toast { border-radius: 12px; text-align: center; font-size: 13px; }
  #warnings { left: 8px; right: 8px; bottom: calc(var(--nav) + var(--sb) + 8px); max-width: none; align-items: stretch; }
  body:not(.view-fig) #warnings { display: none; }
  #warnings div { font-size: 12.5px; }
  #warnings div:not(:first-child) { display: none; }
  #warnings div span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  #warnings div.open span { display: block; }
  #warnings div button { font-size: 18px; padding: 0 2px; }

  /* dialogs slide up from the bottom */
  .dlg { align-items: flex-end; }
  .dlg-body { margin: 0; width: 100%; max-width: none; max-height: 90dvh; border-radius: 16px 16px 0 0; padding: 20px 18px calc(18px + var(--sb)); }
  .pf { width: 100%; }
  .pf-item { flex-wrap: wrap; }
  .pf-actions { flex-wrap: wrap; }
  .pf-actions .flex { display: none; }
  .pf-actions .btn { flex: 1; }

  /* settings and start screen */
  .sec { padding: 12px 14px; }
  .list { max-height: none; }
  .empty { padding: 30px 22px calc(30px + var(--sb)); }
  .empty .btn { min-height: 46px; font-size: 15px; }
  .expo-item { width: 84px; }
}

/* phone held sideways: shorter bars, no coach line */
@media (max-height: 520px) and (pointer: coarse) {
  :root { --top: 42px; --nav: 46px; }
  body.has-image .m-coach { display: none; }
  #mNav button { flex-direction: row; gap: 6px; font-size: 12.5px; }
  #mNav .m-exp-pill { flex-direction: row; gap: 6px; padding: 4px 14px; }
  body > #modeBanner { top: calc(var(--top) + 6px); }
  #toasts { bottom: calc(var(--nav) + var(--sb) + 64px); }
}

/* bottom sheets (export, more, exported file) */
.sheet-wrap { position: fixed; inset: 0; z-index: 88; display: flex; align-items: flex-end; justify-content: center; background: rgba(14,20,28,.45); animation: sheetFade .15s ease; }
.sheet { width: 100%; max-width: 560px; max-height: 88dvh; overflow-y: auto; overscroll-behavior: contain; background: #fff; border-radius: 18px 18px 0 0;
  padding: 4px 14px calc(16px + env(safe-area-inset-bottom, 0px)); box-shadow: 0 -10px 40px rgba(16,24,40,.25); animation: sheetIn .22s cubic-bezier(.2,.8,.2,1); }
@keyframes sheetIn { from { transform: translateY(48px); opacity: .5; } to { transform: none; opacity: 1; } }
@keyframes sheetFade { from { opacity: 0; } }
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: #d6dbe1; margin: 8px auto 8px; }
.sheet-head { display: flex; align-items: center; padding: 0 4px 6px; }
.sheet-head h3 { flex: 1; margin: 0; font-size: 17px; }
.sheet-x { width: 32px; height: 32px; border: none; border-radius: 50%; background: #f1f3f6; color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; }
.sheet-row { display: flex; align-items: center; gap: 10px; padding: 6px 4px 2px; }
.sheet-row-label { font-size: 14px; font-weight: 600; }
.sheet-row .seg button { min-width: 58px; font-size: 14px; }
.sheet-info { margin: 4px 4px 6px; font-size: 12px; line-height: 1.55; color: var(--muted); }
.sheet-info .bad { color: var(--warn); font-weight: 600; }
.sheet-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 6px; border: none; border-radius: 12px; background: none; color: var(--text);
  font-size: 15px; text-align: left; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.sheet-item:hover, .sheet-item:active { background: #f3f5f8; }
.sheet-item .si-ic { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 11px; background: #eef2f8; color: var(--accent-dk); font-size: 12px; font-weight: 800; letter-spacing: .02em; }
.sheet-item .si-tx { flex: 1; min-width: 0; }
.sheet-item small { display: block; margin-top: 2px; color: var(--faint); font-size: 12px; line-height: 1.4; }
.sheet-item.primary .si-ic { background: var(--accent); color: #fff; }
.sheet-item.primary .si-tx > span { font-weight: 700; }
.sheet-item.danger { color: var(--danger); }
.sheet-item.danger .si-ic { background: #fdecee; color: var(--danger); }
.sheet-label { padding: 10px 6px 2px; font-size: 12px; font-weight: 600; color: var(--faint); }
.sheet-sep { height: 1px; margin: 6px; background: var(--line); }
.sheet-check { padding: 12px 6px 4px; font-size: 13.5px; }
.sheet-note { margin: 10px 4px 0; padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--warn); font-size: 12.5px; line-height: 1.55; }
.sheet-foot { margin: 12px 6px 4px; font-size: 11.5px; line-height: 1.6; color: var(--faint); }
.sheet-foot a { color: var(--accent); }
.rs-file { padding: 0 4px 8px; font-size: 13px; word-break: break-all; }
.rs-preview { display: flex; justify-content: center; margin: 0 0 8px; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: #f6f7f9; }
/* long-press on the picture saves it (also inside WeChat, which cannot download files) */
.rs-preview img { display: block; max-width: 100%; max-height: 44dvh; object-fit: contain; -webkit-touch-callout: default; -webkit-user-select: auto; user-select: auto; }
.rs-actions { display: flex; gap: 8px; margin-top: 4px; }
.rs-actions .btn { flex: 1; }
.rs-done { width: 100%; margin-top: 10px; background: #f1f3f6; border-color: transparent; }

/* touch selection bar on the image: nudge, cut, delete — what keys do on a computer */
.sel-bar { position: absolute; left: 8px; right: 8px; bottom: 10px; z-index: 6; display: flex; align-items: center; gap: 6px; padding: 6px 6px 6px 12px;
  border-radius: 14px; background: #16202c; color: #fff; box-shadow: 0 8px 26px rgba(16,24,40,.3); }
.sel-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; }
.sel-btns { display: flex; gap: 4px; flex: none; }
.sel-bar button { min-width: 40px; height: 38px; padding: 0 10px; border: none; border-radius: 10px; background: rgba(255,255,255,.13); color: #fff; font-size: 13px; cursor: pointer; touch-action: manipulation; }
.sel-bar button.danger { background: rgba(255,90,90,.22); color: #ffc2c2; }
.sel-bar button.x { min-width: 34px; padding: 0 6px; background: none; font-size: 18px; }
