/* Quire — warm paper and ink, with a night mode. */
:root {
  --desk: #EFE8DA; --panel: #F6F0E4; --binder: #F3ECDF; --page: #FFFCF5; --card: #FFFCF5; --field: #FBF7EE;
  --ink: #2B2521; --ink2: #4A403A; --muted: #675C52; --rule: #DDD2C0; --rule2: #E9E0CF; --chip: #E9E0CF;
  --accent: #8A2E28; --accent-ink: #FFF8F0; --accent-text: #8A2E28; --accent-soft: #F1DFD6; --accent-soft-ink: #6E231F;
  --idea: #C9BBA3; --drafting: #C9902E; --revised: #5E7391; --done: #5B6B4E;
  --warn-bg: #FBF3E3; --warn-line: #EAD7B3; --warn-ink: #7A5317; --hl: #F4E2C9;
  --cork: #E6DBC6; --cork-dot: rgba(120, 90, 50, .10);
  --shadow: 0 18px 40px -24px rgba(70, 45, 20, .35); --shadow-card: 0 10px 20px -14px rgba(70, 45, 20, .55);
  --serif: Literata, Georgia, 'Times New Roman', serif; --display: Fraunces, Georgia, serif; --sans: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --page-size: 18px; --page-font: var(--serif);
  color-scheme: light;
}
[data-theme="night"] {
  --desk: #1E1A17; --panel: #25201C; --binder: #221D1A; --page: #2A2420; --card: #2C2622; --field: #2C2622;
  --ink: #EDE4D6; --ink2: #CFC4B4; --muted: #A89C8B; --rule: #3D3530; --rule2: #362F2A; --chip: #352E29;
  --accent: #B24A3F; --accent-ink: #FFF6EF; --accent-text: #E8A79B; --accent-soft: #4A2A25; --accent-soft-ink: #F3C6BD;
  --idea: #8F8474; --drafting: #D9A54A; --revised: #8EA3C4; --done: #8FA87F;
  --warn-bg: #3A3020; --warn-line: #5A4A2C; --warn-ink: #EBCB8B; --hl: #4A3A22;
  --cork: #2A2420; --cork-dot: rgba(255, 240, 220, .06);
  --shadow: 0 18px 40px -24px rgba(0, 0, 0, .8); --shadow-card: 0 10px 20px -14px rgba(0, 0, 0, .9);
  color-scheme: dark;
}
[data-font="garamond"] { --page-font: 'EB Garamond', Garamond, Georgia, serif; }
[data-font="sans"] { --page-font: var(--sans); }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--desk); color: var(--ink); font: 14px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-text); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }

