/* Сценарная — рабочая комната сценариста.
   Раскладка: стол цвета грифеля, на нём листы сценария (моноширинный шрифт, как в индустрии)
   и учётные карточки с красной линейкой. Акцент — синие чернила, второй цвет — красный карандаш. */
:root {
  --bg: #eceff3;
  --surface: #f7f8fa;
  --surface-2: #e3e7ec;
  --paper: #ffffff;
  --ink: #1b1f24;
  --muted: #5d6874;
  --line: #d3d9e0;
  --line-strong: #aab3be;
  --accent: #2a55c4;
  --accent-ink: #ffffff;
  --accent-soft: #dfe7fb;
  --rule: #cf3f35;
  --card-lines: #dbe6f5;
  --warn: #b45f06;
  --danger: #b4231a;
  --ok: #24804f;
  --note-bg: #fff6d6;
  --shadow: 0 1px 2px rgba(20, 30, 45, .07), 0 6px 18px rgba(20, 30, 45, .07);

  --st-idea: #98a2b0;
  --st-draft: #c88a1a;
  --st-revision: #7a5bc9;
  --st-done: #2c8a57;
  --act-1: #2a55c4;
  --act-2: #5b7fd8;
  --act-3: #1d3a8a;
  --act-4: #8aa5e6;

  --c-red: #d6453b;
  --c-orange: #e07b28;
  --c-yellow: #d9ae1e;
  --c-green: #3a9b5a;
  --c-teal: #1f9a9a;
  --c-blue: #3567d6;
  --c-violet: #8257cf;
  --c-none: #a3acb7;

  --font-ui: "Golos Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-script: "PT Mono", "Courier Prime", "Courier New", Courier, monospace;
  --radius: 8px;
  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121519;
    --surface: #191d22;
    --surface-2: #232830;
    --paper: #1f242b;
    --ink: #e3e7ec;
    --muted: #9aa5b2;
    --line: #2f363f;
    --line-strong: #4a535e;
    --accent: #7d9ff5;
    --accent-ink: #0e1420;
    --accent-soft: #23304d;
    --rule: #ec6a5f;
    --card-lines: #28323f;
    --warn: #e5a04a;
    --danger: #f07167;
    --ok: #5cc48a;
    --note-bg: #3a3420;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 8px 22px rgba(0, 0, 0, .3);
    --st-idea: #7d8794;
    --st-draft: #e0a43a;
    --st-revision: #a58bea;
    --st-done: #4fbd80;
    --act-1: #7d9ff5;
    --act-2: #5677cc;
    --act-3: #a9c0fa;
    --act-4: #3f5aa0;
    --c-none: #6b7480;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121519;
  --surface: #191d22;
  --surface-2: #232830;
  --paper: #1f242b;
  --ink: #e3e7ec;
  --muted: #9aa5b2;
  --line: #2f363f;
  --line-strong: #4a535e;
  --accent: #7d9ff5;
  --accent-ink: #0e1420;
  --accent-soft: #23304d;
  --rule: #ec6a5f;
  --card-lines: #28323f;
  --warn: #e5a04a;
  --danger: #f07167;
  --ok: #5cc48a;
  --note-bg: #3a3420;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 8px 22px rgba(0, 0, 0, .3);
  --st-idea: #7d8794;
  --st-draft: #e0a43a;
  --st-revision: #a58bea;
  --st-done: #4fbd80;
  --act-1: #7d9ff5;
  --act-2: #5677cc;
  --act-3: #a9c0fa;
  --act-4: #3f5aa0;
  --c-none: #6b7480;
  color-scheme: dark;
}

/* ------------------------------------------------------------ основа */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; text-wrap: balance; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mono { font-family: var(--font-script); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.spacer { flex: 1; }
.boot { padding: 40px var(--gutter-r) 40px var(--gutter-l); color: var(--muted); }
#app { min-height: 100%; display: flex; flex-direction: column; }
#app > main { flex: 1 0 auto; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row > input:not([type="range"]):not([type="file"]) { flex: 1 1 160px; width: auto; }
.row > .field { flex: 1 1 200px; }
.row.between { justify-content: space-between; }
.grid-2, .grid-3 { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }
.scroll-x { overflow-x: auto; max-width: 100%; }

/* ------------------------------------------------------------ элементы управления */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 14px; border-radius: 6px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink); }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); border-color: transparent; }
.btn-small { min-height: 28px; padding: 2px 10px; font-size: .85rem; }
.btn-block { width: 100%; }
.icon-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; width: 32px; height: 32px; border-radius: 6px; flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

