/* ==========================================================================
   Showrunner Studio — styles
   ========================================================================== */

:root {
  --bg: #0d0f13;
  --bg2: #111419;
  --panel: #161a20;
  --panel2: #1c2028;
  --panel3: #232834;
  --line: #252a34;
  --line2: #303746;
  --text: #e8eaef;
  --text2: #b8bfcc;
  --muted: #7c8595;
  --faint: #5a6272;
  --accent: #e3a857;
  --accent2: #f2c487;
  --accent-ink: #1d1407;
  --accent-soft: rgba(227, 168, 87, .12);
  --danger: #ef6b6b;
  --ok: #4fc28b;
  --info: #5aa9f8;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45), 0 2px 8px rgba(0, 0, 0, .3);
  --ui: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'Courier Prime', 'Courier New', Courier, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--ui);
  font-size: 13.5px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

svg.i { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2a303b; border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: #384050; }
::-webkit-scrollbar-track { background: transparent; }

/* ───────────── Layout ───────────── */
.app { display: grid; grid-template-columns: 268px 1fr; height: 100vh; }
.main { display: grid; grid-template-rows: 56px 1fr; min-width: 0; min-height: 0; background: var(--bg); }

/* ───────────── Buttons ───────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line2); background: var(--panel2); color: var(--text);
  font-weight: 500; font-size: 13px; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--panel3); border-color: #3b4353; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: var(--accent2); border-color: var(--accent2); }
.btn-danger { background: transparent; border-color: rgba(239, 107, 107, .45); color: var(--danger); }
.btn-danger:hover { background: rgba(239, 107, 107, .1); border-color: var(--danger); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn:disabled { opacity: .45; pointer-events: none; }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--text2);
}
.icon-btn:hover { background: var(--panel2); color: var(--text); }
.icon-btn.sm { width: 26px; height: 26px; border-radius: 6px; }

/* ───────────── Sidebar ───────────── */
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--bg2); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; padding: 18px 18px 14px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(140deg, #f2c487, #d9893a); color: #1d1407;
  box-shadow: 0 4px 14px rgba(227, 168, 87, .25);
}
.brand-mark svg.i { width: 19px; height: 19px; stroke-width: 2; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.brand-sub { font-size: 10.5px; letter-spacing: .22em; text-transform: uppercase; color: var(--accent); font-weight: 600; margin-top: 1px; }

.series-switch {
  position: relative; margin: 4px 12px 14px; padding: 11px 36px 11px 13px; text-align: left;
  display: flex; flex-direction: column; gap: 2px;
  border-radius: var(--radius); border: 1px solid var(--line2);
  background: linear-gradient(180deg, var(--panel2), var(--panel));
}
.series-switch:hover { border-color: #3d4556; }
.series-label { font-size: 10px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.series-title { font-weight: 700; font-size: 14px; letter-spacing: .02em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.series-meta { font-size: 11.5px; color: var(--muted); }
.series-chev { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }

.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 12px 6px 20px; font-size: 10.5px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--muted);
}
.episode-list { flex: 1; overflow-y: auto; padding: 0 10px 12px; }
.season-head { font-size: 11px; font-weight: 600; color: var(--faint); padding: 12px 10px 6px; letter-spacing: .04em; }
.ep-item {
  position: relative; display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent;
}
.ep-item:hover { background: var(--panel); }
.ep-item.active { background: var(--panel2); border-color: var(--line2); }
.ep-item.active::before { content: ''; position: absolute; left: -10px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.ep-code {
  font-family: var(--mono); font-weight: 700; font-size: 12.5px; color: var(--text2);
  width: 38px; height: 30px; display: grid; place-items: center; border-radius: 6px;
  background: var(--panel3); flex: none;
}
.ep-item.active .ep-code { background: var(--accent-soft); color: var(--accent2); }
.ep-info { min-width: 0; flex: 1; }
.ep-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ep-meta { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.ep-more { opacity: 0; width: 24px; height: 24px; border-radius: 6px; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; flex: none; }
.ep-item:hover .ep-more { opacity: 1; }
.ep-more:hover { background: var(--panel3); color: var(--text); }
.side-empty { color: var(--muted); text-align: center; padding: 26px 10px; line-height: 1.7; }

.st-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.st-0 { --st: #8f9bb3; } .st-1 { --st: #5aa9f8; } .st-2 { --st: #a68bfa; } .st-3 { --st: #e3a857; } .st-4 { --st: #4fc28b; }
.st-dot { background: var(--st); }

.side-foot { border-top: 1px solid var(--line); padding: 10px 12px 14px; }
.side-foot-row { display: flex; gap: 6px; }
.side-link {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 30px; border-radius: 7px; border: 1px solid var(--line); background: transparent; color: var(--text2); font-size: 12px;
}
.side-link:hover { background: var(--panel); color: var(--text); }
.side-link svg.i { width: 14px; height: 14px; }
.storage-note { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--faint); margin-top: 10px; padding-left: 4px; }
.dot-ok { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(79, 194, 139, .15); }

/* ───────────── Top bar ───────────── */
.topbar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
  padding: 0 16px 0 22px; border-bottom: 1px solid var(--line); background: var(--bg2);
}
.crumbs { display: flex; align-items: center; gap: 9px; min-width: 0; white-space: nowrap; }
.crumb-show { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 12px; letter-spacing: .06em; overflow: hidden; text-overflow: ellipsis; }
.crumb-sep { color: var(--faint); }
.crumb-ep { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.crumb-ep b { font-family: var(--mono); color: var(--accent2); margin-right: 6px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 20px;
  font-size: 11px; font-weight: 600; color: var(--st, var(--text2));
  background: color-mix(in srgb, var(--st, #8f9bb3) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--st, #8f9bb3) 30%, transparent);
}
.tabs { display: flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); }
.tabs button {
  height: 30px; padding: 0 14px; border: 0; border-radius: 7px; background: transparent;
  color: var(--muted); font-weight: 500; font-size: 13px;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { background: var(--panel3); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .3), inset 0 0 0 1px var(--line2); }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.save-state { font-size: 11.5px; color: var(--faint); margin-right: 6px; display: inline-flex; align-items: center; gap: 6px; }
.save-state.saving { color: var(--accent); }

/* ───────────── Views ───────────── */
.view { display: none; min-height: 0; }
.view.active { display: grid; }
#view-script { grid-template-rows: 46px 1fr 30px; }
.scroll-view { overflow-y: auto; align-content: start; }
.scroll-view.active { display: block; }
.view-inner { max-width: 1180px; margin: 0 auto; padding: 30px 36px 80px; }

/* ───────────── Toolbar ───────────── */
.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 14px; border-bottom: 1px solid var(--line); background: var(--bg2); overflow-x: auto;
}
.seg { display: flex; gap: 2px; padding: 3px; border-radius: 9px; background: var(--panel); border: 1px solid var(--line); }
.seg button {
  height: 27px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent;
  color: var(--muted); font-size: 12px; font-weight: 500; white-space: nowrap;
}
.seg button:hover { color: var(--text); background: var(--panel2); }
.seg button.active { background: var(--accent-soft); color: var(--accent2); box-shadow: inset 0 0 0 1px rgba(227, 168, 87, .35); }
.toolbar-right { display: flex; align-items: center; gap: 4px; }
.tool-btn {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 7px;
  border: 0; background: transparent; color: var(--muted);
}
.tool-btn:hover { background: var(--panel2); color: var(--text); }
.tool-btn:disabled { opacity: .35; pointer-events: none; }
.tool-btn.toggle.on { color: var(--accent2); background: var(--accent-soft); }
.tool-sep { width: 1px; height: 18px; background: var(--line2); margin: 0 6px; }
.zoom { display: flex; align-items: center; gap: 2px; }
#zoomVal { font-size: 12px; color: var(--text2); width: 42px; text-align: center; font-variant-numeric: tabular-nums; }

/* ───────────── Script body ───────────── */
.script-body { display: grid; grid-template-columns: 1fr 300px; min-height: 0; }
.desk {
  position: relative; overflow: auto; min-width: 0;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(227, 168, 87, .05), transparent 60%),
    #0a0c10;
}
.desk-empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--muted); }
.desk-empty h2 { color: var(--text); font-weight: 600; margin: 14px 0 6px; }
.desk-empty .big-icon { width: 54px; height: 54px; margin: 0 auto; border-radius: 14px; display: grid; place-items: center; background: var(--panel2); color: var(--accent); }
.desk-empty .big-icon svg.i { width: 26px; height: 26px; }

.inspector { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--line); background: var(--bg2); }
.insp-tabs { display: flex; gap: 4px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.insp-tabs button {
  flex: 1; height: 28px; border-radius: 7px; border: 0; background: transparent; color: var(--muted); font-size: 12px; font-weight: 500;
}
.insp-tabs button:hover { color: var(--text); }
.insp-tabs button.active { background: var(--panel2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line2); }
.insp-body { flex: 1; overflow-y: auto; padding: 10px 10px 30px; }
.insp-act {
  font-size: 10.5px; font-weight: 700; letter-spacing: .12em; color: var(--accent);
  padding: 12px 8px 6px; text-transform: uppercase;
}
.insp-hint { font-size: 11.5px; color: var(--faint); padding: 4px 8px 10px; line-height: 1.5; }
.insp-empty { color: var(--muted); font-size: 12.5px; padding: 30px 14px; text-align: center; line-height: 1.6; }
.scene-item {
  width: 100%; display: flex; gap: 10px; align-items: flex-start; text-align: left;
  padding: 8px; border-radius: 8px; border: 1px solid transparent; background: transparent;
}
.scene-item:hover { background: var(--panel); }
.scene-item.current { background: var(--panel2); border-color: var(--line2); }
.si-num {
  font-family: var(--mono); font-weight: 700; font-size: 12px; color: var(--text2);
  min-width: 26px; height: 22px; display: grid; place-items: center; border-radius: 5px; background: var(--panel3);
}
.scene-item.current .si-num { background: var(--accent); color: var(--accent-ink); }
.si-main { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.si-head { font-family: var(--mono); font-size: 12px; font-weight: 700; line-height: 1.35; color: var(--text); word-break: break-word; }
.si-meta { font-size: 11px; color: var(--muted); }

.cast-row {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px;
  border: 0; background: transparent; text-align: left;
}
.cast-row:hover { background: var(--panel); }
.cast-row .cr-main { flex: 1; min-width: 0; }
.cast-row .cr-name { font-weight: 600; font-size: 12.5px; letter-spacing: .02em; }
.cast-row .cr-sub { font-size: 11px; color: var(--muted); }
.cast-row .cr-count { font-size: 11px; color: var(--text2); font-variant-numeric: tabular-nums; }
.cast-row .cr-add { opacity: 0; color: var(--accent); }
.cast-row:hover .cr-add { opacity: 1; }
.insp-sub { font-size: 10.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); padding: 16px 8px 8px; }

.stat-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 4px; }
.stat-tile { background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 11px 12px; }
.stat-tile b { display: block; font-size: 19px; font-weight: 700; letter-spacing: -.02em; }
.stat-tile span { font-size: 11px; color: var(--muted); }
.bar-row { padding: 6px 8px; }
.bar-top { display: flex; justify-content: space-between; font-size: 11.5px; margin-bottom: 5px; }
.bar-top b { font-weight: 600; letter-spacing: .02em; }
.bar-top span { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 4px; background: var(--panel3); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--c, var(--accent)); }
.split { display: flex; height: 8px; border-radius: 5px; overflow: hidden; margin: 6px 8px 4px; background: var(--panel3); }
.split i { display: block; height: 100%; }
.split-legend { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); padding: 0 8px 6px; }

