:root {
  --bg: #14151a; --bg2: #1c1e25; --bg3: #262932; --fg: #e8e8ec; --fg2: #a7abb6; --fg3: #6f7482;
  --accent: #7c9cff; --accent2: #5e7ce0; --ok: #4fc08d; --warn: #e8b84a; --bad: #e06c6c; --line: #2f333d;
  --radius: 10px; --sidew: 200px; --tap: 44px; --font: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) { --bg: #f6f6f8; --bg2: #ffffff; --bg3: #eceef3; --fg: #1b1c21; --fg2: #4b5060; --fg3: #8a8f9c; --line: #dcdfe6; --accent: #3b5bdb; --accent2: #2f4bc0; }
}
:root[data-theme="light"] { --bg: #f6f6f8; --bg2: #ffffff; --bg3: #eceef3; --fg: #1b1c21; --fg2: #4b5060; --fg3: #8a8f9c; --line: #dcdfe6; --accent: #3b5bdb; --accent2: #2f4bc0; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 15px/1.5 var(--font); display: flex; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .5em; font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1rem; color: var(--fg2); }
p { margin: 0 0 .8em; }
.muted { color: var(--fg2); } .small { font-size: .85em; } .hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; } .right { margin-left: auto; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* layout */
.sidenav { width: var(--sidew); background: var(--bg2); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 10px 8px; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.sidenav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--fg2); min-height: 40px; }
.sidenav a i { font-style: normal; width: 22px; text-align: center; }
.sidenav a.active, .sidenav a:hover { background: var(--bg3); color: var(--fg); }
.sidenav .brand { font-weight: 700; color: var(--fg); margin-bottom: 4px; }
.sidenav .project-name { padding: 4px 10px 10px; color: var(--fg3); font-size: .85em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--bg2); position: sticky; top: 0; z-index: 20; min-height: 52px; }
.topbar-title { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; gap: 8px; align-items: center; }
.search { width: 220px; }
.net { color: var(--ok); font-size: 12px; } .net.off { color: var(--bad); } .net.syncing { color: var(--warn); }
.content { padding: 16px; flex: 1; }
.only-mobile { display: none !important; }
@media (max-width: 860px) {
  .sidenav { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .sidenav.open { transform: none; }
  .only-mobile { display: inline-flex !important; }
  .search { width: 130px; }
  .content { padding: 12px; }
}

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg3); color: var(--fg); font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--fg3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent2); }
.btn.danger { color: var(--bad); }
.btn.icon { width: var(--tap); padding: 0; }
.btn.sm { min-height: 34px; padding: 0 10px; font-size: .9em; } .btn.sm.icon { width: 34px; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--fg); background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; min-height: var(--tap); width: 100%; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; }
input[type="color"] { padding: 2px; width: 44px; }
textarea { min-height: 90px; resize: vertical; line-height: 1.5; }
select { appearance: auto; }
label.field { display: block; margin-bottom: 10px; }
label.field > span, .field-label { display: block; font-size: .85em; color: var(--fg2); margin-bottom: 4px; }
.hint { font-size: .8em; color: var(--fg3); margin-top: 3px; }
.card { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card.clickable { cursor: pointer; } .card.clickable:hover { border-color: var(--fg3); }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg3); font-size: .85em; cursor: pointer; min-height: 32px; user-select: none; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .x { opacity: .6; margin-left: 2px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75em; background: var(--bg3); color: var(--fg2); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--fg3); }
.dot.idea { background: var(--fg3); } .dot.draft { background: var(--warn); } .dot.revised { background: var(--accent); } .dot.final { background: var(--ok); }
.progress { height: 10px; background: var(--bg3); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; color: var(--fg2); padding: 10px 12px; font: inherit; cursor: pointer; min-height: var(--tap); white-space: nowrap; }
.tabs button.active { color: var(--fg); border-bottom-color: var(--accent); }
.list { display: flex; flex-direction: column; gap: 6px; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; background: var(--bg2); border: 1px solid var(--line); min-height: var(--tap); cursor: pointer; }
.list-item.active { border-color: var(--accent); }
.list-item:hover { border-color: var(--fg3); }
table.t { width: 100%; border-collapse: collapse; } table.t th, table.t td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { color: var(--fg2); font-weight: 500; font-size: .85em; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; }
.toolbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.empty { padding: 30px; text-align: center; color: var(--fg3); border: 1px dashed var(--line); border-radius: var(--radius); }
.ok { color: var(--ok); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.prose { line-height: 1.6; } .prose h1 { font-size: 1.4rem; margin-top: 1em; } .prose h2 { font-size: 1.15rem; margin-top: 1.4em; } .prose h3 { margin-top: 1.2em; color: var(--fg); }
.prose table { border-collapse: collapse; margin: 8px 0; } .prose td, .prose th { border: 1px solid var(--line); padding: 6px 10px; }
.prose code { background: var(--bg3); padding: 1px 5px; border-radius: 4px; }

/* help panel, toasts, modal */
.help-panel { position: fixed; top: 0; right: 0; width: min(560px, 100%); height: 100vh; background: var(--bg2); border-left: 1px solid var(--line); z-index: 50; display: flex; flex-direction: column; box-shadow: -10px 0 40px rgba(0,0,0,.35); }
.help-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.help-body { overflow: auto; padding: 16px 20px 40px; }
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--bg3); border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.3); }
.toast.bad { border-color: var(--bad); }
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 90; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; width: min(640px, 100%); max-height: 90vh; overflow: auto; padding: 18px; }
.modal h2 { margin-bottom: 12px; }
.search-results { position: absolute; top: 54px; right: 16px; width: min(520px, calc(100% - 32px)); background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; z-index: 30; max-height: 60vh; overflow: auto; padding: 6px; box-shadow: 0 10px 40px rgba(0,0,0,.4); }
.search-results a { display: block; padding: 8px 10px; border-radius: 6px; color: var(--fg); }
.search-results a:hover { background: var(--bg3); }
.search-results .snippet { color: var(--fg3); font-size: .85em; }

