:root {
  --paper: #f2efe6;
  --paper-2: #e9e5da;
  --ink: #11110f;
  --muted: #79766d;
  --line: rgba(17, 17, 15, .17);
  --soft-line: rgba(17, 17, 15, .08);
  --accent: #f04b2f;
  --violet: #6857e5;
  --lime: #d6ff3f;
  --green: #1f7a52;
  --radius: 0px;
  --ui: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: "Iowan Old Style", "Baskerville", "Times New Roman", serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(circle at 16% 8%, rgba(240,75,47,.07), transparent 20rem),
    radial-gradient(circle at 82% 78%, rgba(104,87,229,.06), transparent 26rem),
    var(--paper);
  color: var(--ink);
  font-family: var(--ui);
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button, select { cursor: pointer; }
button { border: 0; }
::selection { background: var(--lime); color: var(--ink); }

.topbar {
  height: 64px;
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr) auto;
  border-bottom: 1px solid var(--ink);
  background: rgba(242,239,230,.92);
  backdrop-filter: blur(18px);
  position: relative;
  z-index: 30;
}
.wordmark {
  background: var(--ink);
  color: var(--paper);
  padding: 0 22px;
  text-align: left;
  font-weight: 900;
  letter-spacing: -.055em;
  font-size: 26px;
  display: flex;
  align-items: center;
  gap: 3px;
}
.wordmark sup { color: var(--lime); font-family: var(--mono); font-size: 9px; letter-spacing: 0; transform: translateY(-8px); }
.project-crumb { min-width: 0; display: flex; align-items: center; gap: 10px; padding: 0 20px; }
.eyebrow { font-family: var(--mono); font-size: 9px; letter-spacing: .13em; margin: 0; text-transform: uppercase; }
.project-crumb > .eyebrow { color: var(--muted); }
.crumb-title, .branch-chip { background: transparent; white-space: nowrap; }
.crumb-title { font-family: var(--serif); font-size: 17px; overflow: hidden; text-overflow: ellipsis; max-width: 340px; }
.slash { color: var(--muted); }
.branch-chip { font-family: var(--mono); font-size: 10px; padding: 6px 8px; border: 1px solid var(--line); background: rgba(255,255,255,.28); }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding-right: 12px; }
.sync-status { display: flex; align-items: center; gap: 6px; color: var(--muted); font-family: var(--mono); font-size: 9px; text-transform: uppercase; letter-spacing: .08em; }
.sync-status i, .network-note i { width: 7px; height: 7px; background: #b5ae9b; display: inline-block; border-radius: 50%; }
.sync-status.live i, .network-note.live i { background: var(--green); box-shadow: 0 0 0 4px rgba(31,122,82,.08); }
.sync-status.warn i, .network-note.warn i { background: #d88826; }
.presence-stack { display: flex; flex-direction: row-reverse; padding-left: 8px; }
.avatar { width: 30px; height: 30px; margin-left: -8px; border: 2px solid var(--paper); display: grid; place-items: center; border-radius: 50%; font-size: 9px; font-weight: 800; letter-spacing: .02em; }
.avatar.self { outline: 1px solid var(--ink); }
.btn { min-height: 42px; padding: 0 14px; border: 1px solid var(--ink); background: transparent; font-weight: 800; font-size: 11px; letter-spacing: .01em; }
.btn:hover { transform: translateY(-1px); }
.btn.compact { min-height: 36px; }
.btn-ink { background: var(--ink); color: var(--paper); }
.btn-ink:hover { background: var(--accent); border-color: var(--accent); }
.btn-ghost { background: rgba(255,255,255,.3); }
.btn.full { width: 100%; }

.workspace { height: calc(100vh - 64px); display: grid; grid-template-columns: 290px minmax(520px, 1fr) 340px; }
.panel { min-height: 0; background: rgba(242,239,230,.7); }
.structure-panel { border-right: 1px solid var(--ink); display: flex; flex-direction: column; }
.collab-panel { border-left: 1px solid var(--ink); overflow: hidden; }
.panel-head { padding: 22px 20px 14px; display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.panel-head h2, .panel-intro h2, .dialog h2 { font-family: var(--serif); font-weight: 500; line-height: .95; letter-spacing: -.035em; margin: 6px 0 0; font-size: 25px; }
.icon-btn { width: 33px; height: 33px; background: transparent; border: 1px solid var(--ink); font-size: 19px; line-height: 1; }
.icon-btn:hover { background: var(--ink); color: var(--paper); }
.project-meter { padding: 0 20px 17px; border-bottom: 1px solid var(--line); }
.meter-copy { display: flex; justify-content: space-between; color: var(--muted); font-family: var(--mono); font-size: 9px; text-transform: uppercase; }
.meter-track { height: 3px; background: rgba(17,17,15,.1); margin-top: 9px; overflow: hidden; }
.meter-track span { display: block; height: 100%; background: var(--accent); width: 0; transition: width .25s ease; }
.section-list { overflow: auto; flex: 1; padding-bottom: 100px; scrollbar-width: thin; }
.section-card { position: relative; border-bottom: 1px solid var(--line); padding: 16px 18px 15px 52px; min-height: 88px; cursor: pointer; background: transparent; transition: background .14s ease, padding .14s ease; }
.section-card:hover { background: rgba(255,255,255,.32); }
.section-card.active { background: var(--ink); color: var(--paper); }
.section-card.active::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--lime); }
.section-no { position: absolute; left: 19px; top: 18px; font-family: var(--mono); font-size: 9px; color: var(--muted); }
.section-card.active .section-no { color: #a9a59a; }
.section-card .type { font-family: var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: .12em; font-size: 8px; }
.section-card.active .type { color: #aaa69a; }
.section-card h3 { font-family: var(--serif); font-weight: 500; font-size: 17px; line-height: 1.1; margin: 5px 0 9px; }
.section-card .mini { display: flex; justify-content: space-between; color: var(--muted); font-family: var(--mono); font-size: 8px; }
.section-card.active .mini { color: #aaa69a; }
.section-live-dot { width: 6px; height: 6px; background: var(--accent); border-radius: 50%; position: absolute; right: 13px; top: 14px; }
.structure-footer { border-top: 1px solid var(--ink); background: var(--paper); padding: 10px 14px; display: flex; flex-direction: column; gap: 2px; }
.text-btn { text-align: left; background: transparent; padding: 7px 5px; font-size: 10px; font-weight: 700; }
.text-btn:hover { text-decoration: underline; text-underline-offset: 3px; }
.text-btn.small { padding: 0; font-size: 9px; }

.editor-stage { min-width: 0; position: relative; overflow: hidden; display: flex; flex-direction: column; }
.editor-toolbar { min-height: 53px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; }
.section-meta, .editor-tools { display: flex; align-items: center; gap: 8px; }
.section-meta select, .status-pill, .tool-btn { appearance: none; background: transparent; border: 0; font-family: var(--mono); font-size: 9px; letter-spacing: .08em; text-transform: uppercase; }
.section-meta select { padding: 7px 16px 7px 0; background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%); background-position: calc(100% - 7px) 50%, calc(100% - 3px) 50%; background-size: 4px 4px, 4px 4px; background-repeat: no-repeat; }
.status-pill { border: 1px solid var(--line); padding: 6px 8px; }
.status-pill[data-status="Polished"] { background: var(--lime); color: var(--ink); border-color: var(--ink); }
.status-pill[data-status="Review"] { background: var(--violet); color: white; border-color: var(--violet); }
.tiny-rule { width: 1px; height: 18px; background: var(--line); display: inline-block; }
.tool-btn { min-width: 28px; min-height: 28px; padding: 0 6px; }
.tool-btn:hover { background: rgba(17,17,15,.07); }
.tool-btn.italic { font-style: italic; font-family: var(--serif); font-size: 14px; text-transform: none; }
.tool-btn.labeled { min-width: 44px; }
.paper { margin: clamp(14px, 3vh, 38px) auto 60px; width: min(780px, calc(100% - 60px)); flex: 1; min-height: 0; background: rgba(250,248,241,.73); border: 1px solid rgba(17,17,15,.12); box-shadow: 0 26px 65px rgba(50,43,31,.08); padding: clamp(34px, 6vh, 70px) clamp(40px, 7vw, 96px) 32px; overflow: auto; position: relative; }
.paper::before { content: ""; position: fixed; width: 7px; height: 7px; background: var(--accent); border-radius: 50%; transform: translate(-20px, 6px); }
.paper-kicker { display: flex; justify-content: space-between; gap: 20px; font-family: var(--mono); color: var(--muted); font-size: 9px; letter-spacing: .12em; text-transform: uppercase; margin-bottom: 37px; }
#activePresenceText { color: var(--violet); }
.section-title-input, .manuscript { width: 100%; resize: none; overflow: hidden; border: 0; outline: 0; background: transparent; }
.section-title-input { font-family: var(--serif); font-size: clamp(40px, 5vw, 68px); line-height: .93; letter-spacing: -.055em; min-height: 1.05em; padding: 0; margin-bottom: 38px; }
.manuscript { font-family: var(--serif); font-size: 20px; line-height: 1.68; letter-spacing: -.012em; min-height: 50vh; padding: 0 0 90px; white-space: pre-wrap; }
.manuscript::placeholder { color: #b3afa5; }
.paper-footer { position: sticky; bottom: -32px; margin: 0 -96px -32px; padding: 13px 96px; border-top: 1px solid var(--soft-line); background: rgba(250,248,241,.95); display: flex; justify-content: space-between; color: var(--muted); font-family: var(--mono); font-size: 8px; text-transform: uppercase; letter-spacing: .08em; }
.selection-bubble { position: fixed; z-index: 50; background: var(--ink); color: var(--paper); border: 1px solid var(--paper); box-shadow: 0 10px 30px rgba(0,0,0,.18); }
.selection-bubble button { background: transparent; color: inherit; padding: 8px 10px; font-size: 9px; border-right: 1px solid #555; }
.selection-bubble button:last-child { border-right: 0; }
.selection-bubble button:hover { background: var(--accent); }

.tabs { display: grid; grid-template-columns: 1fr 1fr .8fr; height: 53px; border-bottom: 1px solid var(--ink); }
.tab { background: transparent; border-right: 1px solid var(--line); font-family: var(--mono); text-transform: uppercase; font-size: 9px; letter-spacing: .08em; position: relative; }
.tab:last-child { border-right: 0; }
.tab span { margin-left: 4px; color: var(--muted); }
.tab.active { background: var(--ink); color: var(--paper); }
.tab.active span { color: var(--lime); }
.tab-view { height: calc(100% - 53px); display: none; overflow: auto; }
.tab-view.active { display: flex; flex-direction: column; }
.panel-intro { padding: 24px 20px 18px; border-bottom: 1px solid var(--line); }
.panel-intro h2 { font-size: 32px; }
.panel-intro > p:last-child { color: var(--muted); font-size: 11px; line-height: 1.55; max-width: 260px; margin: 13px 0 0; }
.comment-list { flex: 1; overflow: auto; padding-bottom: 20px; }
.comment-card { padding: 17px 20px; border-bottom: 1px solid var(--line); position: relative; }
.comment-card.resolved { opacity: .45; }
.comment-author { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 9px; }
.comment-author .who { display: flex; align-items: center; gap: 8px; font-size: 10px; font-weight: 800; }
.mini-avatar { width: 21px; height: 21px; border-radius: 50%; display: grid; place-items: center; font-size: 7px; font-weight: 900; }
.comment-author time { font-family: var(--mono); font-size: 8px; color: var(--muted); }
.comment-card p { font-family: var(--serif); font-size: 15px; line-height: 1.45; margin: 0; }
.comment-context { margin-top: 9px; padding: 8px 10px; border-left: 2px solid var(--violet); background: rgba(104,87,229,.06); font-size: 10px; color: var(--muted); line-height: 1.4; }
.suggestion-swap { margin-top: 10px; font-size: 10px; }
.suggestion-swap .from { text-decoration: line-through; color: var(--muted); }
.suggestion-swap .to { margin-top: 5px; padding: 7px; background: rgba(214,255,63,.32); font-family: var(--serif); font-size: 13px; }
.comment-actions { display: flex; gap: 10px; margin-top: 10px; }
.comment-actions button { background: transparent; padding: 0; font-size: 9px; font-weight: 800; }
.comment-actions button:hover { text-decoration: underline; }
.comment-composer { border-top: 1px solid var(--ink); padding: 13px 15px 15px; background: var(--paper); }
.composer-mode { display: flex; gap: 3px; margin-bottom: 8px; }
.mode { padding: 5px 7px; background: transparent; font-family: var(--mono); font-size: 8px; text-transform: uppercase; border: 1px solid transparent; }
.mode.active { border-color: var(--ink); }
.comment-composer textarea { width: 100%; border: 0; border-bottom: 1px solid var(--line); background: transparent; resize: none; outline: none; font-family: var(--serif); font-size: 15px; padding: 6px 2px 10px; margin-bottom: 10px; }
.comment-composer .btn { width: 100%; }

.branch-create { margin: 15px; padding: 14px; background: var(--lime); display: flex; gap: 12px; align-items: center; text-align: left; border: 1px solid var(--ink); }
.branch-plus { font-size: 24px; }
.branch-create b, .branch-create small { display: block; }
.branch-create b { font-size: 11px; }
.branch-create small { color: #555; margin-top: 3px; font-size: 9px; }
.branch-list { border-top: 1px solid var(--line); }
.branch-row { padding: 15px 18px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: 9px; align-items: start; }
.branch-glyph { font-family: var(--mono); font-size: 13px; }
.branch-row b { display: block; font-size: 11px; }
.branch-row small { display: block; margin-top: 4px; color: var(--muted); font-family: var(--mono); font-size: 8px; }
.branch-row button { background: transparent; font-size: 9px; font-weight: 800; padding: 2px 0; }
.branch-row.active { background: var(--ink); color: var(--paper); }
.branch-row.active small { color: #aaa69a; }
.branch-row.active button { color: var(--lime); }
.version-block { margin-top: 18px; border-top: 1px solid var(--ink); }
.version-head { display: flex; justify-content: space-between; padding: 13px 18px; text-transform: uppercase; font-family: var(--mono); font-size: 8px; }
.version-list { border-top: 1px solid var(--line); }
.version-row { padding: 11px 18px; display: flex; justify-content: space-between; align-items: center; gap: 10px; border-bottom: 1px solid var(--soft-line); }
.version-row span { font-size: 9px; }
.version-row time { display: block; color: var(--muted); font-family: var(--mono); font-size: 8px; margin-top: 3px; }
.version-row button { background: transparent; font-size: 8px; font-weight: 800; }

.muse-controls { padding: 15px; border-bottom: 1px solid var(--ink); }
.muse-controls select { width: 100%; border: 1px solid var(--ink); background: transparent; padding: 10px; font-family: var(--mono); font-size: 9px; margin-bottom: 8px; }
.muse-controls .btn { width: 100%; }
.muse-output { padding: 0 15px 30px; }
.muse-empty { padding: 40px 14px; text-align: center; color: var(--muted); }
.muse-empty span { font-size: 35px; color: var(--accent); }
.muse-empty p { font-family: var(--serif); font-size: 16px; line-height: 1.4; }
.spark-card { border-bottom: 1px solid var(--line); padding: 17px 4px; }
.spark-card .num { color: var(--accent); font-family: var(--mono); font-size: 8px; }
.spark-card p { font-family: var(--serif); font-size: 17px; line-height: 1.36; margin: 7px 0 9px; }
.spark-card button { background: transparent; padding: 0; font-size: 9px; font-weight: 800; }

.dialog { border: 0; padding: 0; width: min(520px, calc(100vw - 30px)); background: transparent; }
.dialog::backdrop { background: rgba(17,17,15,.44); backdrop-filter: blur(5px); }
.dialog-card { background: var(--paper); border: 1px solid var(--ink); box-shadow: 12px 12px 0 var(--ink); padding: 22px; }
.dialog-card.compact-card { width: min(430px, 100%); margin: auto; }
.dialog-head { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.dialog h2 { font-size: 39px; }
.dialog-copy { font-family: var(--serif); font-size: 15px; line-height: 1.45; color: #555149; }
.dialog label { display: block; margin-top: 14px; font-family: var(--mono); font-size: 8px; letter-spacing: .1em; }
.dialog input, .dialog textarea, .dialog select { width: 100%; border: 1px solid var(--ink); background: rgba(255,255,255,.34); padding: 11px; margin-top: 6px; outline: none; font-family: var(--ui); font-size: 12px; }
.dialog textarea { resize: vertical; }
.copy-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; margin-top: 6px; }
.copy-field input { margin: 0; border-right: 0; font-family: var(--mono); font-size: 9px; }
.copy-field button { background: var(--ink); color: var(--paper); padding: 0 12px; font-size: 9px; font-weight: 800; }
.network-note { display: flex; gap: 8px; align-items: center; margin: 13px 0; color: var(--muted); font-size: 10px; }

.toast { position: fixed; left: 50%; top: 75px; transform: translate(-50%, -14px); opacity: 0; background: var(--ink); color: var(--paper); padding: 10px 13px; z-index: 100; font-size: 10px; pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.focus-exit { position: fixed; right: 16px; top: 14px; z-index: 80; }
.focus-exit button { background: var(--ink); color: var(--paper); padding: 10px 12px; font-size: 9px; font-weight: 800; }
body.focus-mode .topbar, body.focus-mode .structure-panel, body.focus-mode .collab-panel, body.focus-mode .editor-toolbar { display: none; }
body.focus-mode .workspace { height: 100vh; display: block; }
body.focus-mode .editor-stage { height: 100vh; }
body.focus-mode .paper { width: min(790px, calc(100% - 30px)); margin-top: 24px; }

.reorder-mode .section-card { cursor: grab; }
.reorder-mode .section-card::before { content: "⋮⋮"; position: absolute; left: 17px; bottom: 12px; color: var(--muted); font-size: 10px; }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 240px minmax(480px, 1fr) 300px; }
  .topbar { grid-template-columns: 240px minmax(0,1fr) auto; }
  .wordmark { padding-left: 18px; }
  .paper { width: calc(100% - 40px); padding-left: 56px; padding-right: 56px; }
  .paper-footer { margin-left: -56px; margin-right: -56px; padding-left: 56px; padding-right: 56px; }
}
@media (max-width: 900px) {
  body { overflow: auto; }
  .topbar { grid-template-columns: auto minmax(0,1fr) auto; }
  .wordmark { width: 80px; padding: 0 12px; font-size: 19px; }
  .project-crumb > .eyebrow, .branch-chip, .slash, .sync-status, .top-actions .btn-ink { display: none; }
  .project-crumb { padding: 0 10px; }
  .crumb-title { max-width: 38vw; font-size: 15px; }
  .workspace { height: auto; min-height: calc(100vh - 64px); display: block; }
  .structure-panel { border-right: 0; border-bottom: 1px solid var(--ink); }
  .panel-head, .project-meter, .structure-footer { display: none; }
  .section-list { display: flex; overflow-x: auto; padding: 0; }
  .section-card { min-width: 180px; border-right: 1px solid var(--line); border-bottom: 0; padding-left: 40px; min-height: 75px; }
  .editor-stage { min-height: calc(100vh - 140px); }
  .paper { width: calc(100% - 24px); margin: 12px auto 20px; padding: 38px 28px 22px; }
  .paper-footer { margin: 0 -28px -22px; bottom: -22px; padding: 11px 28px; }
  .section-title-input { font-size: 44px; }
  .manuscript { font-size: 18px; }
  .collab-panel { border-left: 0; border-top: 1px solid var(--ink); min-height: 70vh; }
  .tab-view { min-height: 65vh; height: auto; }
}
@media (max-width: 560px) {
  .top-actions { padding-right: 7px; }
  .presence-stack .avatar:not(:first-child) { display: none; }
  .editor-toolbar { padding: 0 10px; }
  .tool-btn:not(.labeled), .tiny-rule { display: none; }
  .paper-kicker { margin-bottom: 28px; }
  .section-title-input { font-size: 38px; margin-bottom: 26px; }
  .manuscript { font-size: 17px; line-height: 1.62; }
  .dialog-card { box-shadow: 6px 6px 0 var(--ink); }
}
