:root {
  --ivory: #f4f0e8;
  --paper: #fbfaf6;
  --paper-deep: #ebe5da;
  --stone: #e4ded3;
  --stone-dark: #c9c0b2;
  --ink: #1d2922;
  --forest: #214d3b;
  --forest-deep: #16392d;
  --sage: #b8c8b4;
  --sage-soft: #e1e9de;
  --clay: #bd7b63;
  --clay-soft: #f0ddd4;
  --sand: #dfc18d;
  --blue-soft: #d9e1e6;
  --rose-soft: #ead4ce;
  --line: rgba(29, 41, 34, 0.16);
  --line-strong: rgba(29, 41, 34, 0.28);
  --muted: #647068;
  --danger: #a54535;
  --shadow: 0 16px 40px rgba(35, 42, 36, 0.09);
  --radius: 4px;
  --font-sans: "Segoe UI", Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-serif: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { min-width: 320px; background: var(--ivory); }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 100% 0, rgba(184, 200, 180, 0.25), transparent 30rem),
    var(--ivory);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
}

button, input, select, textarea { font: inherit; }

button, .button-link { cursor: pointer; }

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible,
a:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid rgba(189, 123, 99, 0.65);
  outline-offset: 2px;
}

button:disabled, select:disabled, input:disabled, textarea:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-root { min-height: 100vh; }

.boot-state, .auth-shell { min-height: 100vh; }

.boot-state {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0.6rem;
  color: var(--muted);
}

.boot-state p { margin: 0; }

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--forest-deep);
  font-weight: 760;
  letter-spacing: -0.04em;
}

.brand-wordmark { font-size: 1.55rem; }

.brand-mark {
  position: relative;
  display: inline-block;
  width: 1.55rem;
  height: 1.55rem;
  flex: 0 0 auto;
}

.brand-mark span { position: absolute; display: block; border: 2px solid currentColor; }
.brand-mark span:first-child {
  left: 0.1rem;
  bottom: 0.15rem;
  width: 0.95rem;
  height: 1.17rem;
  border-right: 0;
  border-radius: 0.2rem 0 0 0.2rem;
  transform: skewY(-15deg);
}
.brand-mark span:last-child {
  top: 0.1rem;
  right: 0.05rem;
  width: 0.85rem;
  height: 1.25rem;
  border-left: 0;
  border-radius: 0 0.2rem 0.2rem 0;
  transform: rotate(28deg);
}
.brand-mark-large { width: 2.75rem; height: 2.75rem; color: var(--forest); transform: scale(1.3); }

.auth-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(19rem, 26rem);
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(1.4rem, 5vw, 4.5rem);
  gap: clamp(2rem, 8vw, 8rem);
  align-items: center;
}

.auth-intro { max-width: 43rem; }

.auth-intro .brand-lockup { margin-bottom: 4rem; }

.auth-intro h1 {
  max-width: 10ch;
  margin: 0 0 1.2rem;
  color: var(--forest-deep);
  font-family: var(--font-serif);
  font-size: clamp(3.3rem, 8vw, 7rem);
  font-weight: 500;
  letter-spacing: -0.075em;
  line-height: 0.9;
}

.auth-intro > p {
  max-width: 38rem;
  margin: 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.8vw, 1.25rem);
}

.auth-note {
  display: flex;
  align-items: start;
  gap: 0.7rem;
  max-width: 32rem;
  margin-top: 2.4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.88rem;
}

.auth-note strong { color: var(--forest); font-weight: 700; }

.auth-panel {
  padding: clamp(1.25rem, 3vw, 2rem);
  border: 1px solid var(--line-strong);
  background: rgba(251, 250, 246, 0.9);
  box-shadow: var(--shadow);
}

.auth-panel h2 { margin: 0 0 0.35rem; font-family: var(--font-serif); font-size: 2rem; font-weight: 500; }
.auth-panel > p { margin: 0 0 1.4rem; color: var(--muted); }

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--line);
}

.auth-tabs button {
  min-height: 2.8rem;
  padding: 0.4rem 0.25rem;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  background: transparent;
  font-size: 0.78rem;
  font-weight: 700;
}

.auth-tabs button[aria-selected="true"] { border-bottom-color: var(--forest); color: var(--forest); }

.field { display: grid; gap: 0.38rem; margin-bottom: 1rem; }
.field label, .field legend { color: var(--ink); font-size: 0.79rem; font-weight: 720; letter-spacing: 0.02em; }
.field small, .field-hint { color: var(--muted); font-size: 0.78rem; }
.field input, .field select, .field textarea,
.text-input, .select-input {
  width: 100%;
  min-height: 2.85rem;
  padding: 0.65rem 0.72rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--paper);
}

