/* Plot Trellis - a whiteboard: near-white board with a faint dot grid, soft
 * rounded cards tinted by depth (a pastel ramp), marker-coloured connectors
 * per act. Light by default; the dark board keeps the same ramp, deepened. */

:root {
  --font: "Avenir Next", Avenir, "Century Gothic", "Futura", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --board: #fbfaf7; --dot: #dedbe8; --ink: #2b2a33; --ink-2: #5d5a6b; --ink-3: #8b87a0;
  --rule: #e7e3ef; --panel: #ffffff; --panel-2: #f6f4fb; --shadow: 0 1px 2px rgba(40, 32, 80, .06), 0 6px 18px rgba(40, 32, 80, .07);
  --accent: #6c58ee; --accent-2: #5443d2; --accent-ink: #ffffff; --accent-soft: #ece8ff;
  --good: #2c9466; --good-soft: #e1f5ea; --warn: #b97a10; --warn-soft: #fff1d4; --bad: #cf563d; --bad-soft: #ffe6df;
  --t0: #e9e4ff; --t1: #dff0ff; --t2: #e2f6e7; --t3: #fff3d6; --t4: #ffe7e1;
  --s0: #b9aef0; --s1: #a9cdef; --s2: #a8d8b4; --s3: #ecd394; --s4: #f0b9aa;
  --b0: #7c6cf0; --b1: #3f9be0; --b2: #3fb07a; --b3: #e0a23a; --b4: #e0705a; --b5: #c262c9; --b6: #5a8fa8;
  --k-turn: #e0705a; --k-setup: #3f9be0; --k-payoff: #3fb07a; --k-note: #a9a4bb;
  --radius: 14px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --board: #16151b; --dot: #2b2935; --ink: #ecebf3; --ink-2: #b6b3c6; --ink-3: #8a869c;
  --rule: #302d3b; --panel: #201e28; --panel-2: #282532; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 22px rgba(0, 0, 0, .35);
  --accent: #9a8cff; --accent-2: #b2a7ff; --accent-ink: #15131c; --accent-soft: #2d2852;
  --good: #5fd09b; --good-soft: #1b3428; --warn: #f0b84e; --warn-soft: #3a2f16; --bad: #ff8a72; --bad-soft: #3e231d;
  --t0: #2f2954; --t1: #1c3249; --t2: #1d392b; --t3: #3e3419; --t4: #43261e;
  --s0: #5a4fa8; --s1: #3b6690; --s2: #3d7656; --s3: #7d6a33; --s4: #87503f;
  --b0: #9a8cff; --b1: #63b4f0; --b2: #5fd09b; --b3: #f0b84e; --b4: #ff8a72; --b5: #dd86e2; --b6: #84b5cc;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font); color: var(--ink); background-color: var(--board);
  background-image: radial-gradient(var(--dot) 1.1px, transparent 1.2px); background-size: 22px 22px;
  font-size: 15px; line-height: 1.45; min-height: 100vh; overflow-x: hidden;
}
.hidden { display: none !important; }
.mono { font-family: var(--mono); font-size: .85em; }
a { color: var(--accent-2); }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 700; }
h3 { font-size: 13px; font-weight: 700; }
.hint { color: var(--ink-3); font-size: 12.5px; margin: 4px 0; }

/* --- buttons ------------------------------------------------------------ */
.btn {
  font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; color: var(--ink);
  background: var(--panel); border: 1.5px solid var(--rule); border-radius: 999px; padding: 7px 14px; line-height: 1.2;
  transition: border-color .12s, background .12s, transform .08s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); }