/* dictation */
.dictate-wrap { position: relative; }
.dictate-btn { position: absolute; right: 8px; bottom: 8px; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg3); color: var(--fg2); cursor: pointer; font-size: 16px; z-index: 2; }
.dictate-btn.on { background: var(--bad); color: #fff; border-color: var(--bad); animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(224,108,108,.5); } 100% { box-shadow: 0 0 0 12px rgba(224,108,108,0); } }
.dictate-interim { position: absolute; left: 8px; bottom: 8px; right: 50px; font-size: .85em; color: var(--fg2); background: var(--bg3); padding: 4px 8px; border-radius: 6px; pointer-events: none; }

/* write screen */
.write { display: grid; grid-template-columns: 260px 1fr 300px; gap: 0; height: calc(100vh - 52px); margin: -16px; }
.write > * { min-width: 0; overflow: auto; }
.write .tree { border-right: 1px solid var(--line); padding: 10px; background: var(--bg2); }
.write .inspector { border-left: 1px solid var(--line); padding: 12px; background: var(--bg2); }
.write .editor { display: flex; flex-direction: column; }
.editor .toolbar { padding: 8px 12px; border-bottom: 1px solid var(--line); margin: 0; background: var(--bg2); position: sticky; top: 0; z-index: 3; }
.editor textarea.body { flex: 1; border: 0; border-radius: 0; background: var(--bg); font: 18px/1.7 var(--serif); padding: 28px max(24px, calc(50% - 360px)); resize: none; min-height: 60vh; outline: none; }
.editor .statusline { padding: 6px 12px; border-top: 1px solid var(--line); font-size: .85em; color: var(--fg3); display: flex; gap: 14px; background: var(--bg2); }
.tree .chapter { margin-bottom: 6px; }
.tree .chapter-head { display: flex; align-items: center; gap: 6px; padding: 6px 6px; border-radius: 6px; font-weight: 600; cursor: pointer; min-height: 36px; }
.tree .chapter-head:hover { background: var(--bg3); }
.tree .scene { display: flex; align-items: center; gap: 6px; padding: 5px 6px 5px 22px; border-radius: 6px; cursor: pointer; min-height: 36px; font-size: .95em; }
.tree .scene:hover { background: var(--bg3); } .tree .scene.active { background: var(--bg3); color: var(--accent); }
.tree .wc { margin-left: auto; color: var(--fg3); font-size: .8em; }
.tree .scene-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree [draggable] { cursor: grab; } .tree .drop-before { box-shadow: inset 0 2px 0 var(--accent); } .tree .drop-after { box-shadow: inset 0 -2px 0 var(--accent); }
.write.focus .tree, .write.focus .inspector { display: none; } .write.focus { grid-template-columns: 1fr; }
.pane-tabs { display: none; }
@media (max-width: 1000px) { .write { grid-template-columns: 220px 1fr; } .write .inspector { display: none; } .write.show-inspector .inspector { display: block; grid-column: 2; } .write.show-inspector .editor { display: none; } }
@media (max-width: 760px) {
  .write { grid-template-columns: 1fr; height: auto; margin: -12px; }
  .write .tree, .write .inspector, .write .editor { display: none; }
  .write.show-tree .tree, .write.show-inspector .inspector, .write.show-editor .editor { display: flex; flex-direction: column; }
  .pane-tabs { display: flex; position: sticky; top: 52px; z-index: 5; background: var(--bg2); border-bottom: 1px solid var(--line); }
  .pane-tabs button { flex: 1; }
  .editor textarea.body { padding: 18px 16px; font-size: 17px; min-height: calc(100vh - 200px); }
}

/* sheets */
.sheet-section { margin-bottom: 18px; } .sheet-section h3 { color: var(--fg); margin-bottom: 10px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.sheet-fields { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.sheet-fields .wide { grid-column: 1 / -1; }

/* characters */
.two-col { display: grid; grid-template-columns: 280px 1fr; gap: 16px; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } .two-col .col-list.collapsed { display: none; } }
.portrait { width: 96px; height: 96px; border-radius: 12px; object-fit: cover; background: var(--bg3); border: 1px solid var(--line); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--bg3); object-fit: cover; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; flex-shrink: 0; }
.arc-timeline { position: relative; padding-left: 22px; }
.arc-timeline:before { content: ""; position: absolute; left: 8px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.arc-event { position: relative; margin-bottom: 12px; }
.arc-event:before { content: ""; position: absolute; left: -19px; top: 14px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }

/* ideas kanban */
.kanban { display: grid; grid-template-columns: repeat(4, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; align-items: start; }
.kanban .col { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 200px; }
.kanban .col h3 { display: flex; justify-content: space-between; }
.kanban .col.over { border-color: var(--accent); }
.idea-card { background: var(--bg3); border-radius: 8px; padding: 10px; margin-bottom: 8px; cursor: pointer; border-left: 4px solid transparent; }
.idea-card .body { color: var(--fg2); font-size: .9em; max-height: 60px; overflow: hidden; }
@media (max-width: 860px) { .kanban { grid-template-columns: repeat(4, 80vw); } }

/* storyboard */
.sb-row { margin-bottom: 14px; }
.sb-row h3 { display: flex; align-items: center; gap: 10px; }
.sb-cards { display: flex; gap: 10px; overflow-x: auto; padding: 6px 2px 10px; min-height: 150px; }
.sb-card { width: 200px; flex-shrink: 0; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; border-top: 4px solid var(--line); }
.sb-card img, .sb-card .noimg { width: 100%; height: 110px; object-fit: cover; background: var(--bg3); display: flex; align-items: center; justify-content: center; color: var(--fg3); }
.sb-card .cap { padding: 8px; font-size: .9em; }
.sb-card .sum { color: var(--fg3); font-size: .8em; max-height: 54px; overflow: hidden; }
.sb-cards.over { outline: 2px dashed var(--accent); border-radius: 10px; }
.sb-card.dragging { opacity: .4; }

/* photos */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.photo { position: relative; border-radius: 10px; overflow: hidden; background: var(--bg3); cursor: pointer; aspect-ratio: 1; border: 1px solid var(--line); }
.photo img { width: 100%; height: 100%; object-fit: cover; }
.photo .cap { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.55); color: #fff; font-size: .75em; padding: 4px 6px; }
.board { position: relative; height: 70vh; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.board .pin { position: absolute; width: 160px; cursor: grab; box-shadow: 0 6px 20px rgba(0,0,0,.4); border-radius: 8px; overflow: hidden; background: var(--bg3); }
.board .pin img { width: 100%; display: block; } .board .pin .cap { font-size: .75em; padding: 4px 6px; }

/* outline */
.beat { border-left: 4px solid var(--line); padding-left: 12px; margin-bottom: 10px; }
.beat.here { border-left-color: var(--accent); }
.beat.planned { border-left-color: var(--warn); } .beat.drafted { border-left-color: var(--ok); }
.beat-head { display: flex; align-items: center; gap: 10px; cursor: pointer; min-height: 40px; }
.beat .pct { color: var(--fg3); font-size: .8em; min-width: 40px; }
.beat .desc { color: var(--fg2); font-size: .9em; }
.outline-bar { position: relative; height: 14px; background: var(--bg3); border-radius: 999px; margin: 8px 0 18px; }
.outline-bar i { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--fg3); }
.outline-bar b { position: absolute; top: -4px; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); transform: translateX(-50%); }

/* wizard */
.wizard { max-width: 760px; margin: 0 auto; }
.wizard .steps { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.wizard .steps span { padding: 4px 10px; border-radius: 999px; background: var(--bg3); font-size: .8em; color: var(--fg3); }
.wizard .steps span.on { background: var(--accent); color: #fff; }
.option-cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.option-card { border: 2px solid var(--line); border-radius: 10px; padding: 12px; cursor: pointer; background: var(--bg2); }
.option-card.on { border-color: var(--accent); }
.option-card p { font-size: .85em; color: var(--fg2); margin: 4px 0 0; }

/* audiobook */
.ab-chapter { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.check { display: flex; gap: 8px; align-items: center; font-size: .85em; padding: 6px 8px; background: var(--bg3); border-radius: 6px; }
audio { width: 100%; }

/* login */
.login { max-width: 360px; margin: 12vh auto; }

/* manuscript preview */
.manuscript { background: #fff; color: #000; font: 12pt/2 "Times New Roman", Times, serif; max-width: 8.5in; margin: 0 auto; padding: 1in; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.manuscript p { text-indent: .5in; margin: 0; } .manuscript .scene-break { text-align: center; text-indent: 0; }
.manuscript .chapter { page-break-before: always; padding-top: 3in; } .manuscript .chapter h2 { text-align: center; font-weight: normal; font-size: 12pt; margin: 0 0 2em; text-transform: uppercase; }
.manuscript .title-page { page-break-after: always; min-height: 9in; } .manuscript .title-page .mid { text-align: center; margin-top: 3in; }
.manuscript .matter { page-break-before: always; } .manuscript .matter.center { text-align: center; padding-top: 3in; } .manuscript .matter.center p { text-indent: 0; }
@media print { body { background: #fff; display: block; } .sidenav, .topbar, .help-panel, .toasts, .no-print { display: none !important; } .content { padding: 0; } .manuscript { box-shadow: none; margin: 0; padding: 0; max-width: none; } @page { size: letter; margin: 1in; } }