.field textarea { min-height: 8rem; resize: vertical; }
.field input::placeholder, .field textarea::placeholder { color: #8a938b; }

.form-error, .inline-error { margin: 0 0 1rem; padding: 0.65rem 0.75rem; border-left: 3px solid var(--danger); color: var(--danger); background: rgba(165, 69, 53, 0.08); font-size: 0.86rem; }

.button-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.55rem; }
.button-row.end { justify-content: flex-end; }

.primary-button, .secondary-button, .quiet-button, .danger-button, .icon-button, .tool-button,
.drawer-action, .text-button, .link-button {
  min-height: 2.75rem;
  border-radius: var(--radius);
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
}

.primary-button, .secondary-button, .quiet-button, .danger-button, .drawer-action, .text-button, .link-button {
  padding: 0.55rem 0.85rem;
  border: 1px solid transparent;
  font-weight: 700;
}

.primary-button { color: var(--paper); background: var(--forest); }
.primary-button:hover { background: var(--forest-deep); }
.secondary-button { border-color: var(--forest); color: var(--forest); background: transparent; }
.secondary-button:hover { background: var(--sage-soft); }
.quiet-button, .text-button, .link-button { border-color: var(--line); color: var(--ink); background: transparent; }
.quiet-button:hover, .text-button:hover, .link-button:hover { border-color: var(--line-strong); background: rgba(255,255,255,0.5); }
.danger-button { border-color: rgba(165, 69, 53, 0.4); color: var(--danger); background: transparent; }
.danger-button:hover { background: var(--clay-soft); }
.text-button, .link-button { min-height: 2rem; padding: 0.2rem 0.45rem; color: var(--forest); font-size: 0.83rem; }
.icon-button { width: 2.75rem; padding: 0; border: 1px solid var(--line); color: var(--ink); background: transparent; font-size: 1.35rem; line-height: 1; }
.icon-button:hover { border-color: var(--line-strong); background: var(--paper); }

.workspace-shell { min-height: 100vh; }

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: grid;
  grid-template-columns: auto minmax(12rem, 1fr) minmax(13rem, 25rem) auto;
  gap: 0.9rem;
  align-items: center;
  min-height: 4.6rem;
  padding: 0.7rem 1.15rem;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 240, 232, 0.94);
  backdrop-filter: blur(12px);
}

.header-brand { min-width: 9rem; }
.header-brand .brand-wordmark { font-size: 1.3rem; }
.header-project { display: flex; align-items: center; min-width: 0; }
.project-select { width: min(100%, 24rem); min-height: 2.55rem; padding: 0.4rem 0.6rem; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); background: transparent; font-weight: 700; }
.header-search { display: flex; min-width: 0; }
.header-search input { width: 100%; min-height: 2.55rem; padding: 0.4rem 0.75rem; border: 1px solid var(--line); border-radius: var(--radius) 0 0 var(--radius); background: rgba(255,255,255,0.5); }
.header-search button { min-width: 2.75rem; min-height: 2.55rem; border: 1px solid var(--line); border-left: 0; border-radius: 0 var(--radius) var(--radius) 0; color: var(--forest); background: var(--paper); font-weight: 700; }
.header-tools { display: flex; justify-content: flex-end; align-items: center; gap: 0.45rem; }
.header-tools .quiet-button { min-height: 2.45rem; padding: 0.4rem 0.65rem; font-size: 0.82rem; }
.account-chip { display: none; color: var(--muted); font-size: 0.78rem; }