input, select, textarea {
  width: 100%; min-height: 38px; padding: 7px 10px; border-radius: 6px;
  border: 1px solid var(--line-strong); background: var(--paper);
}
textarea { resize: vertical; line-height: 1.45; }
input[type="range"] { padding: 0; border: 0; background: transparent; min-height: 24px; accent-color: var(--accent); }
input[type="file"] { padding: 6px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field-label { font-size: .8rem; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.field-hint { font-size: .78rem; color: var(--muted); }
.form { display: grid; gap: 14px; }
.form-error { color: var(--danger); font-size: .9rem; }
.inline-field { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: .9rem; }
.inline-field select { width: auto; }

.seg-toggle { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; background: var(--surface-2); border-radius: 8px; }
.seg-toggle button { border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 500; display: inline-flex; gap: 6px; align-items: center; }
.seg-toggle button.on { background: var(--paper); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg-toggle.small button { padding: 3px 10px; font-size: .85rem; }
.seg-toggle .count { background: var(--accent-soft); color: var(--accent); border-radius: 10px; padding: 0 7px; font-size: .78rem; font-variant-numeric: tabular-nums; }

.chip { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 10px; background: var(--surface-2); color: var(--ink); font-size: .78rem; white-space: nowrap; }
.chip-beat { background: color-mix(in srgb, var(--rule) 14%, transparent); color: var(--rule); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c-none); flex: none; }
.who { display: inline-block; font-size: .72rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; padding: 1px 7px; border-radius: 4px; background: var(--surface-2); color: var(--muted); flex: none; }
.who-claude { background: var(--accent-soft); color: var(--accent); }
kbd { font: .78rem var(--font-script); padding: 1px 5px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--paper); }

/* статусы, акты, цвета карточек */
.st-idea { --st: var(--st-idea); }
.st-draft { --st: var(--st-draft); }
.st-revision { --st: var(--st-revision); }
.st-done { --st: var(--st-done); }
.dot.st-idea, .dot.st-draft, .dot.st-revision, .dot.st-done, .seg.st-idea, .seg.st-draft, .seg.st-revision, .seg.st-done { background: var(--st); }
.c-red { --c: var(--c-red); } .c-orange { --c: var(--c-orange); } .c-yellow { --c: var(--c-yellow); }
.c-green { --c: var(--c-green); } .c-teal { --c: var(--c-teal); } .c-blue { --c: var(--c-blue); }
.c-violet { --c: var(--c-violet); } .c-none { --c: var(--c-none); }
.act-1 { --a: var(--act-1); } .act-2 { --a: var(--act-2); } .act-3 { --a: var(--act-3); } .act-4 { --a: var(--act-4); }
.dot.act-1, .dot.act-2, .dot.act-3, .dot.act-4 { background: var(--a); }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--paper); background: var(--c); box-shadow: 0 0 0 1px var(--line-strong); cursor: pointer; padding: 0; }
.swatch.c-none { background: repeating-linear-gradient(135deg, var(--surface-2) 0 4px, var(--paper) 4px 8px); }
.swatch.on { box-shadow: 0 0 0 2px var(--ink); }

/* ------------------------------------------------------------ каркас */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 8px var(--gutter-r) 8px var(--gutter-l);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); letter-spacing: .01em; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 22px; height: 18px; border-radius: 3px; background: var(--ink); position: relative; flex: none;
}
.brand-mark::before {
  content: ""; position: absolute; left: -1px; right: -1px; top: -6px; height: 6px; border-radius: 2px;
  background: repeating-linear-gradient(115deg, var(--ink) 0 4px, var(--bg) 4px 7px);
  transform: rotate(-8deg); transform-origin: left bottom;
}

.page { padding: 20px var(--gutter-r) 48px var(--gutter-l); max-width: 1480px; width: 100%; margin: 0 auto; display: grid; gap: 18px; min-width: 0; align-content: start; }
.page-head { display: flex; gap: 16px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; }
.page-head > div { display: grid; gap: 4px; }