/* ---------- buttons, fields, chips ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 14px; border: 1px solid var(--rule); border-radius: 8px; background: var(--field); white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--chip); }
.btn.small { min-height: 34px; padding: 0 10px; font-size: 13px; }
.btn.danger { color: #B3261E; }
[data-theme="night"] .btn.danger { color: #F2B8B5; }
.btn.icon { width: 40px; padding: 0; }
.btn:disabled { opacity: .5; cursor: default; }
.field { width: 100%; min-height: 40px; border: 1px solid var(--rule); border-radius: 8px; padding: 8px 12px; background: var(--field); }
textarea.field { resize: vertical; line-height: 1.5; }
.field:focus { border-color: var(--accent-text); outline: none; }
.label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin: 0 0 6px; }
.cap { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; background: var(--chip); color: var(--ink2); font-size: 12px; border: 0; white-space: nowrap; }
button.chip { min-height: 32px; }
.chip.on { background: var(--ink); color: var(--panel); font-weight: 600; }
.chip.accent { background: var(--accent-soft); color: var(--accent-soft-ink); font-weight: 600; }
.chip .x { opacity: .6; margin-left: 2px; }
.pill { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.st-idea { background: color-mix(in srgb, var(--idea) 30%, var(--page)); color: var(--ink2); }
.st-drafting { background: color-mix(in srgb, var(--drafting) 25%, var(--page)); color: color-mix(in srgb, var(--drafting) 55%, var(--ink)); }
.st-revised { background: color-mix(in srgb, var(--revised) 22%, var(--page)); color: color-mix(in srgb, var(--revised) 55%, var(--ink)); }
.st-done { background: color-mix(in srgb, var(--done) 22%, var(--page)); color: color-mix(in srgb, var(--done) 55%, var(--ink)); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--idea); }
.dot.drafting { background: var(--drafting); } .dot.revised { background: var(--revised); } .dot.done { background: var(--done); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 600; flex: none; background: var(--idea); color: #2B2521; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.meter { height: 6px; border-radius: 3px; background: var(--rule2); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.meter.good > i { background: var(--done); }
.empty { color: var(--muted); padding: 24px; text-align: center; }

/* ---------- app frame ---------- */
#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; padding: 10px 18px; border-bottom: 1px solid var(--rule); background: var(--panel); }
.brand { font: 600 24px/1 var(--display); color: var(--accent-text); letter-spacing: -.01em; }
.bookbtn { display: flex; align-items: center; gap: 6px; border: 0; background: none; padding: 6px 8px; border-radius: 8px; font: 17px var(--display); max-width: 260px; }
.bookbtn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bookbtn:hover { background: var(--chip); }
.views { display: flex; gap: 4px; background: var(--rule2); border-radius: 10px; padding: 4px; }
.views button { border: 0; background: none; padding: 7px 13px; border-radius: 7px; color: var(--ink2); white-space: nowrap; }
.views button[aria-current="page"] { background: var(--page); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(60, 40, 20, .12); }
.grow { flex: 1 1 0; }
.goal { white-space: nowrap; display: flex; align-items: center; gap: 10px; color: var(--ink2); font-size: 13px; border: 0; background: none; padding: 6px; border-radius: 8px; }
.goal:hover { background: var(--chip); }
.goal .meter { width: 100px; }
.timer { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 8px 0 12px; border: 1px solid var(--rule); border-radius: 8px; background: var(--field); }
.timer .t { font-variant-numeric: tabular-nums; font-weight: 600; }
.timer .w { font-size: 12px; color: var(--ink2); white-space: nowrap; }
.top > * { flex-shrink: 0; }
.top .grow { flex-shrink: 1; min-width: 0; }
.top .bookbtn { flex-shrink: 1; min-width: 0; }
.timer.running { border-color: var(--accent-text); }
.timer.done { background: var(--accent-soft); }
#view { flex: 1; display: flex; min-height: 0; min-width: 0; overflow: hidden; }
#view > * { min-width: 0; }
.wcol { flex: 1 1 0; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.wcol .desk { flex: 1; }
.tabs { display: none; }

/* ---------- write ---------- */
.write { flex: 1; display: flex; min-height: 0; min-width: 0; }
.binder { width: 270px; flex: none; border-right: 1px solid var(--rule); background: var(--binder); padding: 14px 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.binder .cap { padding: 4px 8px 6px; }
.b-ch { display: flex; align-items: center; gap: 6px; padding: 7px 6px; font: 600 15px var(--display); margin-top: 6px; border-radius: 6px; }
.b-ch .n { margin-left: auto; font: 12px var(--sans); color: var(--muted); }
.b-ch .tw { border: 0; background: none; padding: 2px; color: var(--accent-text); display: grid; }
.b-ch .tw svg { transition: transform .15s; }
.b-ch.shut .tw svg { transform: rotate(-90deg); }
.b-ch .more, .b-sc .more { opacity: 0; border: 0; background: none; padding: 4px; border-radius: 6px; color: var(--muted); display: grid; }
.b-ch:hover .more, .b-sc:hover .more, .b-sc.on .more { opacity: 1; }
.b-sc { display: flex; align-items: center; gap: 10px; padding: 7px 6px 7px 28px; border-radius: 6px; cursor: pointer; color: var(--ink2); min-height: 36px; border: 0; background: none; width: 100%; text-align: left; }
.b-sc:hover { background: color-mix(in srgb, var(--page) 60%, transparent); }
.b-sc.on { background: var(--page); box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; color: var(--ink); }
.b-sc .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.b-sc .n { font-size: 12px; color: var(--muted); font-weight: 400; }
.b-add { margin: 2px 0 4px 28px; border: 0; background: none; color: var(--muted); text-align: left; padding: 6px; border-radius: 6px; font-size: 13px; }
.b-add:hover { color: var(--accent-text); background: var(--chip); }
.drop-before { box-shadow: inset 0 2px 0 var(--accent) !important; }
.drop-into { background: var(--accent-soft) !important; }
.dragging { opacity: .4; }
.desk { flex: 1 1 0; min-width: 0; overflow-y: auto; display: flex; justify-content: center; padding: 34px 24px 80px; }
.page { width: 100%; max-width: 700px; background: var(--page); border: 1px solid var(--rule2); border-radius: 4px; box-shadow: 0 1px 0 var(--rule2), var(--shadow); padding: 52px 72px 90px; align-self: flex-start; min-height: 70vh; }
.crumb { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--accent-text); font-weight: 600; display: flex; gap: 10px; align-items: center; }
.crumb .save { margin-left: auto; letter-spacing: 0; text-transform: none; font-weight: 400; color: var(--muted); }
.scene-title { width: 100%; border: 0; background: none; font: 400 34px/1.15 var(--display); margin: 10px 0 26px; padding: 0; outline: none; }
.editor { font-family: var(--page-font); font-size: var(--page-size); line-height: 1.75; outline: none; min-height: 40vh; caret-color: var(--accent-text); overflow-wrap: break-word; }
.editor p { margin: 0 0 .9em; }
.editor p + p { text-indent: 1.6em; }
.editor hr { border: 0; text-align: center; margin: 1.2em 0; height: 1.4em; }
.editor hr::after { content: '* * *'; color: var(--muted); letter-spacing: .4em; }
.editor h3 { font: 600 1.05em var(--display); margin: 1.2em 0 .6em; }
.editor blockquote { margin: 0 2em .9em; font-style: italic; }
.editor:empty::before { content: 'Start writing…'; color: var(--muted); }
.fmt { display: flex; gap: 4px; margin: -12px 0 18px; flex-wrap: wrap; }
.fmt button { min-width: 34px; height: 32px; border: 1px solid transparent; background: none; border-radius: 6px; color: var(--ink2); }
.fmt button:hover { background: var(--chip); }
.focus .binder, .focus .inspector { display: none; }
.focus .top { opacity: .35; transition: opacity .2s; }
.focus .top:hover { opacity: 1; }
.focus .page { box-shadow: none; border-color: transparent; background: transparent; }
.inspector { width: 330px; flex: none; border-left: 1px solid var(--rule); background: var(--panel); padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.inspector section { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1 1 0; min-width: 0; }
.syn { font-family: var(--serif); font-size: 14px; }
.who { display: flex; flex-direction: column; gap: 6px; }
.who-item { display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 4px; border-radius: 8px; text-align: left; width: 100%; }
.who-item:hover { background: var(--chip); }
.who-item .x { margin-left: auto; opacity: 0; border: 0; background: none; color: var(--muted); padding: 4px; display: grid; }
.who-item:hover .x { opacity: 1; }

/* ---------- assistant ---------- */
.assist { display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--rule2); border-radius: 10px; min-height: 320px; overflow: hidden; }
.assist-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--rule2); }
.assist-head .s { margin-left: auto; font-size: 12px; color: var(--muted); }
.assist-acts { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px 0; }
.assist-acts .btn { min-height: 30px; padding: 0 9px; font-size: 12.5px; border-radius: 999px; }
.assist-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; font-size: 13px; line-height: 1.55; max-height: 460px; }
.msg { border-radius: 8px; padding: 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me { background: var(--chip); align-self: flex-end; max-width: 90%; }
.msg.ai { background: var(--warn-bg); border: 1px solid var(--warn-line); }
.msg.err { background: var(--accent-soft); color: var(--accent-soft-ink); }
.msg .k { display: block; font-weight: 600; color: var(--warn-ink); margin-bottom: 4px; white-space: normal; }
.msg .acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; white-space: normal; }
.assist-in { display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--rule2); }
.assist-in textarea { flex: 1; min-height: 40px; max-height: 140px; resize: none; }

