:root {
    --bg: #0d0f0e;
    --sidebar: #111412;
    --surface: #161a17;
    --surface-2: #1b201c;
    --surface-3: #222822;
    --ink: #f1f1e9;
    --soft: #b8bdb2;
    --muted: #727a70;
    --line: #29302a;
    --line-bright: #364137;
    --accent: #cbe86b;
    --accent-ink: #17200e;
    --coral: #ef826b;
    --blue: #83b9dc;
    --scrollbar-track: #161a17;
    --scrollbar-thumb: #52613e;
    --scrollbar-thumb-hover: #cbe86b;
    --serif: 'Cormorant Garamond', Georgia, serif;
    --sans: 'Inter', system-ui, sans-serif;
    --typewriter: 'SFMono-Regular', 'Cascadia Code', 'Roboto Mono', Consolas, 'Liberation Mono', monospace;
    --shadow: 0 22px 60px rgba(0,0,0,.26);
}

* { box-sizing: border-box; scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track); scrollbar-width: thin; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: var(--scrollbar-track); }
*::-webkit-scrollbar-thumb { border: 2px solid var(--scrollbar-track); border-radius: 0; background: var(--scrollbar-thumb); }
*::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }
*::-webkit-scrollbar-corner { background: var(--scrollbar-track); }
html, body { min-height: 100%; margin: 0; background: var(--bg); color: var(--ink); }
body { font: 13px var(--sans); letter-spacing: -.01em; overflow-x: clip; }
button, input, textarea { font: inherit; }
button { border: 0; cursor: pointer; appearance: none; }
a { color: inherit; text-decoration: none; }
h1, h2, p { margin: 0; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 238px; flex: 0 0 238px; background: var(--sidebar); border-right: 1px solid var(--line); padding: 26px 14px 18px; display: flex; flex-direction: column; transition: width .2s ease, flex-basis .2s ease, padding .2s ease; }
.brand-lockup { display: flex; align-items: center; gap: 11px; padding: 0 12px 46px; }
.brand-mark { width: 29px; height: 29px; display: grid; place-items: center; border: 1px solid var(--accent); color: var(--accent); overflow: hidden; font-size: 0; background: url('/img/authorroom-mark.png') center / cover no-repeat; transform: rotate(-7deg); }
.brand-mark img { display: block; width: 100%; height: 100%; object-fit: cover; transform: rotate(7deg) scale(1.24); }
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -.07em; }
.brand-name span { color: var(--soft); font-weight: 400; }
.brand-subtitle { color: var(--muted); font-size: 9px; margin-top: 3px; }
.sidebar-label { color: #697269; font-size: 9px; font-weight: 700; letter-spacing: .15em; text-transform: uppercase; padding: 0 12px 11px; }
.main-nav, .book-list { display: grid; gap: 2px; }
.main-nav { width: 100%; margin-bottom: 34px; }
.sidebar-collapse { display: flex; align-items: center; gap: 11px; width: 100%; min-height: 34px; margin: -31px 0 25px; padding: 0 12px; border: 1px solid transparent; background: transparent; color: var(--muted); font-size: 10px; text-align: left; }
.sidebar-collapse:hover { border-color: var(--line); background: var(--surface-2); color: var(--ink); }
.sidebar-collapse i { font-size: 16px; }
.nav-item { display: flex; align-items: center; gap: 11px; width: 100%; min-height: 38px; box-sizing: border-box; padding: 0 12px; background: transparent; color: #8c978c; border-left: 2px solid transparent; }
.nav-item:hover { color: var(--ink); background: rgba(255,255,255,.03); }
.nav-item.active { color: var(--ink); border-left-color: var(--accent); background: rgba(203,232,107,.06); }
.nav-item i { font-size: 17px; }
.books-label { display: flex; justify-content: space-between; align-items: center; }
.text-button { background: none; color: var(--muted); padding: 0 3px; font-size: 16px; }
.book-link { position: relative; display: flex; align-items: center; gap: 10px; width: 100%; min-width: 0; padding: 10px 12px; background: none; color: #9aa399; text-align: left; border-left: 2px solid transparent; }
.book-link:hover, .book-link.selected { color: var(--ink); background: rgba(255,255,255,.035); border-left-color: var(--accent); }
.book-link span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-link i { margin-left: auto; color: var(--muted); opacity: 0; }
.book-link:hover i, .book-link.selected i { opacity: 1; }
.book-dot { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; }
.coral { background: var(--coral); } .amber { background: #d8b45d; } .violet { background: #aa8fe9; }
.sidebar-bottom { margin-top: auto; }
.sidebar-bottom > .nav-item { margin-bottom: 16px; }
.profile-card { display: flex; align-items: center; gap: 9px; padding: 16px 8px 0; border-top: 1px solid var(--line); }
.avatar, .mini-avatar { display: grid; place-items: center; border-radius: 50%; background: #806f63; color: #f9efe5; font-weight: 700; }
.avatar { width: 29px; height: 29px; font-size: 9px; }
.profile-copy { display: grid; gap: 3px; min-width: 0; }
.profile-copy strong, .profile-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-copy strong { font-size: 11px; }
.profile-copy span { color: var(--muted); font-size: 9px; }
.profile-card form { margin-left: auto; }
.profile-menu { padding: 0; background: none; color: var(--muted); font-size: 16px; }

.main-content { flex: 1; min-width: 0; }
.sidebar.collapsed { width: 64px; flex-basis: 64px; padding-right: 8px; padding-left: 8px; }
.sidebar.collapsed .brand-lockup { justify-content: center; padding-right: 0; padding-left: 0; }
.sidebar.collapsed .brand-lockup > div:last-child, .sidebar.collapsed .sidebar-collapse span, .sidebar.collapsed .sidebar-label > span, .sidebar.collapsed .nav-item span, .sidebar.collapsed .book-link span:nth-child(2), .sidebar.collapsed .profile-copy { display: none; }
.sidebar.collapsed .sidebar-collapse { justify-content: center; margin-right: 0; margin-left: 0; padding-right: 0; padding-left: 0; }
.sidebar.collapsed .main-nav, .sidebar.collapsed .book-list { width: 100%; }
.sidebar.collapsed .nav-item, .sidebar.collapsed .book-link { justify-content: center; padding-right: 0; padding-left: 0; }
.sidebar.collapsed .book-link i { display: none; }
.sidebar.collapsed .book-link[data-tooltip]::after { content: attr(data-tooltip); position: absolute; left: calc(100% + 10px); top: 50%; z-index: 20; max-width: 240px; padding: 8px 10px; border: 1px solid var(--line-bright); background: var(--surface-3); color: var(--ink); box-shadow: var(--shadow); font: 11px var(--sans); line-height: 1.2; white-space: nowrap; pointer-events: none; opacity: 0; transform: translate(-4px, -50%); transition: opacity .12s ease, transform .12s ease; }
.sidebar.collapsed .book-link[data-tooltip]:hover::after, .sidebar.collapsed .book-link[data-tooltip]:focus-visible::after { opacity: 1; transform: translate(0, -50%); }
.sidebar.collapsed .books-label { justify-content: center; padding-right: 0; padding-left: 0; font-size: 0; }
.sidebar.collapsed .books-label .text-button { font-size: 16px; }
.sidebar.collapsed .text-button { display: grid; place-items: center; }
.sidebar.collapsed .profile-card { justify-content: center; padding-right: 0; padding-left: 0; }
.sidebar.collapsed .profile-card form { margin-left: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; height: 68px; padding: 0 4vw; border-bottom: 1px solid var(--line); }
.breadcrumbs { display: flex; align-items: center; gap: 9px; min-width: 0; color: var(--muted); font-size: 11px; }
.breadcrumbs strong { overflow: hidden; color: var(--soft); font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.breadcrumbs i { font-size: 14px; }
.topbar-actions { display: flex; align-items: center; gap: 7px; min-width: 0; }
.icon-button { display: grid; place-items: center; width: 32px; height: 32px; background: transparent; color: var(--muted); border-radius: 3px; }
.icon-button:hover { color: var(--ink); background: var(--surface-2); }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 34px; padding: 0 13px; border-radius: 3px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.primary-button { background: var(--accent); color: var(--accent-ink); }
.primary-button:hover { background: #e2fb8c; }
.ghost-button { background: transparent; border: 1px solid var(--line-bright); color: var(--soft); }
.ghost-button:hover { background: var(--surface-2); color: var(--ink); }
.mobile-menu { display: none; background: none; color: var(--soft); font-size: 20px; }

.workspace-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; max-width: 1420px; padding: 49px 4vw 38px; }
.eyebrow { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: .15em; text-transform: uppercase; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
h1 { max-width: 820px; margin-top: 9px; font: 500 clamp(34px, 4vw, 58px)/.95 var(--serif); letter-spacing: -.055em; overflow-wrap: anywhere; }
h2 { font: 500 26px/1 var(--serif); letter-spacing: -.03em; }
.book-meta { margin-top: 12px; color: var(--muted); font-size: 11px; }
.meta-separator { padding: 0 7px; color: var(--line-bright); }

.content-grid { display: grid; grid-template-columns: 228px minmax(480px, 1fr) 286px; width: calc(100% - 8vw); max-width: 1420px; min-height: 680px; margin: 0 4vw 40px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.chapter-panel, .insight-panel { min-width: 0; padding: 26px 18px; background: transparent; }
.chapter-panel { border-right: 1px solid var(--line); }
.insight-panel { border-left: 1px solid var(--line); }
.panel-heading, .insight-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.chapter-total, .note-count { margin-left: 4px; color: var(--muted); font: 400 12px var(--sans); vertical-align: middle; }
.small { width: 27px; min-height: 27px; padding: 0; }
.progress-track { height: 2px; margin-top: 25px; background: var(--line); }
.progress-track span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .25s ease; }
.progress-copy { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; color: var(--muted); font-size: 9px; }
.chapter-list { display: grid; margin-top: 20px; }
.chapter-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 54px; padding: 8px 3px; background: transparent; border-top: 1px solid var(--line); color: #929d92; text-align: left; }
.chapter-item:last-child { border-bottom: 1px solid var(--line); }
.chapter-item:hover, .chapter-item.active { color: var(--ink); background: rgba(255,255,255,.025); }
.chapter-item.active { box-shadow: inset 2px 0 var(--accent); }
.chapter-number { width: 22px; color: var(--muted); font-size: 9px; }
.chapter-copy { display: grid; min-width: 0; gap: 4px; }
.chapter-copy strong { overflow: hidden; font-size: 11px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.chapter-copy small, .chapter-status { color: var(--muted); font-size: 9px; }
.chapter-item > i { margin-left: auto; color: var(--accent); }
.chapter-status { margin-left: auto; }
.notes-link, .all-notes-button { display: flex; align-items: center; gap: 9px; width: 100%; margin-top: 16px; padding: 0 2px; background: none; color: var(--soft); font-size: 11px; text-align: left; }
.notes-link i:last-child, .all-notes-button i { margin-left: auto; color: var(--muted); }

.editor-panel { display: flex; flex-direction: column; min-width: 0; background: #181d19; }
.editor-toolbar { display: flex; align-items: center; justify-content: space-between; min-height: 55px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.toolbar-group, .toolbar-right { display: flex; align-items: center; gap: 2px; min-width: 0; }.toolbar-group { position: relative; }
.toolbar-group button { display: grid; place-items: center; min-width: 28px; height: 28px; background: transparent; color: var(--muted); border-radius: 3px; }
.toolbar-group button:hover { background: var(--surface-3); color: var(--ink); }
.toolbar-select { display: flex !important; align-items: center; gap: 5px; width: auto !important; padding: 0 7px; font-size: 10px !important; }
.toolbar-divider { width: 1px; height: 18px; margin: 0 7px; background: var(--line-bright); }
.save-state { margin-right: 12px; color: var(--muted); font-size: 10px; }
.save-dot { display: inline-block; width: 5px; height: 5px; margin-right: 5px; border-radius: 50%; background: var(--accent); }
.save-state.saved { color: var(--muted); }.save-state.saving { color: var(--accent); }.save-state.saving .save-dot { animation: pulse 1s ease-in-out infinite; }.save-state.unsaved { color: #e4bd6b; }.save-state.unsaved .save-dot { background: #e4bd6b; }
.save-button { min-height: 28px; padding: 0 9px; border: 1px solid var(--line-bright); background: transparent; color: var(--soft); font-size: 10px; }.save-button:hover { border-color: var(--accent); color: var(--accent); }.save-button:disabled { cursor: wait; opacity: .8; }@keyframes pulse { 50% { opacity: .35; } }
.format-menu { position: absolute; top: calc(100% + 7px); left: 0; z-index: 10; display: none; min-width: 150px; padding: 5px; border: 1px solid var(--line-bright); background: var(--surface); box-shadow: var(--shadow); }
.format-menu.open { display: grid; }
.format-menu button { display: block; width: 100%; padding: 9px 10px; background: transparent; color: var(--soft); font: 11px var(--sans); text-align: left; }
.format-menu button:hover { background: var(--surface-2); color: var(--ink); }
.writing-surface { flex: 1; min-height: 580px; padding: 68px clamp(34px, 8vw, 120px) 110px; outline: 0; color: #d6d8d0; font: 16px/1.85 var(--typewriter); font-style: normal; overflow-wrap: anywhere; scroll-padding-block: 32px 64px; }
.writing-surface h2 { margin: 7px 0 25px; color: var(--ink); font: 500 41px/1 var(--serif); }
.writing-surface p { margin: 0 0 17px; }
.writing-surface .chapter-kicker { margin: 0; color: var(--accent); font: 700 10px var(--sans); letter-spacing: .18em; }
.writing-surface .opening-line { color: #ebebe2; font-style: normal; }
.editor-footer { display: flex; align-items: center; justify-content: space-between; min-height: 43px; padding: 0 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
kbd { padding: 2px 4px; border: 1px solid var(--line-bright); border-radius: 3px; background: var(--surface-3); font-size: 9px; }

.context-tabs { display: flex; gap: 3px; margin: -26px -18px 25px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.context-tab { padding: 15px 7px 12px; background: none; border-bottom: 2px solid transparent; color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.context-tab.active { border-bottom-color: var(--accent); color: var(--ink); }
.context-view { display: none; }
.context-view.active { display: block; }
.editor-context-tab[data-context="ai"] { display: none; }
.editor-layout:not(.context-open) .insight-panel { display: flex; flex-direction: column; }
.editor-layout:not(.context-open) #context-ai { display: block; order: -1; }
.editor-layout:not(.context-open) #context-ai + #context-plan { display: none; }
.notes-divider { margin: 25px 0; border-top: 1px solid var(--line); }
.notes-stack { display: grid; gap: 14px; margin-top: 25px; }
.ai-status { margin-top: 6px; color: var(--accent); font-size: 9px; }
.ai-controls { display: grid; gap: 10px; margin-top: 22px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.ai-controls label { display: grid; gap: 7px; color: var(--muted); font-size: 9px; letter-spacing: .08em; text-transform: uppercase; }
.ai-controls select { height: 34px; padding: 0 9px; border: 1px solid var(--line-bright); background: var(--surface-2); color: var(--soft); font: 11px var(--sans); }
.ai-results { display: grid; gap: 12px; margin-top: 18px; }
.ai-card { padding: 12px; border: 1px solid var(--line); border-left: 2px solid var(--blue); background: var(--surface-2); }
.ai-card.ai-spelling, .ai-card.ai-grammar { border-left-color: #d4b45b; }
.ai-card.ai-story { border-left-color: #aa8fe9; }
.ai-card.ai-next { border-left-color: var(--accent); background: rgba(203,232,107,.055); }
.ai-card-top { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 8px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.ai-card p { margin: 10px 0 0; color: var(--soft); font: 13px/1.45 var(--serif); }
.ai-example { display: grid; gap: 5px; margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--line); }
.ai-example small { color: var(--muted); font-size: 8px; text-transform: uppercase; }
.ai-example span { color: var(--ink); font: 12px/1.4 var(--typewriter); }
.ai-empty { display: grid; justify-items: start; gap: 8px; margin-top: 26px; color: var(--muted); }
.ai-empty i { color: var(--accent); font-size: 22px; }
.ai-empty strong { color: var(--soft); font: 700 13px var(--sans); }
.ai-empty span { font-size: 11px; line-height: 1.5; }
.ai-error i { color: var(--coral); }
.note-card { padding: 13px 0 14px; border-bottom: 1px solid var(--line); background: transparent; }
.note-card p { margin: 10px 0 13px; color: #d3d5ce; font: 16px/1.35 var(--serif); }
.note-card.yellow { border-left: 2px solid #d4b45b; padding-left: 12px; }.note-card.blue { border-left: 2px solid var(--blue); padding-left: 12px; }.note-card.purple { border-left: 2px solid #aa8fe9; padding-left: 12px; }
.note-top { display: flex; justify-content: space-between; color: var(--muted); font-size: 8px; font-weight: 700; letter-spacing: .12em; }
.note-top button { background: none; color: var(--muted); }
.note-author { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 9px; }
.mini-avatar { width: 17px; height: 17px; font-size: 7px; }
.plan-mode { display: block; overflow: visible; }
.plan-mode .chapter-panel, .plan-mode .editor-panel { display: none; }
.plan-mode .insight-panel { width: 100%; border: 0; background: transparent; }
.plan-mode .context-tabs { margin: 0 0 24px; padding: 0; }
.plan-board { --plan-grid-width: 180px; --plan-grid-height: 150px; --plan-grid-columns: 7; --plan-grid-rows: 4; position: relative; box-sizing: border-box; width: 100%; margin-top: 20px; padding-right: 52px; padding-bottom: 52px; overflow-x: auto; overflow-y: visible; }
.plan-board { scrollbar-color: #52613e transparent; scrollbar-width: thin; }
.plan-board::-webkit-scrollbar { height: 10px; }
.plan-board::-webkit-scrollbar-track { border: 1px solid var(--line); background: var(--surface-2); }
.plan-board::-webkit-scrollbar-thumb { border: 2px solid var(--surface-2); border-radius: 0; background: #52613e; }
.plan-board::-webkit-scrollbar-thumb:hover { background: var(--accent); }
.plan-canvas { --plan-grid-width: 180px; --plan-grid-height: 150px; position: relative; min-height: 280px; margin-top: 0; border: 1px solid var(--line); background-color: var(--surface-2); background-image: linear-gradient(rgba(203,232,107,.08) 1px, transparent 1px), linear-gradient(90deg, rgba(203,232,107,.08) 1px, transparent 1px); background-size: var(--plan-grid-width) var(--plan-grid-height); overflow: hidden; }
.plan-mode .plan-canvas, .editor-layout.context-open .plan-canvas { box-sizing: border-box; width: calc(var(--plan-grid-width) * var(--plan-grid-columns) + 2px); height: calc(var(--plan-grid-height) * var(--plan-grid-rows) + 2px); min-height: calc(var(--plan-grid-height) * var(--plan-grid-rows) + 2px); }
.plan-expand { position: absolute; z-index: 3; display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid var(--line-bright); background: var(--surface-3); color: var(--accent); box-shadow: 0 5px 15px rgba(0,0,0,.28); cursor: pointer; }
.plan-expand:hover { border-color: var(--accent); background: var(--surface); }
.plan-zoom-controls { display: inline-flex; align-items: center; margin-left: 8px; border: 1px solid var(--line-bright); background: var(--surface-2); }
.plan-zoom-controls button { display: grid; place-items: center; width: 30px; height: 30px; border: 0; border-left: 1px solid var(--line-bright); background: transparent; color: var(--soft); font: 11px var(--typewriter); }
.plan-zoom-controls button:first-child { border-left: 0; }.plan-zoom-controls button:hover { background: var(--surface-3); color: var(--accent); }.plan-zoom-controls #plan-zoom-value { width: 48px; color: var(--ink); }
.web-canvas { --plan-zoom: 1; width: calc(var(--plan-grid-width) * var(--plan-grid-columns) * var(--plan-zoom) + 2px) !important; height: calc(var(--plan-grid-height) * var(--plan-grid-rows) * var(--plan-zoom) + 2px) !important; min-height: calc(var(--plan-grid-height) * var(--plan-grid-rows) * var(--plan-zoom) + 2px) !important; background-size: calc(var(--plan-grid-width) * var(--plan-zoom)) calc(var(--plan-grid-height) * var(--plan-zoom)); }
.web-canvas .plan-node { width: calc(var(--plan-grid-width) * var(--plan-zoom)); height: calc(var(--plan-grid-height) * var(--plan-zoom)); }
.web-canvas .plan-node { overflow: hidden; }
.web-canvas .plan-node-note { max-height: calc((var(--plan-grid-height) * var(--plan-zoom)) - 64px); overflow-y: auto; }
.plan-board:has(.web-canvas) .plan-expand { display: grid; }
.plan-expand-column { top: calc(var(--plan-grid-height) * var(--plan-grid-rows) / 2 - 19px); left: calc(var(--plan-grid-width) * var(--plan-grid-columns) + 8px); }
.plan-expand-row { top: calc(var(--plan-grid-height) * var(--plan-grid-rows) + 8px); bottom: auto; left: 50%; transform: translateX(-50%); }
.plan-node { position: absolute; z-index: 1; box-sizing: border-box; width: var(--plan-grid-width); height: var(--plan-grid-height); padding: 12px; transform: none; border: 1px solid #4e5d38; background: #20291a; color: #edf6d8; box-shadow: 0 12px 22px rgba(0,0,0,.22); cursor: grab; }
.plan-node:active, .plan-node.dragging { cursor: grabbing; touch-action: none; }
.plan-node strong { display: block; margin: 5px 0; font-size: 12px; }.plan-node small { color: #a8bb7d; font-size: 8px; letter-spacing: .1em; text-transform: uppercase; }
.plan-node-note { display: block; min-height: 22px; max-height: calc(var(--plan-grid-height) - 64px); overflow-y: auto; margin-top: 8px; padding: 7px 8px 0 0; border-top: 1px solid rgba(198,211,174,.2); color: #c6d3ae; font: 12px/1.45 var(--typewriter); text-align: left; white-space: pre-wrap; overflow-wrap: anywhere; scrollbar-width: thin; scrollbar-color: #52613e transparent; }
.plan-node-note::-webkit-scrollbar { width: 5px; }
.plan-node-note::-webkit-scrollbar-track { background: transparent; }
.plan-node-note::-webkit-scrollbar-thumb { border-radius: 0; background: #52613e; }
.plan-node-note::before { content: 'Note'; display: block; margin-bottom: 3px; color: #a8bb7d; font: 700 8px var(--sans); letter-spacing: .12em; text-transform: uppercase; }
.plan-node > span:not(.plan-node-note) { display: none; }
.plan-node-note.empty { color: #a4b294; font-style: normal; }
.kanban-canvas { width: 100% !important; height: auto !important; min-height: 0 !important; border: 0; background: transparent; overflow: visible !important; }
.plan-kanban { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; min-height: 100%; padding: 1px; }
.plan-lane { display: flex; flex-direction: column; min-width: 0; min-height: 280px; border: 1px solid var(--line); background: var(--surface-2); }
.plan-lane > header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 15px; border-bottom: 1px solid var(--line); background: var(--surface); }
.plan-lane > header h3 { margin: 5px 0 0; color: var(--ink); font: 700 14px/1 var(--sans); letter-spacing: .04em; }
.plan-lane-count { display: grid; place-items: center; min-width: 24px; height: 24px; border: 1px solid var(--line-bright); color: var(--accent); font: 11px var(--typewriter); }
.plan-lane-cards { display: grid; align-content: start; gap: 10px; min-height: 220px; padding: 10px; overflow-y: auto; }
.plan-lane-cards.drag-over { background: rgba(203,232,107,.08); outline: 1px dashed var(--accent); outline-offset: -5px; }
.plan-node.kanban-card { position: relative; width: auto; height: auto; min-height: 150px; padding: 14px; transform: none; cursor: grab; }
.plan-node.kanban-card .plan-node-note { max-height: none; overflow: visible; padding-right: 0; }
.plan-node.kanban-card.dragging { opacity: .55; }
#plan-board:has(.kanban-canvas) .plan-expand { display: none; }
.plan-connect { min-height: 34px; padding: 0 12px; font-size: 10px; }
.plan-help { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 16px; color: var(--muted); font-size: 11px; }
.plan-help span { display: inline-flex; align-items: center; gap: 6px; }
.plan-help i { color: var(--accent); font-size: 14px; }
.plan-workspace { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 0; gap: 18px; min-height: 0; flex: 1 1 auto; --plan-grid-width: 180px; --plan-grid-height: 150px; --plan-grid-columns: 7; --plan-grid-rows: 4; }
.plan-workspace:has(.plan-detail-panel.open) { grid-template-columns: minmax(0, 1fr) minmax(300px, 360px); }
.plan-workspace > .plan-board { grid-column: 1; grid-row: 1; }
.plan-workspace > .plan-detail-panel { grid-column: 2; grid-row: 1 / span 2; }
.plan-workspace > .plan-expand-controls { grid-column: 1; grid-row: 2; align-self: start; }
.plan-board > .plan-expand { position: absolute; }
.plan-detail-panel { min-width: 0; overflow: hidden; border: 1px solid var(--line); background: var(--surface-2); opacity: 0; pointer-events: none; transform: translateX(10px); transition: opacity .18s ease, transform .18s ease; }
.plan-detail-panel.open { opacity: 1; pointer-events: auto; transform: translateX(0); }
.plan-detail-empty { display: grid; place-items: center; align-content: center; gap: 8px; height: 100%; min-height: 220px; padding: 24px; color: var(--muted); text-align: center; }
.plan-detail-empty i { color: var(--accent); font-size: 24px; }.plan-detail-empty strong { color: var(--soft); font: 700 13px var(--sans); }.plan-detail-empty span { max-width: 190px; font-size: 11px; line-height: 1.5; }
.plan-detail-content { display: grid; align-content: start; gap: 18px; height: 100%; padding: 20px; box-sizing: border-box; overflow-y: auto; }
.plan-detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding-bottom: 15px; border-bottom: 1px solid var(--line); }.plan-detail-head h3 { margin: 6px 0 0; color: var(--ink); font: 700 21px/1.15 var(--sans); }.plan-detail-meta { color: var(--muted); font-size: 11px; }.plan-detail-note { min-height: 160px; color: var(--soft); font: 15px/1.65 var(--typewriter); white-space: pre-wrap; overflow-wrap: anywhere; }.plan-detail-edit { justify-self: start; }
.plan-expand-controls { grid-column: 1; display: flex; align-items: center; gap: 8px; padding-top: 10px; }
.plan-expand-controls .plan-expand { position: static; display: inline-flex; align-items: center; gap: 6px; width: auto; height: 34px; padding: 0 12px; transform: none; box-shadow: none; }
.plan-workspace, .plan-workspace:has(.plan-detail-panel.open) { grid-template-columns: minmax(0, 1fr); }
.plan-detail-panel { display: none !important; }
@media (max-width: 760px) { .plan-workspace { display: block; }.plan-detail-panel.open { min-height: 300px; margin-top: 14px; }.plan-detail-content { height: auto; min-height: 300px; } }
.plan-lines { position: absolute; inset: 0; z-index: 0; width: 100%; height: 100%; pointer-events: none; }.plan-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font: 17px var(--serif); text-align: center; }
.plan-legend { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 17px; color: var(--muted); font-size: 9px; }.legend-dot { display: inline-block; width: 6px; height: 6px; margin-right: 4px; border-radius: 50%; }.legend-dot.lime { background: var(--accent); }.legend-dot.coral { background: var(--coral); }.legend-dot.blue { background: var(--blue); }
.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin: 25px 0; border: 1px solid var(--line); }.metric-grid div { padding: 12px 8px; background: var(--surface-2); }.metric-grid strong { display: block; color: var(--ink); font: 22px var(--serif); }.metric-grid span { color: var(--muted); font-size: 8px; letter-spacing: .08em; text-transform: uppercase; }.streak-badge { margin-top: 6px; color: var(--accent); font-size: 9px; }.analytics-chart { display: flex; align-items: end; gap: 3px; height: 120px; padding: 0 2px; border-bottom: 1px solid var(--line); }.chart-bar { flex: 1; min-height: 3px; background: var(--accent); opacity: .8; }.analytics-caption { display: flex; justify-content: space-between; margin-top: 9px; color: var(--muted); font-size: 9px; }
.utility-view { display: none; margin: 0 4vw; padding: 48px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--surface); min-height: 420px; }.utility-view.active { display: block; }.utility-view h2 { margin: 8px 0 12px; font-size: 38px; }.utility-view p { max-width: 480px; color: var(--soft); font: 18px/1.45 var(--serif); }.utility-view .button { margin-top: 25px; }
.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 30px; background: radial-gradient(circle at 50% 0, #20291d 0, transparent 42%); }.auth-card { width: min(420px, 100%); padding: 42px 40px; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }.auth-brand { padding-bottom: 54px; }.auth-card h1 { margin: 10px 0 12px; font-size: 42px; }.auth-intro { margin-bottom: 29px; color: var(--muted); font-size: 12px; }.auth-card form { display: grid; gap: 17px; }.auth-card label { display: grid; gap: 7px; color: var(--soft); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; }.auth-card input { width: 100%; height: 42px; padding: 0 12px; outline: 0; border: 1px solid var(--line-bright); background: var(--bg); color: var(--ink); font: 14px var(--sans); }.auth-card input:focus { border-color: var(--accent); }.auth-submit { width: 100%; height: 42px; margin-top: 8px; }.auth-submit i { margin-left: auto; }.auth-switch { margin-top: 25px; color: var(--muted); font-size: 11px; text-align: center; }.auth-switch a { color: var(--accent); }.form-error { display: flex; gap: 8px; align-items: center; margin-bottom: 18px; padding: 11px; border: 1px solid #734b43; background: #3a2622; color: #f1a896; font-size: 11px; }
.loading-line { padding: 17px 3px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 10px; }.editor-placeholder { color: var(--muted) !important; font-style: italic; }
.toast { position: fixed; right: 28px; bottom: 26px; z-index: 5; display: flex; gap: 9px; align-items: center; padding: 12px 16px; background: var(--accent); color: var(--accent-ink); border-radius: 3px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(20px); transition: .25s; }.toast.show { opacity: 1; transform: translateY(0); }
.modal-backdrop { position: fixed; inset: 0; z-index: 6; display: none; align-items: center; justify-content: center; padding: 20px; background: rgba(0,0,0,.7); }.modal-backdrop.open { display: flex; }.modal-card { position: relative; width: min(430px, 100%); padding: 30px; border: 1px solid var(--line-bright); background: var(--surface-2); box-shadow: var(--shadow); }.modal-card h2 { margin: 8px 0; }.modal-intro { color: var(--muted); font-size: 11px; }.modal-card textarea { display: block; width: 100%; height: 130px; margin: 20px 0; padding: 12px; outline: 0; border: 1px solid var(--line-bright); background: var(--bg); color: var(--ink); font: 15px/1.6 var(--typewriter); font-style: normal; letter-spacing: 0; resize: vertical; }.modal-close { position: absolute; top: 13px; right: 14px; background: none; color: var(--muted); font-size: 18px; }.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.export-card { width: min(520px, 100%); }.export-options { display: grid; gap: 10px; margin-top: 24px; }.export-option { display: grid; grid-template-columns: 38px 1fr 18px; align-items: center; gap: 12px; width: 100%; padding: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-align: left; }.export-option:hover { border-color: var(--accent); background: var(--surface-3); }.export-option strong, .export-option small { display: block; }.export-option strong { font-size: 12px; }.export-option small { margin-top: 4px; color: var(--muted); font-size: 10px; line-height: 1.35; }.export-option > i { color: var(--muted); }.export-icon { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--line-bright); color: var(--accent); font-size: 18px; }

.app-view { display: none; }
.app-view.active { display: block; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; max-width: 1420px; padding: 54px 4vw 34px; }
.page-heading h1 { margin-top: 10px; }
.page-heading p { margin-top: 12px; color: var(--muted); font: 17px/1.35 var(--serif); }
.library-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; width: calc(100% - 8vw); max-width: 1420px; margin: 0 4vw; padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.library-filter { display: flex; gap: 3px; }
.filter-button { padding: 7px 10px; background: transparent; color: var(--muted); font-size: 10px; }
.filter-button:hover, .filter-button.active { background: var(--surface-2); color: var(--ink); }
.library-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; width: calc(100% - 8vw); max-width: 1420px; margin: 28px 4vw 50px; border: 1px solid var(--line); background: var(--line); }
.book-card { position: relative; min-height: 240px; padding: 25px; background: var(--surface); }
.book-card:hover { background: var(--surface-2); }
.book-card-main { display: block; width: 100%; min-height: 184px; padding: 0 34px 0 0; background: transparent; color: var(--ink); text-align: left; }
.book-card-accent { display: block; width: 26px; height: 3px; margin-bottom: 25px; border-radius: 0; }
.book-card h2 { max-width: 270px; margin: 12px 0; overflow-wrap: anywhere; }
.book-card p, .book-card small { display: block; color: var(--muted); font-size: 10px; }
.book-card p span { padding: 0 5px; color: var(--line-bright); }
.book-card small { margin-top: 26px; }
.card-open { position: absolute; right: 19px; bottom: 19px; display: grid; place-items: center; width: 31px; height: 31px; border: 1px solid var(--line-bright); background: transparent; color: var(--soft); }
.card-open:hover { border-color: var(--accent); color: var(--accent); }
.empty-state { grid-column: 1 / -1; padding: 80px 25px; background: var(--surface); text-align: center; }
.empty-mark { margin-bottom: 16px; color: var(--accent); font: 42px var(--serif); }
.empty-state h2 { margin-bottom: 10px; }
.empty-state p { color: var(--muted); font: 16px/1.4 var(--serif); }
.empty-state .button { margin-top: 24px; }
.activity-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; width: calc(100% - 8vw); max-width: 1420px; margin: 0 4vw 28px; border: 1px solid var(--line); background: var(--line); }
.summary-card { min-height: 112px; padding: 20px; background: var(--surface); }
.summary-card span { color: var(--muted); font-size: 9px; letter-spacing: .1em; text-transform: uppercase; }
.summary-card strong { display: block; margin-top: 17px; color: var(--ink); font: 34px var(--serif); }
.activity-panel, .settings-panel { width: calc(100% - 8vw); max-width: 1420px; margin: 0 4vw 50px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--surface); }
.activity-panel { padding: 28px; }
.heatmap-panel { overflow: hidden; }
.heatmap-meta { display: flex; justify-content: space-between; gap: 20px; margin: 24px 0 12px; color: var(--muted); font-size: 10px; }
.writing-heatmap { width: 100%; overflow-x: auto; padding-bottom: 4px; }
.heatmap-grid { display: grid; grid-template-rows: repeat(7, 13px); grid-auto-flow: column; grid-auto-columns: 13px; gap: 4px; min-width: 900px; }
.heat-cell { width: 13px; height: 13px; border: 1px solid rgba(255,255,255,.035); background: var(--surface-3); }
.heat-cell.level-1 { background: #536735; }.heat-cell.level-2 { background: #789546; }.heat-cell.level-3 { background: #a7c75b; }.heat-cell.level-4 { background: var(--accent); }
.heatmap-month-labels { display: grid; grid-template-columns: repeat(12, 1fr); min-width: 900px; margin-bottom: 8px; color: var(--muted); font-size: 9px; }
.heatmap-scale { display: flex; align-items: center; justify-content: flex-end; gap: 5px; min-width: 900px; margin-top: 10px; color: var(--muted); font-size: 9px; }
.heatmap-scale .heat-cell { display: inline-block; flex: 0 0 13px; }
.heat-cell { position: relative; cursor: crosshair; }
.heatmap-tooltip { position: fixed; z-index: 100; display: none; width: max-content; max-width: min(220px, calc(100vw - 16px)); padding: 7px 9px; border: 1px solid var(--line-bright); background: #151914; color: #eef4e5; font: 10px/1.35 var(--sans); pointer-events: none; white-space: nowrap; box-shadow: var(--shadow); }
.heatmap-tooltip.show { display: block; }
@media (min-width: 761px) {
    html, body { height: 100%; overflow-y: auto; }
    html.editor-active, html.editor-active body, html.has-book-route, html.has-book-route body { overflow: hidden; }
}
.panel-title h2 { margin-top: 8px; }
.library-activity-list { margin-top: 25px; border-top: 1px solid var(--line); }
.activity-row { display: grid; grid-template-columns: 1fr auto 22px; align-items: center; gap: 15px; width: 100%; padding: 15px 4px; border-bottom: 1px solid var(--line); background: transparent; color: var(--soft); text-align: left; }
.activity-row:hover { color: var(--ink); }
.activity-row strong { color: var(--accent); font-size: 10px; font-weight: 500; }
.activity-row i { color: var(--muted); }
.settings-panel { display: flex; align-items: center; justify-content: space-between; gap: 25px; padding: 23px 27px; }
.settings-panel div { display: grid; gap: 6px; }.settings-panel strong { font-size: 12px; }.settings-panel span { color: var(--muted); font-size: 11px; }
.editor-head { display: grid; grid-template-columns: 1fr minmax(220px, 2fr) 1fr; align-items: center; gap: 20px; width: calc(100% - 8vw); max-width: 1420px; margin: 0 4vw; padding: 36px 0 30px; border-bottom: 1px solid var(--line); }
.back-button { justify-self: start; display: inline-flex; align-items: center; gap: 8px; padding: 8px 0; background: transparent; color: var(--muted); font-size: 10px; }.back-button:hover { color: var(--ink); }.back-button i { font-size: 15px; }
.editor-book-title { min-width: 0; text-align: center; }.editor-book-title h1 { max-width: none; margin-top: 7px; font-size: clamp(30px, 4vw, 52px); }
.editor-head-actions { justify-self: end; display: flex; align-items: center; gap: 7px; }
.action-menu-wrap { position: relative; }.action-menu { position: absolute; top: calc(100% + 8px); right: 0; z-index: 3; display: none; width: 190px; padding: 5px; border: 1px solid var(--line-bright); background: var(--surface-2); box-shadow: var(--shadow); }.action-menu.open { display: grid; }.action-menu button { display: flex; align-items: center; gap: 9px; padding: 10px; background: transparent; color: var(--soft); font-size: 10px; text-align: left; }.action-menu button:hover { background: var(--surface-3); color: var(--ink); }.action-menu button i { width: 15px; }.action-menu .danger-action:hover { color: #ff9f8b; }
.editor-layout { display: grid; grid-template-columns: 228px minmax(480px, 1fr) 286px; width: calc(100% - 8vw); max-width: 1420px; min-height: 680px; margin: 0 4vw 40px; border-bottom: 1px solid var(--line); }
.editor-layout .chapter-panel, .editor-layout .insight-panel { min-width: 0; padding: 26px 18px; background: transparent; }.editor-layout .chapter-panel { border-right: 1px solid var(--line); }.editor-layout .insight-panel { border-left: 1px solid var(--line); }
.modal-label { display: grid; gap: 7px; margin-top: 20px; color: var(--soft); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; }.modal-label input, .modal-label select { width: 100%; height: 42px; padding: 0 12px; outline: 0; border: 1px solid var(--line-bright); background: var(--bg); color: var(--ink); font: 14px var(--sans); }.modal-label input:focus, .modal-label select:focus, .modal-label textarea:focus { border-color: var(--accent); }.modal-label textarea { margin: 0; }
.danger-button { background: #a94f43; color: #fff2ed; }.danger-button:hover { background: #c26455; }
.toast.error { background: #b45d4e; color: #fff6f2; }.spin { display: inline-block; animation: spin .8s linear infinite; }@keyframes spin { to { transform: rotate(360deg); } }
.plan-node.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(203,232,107,.25), 0 12px 22px rgba(0,0,0,.22); }
.archived-card { display: flex; flex-direction: column; justify-content: space-between; gap: 25px; min-height: 180px; }.archived-card .button { align-self: flex-start; }
.chapter-item { position: relative; display: flex; align-items: center; gap: 4px; padding-right: 0; }
.chapter-select { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; min-height: 54px; padding: 8px 3px; background: transparent; color: inherit; text-align: left; }
.chapter-actions { display: flex; gap: 1px; opacity: 0; transition: opacity .15s ease; }.chapter-item:hover .chapter-actions, .chapter-item.active .chapter-actions { opacity: 1; }
.chapter-action { display: grid; place-items: center; width: 25px; height: 25px; background: transparent; color: var(--muted); font-size: 12px; }.chapter-action:hover { color: var(--ink); background: var(--surface-3); }.chapter-action.danger-action:hover { color: #ff9f8b; }

/* The editor is the primary workspace: give it the full viewport and keep its chrome quiet. */
.editor-view { width: 100%; }
.editor-head { width: 100%; max-width: none; margin: 0; padding: 18px 28px 16px; }
.editor-book-title h1 { font-size: clamp(26px, 3vw, 40px); }
.editor-layout { width: 100%; max-width: none; margin: 0; min-height: calc(100vh - 145px); }
.editor-layout .writing-surface { min-height: calc(100vh - 245px); }
.nav-item, .book-link, .button, .filter-button { font-size: 12px; }
.eyebrow, .sidebar-label, .toolbar-group button, .save-state, .progress-copy, .chapter-copy small, .chapter-status, .book-card p, .book-card small, .activity-row strong, .summary-card span, .settings-panel span { font-size: 10px; }
.breadcrumbs, .book-meta, .profile-copy span, .modal-intro, .auth-intro { font-size: 12px; }
.chapter-copy strong, .notes-link, .all-notes-button, .activity-row, .settings-panel strong { font-size: 12px; }
.note-card p { font-size: 17px; }
.note-actions { display: inline-flex; align-items: center; gap: 5px; margin-left: auto; }.note-actions button { display: grid; place-items: center; width: 32px; height: 32px; border: 1px solid var(--line-bright); background: transparent; color: var(--soft); font-size: 15px; }.note-actions button:hover { border-color: var(--accent); color: var(--accent); background: var(--surface-2); }.note-actions button:last-child:hover { border-color: #ff9f8b; color: #ff9f8b; }
.merged-context-divider { display: flex; align-items: center; gap: 14px; margin: 48px 0 25px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }.merged-context-divider::after { content: ''; height: 1px; flex: 1; background: var(--line); }
.merged-plan-view { display: block !important; max-width: none !important; margin: 0 !important; }
.legacy-notes-view { display: none !important; }

/* Editor viewport: the app chrome stays fixed while only the writing/context columns scroll. */
.editor-view { height: calc(100vh - 68px); overflow: hidden; }
.editor-head { display: flex; align-items: center; width: 100%; max-width: none; margin: 0; padding: 14px 28px; border-bottom: 1px solid var(--line); }
.back-button { flex: 0 0 auto; }
.editor-book-title { flex: 1; min-width: 0; text-align: left; }
.editor-book-title h1 { margin-top: 4px; font-size: clamp(25px, 2.5vw, 36px); }
.editor-head-actions { flex: 0 0 auto; }
.editor-layout { grid-template-columns: minmax(190px, 220px) minmax(0, 1fr) minmax(220px, 300px); height: calc(100% - 82px); min-height: 0; border: 0; overflow: hidden; }
.editor-layout .chapter-panel, .editor-layout .insight-panel, .editor-layout .editor-panel { min-height: 0; height: 100%; overflow-y: auto; }
.editor-layout .editor-panel { overflow: hidden; }
.editor-layout .writing-surface { min-height: 0; height: calc(100% - 98px); overflow-y: auto; }
.editor-layout .editor-footer { flex: 0 0 43px; }
.editor-layout .progress-track, .editor-layout .progress-copy, .editor-layout .notes-link { display: none; }
.editor-head-actions { min-width: 0; }

@media (max-width: 760px) {
    .app-shell, .main-content { width: 100%; max-width: 100%; overflow-x: hidden; }
    .editor-view { height: auto; min-height: calc(100vh - 60px); overflow: visible; }
    .editor-head { display: grid; height: auto; }
    .editor-layout { height: auto; min-height: 0; overflow: visible; }
    .editor-layout .chapter-panel, .editor-layout .insight-panel, .editor-layout .editor-panel { height: auto; overflow: visible; }
    .editor-layout .writing-surface { height: auto; min-height: 530px; overflow: visible; }
}

@media (min-width: 761px) {
    .app-shell { width: 100vw; max-width: 100vw; overflow: visible; }
    .main-content { flex: 1 1 0; width: calc(100vw - 238px); max-width: calc(100vw - 238px); min-width: 0; overflow: visible; }
    .editor-view, .editor-layout { width: 100%; min-width: 0; max-width: 100%; }
    .editor-layout { grid-template-columns: 200px minmax(0, 1fr) minmax(0, 260px); }
    .editor-layout .insight-panel { min-width: 0; overflow-x: hidden; }
    .context-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; overflow: hidden; }
    .context-tab { width: 100%; min-width: 0; padding-left: 2px; padding-right: 2px; font-size: 9px; }
    .editor-layout { grid-template-columns: 200px minmax(0, 1fr); padding-right: 300px; }
    .editor-view, .editor-layout { overflow: visible; }
    .editor-layout .insight-panel { position: fixed; top: 143px; left: calc(100vw - 300px); right: auto; bottom: 0; z-index: 3; display: block; width: 300px; max-width: none; min-width: 0; height: auto; padding: 26px 18px; box-sizing: border-box; border-top: 0; border-right: 0; border-bottom: 0; border-left: 1px solid var(--line); background: var(--bg); overflow-x: hidden; overflow-y: auto; }
}

.editor-context-nav { display: flex; align-items: stretch; gap: 4px; width: 100%; padding: 0 28px; border-bottom: 1px solid var(--line); background: var(--bg); }
.editor-context-tab { min-width: 100px; padding: 13px 15px 11px; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.editor-context-tab:hover, .editor-context-tab.active { border-bottom-color: var(--accent); color: var(--ink); }
.overview-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; gap: 18px; margin-top: 28px; }
.overview-field { display: grid; gap: 8px; color: var(--soft); font: 700 10px var(--sans); letter-spacing: .12em; text-transform: uppercase; }
.overview-field input, .overview-field textarea { width: 100%; box-sizing: border-box; padding: 13px; outline: 0; border: 1px solid var(--line-bright); background: var(--surface-2); color: var(--ink); font: 15px/1.55 var(--typewriter); letter-spacing: 0; text-transform: none; }
.overview-field input { height: 48px; resize: none; }
.overview-field input:focus, .overview-field textarea:focus { border-color: var(--accent); }
.overview-field textarea { min-height: 110px; max-height: 360px; resize: none; overflow-y: hidden; scrollbar-width: thin; scrollbar-color: #52613e transparent; }
.overview-wide { grid-column: 1 / -1; }.overview-wide textarea { min-height: 135px; }
.overview-structure-field textarea { min-height: 190px; }
.structure-field-head, .structure-section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }.structure-field-head { margin-bottom: 8px; }.structure-field-head > span { color: var(--soft); }.structure-field-head .button { min-height: 30px; padding: 0 10px; font-size: 10px; letter-spacing: 0; text-transform: none; }
.context-plot .panel-intro { max-width: 700px; margin: 14px 0 28px; color: var(--soft); font: 17px/1.45 var(--serif); }
.structure-groups { display: grid; gap: 26px; }
.structure-group-tabs { display: flex; gap: 4px; margin: 24px 0 0; border-bottom: 1px solid var(--line); }
.structure-group-tab { appearance: none; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); cursor: pointer; padding: 12px 16px; font: 700 11px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase; }
.structure-group-tab:hover, .structure-group-tab.active { color: var(--ink); }
.structure-group-tab.active { border-bottom-color: var(--accent); }
.structure-group { display: none; padding-top: 22px; }
.structure-group.active { display: block; }
.structure-group-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 12px; }
.structure-group-head p { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.structure-group-head .button { flex: 0 0 auto; }
.structure-sections { display: grid; gap: 12px; }.structure-section { padding: 14px; border: 1px solid var(--line-bright); background: var(--surface-2); }.structure-section-head input, .structure-section > textarea { width: 100%; box-sizing: border-box; outline: 0; border: 1px solid var(--line-bright); background: var(--bg); color: var(--ink); font: 15px/1.55 var(--typewriter); letter-spacing: 0; }.structure-section-head input { flex: 1; min-width: 0; height: 38px; padding: 9px 11px; }.structure-section-head .icon-button { flex: 0 0 32px; }.structure-section > textarea { display: block; min-height: 130px; max-height: 360px; margin-top: 10px; padding: 12px; resize: none; overflow-y: hidden; }.structure-section-head input:focus, .structure-section > textarea:focus { border-color: var(--accent); }
.overview-section { margin-top: 38px; border-top: 1px solid var(--line); }.overview-section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 20px; padding: 18px 0 12px; }.overview-section-head strong { color: var(--soft); font-size: 12px; }
.overview-details { margin-top: 22px; }.overview-details .overview-grid { margin-top: 12px; }.overview-section-note { color: var(--muted); font-size: 11px; }.overview-stat { display: grid; align-content: center; gap: 5px; min-height: 48px; padding: 12px 14px; border: 1px solid var(--line); background: var(--surface); }.overview-stat strong { color: var(--ink); font: 24px var(--typewriter); }.overview-stat small { color: var(--muted); font-size: 10px; }.story-brief-section { margin-top: 34px; }
.overview-chapters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; border: 1px solid var(--line); background: var(--line); }.overview-chapter { display: grid; grid-template-columns: 36px 1fr; gap: 12px; padding: 16px; background: var(--surface); }.overview-chapter:only-child { grid-column: 1 / -1; }.overview-chapter-number { color: var(--accent); font: 11px var(--typewriter); }.overview-chapter strong, .overview-chapter small { display: block; }.overview-chapter small { margin-top: 5px; color: var(--muted); font-size: 10px; }.overview-progress { display: block; height: 3px; margin-top: 12px; background: var(--surface-3); }.overview-progress i { display: block; height: 100%; background: var(--accent); }
.editor-layout.context-open { display: block; height: calc(100% - 127px); padding: 0; overflow: auto; }
.editor-layout.context-open .chapter-panel, .editor-layout.context-open .editor-panel { display: none; }
.editor-layout.context-open .insight-panel { position: static; display: block; width: 100%; max-width: none; min-width: 0; height: auto; min-height: calc(100vh - 230px); padding: 38px clamp(24px, 6vw, 100px) 80px; border: 0; background: var(--bg); overflow: visible; }
.editor-layout.context-open .context-view { display: none; max-width: none; margin: 0; }
.editor-layout.context-open .context-view.active { display: block; }
.editor-layout.context-open.plan-context-open { overflow: hidden; }
.editor-layout.context-open.plan-context-open .insight-panel { height: 100%; min-height: 0; overflow: hidden; }
.editor-layout.context-open.plan-context-open #context-plan.active { display: flex; flex-direction: column; height: 100%; }
.editor-layout.context-open.plan-context-open .plan-board { flex: 1 1 auto; min-height: 0; overflow: auto; }
.editor-layout.context-open .context-view .insight-head { align-items: end; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.editor-layout.context-open .context-view h2 { font-size: clamp(32px, 4vw, 52px); }
.editor-layout.context-open .notes-stack { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; margin-top: 30px; }
.editor-layout.context-open .note-card { min-height: 170px; padding: 18px; border: 1px solid var(--line); border-left: 3px solid var(--accent); background: var(--surface); }
.editor-layout.context-open .plan-board { margin-top: 0; }
.editor-layout.context-open .analytics-chart { height: 240px; margin-top: 35px; }
.editor-layout.context-open .analytics-chart { display: block; height: auto; padding: 0 0 5px; border: 0; overflow-x: auto; }
.editor-layout.context-open .analytics-chart .heatmap-grid { min-width: 900px; }

@media (max-width: 760px) {
    .editor-context-nav { padding: 0 16px; overflow-x: auto; }
    .editor-context-tab { min-width: 92px; padding-left: 10px; padding-right: 10px; }
    .editor-layout.context-open { height: auto; overflow: visible; }
    .editor-layout.context-open .insight-panel { min-height: 600px; padding: 30px 18px 70px; }
    .editor-layout.context-open .notes-stack { grid-template-columns: 1fr; }
}
.writing-surface p, .writing-surface li, .writing-surface blockquote { font-family: var(--typewriter); font-style: normal; }

[data-theme=light] { --bg:#f4f3ee; --sidebar:#e9ebe4; --surface:#fffefa; --surface-2:#f7f7f0; --surface-3:#eef0e7; --ink:#242823; --soft:#596158; --muted:#7c857c; --line:#d9ded5; --line-bright:#c4ccc0; --scrollbar-track:#eef0e7; --scrollbar-thumb:#a8b49e; --scrollbar-thumb-hover:#718556; }
[data-theme=light] .plan-board { scrollbar-color: #a8b49e var(--surface-2); }
[data-theme=light] .plan-board::-webkit-scrollbar-track { background: var(--surface-2); }
[data-theme=light] .plan-board::-webkit-scrollbar-thumb { border-color: var(--surface-2); background: #a8b49e; }
[data-theme=light] .plan-board::-webkit-scrollbar-thumb:hover { background: #718556; }
@media (max-width: 760px) { .sidebar-collapse { display: none; } .sidebar.collapsed { width: 238px; flex-basis: 238px; padding: 26px 14px 18px; } .sidebar.collapsed .brand-lockup { justify-content: flex-start; padding-right: 12px; padding-left: 12px; } .sidebar.collapsed .brand-lockup > div:last-child, .sidebar.collapsed .sidebar-label > span, .sidebar.collapsed .nav-item span, .sidebar.collapsed .book-link span:nth-child(2), .sidebar.collapsed .profile-copy { display: block; } .sidebar.collapsed .nav-item, .sidebar.collapsed .book-link { justify-content: flex-start; padding-right: 12px; padding-left: 12px; } .sidebar.collapsed .profile-card { justify-content: flex-start; padding-right: 8px; padding-left: 8px; } .sidebar.collapsed .profile-card form { margin-left: auto; } }
@media (max-width: 1180px) { .content-grid { grid-template-columns: 210px minmax(420px,1fr); }.editor-layout { grid-template-columns: 180px minmax(0,1fr) 220px; }.editor-layout .insight-panel { display: block; }.library-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 4; width: 238px; transform: translateX(-100%); transition: transform .25s; }.sidebar.open { transform: translateX(0); }.mobile-menu { display: grid; place-items: center; margin-right: 8px; }.topbar { height: 60px; padding: 0 18px; }.breadcrumbs span,.breadcrumbs i { display: none; }.topbar-actions { gap: 2px; }.topbar-actions .button span { display: none; }.topbar-actions .button { padding: 0 9px; }.workspace-head { align-items: flex-start; padding: 32px 18px 25px; }.workspace-head .ghost-button span { display: none; }.page-heading { align-items: flex-start; padding: 34px 18px 24px; }.page-heading .button { margin-top: 5px; }.page-heading p { font-size: 16px; }.library-toolbar, .activity-summary, .activity-panel, .settings-panel { width: calc(100% - 24px); margin-right: 12px; margin-left: 12px; }.library-toolbar { align-items: flex-start; flex-direction: column; gap: 10px; }.library-grid { grid-template-columns: 1fr; width: calc(100% - 24px); margin-right: 12px; margin-left: 12px; }.activity-summary { grid-template-columns: 1fr 1fr; }.editor-head { grid-template-columns: 1fr auto; width: 100%; margin: 0; padding: 14px 16px; }.editor-book-title { grid-column: 1 / -1; grid-row: 1; text-align: left; }.editor-head-actions { grid-column: 1 / -1; grid-row: 2; justify-self: start; }.back-button { grid-column: 1 / -1; grid-row: 3; }.editor-layout { display: block; width: 100%; margin: 0 0 30px; }.editor-layout .chapter-panel { border-right: 0; border-bottom: 1px solid var(--line); }.chapter-list { grid-template-columns: 1fr 1fr; }.chapter-item:nth-child(n+5) { display: none; }.editor-panel { min-height: 640px; }.writing-surface { min-height: 530px; padding: 45px 25px 80px; font-size: 17px; }.writing-surface h2 { font-size: 33px; }.editor-toolbar { padding: 0 8px; }.toolbar-select,.toolbar-divider:nth-of-type(2) { display: none !important; }.editor-layout .insight-panel { display: block; border-left: 0; border-top: 1px solid var(--line); }.plan-board { --plan-grid-width: 135px; }.plan-mode .plan-canvas, .editor-layout.context-open .plan-canvas { --plan-grid-width: 135px; min-height: calc(var(--plan-grid-height) * var(--plan-grid-rows) + 2px); height: calc(var(--plan-grid-height) * var(--plan-grid-rows) + 2px); }.plan-node { width: var(--plan-grid-width); }.utility-view { margin: 0 12px; padding: 32px 22px; }.settings-panel { align-items: flex-start; flex-direction: column; } }

@media (min-width: 761px) {
    .sidebar.collapsed + .main-content { width: calc(100vw - 64px); max-width: calc(100vw - 64px); }
    html, body { height: 100%; overflow: hidden; }
    .editor-view { display: flex; flex-direction: column; height: calc(100vh - 68px); min-height: 0; overflow: hidden; }
    .editor-head, .editor-context-nav { flex: 0 0 auto; }
    .editor-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); flex: 1 1 auto; width: 100%; height: auto; min-height: 0; margin: 0; padding: 0; overflow: hidden; }
    .editor-layout:not(.context-open) .insight-panel { display: none; }
    .editor-layout:not(.context-open) .chapter-panel { height: 100%; min-width: 0; overflow-y: auto; }
    .editor-layout:not(.context-open) .editor-panel { height: 100%; min-width: 0; min-height: 0; overflow: hidden; }
    .editor-layout:not(.context-open) .writing-surface { height: calc(100% - 98px); min-height: 0; padding: 32px 34px 64px; overflow-y: auto; }
    .editor-layout.context-open { display: block; flex: 1 1 auto; height: auto; min-height: 0; overflow-y: auto; }
    .editor-layout.context-open .insight-panel { display: block; position: static; width: 100%; max-width: none; min-width: 0; min-height: 100%; padding: 34px 28px 70px; box-sizing: border-box; }
    .editor-layout.context-open .context-view.active { display: block; width: 100%; max-width: none; margin: 0; }
    .editor-layout.context-open, .editor-layout.context-open .insight-panel, .editor-layout.context-open .context-view.active { width: 100% !important; max-width: none !important; margin-left: 0 !important; margin-right: 0 !important; }
    .editor-layout.context-open .insight-panel { position: static !important; left: auto !important; right: auto !important; padding-right: 28px !important; padding-left: 28px !important; }
}

@media (max-width: 760px) {
    html, body { overflow-x: hidden; }
    .editor-layout:not(.context-open) .insight-panel { display: none; }
    .editor-layout:not(.context-open) .writing-surface { padding: 32px 22px 64px; }
}

.chapter-list.locked { opacity: .62; }
.chapter-list.locked .chapter-select, .chapter-list.locked .chapter-action { cursor: wait; }
.chapter-list.locked::after { content: 'Saving changes…'; display: block; padding: 12px 14px; color: var(--muted); font-size: 11px; letter-spacing: .04em; }
.plan-field { display: none; }
#add-note { display: inline-flex; align-items: center; justify-content: center; gap: 7px; width: auto; min-width: 92px; padding: 0 11px; border: 1px solid var(--line-bright); background: transparent; color: var(--soft); }
#add-note::after { content: 'Add note'; font: 600 10px var(--sans); letter-spacing: .02em; }
#add-note:hover { border-color: var(--accent); color: var(--accent); background: var(--surface-2); }
#notes-modal .modal-card { width: min(760px, calc(100vw - 40px)); }
#form-modal.plan-modal .modal-card { width: min(760px, calc(100vw - 40px)); }
#notes-modal textarea, #form-body { min-height: 320px; max-height: 60vh; font: 15px/1.6 var(--typewriter); }
html.has-book-route #library-view { display: none !important; }

/* Final editor sizing: one viewport, no document scroll, and no hidden third column in Writing mode. */
@media (min-width: 761px) {
    html, body { height: 100%; overflow: hidden; }
    .app-shell, .main-content, .editor-view { min-height: 0; }
    .app-view.editor-view { display: none; }
    .app-view.editor-view.active { display: flex; }
    .editor-view { display: flex; flex-direction: column; height: calc(100vh - 68px); overflow: hidden; }
    .editor-head { flex: 0 0 auto; }
    .editor-context-nav { flex: 0 0 auto; }
    .editor-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); flex: 1 1 auto; width: 100%; height: auto; min-height: 0; margin: 0; padding: 0; overflow: hidden; }
    .editor-layout:not(.context-open) .insight-panel { display: none; }
    .editor-layout:not(.context-open) .chapter-panel { min-width: 0; height: 100%; overflow-y: auto; }
    .editor-layout:not(.context-open) .editor-panel { min-width: 0; height: 100%; min-height: 0; overflow: hidden; }
    .editor-layout:not(.context-open) .writing-surface { height: calc(100% - 98px); min-height: 0; padding: 32px 34px 64px; overflow-y: auto; }
    .editor-layout.context-open { display: block; flex: 1 1 auto; height: auto; min-height: 0; overflow-y: auto; }
    .editor-layout.context-open .insight-panel { min-height: 100%; padding: 34px clamp(24px, 6vw, 100px) 70px; }
}

@media (max-width: 760px) {
    html, body { overflow-x: hidden; }
    .app-view.editor-view.active { display: block; }
    .editor-layout:not(.context-open) .insight-panel { display: none; }
    .editor-layout:not(.context-open) .writing-surface { padding: 32px 22px 64px; }
    .overview-grid, .overview-chapters { grid-template-columns: 1fr; }
    .overview-wide { grid-column: auto; }
}

/* The book workspace has its own header; remove the global app bar so the editor does not stack duplicate chrome. */
html.editor-active .topbar { display: none; }
html.editor-active .editor-view { height: 100vh; min-height: 100vh; }
@media (max-width: 760px) {
    html.editor-active .editor-view { min-height: 100vh; }
}

@media (min-width: 761px) {
    .editor-layout.context-open:has(#context-plan.active) { height: auto !important; min-height: 0 !important; overflow: hidden !important; }
    .editor-layout.context-open:has(#context-plan.active) .insight-panel { height: 100% !important; min-height: 0 !important; overflow: hidden !important; }
    .editor-layout.context-open:has(#context-plan.active) #context-plan.active { display: flex !important; flex-direction: column; height: 100%; min-height: 0; }
    .editor-layout.context-open:has(#context-plan.active) .plan-board { flex: 1 1 auto; min-height: 0; overflow: auto; }
}

/* Writing keeps the manuscript context visible in a dedicated right column. */
@media (min-width: 761px) {
    .editor-layout:not(.context-open) { grid-template-columns: 220px minmax(0, 1fr) minmax(300px, 375px); }
    .editor-layout:not(.context-open) .insight-panel { display: flex; flex-direction: column; position: static; width: auto; height: 100%; padding: 28px 22px; border-left: 1px solid var(--line); overflow-y: auto; }
    .editor-layout:not(.context-open) #context-ai { display: block; order: -1; }
    .editor-layout:not(.context-open) #context-notes { display: block; margin-top: 32px; padding-top: 28px; border-top: 1px solid var(--line); }
}

/* AI review typography and rhythm. */
#context-ai .panel-intro { margin-top: 14px; color: var(--muted); font-size: 14px; line-height: 1.55; }
#context-ai .ai-status { font-size: 10px; }
#context-ai .ai-controls { gap: 12px; margin-top: 20px; padding-bottom: 22px; }
#context-ai .ai-controls label { gap: 8px; font-size: 10px; }
#context-ai .ai-controls select { height: 38px; padding: 0 11px; font-size: 12px; }
#context-ai .ai-controls .button { min-height: 38px; font-size: 12px; }
#context-ai .ai-results { gap: 14px; margin-top: 22px; }
#context-ai .ai-card { padding: 15px; }
#context-ai .ai-card-top { font-size: 9px; line-height: 1.35; }
#context-ai .ai-card p { margin-top: 12px; font-size: 15px; line-height: 1.5; }
#context-ai .ai-example { gap: 7px; margin-top: 13px; padding-top: 12px; }
#context-ai .ai-example small { font-size: 9px; }
#context-ai .ai-example span { font-size: 13px; line-height: 1.5; }
#context-ai .ai-card.ai-next .ai-card-top span:first-child { color: var(--accent); }
#context-ai .ai-card.has-passage { cursor: pointer; transition: border-color .15s ease, background .15s ease, transform .15s ease; }
#context-ai .ai-card.has-passage:hover, #context-ai .ai-card.has-passage:focus-visible { border-color: var(--line-bright); background: var(--surface-3); outline: none; }
#context-ai .ai-card.is-preview { border-color: rgba(203,232,107,.55); }
#context-ai .ai-card.is-pinned { border-color: var(--accent); background: rgba(203,232,107,.07); box-shadow: inset 0 0 0 1px rgba(203,232,107,.2); }
#context-ai .ai-passage-cue { display: flex; align-items: center; gap: 6px; margin-top: 13px; color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
#context-ai .ai-passage-cue i { font-size: 13px; }
#context-ai .ai-results > .ai-empty { margin-top: 0; gap: 9px; }
#context-ai .ai-empty strong { font-size: 14px; }
#context-ai .ai-empty span { font-size: 13px; line-height: 1.55; }

::highlight(authorroom-ai-preview) { color: inherit; background-color: rgba(203,232,107,.28); text-decoration: underline 1px rgba(203,232,107,.75); text-underline-offset: 3px; }
::highlight(authorroom-ai-pinned) { color: inherit; background-color: rgba(203,232,107,.48); text-decoration: underline 2px var(--accent); text-underline-offset: 3px; }

/* Give medium-width screens room to write before stacking the supporting context. */
@media (min-width: 761px) and (max-width: 1250px) {
    .editor-context-tab[data-context="ai"] { display: block; }
    .editor-layout:not(.context-open) { grid-template-columns: 190px minmax(0, 1fr); }
    .editor-layout:not(.context-open) .insight-panel { display: none; }
}
