/* ==========================================================================
   Lorekeeper — calm, paper-toned interface
   ========================================================================== */

:root {
  --bg: #f6f3ed;
  --surface: #fffdf9;
  --surface-2: #efebe3;
  --surface-3: #e7e2d8;
  --ink: #24211c;
  --ink-2: #4b463d;
  --muted: #8a8377;
  --line: #e4ded3;
  --line-2: #d6cfc2;
  --accent: #4e7a70;
  --accent-2: #3f665d;
  --accent-soft: #e2ece8;
  --accent-ink: #fbfaf6;
  --danger: #a6483e;
  --danger-soft: #f6e5e1;
  --warn: #b38a3e;
  --shadow-sm: 0 1px 2px rgba(40, 32, 20, .06);
  --shadow: 0 1px 2px rgba(40, 32, 20, .05), 0 6px 20px -8px rgba(40, 32, 20, .14);
  --shadow-lg: 0 24px 60px -20px rgba(30, 24, 14, .35);
  --radius: 10px;
  --radius-sm: 7px;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Literata', 'Iowan Old Style', Georgia, serif;
  --sidebar-w: 268px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161513; --surface: #1e1c19; --surface-2: #26231f; --surface-3: #2f2b26;
    --ink: #ece7de; --ink-2: #c9c2b6; --muted: #958d80; --line: #312d28; --line-2: #3d3832;
    --accent: #84b3a6; --accent-2: #9cc4b8; --accent-soft: #23302c; --accent-ink: #12201c;
    --danger: #e08a7e; --danger-soft: #3a2421;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow: 0 1px 2px rgba(0,0,0,.25), 0 8px 24px -10px rgba(0,0,0,.5);
    --shadow-lg: 0 24px 60px -20px rgba(0,0,0,.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161513; --surface: #1e1c19; --surface-2: #26231f; --surface-3: #2f2b26;
  --ink: #ece7de; --ink-2: #c9c2b6; --muted: #958d80; --line: #312d28; --line-2: #3d3832;
  --accent: #84b3a6; --accent-2: #9cc4b8; --accent-soft: #23302c; --accent-ink: #12201c;
  --danger: #e08a7e; --danger-soft: #3a2421;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow: 0 1px 2px rgba(0,0,0,.25), 0 8px 24px -10px rgba(0,0,0,.5);
  --shadow-lg: 0 24px 60px -20px rgba(0,0,0,.7);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14.5px/1.55 var(--sans); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); }
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 500; letter-spacing: -.01em; margin: 0; color: var(--ink); }
h1 { font-size: 30px; line-height: 1.2; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
p { margin: 0 0 .8em; }
button { font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
code { font: 12.5px ui-monospace, 'SF Mono', Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
kbd { font: 11px var(--sans); border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; color: var(--muted); }
mark { background: color-mix(in srgb, var(--warn) 30%, transparent); color: inherit; border-radius: 2px; padding: 0 1px; }
.i { flex: none; display: inline-block; vertical-align: middle; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.grow { flex: 1; min-width: 0; }
[hidden] { display: none !important; }
::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 14px;
  border: 1px solid var(--line-2); background: var(--surface); border-radius: var(--radius-sm);
  font-weight: 500; font-size: 13.5px; cursor: pointer; white-space: nowrap; color: var(--ink);
  box-shadow: var(--shadow-sm); transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--surface-2); border-color: var(--line-2); color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: var(--accent-ink); }
.btn-ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.05); background: var(--danger); color: #fff; }
.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--danger); box-shadow: none; }
.btn-danger-ghost:hover { background: var(--danger-soft); color: var(--danger); }
.btn-block { width: 100%; justify-content: center; height: 42px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius-sm);
  border: 0; background: transparent; color: var(--muted); cursor: pointer; transition: background .15s, color .15s; flex: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.sm { width: 26px; height: 26px; }