/* ---------- corkboard ---------- */
.board { flex: 1; overflow-y: auto; padding: 26px 32px 60px; background: var(--cork); background-image: radial-gradient(var(--cork-dot) 1px, transparent 1.4px); background-size: 14px 14px; display: flex; flex-direction: column; gap: 28px; }
.board-ch h2 { margin: 0; font: 600 20px var(--display); }
.board-ch .head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.board-ch .meta { color: var(--ink2); font-size: 13px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; min-height: 60px; border-radius: 8px; }
.card { background: var(--card); border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; display: flex; flex-direction: column; min-height: 170px; box-shadow: var(--shadow-card); cursor: grab; text-align: left; padding: 0; transition: transform .12s; }
.card:nth-child(3n+1) { transform: rotate(-.5deg); } .card:nth-child(3n+2) { transform: rotate(.4deg); }
.card:hover { transform: rotate(0) translateY(-2px); }
.card .bar { height: 6px; background: var(--idea); }
.card .bar.drafting { background: var(--drafting); } .card .bar.revised { background: var(--revised); } .card .bar.done { background: var(--done); }
.card .in { padding: 14px 16px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card .tt { font: 600 17px/1.25 var(--display); display: flex; gap: 8px; align-items: flex-start; }
.card .tt span { flex: 1; }
.card .more { border: 0; background: none; color: var(--muted); padding: 2px; border-radius: 6px; display: grid; }
.card p { margin: 0; font: 14px/1.5 var(--serif); color: var(--ink2); display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.card .ft { margin-top: auto; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink2); }
.card .ft .w { margin-left: auto; }
.card.add { border: 1.5px dashed var(--rule); background: transparent; box-shadow: none; align-items: center; justify-content: center; color: var(--ink2); transform: none; cursor: pointer; }

/* ---------- outline ---------- */
.sheet { flex: 1; overflow-y: auto; }
.sheet-in { padding: 26px 32px 60px; max-width: 1280px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat { background: var(--card); border: 1px solid var(--rule2); border-radius: 10px; padding: 16px; text-align: left; display: flex; flex-direction: column; gap: 2px; }
button.stat:hover { border-color: var(--muted); }
.stat .k { font-size: 12px; color: var(--ink2); }
.stat .v { font: 30px/1.2 var(--display); }
.stat .meter { margin-top: 8px; }
.spark { display: flex; align-items: flex-end; gap: 2px; height: 28px; margin-top: 8px; }
.spark i { flex: 1; background: var(--rule); border-radius: 1px; min-height: 2px; }
.spark i.hit { background: var(--done); }
.tablebox { background: var(--card); border: 1px solid var(--rule2); border-radius: 10px; overflow-x: auto; }
table.ol { width: 100%; border-collapse: collapse; min-width: 900px; }
.ol th { text-align: left; font-size: 12px; color: var(--ink2); font-weight: 600; padding: 12px 8px; border-bottom: 1px solid var(--rule2); }
.ol td { padding: 4px 8px; border-bottom: 1px solid var(--rule2); vertical-align: middle; }
.ol tr.ch td { background: var(--panel); }
.ol input, .ol select { width: 100%; border: 1px solid transparent; background: none; padding: 7px 8px; border-radius: 6px; min-height: 36px; }
.ol input:hover, .ol select:hover { border-color: var(--rule); }
.ol input:focus, .ol select:focus { border-color: var(--accent-text); background: var(--field); outline: none; }
.ol .chname { font: 600 15px var(--display); }
.ol .syn input { font-family: var(--serif); }
.ol .w { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--ink2); padding-right: 16px; }
.ol .w input { width: 70px; text-align: right; display: inline-block; }
.ol .open { border: 0; background: none; color: var(--accent-text); padding: 6px; border-radius: 6px; display: grid; }

/* ---------- story bible ---------- */
.bible { flex: 1; display: flex; min-height: 0; }
.blist { width: 300px; flex: none; border-right: 1px solid var(--rule); background: var(--binder); padding: 14px 12px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.blist .kinds { display: flex; gap: 6px; flex-wrap: wrap; }
.bitem { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; border: 0; background: none; width: 100%; text-align: left; }
.bitem:hover { background: color-mix(in srgb, var(--page) 60%, transparent); }
.bitem.on { background: var(--page); box-shadow: inset 3px 0 0 var(--accent); }
.bitem .nm { font-weight: 600; display: block; }
.bitem .rl { font-size: 12px; color: var(--ink2); display: block; }
.bdetail { flex: 1; min-width: 0; overflow-y: auto; padding: 30px 40px 60px; display: flex; flex-wrap: wrap; gap: 26px; align-content: flex-start; }
.entry { flex: 2 1 460px; min-width: 0; background: var(--page); border: 1px solid var(--rule2); border-radius: 6px; padding: 30px 34px; }
.entry .hd { display: flex; gap: 20px; align-items: center; }
.portrait { width: 96px; height: 96px; border-radius: 8px; background: var(--rule2); display: grid; place-items: center; color: var(--muted); font-size: 12px; text-align: center; flex: none; overflow: hidden; border: 0; padding: 0; }
.portrait img { width: 100%; height: 100%; object-fit: cover; }
.entry .nm { width: 100%; border: 0; background: none; font: 400 32px var(--display); padding: 0; outline: none; }
.entry .kind { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--accent-text); font-weight: 600; display: flex; gap: 8px; align-items: center; }
.entry .kind select { border: 0; background: none; color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit; padding: 0; }
.entry .role { border: 0; background: none; color: var(--ink2); padding: 0; width: 100%; outline: none; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 22px; margin: 22px 0; padding: 14px 0; border-top: 1px solid var(--rule2); border-bottom: 1px solid var(--rule2); }
.fact { display: flex; flex-direction: column; position: relative; }
.fact input { border: 0; background: none; padding: 2px 0; outline: none; }
.fact .fk { font-size: 12px; color: var(--ink2); }
.fact .fv { font-family: var(--serif); }
.fact .x { position: absolute; right: 0; top: 0; border: 0; background: none; color: var(--muted); opacity: 0; padding: 2px; display: grid; }
.fact:hover .x { opacity: 1; }
.entry .body { width: 100%; border: 0; background: none; font: 16px/1.7 var(--serif); resize: none; outline: none; min-height: 200px; padding: 0; }
.swatches { display: flex; gap: 6px; }
.swatches button { width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; padding: 0; }
.swatches button.on { border-color: var(--ink); }
.side { flex: 1 1 280px; display: flex; flex-direction: column; gap: 16px; }
.box { background: var(--card); border: 1px solid var(--rule2); border-radius: 10px; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.box .cap { margin-bottom: 2px; }
.box a, .linkbtn { text-decoration: none; color: var(--accent-text); border: 0; background: none; padding: 2px 0; text-align: left; }
.minis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.mini { aspect-ratio: 1; border-radius: 6px; background: var(--rule2); display: grid; place-items: center; font-size: 12px; color: var(--ink2); overflow: hidden; border: 0; padding: 4px; text-align: center; }
.mini img { width: 100%; height: 100%; object-fit: cover; }
.rgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; width: 100%; }
.ritem { background: var(--card); border: 1px solid var(--rule2); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; text-align: left; padding: 0; }
.ritem .pv { aspect-ratio: 4/3; background: var(--rule2); display: grid; place-items: center; color: var(--ink2); overflow: hidden; }
.ritem .pv img { width: 100%; height: 100%; object-fit: cover; }
.ritem .tx { padding: 10px 12px; }
.ritem .tx b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ritem .tx span { font-size: 12px; color: var(--ink2); }
.viewer { width: 100%; max-height: 70vh; border: 0; border-radius: 6px; background: var(--rule2); }
img.viewer { object-fit: contain; }
iframe.viewer { height: 70vh; }

/* ---------- notes ---------- */
.notes { flex: 1; overflow-y: auto; }
.notes-in { max-width: 1100px; margin: 0 auto; padding: 24px 28px 80px; display: flex; flex-direction: column; gap: 14px; }
.capture { background: var(--card); border: 1px solid var(--rule); border-radius: 14px; padding: 14px; box-shadow: var(--shadow-card); }
.capture textarea { display: block; width: 100%; border: 0; background: transparent; resize: none; font: 16px/1.5 var(--serif); outline: none; min-height: 72px; }
.capture .row { flex-wrap: wrap; margin-top: 8px; }
.capture .row > * { flex: none; }
.capture .att { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.round { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--rule); background: var(--panel); display: grid; place-items: center; color: var(--accent-text); padding: 0; }
.round.rec { background: var(--accent); color: var(--accent-ink); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .7; } }
.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; align-items: center; }
.filters .field { max-width: 240px; min-height: 36px; margin-left: auto; flex: none; }
.ngrid { columns: 3 260px; column-gap: 14px; }
.note { break-inside: avoid; margin: 0 0 14px; background: var(--card); border: 1px solid var(--rule2); border-radius: 12px; padding: 12px 14px; display: block; width: 100%; text-align: left; }
.note.pin { border-color: var(--drafting); }
.note p { margin: 0; font: 15px/1.5 var(--serif); white-space: pre-wrap; overflow-wrap: anywhere; }
.note img { width: 100%; border-radius: 8px; margin-top: 8px; display: block; }
.note audio { width: 100%; margin-top: 8px; }
.note .ft { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; font-size: 12px; }
.note .ft .when { margin-left: auto; color: var(--muted); }

