:root {
  --bg: #112232;
  --bg-deep: #0c1928;
  --panel: #152a3e;
  --panel-2: #1b3349;
  --panel-3: #22405a;
  --line: rgba(200, 216, 236, 0.13);
  --line-2: rgba(200, 216, 236, 0.22);
  --text: #e7eef6;
  --muted: #92a7bd;
  --accent: #6fd6ec;
  --accent-soft: rgba(111, 214, 236, 0.18);
  --gold: #e6bb5e;
  --danger: #ef7a72;
  --ok: #7fd49a;
  --core: #99241b;
  --core-bar: #8a1b14;
  --decision: #dcdcdc;
  --scene: #2b4560;
  --special: #2a3147;
  --ending: #5b3f86;
  --note: #e9dc9a;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --top-h: 52px;
  --dock-w: 390px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.4; cursor: default; }
.ic { flex: none; display: block; }

/* ---------------- top bar ---------------- */
#topbar {
  height: calc(var(--top-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(180deg, #0e1d2c, #10202f);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 30;
  overflow-x: auto; scrollbar-width: none;
}
#topbar::-webkit-scrollbar { display: none; }
.brand { display: flex; align-items: center; gap: 7px; font-weight: 650; letter-spacing: 0.2px; white-space: nowrap; color: #dfe8f2; }
.brand-icon { width: 28px; height: 28px; border-radius: 7px; display: block; }
.vault-btn {
  display: flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--line);
  padding: 6px 10px; border-radius: 8px; max-width: 260px; white-space: nowrap; min-height: 36px;
}
.vault-name { overflow: hidden; text-overflow: ellipsis; }
.tb-group { display: flex; align-items: center; gap: 4px; padding-left: 8px; border-left: 1px solid var(--line); }
.tb-group.right { margin-left: auto; border-left: 0; }
.tb-btn {
  position: relative; display: flex; align-items: center; gap: 6px; height: 38px; min-width: 38px; padding: 0 10px;
  background: transparent; border: 1px solid transparent; border-radius: 8px; color: #cfdbe7; white-space: nowrap;
}
.tb-btn:hover:not(:disabled) { background: var(--panel); }
.tb-btn.on { background: var(--accent-soft); border-color: rgba(111, 214, 236, 0.4); color: #fff; }
.tb-btn.primary { background: #2a5d78; color: #fff; }
.tb-btn.primary:hover { background: #33708f; }
.badge-n { background: var(--gold); color: #1b1b1b; font-size: 11px; font-weight: 700; border-radius: 9px; padding: 0 6px; line-height: 17px; }
.sync-dot { position: absolute; right: 6px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: #6b7d90; }
.sync-btn[data-state="idle"] .sync-dot { background: var(--ok); }
.sync-btn[data-state="syncing"] .sync-dot { background: var(--accent); animation: pulse 1s infinite; }
.sync-btn[data-state="error"] .sync-dot { background: var(--danger); }
.sync-btn[data-state="offline"] .sync-dot, .sync-btn[data-state="signed-out"] .sync-dot { background: var(--gold); }
@keyframes pulse { 50% { opacity: 0.3; } }
.add-wrap { position: relative; }
.add-pop, .add-menu {
  position: fixed; z-index: 60; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 12px;
  padding: 6px; display: flex; flex-direction: column; min-width: 180px; box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
}
.add-pop { top: calc(var(--top-h) + env(safe-area-inset-top) - 4px); }
.add-menu { position: absolute; }
.add-pop[hidden] { display: none; }
.add-pop button, .add-menu button {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 0; background: transparent; border-radius: 8px; text-align: left; min-height: 40px;
}
.add-pop button:hover, .add-menu button:hover { background: var(--panel-3); }
.am-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); padding: 4px 10px 6px; }

.sw { width: 14px; height: 14px; border-radius: 4px; display: inline-block; flex: none; border: 1px solid rgba(255, 255, 255, 0.2); }
.sw.t-core { background: var(--core); }
.sw.t-decision { background: var(--decision); }
.sw.t-scene { background: var(--scene); }
.sw.t-special { background: var(--special); border-color: var(--gold); }
.sw.t-ending { background: var(--ending); }
.sw.t-note { background: var(--note); }

/* ---------------- layout ---------------- */
#main { position: absolute; top: calc(var(--top-h) + env(safe-area-inset-top)); left: 0; right: 0; bottom: 0; display: flex; }
#stage { position: relative; flex: 1; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; background: var(--bg); }
#mesh { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }

/* lanes */
.lane { position: absolute; left: -60000px; width: 120000px; background: var(--lc); border-bottom: 1px solid var(--lb); }
.lane.collapsed { background: rgba(0, 0, 0, 0.18); }
.lane-grip { position: absolute; left: 0; right: 0; bottom: -6px; height: 12px; cursor: ns-resize; }
.lane-grip:hover { background: rgba(111, 214, 236, 0.12); }

#lane-labels { position: absolute; left: 0; top: 0; bottom: 0; width: 0; z-index: 5; }
.lane-label { position: absolute; left: 0; display: flex; align-items: flex-start; padding: 8px 0 0 8px; pointer-events: none; overflow: hidden; }
.ll-btn {
  pointer-events: auto; display: flex; align-items: center; gap: 7px; padding: 5px 9px 5px 8px;
  background: rgba(13, 27, 41, 0.82); border: 1px solid var(--line); border-left: 3px solid var(--lc);
  border-radius: 8px; color: var(--text); font-weight: 600; font-size: 13px; white-space: nowrap; backdrop-filter: blur(6px);
}
.ll-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--lc); box-shadow: 0 0 8px var(--lc); }
.ll-chev { color: var(--muted); transition: transform 0.15s; }
.ll-chev.closed { transform: rotate(-90deg); }
.lane-label.small .ll-name, .lane-label.small .ll-chev { display: none; }
.lane-label.small { padding-top: 3px; }

/* arcs */
.arc { position: absolute; border-radius: 10px; background: var(--abg); border: 1px solid var(--ac); display: flex; align-items: center; justify-content: center; cursor: grab; }
.arc.global { box-shadow: inset 0 -3px 0 var(--ac); }
.arc.sel { outline: 2px solid var(--accent); outline-offset: 2px; }
.arc-name { font-size: 22px; font-weight: 500; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 24px; pointer-events: none; letter-spacing: 0.3px; }
.arc.char .arc-name { font-size: 12px; font-weight: 600; }
.arc-grip { position: absolute; top: 0; bottom: 0; width: 16px; cursor: ew-resize; }
.arc-grip.l { left: -4px; } .arc-grip.r { right: -4px; }
.arc-grip::after { content: ""; position: absolute; top: 25%; bottom: 25%; left: 6px; width: 3px; border-radius: 2px; background: var(--ac); opacity: 0.8; }
.arc-line { position: absolute; width: 0; border-left: 1px dashed var(--ac); pointer-events: none; }

/* core barriers */
.core-bar {
  position: absolute; width: 14px; background: linear-gradient(90deg, #7b1711, var(--core-bar) 40%, #a2261d);
  border-radius: 2px; box-shadow: 0 0 18px rgba(170, 30, 20, 0.35); pointer-events: none;
}
.core-bar.dim { opacity: 0.25; }

/* edges */
.w-edges { position: absolute; left: 0; top: 0; overflow: visible; }
.w-edges path.edge { fill: none; stroke: rgba(222, 230, 241, 0.6); stroke-width: 1.6; }
.w-edges path.edge.cond { stroke-dasharray: 7 5; }
.w-edges path.edge.dead { stroke: rgba(239, 122, 114, 0.6); }
.w-edges path.edge.sel { stroke: var(--accent); stroke-width: 2.6; filter: drop-shadow(0 0 4px rgba(111, 214, 236, 0.8)); }
.w-edges path.edge.hl { stroke: rgba(111, 214, 236, 0.85); stroke-width: 2.2; }
.w-edges path.edge.hl-strong { stroke: var(--gold); stroke-width: 2.8; }
.w-edges path.edge.dim { opacity: 0.12; }
.w-edges path.hit { fill: none; stroke: transparent; stroke-width: 16; pointer-events: stroke; cursor: pointer; }
.w-edges .temp-edge { fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 5 4; }
.ar-n { fill: rgba(222, 230, 241, 0.75); } .ar-h { fill: var(--gold); } .ar-s { fill: var(--accent); } .ar-d { fill: rgba(239, 122, 114, 0.8); }

.elabel {
  position: absolute; transform: translate(-50%, -50%); display: flex; align-items: center; gap: 4px;
  background: #0f2133; border: 1px solid var(--line-2); color: #dfe8f2; border-radius: 999px; padding: 3px 9px;
  font-size: 12px; white-space: nowrap; max-width: 220px; cursor: pointer; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.elabel span { overflow: hidden; text-overflow: ellipsis; }
.elabel.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft), 0 0 14px rgba(111, 214, 236, 0.45); }
.elabel.hl, .elabel.hl-strong { border-color: var(--gold); }
.elabel.dim { opacity: 0.2; }
.elabel.dead { border-color: rgba(239, 122, 114, 0.6); }
.elabel .ic { color: var(--muted); }
.warn, .warn .ic { color: var(--danger) !important; }

/* nodes */
.node {
  position: absolute; border-radius: 9px; padding: 8px 10px 9px 12px; cursor: grab;
  background: var(--scene); color: #e9f0f7; border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.32); transition: box-shadow 0.15s, opacity 0.15s;
}
.node.dragging { cursor: grabbing; box-shadow: 0 16px 34px rgba(0, 0, 0, 0.5); z-index: 5; }
.node.t-core { background: linear-gradient(180deg, #a6291f, var(--core)); color: #fff; border-color: rgba(255, 160, 150, 0.25); }
.node.t-decision { background: var(--decision); color: #15222f; border-color: #fff; }
.node.t-special { background: var(--special); border: 1.5px solid var(--gold); box-shadow: 0 0 0 1px rgba(230, 187, 94, 0.15), 0 6px 18px rgba(0, 0, 0, 0.35); }
.node.t-ending { background: linear-gradient(180deg, #684894, var(--ending)); border-color: rgba(220, 200, 255, 0.25); }
.node.t-note { background: var(--note); color: #3a3317; border-radius: 3px 12px 3px 3px; transform: rotate(-0.6deg); }
.node.sel {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent), 0 0 18px 4px rgba(111, 214, 236, 0.55), 0 8px 22px rgba(0, 0, 0, 0.45);
}
.node.hl { box-shadow: 0 0 0 2px rgba(111, 214, 236, 0.7), 0 6px 16px rgba(0, 0, 0, 0.32); }
.node.hl-strong { box-shadow: 0 0 0 2px var(--gold), 0 0 16px rgba(230, 187, 94, 0.5); }
.node.dim { opacity: 0.22; }
.node.play-cur { box-shadow: 0 0 0 3px var(--gold), 0 0 26px 6px rgba(230, 187, 94, 0.6); }
.node.dead:not(.t-note) { outline: 1.5px dashed rgba(239, 122, 114, 0.8); outline-offset: 3px; }

.stripes { position: absolute; left: 0; top: 0; bottom: 0; display: flex; border-radius: 9px 0 0 9px; overflow: hidden; }
.stripes i { width: 4px; display: block; }
.n-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 2px; }
.n-type { font-size: 10px; text-transform: uppercase; letter-spacing: 0.9px; opacity: 0.7; font-weight: 600; }
.n-icons { display: flex; gap: 4px; align-items: center; opacity: 0.85; }
.n-icons .gold { color: var(--gold); }
.n-icons .start { color: var(--ok); }
.t-decision .n-icons .gold, .t-note .n-icons .gold { color: #a87a12; }
.n-title { font-weight: 650; font-size: 14.5px; line-height: 1.25; word-wrap: break-word; }
.t-core .n-title { font-size: 16px; }
.n-with { font-size: 11px; opacity: 0.75; font-style: italic; margin-top: 1px; }
.n-sum { font-size: 12px; opacity: 0.82; margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.n-cond { font-size: 11px; margin-top: 5px; padding: 3px 6px; border-radius: 6px; background: rgba(0, 0, 0, 0.22); display: flex; gap: 4px; align-items: center; }
.n-cond .ic { flex: none; }
.t-decision .n-cond, .t-note .n-cond { background: rgba(0, 0, 0, 0.08); }
.n-chips { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 6px; }
.port { position: absolute; top: 50%; width: 14px; height: 14px; margin-top: -7px; border-radius: 50%; }
.port.in { left: -7px; background: transparent; pointer-events: none; }
.port.out {
  right: -9px; width: 18px; height: 18px; margin-top: -9px; background: #0f2133; border: 2px solid var(--accent); cursor: crosshair;
  box-shadow: 0 0 8px rgba(111, 214, 236, 0.5);
}
.port.out::before { content: ""; position: absolute; inset: -12px; } /* bigger touch target */
.t-decision .port.out { border-color: #8aa8c4; }

/* chips */
.chip {
  display: inline-flex; align-items: center; gap: 3px; font-size: 11px; line-height: 1; padding: 4px 7px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.1); border: 1px solid transparent; white-space: nowrap;
}
.chip.up { background: rgba(127, 212, 154, 0.18); color: #b9f0c9; }
.chip.down { background: rgba(239, 122, 114, 0.2); color: #ffc4bf; }
.chip.flag { background: rgba(230, 187, 94, 0.18); color: #f2d796; }
.chip.tag { background: rgba(111, 214, 236, 0.12); color: #aee8f5; }
.t-decision .chip.up, .t-note .chip.up { color: #1d6b37; background: rgba(40, 140, 70, 0.15); }
.t-decision .chip.down, .t-note .chip.down { color: #9a2a22; background: rgba(180, 40, 30, 0.12); }
.t-decision .chip.flag, .t-note .chip.flag { color: #7d5a08; }
.t-decision .chip.tag, .t-note .chip.tag { color: #1c5d72; background: rgba(30, 110, 140, 0.12); }
.chip.toggle { cursor: pointer; padding: 7px 11px; font-size: 13px; background: var(--panel-2); border-color: var(--line); color: var(--text); }
.chip.toggle.on { background: var(--accent-soft); border-color: rgba(111, 214, 236, 0.6); }
.chip.toggle[style*="--cc"].on { background: color-mix(in srgb, var(--cc) 25%, transparent); border-color: var(--cc); }
.chip .count { opacity: 0.6; margin-left: 4px; }
.chip-x { border: 0; background: transparent; color: inherit; padding: 0 0 0 4px; font-size: 14px; line-height: 1; opacity: 0.7; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* zoom + chips over canvas */
#zoom-ctl { position: absolute; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 2px; background: rgba(13, 27, 41, 0.85); border: 1px solid var(--line); border-radius: 10px; padding: 3px; z-index: 6; backdrop-filter: blur(6px); }
.zoom-label { font-size: 12px; color: var(--muted); min-width: 42px; text-align: center; font-variant-numeric: tabular-nums; }
#trace-chip {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 6; display: flex; gap: 10px; align-items: center;
  background: #2b2416; border: 1px solid var(--gold); color: #f5dda0; border-radius: 999px; padding: 7px 14px; font-size: 13px;
}
#trace-chip[hidden], #disk-banner[hidden] { display: none; }
.tc-x { font-size: 16px; opacity: 0.8; }
#disk-banner { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 7; background: #3a2a10; border: 1px solid var(--gold); color: #f5dda0; border-radius: 10px; padding: 9px 14px; }

/* ---------------- dock ---------------- */
#dock { width: 0; overflow: hidden; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; z-index: 20; }
body.dock-open #dock { width: var(--dock-w); }
.dock-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 8px 16px; border-bottom: 1px solid var(--line); flex: none; }
.dock-head h3 { margin: 0; font-size: 15px; flex: 1; }
.grabber { display: none; }
.dock-body { flex: 1; overflow-y: auto; padding: 14px 16px calc(40px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.dock-body > * + * { margin-top: 12px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.f-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--muted); font-weight: 600; }
input[type="text"], input[type="search"], input[type="email"], input[type="password"], input[type="number"], select, textarea {
  background: var(--bg-deep); border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 10px; min-height: 38px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; line-height: 1.45; }
input[type="number"] { font-family: var(--mono); }
input[type="color"] { width: 38px; height: 38px; padding: 2px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--bg-deep); flex: none; }
.title-input { font-size: 16px; font-weight: 600; }
select.mini { width: auto; min-width: 0; padding: 6px 6px; }
.row { display: flex; align-items: center; gap: 6px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.tiny { font-size: 11px; }
.mono { font-family: var(--mono); font-size: 12.5px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; min-height: 38px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--text); white-space: nowrap;
}
.btn:hover { background: var(--panel-3); }
.btn.small { padding: 6px 10px; min-height: 34px; font-size: 13px; }
.btn.primary { background: #2a5d78; border-color: #3b7a99; }
.btn.primary:hover { background: #33708f; }
.btn.danger { color: #ffb4ad; border-color: rgba(239, 122, 114, 0.35); }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }
.icon-btn.pm { font-weight: 700; font-size: 16px; border-color: var(--line-2); width: 32px; }
.linkish { background: none; border: 0; color: var(--accent); padding: 0; text-align: left; }
.actions { flex-wrap: wrap; padding-top: 6px; border-top: 1px solid var(--line); margin-top: 18px !important; }
.check { display: inline-flex; align-items: center; gap: 5px; }

.type-banner { display: flex; flex-direction: column; gap: 6px; padding: 10px; border-radius: 10px; border-left: 4px solid; background: var(--panel-2); }
.type-banner.t-core { border-color: var(--core); } .type-banner.t-decision { border-color: var(--decision); }
.type-banner.t-scene { border-color: #4f7aa3; } .type-banner.t-special { border-color: var(--gold); }
.type-banner.t-ending { border-color: #8a68c0; } .type-banner.t-note { border-color: var(--note); }
.type-select { font-weight: 600; }
.warnbox { display: flex; gap: 8px; padding: 10px; border-radius: 10px; background: rgba(239, 122, 114, 0.12); border: 1px solid rgba(239, 122, 114, 0.4); color: #ffd1cc; font-size: 13px; }
.warnbox .ic { color: var(--danger); margin-top: 1px; }
.edge-route { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; }

.sec { border-top: 1px solid var(--line); padding-top: 12px; }
.sec h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.8px; color: #b8c9da; display: flex; align-items: center; gap: 4px; }
.cond { display: flex; flex-direction: column; gap: 6px; }
.cond-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.clause { flex-wrap: wrap; background: var(--bg-deep); border: 1px solid var(--line); border-radius: 9px; padding: 5px; }
.clause select, .clause input { min-height: 34px; padding: 5px 7px; }
.clause .grow { flex: 1 1 140px; }
.clause .num { width: 72px; flex: none; }
.kind-ico { color: var(--muted); padding: 0 2px 0 4px; }
.add-row { flex-wrap: wrap; }

.notes summary { cursor: pointer; font-size: 12px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--muted); font-weight: 600; padding: 6px 0; }
.notes textarea { margin-top: 6px; min-height: 120px; }

.tag-editor { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; background: var(--bg-deep); border: 1px solid var(--line-2); border-radius: 8px; padding: 5px; }
.tag-editor .tag-input { border: 0; background: transparent; min-height: 28px; padding: 3px 5px; flex: 1; min-width: 90px; width: auto; box-shadow: none; }

.trace .trace-row { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.tr-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 5px; }
.rbar { position: relative; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); flex: 1; min-width: 60px; }
.rbar i { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.contribs { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.contrib { display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: 1px; padding: 6px 9px; border-radius: 8px; background: var(--bg-deep); border: 1px solid var(--line); border-left: 3px solid var(--accent); }
.contrib.up { border-left-color: var(--ok); } .contrib.down { border-left-color: var(--danger); } .contrib.other { border-left-color: var(--muted); }
.c-text { font-size: 13px; font-weight: 600; }
.c-src { font-size: 11.5px; color: var(--muted); }

.list { display: flex; flex-direction: column; gap: 4px; }
.list-item { display: flex; align-items: center; gap: 10px; text-align: left; padding: 9px 10px; border-radius: 9px; background: var(--bg-deep); border: 1px solid var(--line); min-height: 44px; }
.list-item:hover { border-color: var(--line-2); background: #0f2032; }
.li-main { display: flex; flex-direction: column; min-width: 0; }
.li-main > * { overflow: hidden; text-overflow: ellipsis; }
.search-input { font-size: 16px; }
.idea { background: var(--bg-deep); border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.idea textarea { background: transparent; border-color: transparent; min-height: 0; }
.idea textarea:focus { border-color: var(--accent); }
.idea-input { font-size: 15px; }

.swatch { width: 28px; height: 28px; border-radius: 8px; border: 2px solid transparent; }
.swatch.on { border-color: #fff; }

/* playtest */
.play-card { border-radius: 12px; padding: 12px 14px; background: var(--scene); border-left: 4px solid var(--accent); }
.play-card.t-core { background: var(--core); } .play-card.t-decision { background: #2d3b4b; border-left-color: var(--decision); }
.play-card.t-special { border-left-color: var(--gold); background: var(--special); } .play-card.t-ending { background: var(--ending); }
.play-card h3 { margin: 4px 0; font-size: 18px; }
.play-card p { margin: 4px 0 8px; opacity: 0.9; }
.play-opts { display: flex; flex-direction: column; gap: 6px; }
.opt { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px 12px; border-radius: 10px; background: #e3e7ec; color: #14212e; border: 0; text-align: left; font-weight: 600; min-height: 46px; }
.opt:hover:not(:disabled) { background: #fff; box-shadow: 0 0 0 2px var(--accent); }
.opt .muted { color: #5a6b7d; font-weight: 400; }
.opt.locked { background: var(--bg-deep); color: var(--muted); border: 1px dashed var(--line-2); opacity: 1; }
.opt-main { display: flex; align-items: center; gap: 4px; }
.why { font-size: 11.5px; color: #ffb4ad; font-weight: 400; }
.play-stats { display: flex; flex-direction: column; gap: 5px; }
.ps-char { display: flex; align-items: center; gap: 6px; font-weight: 650; margin-top: 4px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.ps-row { display: grid; grid-template-columns: 80px 1fr 32px 80px; align-items: center; gap: 8px; }
.ps-name { font-size: 12.5px; color: var(--muted); }
.ps-tier { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trail { margin: 0; padding-left: 20px; font-size: 13px; }
.trail li { margin: 2px 0; }
.run { padding: 4px 0; border-bottom: 1px dashed var(--line); }
.table-wrap { overflow-x: auto; margin-top: 8px; }
.compare { border-collapse: collapse; font-size: 12px; width: 100%; }
.compare th, .compare td { border-bottom: 1px solid var(--line); padding: 5px 6px; text-align: left; vertical-align: top; }
.compare th { color: var(--muted); font-weight: 600; }

/* ---------------- modal ---------------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(5, 12, 20, 0.6); z-index: 80; display: flex; align-items: center; justify-content: center; padding: 16px; backdrop-filter: blur(3px); }
.modal { background: var(--panel); border: 1px solid var(--line-2); border-radius: 16px; width: min(520px, 100%); max-height: min(88vh, 900px); display: flex; flex-direction: column; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5); }
.modal.wide { width: min(860px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 10px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 16px 20px 22px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-body h4 { margin: 18px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.7px; color: #b8c9da; display: flex; align-items: center; gap: 6px; }
.modal-body .field { margin-top: 8px; }
.help { padding-left: 18px; margin: 4px 0; }
.help li { margin: 3px 0; }

.vault-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin-top: 14px; }
.vault-card { background: var(--bg-deep); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.vault-card.cur { border-color: rgba(111, 214, 236, 0.5); box-shadow: 0 0 0 1px var(--accent-soft); }
.vault-card .row { margin-top: 8px; flex-wrap: wrap; }
.vc-name { font-weight: 650; font-size: 15px; display: flex; gap: 8px; align-items: center; }
.badge { font-size: 10px; text-transform: uppercase; letter-spacing: 0.6px; background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 2px 6px; }
.disk { margin-top: 18px; }
.sync-status { display: flex; align-items: center; gap: 8px; margin: 12px 0; padding: 8px 10px; border-radius: 8px; background: var(--bg-deep); font-size: 13px; }
.sync-status .dot { background: #6b7d90; }
.sync-status.s-idle .dot { background: var(--ok); } .sync-status.s-error .dot { background: var(--danger); }
.sync-status.s-signed-out .dot, .sync-status.s-offline .dot { background: var(--gold); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px 0 12px; overflow-x: auto; }
.tab { background: transparent; border: 0; border-bottom: 2px solid transparent; padding: 9px 12px; color: var(--muted); white-space: nowrap; }
.tab.on { color: var(--text); border-bottom-color: var(--accent); }
.tab-body > * + * { margin-top: 10px; }
.char-card { border: 1px solid var(--line); border-left: 4px solid var(--cc); border-radius: 12px; padding: 10px; background: var(--bg-deep); display: flex; flex-direction: column; gap: 8px; }
.char-card .name { font-weight: 650; font-size: 15px; }
.stat-box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.stat-row { flex-wrap: wrap; }
.stat-row .grow { flex: 1 1 140px; }
.mini-field { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); }
.mini-field input { width: 66px; min-height: 34px; padding: 4px 6px; }
.tiers { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tier { display: inline-flex; align-items: center; gap: 2px; background: var(--bg-deep); border: 1px solid var(--line); border-radius: 8px; padding: 2px 4px; }
.tier input { min-height: 28px; padding: 2px 5px; border-color: transparent; background: transparent; }
.tier input.tier-name { width: 104px; }
.tier input.tier-at { width: 58px; }
.tier input.tier-tell { flex: 1; min-width: 160px; width: auto; color: #cbd8e5; font-style: italic; }
.tiers { flex-direction: column; align-items: stretch; }
.tier { display: flex; }
/* hidden-state presentation */
.variant { background: var(--bg-deep); border: 1px solid var(--line); border-left: 3px solid #8a68c0; border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.variant.dead { border-left-color: var(--danger); }
.variant .cond { padding-top: 2px; }
.v-num { width: 22px; height: 22px; flex: none; border-radius: 50%; background: var(--panel-3); display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; }
.tell { font-size: 12px; font-style: italic; color: #c9b8ea; margin-top: 4px; }
.ps-tell { margin: -2px 0 2px 88px; }
.reaction { margin: 6px 0 8px; padding: 8px 10px; border-radius: 8px; background: rgba(0, 0, 0, 0.25); border-left: 3px solid var(--cc); font-style: italic; }
.reaction b { font-style: normal; }
.seg { display: inline-flex; background: var(--bg-deep); border: 1px solid var(--line-2); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; color: var(--muted); }
.seg button.on { background: var(--panel-3); color: var(--text); }
.vcount { display: inline-flex; align-items: center; gap: 1px; color: #c9b8ea; }
.flag-row .name, .arc-row input.grow { min-width: 0; }
.flag-row .name { width: 200px; flex: none; font-family: var(--mono); font-size: 13px; }
.arc-row select { width: auto; }

/* ---------------- toast ---------------- */
#toast-root { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #1e3a52; border: 1px solid var(--line-2); padding: 9px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); max-width: 90vw; transition: opacity 0.3s, transform 0.3s; }
.toast.warn { background: #3b2a12; border-color: var(--gold); color: #f8e1aa; }
.toast.out { opacity: 0; transform: translateY(8px); }
.fatal { position: fixed; inset: auto 16px 16px; background: #4a1a16; border: 1px solid var(--danger); padding: 14px; border-radius: 10px; z-index: 200; }

/* ---------------- responsive ---------------- */
@media (max-width: 1100px) {
  :root { --dock-w: 350px; }
  .tb-btn .lbl { display: none; }
}
@media (max-width: 760px) {
  :root { --top-h: 50px; }
  .brand span { display: none; }
  .tb-btn[data-a="redo"] { display: none; }
  .tb-btn { min-width: 34px; }
  .ll-btn { font-size: 12px; padding: 3px 7px 3px 6px; }
  .vault-btn { max-width: 140px; }
  .tb-group { padding-left: 4px; gap: 0; }
  .tb-btn { padding: 0 8px; }
  #dock {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto !important; height: 0; border-left: 0; border-top: 1px solid var(--line-2);
    border-radius: 16px 16px 0 0; box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.45);
  }
  body.dock-open #dock { height: 62vh; height: 62dvh; }
  .grabber { display: block; position: absolute; left: 50%; top: 5px; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--line-2); }
  .dock-head { position: relative; padding-top: 14px; }
  #zoom-ctl { bottom: calc(12px + env(safe-area-inset-bottom)); }
  body.dock-open #zoom-ctl { display: none; }
  .modal-wrap { padding: 0; align-items: flex-end; }
  .modal, .modal.wide { width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0; }
  .ps-row { grid-template-columns: 70px 1fr 30px 70px; }
  input, select, textarea { font-size: 16px; } /* stop iOS zoom on focus */
}

/* ---------- pictures ---------- */
.n-img { margin: -8px -10px 8px -12px; height: 74px; border-radius: 9px 9px 0 0; overflow: hidden; background: rgba(0, 0, 0, 0.25); }
.n-img img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
img.missing { opacity: 0; }
.img-picker { display: flex; flex-direction: column; gap: 6px; }
.img-thumb { width: 100%; max-height: 180px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-deep); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.g-item { display: flex; flex-direction: column; gap: 4px; padding: 6px; border-radius: 10px; background: var(--bg-deep); border: 1px solid var(--line); text-align: left; overflow: hidden; }
.g-item:hover { border-color: var(--accent); }
.g-item img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; }
.panel { position: relative; margin: 8px 0; border-radius: 10px; overflow: hidden; background: #000; }
.panel img { display: block; width: 100%; max-height: 300px; object-fit: cover; }
.bubble {
  position: absolute; left: 12px; right: 12px; bottom: 12px; background: #fdfcf7; color: #1a1f27; border-radius: 16px; padding: 8px 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4); border: 2px solid var(--cc); font-size: 14px;
}
.bubble b { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: #4a5566; }
.bubble::after { content: ""; position: absolute; left: 26px; top: -10px; border: 8px solid transparent; border-bottom-color: var(--cc); }
.swap > summary, .lines > summary { cursor: pointer; font-size: 12px; color: var(--muted); padding: 2px 0; }
.lines > summary { list-style: none; }
.lines > summary h4 { display: inline-flex; margin: 0; }
.lines > summary::-webkit-details-marker { display: none; }
.lines { display: flex; flex-direction: column; gap: 6px; }
.lines[open] > summary { margin-bottom: 4px; }
.line-row { background: var(--bg-deep); border: 1px solid var(--line); border-radius: 10px; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.line-row textarea { min-height: 36px; }
.script { display: flex; flex-direction: column; gap: 4px; margin: 6px 0; }
.sline { font-size: 14px; padding-left: 8px; border-left: 2px solid var(--cc); }
.sline b { margin-right: 6px; }
.sline.narr { font-style: italic; opacity: 0.9; border-left-color: transparent; }

/* ---------- lane label sheet button ---------- */
.lane-label { gap: 4px; }
.ll-sheet { pointer-events: auto; display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 8px; background: rgba(13, 27, 41, 0.82); border: 1px solid var(--line); color: var(--muted); }
.ll-sheet:hover { color: var(--text); }
.lane-label.small .ll-sheet { display: none; }

/* ---------- new project ---------- */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.tpl { display: flex; flex-direction: column; gap: 3px; text-align: left; padding: 12px; border-radius: 12px; background: var(--bg-deep); border: 1px solid var(--line); }
.tpl.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

/* ---------- character sheet ---------- */
.sheet { display: grid; grid-template-columns: 260px 1fr; gap: 20px; }
.sheet-left, .sheet-right { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.sheet-left .img-thumb { max-height: 320px; aspect-ratio: 3 / 4; }
.sheet-stats { background: var(--bg-deep); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 3px; }
.sheet-stats h4 { margin-top: 0 !important; }
.ss-row { margin-top: 6px; }
.ss-tier { font-size: 12.5px; padding-left: 8px; }
.ss-tier .tell { display: inline; margin: 0; }
.custom-field { display: flex; flex-direction: column; gap: 4px; }
.f-label-input { font-size: 11px !important; text-transform: uppercase; letter-spacing: 0.7px; font-weight: 600; }
@media (max-width: 760px) { .sheet { grid-template-columns: 1fr; } }

/* ---------- export ---------- */
.exp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin-top: 12px; }
.exp-card { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-radius: 12px; background: var(--bg-deep); border: 1px solid var(--line); }
.exp-card .row { margin-top: auto; padding-top: 6px; }
pre.code { margin-top: 10px; padding: 12px; background: var(--bg-deep); border: 1px solid var(--line); border-radius: 10px; font: 12px/1.5 var(--mono); white-space: pre-wrap; overflow-x: auto; max-height: 60vh; }

/* ---------- expressions & line-by-line playtest ---------- */
.panel.nobg { background: linear-gradient(180deg, #1d3550, #12243a); min-height: 200px; }
.panel img.sprite { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); height: 88%; max-height: 280px; width: auto; object-fit: contain; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.5)); }
.panel.nobg img.sprite { height: 180px; }
.bubble.narr { font-style: italic; background: rgba(20, 30, 42, 0.88); color: #e7eef6; border-color: transparent; }
.bubble.narr::after { display: none; }
.expr-tag { font-weight: 400; opacity: 0.75; text-transform: none; letter-spacing: 0; }
.step-row { margin: 4px 0 6px; }
ol.script { margin: 6px 0; padding-left: 22px; }
ol.script .sline { cursor: pointer; border-radius: 4px; padding: 2px 6px; }
ol.script .sline.cur { background: rgba(255, 255, 255, 0.1); }
.expr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin: 6px 0; }
.expr-card { display: flex; flex-direction: column; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px; }
.expr-card img, .expr-empty { width: 100%; aspect-ratio: 3 / 4; object-fit: contain; border-radius: 6px; background: rgba(0, 0, 0, 0.25); }
.expr-empty { display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); }
.expr-card input { min-height: 30px; padding: 3px 6px; font-size: 13px; }
.expr-card .row { flex-wrap: wrap; gap: 2px; }
.expr-select { max-width: 130px; }

/* ---------- multi-select & bulk editing ---------- */
.node.msel { outline: 2px dashed var(--accent); outline-offset: 4px; }
.node.msel::after {
  content: "✓"; position: absolute; top: -10px; right: -10px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); color: #0d1b29; font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center;
}
body.select-mode #stage { cursor: crosshair; }
body.select-mode #stage::after {
  content: "Select mode: tap boxes · drag to lasso · two fingers to pan · Esc when done"; position: absolute; left: 50%; bottom: 64px; transform: translateX(-50%);
  background: rgba(13, 27, 41, 0.9); border: 1px solid var(--accent); color: #cfeef6; padding: 7px 14px; border-radius: 999px; font-size: 12.5px; pointer-events: none; white-space: nowrap; z-index: 6;
}
#lasso { position: absolute; border: 1.5px dashed var(--accent); background: rgba(111, 214, 236, 0.1); border-radius: 4px; pointer-events: none; z-index: 8; }
#lasso[hidden] { display: none; }
.bulk-rows { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.bulk-row { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 8px; background: var(--bg-deep); border: 1px solid var(--line); }
.bulk-row .linkish { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.bulk-row .num, .sec .row .num { width: 76px; flex: none; min-height: 34px; padding: 4px 6px; }
.radios { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.radio { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border-radius: 10px; background: var(--bg-deep); border: 1px solid var(--line); cursor: pointer; }
.radio.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.radio input { margin-top: 3px; }
.radio span { display: flex; flex-direction: column; }
.rel-pick { margin: 6px 0; }
.rel-pick select { width: auto; }
.rel-head { font-size: 12.5px; color: #c9b8ea; }
.rel-row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; font-size: 13px; padding: 3px 0; }
.rel-row .btn { margin-left: auto; padding: 4px 6px; min-height: 28px; }
.add-control { margin: 6px 0; }

.bulk-row.head { background: transparent; border-color: transparent; padding-bottom: 0; }
.bulk-row.opt-row { margin-left: 18px; }