.icon-btn.xs { width: 22px; height: 22px; border-radius: 5px; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
.field > span em { font-style: normal; font-weight: 400; color: var(--muted); }
input:not([type=checkbox]):not([type=radio]):not([type=file]), textarea, select {
  width: 100%; border: 1px solid var(--line-2); background: var(--surface); border-radius: var(--radius-sm);
  padding: 8px 11px; outline: none; transition: border-color .15s, box-shadow .15s; min-height: 36px;
}
textarea { resize: vertical; line-height: 1.55; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
select { appearance: none; padding-right: 30px; cursor: pointer;
  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='%238a8377' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .span2 { grid-column: span 2; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }
.check-list { display: flex; flex-direction: column; gap: 8px; }
.error { color: var(--danger); font-size: 13px; }

/* ---------- loading ---------- */
.page-loading { height: 100vh; display: grid; place-items: center; }
.page-loading::after { content: ''; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login & worlds ---------- */
.brand { display: inline-flex; align-items: center; gap: 9px; font-family: var(--serif); font-size: 18px; font-weight: 500; color: var(--ink); }
.brand .i { color: var(--accent); }
.brand.big { font-size: 26px; }
.brand:hover { color: var(--ink); }
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 20% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 34px 30px; box-shadow: var(--shadow-lg); }
.login-card .brand { margin-bottom: 8px; }
.login-card > p { margin-bottom: 24px; }

.worlds-page { max-width: 1040px; margin: 0 auto; padding: 64px 28px; }
.worlds-head { margin-bottom: 36px; }
.worlds-head p { margin-top: 6px; }
.world-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }
.world-card {
  display: flex; flex-direction: column; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 22px; color: var(--ink); box-shadow: var(--shadow); cursor: pointer; transition: transform .2s var(--ease), box-shadow .2s, border-color .2s; min-height: 210px;
}
.world-card:hover { transform: translateY(-2px); border-color: var(--line-2); color: var(--ink); box-shadow: var(--shadow-lg); }
.world-card.last { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.world-card.new { border-style: dashed; background: transparent; box-shadow: none; align-items: flex-start; }
.world-card.new:hover { background: var(--surface); }
.wc-icon { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); margin-bottom: 16px; }
.world-card h2 { font-size: 21px; margin-bottom: 6px; }
.wc-desc { color: var(--ink-2); font-size: 13.5px; flex: 1; }
.wc-stats { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.wc-foot { font-size: 12px; color: var(--muted); margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.worlds-foot { margin-top: 28px; }

/* ---------- shell ---------- */
.shell { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: var(--sidebar-w); flex: none; border-right: 1px solid var(--line); background: color-mix(in srgb, var(--surface-2) 55%, var(--bg));
  display: flex; flex-direction: column; overflow-y: auto; padding: 14px 12px 12px; gap: 4px; scrollbar-width: thin;
}
.main { flex: 1; overflow-y: auto; min-width: 0; position: relative; scroll-behavior: smooth; }
.scrim { display: none; }

.sb-top { display: flex; justify-content: space-between; align-items: center; padding: 2px 6px 10px; }
.world-switch { display: grid; grid-template-columns: 1fr auto; align-items: center; padding: 9px 11px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); color: var(--ink); box-shadow: var(--shadow-sm); margin-bottom: 8px; }
.world-switch:hover { border-color: var(--line-2); color: var(--ink); }
.ws-label { grid-column: 1; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.ws-name { grid-column: 1; font-family: var(--serif); font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.world-switch .i { grid-row: 1 / span 2; grid-column: 2; color: var(--muted); }
.sb-search { display: flex; align-items: center; gap: 8px; padding: 0 10px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--line); margin-bottom: 8px; color: var(--muted); }
.sb-search input { border: 0 !important; box-shadow: none !important; background: transparent !important; padding: 7px 0 !important; min-height: 32px !important; font-size: 13.5px; }
.sb-nav { display: flex; flex-direction: column; gap: 1px; }
.sb-nav a, .sb-bottom a, .sb-bottom button {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: var(--radius-sm); color: var(--ink-2);
  font-size: 13.5px; border: 0; background: none; cursor: pointer; text-align: left; width: 100%;
}
.sb-nav a .i, .sb-bottom .i { color: var(--muted); }
.sb-nav a:hover, .sb-bottom a:hover, .sb-bottom button:hover { background: color-mix(in srgb, var(--surface-3) 70%, transparent); color: var(--ink); }
.sb-nav a.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); font-weight: 500; }
.sb-nav .count { margin-left: auto; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ticon { display: inline-grid; place-items: center; color: var(--c); }
.ticon.big { width: 40px; height: 40px; border-radius: 10px; background: color-mix(in srgb, var(--c) 14%, transparent); margin-right: 12px; vertical-align: -6px; }
.sb-nav a .ticon .i { color: var(--c); }
.sb-section { margin-top: 14px; }
.sb-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 0 10px; margin-bottom: 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 600; }
.sb-empty { font-size: 12.5px; color: var(--muted); padding: 4px 10px; }
.sb-book-row { display: flex; align-items: center; gap: 2px; border-radius: var(--radius-sm); padding-right: 4px; }
.sb-book-row:hover { background: color-mix(in srgb, var(--surface-3) 70%, transparent); }
.sb-book-row.active { background: var(--surface); box-shadow: var(--shadow-sm); }
.twisty { border: 0; background: none; width: 24px; height: 28px; display: grid; place-items: center; color: var(--muted); cursor: pointer; flex: none; }
.twisty .i { transform: rotate(90deg); transition: transform .18s var(--ease); }
.sb-book.collapsed .twisty .i { transform: rotate(0); }
.sb-book.collapsed .sb-chapters { display: none; }
.sb-book-title { flex: 1; font-family: var(--serif); font-size: 14px; color: var(--ink); padding: 5px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ghost-hover { opacity: 0; }
.sb-book-row:hover .ghost-hover { opacity: 1; }
.sb-chapters { margin: 1px 0 6px 22px; border-left: 1px solid var(--line-2); padding-left: 4px; min-height: 6px; }
.sb-chapter { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 6px; color: var(--ink-2); font-size: 13px; cursor: pointer; }
.sb-chapter:hover { background: color-mix(in srgb, var(--surface-3) 70%, transparent); color: var(--ink); }
.sb-chapter.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.sb-chapter .num { font-size: 11px; color: var(--muted); width: 16px; text-align: right; font-variant-numeric: tabular-nums; }
.sb-chapter .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-chapter.sortable-ghost { opacity: .4; }
.sb-bottom { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 1px; }

.status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--line-2); flex: none; }
.status-dot.s-outline { background: #c9b88f; }
.status-dot.s-draft { background: #d39b5c; }
.status-dot.s-revised { background: #7d9fc4; }
.status-dot.s-final { background: #5e9a7f; }

.mobile-bar { display: none; }

/* ---------- pages ---------- */
.host { min-height: 100vh; }
.page { max-width: 1120px; margin: 0 auto; padding: 40px 44px 80px; animation: fade .25s var(--ease); }
.page.narrow { max-width: 760px; }
.page-wide { max-width: none; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.page-head h1 { display: flex; align-items: center; }
.eyebrow { font-size: 11.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 600; margin-bottom: 6px; display: flex; gap: 10px; align-items: center; }
.head-actions { display: flex; gap: 8px; align-items: center; flex: none; }
.lead { font-family: var(--serif); font-size: 17px; color: var(--ink-2); max-width: 70ch; margin-bottom: 28px; }
.save-state { font-size: 11.5px; font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--muted); }
.save-state[data-state="saving"], .save-state[data-state="pending"] { color: var(--warn); }
.save-state[data-state="error"] { color: var(--danger); }
.title-input { font-family: var(--serif) !important; font-size: 30px !important; font-weight: 500; border: 0 !important; background: transparent !important; padding: 2px 0 !important; box-shadow: none !important; letter-spacing: -.01em; }
.subtitle-input { border: 0 !important; background: transparent !important; padding: 2px 0 !important; box-shadow: none !important; color: var(--ink-2); font-size: 15px; }

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 36px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.stat-n { display: block; font-family: var(--serif); font-size: 26px; font-weight: 500; font-variant-numeric: tabular-nums; }
.stat-l { font-size: 12.5px; color: var(--muted); }
.block { margin-bottom: 38px; }
.block-title { font-size: 19px; margin-bottom: 14px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }

.empty { text-align: center; padding: 48px 24px; border: 1px dashed var(--line-2); border-radius: 14px; color: var(--muted); background: color-mix(in srgb, var(--surface) 50%, transparent); }
.empty > .i, .empty > .ticon { margin-bottom: 12px; color: var(--muted); }
.empty p { max-width: 44ch; margin: 0 auto 16px; }
.empty.soft { padding: 32px; }

.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.book-card { display: flex; gap: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; color: var(--ink); box-shadow: var(--shadow-sm); transition: transform .2s var(--ease), box-shadow .2s; }
.book-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); color: var(--ink); }
.book-spine { width: 62px; height: 92px; border-radius: 3px 7px 7px 3px; flex: none; display: flex; align-items: flex-end; padding: 8px 7px; position: relative; overflow: hidden;
  background: linear-gradient(105deg, rgba(0,0,0,.18) 0 6%, transparent 9%), linear-gradient(160deg, hsl(var(--hue) 28% 46%), hsl(var(--hue) 32% 32%)); box-shadow: inset -2px 0 0 rgba(255,255,255,.08), 0 3px 8px -3px rgba(0,0,0,.35); }
.book-spine span { font-family: var(--serif); color: rgba(255,255,255,.92); font-size: 10.5px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.book-info { min-width: 0; flex: 1; }
.book-info h3 { font-size: 17px; margin: 6px 0 2px; }
.book-info p { margin: 0 0 4px; }
.pill { display: inline-flex; align-items: center; font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); }
.pill.s-draft { background: color-mix(in srgb, #d39b5c 18%, transparent); }
.pill.s-revised { background: color-mix(in srgb, #7d9fc4 18%, transparent); }
.pill.s-final { background: color-mix(in srgb, #5e9a7f 20%, transparent); }
.pill.s-outline { background: color-mix(in srgb, #c9b88f 22%, transparent); }
.progress { height: 5px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.progress span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s var(--ease); }

.type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.type-tile { display: flex; align-items: center; gap: 10px; padding: 11px 13px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); color: var(--ink); transition: border-color .15s; }
.type-tile:hover { border-color: color-mix(in srgb, var(--c) 45%, var(--line)); color: var(--ink); }
.type-tile .ticon { width: 30px; height: 30px; border-radius: 8px; background: color-mix(in srgb, var(--c) 14%, transparent); }
.tt-l { flex: 1; font-size: 13.5px; }
.tt-n { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.recent { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.recent li + li { border-top: 1px solid var(--line); }
.recent a { display: flex; align-items: center; gap: 10px; padding: 10px 14px; color: var(--ink); }
.recent a:hover { background: var(--surface-2); color: var(--ink); }
.r-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-sub, .r-time { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ---------- entries list ---------- */
.filter-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.filter-bar select { width: auto; min-width: 180px; }
.filter-input { display: flex; align-items: center; gap: 8px; padding: 0 11px; background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius-sm); color: var(--muted); flex: 1; max-width: 360px; }
.filter-input input { border: 0 !important; box-shadow: none !important; padding: 7px 0 !important; background: transparent !important; }
.entry-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.entry-card { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; color: var(--ink); box-shadow: var(--shadow-sm); transition: transform .2s var(--ease), box-shadow .2s; }
.entry-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); color: var(--ink); }
.ec-img { height: 120px; background-size: cover; background-position: center 25%; }
.ec-mono { height: 64px; display: flex; align-items: flex-end; padding: 0 16px; font-family: var(--serif); font-size: 44px; line-height: .9; color: color-mix(in srgb, var(--c) 55%, transparent);
  background: linear-gradient(180deg, color-mix(in srgb, var(--c) 12%, transparent), transparent); overflow: hidden; }
.ec-body { padding: 12px 16px 14px; display: flex; flex-direction: column; flex: 1; }
.ec-body h3 { font-size: 17px; }
.ec-alias { font-size: 12px; color: var(--muted); margin: 2px 0 0; font-style: italic; }
.ec-sum { font-size: 13px; color: var(--ink-2); margin: 6px 0 10px; flex: 1; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.ec-foot { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ec-time { margin-left: auto; font-size: 11.5px; color: var(--muted); }
.tag { font-size: 11px; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 26px; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 500; padding: 3px 9px 3px 7px; border-radius: 99px; color: var(--c); background: color-mix(in srgb, var(--c) 13%, transparent); }

/* ---------- entry page ---------- */
.entry-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 26px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.entry-head h1 { font-size: 36px; margin-top: 10px; }
.crumbs { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.crumbs .sep { opacity: .5; }
.aliases { color: var(--muted); font-style: italic; font-family: var(--serif); margin: 6px 0 0; }
.entry-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 44px; align-items: start; }
.lead-sum { font-family: var(--serif); font-size: 18px; color: var(--ink-2); font-style: italic; margin-bottom: 20px; }
.entry-side { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 24px; }
.portrait { border-radius: 12px; overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow); }
.portrait img { display: block; width: 100%; max-height: 380px; object-fit: cover; }
.side-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.side-card h3 { font-family: var(--sans); font-size: 11.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.side-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.side-head h3 { margin: 0; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 13.5px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); color: var(--ink); font-size: 12.5px; border: 1px solid transparent; }
.chip:hover { border-color: var(--line-2); color: var(--ink); }
.chip.missing { color: var(--danger); background: var(--danger-soft); }
.chip em { font-style: normal; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; opacity: .8; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); display: inline-block; flex: none; }
.rel-list, .link-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.rel-list li { display: flex; align-items: center; gap: 8px; font-size: 13.5px; padding: 4px 0; flex-wrap: wrap; }
.rel-list li a { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); font-weight: 500; }
.rel-list li a:hover { color: var(--accent); }
.rel-label { color: var(--muted); font-size: 12.5px; }
.rel-list .icon-btn { margin-left: auto; opacity: 0; }
.rel-list li:hover .icon-btn { opacity: 1; }
.link-list a { display: flex; align-items: center; gap: 8px; padding: 5px 6px; margin: 0 -6px; border-radius: 6px; color: var(--ink); font-size: 13.5px; }
.link-list a:hover { background: var(--surface-2); color: var(--ink); }
.link-list a .i { color: var(--muted); }
.link-list a span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-list em { font-style: normal; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.entry-page.editing .entry-head { align-items: flex-end; }
.fields-editor { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.field-row { display: grid; grid-template-columns: 180px 1fr 24px; gap: 8px; align-items: center; }
.field-row .icon-btn { opacity: .5; }
.field-row:hover .icon-btn { opacity: 1; }

/* ---------- markdown ---------- */
.markdown { font-family: var(--serif); font-size: 17px; line-height: 1.75; color: var(--ink); max-width: 70ch; overflow-wrap: break-word; }
.markdown > *:first-child { margin-top: 0; }
.markdown p { margin: 0 0 1em; }
.markdown h1, .markdown h2, .markdown h3 { margin: 1.6em 0 .5em; line-height: 1.3; }
.markdown h1 { font-size: 1.7em; } .markdown h2 { font-size: 1.35em; } .markdown h3 { font-size: 1.12em; }
.markdown blockquote { margin: 1.2em 0; padding: .2em 0 .2em 1.2em; border-left: 3px solid var(--line-2); color: var(--ink-2); font-style: italic; }
.markdown ul, .markdown ol { padding-left: 1.4em; margin: 0 0 1em; }
.markdown li { margin: .25em 0; }
.markdown hr { border: 0; text-align: center; margin: 2em 0; }
.markdown hr::after { content: '⁂'; color: var(--muted); font-size: 1.1em; letter-spacing: .5em; }
.markdown img { max-width: 100%; border-radius: 8px; }
.markdown table { border-collapse: collapse; font-family: var(--sans); font-size: 14px; margin: 1em 0; }
.markdown th, .markdown td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.markdown pre { background: var(--surface-2); padding: 12px 14px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.markdown pre code { background: none; padding: 0; }
.markdown.small { font-size: 14.5px; }
a.wikilink { color: var(--accent); border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); transition: border-color .15s; }
a.wikilink:hover { border-bottom-color: var(--accent); }
a.wikilink.missing { color: var(--danger); border-bottom: 1px dashed color-mix(in srgb, var(--danger) 55%, transparent); }

/* ---------- editor ---------- */
.editor { position: relative; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--surface); }
.editor:focus-within { border-color: color-mix(in srgb, var(--accent) 60%, var(--line-2)); }
.editor-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5px 6px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 2; border-radius: var(--radius) var(--radius) 0 0; flex-wrap: wrap; }
.tb-group { display: flex; gap: 1px; align-items: center; }
.tb { display: inline-flex; align-items: center; gap: 5px; height: 28px; min-width: 28px; justify-content: center; padding: 0 6px; border-radius: 6px; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 12.5px; }
.tb:hover { background: var(--surface-2); color: var(--ink); }
.seg { background: var(--surface-2); border-radius: 7px; padding: 2px; }
.seg .tb { height: 24px; padding: 0 8px; }
.seg .tb.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.editor-panes { display: grid; grid-template-columns: 1fr; }
.editor[data-mode="split"] .editor-panes { grid-template-columns: 1fr 1fr; }
.editor[data-mode="preview"] .editor-input { display: none; }
.editor[data-mode="write"] .editor-preview { display: none; }
.editor-input {
  border: 0 !important; box-shadow: none !important; resize: none !important; border-radius: 0 0 var(--radius) var(--radius) !important;
  background: transparent !important; padding: 18px 20px !important; font: 15px/1.7 ui-monospace, 'SF Mono', Menlo, Consolas, monospace; min-height: 240px; overflow: hidden;
}
.editor-preview { padding: 18px 22px; min-height: 240px; border-left: 1px solid var(--line); max-width: none; }
.editor[data-mode="preview"] .editor-preview { border-left: 0; }
.prose-editor { border: 0; background: transparent; }
.prose-editor .editor-toolbar { background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid transparent; border-radius: 8px; top: 0; margin-bottom: 8px; }
.prose-editor:focus-within .editor-toolbar { border-bottom-color: var(--line); }
.prose-editor .editor-input { font: 19px/1.85 var(--serif); padding: 4px 0 40px !important; min-height: 60vh; color: var(--ink); }
.prose-editor .editor-input::placeholder { color: var(--muted); font-style: italic; }
.prose-editor .editor-preview { font-size: 19px; line-height: 1.85; padding: 4px 0 40px; border: 0; }
.prose-editor[data-mode="split"] .editor-preview { padding-left: 28px; border-left: 1px solid var(--line); }
.prose-editor[data-mode="split"] .editor-input { padding-right: 28px !important; font-size: 16px; }
.ac-pop { position: absolute; z-index: 20; width: 260px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 4px; max-height: 300px; overflow-y: auto; }
.ac-item { display: flex; align-items: center; gap: 9px; padding: 7px 9px; border-radius: 7px; cursor: pointer; font-size: 13.5px; }
.ac-item.active { background: var(--accent-soft); }
.ac-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-type { font-size: 11px; color: var(--muted); }
.ac-new { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); background: var(--accent-soft); border-radius: 4px; padding: 1px 5px; }

/* ---------- book ---------- */
.book-overview { display: grid; grid-template-columns: 1fr 260px; gap: 28px; margin-bottom: 32px; }
.book-stats { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.book-stats .field { margin-bottom: 10px; }
.mini-stat { font-size: 13.5px; color: var(--ink-2); }
.mini-stat strong { font-family: var(--serif); font-size: 20px; font-weight: 500; color: var(--ink); }
.status-summary { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); margin-top: 12px; }
.status-summary span { display: inline-flex; align-items: center; gap: 5px; }
.chapter-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.chapter-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px 12px 8px; }
.chapter-row + .chapter-row { border-top: 1px solid var(--line); }
.chapter-row:hover { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
.chapter-row.sortable-ghost { opacity: .35; }
.grip { color: var(--muted); cursor: grab; display: grid; place-items: center; opacity: .45; }
.chapter-row:hover .grip, .sl-row:hover .grip { opacity: 1; }
.ch-num { font-family: var(--serif); color: var(--muted); width: 22px; text-align: right; font-variant-numeric: tabular-nums; }
.ch-main { flex: 1; min-width: 0; display: flex; flex-direction: column; color: var(--ink); }
.ch-main:hover { color: var(--ink); }
.ch-main:hover .ch-title { color: var(--accent); }
.ch-title { font-family: var(--serif); font-size: 16px; }
.ch-syn { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-meta { display: flex; align-items: center; gap: 10px; flex: none; }
.ch-meta .muted { display: inline-flex; align-items: center; gap: 4px; }
.ch-words { font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--muted); width: 56px; text-align: right; }
.sl-chip { font-size: 11px; padding: 2px 8px; border-radius: 99px; color: var(--c); background: color-mix(in srgb, var(--c) 13%, transparent); white-space: nowrap; }

/* ---------- chapter writing ---------- */
.main-writing { background: var(--bg); }
.chapter-form { display: grid; grid-template-columns: 1fr 0; min-height: 100vh; transition: grid-template-columns .25s var(--ease); }
.chapter-form.panel-open { grid-template-columns: 1fr 320px; }
.writing-area { min-width: 0; }
.writing-top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 20px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); }
.writing-tools { display: flex; align-items: center; gap: 4px; }
.wc { font-size: 12.5px; color: var(--muted); margin-right: 8px; white-space: nowrap; }
.wc strong { color: var(--ink-2); font-weight: 500; font-variant-numeric: tabular-nums; }
.wc em { font-style: normal; color: var(--accent); margin-left: 6px; }
.manuscript { max-width: 720px; margin: 0 auto; padding: 28px 32px 120px; }
.chapter-title { font-family: var(--serif) !important; font-size: 34px !important; font-weight: 500; text-align: center; border: 0 !important; background: transparent !important; box-shadow: none !important; margin: 20px 0 26px; }
.chapter-nav { display: flex; justify-content: space-between; align-items: center; gap: 12px; border-top: 1px solid var(--line); padding-top: 18px; font-size: 13.5px; }
.chapter-nav a { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.chapter-nav a:hover { color: var(--accent); }
.chapter-panel { overflow: hidden; border-left: 1px solid var(--line); background: color-mix(in srgb, var(--surface-2) 45%, var(--bg)); padding: 16px 18px 40px; position: sticky; top: 0; height: 100vh; overflow-y: auto; opacity: 0; transition: opacity .2s; }
.chapter-form.panel-open .chapter-panel { opacity: 1; }
.chapter-form:not(.panel-open) .chapter-panel { padding: 0; border: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.panel-head h3 { font-size: 16px; }
.panel-group { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 4px; margin-bottom: 14px; }
.panel-group h4 { font-family: var(--sans); font-size: 11.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 600; margin-bottom: 10px; display: flex; align-items: center; gap: 6px; }
.panel-actions { display: flex; justify-content: space-between; gap: 8px; border-top: 1px solid var(--line); padding-top: 14px; margin-top: 10px; }
body.focus-mode .sidebar, body.focus-mode .chapter-panel, body.focus-mode .chapter-nav { display: none; }
body.focus-mode .chapter-form, body.focus-mode .chapter-form.panel-open { grid-template-columns: 1fr 0; }
body.focus-mode .writing-top { opacity: .15; transition: opacity .3s; }
body.focus-mode .writing-top:hover { opacity: 1; }
body.focus-mode .prose-editor .editor-toolbar { opacity: 0; transition: opacity .3s; }
body.focus-mode .prose-editor .editor-toolbar:hover { opacity: 1; }
.snap-layout { display: grid; grid-template-columns: 230px 1fr; gap: 18px; height: 56vh; }
.snap-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; border-right: 1px solid var(--line); padding-right: 10px; }
.snap-list label { display: flex; gap: 10px; align-items: flex-start; padding: 8px; border-radius: 7px; cursor: pointer; }
.snap-list label:hover { background: var(--surface-2); }
.snap-list input { accent-color: var(--accent); margin-top: 4px; }
.snap-list span { display: flex; flex-direction: column; font-size: 13px; }
.snap-list em { font-style: normal; color: var(--muted); font-size: 12px; }
.snap-preview { overflow-y: auto; font-size: 15px; padding-right: 8px; }

/* ---------- timeline ---------- */
.timeline-page { padding-left: 36px; padding-right: 36px; --lane-w: 170px; --col-w: 210px; --end-w: 120px; }
.tl-help { margin-left: auto; }
.tl-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-sm); scrollbar-width: thin; }
.tl-grid { display: grid; position: relative; min-width: max-content; }
.tl-corner, .tl-head { position: sticky; top: 0; z-index: 3; background: var(--surface); border-bottom: 1px solid var(--line); }
.tl-corner { left: 0; z-index: 4; border-right: 1px solid var(--line); }
.tl-head { padding: 12px 14px 10px; display: flex; flex-direction: column; gap: 1px; border-left: 1px dashed var(--line); }
.tl-head.end { border-left: 0; }
.tl-when { font-family: var(--serif); font-size: 14px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-ord { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tl-lane-label { position: sticky; left: 0; z-index: 2; display: flex; align-items: center; gap: 9px; padding: 14px 12px; background: var(--surface); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); font-size: 13.5px; font-weight: 500; }
.tl-lane-label .swatch { width: 10px; height: 10px; border-radius: 3px; background: var(--c); flex: none; }
.tl-lane-label .ln { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.tl-lane-label .icon-btn { opacity: 0; }
.tl-lane-label:hover .icon-btn { opacity: 1; }
.tl-cell { min-height: 92px; padding: 10px 8px; border-bottom: 1px solid var(--line); border-left: 1px dashed var(--line); display: flex; flex-direction: column; gap: 6px;
  background: linear-gradient(transparent calc(50% - .5px), color-mix(in srgb, var(--c) 25%, transparent) calc(50% - .5px), color-mix(in srgb, var(--c) 25%, transparent) calc(50% + .5px), transparent calc(50% + .5px)); justify-content: center; }
.tl-cell.end { border-left: 0; }
.tl-card { position: relative; background: var(--surface); border: 1px solid var(--line-2); border-left: 3px solid var(--c); border-radius: 8px; padding: 7px 10px; cursor: grab; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 2px; transition: box-shadow .15s, transform .15s; user-select: none; }
.tl-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.tl-card.ev { background: color-mix(in srgb, var(--c) 9%, var(--surface)); }
.tl-card.dragging { opacity: .35; }
.tl-kind { display: flex; align-items: center; gap: 5px; font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; overflow: hidden; }
.tl-kind .status-dot { margin-left: auto; }
.tl-title { font-family: var(--serif); font-size: 14px; line-height: 1.3; color: var(--ink); }
.tl-sub { font-size: 11.5px; color: var(--ink-2); }
.tl-indicator { position: absolute; pointer-events: none; z-index: 6; border-radius: 4px; transition: left .08s, top .08s, width .08s, height .08s; }
.tl-indicator.line { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.tl-indicator.box { border: 2px dashed var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.tl-card.flash { animation: flash 1.4s var(--ease); }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 40%, transparent); } 100% { box-shadow: var(--shadow-sm); } }
.tl-tray { margin-top: 22px; padding: 16px; border: 1px dashed var(--line-2); border-radius: 14px; transition: background .15s, border-color .15s; }
.tl-tray h3 { font-family: var(--sans); font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.tl-tray.empty-tray { padding: 12px 16px; }
.tl-tray.empty-tray h3 { margin: 0; font-weight: 500; color: var(--muted); }
.is-dragging .tl-tray { border-color: var(--accent); }
.tl-tray.tray-over { background: var(--accent-soft); }
.tray-cards { display: flex; flex-wrap: wrap; gap: 8px; }
.tray-cards .tl-card { width: 200px; }
.preview-box { background: var(--surface-2); padding: 10px 14px; border-radius: 8px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.sw input { position: absolute; opacity: 0; pointer-events: none; }
.sw span { display: block; width: 28px; height: 28px; border-radius: 50%; background: var(--c); cursor: pointer; border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line-2); transition: transform .12s; }
.sw input:checked + span { box-shadow: 0 0 0 2px var(--ink); transform: scale(1.06); }

/* ---------- graph ---------- */
.graph-page { display: flex; flex-direction: column; height: 100vh; padding: 28px 32px 16px; }
.graph-bar { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; margin-bottom: 16px; }
.graph-filters { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.type-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.type-toggle span { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 99px; font-size: 12px; cursor: pointer; border: 1px solid var(--line-2); color: var(--muted); }
.type-toggle input:checked + span { color: var(--c); background: color-mix(in srgb, var(--c) 12%, transparent); border-color: transparent; }
.graph-filters .check { margin: 0 6px; font-size: 12.5px; }
.graph-canvas { flex: 1; min-height: 320px; border: 1px solid var(--line); border-radius: 14px; background: radial-gradient(circle at 1px 1px, var(--line) 1px, transparent 0) 0 0 / 22px 22px, var(--surface); }
.graph-legend { margin: 10px 2px 0; display: flex; align-items: center; gap: 8px; }
.lg { display: inline-block; width: 22px; border-top: 1.5px solid var(--muted); }
.lg.dashed { border-top-style: dashed; margin-left: 10px; }

/* ---------- search ---------- */
.big-search { display: flex; align-items: center; gap: 10px; padding: 0 14px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px; margin-bottom: 22px; color: var(--muted); box-shadow: var(--shadow-sm); }
.big-search input { border: 0 !important; box-shadow: none !important; font-size: 16px; padding: 12px 0 !important; background: transparent !important; }
.results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.results a { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; color: var(--ink); }
.results a:hover { border-color: var(--line-2); box-shadow: var(--shadow-sm); color: var(--ink); }
.results .ticon { margin-top: 2px; }
.res-body { display: flex; flex-direction: column; min-width: 0; }
.res-title { font-family: var(--serif); font-size: 16px; }
.res-sub { font-size: 12px; color: var(--muted); }
.res-snip { font-size: 13.5px; color: var(--ink-2); margin-top: 6px; }

/* ---------- settings ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px; margin-bottom: 18px; box-shadow: var(--shadow-sm); }
.card h2 { font-size: 18px; margin-bottom: 6px; }
.card-head { display: flex; justify-content: space-between; align-items: center; }
.card.danger { border-color: color-mix(in srgb, var(--danger) 30%, var(--line)); }
.sl-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.sl-row { display: flex; align-items: center; gap: 8px; padding: 4px; border-radius: 8px; }
.sl-row:hover { background: var(--surface-2); }
.sl-row input[data-name] { flex: 0 0 34%; }
.sl-row input[data-desc] { flex: 1; color: var(--ink-2); }
.sl-row .icon-btn { opacity: .5; }
.sl-row:hover .icon-btn { opacity: 1; }
.sl-color { width: 22px; height: 22px; border-radius: 6px; border: 0; background: var(--c); cursor: pointer; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0 10px; }
.export-opt { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; text-align: left; padding: 16px; border: 1px solid var(--line-2); border-radius: 12px; background: var(--bg); cursor: pointer; transition: border-color .15s, background .15s; }
.export-opt:hover { border-color: var(--accent); background: var(--accent-soft); }
.export-opt .i { color: var(--accent); }
.export-opt span { font-size: 12.5px; color: var(--muted); }

/* ---------- modal ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 100; background: rgba(24, 20, 14, .38); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 20px; animation: fadein .15s; }
.modal-wrap.out { opacity: 0; transition: opacity .15s; }
@keyframes fadein { from { opacity: 0; } }
.modal { width: 100%; max-width: 480px; max-height: 90vh; display: flex; flex-direction: column; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); border: 1px solid var(--line); animation: pop .2s var(--ease); }
.modal.wide { max-width: 900px; }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px 6px; }
.modal header h2 { font-size: 19px; }
.modal-body { padding: 10px 20px 4px; overflow-y: auto; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px 18px; }
.modal footer .btn-danger-ghost { margin-right: auto; }
.type-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.type-opt input { position: absolute; opacity: 0; pointer-events: none; }
.type-opt span { display: inline-block; padding: 5px 11px; border-radius: 99px; font-size: 12.5px; border: 1px solid var(--line-2); cursor: pointer; transition: all .12s; }
.type-opt input:checked + span { background: color-mix(in srgb, var(--c) 15%, transparent); color: var(--c); border-color: color-mix(in srgb, var(--c) 50%, transparent); font-weight: 500; }
.type-opt input:focus-visible + span { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 13.5px; box-shadow: var(--shadow-lg); animation: pop .2s var(--ease); transition: opacity .3s, transform .3s; max-width: 90vw; }
.toast-error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transform: translateY(6px); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .entry-layout { grid-template-columns: 1fr; }
  .entry-side { position: static; }
  .chapter-form.panel-open { grid-template-columns: 1fr 290px; }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 50; transform: translateX(-100%); transition: transform .25s var(--ease); box-shadow: var(--shadow-lg); background: var(--surface); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.3); }
  .mobile-bar { display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 10; padding: 8px 10px; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); font-family: var(--serif); font-size: 15px; }
  .mobile-bar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .page { padding: 22px 18px 60px; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .two-col, .book-overview, .form-grid, .export-grid { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: auto; }
  .chapter-form.panel-open { grid-template-columns: 1fr; }
  .chapter-panel { position: fixed; inset: 0 0 0 auto; width: min(340px, 90vw); z-index: 30; box-shadow: var(--shadow-lg); background: var(--surface); }
  .chapter-form:not(.panel-open) .chapter-panel { display: none; }
  .writing-top { top: 49px; padding: 8px 12px; }
  .writing-top .crumbs { min-width: 0; white-space: nowrap; }
  .writing-top .crumbs a { overflow: hidden; text-overflow: ellipsis; max-width: 42vw; display: inline-block; }
  .writing-top .crumbs .sep, .writing-top .crumbs > span:not(.save-state), .wc em { display: none; }
  .manuscript { padding: 10px 18px 80px; }
  .chapter-title { font-size: 26px !important; }
  .prose-editor .editor-input { font-size: 17px; }
  .ch-meta .sl-chip, .ch-meta .muted { display: none; }
  .timeline-page { padding: 22px 12px; --lane-w: 110px; --col-w: 170px; --end-w: 70px; }
  .tl-help { display: none; }
  .field-row { grid-template-columns: 110px 1fr 24px; }
  .graph-page { padding: 16px 12px; height: calc(100vh - 49px); }
  .snap-layout { grid-template-columns: 1fr; height: auto; }
  .seg .tb span { display: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