/* ---------- popovers, dialogs, toast ---------- */
.pop { position: fixed; z-index: 60; min-width: 220px; max-width: min(340px, calc(100vw - 24px)); max-height: 70vh; overflow-y: auto; background: var(--page); border: 1px solid var(--rule); border-radius: 10px; box-shadow: 0 20px 50px -20px rgba(40, 25, 10, .5); padding: 6px; }
.pop button.it { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; padding: 10px; border-radius: 6px; text-align: left; min-height: 40px; }
.pop button.it:hover, .pop button.it:focus-visible { background: var(--chip); }
.pop .sep { height: 1px; background: var(--rule2); margin: 4px 0; }
.pop .hd { padding: 8px 10px 4px; }
.pop .chk { margin-left: auto; color: var(--accent-text); }
dialog { border: 1px solid var(--rule); border-radius: 14px; background: var(--page); color: var(--ink); padding: 0; width: min(520px, calc(100vw - 24px)); box-shadow: 0 30px 80px -30px rgba(40, 25, 10, .6); }
dialog::backdrop { background: rgba(30, 20, 10, .35); }
dialog form, dialog .dl { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
dialog h2 { margin: 0; font: 600 20px var(--display); }
dialog .acts { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
dialog.wide { width: min(900px, calc(100vw - 24px)); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; transition: .2s; background: var(--ink); color: var(--panel); padding: 10px 16px; border-radius: 10px; z-index: 80; pointer-events: none; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- sign in ---------- */
.login { flex: 1; overflow-y: auto; display: grid; place-items: center; padding: 24px; }
.login form { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; background: var(--page); border: 1px solid var(--rule2); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login .brand { font-size: 40px; text-align: center; }
.login p { margin: 0; color: var(--ink2); text-align: center; }
.login .err { color: #B3261E; min-height: 1.2em; text-align: center; }

/* ---------- smaller desktops ---------- */
@media (max-width: 1360px) { .goal .meter { display: none; } }
@media (max-width: 1280px) { .inspector { width: 290px; } .binder { width: 240px; } .page { padding: 44px 48px 80px; } .goal .meter { display: none; } }
@media (max-width: 1100px) and (min-width: 821px) { .write:not(.show-insp) .inspector { display: none; } .views button { padding: 7px 10px; } }

/* ---------- phone ---------- */
@media (max-width: 820px) {
  body { font-size: 15px; }
  #app { height: 100dvh; }
  .top { padding: 10px 12px; gap: 8px; padding-top: max(10px, env(safe-area-inset-top)); }
  .top .views, .top .goal, .top .desk-only { display: none; }
  .brand { font-size: 22px; }
  .bookbtn { font-size: 14px; margin-left: auto; max-width: 52vw; }
  #view { overflow: hidden; }
  .tabs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border-top: 1px solid var(--rule); background: var(--field); padding: 6px 2px calc(8px + env(safe-area-inset-bottom)); flex: none; }
  .tabs button { border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 2px; color: var(--ink2); font-size: 11.5px; min-height: 50px; }
  .tabs button[aria-current="page"] { color: var(--accent-text); font-weight: 600; }
  .tabs svg.i { width: 22px; height: 22px; }
  .binder { position: fixed; inset: 0 auto 0 0; width: min(86vw, 340px); z-index: 40; transform: translateX(-105%); transition: transform .2s; box-shadow: 20px 0 50px -20px rgba(0, 0, 0, .4); padding-top: max(14px, env(safe-area-inset-top)); }
  .write.show-binder .binder { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(30, 20, 10, .35); z-index: 35; }
  .inspector { position: fixed; left: 0; right: 0; bottom: 0; width: auto; max-height: 80dvh; z-index: 40; border: 0; border-top: 1px solid var(--rule); border-radius: 16px 16px 0 0; transform: translateY(105%); transition: transform .2s; box-shadow: 0 -20px 50px -20px rgba(0, 0, 0, .4); padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .write.show-insp .inspector { transform: none; }
  .inspector .assist { display: none; }
  .desk { padding: 0; display: block; }
  .page { border: 0; border-radius: 0; box-shadow: none; padding: 14px 20px 120px; min-height: 100%; max-width: none; }
  .scene-title { font-size: 26px; margin: 4px 0 14px; }
  .editor { font-size: calc(var(--page-size) - 1px); }
  .fmt { margin: -4px 0 10px; }
  .phonebar { display: flex; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--rule); background: var(--panel); overflow-x: auto; }
  .phonebar .btn { flex: none; }
  .wcol { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
  .wcol .desk { flex: 1; overflow-y: auto; }
  .board { padding: 16px 14px 40px; }
  .cards { grid-template-columns: 1fr; }
  .card { min-height: 0; transform: none !important; cursor: pointer; }
  .sheet-in { padding: 16px 12px 40px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat .v { font-size: 24px; }
  .bible { flex-direction: column; overflow-y: auto; }
  .blist { width: auto; border: 0; background: none; padding: 14px 16px; overflow: visible; }
  .bible.has-detail .blist { display: none; }
  .bible:not(.has-detail) .bdetail { display: none; }
  .bdetail { padding: 12px 14px 40px; overflow: visible; }
  .entry { padding: 20px; }
  .facts { grid-template-columns: 1fr; }
  .notes-in { padding: 14px 14px 40px; }
  .ngrid { columns: 1; }
  .filters .field { max-width: none; flex: 1 1 140px; margin-left: 0; }
  .assist.full { border: 0; border-radius: 0; flex: 1; min-height: 0; background: var(--panel); }
  .assist.full .assist-log { max-height: none; }
  .toast { bottom: calc(90px + env(safe-area-inset-bottom)); }
}
@media (min-width: 821px) { .phone-only { display: none !important; } }
.phonebar .btn[aria-pressed="true"] { background: var(--ink); color: var(--panel); border-color: var(--ink); }
