/* ===== Theme tokens ===== */
:root {
  --bg: #f7f4ee;
  --surface: #fffdf9;
  --surface-2: #f1ece3;
  --border: #e4ddd0;
  --text: #2a2622;
  --muted: #7a7166;
  --accent: #b4532a;
  --accent-soft: #f5e3d8;
  --on-accent: #fff;
  --danger: #c0392b;
  --success: #3d8b5a;
  --warn: #c58a1b;
  --paper: #fffdf9;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 8px 24px rgba(40, 30, 20, .07);
  --radius: 12px;
  --ui-font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --editor-font: "Lora", "Noto Serif", Georgia, serif;
  --editor-size: 19px;
  --editor-lh: 1.8;
  --editor-width: 720px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #15151a;
  --surface: #1d1d23;
  --surface-2: #26262d;
  --border: #34343c;
  --text: #ebe7e1;
  --muted: #9b958c;
  --accent: #e57d4c;
  --accent-soft: #3b2a21;
  --on-accent: #1a120d;
  --danger: #ef6b5b;
  --success: #5fbf84;
  --warn: #e0ab45;
  --paper: #1b1b21;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #15151a;
    --surface: #1d1d23;
    --surface-2: #26262d;
    --border: #34343c;
    --text: #ebe7e1;
    --muted: #9b958c;
    --accent: #e57d4c;
    --accent-soft: #3b2a21;
    --on-accent: #1a120d;
    --danger: #ef6b5b;
    --success: #5fbf84;
    --warn: #e0ab45;
    --paper: #1b1b21;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

:root[data-theme="sepia"] {
  --bg: #ede3cd;
  --surface: #f6eedb;
  --surface-2: #e7dbc0;
  --border: #d6c8aa;
  --text: #45372a;
  --muted: #806e58;
  --accent: #9c4a23;
  --accent-soft: #ead2bd;
  --paper: #f8f0dc;
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui-font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
::selection { background: var(--accent-soft); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-style: dashed; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .4; cursor: default; pointer-events: none; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border-radius: 9px; border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.active { background: var(--accent-soft); color: var(--accent); }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn.sm svg.i { width: 15px; height: 15px; }

input[type="text"], input[type="search"], input[type="number"], input[type="password"], select, textarea {
  width: 100%; padding: 9px 12px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 80px; line-height: 1.6; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
label.check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; cursor: pointer; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.muted { color: var(--muted); }
.mobile-only { display: none !important; }

/* ===== Top bar (home) ===== */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand-logo { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; }
.brand-logo svg.i { width: 18px; height: 18px; }
.search { flex: 1; max-width: 460px; position: relative; margin-left: auto; }
.search svg.i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 38px; border-radius: 999px; background: var(--surface); }
.top-actions { display: flex; gap: 2px; }

/* ===== Home ===== */
.home { max-width: 1200px; margin: 0 auto; padding: 28px 24px 64px; }
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.hero h1 { margin: 0 0 4px; font-size: 28px; letter-spacing: -.02em; }
.hero p { margin: 0; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr) 1.4fr; gap: 14px; margin-bottom: 28px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 13px; font-weight: 500; color: var(--muted); }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.progress.done > i { background: var(--success); }
.heatmap { display: grid; grid-template-columns: repeat(14, 1fr); gap: 4px; margin-top: 10px; }
.heatmap i { aspect-ratio: 1; border-radius: 3px; background: var(--surface-2); }
.heatmap i[data-l="1"] { background: color-mix(in srgb, var(--accent) 30%, var(--surface-2)); }
.heatmap i[data-l="2"] { background: color-mix(in srgb, var(--accent) 55%, var(--surface-2)); }
.heatmap i[data-l="3"] { background: color-mix(in srgb, var(--accent) 80%, var(--surface-2)); }
.heatmap i[data-l="4"] { background: var(--accent); }

.filter-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 6px 13px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 13.5px; }
.chip:hover { background: var(--surface-2); }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.filter-row select { width: auto; padding: 6px 10px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.card {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; overflow: hidden; transition: transform .15s, box-shadow .15s;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.cover {
  position: relative; height: 150px; padding: 18px; display: flex; align-items: flex-end;
  background: linear-gradient(135deg, var(--cover), color-mix(in srgb, var(--cover) 55%, #000));
  color: #fff;
}
.cover::before { content: ""; position: absolute; left: 10px; top: 0; bottom: 0; width: 2px; background: rgba(255, 255, 255, .18); }
.cover-title { font-family: var(--editor-font); font-size: 20px; font-weight: 600; line-height: 1.25; text-shadow: 0 1px 8px rgba(0, 0, 0, .25); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.badge { position: absolute; top: 12px; right: 12px; font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: rgba(0, 0, 0, .32); color: #fff; backdrop-filter: blur(4px); }
.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card-body .meta { font-size: 13px; color: var(--muted); margin: 0; }
.card-body .summary { font-size: 13.5px; margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-body .updated { font-size: 12px; color: var(--muted); margin: auto 0 0; padding-top: 6px; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { font-size: 11.5px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.card.new {
  border-style: dashed; align-items: center; justify-content: center; min-height: 260px; color: var(--muted);
  background: transparent; cursor: pointer; gap: 10px; font-weight: 500;
}
.card.new:hover { color: var(--accent); border-color: var(--accent); }
.card.new svg.i { width: 32px; height: 32px; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); grid-column: 1 / -1; }

/* ===== Workspace ===== */
.workspace { display: grid; grid-template-columns: 280px 1fr 300px; height: 100vh; height: 100dvh; overflow: hidden; }
.workspace.no-panel { grid-template-columns: 280px 1fr 0; }
.sidebar, .panel { background: var(--surface); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.sidebar { border-right: 1px solid var(--border); }
.panel { border-left: 1px solid var(--border); }
.no-panel .panel { border: 0; }

.side-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--border); }
.back-link { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); padding: 4px 6px 4px 2px; border-radius: 6px; }
.back-link:hover { color: var(--text); background: var(--surface-2); }
.back-link svg.i { width: 15px; height: 15px; }
.story-head { display: flex; align-items: flex-start; gap: 8px; margin-top: 8px; }
.story-head h2 { margin: 0; font-size: 17px; line-height: 1.3; flex: 1; font-family: var(--editor-font); }
.story-meta { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

.tabs { display: flex; padding: 8px 10px 0; gap: 2px; border-bottom: 1px solid var(--border); }
.tab { flex: 1; display: flex; align-items: center; justify-content: center; gap: 5px; padding: 9px 2px; white-space: nowrap; font-size: 13px !important; border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 13px; font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab svg.i { width: 15px; height: 15px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.side-body { flex: 1; overflow-y: auto; padding: 10px; }

.chapter-list { list-style: none; margin: 0 0 10px; padding: 0; }
.ch-item { position: relative; display: flex; align-items: center; border-radius: 9px; margin-bottom: 2px; }
.ch-item:hover { background: var(--surface-2); }
.ch-item.active { background: var(--accent-soft); }
.ch-item.dragging { opacity: .4; }
.ch-item.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.ch-item.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }
.grip { width: 14px; align-self: stretch; cursor: grab; display: grid; place-items: center; color: var(--muted); opacity: 0; }
.grip svg.i { width: 12px; height: 12px; }
.ch-item:hover .grip { opacity: .7; }
.ch-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 8px 6px 8px 2px; }
.ch-num { font-size: 12px; color: var(--muted); width: 18px; text-align: right; font-variant-numeric: tabular-nums; }
.ch-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.ch-item.active .ch-title { font-weight: 600; }
.ch-words { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; margin-right: 8px; background: var(--border); }
.dot.revise { background: var(--warn); }
.dot.done { background: var(--success); }
.ch-actions { position: absolute; right: 4px; display: none; gap: 0; background: var(--surface-2); border-radius: 8px; }
.ch-item.active .ch-actions { background: var(--accent-soft); }
.ch-item:hover .ch-actions { display: flex; }

.entity { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 9px; cursor: pointer; width: 100%; border: 0; background: none; text-align: left; }
.entity:hover { background: var(--surface-2); }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 600; flex: none; font-size: 14px; }
.entity-name { font-weight: 500; font-size: 14px; }
.entity-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entity > div { min-width: 0; flex: 1; }
.group-label { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 12px 8px 4px; }
.note-icon { width: 34px; height: 34px; border-radius: 9px; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); flex: none; }

/* ===== Editor ===== */
.editor-area { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--paper); }
.editor-top { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-bottom: 1px solid var(--border); background: var(--surface); }
.format-bar { display: flex; align-items: center; gap: 1px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.format-bar::-webkit-scrollbar { display: none; }
.format-bar .fmt, .format-bar .sep { flex: none; }
.format-bar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 6px; }
.fmt { min-width: 32px; height: 32px; padding: 0 7px; border: 0; background: none; border-radius: 7px; cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 600; display: inline-grid; place-items: center; }
.fmt:hover { background: var(--surface-2); color: var(--text); }
.fmt.on { background: var(--accent-soft); color: var(--accent); }
.fmt svg.i { width: 16px; height: 16px; }
.editor-tools { display: flex; gap: 1px; flex: none; }

.editor-scroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.page-wrap { max-width: var(--editor-width); margin: 0 auto; padding: 48px 32px 40vh; }
.chapter-title {
  width: 100%; border: 0; background: transparent; outline: none; padding: 0; margin-bottom: 24px;
  font-family: var(--editor-font); font-size: calc(var(--editor-size) * 1.65); font-weight: 600; line-height: 1.25;
}
.chapter-title:focus { box-shadow: none; }
.editor {
  outline: none; font-family: var(--editor-font); font-size: var(--editor-size); line-height: var(--editor-lh);
  min-height: 50vh; caret-color: var(--accent); overflow-wrap: break-word;
}
.editor.is-empty::before { content: attr(data-placeholder); color: var(--muted); opacity: .6; position: absolute; pointer-events: none; }
.prose p, .prose div { margin: 0 0 1em; }
.prose.indent p { text-indent: 2em; margin-bottom: .35em; }
.prose h1, .prose h2, .prose h3 { line-height: 1.3; margin: 1.4em 0 .6em; }
.prose h2 { font-size: 1.35em; }
.prose h3 { font-size: 1.15em; }
.prose blockquote { margin: 1em 0; padding: .2em 0 .2em 1.2em; border-left: 3px solid var(--accent); color: var(--muted); font-style: italic; }
.prose blockquote p { text-indent: 0; }
.prose hr { border: 0; text-align: center; margin: 2em 0; height: auto; }
.prose hr::after { content: "⁂"; color: var(--muted); font-size: 1.1em; letter-spacing: .5em; }
.prose ul, .prose ol { padding-left: 1.6em; margin: 0 0 1em; }
.prose li p { text-indent: 0; }

.statusbar {
  display: flex; align-items: center; gap: 18px; padding: 7px 16px; border-top: 1px solid var(--border);
  font-size: 12.5px; color: var(--muted); background: var(--surface); font-variant-numeric: tabular-nums; flex-wrap: wrap;
}
.statusbar .grow { flex: 1; }
.statusbar b { color: var(--text); font-weight: 600; }
.sb-sprint { color: var(--accent); font-weight: 600; cursor: pointer; }
.saved::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--success); margin-right: 6px; }
.saved.pending::before { background: var(--warn); }

.empty-editor { flex: 1; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 24px; }
.empty-editor h3 { color: var(--text); font-family: var(--editor-font); font-size: 22px; margin: 0 0 6px; }

/* ===== Right panel ===== */
.panel-inner { overflow-y: auto; padding: 16px; flex: 1; width: 300px; }
.panel h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 10px; }
.panel section { margin-bottom: 24px; }
.panel textarea { min-height: 160px; font-size: 14px; }
.kv { display: flex; justify-content: space-between; font-size: 13.5px; padding: 5px 0; border-bottom: 1px dashed var(--border); }
.kv span:first-child { color: var(--muted); }
.mini-chars { display: flex; flex-direction: column; gap: 2px; }
.mini-chars .entity { padding: 5px 6px; }
.mini-chars .avatar { width: 26px; height: 26px; font-size: 12px; }
.seg { display: flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { flex: 1; border: 0; background: none; padding: 6px 4px; border-radius: 7px; cursor: pointer; font-size: 12.5px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); font-weight: 600; }

/* ===== Focus mode ===== */
body.focus .sidebar, body.focus .panel { display: none; }
body.focus .workspace { grid-template-columns: 1fr; }
body.focus .editor-top { opacity: 0; transition: opacity .25s; position: absolute; left: 0; right: 0; z-index: 5; }
body.focus .editor-top:hover { opacity: 1; }
body.focus .statusbar { opacity: .5; }
body.focus .editor-area { position: relative; }
.focus-exit { position: fixed; top: 14px; right: 18px; z-index: 20; display: none; }
body.focus .focus-exit { display: inline-flex; }

/* ===== Reader ===== */
.reader { position: fixed; inset: 0; z-index: 50; background: var(--paper); display: flex; flex-direction: column; }
.reader-top { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.reader-top select { width: auto; max-width: 40vw; }
.reader-top .grow { flex: 1; }
.reader-scroll { flex: 1; overflow-y: auto; }
.reader article { max-width: 680px; margin: 0 auto; padding: 56px 28px 80px; font-family: var(--editor-font); font-size: var(--reader-size, 20px); line-height: 1.85; }
.reader article h1.ch { font-size: 1.6em; text-align: center; margin: 0 0 1.6em; line-height: 1.3; }
.reader article .ch-block + .ch-block { margin-top: 4em; padding-top: 3em; border-top: 1px solid var(--border); }
.reader .title-page { text-align: center; padding: 10vh 0 4em; }
.reader .title-page h1 { font-size: 2.2em; margin: 0 0 .3em; }
.reader-nav { display: flex; justify-content: space-between; max-width: 680px; margin: 0 auto; padding: 0 28px 48px; gap: 12px; }

/* ===== Modal ===== */
dialog#modal {
  border: 0; padding: 0; border-radius: 16px; background: var(--surface); color: var(--text);
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog#modal.wide { width: min(780px, calc(100vw - 32px)); }
dialog#modal::backdrop { background: rgba(20, 15, 10, .45); backdrop-filter: blur(2px); }
.modal-card { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.modal-card > header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 8px; }
.modal-card h3 { margin: 0; font-size: 18px; }
.modal-body { padding: 8px 20px 16px; overflow-y: auto; }
.modal-card > footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; border-top: 1px solid var(--border); }
.modal-card > footer .left { margin-right: auto; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; padding: 0; }
.swatch.on { border-color: var(--text); }
.list { display: flex; flex-direction: column; gap: 6px; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.list-item > div:first-child { flex: 1; min-width: 0; }
.preview-box { margin-top: 12px; padding: 16px; border: 1px solid var(--border); border-radius: 10px; max-height: 320px; overflow-y: auto; font-family: var(--editor-font); background: var(--paper); }
.export-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.export-opt { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); cursor: pointer; text-align: left; }
.export-opt:hover { border-color: var(--accent); background: var(--accent-soft); }
.export-opt b { font-size: 15px; }
.export-opt span { font-size: 12.5px; color: var(--muted); }
kbd { font-family: ui-monospace, monospace; font-size: 12px; padding: 2px 6px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; background: var(--surface-2); }
.help-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.help-table td { padding: 7px 0; border-bottom: 1px solid var(--border); }
.help-table td:last-child { text-align: right; }
.result-line { font-size: 13.5px; padding: 6px 0; color: var(--muted); }

/* ===== AI ===== */
.hero-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ai-btn { background: linear-gradient(135deg, #6d4bd8, #c2477a); border-color: transparent; color: #fff; }
.ai-btn:hover { background: linear-gradient(135deg, #7a58e6, #d0548a); filter: brightness(1.05); }
.tab-ai.active { color: #8a5cf0; border-bottom-color: #8a5cf0; }
.ai-empty { text-align: center; padding: 24px 8px; }
.ai-empty h3 { margin: 8px 0 6px; font-family: var(--editor-font); }
.ai-empty p { font-size: 13.5px; }
.ai-badge { width: 52px; height: 52px; margin: 0 auto; border-radius: 16px; display: grid; place-items: center; font-size: 26px; background: linear-gradient(135deg, #6d4bd8, #c2477a); }
.ai-status { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: 13.5px; font-weight: 600; margin-bottom: 12px; }
.ai-status.locked { background: color-mix(in srgb, var(--success) 14%, var(--surface)); }
.ai-prog-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.ai-prog-row b { color: var(--text); }
.ai-actions { display: flex; flex-direction: column; gap: 8px; margin: 14px 0 6px; }
.ai-actions .btn { white-space: normal; }
.ai-writing { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--accent); font-weight: 600; padding: 6px 2px; }
.ai-done { text-align: center; padding: 10px; border-radius: 10px; background: color-mix(in srgb, var(--success) 14%, var(--surface)); font-weight: 600; font-size: 14px; }
.ai-outline { list-style: none; margin: 0; padding: 0; }
.ai-outline li { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px; font-size: 13.5px; }
.ai-outline li[data-action] { cursor: pointer; }
.ai-outline li[data-action]:hover { background: var(--surface-2); }
.ai-outline li.active { background: var(--accent-soft); font-weight: 600; }
.ai-outline li.todo { color: var(--muted); }
.ai-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; border: 2px solid var(--border); }
.ai-outline li.done .ai-dot { background: var(--success); border-color: var(--success); }
.ai-outline li.writing .ai-dot { border-color: var(--accent); border-top-color: transparent; animation: spin .8s linear infinite; }
.ai-ol-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-ol-go { font-size: 11.5px; color: var(--accent); opacity: 0; font-weight: 600; }
.ai-outline li:hover .ai-ol-go { opacity: 1; }
.ai-usage { font-size: 12px; margin: 10px 8px 0; }
.ai-caret { color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
.ai-progress { display: flex; align-items: center; gap: 16px; padding: 10px 0 6px; }
.ai-spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--surface-2); border-top-color: #8a5cf0; animation: spin .9s linear infinite; flex: none; }
.ai-spinner.sm { width: 16px; height: 16px; border-width: 2px; }
.ai-banner { padding: 10px 14px; border-radius: 10px; background: color-mix(in srgb, #8a5cf0 12%, var(--surface)); font-size: 13.5px; margin-bottom: 14px; }
.ai-banner.locked { background: color-mix(in srgb, var(--success) 14%, var(--surface)); }
.bible-tabs { margin-bottom: 14px; }
.bible-card { border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 8px; }
.bible-card .row { gap: 8px; }
.bible-card textarea { min-height: 54px; font-size: 14px; }
.row3 { display: flex; gap: 8px; align-items: center; }
.row3 input[data-f="name"], .row3 input[data-f="title"] { flex: 2; }
.row3 select, .row3 input[data-f="age"] { flex: 1; }
.ol-num { width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: 12.5px; font-weight: 600; flex: none; }
.pill { font-size: 11.5px; padding: 3px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.ok { background: color-mix(in srgb, var(--success) 18%, var(--surface)); color: var(--success); }
.ai-feedback { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
textarea:disabled, input:disabled, select:disabled { opacity: .85; background: var(--surface-2); cursor: default; }
@media (max-width: 760px) { .modal-card > footer { flex-wrap: wrap; } .modal-card > footer .left { margin-right: 0; } }

/* ===== Cloud sync ===== */
.sync-ind.idle { color: var(--success); }
.sync-ind.syncing { color: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.sync-ind.error { color: var(--danger); }
.sync-ind.offline { color: var(--warn); }
@keyframes pulse { 50% { opacity: .4; } }
.sb-sync { cursor: pointer; }
.sb-sync.error { color: var(--danger); }
.sb-sync.offline { color: var(--warn); }
.sync-join { display: flex; gap: 8px; margin: 12px 0 4px; }
.sync-join input { font-family: ui-monospace, monospace; letter-spacing: .04em; }
.sync-adv { margin-top: 10px; font-size: 13.5px; }
.sync-adv summary { cursor: pointer; color: var(--muted); }
.sync-state { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--success) 12%, var(--surface)); font-size: 13.5px; font-weight: 600; margin-bottom: 14px; }
.sync-state.error { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }
.sync-state.offline { background: color-mix(in srgb, var(--warn) 14%, var(--surface)); }
.sync-state .muted { font-weight: 400; font-size: 12.5px; }
.sync-code-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sync-code { flex: 1; min-width: 0; font-family: ui-monospace, monospace; font-size: 15px; letter-spacing: .06em; padding: 8px 12px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--border); overflow-wrap: anywhere; }
.sync-code.masked { color: transparent; text-shadow: 0 0 7px var(--muted); user-select: none; }

/* ===== Toast ===== */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); animation: toast-in .2s ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ===== Responsive ===== */
@media (max-width: 1100px) {
  .workspace, .workspace.no-panel { grid-template-columns: 260px 1fr; }
  .panel { position: fixed; right: 0; top: 0; bottom: 0; z-index: 30; width: 300px; box-shadow: var(--shadow); transform: translateX(100%); transition: transform .2s; }
  .workspace.show-panel .panel { transform: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stats .heat { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .mobile-only { display: inline-grid !important; }
  .desktop-only { display: none !important; }
  .workspace, .workspace.no-panel { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 30; width: 290px; box-shadow: var(--shadow); transform: translateX(-100%); transition: transform .2s; }
  .workspace.show-sidebar .sidebar { transform: none; }
  .topbar { padding: 10px 16px; gap: 8px; flex-wrap: wrap; }
  .search { order: 3; max-width: none; flex-basis: 100%; }
  .brand span { display: none; }
  .home { padding: 20px 16px 48px; }
  .hero { flex-direction: column; align-items: stretch; }
  .hero h1 { font-size: 24px; }
  .page-wrap { padding: 28px 18px 40vh; }
  .editor-top { padding: 6px 8px; flex-wrap: wrap; }
  .format-bar { order: 3; flex-basis: 100%; }
  .editor-tools { margin-left: auto; }
  .statusbar { gap: 12px; padding: 6px 12px; }
  .row { grid-template-columns: 1fr; }
  .reader article { padding: 32px 18px 60px; }
}
.scrim { display: none; }
@media (max-width: 1100px) {
  .workspace.show-panel .scrim, .workspace.show-sidebar .scrim { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, .3); }
}

/* ===== Print (reader content only) ===== */
@media print {
  body > *:not(.reader) { display: none !important; }
  .reader { position: static; background: #fff; color: #000; }
  .reader-top, .reader-nav { display: none !important; }
  .reader-scroll { overflow: visible; }
  .reader article { max-width: none; padding: 0; font-size: 12pt; }
  .reader article .ch-block + .ch-block { page-break-before: always; border: 0; margin: 0; padding: 0; }
  .reader .title-page { page-break-after: always; }
}