.project-head { padding: 14px var(--gutter-r) 0 var(--gutter-l); max-width: 1480px; width: 100%; margin: 0 auto; display: grid; gap: 10px; }
.project-title-row { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.crumb { color: var(--muted); font-size: .9rem; }
.crumb::after { content: " /"; color: var(--line-strong); }
.project-title { font-size: 1.45rem; flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.project-actions { display: flex; gap: 2px; flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 500; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--rule); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; min-width: 0; }
.panel-head { display: flex; gap: 6px 16px; align-items: baseline; justify-content: space-between; flex-wrap: wrap; }
.panel-head p { flex: 1 1 320px; font-size: .88rem; }
.panel-grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.panel-grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.split { display: grid; gap: 18px; grid-template-columns: minmax(240px, 320px) minmax(0, 1fr); align-items: start; }
@media (max-width: 820px) { .split { grid-template-columns: minmax(0, 1fr); } }

.empty-state { background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 32px 24px; display: grid; gap: 12px; justify-items: start; max-width: 640px; }
.empty-note { color: var(--muted); font-size: .9rem; padding: 6px 0; }

/* ------------------------------------------------------------ вход */
.login-page { min-height: 100%; display: grid; place-items: center; padding: 24px var(--gutter-r) 24px var(--gutter-l); }
.login-card { width: min(100%, 380px); display: grid; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 28px 24px; box-shadow: var(--shadow); }
.slate { display: flex; height: 14px; border-radius: 3px; overflow: hidden; transform: rotate(-3deg); margin-bottom: 6px; }
.slate span { flex: 1; background: var(--ink); }
.slate span:nth-child(even) { background: var(--paper); }
.brand-title { font-family: var(--font-script); font-size: 1.8rem; letter-spacing: .04em; text-transform: uppercase; }

/* ------------------------------------------------------------ проекты */
.project-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.project-tile { display: grid; gap: 10px; align-content: start; padding: 18px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); box-shadow: var(--shadow); }
.project-tile:hover { text-decoration: none; border-color: var(--accent); }
.tile-title { font-family: var(--font-script); font-size: 1.15rem; text-transform: uppercase; letter-spacing: .03em; overflow-wrap: anywhere; }
.tile-meta { font-size: .82rem; color: var(--muted); }
.tile-logline { font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.tile-progress { display: grid; gap: 6px; }
.tile-numbers { display: flex; justify-content: space-between; font-size: .85rem; font-variant-numeric: tabular-nums; }
.tile-foot { font-size: .78rem; }

/* ------------------------------------------------------------ обзор */
.overview-top { display: grid; gap: 18px; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: stretch; }
@media (max-width: 900px) { .overview-top { grid-template-columns: minmax(0, 1fr); } }
.title-page { display: flex; }
.title-sheet {
  flex: 1; background: var(--paper); border: 1px solid var(--line); border-radius: 4px; box-shadow: var(--shadow);
  padding: 34px clamp(18px, 5vw, 56px); display: grid; gap: 14px; align-content: center; text-align: center; font-family: var(--font-script);
}
.tp-kicker { font-size: .8rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.tp-title { font-family: var(--font-script); font-size: clamp(1.5rem, 3.2vw, 2.2rem); text-transform: uppercase; letter-spacing: .05em; font-weight: 400; overflow-wrap: anywhere; }
.tp-author { color: var(--muted); }
.tp-logline { font-size: 1rem; line-height: 1.6; max-width: 56ch; margin: 6px auto 0; text-wrap: pretty; }
.tp-facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 10px auto 0; text-align: left; font-size: .85rem; max-width: 52ch; }
.tp-facts dt { color: var(--muted); }
.tp-facts dd { margin: 0; }
.overview-side { display: grid; }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 8px; align-content: start; min-width: 0; }
.kpi-label { font-size: .75rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.kpi-value { font-size: 1rem; font-variant-numeric: tabular-nums; }
.kpi-value b { font-size: 1.7rem; font-weight: 600; letter-spacing: -.01em; }
.kpi-value b.warn { color: var(--warn); }
.meter { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

.status-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; gap: 2px; background: transparent; }
.status-bar .seg { min-width: 4px; }
.status-bar .seg-empty { background: var(--surface-2); }
.status-wrap { display: grid; gap: 8px; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .82rem; color: var(--muted); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend b { color: var(--ink); font-variant-numeric: tabular-nums; }

.review-list, .feed, .decision-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.review-list li { display: grid; gap: 2px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.review-list li:last-child { border-bottom: 0; }
.review-list a { display: flex; gap: 8px; align-items: center; color: var(--ink); }
.feed li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--line); }
.feed li:last-child { border-bottom: 0; }
.feed-text { overflow-wrap: anywhere; font-size: .9rem; }
.decision-list li { padding: 5px 0; }

/* ------------------------------------------------------------ графики */
.chart { width: 100%; min-width: 0; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.timeline .chart-svg { min-width: 640px; }
.chart-svg .grid { stroke: var(--line); stroke-width: 1; }
.chart-svg .axis { fill: var(--muted); font: 11px var(--font-ui); font-variant-numeric: tabular-nums; }
.chart-svg .area { fill: var(--accent); opacity: .13; }
.chart-svg .line { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.chart-svg .endpoint, .chart-svg .point { fill: var(--accent); stroke: var(--paper); stroke-width: 2; }
.chart-svg .point { cursor: pointer; }
.chart-svg .target-line { stroke: var(--rule); stroke-dasharray: 4 4; stroke-width: 1.2; }
.chart-svg .tick { stroke: var(--line-strong); }
.tl-seg { cursor: pointer; fill: var(--a, var(--st, var(--c, var(--accent)))); }
.tl-seg.st-idea, .tl-seg.st-draft, .tl-seg.st-revision, .tl-seg.st-done { fill: var(--st); }
.tl-seg[class*="c-"] { fill: var(--c); }
.tl-seg[class*="act-"] { fill: var(--a); }
.tl-seg:hover { opacity: .8; }
.tl-rest { fill: none; stroke: var(--line-strong); stroke-dasharray: 3 3; }
.beat-target { stroke: var(--muted); stroke-dasharray: 2 4; stroke-width: 1.2; }
.beat-target.faint { opacity: .5; }
.beat-label { fill: var(--muted); font-size: 10.5px; }
.beat-actual { stroke: var(--rule); stroke-width: 2; }
.beat-actual-label { fill: var(--rule); font-weight: 600; font-size: 10.5px; }
.timeline-wrap { display: grid; gap: 10px; }

.matrix .axis { font-size: 10px; }
.matrix .matrix-name { fill: var(--ink); font-size: 11.5px; }
.matrix .matrix-row { fill: var(--surface-2); opacity: .55; }
.matrix .matrix-cell { fill: var(--accent); cursor: pointer; }
.matrix .act-sep { stroke: var(--rule); stroke-width: 1; opacity: .55; }

.bar-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.bar-list li { display: grid; grid-template-columns: minmax(70px, 38%) minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: .85rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar-value { font-variant-numeric: tabular-nums; color: var(--muted); }
.pairs { display: grid; gap: 14px; }
.pair { display: grid; gap: 5px; }
.pair-head { font-size: .85rem; font-weight: 600; }
.pair-bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; gap: 2px; }
.pair-a { background: var(--accent); }
.pair-b { background: var(--rule); opacity: .75; }
.pair-legend { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.pair-legend span { display: inline-flex; gap: 6px; align-items: center; }

/* ------------------------------------------------------------ редактор */
.view-script.page { max-width: 1600px; }
.editor-layout { display: grid; gap: 18px; grid-template-columns: 250px minmax(0, 1fr) 300px; align-items: start; }
@media (max-width: 1200px) { .editor-layout { grid-template-columns: 230px minmax(0, 1fr); } .scene-side { grid-column: 2; } }
@media (max-width: 780px) {
  .editor-layout { grid-template-columns: minmax(0, 1fr); }
  .scene-side { grid-column: auto; }
  .scene-nav .nav-list, .scene-nav #nav-search { display: none; }
}
.scene-nav { position: sticky; top: 64px; display: grid; gap: 8px; max-height: calc(100vh - 90px); overflow: hidden; grid-template-rows: auto auto auto minmax(0, 1fr); }
@media (max-width: 780px) { .scene-nav { position: static; max-height: none; } }
.nav-head { display: flex; justify-content: space-between; font-size: .88rem; font-variant-numeric: tabular-nums; }
.nav-jump { display: none; }
@media (max-width: 780px) { .nav-jump { display: block; } }
.nav-list { list-style: none; margin: 0; padding: 0 4px 0 0; overflow-y: auto; display: grid; align-content: start; gap: 1px; }
.nav-act { font-size: .72rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--rule); padding: 10px 8px 4px; }
.nav-list a { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 6px; align-items: center; padding: 6px 8px; border-radius: 6px; color: var(--ink); font-size: .86rem; }
.nav-list a:hover { background: var(--surface-2); text-decoration: none; }
.nav-list a.active { background: var(--accent-soft); }
.nav-num { font-family: var(--font-script); color: var(--muted); font-size: .8rem; text-align: right; }
.nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-label small { display: block; color: var(--muted); font-size: .74rem; overflow: hidden; text-overflow: ellipsis; }

.editor-main { display: grid; gap: 10px; min-width: 0; }
.editor-toolbar { position: sticky; top: 56px; z-index: 5; display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; padding: 8px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.type-picker select { width: auto; min-height: 32px; padding: 3px 8px; }
.counter { font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.save-state { font-size: .8rem; color: var(--muted); }
.save-state[data-kind="error"] { color: var(--danger); }
.save-state[data-kind="dirty"] { color: var(--warn); }
.save-state[data-kind="ok"] { color: var(--ok); }

.paper {
  position: relative; background: var(--paper); border: 1px solid var(--line); border-radius: 3px; box-shadow: var(--shadow);
  width: 100%; max-width: 780px; margin: 0 auto; padding: 48px clamp(16px, 7%, 72px) 64px;
  font: 15px/1.55 var(--font-script); min-height: 60vh;
}
.scene-heading { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 18px; text-transform: uppercase; }
.scene-heading select, .scene-heading input {
  font: 700 15px var(--font-script); text-transform: uppercase; border: 0; border-bottom: 1px dashed var(--line-strong);
  border-radius: 0; background: transparent; padding: 2px 2px; min-height: 30px; width: auto;
}
.scene-heading select { padding-right: 0; }
.scene-heading .heading-loc { flex: 1 1 200px; min-width: 120px; }
.scene-heading .heading-time { width: 9.5em; }
.scene-heading input:focus, .scene-heading select:focus { outline: none; border-bottom: 2px solid var(--accent); }
.scene-no { position: absolute; left: 14px; color: var(--muted); font-size: .85rem; }
@media (max-width: 640px) { .scene-no { position: static; } }
.heading-dash { color: var(--muted); }

.blocks { display: grid; gap: 0; }
.blk { white-space: pre-wrap; overflow-wrap: anywhere; outline: none; padding: 1px 4px; border-radius: 3px; min-height: 1.55em; caret-color: var(--accent); }
.blk:focus { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.blk:empty::before { color: var(--line-strong); }
.blk-action { margin-top: 14px; }
.blk-action:first-child { margin-top: 0; }
.blk-action:empty::before { content: "Действие"; }
.blk-character { margin: 14px 0 0 37%; text-transform: uppercase; }
.blk-character:empty::before { content: "ПЕРСОНАЖ"; }
.blk-parenthetical { margin-left: 28%; margin-right: 26%; color: var(--muted); }
.blk-parenthetical::before { content: "("; } .blk-parenthetical::after { content: ")"; }
.blk-parenthetical:empty::before { content: "(ремарка"; color: var(--line-strong); }
.blk-dialogue { margin-left: 19%; margin-right: 18%; }
.blk-dialogue:empty::before { content: "Реплика"; }
.blk-transition { margin-top: 14px; text-align: right; text-transform: uppercase; }
.blk-transition:empty::before { content: "СМЕНА КАДРА:"; }
.blk-note { margin-top: 14px; background: var(--note-bg); font-family: var(--font-ui); font-size: .9rem; font-style: italic; padding: 4px 8px; }
.blk-note:empty::before { content: "Заметка для себя"; }
@media (max-width: 640px) {
  .paper { font-size: 14px; padding-top: 24px; }
  .blk-character { margin-left: 26%; }
  .blk-parenthetical { margin-left: 16%; margin-right: 10%; }
  .blk-dialogue { margin-left: 8%; margin-right: 4%; }
}
.suggest { position: absolute; z-index: 6; display: grid; min-width: 180px; background: var(--paper); border: 1px solid var(--line-strong); border-radius: 6px; box-shadow: var(--shadow); padding: 4px; margin-left: 37%; }
.suggest button { text-align: left; border: 0; background: transparent; padding: 6px 10px; border-radius: 4px; font: 14px var(--font-script); cursor: pointer; }
.suggest button.active, .suggest button:hover { background: var(--accent-soft); }
.keys-hint { font-size: .8rem; color: var(--muted); text-align: center; }
@media (hover: none) { .keys-hint { display: none; } }

.scene-side { display: grid; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.side-title { font-size: 1rem; }
.side-sub { font-size: .85rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-top: 6px; }
.range-row { display: flex; gap: 10px; align-items: center; }
.range-row output { font-size: .85rem; color: var(--muted); white-space: nowrap; min-width: 6em; }
.scene-notes { display: grid; gap: 8px; }
.mini-note { border-left: 3px solid var(--rule); padding: 4px 0 4px 10px; display: grid; gap: 4px; font-size: .88rem; }
.mini-note.resolved { border-left-color: var(--st-done); opacity: .7; }
.mini-note-head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* ------------------------------------------------------------ доска карточек */
.board-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.board-scroll { overflow-x: auto; padding-bottom: 8px; }
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 300px); gap: 14px; align-items: start; }
.col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; display: grid; gap: 10px; min-width: 0; }
.col-head { display: grid; gap: 2px; padding: 2px 4px; }
.col-head h2 { font-size: .95rem; letter-spacing: .02em; }
.col-cards { display: grid; gap: 10px; min-height: 40px; grid-template-columns: minmax(0, 1fr); }
.icard, .icard-foot { min-width: 0; }
.icard { grid-template-columns: minmax(0, 1fr); }
.add-card { border: 1px dashed var(--line-strong); background: transparent; border-radius: 6px; padding: 8px; color: var(--muted); cursor: pointer; }
.add-card:hover { color: var(--accent); border-color: var(--accent); }
.icard {
  position: relative; background: var(--paper); border-radius: 3px; box-shadow: var(--shadow); cursor: grab;
  display: grid; touch-action: manipulation; user-select: none; -webkit-user-select: none; overflow: hidden;
}
.icard::before { content: ""; position: absolute; right: 0; top: 0; border-style: solid; border-width: 0 18px 18px 0; border-color: transparent var(--c) transparent transparent; }
.icard.c-none::before { display: none; }
.icard-top { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 9px 26px 7px 10px; border-bottom: 2px solid var(--rule); font-weight: 600; font-size: .9rem; }
.icard-no { font-family: var(--font-script); color: var(--muted); font-weight: 400; }
.icard-title { overflow-wrap: anywhere; }
.icard-body {
  padding: 4px 10px 6px; font-size: .86rem; line-height: 22px; min-height: 66px;
  background: repeating-linear-gradient(to bottom, transparent 0 21px, var(--card-lines) 21px 22px);
  overflow-wrap: anywhere;
}
.icard-foot { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; padding: 6px 10px 8px; font-size: .75rem; color: var(--muted); }
.icard-heading { font-family: var(--font-script); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.icard-pages { margin-left: auto; font-variant-numeric: tabular-nums; }
.icard:focus-visible { outline: 2px solid var(--accent); }
.icard.dragging { position: fixed; z-index: 50; pointer-events: none; transform: rotate(2deg); box-shadow: 0 14px 30px rgba(0,0,0,.25); cursor: grabbing; }
.icard-placeholder { border: 2px dashed var(--accent); border-radius: 4px; background: var(--accent-soft); }
body.is-dragging { cursor: grabbing; user-select: none; }
.board.filtering .icard:not(.hit) { opacity: .35; }
.board.filtering .icard.hit { outline: 2px solid var(--accent); }

.heading-fields { display: grid; gap: 10px; grid-template-columns: 8em minmax(0, 1fr) 9em; }
@media (max-width: 560px) { .heading-fields { grid-template-columns: minmax(0, 1fr); } }

/* ------------------------------------------------------------ персонажи и локации */
.graph-wrap { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
@media (max-width: 900px) { .graph-wrap { grid-template-columns: minmax(0, 1fr); } }
.graph { min-width: 520px; }
.graph .edge { stroke: var(--line-strong); stroke-width: 1.5; }
.graph .edge-label { fill: var(--muted); font: 11px var(--font-ui); paint-order: stroke; stroke: var(--surface); stroke-width: 4px; }
.graph .node { cursor: pointer; }
.graph .node circle { fill: var(--c); stroke: var(--paper); stroke-width: 3; }
.graph .node.c-none circle { fill: var(--accent); }
.graph .node-label { fill: var(--ink); font: 600 11.5px var(--font-ui); paint-order: stroke; stroke: var(--surface); stroke-width: 4px; }
.graph-side { display: grid; gap: 12px; }
.rel-form { display: grid; gap: 8px; }
.rel-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; font-size: .88rem; }
.rel-list li { display: flex; justify-content: space-between; gap: 8px; align-items: center; border-bottom: 1px solid var(--line); padding: 2px 0; }

.char-list { display: grid; gap: 10px; align-content: start; }
.people { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.people a { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 10px; align-items: center; padding: 7px 8px; border-radius: 6px; color: var(--ink); }
.people a:hover { background: var(--surface-2); text-decoration: none; }
.people a.active { background: var(--accent-soft); }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--c); color: #fff; font-weight: 700; font-size: .8rem; }
.avatar.c-none { background: var(--line-strong); color: var(--ink); }
.person { display: grid; min-width: 0; }
.person b, .person small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.char-editor { display: grid; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.char-name { font-family: var(--font-script); font-weight: 400; font-size: 1.4rem; letter-spacing: .04em; }
.stat-row { display: flex; gap: 24px; flex-wrap: wrap; }
.stat { display: grid; }
.stat b { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .8rem; color: var(--muted); }
.appear-list { margin: 0; padding-left: 0; list-style: none; display: grid; gap: 2px; font-size: .9rem; }

.loc-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
@media (max-width: 400px) { .loc-list { grid-template-columns: minmax(0, 1fr); } }
.loc-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; min-width: 0; }
.loc-card h3 { font-family: var(--font-script); font-weight: 400; letter-spacing: .03em; overflow-wrap: anywhere; }
.loc-scenes { display: flex; flex-wrap: wrap; gap: 6px; }

/* ------------------------------------------------------------ заметки */
.note-list { display: grid; gap: 6px; align-content: start; }
.note-item { text-align: left; display: grid; gap: 3px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); cursor: pointer; color: var(--ink); }
.note-item:hover { border-color: var(--accent); }
.note-item.active { border-color: var(--accent); background: var(--accent-soft); }
.note-item.resolved { opacity: .6; }
.note-item-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.note-editor { display: grid; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.note-editor textarea { min-height: 260px; }
.note-preview { background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px; }
.md { display: grid; gap: 8px; line-height: 1.55; overflow-wrap: anywhere; }
.md h3, .md h4, .md h5 { margin-top: 6px; }
.md ul, .md ol { margin: 0; padding-left: 1.3em; display: grid; gap: 3px; }
.md blockquote { margin: 0; padding-left: 12px; border-left: 3px solid var(--line-strong); color: var(--muted); }
.md code { font-family: var(--font-script); background: var(--surface-2); padding: 0 4px; border-radius: 3px; }
.md q { quotes: "«" "»"; font-family: var(--font-script); }

/* ------------------------------------------------------------ окна и уведомления */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(10, 14, 20, .45); display: grid; place-items: start center; overflow-y: auto; padding: max(24px, env(safe-area-inset-top, 0px)) var(--gutter-r) 24px var(--gutter-l); }
.dialog { width: min(100%, 520px); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 20px 50px rgba(0,0,0,.3); margin-top: 6vh; }
.dialog-wide { width: min(100%, 760px); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.dialog-body { padding: 16px; }
.dialog-body h3 { margin-top: 8px; }
.confirm { display: grid; gap: 16px; }
.toasts { position: fixed; z-index: 200; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 8px; width: min(92vw, 420px); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: .9rem; transition: opacity .3s, transform .3s; }
.toast-error { background: var(--danger); color: #fff; }
.toast.leaving { opacity: 0; transform: translateY(6px); }
.tokens { display: grid; gap: 8px; }
.token-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.token-out { display: grid; gap: 8px; padding: 12px; background: var(--accent-soft); border-radius: 6px; }
.token-value { font-family: var(--font-script); word-break: break-all; user-select: all; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