.statusbar {
  display: flex; align-items: center; gap: 18px; padding: 0 16px; font-size: 11.5px; color: var(--muted);
  border-top: 1px solid var(--line); background: var(--bg2); white-space: nowrap; overflow: hidden;
}
.statusbar b { color: var(--text2); font-weight: 600; }
.statusbar .sb-type { color: var(--accent2); font-weight: 600; }
.statusbar .sb-right { margin-left: auto; }

/* ==========================================================================
   Screenplay page (shared by editor, print and title preview)
   12pt Courier — 10 characters per inch, 6 lines per inch.
   ========================================================================== */
.sp {
  --z: 1;
  --in: calc(96px * var(--z));
  --ln: calc(16px * var(--z));
  font-family: var(--mono);
  font-size: var(--ln);
  line-height: var(--ln);
  color: #141414;
}
.paper {
  position: relative;
  width: calc(var(--in) * 8.5);
  min-height: calc(var(--in) * 11);
  margin: 30px auto 140px;
  padding: var(--in) var(--in) var(--in) calc(var(--in) * 1.5);
  background: #fffefb;
  border-radius: 2px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .04), 0 30px 80px rgba(0, 0, 0, .55), 0 4px 14px rgba(0, 0, 0, .35);
}
.editor { outline: none; min-height: calc(var(--in) * 9); caret-color: #c47512; }
.editor ::selection { background: rgba(227, 168, 87, .35); }

.sp .el { position: relative; white-space: pre-wrap; overflow-wrap: break-word; margin: var(--ln) 0 0; }
.sp .el:first-child { margin-top: 0; }
.sp .el-scene { text-transform: uppercase; }
.sp.bold-slugs .el-scene { font-weight: 700; }
.sp .el-action { }
.sp .el-character { margin-left: calc(var(--in) * 2.2); text-transform: uppercase; }
.sp .el-dialogue { margin: 0 calc(var(--in) * 1.5) 0 var(--in); }
.sp .el-parenthetical {
  margin: 0 calc(var(--in) * 1.9) 0 calc(var(--in) * 1.6);
  padding-left: calc(var(--in) * .1); text-indent: calc(var(--in) * -.1);
}
.sp .el-transition { text-align: right; text-transform: uppercase; }
.sp .el-shot { text-transform: uppercase; }
.sp .el-act { text-align: center; text-transform: uppercase; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; margin-top: calc(var(--ln) * 2); }
.sp .el-act:first-child { margin-top: 0; }

/* Editor-only affordances */
.editor .el.is-empty.is-active::before {
  content: attr(data-ph); position: absolute; left: 0; top: 0; right: 0; text-indent: 0;
  color: #bdb6a8; pointer-events: none; text-transform: none; font-weight: 400; text-decoration: none;
}
.editor .el-transition.is-empty.is-active::before { text-align: right; }
.editor .el-act.is-empty.is-active::before { text-align: center; }
.editor .el-act.is-empty { text-decoration: none; }

.hl .editor .el-character:not(.is-empty)::after {
  content: ''; position: absolute; top: calc(var(--ln) / 2 - 4px);
  left: calc(var(--in) * -3.42);
  width: 8px; height: 8px; border-radius: 50%; box-sizing: border-box;
  border: 1.5px dashed #c9c2b3; background: transparent;
}

.overlay { position: absolute; inset: 0; pointer-events: none; }
.ov-break { position: absolute; left: 0; right: 0; height: 0; border-top: 1px dashed #e0d8c6; }
.ov-break span {
  position: absolute; right: calc(var(--in) * .4); top: 0; transform: translateY(-50%);
  font-family: var(--ui); font-size: 10px; font-weight: 600; color: #a89f8c; background: #fffefb; padding: 0 6px; letter-spacing: .04em;
}
.ov-scn { position: absolute; font-weight: 700; color: #6b6458; }
.ov-scn.l { left: calc(var(--in) * .82); }
.ov-scn.r { right: calc(var(--in) * .45); }
.ov-play {
  position: absolute; pointer-events: auto; transform: translateX(calc(-100% - 7px));
  width: var(--ln); height: var(--ln); min-width: 16px; min-height: 16px; padding: 0; border: 0; border-radius: 50%;
  display: grid; place-items: center; background: transparent; color: #cfc6b3; cursor: pointer;
  transition: color .12s, background .12s, opacity .12s; opacity: .55;
}
.ov-play svg.i { width: 62%; height: 62%; fill: currentColor; stroke-width: 1.2; }
.ov-play:hover { opacity: 1; color: #fff; background: #c47512; }
.ov-play.on { opacity: 1; color: #fff; background: #c47512; box-shadow: 0 0 0 4px rgba(196, 117, 18, .18); }
.editor .el.is-speaking { background: rgba(227, 168, 87, .16); box-shadow: -6px 0 0 rgba(227, 168, 87, .16), 6px 0 0 rgba(227, 168, 87, .16); border-radius: 2px; }
.ov-type {
  position: absolute; right: 10px; display: none; pointer-events: none;
  font-family: var(--ui); font-size: 9.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  color: #c4b9a3; padding-top: calc(var(--ln) / 2 - 7px);
}
.ov-type.show { display: block; }

/* ───────────── Autocomplete ───────────── */
.ac {
  position: fixed; z-index: 60; min-width: 230px; max-width: 360px;
  background: var(--panel2); border: 1px solid var(--line2); border-radius: 10px; box-shadow: var(--shadow);
  padding: 5px; font-family: var(--ui);
}
.ac-head { font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); padding: 6px 9px 5px; }
.ac-item { display: flex; align-items: center; gap: 9px; padding: 7px 9px; border-radius: 7px; cursor: pointer; font-size: 12.5px; }
.ac-item:hover { background: var(--panel3); }
.ac-item.active { background: var(--accent-soft); color: var(--accent2); }
.ac-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line2); flex: none; }
.ac-label { font-family: var(--mono); font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-hint { font-size: 11px; color: var(--muted); white-space: nowrap; }
.ac-foot { font-size: 10.5px; color: var(--faint); padding: 6px 9px 4px; border-top: 1px solid var(--line); margin-top: 4px; }

/* ───────────── Page header / cards / forms ───────────── */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-head h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.page-head p { margin: 6px 0 0; color: var(--muted); }
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); margin-bottom: 6px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; }
.card h3 { margin: 0 0 4px; font-size: 14px; font-weight: 600; }
.card .card-sub { color: var(--muted); font-size: 12.5px; margin: 0 0 18px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.span2 { grid-column: span 2; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 11.5px; font-weight: 600; color: var(--text2); }
.field > span small { font-weight: 400; color: var(--faint); margin-left: 6px; }
.field input, .field select, .field textarea, .input {
  width: 100%; height: 38px; padding: 0 12px; border-radius: 8px;
  background: var(--bg2); border: 1px solid var(--line2); color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { height: auto; padding: 10px 12px; line-height: 1.55; resize: vertical; min-height: 70px; }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(227, 168, 87, .15); }
.field select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237c8595' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
.field select option { background: var(--panel2); }
.field input[type=date]::-webkit-calendar-picker-indicator { filter: invert(.7); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 0; border-top: 1px solid var(--line); }
.switch-row:first-of-type { border-top: 0; }
.switch-row b { font-weight: 600; font-size: 13px; display: block; }
.switch-row span { color: var(--muted); font-size: 12px; }
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 22px; background: var(--panel3); border: 1px solid var(--line2); transition: .2s; }
.switch i::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #9aa3b2; transition: .2s; }
.switch input:checked + i { background: var(--accent); border-color: var(--accent); }
.switch input:checked + i::after { left: 18px; background: #fff; }

/* ───────────── Characters ───────────── */
.filters { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.search { position: relative; flex: 0 1 300px; }
.search svg.i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 34px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  height: 30px; padding: 0 12px; border-radius: 20px; border: 1px solid var(--line2); background: transparent;
  color: var(--text2); font-size: 12px; font-weight: 500;
}
.chip:hover { border-color: #3d4556; color: var(--text); }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .n { opacity: .55; margin-left: 4px; }
.filters .sort { margin-left: auto; width: 170px; }

.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.char-card {
  position: relative; display: flex; flex-direction: column; gap: 13px; padding: 18px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.char-card::before { content: ''; position: absolute; inset: 0 0 auto; height: 3px; background: var(--c); opacity: .9; }
.char-card:hover { border-color: #3a4252; transform: translateY(-2px); box-shadow: 0 14px 30px rgba(0, 0, 0, .3); }
.cc-top { display: flex; align-items: center; gap: 13px; }
.cc-id { flex: 1; min-width: 0; }
.cc-id h3 { margin: 0; font-size: 15px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cc-cue { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cc-desc { margin: 0; color: var(--text2); line-height: 1.55; font-size: 13px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; min-height: 3.1em; }
.cc-desc.empty { color: var(--faint); font-style: italic; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; gap: 5px; height: 23px; padding: 0 9px; border-radius: 6px; background: var(--panel3); color: var(--text2); font-size: 11.5px; }
.tag button { border: 0; background: none; padding: 0; color: var(--muted); display: grid; place-items: center; }
.tag button:hover { color: var(--danger); }
.tag button svg.i { width: 12px; height: 12px; }
.cc-stats { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); padding-top: 13px; margin-top: auto; }
.cc-stats div { text-align: center; }
.cc-stats div + div { border-left: 1px solid var(--line); }
.cc-stats b { display: block; font-size: 16px; font-weight: 700; }
.cc-stats span { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.cc-actor { font-size: 12px; color: var(--muted); }
.cc-actor b { color: var(--text2); font-weight: 500; }
.add-card {
  display: grid; place-items: center; align-content: center; gap: 10px; min-height: 250px; cursor: pointer;
  border: 1.5px dashed var(--line2); border-radius: 14px; color: var(--muted); background: transparent;
}
.add-card:hover { border-color: var(--accent); color: var(--accent2); background: var(--accent-soft); }
.add-card .plus { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--panel2); }

.avatar {
  --c: #8f9bb3;
  width: 34px; height: 34px; border-radius: 50%; flex: none; overflow: hidden;
  display: grid; place-items: center; font-weight: 700; font-size: 12px; letter-spacing: .02em;
  color: var(--c); background: color-mix(in srgb, var(--c) 18%, var(--panel2));
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--c) 55%, transparent);
}
.avatar.sm { width: 26px; height: 26px; font-size: 10px; }
.avatar.lg { width: 48px; height: 48px; font-size: 15px; }
.avatar.xl { width: 68px; height: 68px; font-size: 21px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.role-chip { font-size: 10.5px; font-weight: 600; padding: 3px 8px; border-radius: 6px; white-space: nowrap; background: var(--panel3); color: var(--text2); }
.role-Lead { background: rgba(227, 168, 87, .15); color: var(--accent2); }
.role-Series-Regular { background: rgba(90, 169, 248, .14); color: #8cc4fb; }
.role-Recurring { background: rgba(166, 139, 250, .15); color: #c3b2fc; }
.role-Guest-Star { background: rgba(79, 194, 139, .14); color: #7fd8ac; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); border: 1.5px dashed var(--line2); border-radius: 14px; }
.empty-state h3 { color: var(--text); margin: 0 0 6px; }

/* ───────────── Drawer ───────────── */
.scrim { position: fixed; inset: 0; background: rgba(5, 6, 9, .55); backdrop-filter: blur(2px); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40; }
.scrim.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(540px, 100vw); z-index: 41;
  background: var(--bg2); border-left: 1px solid var(--line2); box-shadow: var(--shadow);
  transform: translateX(102%); transition: transform .25s cubic-bezier(.2, .8, .2, 1);
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; gap: 16px; padding: 22px 22px 18px; border-bottom: 1px solid var(--line); position: relative; }
.drawer-head::before { content: ''; position: absolute; inset: 0 0 auto; height: 3px; background: var(--c); }
.drawer-title { flex: 1; min-width: 0; }
.title-input {
  width: 100%; border: 0; background: transparent; outline: none; padding: 2px 0;
  font-size: 21px; font-weight: 700; letter-spacing: -.01em; color: var(--text);
}
.title-input::placeholder { color: var(--faint); }
.drawer-sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 22px 22px 40px; display: flex; flex-direction: column; gap: 16px; }
.drawer-section { font-size: 10.5px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; color: var(--muted); margin: 10px 0 -4px; display: flex; align-items: center; gap: 10px; }
.drawer-section::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; background: var(--sw); box-shadow: inset 0 0 0 2px var(--bg2); }
.swatch.active { border-color: var(--sw); }
.photo-row { display: flex; align-items: center; gap: 10px; }
.trait-input { flex: 1; min-width: 120px; border: 0; background: transparent; outline: none; height: 23px; color: var(--text); }
.tags-box { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 38px; padding: 6px 8px; border-radius: 8px; background: var(--bg2); border: 1px solid var(--line2); }
.tags-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(227, 168, 87, .15); }
.rel-row { display: grid; grid-template-columns: 1fr 1fr 34px; gap: 8px; align-items: center; }
.rel-row select, .rel-row input { height: 36px; }
.mini-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.mini-stats div { background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 10px; text-align: center; }
.mini-stats b { display: block; font-size: 17px; }
.mini-stats span { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.appears { display: flex; flex-direction: column; gap: 4px; }
.appears button { display: flex; align-items: center; gap: 10px; text-align: left; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); font-size: 12.5px; }
.appears button:hover { border-color: var(--line2); background: var(--panel2); }
.appears .code { font-family: var(--mono); font-weight: 700; color: var(--accent2); }
.appears .grow { flex: 1; }
.appears .n { color: var(--muted); font-size: 11.5px; }
.danger-zone { border-top: 1px solid var(--line); padding-top: 18px; margin-top: 8px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.danger-zone span { color: var(--muted); font-size: 12px; }

/* ───────────── Outline ───────────── */
.outline-meta { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 22px; }
.meta-chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 13px; border-radius: 9px; background: var(--panel); border: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.meta-chip b { color: var(--text); font-size: 14px; }
.outline-act {
  display: flex; align-items: center; gap: 12px; margin: 26px 0 10px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .14em; color: var(--accent); text-transform: uppercase;
}
.outline-act::after { content: ''; flex: 1; height: 1px; background: linear-gradient(90deg, rgba(227, 168, 87, .35), transparent); }
.outline-act .n { color: var(--muted); font-weight: 500; letter-spacing: .02em; text-transform: none; }
.scene-row {
  display: grid; grid-template-columns: 46px 1fr 70px 36px; gap: 14px; align-items: start;
  padding: 15px 16px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); margin-bottom: 8px;
}
.scene-row:hover { border-color: var(--line2); }
.sr-num { font-family: var(--mono); font-weight: 700; font-size: 15px; color: var(--accent2); height: 32px; display: grid; place-items: center; border-radius: 8px; background: var(--accent-soft); }
.sr-head { font-family: var(--mono); font-weight: 700; font-size: 14px; letter-spacing: .01em; margin-bottom: 8px; line-height: 1.4; }
.sr-note {
  width: 100%; border: 1px solid transparent; background: transparent; outline: none; resize: none; padding: 6px 8px; margin-left: -8px;
  border-radius: 7px; color: var(--text2); line-height: 1.55; field-sizing: content; min-height: 34px;
}
.sr-note:hover { border-color: var(--line); }
.sr-note:focus { border-color: var(--accent); background: var(--bg2); }
.sr-note::placeholder { color: var(--faint); font-style: italic; }
.sr-cast { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.cast-chip { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px 0 6px; border-radius: 6px; background: var(--panel3); font-size: 11px; font-weight: 600; letter-spacing: .02em; }
.cast-chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--c, #8f9bb3); }
.sr-len { text-align: right; font-variant-numeric: tabular-nums; }
.sr-len b { display: block; font-size: 14px; }
.sr-len span { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

/* ───────────── Title page / Series ───────────── */
.title-layout { display: grid; grid-template-columns: minmax(320px, 1fr) auto; gap: 28px; align-items: start; }
.tp-preview { --z: .62; position: sticky; top: 0; }
.tp-preview .ppage { box-shadow: 0 30px 80px rgba(0, 0, 0, .5); border-radius: 2px; }
.series-layout { display: grid; grid-template-columns: 1fr 340px; gap: 22px; align-items: start; }
.series-side { display: flex; flex-direction: column; gap: 22px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 13px 14px; }
.kpi b { display: block; font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.kpi span { font-size: 11.5px; color: var(--muted); }

/* Printable page (title page + script pages) */
.ppage {
  position: relative; background: #fff; color: #111;
  width: calc(var(--in) * 8.5); height: calc(var(--in) * 11);
  padding: var(--in) var(--in) var(--in) calc(var(--in) * 1.5);
  overflow: hidden;
}
.ppage .pnum { position: absolute; top: calc(var(--in) * .5); right: var(--in); }
.tp { position: relative; height: 100%; }
.tp-center { position: absolute; top: calc(var(--in) * 2.4); left: 0; right: 0; text-align: center; }
.tp-show { text-transform: uppercase; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.tp-ep { margin-top: var(--ln); }
.tp-num { margin-top: var(--ln); }
.tp-by { margin-top: calc(var(--ln) * 4); }
.tp-writer { margin-top: var(--ln); }
.tp-based { margin-top: calc(var(--ln) * 3); }
.tp-bottom { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; align-items: flex-end; gap: var(--in); }
.tp-draft { text-align: right; }
.scn .el-scene::before { content: attr(data-num); position: absolute; left: calc(var(--in) * -.75); }
.scn .el-scene::after { content: attr(data-num); position: absolute; right: calc(var(--in) * -.6); }

.print-root { position: fixed; left: -30000px; top: 0; visibility: hidden; pointer-events: none; }
.print-root .measure { width: calc(var(--in) * 6); }

/* ───────────── Menus, modals, toasts ───────────── */
.menu {
  position: fixed; z-index: 70; min-width: 220px; padding: 5px;
  background: var(--panel2); border: 1px solid var(--line2); border-radius: 10px; box-shadow: var(--shadow);
  animation: pop .12s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
.menu-item {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; border: 0;
  background: transparent; text-align: left; font-size: 13px; color: var(--text);
}
.menu-item:hover { background: var(--panel3); }
.menu-item.danger { color: var(--danger); }
.menu-item.disabled { opacity: .4; pointer-events: none; }
.menu-item svg.i { color: var(--muted); }
.menu-item.danger svg.i { color: var(--danger); }
.mi-sp { width: 16px; flex: none; }
.mi-label { flex: 1; white-space: nowrap; }
.mi-hint { font-size: 11px; color: var(--faint); }
.mi-check svg.i { color: var(--accent); }
.menu-sep { height: 1px; background: var(--line2); margin: 5px 4px; }
.menu-header { font-size: 10px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; color: var(--faint); padding: 8px 10px 4px; }

.modal-wrap {
  position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 20px;
  background: rgba(5, 6, 9, .62); backdrop-filter: blur(3px); animation: fade .15s;
}
.modal-wrap.closing { opacity: 0; transition: opacity .15s; }
@keyframes fade { from { opacity: 0; } }
.modal {
  width: min(520px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line2); border-radius: 16px; box-shadow: var(--shadow);
  animation: rise .18s cubic-bezier(.2, .8, .2, 1);
}
.modal.wide { width: min(720px, 100%); }
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.985); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 6px 24px; }
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 650; }
.modal-body { padding: 12px 24px 20px; overflow-y: auto; color: var(--text2); line-height: 1.55; }
.modal-body p { margin: 0 0 12px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.check-list { display: flex; flex-direction: column; gap: 4px; max-height: 340px; overflow-y: auto; margin-top: 6px; }
.check-item { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px; background: var(--bg2); border: 1px solid var(--line); cursor: pointer; }
.check-item input { accent-color: var(--accent); width: 16px; height: 16px; }
.check-item b { font-family: var(--mono); flex: 1; color: var(--text); }
.check-item span { font-size: 11.5px; color: var(--muted); }
.kbd-table { width: 100%; border-collapse: collapse; }
.kbd-table td { padding: 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.kbd-table td:last-child { text-align: right; white-space: nowrap; }
.kbd-table h4 { margin: 18px 0 4px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
kbd {
  display: inline-block; min-width: 22px; padding: 2px 7px; margin-left: 3px; border-radius: 5px; text-align: center;
  background: var(--panel3); border: 1px solid var(--line2); border-bottom-width: 2px; font-family: var(--ui); font-size: 11px; color: var(--text);
}

.toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-radius: 10px;
  background: #f3f4f7; color: #12151b; font-weight: 500; font-size: 13px; box-shadow: var(--shadow);
  animation: rise .2s cubic-bezier(.2, .8, .2, 1);
}
.toast.error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transform: translateY(6px); transition: .25s; }
.toast svg.i { color: var(--ok); }
.toast.error svg.i { color: #fff; }

/* ───────────── AI Writer ───────────── */
.btn-ai {
  background: linear-gradient(135deg, rgba(166, 139, 250, .2), rgba(227, 168, 87, .16));
  border-color: rgba(196, 170, 250, .45); color: #ece3ff;
}
.btn-ai:hover { background: linear-gradient(135deg, rgba(166, 139, 250, .32), rgba(227, 168, 87, .24)); border-color: rgba(206, 184, 255, .7); }
.btn-ai svg.i { color: #cdb8ff; }
.btn-ai.busy svg.i { animation: spin 1.6s linear infinite; }
.ai-lead { color: var(--text2); margin: 0 0 16px; }
.ai-idea { min-height: 150px; font-size: 14px !important; }
.ai-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ai-modes.ai-modes-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) { .ai-modes.ai-modes-3 { grid-template-columns: 1fr; } }
.ai-mode { display: flex; gap: 11px; align-items: flex-start; padding: 13px 14px; border-radius: 10px; background: var(--bg2); border: 1.5px solid var(--line); cursor: pointer; }
.ai-mode:hover { border-color: var(--line2); }
.ai-mode:has(input:checked) { border-color: rgba(196, 170, 250, .7); background: rgba(166, 139, 250, .08); }
.field .ai-mode input { accent-color: #a68bfa; margin: 3px 0 0; flex: none; width: 16px; height: 16px; padding: 0; border: 0; box-shadow: none; }
.ai-mode b { display: flex; align-items: center; gap: 7px; color: var(--text); font-weight: 600; font-size: 13.5px; margin-bottom: 3px; }
.ai-mode b svg.i { color: #cdb8ff; }
.ai-mode span { font-size: 12px; color: var(--muted); line-height: 1.5; }
.gta-card {
  padding: 20px 22px; border-radius: 14px;
  background: linear-gradient(145deg, rgba(240, 139, 196, .1), rgba(166, 139, 250, .1) 50%, rgba(56, 198, 217, .08));
  border: 1px solid rgba(206, 184, 255, .35);
}
.gta-label { display: flex; align-items: center; gap: 7px; font-size: 10.5px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; color: #e2d4ff; margin-bottom: 12px; }
.gta-label svg.i { width: 14px; height: 14px; }
.gta-text { font-size: 18px; line-height: 1.6; color: var(--text); font-weight: 500; min-height: 90px; display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px; white-space: pre-wrap; }
.gta-wait { color: var(--muted); font-size: 14px; font-weight: 400; }
.gta-meta { margin-top: 14px; font-size: 12px; color: var(--muted); }
.ai-mode-link { text-align: left; color: inherit; font: inherit; }
.ai-mode-link:hover { border-color: rgba(196, 170, 250, .6); }
.fakes-layout { display: grid; grid-template-columns: minmax(320px, 420px) 1fr; gap: 22px; align-items: start; }
.fact-gen { display: flex; flex-direction: column; gap: 14px; }
.fact-gen .card-sub { margin: -10px 0 0; }
.fact-gen .ai-conn { margin-top: 0; }
.fact-chips { margin-top: -6px; }
.fact-chips .chip { height: 26px; font-size: 11.5px; padding: 0 10px; }
.fact-go { justify-content: center; height: 42px; font-size: 14px; }
.fact-go .ai-spin { border-color: rgba(29, 20, 7, .25); border-top-color: var(--accent-ink); }
.fact-result { position: sticky; top: 0; display: flex; flex-direction: column; gap: 12px; }
.fact-result .gta-text { font-size: 20px; min-height: 160px; }
.fact-empty .gta-text { min-height: 120px; }
.fact-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.fact-actions .btn-primary { margin-left: auto; }
.btn-star { color: var(--accent2); border-color: rgba(227, 168, 87, .5); }
.fact-lib-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 40px 0 14px; padding-top: 26px; border-top: 1px solid var(--line); }
.fact-lib-head h2 { margin: 0; font-size: 19px; }
.fact-lib-head p { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; }
.fact-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; }
.fact-item { display: flex; flex-direction: column; gap: 10px; padding: 15px 16px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.fact-item.current { border-color: rgba(196, 170, 250, .55); }
.fact-item p { margin: 0; line-height: 1.6; color: var(--text2); font-size: 13px; flex: 1; }
.fact-item-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fact-topic { font-size: 12px; color: var(--text2); font-weight: 500; }
.fact-date { margin-left: auto; font-size: 11px; color: var(--faint); }
.fact-item-actions { display: flex; gap: 6px; align-items: center; }
.fact-item-actions .icon-btn { margin-left: auto; }
@media (max-width: 1120px) { .fakes-layout { grid-template-columns: 1fr; } .fact-result { position: static; } }
.gta-history { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow-y: auto; }
.gta-row { display: flex; gap: 12px; align-items: flex-start; padding: 11px 12px; border-radius: 9px; background: var(--bg2); border: 1px solid var(--line); }
.gta-row p { margin: 0; flex: 1; font-size: 12.5px; line-height: 1.55; color: var(--text2); }
.gta-row-actions { display: flex; gap: 4px; flex: none; }
.ai-checks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.ai-check { display: flex; gap: 11px; align-items: flex-start; padding: 11px 12px; border-radius: 9px; background: var(--bg2); border: 1px solid var(--line); cursor: pointer; }
.ai-check:hover { border-color: var(--line2); }
.ai-check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 2px 0 0; flex: none; }
.ai-check b { display: block; color: var(--text); font-weight: 600; font-size: 13px; }
.ai-check span { font-size: 12px; color: var(--muted); }
.ai-conn { margin-top: 16px; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px; font-size: 12.5px; }
.ai-conn .grow { flex: 1; }
.ai-conn.ok { background: rgba(79, 194, 139, .08); border: 1px solid rgba(79, 194, 139, .25); color: #a5e3c4; }
.ai-conn.warn { background: rgba(227, 168, 87, .08); border: 1px solid rgba(227, 168, 87, .3); color: var(--accent2); }
.link-btn { border: 0; background: none; color: var(--accent); padding: 0; font-weight: 600; }
.link-btn:hover { text-decoration: underline; }
.modal .hint { font-size: 12px; color: var(--muted); margin: 10px 0 0; line-height: 1.55; }
.modal .hint a { color: var(--accent); }
.script-body { position: relative; }
.ai-banner {
  position: absolute; z-index: 5; top: 14px; left: calc(50% - 150px); transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; padding: 9px 10px 9px 14px; border-radius: 12px;
  background: rgba(26, 29, 37, .94); backdrop-filter: blur(8px);
  border: 1px solid rgba(196, 170, 250, .38); box-shadow: var(--shadow);
  width: max-content; max-width: min(640px, calc(100% - 340px));
}
.ai-spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(196, 170, 250, .25); border-top-color: #cdb8ff; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.ai-banner-main { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.ai-banner-title { font-weight: 600; font-size: 12.5px; white-space: nowrap; }
.ai-banner-status { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 440px; }
.editor[contenteditable="false"] { caret-color: transparent; cursor: default; }
.ep-meta .ai-tag { color: #cdb8ff; display: inline-flex; align-items: center; gap: 5px; }
.ep-meta .ai-tag svg.i { width: 12px; height: 12px; animation: spin 1.6s linear infinite; }

/* ───────────── Stream Toolkit shell ───────────── */
.side-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px 14px; }
.side-nav button {
  display: flex; align-items: center; gap: 11px; height: 38px; padding: 0 12px; border-radius: 9px;
  border: 1px solid transparent; background: transparent; color: var(--text2); font-weight: 500; text-align: left;
}
.side-nav button:hover { background: var(--panel); color: var(--text); }
.side-nav button.active { background: var(--panel2); border-color: var(--line2); color: var(--text); }
.side-nav button.active svg.i { color: var(--accent); }
.side-nav .nav-main { height: 44px; font-weight: 650; font-size: 14px; color: var(--text); }
.side-nav .nav-main.active { background: linear-gradient(135deg, rgba(227, 168, 87, .16), rgba(227, 168, 87, .06)); border-color: rgba(227, 168, 87, .4); }
.side-nav .nav-group { margin-top: 6px; color: var(--muted); font-size: 12.5px; }
.side-nav .nav-group.has-active { color: var(--text2); }
.nav-chev { margin-left: auto; display: grid; transition: transform .15s; }
.nav-chev svg.i { width: 14px; height: 14px; }
.nav-group[aria-expanded="true"] .nav-chev { transform: rotate(180deg); }
.nav-sub { display: flex; flex-direction: column; gap: 2px; margin: 2px 0 0 18px; padding-left: 10px; border-left: 1px solid var(--line2); }
.side-nav .nav-sub button { height: 34px; font-size: 13px; }
.side-nav .nav-sub button svg.i { width: 15px; height: 15px; }
.side-nav-sep { height: 1px; background: var(--line); margin: 8px 4px; }
.studio-side { flex: 1; display: flex; flex-direction: column; min-height: 0; border-top: 1px solid var(--line); padding-top: 12px; }
.side-spacer { display: none; }
body.mode-toolkit .studio-side { display: none; }
body.mode-toolkit .side-spacer { display: block; flex: 1; }
body.mode-toolkit .studio-only, body.mode-toolkit #tabs, body.mode-toolkit #crumbs { display: none !important; }
body.mode-studio .toolkit-only, body.mode-studio #pageTitle { display: none !important; }
.page-title { display: flex; align-items: center; gap: 9px; white-space: nowrap; }
#aiConnBtn .dot-ok { margin-right: 2px; }

/* Home */
.home .hero {
  position: relative; overflow: hidden; padding: 38px 40px; border-radius: 20px; margin-bottom: 18px;
  background:
    radial-gradient(600px 260px at 85% 0%, rgba(166, 139, 250, .22), transparent 70%),
    radial-gradient(500px 240px at 0% 100%, rgba(227, 168, 87, .16), transparent 70%),
    var(--panel);
  border: 1px solid var(--line2);
}
.hero-kicker { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; color: var(--accent2); letter-spacing: .04em; margin-bottom: 12px; }
.hero h1 { margin: 0; font-size: 40px; font-weight: 750; letter-spacing: -.03em; }
.hero p { margin: 12px 0 0; max-width: 640px; color: var(--text2); font-size: 15px; line-height: 1.6; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 24px; }
.hero-actions .btn { height: 40px; padding: 0 16px; }
.story-result { position: sticky; top: 0; min-width: 0; }
.story-card { display: flex; flex-direction: column; gap: 14px; }
.story-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.story-head h3 { margin: 0; font-size: 16px; }
.story-page { --z: .82; background: #fffefb; border-radius: 8px; padding: 24px 28px 26px 58px; max-height: 560px; overflow-y: auto; }
.story-page .el { padding-left: 0; }
.story-page .story-play { top: 0; left: 0; }
.story-page .el-dialogue .story-play, .story-page .el-character .story-play, .story-page .el-parenthetical .story-play { left: 0; }
.story-page .el.is-speaking { background: rgba(227, 168, 87, .16); box-shadow: -6px 0 0 rgba(227, 168, 87, .16), 6px 0 0 rgba(227, 168, 87, .16); }
.home-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 30px; }
.home-h { font-size: 17px; margin: 0 0 14px; }
.tool-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 30px; }
.tool-card {
  display: flex; flex-direction: column; gap: 8px; text-align: left; padding: 20px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line); transition: border-color .15s, transform .15s, box-shadow .15s;
}
.tool-card:hover { border-color: #3a4252; transform: translateY(-2px); box-shadow: 0 14px 30px rgba(0, 0, 0, .3); }
.tool-ic { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent2); margin-bottom: 6px; }
.tool-ic svg.i { width: 20px; height: 20px; }
.tool-card b { font-size: 15px; }
.tool-card span:not(.tool-ic) { color: var(--muted); font-size: 12.5px; line-height: 1.55; flex: 1; }
.tool-card em { font-style: normal; font-size: 12.5px; font-weight: 600; color: var(--accent); display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.tool-card em svg.i { width: 14px; height: 14px; }
.home-split { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; }
.tip-head { display: flex; align-items: center; gap: 9px; color: var(--accent2); }
.tip-head h3 { margin: 0; color: var(--text); }
.tip-text { font-size: 16px; line-height: 1.6; margin: 12px 0 0; color: var(--text); }
.home-facts { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.home-fact { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; background: var(--bg2); border: 1px solid var(--line); }
.home-fact p { margin: 0; color: var(--text2); font-size: 13px; line-height: 1.55; }
.safe-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.safe-cols h4 { margin: 0 0 8px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; }
.safe-cols h4.ok { color: var(--ok); }
.safe-cols h4.no { color: var(--danger); }
.safe-cols ul { margin: 0; padding-left: 18px; color: var(--text2); font-size: 13px; line-height: 1.9; }
.safe-card .tip-head { color: var(--ok); }

/* Growth Coach */
.coach-layout { display: grid; grid-template-columns: minmax(320px, 400px) 1fr; gap: 22px; align-items: start; }
.coach-main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.coach-modes { align-self: flex-start; }
.coach-modes button { display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 14px; font-size: 13px; }
.coach-ask { display: flex; flex-direction: column; gap: 14px; }
.coach-ask .ai-conn { margin-top: 0; }
.coach-go-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.coach-go-row .btn { height: 40px; }
.coach-wait { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.coach-answer-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.coach-answer-head .fact-date { margin-left: auto; }
.md { color: var(--text2); line-height: 1.65; font-size: 14px; }
.md h3 { color: var(--text); font-size: 15px; margin: 18px 0 6px; }
.md h3:first-child { margin-top: 0; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 20px; }
.md li { margin-bottom: 4px; }
.md b { color: var(--text); }
.coach-list { display: flex; flex-direction: column; gap: 8px; }
.coach-note { border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.coach-note.open { border-color: var(--line2); padding-bottom: 14px; }
.coach-note .md, .coach-note .fact-item-actions { padding: 0 18px; }
.coach-note-head { width: 100%; display: flex; align-items: center; gap: 10px; padding: 13px 16px; border: 0; background: transparent; text-align: left; }
.coach-note-head b { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.coach-note-head svg.i { color: var(--muted); transition: transform .15s; }
.coach-note.open .coach-note-head svg.i { transform: rotate(180deg); }
@media (max-width: 1220px) { .tool-grid { grid-template-columns: repeat(2, 1fr); } .home-split, .coach-layout { grid-template-columns: 1fr; } }

/* ───────────── AI start page ───────────── */
.side-nav .nav-ai.active { background: linear-gradient(135deg, rgba(166, 139, 250, .2), rgba(227, 168, 87, .12)); border-color: rgba(196, 170, 250, .45); }
.side-nav .nav-ai svg.i { color: #cdb8ff; }
#view-start {
  background:
    radial-gradient(900px 420px at 50% -8%, rgba(166, 139, 250, .16), transparent 65%),
    radial-gradient(700px 360px at 50% 110%, rgba(227, 168, 87, .08), transparent 70%);
}
.start { max-width: 780px; margin: 0 auto; padding: 9vh 28px 80px; text-align: center; }
.start-badge { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 30px; font-size: 12px; font-weight: 500; color: #e2d4ff; background: rgba(166, 139, 250, .12); border: 1px solid rgba(196, 170, 250, .3); }
.start-badge svg.i { width: 14px; height: 14px; }
.start h1 { margin: 22px 0 10px; font-size: 42px; font-weight: 700; letter-spacing: -.035em; }
.start-sub { margin: 0 auto 30px; max-width: 600px; color: var(--text2); font-size: 15px; line-height: 1.6; }
.prompt-box {
  text-align: left; border-radius: 20px; background: var(--panel2); border: 1px solid var(--line2);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .4), 0 0 0 1px rgba(255, 255, 255, .02) inset; transition: border-color .15s, box-shadow .15s;
}
.prompt-box:focus-within { border-color: rgba(196, 170, 250, .6); box-shadow: 0 24px 60px rgba(0, 0, 0, .4), 0 0 0 4px rgba(166, 139, 250, .12); }
.prompt-box textarea {
  width: 100%; min-height: 96px; resize: none; border: 0; outline: none; background: transparent; color: var(--text);
  padding: 20px 22px 6px; font-size: 16px; line-height: 1.6; font-family: var(--ui);
}
.prompt-box textarea::placeholder { color: var(--faint); }
.prompt-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px 12px 16px; }
.prompt-opts { display: flex; gap: 6px; flex-wrap: wrap; }
.pill-toggle {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px; border-radius: 20px;
  border: 1px solid var(--line2); background: transparent; color: var(--muted); font-size: 12.5px; font-weight: 500;
}
.pill-toggle svg.i { width: 14px; height: 14px; }
.pill-toggle:hover { color: var(--text); border-color: #3d4556; }
.pill-toggle.on { color: var(--accent2); border-color: rgba(227, 168, 87, .45); background: var(--accent-soft); }
.pill-toggle.warn { color: var(--accent2); border-color: rgba(227, 168, 87, .45); }
.prompt-send {
  width: 42px; height: 42px; border-radius: 50%; border: 0; flex: none; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); transition: transform .1s, background .15s;
}
.prompt-send:hover { background: var(--accent2); }
.prompt-send:active { transform: scale(.95); }
.prompt-send svg.i { width: 19px; height: 19px; stroke-width: 2.2; transform: rotate(-90deg); }
.prompt-send:disabled { opacity: .6; pointer-events: none; }
.prompt-send .ai-spin { border-color: rgba(29, 20, 7, .25); border-top-color: var(--accent-ink); }
.prompt-hint { margin-top: 10px; font-size: 12px; color: var(--faint); }
.start-examples { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 28px; text-align: left; }
.example {
  display: flex; gap: 10px; align-items: flex-start; padding: 13px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: rgba(22, 26, 32, .7); color: var(--text2); font-size: 13px; line-height: 1.5; text-align: left;
}
.example:hover { border-color: var(--line2); background: var(--panel); color: var(--text); }
.example svg.i { color: var(--accent); margin-top: 2px; }
.start-or { display: flex; align-items: center; gap: 14px; margin: 34px 0 18px; color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: .14em; }
.start-or::before, .start-or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.start-manual { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.start-manual .btn { height: 40px; padding: 0 16px; }
.start-recent { margin-top: 40px; text-align: left; }
.start-recent h3 { font-size: 12px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
.start-recent-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.recent-card { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); text-align: left; }
.recent-card:hover { border-color: var(--line2); }
.recent-main { min-width: 0; display: flex; flex-direction: column; }
.recent-main b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-main span { font-size: 11.5px; color: var(--muted); }
@media (max-width: 760px) { .start-examples, .start-recent-grid { grid-template-columns: 1fr; } .start h1 { font-size: 32px; } }

/* ───────────── Responsive ───────────── */
@media (max-width: 1320px) {
  .script-body { grid-template-columns: 1fr 260px; }
  .series-layout { grid-template-columns: 1fr; }
}
@media (max-width: 1120px) {
  .script-body { grid-template-columns: 1fr; }
  .inspector { display: none; }
  .ai-banner { left: 50%; max-width: calc(100% - 40px); }
  .title-layout { grid-template-columns: 1fr; }
  .topbar { grid-template-columns: 1fr auto; }
  .crumbs { display: none; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

/* ==========================================================================
   Print — US Letter, industry standard margins
   ========================================================================== */
@media print {
  @page { size: letter; margin: 0; }
  html, body { height: auto; overflow: visible; background: #fff !important; }
  body > *:not(.print-root) { display: none !important; }
  .print-root { position: static; left: auto; visibility: visible; --z: 1; }
  .print-root .ppage { break-after: page; page-break-after: always; box-shadow: none; }
  .print-root .ppage:last-child { break-after: auto; page-break-after: auto; }
}


/* ==========================================================================
   Mobile & tablet
   ========================================================================== */
.menu-btn { display: none; }
.nav-scrim { display: none; }
.char-grid { grid-template-columns: repeat(auto-fill, minmax(min(290px, 100%), 1fr)); }
.fact-list { grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr)); }
@media (hover: none) { .ep-item .ep-more { opacity: 1; } .ov-play { opacity: .8; } }

@media (max-width: 1100px) {
  .home-stats { grid-template-columns: repeat(2, 1fr); }
  .tool-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 860px) {
  body { overflow: hidden; }
  .app { grid-template-columns: 1fr; height: 100dvh; }
  /* Sidebar becomes a slide-in menu */
  .sidebar {
    display: flex !important; position: fixed; z-index: 45; top: 0; bottom: 0; left: 0; width: min(300px, 86vw);
    transform: translateX(-102%); transition: transform .25s cubic-bezier(.2, .8, .2, 1); box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: none; }
  .nav-scrim { display: block; position: fixed; inset: 0; z-index: 44; background: rgba(5, 6, 9, .55); opacity: 0; pointer-events: none; transition: opacity .2s; }
  body.nav-open .nav-scrim { opacity: 1; pointer-events: auto; }
  .menu-btn { display: inline-grid; flex: none; }

  /* Top bar */
  .main { grid-template-rows: auto 1fr; }
  .topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 8px 10px; min-height: 54px; }
  .crumbs { display: flex !important; flex: 1; min-width: 0; }
  body.mode-studio .crumbs .crumb-show, body.mode-studio .crumbs .crumb-sep, body.mode-studio .crumbs .pill { display: none; }
  .page-title { flex: 1; min-width: 0; overflow: hidden; }
  .page-title .crumb-show, .page-title .crumb-sep { display: none; }
  .top-actions { gap: 6px; }
  .save-state, #helpBtn { display: none !important; }
  .top-actions .btn { height: 34px; padding: 0 10px; font-size: 12.5px; }
  #exportBtn { font-size: 0; gap: 0; width: 36px; padding: 0; justify-content: center; }
  #exportBtn svg.i { width: 17px; height: 17px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: 1 0 auto; padding: 0 12px; }

  /* Script page */
  #view-script { grid-template-rows: auto 1fr 26px; }
  .toolbar { padding: 6px 8px; gap: 8px; min-height: 44px; }
  .toolbar-right .tool-sep, #sceneNumBtn, #castHlBtn { display: none; }
  .paper { margin: 10px auto 90px; }
  .statusbar { gap: 12px; padding: 0 10px; font-size: 11px; }
  .statusbar .sb-right, .statusbar span:nth-child(4) { display: none; }
  .ov-type { display: none !important; }
  .ai-banner { left: 50%; top: 8px; max-width: calc(100% - 16px); padding: 8px; gap: 8px; }
  .ai-banner-status { max-width: 52vw; }
  .ac { max-width: calc(100vw - 16px); }

  /* Pages */
  .view-inner { padding: 20px 14px 70px; }
  .page-head { flex-direction: column; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
  .page-head h1 { font-size: 22px; }
  .form-grid { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .card { padding: 16px; border-radius: 12px; }
  .filters { gap: 8px; }
  .search { flex: 1 1 100%; }
  .filters .sort { margin-left: 0; width: 100%; }
  .scene-row { grid-template-columns: 34px 1fr; gap: 10px; padding: 12px; }
  .scene-row .sr-len, .scene-row > .icon-btn { grid-column: 2; justify-self: start; text-align: left; }
  .sr-num { height: 28px; font-size: 13px; }
  .tp-preview { --z: .42; position: static; justify-self: center; }
  .series-layout, .coach-layout, .fakes-layout, .home-split { grid-template-columns: 1fr; }
  .fact-result, .story-result { position: static; }
  .fact-result .gta-text { font-size: 17px; min-height: 0; }
  .fact-lib-head { margin-top: 26px; padding-top: 18px; }
  .story-page { --z: .62; padding: 16px 14px 18px 40px; }
  .coach-modes { align-self: stretch; overflow-x: auto; }
  .coach-modes button { flex: 1 0 auto; }

  /* Home / Overview */
  .home .hero { padding: 24px 18px; border-radius: 16px; }
  .hero h1 { font-size: 28px; }
  .hero p { font-size: 14px; }
  .tool-grid { grid-template-columns: 1fr; }
  .safe-cols { grid-template-columns: 1fr; }

  /* AI start page */
  .start { padding: 32px 14px 60px; }
  .start h1 { font-size: 28px; margin-top: 16px; }
  .start-sub { font-size: 14px; margin-bottom: 20px; }
  .prompt-box { border-radius: 16px; }
  .prompt-box textarea { font-size: 16px; padding: 16px 16px 4px; }
  .prompt-bar { padding: 8px 10px 10px 12px; align-items: flex-end; }
  .pill-toggle { height: 30px; padding: 0 10px; font-size: 12px; }
  .prompt-hint { display: none; }
  .start-examples, .start-recent-grid { grid-template-columns: 1fr; }
  .start-manual .btn { flex: 1 1 100%; justify-content: center; }

  /* Dialogs, drawer, menus */
  .modal-wrap { padding: 0; align-items: end; }
  .modal, .modal.wide { width: 100%; max-height: 92dvh; border-radius: 18px 18px 0 0; }
  .modal-body { padding: 10px 16px 16px; }
  .modal-head { padding: 16px 16px 4px; }
  .modal-foot { flex-wrap: wrap; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1 1 auto; justify-content: center; }
  .ai-modes, .ai-modes.ai-modes-3, .ai-checks { grid-template-columns: 1fr; }
  .drawer { width: 100vw; }
  .drawer-head, .drawer-body { padding-left: 16px; padding-right: 16px; }
  .rel-row { grid-template-columns: 1fr 34px; }
  .rel-row .field:first-child { grid-column: 1 / -1; }
  .mini-stats { grid-template-columns: repeat(2, 1fr); }
  .menu { max-width: calc(100vw - 16px); }
  .toasts { left: 12px; right: 12px; transform: none; bottom: calc(14px + env(safe-area-inset-bottom)); }
  .toast { width: 100%; }
  /* 16px inputs stop phones from zooming in when a field is tapped */
  .field input, .field select, .field textarea, .input, .trait-input, .title-input { font-size: 16px; }
}

@media (max-width: 420px) {
  .home-stats { grid-template-columns: 1fr 1fr; }
  .kpi b { font-size: 19px; }
  .seg button { padding: 0 8px; }
  .zoom #zoomVal { width: 36px; }
}

/* Phone script editor: same screenplay layout, reflowed to the screen at a readable size */
@media (max-width: 860px) {
  .paper { width: auto; min-height: 0; margin: 8px 8px 90px; padding: 18px 14px 48px 30px; border-radius: 6px; }
  .paper.sp { --ln: 21px; font-size: 14.5px; line-height: 21px; }
  .paper .editor { min-height: 60vh; }
  .paper .el-character { margin-left: 34%; }
  .paper .el-dialogue { margin: 0 6% 0 14%; }
  .paper .el-parenthetical { margin: 0 14% 0 24%; padding-left: .6em; text-indent: -.6em; }
  .hl .paper .editor .el-character::after, .paper .ov-scn, .paper .ov-break { display: none; }
  .paper .ov-play { width: 18px; height: 18px; }
  .zoom { display: none; }
}

/* ───────────── Accounts & admin ───────────── */
.account-btn { gap: 8px; }
.account-btn svg.i { width: 15px; height: 15px; }
.account-btn.signed-in { padding: 0 12px 0 5px; border-radius: 20px; }
.account-btn .avatar.sm { width: 26px; height: 26px; font-size: 10.5px; }
.auth-tabs { display: flex; gap: 4px; padding: 4px; border-radius: 10px; background: var(--bg2); border: 1px solid var(--line); margin-bottom: 16px; }
.auth-tabs button { flex: 1; height: 34px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-weight: 600; }
.auth-tabs button.active { background: var(--panel3); color: var(--text); box-shadow: inset 0 0 0 1px var(--line2); }
.auth-fields { display: flex; flex-direction: column; gap: 14px; }
.auth-error { margin: 14px 0 0; padding: 10px 12px; border-radius: 8px; background: rgba(239, 107, 107, .1); border: 1px solid rgba(239, 107, 107, .35); color: #ffb3b3; font-size: 13px; }
.admin-warn { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 12px; margin-bottom: 18px; background: rgba(227, 168, 87, .08); border: 1px solid rgba(227, 168, 87, .35); color: var(--text2); font-size: 13px; line-height: 1.55; }
.admin-warn svg.i { color: var(--accent); flex: none; margin-top: 2px; }
.admin-warn b { color: var(--text); }
.admin-stats { grid-template-columns: repeat(5, 1fr); }
.admin-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 760px; }
.admin-table th { text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--bg2); }
.admin-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); color: var(--text2); vertical-align: middle; white-space: nowrap; }
.admin-table tr:last-child td { border-bottom: 0; }
.admin-user { display: flex; align-items: center; gap: 10px; }
.admin-user b { color: var(--text); font-weight: 600; margin-right: 6px; }
.admin-user span:not(.avatar):not(.admin-new) { display: block; font-size: 12px; color: var(--muted); }
.admin-new { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: 2px 6px; border-radius: 5px; background: rgba(79, 194, 139, .15); color: #8fe0b8; vertical-align: 1px; margin-right: 4px; }
.admin-badge { background: var(--accent-soft); color: var(--accent2); }
.admin-empty { text-align: center; color: var(--muted); padding: 30px !important; white-space: normal !important; }
@media (max-width: 860px) {
  .account-btn .acct-name, .account-btn:not(.signed-in) span { display: none; }
  .account-btn:not(.signed-in) { width: 36px; padding: 0; justify-content: center; }
  .account-btn.signed-in { padding: 0 4px; }
  .admin-stats { grid-template-columns: repeat(2, 1fr); }
}