.btn.small { font-size: 12.5px; padding: 5px 11px; }
.btn.icon { padding: 6px 10px; min-width: 34px; }
.btn.ghosty { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.tool { background: var(--panel); }
.linkish { font: inherit; color: var(--accent-2); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }
.chip-link { color: var(--ink-2); text-decoration: none; font-size: 13px; padding: 5px 10px; border-radius: 999px; border: 1.5px solid var(--rule); background: var(--panel); white-space: nowrap; }
.chip { display: inline-block; font-size: 11.5px; font-weight: 600; color: var(--accent-2); background: var(--accent-soft); border-radius: 999px; padding: 1px 8px; margin-left: 6px; }
.free, .paid { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; border-radius: 999px; padding: 2px 8px; }
.free { color: var(--good); background: var(--good-soft); }
.paid { color: var(--accent-2); background: var(--accent-soft); }

/* --- top bar and toolbar ---------------------------------------------------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px 8px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; min-width: 0; }
.mark { width: 34px; height: 34px; color: var(--accent); flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 19px; letter-spacing: -.02em; }
.story-line { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.session { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.credits { font-size: 13px; font-weight: 700; color: var(--good); background: var(--good-soft); border-radius: 999px; padding: 5px 11px; }

.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  margin: 0 18px 10px; padding: 7px 8px; background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1.5px solid var(--rule); border-radius: 18px; box-shadow: var(--shadow); position: sticky; top: 6px; z-index: 20;
  backdrop-filter: blur(6px);
}
.tool-group { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary::after { content: " \25BE"; font-size: 11px; color: var(--ink-3); }
.menu-pop {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 40; min-width: 250px; background: var(--panel);
  border: 1.5px solid var(--rule); border-radius: 14px; box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; gap: 2px;
}
.menu-pop.right { left: auto; right: 0; }
.mi { font: inherit; text-align: left; background: none; border: 0; color: var(--ink); padding: 8px 10px; border-radius: 10px; cursor: pointer; font-size: 13.5px; }
.mi:hover, .mi:focus-visible { background: var(--panel-2); outline: none; }
.mi small { display: block; color: var(--ink-3); font-size: 12px; }
.tabs { display: none; }
.tab { font: inherit; font-size: 13.5px; font-weight: 700; background: none; border: 0; color: var(--ink-2); padding: 8px 12px; border-radius: 12px; cursor: pointer; }
.tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent-2); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 11px; line-height: 18px; text-align: center; }

/* --- workspace ---------------------------------------------------------------- */
.workspace { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr) minmax(300px, 360px); gap: 14px; padding: 0 18px 18px; align-items: start; }
.workspace > * { min-width: 0; }
.pane { background: color-mix(in srgb, var(--panel) 94%, transparent); border: 1.5px solid var(--rule); border-radius: 20px; box-shadow: var(--shadow); }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px 6px; }
.counts { font-size: 12px; color: var(--ink-3); }
.side-pane { background: none; border: 0; box-shadow: none; display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--panel); border: 1.5px solid var(--rule); border-radius: 20px; box-shadow: var(--shadow); padding: 12px 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }

/* --- outline ------------------------------------------------------------------ */
.outline-pane { position: sticky; top: 74px; max-height: calc(100vh - 88px); display: flex; flex-direction: column; }
.story-meta { margin: 0 14px 6px; padding: 6px 10px; border-radius: 12px; background: var(--panel-2); }
.story-meta summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.lbl { display: block; font-size: 12px; font-weight: 700; color: var(--ink-2); margin: 8px 0 3px; }
input[type="text"], textarea, select {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--panel); border: 1.5px solid var(--rule); border-radius: 10px; padding: 6px 9px; width: 100%;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.outline { overflow: auto; padding: 4px 8px 6px; flex: 1 1 auto; min-height: 160px; }
.row {
  position: relative; display: flex; align-items: center; gap: 4px; padding: 1px 4px 1px calc(4px + var(--depth, 0) * 18px);
  border-radius: 10px; min-height: 34px;
}
.row::before { /* indent guide */
  content: ""; position: absolute; left: calc(var(--depth, 0) * 18px - 6px); top: 0; bottom: 0; width: 1.5px; background: var(--rule);
}
.row.d0::before, .row.d1::before { display: none; }
.row:hover { background: var(--panel-2); }
.row.sel { background: var(--accent-soft); }
.row .handle { cursor: grab; color: var(--ink-3); font-size: 13px; width: 16px; text-align: center; user-select: none; touch-action: none; flex: none; padding: 6px 0; }
.row.d0 .handle { visibility: hidden; }
.row .tw { font: inherit; width: 20px; height: 22px; flex: none; border: 0; background: none; color: var(--ink-3); cursor: pointer; border-radius: 6px; padding: 0; font-size: 11px; }
.row .tw:hover { background: var(--rule); color: var(--ink); }
.row .tw.leaf { visibility: hidden; }
.row .dotk { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--dc, var(--s1)); }
.row.d0 .dotk { --dc: var(--s0); } .row.d1 .dotk { --dc: var(--s1); } .row.d2 .dotk { --dc: var(--s2); } .row.d3 .dotk { --dc: var(--s3); } .row.d4 .dotk, .row.d5 .dotk { --dc: var(--s4); }
.row .tx {
  flex: 1 1 auto; min-width: 0; border: 0; background: transparent; padding: 5px 6px; border-radius: 8px; font-size: 14px; color: var(--ink);
}
.row .tx:focus { background: var(--panel); outline: 2px solid var(--accent); }
.row.d0 .tx { font-weight: 800; font-size: 16px; }
.row.d1 .tx { font-weight: 700; }
.row.d2 .tx { font-weight: 600; }
.row .kchip { flex: none; font-size: 10px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; border-radius: 6px; padding: 1px 5px; color: #fff; background: var(--k-note); }
.row .kchip.turn { background: var(--k-turn); } .row .kchip.setup { background: var(--k-setup); } .row .kchip.payoff { background: var(--k-payoff); }
.row .cnt { flex: none; font-size: 11px; color: var(--ink-3); padding: 0 2px; }
.row .flag { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.row.drop-before { box-shadow: inset 0 2.5px 0 var(--accent); }
.row.drop-after { box-shadow: inset 0 -2.5px 0 var(--accent); }
.row.drop-inside { background: var(--accent-soft); outline: 2px dashed var(--accent); }
.row.dragging { opacity: .45; }
.row.ghost { border: 1.5px dashed var(--accent); background: transparent; margin: 2px 0; }
.row.ghost .gtext { flex: 1 1 auto; min-width: 0; font-style: italic; color: var(--accent-2); font-size: 13.5px; padding: 4px 4px; }
.prop-tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--accent-2); border: 1.5px dashed var(--accent); border-radius: 8px; padding: 1px 6px; margin: 0 0 2px calc(40px + var(--depth, 0) * 18px); }
.mini { font: inherit; font-size: 11.5px; font-weight: 700; cursor: pointer; border-radius: 7px; padding: 2px 7px; border: 1.5px solid var(--accent); background: var(--accent); color: var(--accent-ink); }
.mini.no { background: transparent; color: var(--ink-3); border-color: var(--rule); }
.add-row { display: flex; align-items: center; gap: 10px; padding: 4px 14px 8px; flex-wrap: wrap; }
.inspector { border-top: 1.5px solid var(--rule); padding: 10px 14px 12px; }
.path { font-weight: 500; color: var(--ink-3); font-size: 12px; }
.kinds { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.kind { font: inherit; font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 999px; border: 1.5px solid var(--rule); background: var(--panel); color: var(--ink-2); cursor: pointer; }
.kind[aria-checked="true"] { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.kind.k-turn[aria-checked="true"] { background: var(--k-turn); border-color: var(--k-turn); color: #fff; }
.kind.k-setup[aria-checked="true"] { background: var(--k-setup); border-color: var(--k-setup); color: #fff; }
.kind.k-payoff[aria-checked="true"] { background: var(--k-payoff); border-color: var(--k-payoff); color: #fff; }
.insp-actions { display: flex; gap: 8px; margin-top: 8px; }

/* --- map ------------------------------------------------------------------------ */
.map-pane { position: sticky; top: 74px; display: flex; flex-direction: column; height: calc(100vh - 88px); min-height: 420px; background: transparent; }
.map-tools { display: flex; gap: 5px; flex-wrap: wrap; }
.map-wrap { position: relative; flex: 1 1 auto; min-height: 0; }
.map { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; user-select: none; }
.map.panning { cursor: grabbing; }
.map-hint { position: absolute; left: 50%; transform: translateX(-50%); bottom: 8px; margin: 0; max-width: calc(100% - 24px); font-size: 11.5px; color: var(--ink-3); pointer-events: none; text-align: center; background: color-mix(in srgb, var(--panel) 88%, transparent); border: 1px solid var(--rule); border-radius: 999px; padding: 3px 12px; }
.map text { font-family: var(--font); fill: var(--ink); }
.map .nd { cursor: pointer; }
.map .card { fill: var(--panel); stroke: var(--rule); stroke-width: 1.2; filter: drop-shadow(0 1px 1.5px rgba(40, 32, 80, .10)); }
.map .d0 .card { fill: var(--t0); stroke: var(--s0); } .map .d1 .card { fill: var(--t1); stroke: var(--s1); }
.map .d2 .card { fill: var(--t2); stroke: var(--s2); } .map .d3 .card { fill: var(--t3); stroke: var(--s3); }
.map .d4 .card, .map .d5 .card { fill: var(--t4); stroke: var(--s4); }
.map .d0 .tx { font-weight: 800; } .map .d1 .tx { font-weight: 700; } .map .d2 .tx { font-weight: 600; }
.map .nd.sel .card { stroke: var(--accent); stroke-width: 2.6; }
.map .nd.flag .card { stroke: var(--warn); stroke-width: 2; }
.map .nd.sel.flag .card { stroke: var(--accent); }
.map .nd.drop .card { stroke: var(--accent); stroke-width: 3; stroke-dasharray: 5 3; }
.map .nd.lifted { opacity: .4; }
.map .kbar { fill: var(--k-note); } .map .k-turn .kbar { fill: var(--k-turn); } .map .k-setup .kbar { fill: var(--k-setup); } .map .k-payoff .kbar { fill: var(--k-payoff); }
.map .lk { fill: none; stroke-linecap: round; opacity: .85; }
.map .b0 { stroke: var(--b0); } .map .b1 { stroke: var(--b1); } .map .b2 { stroke: var(--b2); } .map .b3 { stroke: var(--b3); }
.map .b4 { stroke: var(--b4); } .map .b5 { stroke: var(--b5); } .map .b6 { stroke: var(--b6); }
.map .fold circle { fill: var(--panel); stroke: var(--ink-3); stroke-width: 1.2; cursor: pointer; }
.map .fold path { stroke: var(--ink-2); stroke-width: 1.6; }
.map .fold text { fill: var(--ink-2); font-weight: 700; }
.map .ghost .card { fill: color-mix(in srgb, var(--accent-soft) 55%, transparent); stroke: var(--accent); stroke-dasharray: 5 4; filter: none; }
.map .ghost .tx { fill: var(--accent-2); font-style: italic; }
.map .lk.ghost { stroke: var(--accent); stroke-dasharray: 6 5; }
.map .rn { fill: var(--accent-2); font-style: italic; } .map .rn-rule { stroke: var(--accent); stroke-dasharray: 4 3; }
.map .ov { fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-dasharray: 6 5; }
.map .ovl rect { fill: var(--panel); stroke: var(--accent); stroke-dasharray: 4 3; }
.map .ovl text { fill: var(--accent-2); font-weight: 700; }
.map .ovl, .map .acc { cursor: pointer; }
.map .acc circle { fill: var(--accent); }
.map .acc path { fill: none; stroke: var(--accent-ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.map .arrowhead, .arrowhead { fill: var(--accent); }

/* --- balance and checks ------------------------------------------------------------ */
.score { font-weight: 800; font-size: 13px; border-radius: 999px; padding: 2px 9px; background: var(--good-soft); color: var(--good); }
.score.mid { background: var(--warn-soft); color: var(--warn); }
.score.low { background: var(--bad-soft); color: var(--bad); }
.bal-bar { position: relative; display: flex; height: 26px; border-radius: 10px; overflow: hidden; background: var(--panel-2); margin: 6px 0 4px; }
.bal-seg { height: 100%; min-width: 2px; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 800; color: #2b2a33; white-space: nowrap; overflow: hidden; }
.bal-tick { position: absolute; top: -3px; bottom: -3px; width: 0; border-left: 2px dashed var(--ink); opacity: .55; }
.bal-table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 6px; }
.bal-table th { text-align: left; color: var(--ink-3); font-weight: 700; font-size: 11.5px; padding: 3px 4px; }
.bal-table td { padding: 4px; border-top: 1px solid var(--rule); }
.bal-table td:first-child { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bal-table .heavy { color: var(--bad); font-weight: 700; } .bal-table .thin { color: var(--warn); font-weight: 700; }
.swatch { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: 0; }
.check-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 5px; }
.check-list li { font-size: 13px; padding: 6px 9px; border-radius: 10px; background: var(--panel-2); border-left: 4px solid var(--ink-3); }
.check-list li.warn { border-left-color: var(--warn); }
.check-list li.none { border-left-color: var(--good); color: var(--ink-2); }
.idlink { font: inherit; font-family: var(--mono); font-size: 11.5px; color: var(--accent-2); background: var(--accent-soft); border: 0; border-radius: 6px; padding: 0 5px; cursor: pointer; margin-left: 3px; }

/* --- critique ------------------------------------------------------------------------- */
.run-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.meter { font-size: 12.5px; color: var(--ink-2); margin: 4px 0; min-height: 1em; }
.gate, .replay { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; background: var(--accent-soft); border-radius: 12px; padding: 8px 10px; margin: 6px 0; }
.replay { background: var(--good-soft); }
.progress { border: 1.5px dashed var(--accent); border-radius: 14px; padding: 9px 12px; margin: 8px 0; }
.pg-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.pg-steps { margin: 6px 0 0; padding-left: 20px; font-size: 12.5px; color: var(--ink-3); }
.pg-steps li.done { color: var(--good); }
.pg-steps li.now { color: var(--ink); font-weight: 700; }
.result h3 { margin: 12px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); }
.verdict { border-radius: 14px; padding: 10px 12px; background: var(--panel-2); font-size: 13.5px; }
.verdict .shape { display: inline-block; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; border-radius: 999px; padding: 2px 8px; margin-bottom: 4px; }
.shape.sound { background: var(--good-soft); color: var(--good); } .shape.workable { background: var(--warn-soft); color: var(--warn); } .shape.needs_work { background: var(--bad-soft); color: var(--bad); }
.verdict p { margin: 4px 0; }
.branch-group { margin-top: 8px; }
.branch-group h4 { margin: 0 0 4px; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.finding { font-size: 13px; padding: 7px 9px; border-radius: 10px; background: var(--panel-2); margin-bottom: 5px; }
.finding .ft { font-weight: 700; font-size: 12px; color: var(--ink-2); }
.finding .st { font-size: 10.5px; font-weight: 800; text-transform: uppercase; border-radius: 6px; padding: 1px 5px; margin-left: 4px; }
.st.resolved { background: var(--good-soft); color: var(--good); } .st.open { background: var(--warn-soft); color: var(--warn); } .st.new { background: var(--accent-soft); color: var(--accent-2); }
.st.disputed { background: var(--bad-soft); color: var(--bad); }
.proposal { border: 1.5px dashed var(--accent); border-radius: 12px; padding: 8px 10px; margin-bottom: 6px; font-size: 13px; }
.proposal.accepted { border-style: solid; border-color: var(--good); }
.proposal.dismissed, .proposal.refused, .proposal.stale { border-color: var(--rule); opacity: .7; }
.proposal .what { font-weight: 700; }
.proposal .why { color: var(--ink-2); font-size: 12.5px; margin: 2px 0 6px; }
.proposal .acts { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.proposal .state { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); }
.notes { list-style: none; padding: 0; margin: 0; font-size: 12.5px; }
.notes li { padding: 5px 8px; border-radius: 8px; margin-bottom: 4px; background: var(--panel-2); color: var(--ink-2); }
.notes li.warn { background: var(--warn-soft); color: var(--ink); }
.none { color: var(--ink-3); font-size: 13px; font-style: italic; margin: 2px 0; }
.res-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* --- dialogs, toasts, footer -------------------------------------------------------------- */
.dlg { border: 1.5px solid var(--rule); border-radius: 20px; padding: 0; background: var(--panel); color: var(--ink); width: min(620px, calc(100vw - 32px)); box-shadow: var(--shadow); }
.dlg::backdrop { background: rgba(20, 16, 40, .35); }
.dlg-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; }
.dlg-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dlg-row.end { justify-content: flex-end; }
.drop { border-radius: 12px; }
.drop.over textarea { outline: 2px dashed var(--accent); }
.drop textarea { font-family: var(--mono); font-size: 13px; }
.history { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow: auto; display: flex; flex-direction: column; gap: 5px; }
.history li { display: flex; gap: 6px; align-items: stretch; }
.h-open { flex: 1 1 auto; min-width: 0; text-align: left; font: inherit; background: var(--panel-2); border: 1.5px solid transparent; border-radius: 12px; padding: 8px 10px; cursor: pointer; color: var(--ink); }
.h-open.cur { border-color: var(--accent); }
.h-open span { display: block; }
.h-sub { font-size: 12px; color: var(--ink-3); }
.h-del { font: inherit; border: 1.5px solid var(--rule); background: var(--panel); border-radius: 12px; cursor: pointer; color: var(--ink-3); padding: 0 12px; }
.keys { border-collapse: collapse; font-size: 13.5px; }
.keys td { padding: 5px 8px; border-top: 1px solid var(--rule); }
.keys td:first-child { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 80; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--panel); border: 1.5px solid var(--rule); border-left: 5px solid var(--accent); border-radius: 12px; padding: 9px 12px; font-size: 13.5px; box-shadow: var(--shadow); transition: opacity .5s; }
.toast.ok { border-left-color: var(--good); } .toast.warn { border-left-color: var(--warn); } .toast.err { border-left-color: var(--bad); }
.toast a { margin-left: 8px; }
.toast.gone { opacity: 0; }
.foot { padding: 6px 18px 28px; font-size: 12.5px; color: var(--ink-3); }
.foot p { margin: 4px 0; }
.print-area { display: none; }

/* --- narrower screens ---------------------------------------------------------------------- */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); }
  .side-pane { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); align-items: start; }
  .critique { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  body { padding-bottom: 86px; font-size: 15px; }
  .topbar { padding: 10px 16px 6px; }
  .story-line { max-width: 52vw; }
  #home { display: none; }
  .toolbar {
    position: fixed; top: auto; bottom: max(10px, env(safe-area-inset-bottom)); left: 10px; right: 10px; margin: 0;
    flex-direction: column-reverse; align-items: stretch; gap: 6px; border-radius: 20px; padding: 6px;
  }
  .tool-group { justify-content: center; gap: 4px; }
  .tool-group .btn.tool { padding: 6px 10px; font-size: 12.5px; }
  .menu-pop { top: auto; bottom: calc(100% + 8px); }
  .tabs { display: flex; justify-content: space-around; }
  .tab { flex: 1; padding: 9px 6px; }
  .workspace { display: block; padding: 0 16px 16px; }
  .pane, .side-pane { display: none; }
  body[data-tab="outline"] .outline-pane { display: flex; }
  body[data-tab="map"] .map-pane { display: flex; }
  body[data-tab="critique"] .side-pane { display: flex; }
  .outline-pane, .map-pane { position: static; max-height: none; }
  .map-pane { height: calc(100vh - 210px); }
  .row { min-height: 40px; }
  .row .tx { font-size: 15px; padding: 8px 6px; }
  .row .handle { width: 22px; font-size: 15px; }
  .map-hint { display: none; }
  .toasts { bottom: 150px; }
}

/* --- print: only the one-page outline ------------------------------------------------------- */
@media print {
  body { background: #fff; color: #000; padding: 0; }
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block !important; }
  .po { font-family: var(--font); font-size: 10.5pt; line-height: 1.35; columns: 2; column-gap: 22pt; }
  .po header { column-span: all; margin-bottom: 8pt; }
  .po h1 { font-size: 18pt; }
  .po-sub, .po-log { margin: 2pt 0; color: #444; }
  .po-bal { display: flex; column-span: all; margin: 6pt 0 10pt; border: 1px solid #999; font-size: 8pt; }
  .po-bal span { padding: 2pt 4pt; border-right: 1px solid #999; white-space: nowrap; overflow: hidden; }
  .po-parts { padding-left: 16pt; margin: 0; }
  .po-parts > li { break-inside: avoid-column; margin-bottom: 6pt; }
  .po h2 { font-size: 12pt; margin: 4pt 0 2pt; } .po h2 small { font-weight: 400; color: #666; font-size: 8.5pt; }
  .po h3 { font-size: 10.5pt; margin: 3pt 0 1pt; }
  .po-ch { padding-left: 14pt; margin: 0; }
  .po-sc { padding-left: 12pt; margin: 0 0 3pt; }
  .po-note { margin: 0 0 2pt; color: #555; font-size: 9pt; font-style: italic; }
  .po-k { font-style: normal; font-size: 7.5pt; font-weight: 700; text-transform: uppercase; border: 1px solid #888; border-radius: 3pt; padding: 0 2pt; }
  .po-gaps { column-span: all; border-top: 1px solid #999; margin-top: 8pt; }
  .po footer { column-span: all; margin-top: 8pt; color: #888; font-size: 8pt; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