.save-status {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  max-width: 10.5rem;
  padding: 0.25rem 0.55rem;
  border-left: 2px solid var(--line-strong);
  color: var(--muted);
  font-size: 0.76rem;
  white-space: nowrap;
}
.save-status[data-state="saved"] { border-left-color: var(--forest); color: var(--forest); }
.save-status[data-state="saving"], .save-status[data-state="pending"] { border-left-color: var(--sand); color: #7b5b1a; }
.save-status[data-state="error"], .save-status[data-state="conflict"] { border-left-color: var(--danger); color: var(--danger); }

.sample-banner {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 2rem;
  padding: 0.35rem 1rem;
  color: var(--forest-deep);
  background: var(--sage-soft);
  font-size: 0.78rem;
}
.sample-banner button { margin-left: 0.75rem; padding: 0.15rem 0.45rem; border: 0; border-bottom: 1px solid currentColor; color: inherit; background: transparent; }

.workspace-body { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: calc(100vh - 4.6rem); }
.project-drawer { min-width: 0; padding: 1.05rem 0.85rem; border-right: 1px solid var(--line); background: rgba(228, 222, 211, 0.72); }
.drawer-heading { display: flex; justify-content: space-between; align-items: start; gap: 0.5rem; margin-bottom: 0.85rem; }
.drawer-heading h2 { margin: 0; font-size: 0.85rem; letter-spacing: 0.06em; text-transform: uppercase; }
.drawer-close { display: none; }
.eyebrow { margin: 0 0 0.4rem; color: var(--forest); font-size: 0.68rem; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; }
.drawer-filter { width: 100%; min-height: 2.3rem; padding: 0.4rem 0.55rem; border: 1px solid var(--line); background: rgba(255,255,255,0.45); }
.drawer-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.35rem; margin: 0.65rem 0 1rem; }
.drawer-action { min-height: 2.35rem; padding: 0.35rem 0.45rem; border-color: var(--line); color: var(--forest); background: rgba(255,255,255,0.34); font-size: 0.76rem; }
.drawer-action:hover { border-color: var(--forest); background: var(--sage-soft); }
.drawer-section { margin: 1rem 0; }
.drawer-section h3 { margin: 0 0 0.4rem; color: var(--muted); font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase; }
.folder-row, .item-row { display: flex; align-items: center; gap: 0.25rem; min-height: 2.25rem; padding: 0.2rem 0.25rem; border-left: 2px solid transparent; }
.folder-row { color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.item-row { width: 100%; color: var(--ink); background: transparent; font-size: 0.8rem; text-align: left; }
.item-row:hover { background: rgba(255,255,255,0.4); }
.item-row[aria-current="true"] { border-left-color: var(--forest); color: var(--forest-deep); background: var(--sage-soft); font-weight: 700; }
.item-row .item-icon { width: 1.1rem; color: var(--muted); text-align: center; }
.item-row .item-label { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-row .item-count { color: var(--muted); font-size: 0.68rem; }
.archived-label { color: var(--muted); font-size: 0.7rem; font-style: italic; }

.editor-shell { min-width: 0; background: var(--paper); }
.workspace-toolbar { display: flex; align-items: center; gap: 0.75rem; min-height: 3.65rem; padding: 0.55rem clamp(0.85rem, 2vw, 1.8rem); border-bottom: 1px solid var(--line); background: rgba(251,250,246,0.92); }
.mobile-drawer-button { display: none; }
.tool-nav { display: flex; align-items: center; gap: 0.2rem; min-width: 0; overflow-x: auto; }
.tool-button { flex: 0 0 auto; min-height: 2.45rem; padding: 0.35rem 0.75rem; border: 1px solid transparent; color: var(--muted); background: transparent; font-size: 0.78rem; font-weight: 750; }
.tool-button:hover { color: var(--forest); background: var(--sage-soft); }
.tool-button[aria-current="true"] { border-color: var(--line); color: var(--forest-deep); background: var(--ivory); }
.toolbar-spacer { flex: 1; }
.working-tools { display: flex; gap: 0.4rem; flex: 0 0 auto; }
.working-tools .quiet-button { min-height: 2.35rem; padding: 0.3rem 0.55rem; font-size: 0.77rem; }

.working-layout { display: grid; grid-template-columns: minmax(0, 1fr) var(--reference-width, 310px); min-height: calc(100vh - 8.25rem); }
.working-layout.reference-closed { grid-template-columns: minmax(0, 1fr); }
.primary-panel { min-width: 0; padding: clamp(1rem, 3vw, 2.35rem) clamp(0.95rem, 4vw, 4.5rem); overflow: hidden; }
.reference-panel { position: relative; min-width: 0; border-left: 1px solid var(--line); background: #f0ece3; overflow: auto; }
.reference-resizer { position: absolute; z-index: 3; top: 0; bottom: 0; left: -0.45rem; width: 0.9rem; border: 0; background: transparent; cursor: col-resize; }
.reference-resizer:hover, .reference-resizer:focus-visible { background: rgba(33, 77, 59, 0.12); outline: 0; }
.reference-panel[hidden] { display: none; }
.reference-heading { display: flex; justify-content: space-between; align-items: start; gap: 0.5rem; padding: 1.1rem 1rem 0.65rem; border-bottom: 1px solid var(--line); }
.reference-heading h2 { margin: 0; font-family: var(--font-serif); font-size: 1.3rem; font-weight: 500; }
.reference-select { width: calc(100% - 2rem); margin: 0.85rem 1rem; }
.reference-content { padding: 0 1rem 1.5rem; }

.empty-library { display: grid; place-items: center; align-content: center; min-height: 65vh; text-align: center; }
.empty-library .empty-symbol { margin-bottom: 1rem; color: var(--clay); font-family: var(--font-serif); font-size: 3rem; }
.empty-library h1 { margin: 0 0 0.5rem; font-family: var(--font-serif); font-size: 2.25rem; font-weight: 500; }
.empty-library p { max-width: 33rem; margin: 0 auto 1.4rem; color: var(--muted); }

.tool-view { max-width: 920px; margin: 0 auto; }
.tool-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: start; gap: 1rem; margin-bottom: 1.4rem; }
.tool-head > div:first-child { flex: 1 1 240px; }
.tool-head h1 { margin: 0; color: var(--forest-deep); font-family: var(--font-serif); font-size: clamp(1.9rem, 4vw, 3rem); font-weight: 500; letter-spacing: -0.04em; line-height: 1.04; }
.tool-head p { margin: 0.45rem 0 0; color: var(--muted); }
.tool-head .button-row { flex: 0 0 auto; }
.item-context { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 0.85rem; color: var(--muted); font-size: 0.78rem; }
.item-context strong { color: var(--forest); }

.write-view { max-width: 900px; margin: 0 auto; }
.focus-exit-row { position: fixed; z-index: 30; top: 1rem; right: 1rem; }
.write-meta { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0.65rem; margin-bottom: 0.75rem; }
.write-meta .write-title { grid-column: 1 / -1; }
.write-title { width: 100%; min-height: 3.7rem; padding: 0; border: 0; border-bottom: 1px solid var(--line); color: var(--forest-deep); background: transparent; font-family: var(--font-serif); font-size: clamp(2.1rem, 4vw, 3.4rem); font-weight: 500; letter-spacing: -0.05em; }
.write-title:focus-visible { outline-offset: 5px; }
.write-toolbar { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0.7rem 0 0; }
.format-button { min-width: 2.6rem; min-height: 2.35rem; padding: 0.3rem 0.55rem; border: 1px solid var(--line); border-radius: var(--radius); color: var(--muted); background: var(--ivory); font-weight: 750; }
.format-button:hover { color: var(--forest); border-color: var(--forest); }
.write-tabs { display: flex; gap: 0.2rem; margin-top: 0.8rem; border-bottom: 1px solid var(--line); }
.write-tabs button { min-height: 2.25rem; padding: 0.3rem 0.65rem; border: 0; border-bottom: 2px solid transparent; color: var(--muted); background: transparent; font-size: 0.78rem; font-weight: 700; }
.write-tabs button[aria-selected="true"] { border-bottom-color: var(--forest); color: var(--forest); }
.document-label { display: block; margin: 0.75rem 0 0.35rem; color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.document-editor { width: 100%; min-height: min(62vh, 680px); padding: 1.2rem 0.25rem 3rem; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; outline-offset: 6px; color: var(--ink); background: transparent; font-family: var(--font-serif); font-size: 1.16rem; line-height: 1.78; resize: vertical; }
.document-editor:focus { outline: 1px solid rgba(33, 77, 59, 0.35); }
.preview-pane, .markdown-preview { min-height: 300px; padding: 1rem 0 2rem; font-family: var(--font-serif); font-size: 1.12rem; line-height: 1.75; }
.preview-pane h1, .preview-pane h2, .preview-pane h3, .markdown-preview h1, .markdown-preview h2, .markdown-preview h3 { color: var(--forest-deep); font-weight: 500; line-height: 1.1; }
.preview-pane h1, .markdown-preview h1 { font-size: 2rem; }
.preview-pane h2, .markdown-preview h2 { font-size: 1.55rem; }
.preview-pane h3, .markdown-preview h3 { font-size: 1.25rem; }
.preview-pane p, .markdown-preview p { margin: 0 0 1rem; }
.preview-pane ul, .markdown-preview ul { margin: 0 0 1rem; padding-left: 1.4rem; }
.preview-pane blockquote, .markdown-preview blockquote { margin: 1.2rem 0; padding-left: 1rem; border-left: 3px solid var(--clay); color: var(--muted); }
.preview-pane code, .markdown-preview code { padding: 0.1rem 0.25rem; color: var(--forest-deep); background: var(--sage-soft); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.9em; }
.preview-pane a, .markdown-preview a { color: var(--forest); text-decoration-color: var(--clay); }
.wiki-link { padding: 0; border: 0; border-bottom: 1px solid var(--clay); color: var(--forest); background: transparent; font: inherit; }
.write-footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.75rem; align-items: center; margin-top: 0.8rem; color: var(--muted); font-size: 0.78rem; }
.goal-track { display: inline-flex; align-items: center; gap: 0.5rem; }
.goal-track progress { width: 100px; height: 0.45rem; accent-color: var(--forest); }
body.focus-mode-active .app-header,
body.focus-mode-active .sample-banner,
body.focus-mode-active .project-drawer,
body.focus-mode-active .workspace-toolbar,
body.focus-mode-active .reference-panel { display: none !important; }
body.focus-mode-active .workspace-body,
body.focus-mode-active .editor-shell,
body.focus-mode-active .working-layout { display: block; min-height: 100vh; }
body.focus-mode-active .working-layout { grid-template-columns: minmax(0, 1fr); }
body.focus-mode-active .primary-panel { min-height: 100vh; padding-top: 5vh; }
body.focus-mode-active .write-view { max-width: 980px; }

.busy-overlay { position: fixed; z-index: 100; inset: 0; display: grid; place-content: center; gap: 0.25rem; color: var(--forest-deep); background: rgba(247, 244, 237, 0.88); text-align: center; backdrop-filter: blur(3px); }
.busy-overlay strong { font-family: var(--font-serif); font-size: 1.8rem; font-weight: 500; }
.busy-overlay span { color: var(--muted); font-size: 0.82rem; }

.panel { border-top: 1px solid var(--line); }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; padding: 0.8rem 0; }
.panel-heading h2 { margin: 0; color: var(--forest-deep); font-family: var(--font-serif); font-size: 1.35rem; font-weight: 500; }
.panel-heading p { margin: 0; color: var(--muted); font-size: 0.8rem; }
.manuscript-list { display: grid; gap: 0.45rem; margin: 0; padding: 0; list-style: none; }
.manuscript-row { display: grid; grid-template-columns: 2.1rem minmax(0, 1fr) auto; align-items: center; gap: 0.65rem; min-height: 3.2rem; padding: 0.45rem 0.6rem; border: 1px solid var(--line); background: var(--ivory); }
.manuscript-row .order-number { color: var(--muted); font-size: 0.78rem; text-align: center; }
.manuscript-row strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.manuscript-row small { color: var(--muted); }
.manuscript-row .row-actions { display: flex; gap: 0.2rem; }
.row-actions button { min-width: 2.25rem; min-height: 2.25rem; padding: 0.2rem 0.35rem; border: 1px solid var(--line); color: var(--forest); background: transparent; }
.row-actions button:hover { border-color: var(--forest); background: var(--sage-soft); }
.include-list { display: grid; gap: 0.35rem; margin-top: 1.2rem; }
.include-row { display: flex; align-items: center; gap: 0.55rem; min-height: 2.55rem; padding: 0.3rem 0.45rem; border-bottom: 1px solid var(--line); }
.include-row label { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.include-row input { width: 1rem; height: 1rem; accent-color: var(--forest); }
.compiled-preview { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.compiled-preview > h2 { margin: 0; color: var(--muted); font-size: 0.75rem; letter-spacing: 0.1em; text-transform: uppercase; }

.card-columns { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.8rem; }
.card-column { min-width: 0; }
.card-column-heading { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 0.45rem; padding-bottom: 0.4rem; border-bottom: 2px solid var(--line-strong); }
.card-column-heading h2 { margin: 0; font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; }
.card-column-heading span { color: var(--muted); font-size: 0.72rem; }
.card-stack { display: grid; gap: 0.55rem; min-height: 7rem; }
.idea-card { min-width: 0; padding: 0.7rem; border: 1px solid var(--line); border-top: 3px solid var(--sand); background: var(--paper); }
.idea-card[data-color="sage"] { border-top-color: #7d9c79; }
.idea-card[data-color="rose"] { border-top-color: var(--clay); }
.idea-card[data-color="blue"] { border-top-color: #7996a6; }
.idea-card input, .idea-card textarea { width: 100%; padding: 0.35rem 0; border: 0; border-bottom: 1px solid transparent; border-radius: 0; color: var(--ink); background: transparent; }
.idea-card input { font-weight: 750; }
.idea-card textarea { min-height: 4.6rem; resize: vertical; font-size: 0.82rem; }
.idea-card input:focus, .idea-card textarea:focus { border-bottom-color: var(--forest); outline: 0; }
.card-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem; margin-top: 0.5rem; }
.card-controls select { width: 100%; min-height: 2rem; padding: 0.2rem; border: 1px solid var(--line); color: var(--muted); background: transparent; font-size: 0.72rem; }
.card-controls .card-link { grid-column: 1 / -1; }
.card-controls button { min-height: 2rem; padding: 0.2rem 0.35rem; border: 1px solid var(--line); color: var(--muted); background: transparent; font-size: 0.72rem; }
.card-controls button:hover { color: var(--forest); border-color: var(--forest); }

.outline-list { display: grid; gap: 0.3rem; }
.outline-row { display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; align-items: start; min-width: 0; margin-left: calc(var(--depth, 0) * 1.25rem); padding: 0.45rem 0.55rem; border-left: 2px solid var(--sage); background: var(--ivory); }
.outline-row.is-selected { border-left-color: var(--forest); background: var(--sage-soft); }
.outline-fields { min-width: 0; display: grid; gap: 0.25rem; }
.outline-fields input, .outline-fields textarea { width: 100%; min-width: 0; padding: 0.2rem 0.1rem; border: 0; border-bottom: 1px solid transparent; color: var(--ink); background: transparent; }
.outline-fields input { font-weight: 720; }
.outline-fields textarea { min-height: 1.8rem; resize: vertical; color: var(--muted); font-size: 0.78rem; }
.outline-fields input:focus, .outline-fields textarea:focus { border-bottom-color: var(--forest); outline: 0; }
.outline-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.2rem; }
.outline-actions button { min-width: 2rem; min-height: 2.1rem; padding: 0.2rem; border: 1px solid var(--line); color: var(--forest); background: transparent; font-size: 0.78rem; }
.outline-actions button:hover { border-color: var(--forest); background: var(--paper); }
.outline-link { width: 100%; min-height: 2rem; padding: 0.2rem; border: 1px solid var(--line); color: var(--muted); background: transparent; font-size: 0.72rem; }

.wiki-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 1rem; }
.wiki-list { display: grid; align-content: start; gap: 0.2rem; }
.wiki-list button { width: 100%; min-height: 2.5rem; padding: 0.4rem 0.55rem; border: 1px solid transparent; color: var(--ink); background: transparent; text-align: left; }
.wiki-list button:hover, .wiki-list button[aria-current="true"] { border-color: var(--line); background: var(--sage-soft); }
.wiki-editor { min-width: 0; }
.wiki-editor .field textarea { min-height: 16rem; font-family: var(--font-serif); line-height: 1.65; }
.tag-row { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tag { padding: 0.18rem 0.45rem; border-radius: 99px; color: var(--forest); background: var(--sage-soft); font-size: 0.72rem; }

.map-help { margin: 0 0 0.7rem; color: var(--muted); font-size: 0.8rem; }
.map-viewport { position: relative; min-height: 27rem; max-height: 65vh; overflow: auto; border: 1px solid var(--line-strong); background-color: var(--paper); background-image: radial-gradient(rgba(33,77,59,0.2) 1px, transparent 1px); background-size: 22px 22px; }
.map-canvas { position: relative; width: 1200px; height: 700px; }
.map-lines { position: absolute; z-index: 1; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.map-lines line { stroke: var(--forest); stroke-width: 2; stroke-opacity: 0.55; }
.map-lines text { fill: var(--muted); font-family: var(--font-sans); font-size: 12px; }
.map-node { position: absolute; z-index: 2; display: grid; grid-template-columns: 0.65rem minmax(5rem, 10rem); align-items: center; gap: 0.45rem; min-width: 8rem; max-width: 12rem; min-height: 2.7rem; padding: 0.4rem 0.55rem; border: 1px solid var(--line-strong); border-left: 4px solid var(--sand); border-radius: 2px; color: var(--ink); background: var(--paper); box-shadow: 0 3px 10px rgba(35,42,36,0.08); text-align: left; touch-action: none; }
.map-node[data-color="sage"] { border-left-color: #7d9c79; }
.map-node[data-color="rose"] { border-left-color: var(--clay); }
.map-node[data-color="blue"] { border-left-color: #7996a6; }
.map-node:hover, .map-node.is-selected { border-color: var(--forest); box-shadow: 0 4px 15px rgba(33,77,59,0.18); }
.map-node .node-dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: currentColor; }
.map-node .node-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.78rem; font-weight: 700; }
.map-edge-list { display: grid; gap: 0.35rem; margin-top: 0.8rem; }
.map-edge-row { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; padding: 0.35rem 0; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 0.78rem; }

.scratchpad-text { width: 100%; min-height: min(62vh, 680px); padding: 1rem; border: 1px solid var(--line); color: var(--ink); background: #f5f1e9; font-family: var(--font-serif); font-size: 1.12rem; line-height: 1.75; resize: vertical; }
.scratchpad-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.75rem; }

.search-results { margin-bottom: 1.3rem; padding: 0.8rem; border: 1px solid var(--line); background: var(--ivory); }
.search-results h2 { margin: 0 0 0.45rem; font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; }
.search-results-list { display: grid; gap: 0.25rem; }
.search-result { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.55rem; align-items: start; padding: 0.45rem; border: 0; color: var(--ink); background: transparent; text-align: left; }
.search-result:hover { background: rgba(255,255,255,0.65); }
.search-result strong { display: block; }
.search-result small { color: var(--muted); }
.search-empty { margin: 0; color: var(--muted); font-size: 0.82rem; }

.save-recovery { display: grid; gap: 0.55rem; margin-bottom: 1rem; padding: 0.75rem 0.85rem; border-left: 3px solid var(--danger); color: var(--danger); background: var(--clay-soft); }
.save-recovery strong { font-size: 0.84rem; }
.save-recovery p { margin: 0; font-size: 0.8rem; }
.save-recovery .button-row { margin-top: 0.15rem; }
.recovery-code { display: block; overflow-wrap: anywhere; padding: 0.6rem; border: 1px solid var(--line-strong); color: var(--forest-deep); background: var(--sage-soft); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.88rem; }

.empty-state { padding: 2rem 1rem; border: 1px dashed var(--line-strong); color: var(--muted); text-align: center; }
.empty-state strong { display: block; margin-bottom: 0.3rem; color: var(--forest-deep); font-family: var(--font-serif); font-size: 1.25rem; font-weight: 500; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.toast-region { position: fixed; z-index: 100; right: 1rem; bottom: 1rem; display: grid; gap: 0.5rem; width: min(24rem, calc(100vw - 2rem)); pointer-events: none; }
.toast { display: grid; gap: 0.35rem; padding: 0.75rem 0.85rem; border: 1px solid var(--line-strong); color: var(--ink); background: var(--paper); box-shadow: var(--shadow); pointer-events: auto; }
.toast[data-kind="error"] { border-left: 3px solid var(--danger); }
.toast[data-kind="success"] { border-left: 3px solid var(--forest); }
.toast p { margin: 0; font-size: 0.82rem; }
.toast .button-row { justify-content: flex-end; }

.modal-shell { width: min(100% - 2rem, 34rem); padding: 0; border: 0; color: var(--ink); background: transparent; }
.modal-shell::backdrop { background: rgba(22, 38, 29, 0.4); backdrop-filter: blur(3px); }
.modal-card { max-height: min(88vh, 740px); overflow: auto; padding: 1.2rem 1.25rem 1.25rem; border: 1px solid var(--line-strong); background: var(--paper); box-shadow: var(--shadow); }
.modal-heading { display: flex; justify-content: space-between; align-items: start; gap: 0.8rem; margin-bottom: 1rem; }
.modal-heading h2 { margin: 0; color: var(--forest-deep); font-family: var(--font-serif); font-size: 1.7rem; font-weight: 500; }
.modal-body { min-width: 0; }
.modal-body > p { margin: 0 0 1rem; color: var(--muted); }

@media (max-width: 1160px) {
  .app-header { grid-template-columns: auto minmax(10rem, 1fr) minmax(12rem, 1.6fr) auto; }
  .working-layout { grid-template-columns: minmax(0, 1fr) 280px; }
  .primary-panel { padding-inline: clamp(0.85rem, 3vw, 2rem); }
}

@media (max-width: 860px) {
  .auth-shell { grid-template-columns: 1fr; align-content: center; max-width: 40rem; }
  .auth-intro .brand-lockup { margin-bottom: 2.5rem; }
  .auth-intro h1 { max-width: 14ch; font-size: clamp(3.5rem, 14vw, 5.5rem); }
  .app-header { grid-template-columns: auto minmax(0, 1fr) auto; }
  .header-project { display: flex; }
  .header-project { grid-column: 2; grid-row: 1; }
  .header-search { grid-column: 1 / -1; grid-row: 2; }
  .header-tools { grid-column: 3; grid-row: 1; }
  .account-chip { display: none; }
  .working-layout { grid-template-columns: minmax(0, 1fr); }
  .workspace-toolbar { flex-wrap: wrap; }
  .workspace-toolbar .toolbar-spacer { display: none; }
  .tool-nav { flex: 1 1 100%; }
  .working-tools { margin-left: auto; }
  .reference-panel { position: fixed; z-index: 25; top: 8.25rem; right: 0; bottom: 0; width: min(90vw, 350px); box-shadow: -10px 0 30px rgba(35,42,36,0.15); }
  .working-layout:not(.reference-closed) > .primary-panel { display: none; }
  .working-layout:not(.reference-closed) > .reference-panel { position: relative; inset: auto; width: 100%; min-height: 60vh; border-left: 0; box-shadow: none; }
  .reference-resizer { display: none; }
  .card-columns { grid-template-columns: 1fr; }
  .card-column { padding-bottom: 0.4rem; }
  .wiki-layout { grid-template-columns: 180px minmax(0, 1fr); }
}

@media (max-width: 650px) {
  body { font-size: 14px; }
  .auth-shell { padding: 1.25rem; gap: 2rem; }
  .auth-intro .brand-lockup { margin-bottom: 2rem; }
  .auth-intro h1 { font-size: clamp(3.3rem, 16vw, 5rem); }
  .auth-note { margin-top: 1.4rem; }
  .auth-panel { padding: 1rem; }
  .app-header { grid-template-rows: auto auto auto; gap: 0.4rem; min-height: auto; padding: 0.55rem 0.7rem; }
  .header-brand { min-width: auto; }
  .header-brand .brand-mark { width: 1.25rem; height: 1.25rem; }
  .header-brand .brand-wordmark { font-size: 1.15rem; }
  .header-project { grid-column: 1 / -1; grid-row: 2; min-width: 0; }
  .project-select { width: 100%; }
  .header-search { grid-column: 1 / -1; grid-row: 3; }
  .header-tools { grid-column: 2; grid-row: 1; }
  .header-tools { gap: 0.25rem; min-width: 0; }
  .header-tools .quiet-button { min-height: 2.75rem; padding: 0.35rem 0.45rem; font-size: 0.75rem; }
  .save-status { grid-column: 1; grid-row: 1; max-width: 4.5rem; overflow: hidden; text-overflow: ellipsis; }
  .sample-banner { align-items: start; padding: 0.45rem 0.7rem; font-size: 0.73rem; }
  .workspace-body { display: block; min-height: calc(100vh - 10rem); }
  .project-drawer { position: fixed; z-index: 40; top: 9.6rem; left: 0; bottom: 0; width: min(88vw, 300px); overflow: auto; transform: translateX(-105%); transition: transform 160ms ease; box-shadow: 12px 0 25px rgba(35,42,36,0.15); }
  .sample-banner + .workspace-body .project-drawer { top: 11.8rem; }
  .project-drawer.is-open { transform: translateX(0); }
  .drawer-close { display: inline-flex; }
  .workspace-toolbar { position: sticky; z-index: 15; top: 9.6rem; display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto auto auto; min-height: auto; padding: 0.4rem 0.65rem; }
  .sample-banner + .workspace-body .workspace-toolbar { top: 11.8rem; }
  .mobile-drawer-button { display: inline-flex; }
  .tool-nav { grid-column: 1 / -1; grid-row: 2; width: 100%; order: 2; flex: none; }
  .toolbar-spacer { display: none; }
  .working-tools { grid-column: 1 / -1; grid-row: 3; justify-content: flex-end; order: 3; }
  .working-tools .quiet-button { width: auto; min-height: 2.75rem; overflow: visible; padding: 0.4rem 0.7rem; font-size: 0.78rem; }
  .primary-panel { padding: 1rem 0.8rem 3rem; }
  .tool-head { display: block; }
  .tool-head .button-row { margin-top: 0.75rem; }
  .write-meta { grid-template-columns: minmax(0, 1fr) 1fr; }
  .write-meta .write-title { grid-column: 1 / -1; }
  .write-meta > .field:last-child { grid-column: 2; }
  .document-editor { min-height: 55vh; font-size: 1.08rem; }
  .write-footer { align-items: start; flex-direction: column; }
  .manuscript-row { grid-template-columns: 1.6rem minmax(0, 1fr); }
  .manuscript-row .row-actions { grid-column: 2; justify-content: flex-start; }
  .wiki-layout { grid-template-columns: 1fr; }
  .wiki-list { display: flex; gap: 0.3rem; overflow-x: auto; padding-bottom: 0.3rem; }
  .wiki-list button { flex: 0 0 auto; width: auto; min-width: 9rem; }
  .map-viewport { min-height: 23rem; }
  .map-canvas { width: 960px; height: 600px; }
  .reference-panel { top: 12.8rem; }
  .modal-shell { width: calc(100% - 1rem); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
