/* Margin — warm, papery, quiet. */
:root {
  --paper: #faf9f7;
  --surface: #ffffff;
  --ink: #1c1b1a;
  --ink-soft: #6f6a64;
  --ink-faint: #a8a29b;
  --line: #e8e4de;
  --accent: #c2410c;
  --accent-soft: #fff1e8;
  --green: #2b8a3e;
  --green-soft: #e6f4ea;
  --red: #c92a2a;
  --red-soft: #fdecec;
  --yellow-soft: #fef3c0;
  --yellow: #f5c518;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(28, 27, 26, .05), 0 4px 16px rgba(28, 27, 26, .06);
  --shadow-lg: 0 4px 12px rgba(28, 27, 26, .08), 0 16px 48px rgba(28, 27, 26, .14);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .4em; font-weight: 650; letter-spacing: -.015em; }

/* ---------- shared controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 14px; font-weight: 500; line-height: 1;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { background: #f5f2ee; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #000; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; padding: 10px; }
.icon-btn {
  padding: 3px 6px; border-radius: 6px; color: var(--ink-faint);
  font-size: 13px; line-height: 1;
}
.icon-btn:hover { background: #f1ede8; color: var(--ink); }
.icon-danger:hover { color: var(--red); background: var(--red-soft); }
.text-input {
  width: 100%; padding: 9px 12px; font: inherit; font-size: 14px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
  color: var(--ink); outline: none;
}
.text-input:focus { border-color: var(--ink-soft); box-shadow: 0 0 0 3px rgba(28,27,26,.06); }
kbd {
  font-family: var(--sans); font-size: 11px; padding: 2px 5px;
  background: var(--surface); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; margin: 0 1px;
}

.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--ink); color: #fff; font-size: 13.5px; padding: 9px 16px;
  border-radius: 99px; box-shadow: var(--shadow-lg);
  animation: toast-in .18s ease-out;
}
.toast.out { opacity: 0; transition: opacity .3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.overlay {
  position: fixed; inset: 0; background: rgba(28, 27, 26, .35);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  animation: fade-in .12s ease-out; backdrop-filter: blur(2px);
}
@keyframes fade-in { from { opacity: 0; } }
.modal {
  width: min(520px, calc(100vw - 32px)); max-height: 85vh; overflow: auto;
  background: var(--paper); border-radius: 14px; box-shadow: var(--shadow-lg);
  padding: 24px;
}
.modal-sm { width: min(380px, calc(100vw - 32px)); }
.modal h2 { font-size: 19px; }
.modal h3 { font-size: 14px; margin: 18px 0 4px; }
.modal-sub { color: var(--ink-soft); font-size: 13.5px; margin: 0 0 14px; }
.modal-foot { display: flex; justify-content: flex-end; margin-top: 18px; }

.spinner {
  width: 22px; height: 22px; border-radius: 50%; display: inline-block;
  border: 2.5px solid var(--line); border-top-color: var(--ink-soft);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; justify-content: center; padding: 80px 0; }

.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  color: #fff; font-size: 10px; font-weight: 700; letter-spacing: .02em;
  flex: none;
}
.card-spacer { flex: 1; }

/* ---------- doc page layout ---------- */
.page-doc #app { display: flex; flex-direction: column; height: 100dvh; }
#topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; background: rgba(250, 249, 247, .92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px); z-index: 10; flex: none;
}
.logo { display: flex; align-items: center; color: var(--ink); padding: 4px; border-radius: 8px; }
.logo:hover { background: #f1ede8; }
.logo-mark { display: inline-flex; align-items: center; }
.doc-title {
  font: inherit; font-size: 15px; font-weight: 600; color: var(--ink);
  border: 1px solid transparent; background: none; border-radius: 8px;
  padding: 6px 10px; width: min(34vw, 360px); outline: none;
}
.doc-title:hover:not(:disabled) { border-color: var(--line); }
.doc-title:focus { border-color: var(--ink-soft); background: var(--surface); }
.doc-title:disabled { color: var(--ink); }
.conn { font-size: 12px; color: var(--ink-faint); }
.conn-off { color: var(--accent); }
.presence { display: flex; align-items: center; margin-right: 4px; }
.avatar-presence { width: 26px; height: 26px; font-size: 11px; border: 2px solid var(--paper); margin-left: -6px; }
.presence-more { font-size: 12px; color: var(--ink-soft); margin-left: 4px; }

.mode-group {
  display: flex; background: #efebe5; border-radius: 9px; padding: 3px; gap: 2px;
}
.mode-btn {
  padding: 5px 12px; border-radius: 7px; font-size: 13px; font-weight: 500;
  color: var(--ink-soft);
}
.mode-btn:hover { color: var(--ink); }
.mode-btn.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(28,27,26,.12); }
body[data-mode="suggest"] .mode-btn.active { color: var(--green); }

.tool-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 11px; border-radius: 8px; font-size: 13.5px; font-weight: 500;
  color: var(--ink-soft);
}
.tool-btn:hover { background: #f1ede8; color: var(--ink); }
.tool-btn.active { background: #efebe5; color: var(--ink); }
.btn-share { background: var(--ink); color: #fff; }
.btn-share:hover { background: #000; color: #fff; }
.count-badge { font-size: 11px; font-weight: 700; color: var(--accent); }
.claim-chip {
  display: inline-flex; align-items: center;
  font-size: 12.5px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); border: 1px solid #f3ceb4;
  padding: 5px 11px; border-radius: 99px; white-space: nowrap;
  cursor: pointer; text-decoration: none;
}
.claim-chip:hover { background: #ffe6d4; }
.claim-chip:disabled { opacity: .6; }

#main { display: flex; flex: 1; min-height: 0; }
#editor-wrap { flex: 1; min-width: 0; overflow-y: auto; position: relative; }
#editor { max-width: 760px; margin: 0 auto; padding: 36px 48px 50vh; }

#panel {
  width: 0; flex: none; border-left: 1px solid transparent; overflow: hidden;
  display: flex; flex-direction: column;
  transition: width .18s ease;
}
body.panel-open #panel { width: 340px; border-left-color: var(--line); }
.panel-head {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 16px 10px; flex: none; min-width: 300px;
}
.panel-title { font-weight: 650; font-size: 14px; }
.panel-counts { font-size: 12px; color: var(--ink-faint); flex: 1; }
.panel-body { overflow-y: auto; padding: 4px 14px 40px; flex: 1; min-width: 300px; }
.panel-empty { text-align: center; color: var(--ink-faint); font-size: 13.5px; padding: 36px 16px; }
.panel-empty-art { font-size: 30px; margin-bottom: 8px; color: var(--ink-faint); }
.kbd-hint { margin-top: 6px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(28,27,26,.04);
  cursor: pointer; transition: border-color .12s, box-shadow .12s;
}
.card:hover { border-color: #d9d3cb; }
.card.active { border-color: var(--ink-soft); box-shadow: var(--shadow); }
.card.resolved { opacity: .7; cursor: default; }
.card-head { display: flex; align-items: center; gap: 7px; margin-bottom: 6px; }
.card-author { font-size: 13px; font-weight: 600; }
.card-time { font-size: 11.5px; color: var(--ink-faint); }
.card-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 9px; }
.quote {
  font-size: 12px; color: var(--ink-soft);
  border-left: 3px solid var(--yellow); padding: 2px 8px; margin-bottom: 7px;
  background: #fdf9ec; border-radius: 0 6px 6px 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cm-body { font-size: 13.5px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: break-word; }
.reply { margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--line); }
.reply-btn { font-size: 12.5px; color: var(--ink-faint); margin-top: 8px; padding: 0; }
.reply-btn:hover { color: var(--accent); }
.resolved-toggle { font-size: 12.5px; color: var(--ink-faint); margin: 8px 0; display: block; }
.resolved-toggle:hover { color: var(--ink); }
.composer-input {
  width: 100%; font: inherit; font-size: 13.5px; resize: vertical;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  outline: none; background: var(--paper); margin-top: 2px;
}
.composer-input:focus { border-color: var(--ink-soft); background: var(--surface); }
.composer { cursor: default; border-color: var(--ink-soft); box-shadow: var(--shadow); }

.sg-badge {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 7px; border-radius: 99px;
}
.sg-badge-insert { background: var(--green-soft); color: var(--green); }
.sg-badge-delete { background: var(--red-soft); color: var(--red); }
.sg-text { font-family: var(--mono); font-size: 12.5px; line-height: 1.5; overflow-wrap: break-word; }
.sg-text-ins { color: var(--green); }
.sg-text-del { color: var(--red); text-decoration: line-through; }

.comment-bubble {
  position: fixed; z-index: 30;
  width: 34px; height: 34px; border-radius: 50% 50% 50% 6px;
  background: var(--ink); color: #fff; font-size: 15px;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; justify-content: center;
  animation: toast-in .15s ease-out;
}
.comment-bubble:hover { background: #000; transform: scale(1.08); }

/* ---------- editor content ---------- */
.cm-editor { outline: none !important; }
.cm-editor .cm-scroller {
  font-family: var(--mono); font-size: 15px; line-height: 1.75;
}
.cm-editor .cm-content { caret-color: var(--ink); }
.cm-editor .cm-line { padding: 0; }
.cm-editor .cm-activeLine { background: rgba(28,27,26,.025); border-radius: 4px; }
.cm-editor .cm-selectionBackground { background: #d7e3f4 !important; }
.cm-editor .cm-cursor { border-left-width: 2px; }
.cm-editor .cm-placeholder { color: var(--ink-faint); font-style: italic; }
.cm-editor .md-codeblock { background: #f4f1ec; font-size: 13.5px; }
.cm-editor .md-blockquote { border-left: 3px solid #ddd6cc; background: rgba(232, 228, 222, .25); }
.cm-editor .md-codeblock.cm-activeLine, .cm-editor .md-blockquote.cm-activeLine { background: #efebe3; }

.md-h1 { font-size: 1.7em; font-weight: 750; line-height: 1.3; }
.md-h2 { font-size: 1.4em; font-weight: 700; line-height: 1.35; }
.md-h3 { font-size: 1.2em; font-weight: 650; }
.md-h4 { font-size: 1.05em; font-weight: 650; }
.md-strong { font-weight: 700; }
.md-em { font-style: italic; }
.md-strike { text-decoration: line-through; color: var(--ink-soft); }
.md-link { color: var(--accent); }
.md-url { color: var(--ink-faint); }
.md-code { background: #f1ede8; border-radius: 4px; padding: 1px 0; }
.md-quote { color: var(--ink-soft); font-style: italic; }
.md-meta, .md-comment { color: var(--ink-faint); }
.md-list { color: var(--accent); }
.tok-keyword { color: #7c3aed; }
.tok-string { color: var(--green); }
.tok-number { color: #b45309; }
.tok-type { color: #0b7285; }
.tok-fn { color: #1971c2; }

.sg-ins { background: var(--green-soft); text-decoration: underline; text-decoration-color: var(--green); text-underline-offset: 3px; }
.sg-del { background: var(--red-soft); text-decoration: line-through; text-decoration-color: var(--red); }
.cm-hl { background: var(--yellow-soft); border-bottom: 2px solid var(--yellow); cursor: pointer; }
.mark-active.cm-hl { background: #fce588; }
.mark-active.sg-ins { background: #c9ecd2; }
.mark-active.sg-del { background: #fbd3d3; }

/* y-codemirror remote cursors */
.cm-ySelectionInfo { font-family: var(--sans) !important; font-size: 10.5px !important; padding: 2px 5px !important; border-radius: 4px !important; opacity: 1 !important; }

/* ---------- preview ---------- */
#preview { display: none; }
body.preview-on #editor { display: none; }
body.preview-on #preview { display: block; }
.prose { max-width: 720px; margin: 0 auto; padding: 40px 48px 30vh; font-size: 16.5px; line-height: 1.75; }
.prose h1 { font-size: 2em; margin: 1em 0 .4em; }
.prose h2 { font-size: 1.5em; margin: 1.4em 0 .4em; }
.prose h3 { font-size: 1.2em; margin: 1.2em 0 .3em; }
.prose p { margin: .65em 0; }
.prose pre { background: #f4f1ec; border: 1px solid var(--line); border-radius: 8px; padding: 14px; overflow-x: auto; font-size: 13.5px; line-height: 1.6; }
.prose code { font-family: var(--mono); font-size: .88em; background: #f1ede8; padding: 2px 5px; border-radius: 4px; }
.prose pre code { background: none; padding: 0; }
.prose blockquote { border-left: 3px solid var(--line); margin: 1em 0; padding: 2px 18px; color: var(--ink-soft); }
.prose img { max-width: 100%; border-radius: 8px; }
.prose table { border-collapse: collapse; width: 100%; }
.prose th, .prose td { border: 1px solid var(--line); padding: 7px 11px; text-align: left; }
.prose th { background: #f4f1ec; }
.prose hr { border: none; border-top: 1px solid var(--line); margin: 2em 0; }

/* ---------- history drawer ---------- */
.drawer {
  width: min(980px, calc(100vw - 32px)); height: min(640px, calc(100dvh - 64px));
  background: var(--paper); border-radius: 14px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 10px; }
.drawer-cols { display: flex; flex: 1; min-height: 0; border-top: 1px solid var(--line); }
.drawer-list { width: 240px; flex: none; overflow-y: auto; border-right: 1px solid var(--line); padding: 8px; }
.drawer-detail { flex: 1; overflow-y: auto; padding: 14px 20px; }
.drawer-hint { color: var(--ink-faint); font-size: 13.5px; }
.rev-day {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-faint); padding: 12px 11px 4px;
}
.rev-item {
  display: block; width: 100%; text-align: left; padding: 9px 11px;
  border-radius: 8px; margin-bottom: 2px;
}
.rev-item:hover { background: #f1ede8; }
.rev-item.active { background: var(--surface); box-shadow: var(--shadow); }
.rev-time { font-size: 13.5px; font-weight: 600; }
.rev-meta { font-size: 12px; color: var(--ink-faint); margin-top: 1px; }
.rev-actions { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.diff { font-family: var(--mono); font-size: 13px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: break-word; }
.diff > div { padding: 2px 10px; border-radius: 4px; }
.diff-del { background: var(--red-soft); color: #8c1f1f; }
.diff-ins { background: var(--green-soft); color: #1e5e2e; }
.diff-ctx { color: var(--ink-faint); }
.diff mark.dw-del { background: #f6b3b3; color: inherit; border-radius: 3px; text-decoration: line-through; }
.diff mark.dw-ins { background: #a9dfb6; color: inherit; border-radius: 3px; }

/* ---------- share dialog ---------- */
.share-row { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.share-row:last-of-type { border-bottom: none; }
.share-info { display: flex; flex-direction: column; gap: 1px; font-size: 14px; }
.share-desc { font-size: 12px; color: var(--ink-faint); }
.share-actions { display: flex; gap: 6px; }
.token-row { display: flex; align-items: center; gap: 8px; }
.token-field {
  font-family: var(--mono); font-size: 12px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px;
  overflow-x: auto; white-space: nowrap; flex: 1;
}
.cli-block {
  font-family: var(--mono); font-size: 12px; background: #211f1d; color: #e8e4de;
  border-radius: 8px; padding: 12px 14px; overflow-x: auto; margin: 6px 0 10px;
}

/* ---------- gates ---------- */
.gate { display: flex; align-items: center; justify-content: center; min-height: 100dvh; padding: 20px; }
.gate-card {
  text-align: center; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 44px 40px; max-width: 420px; box-shadow: var(--shadow);
}
.gate-card h1 { font-size: 22px; margin: 14px 0 6px; }
.gate-card p { color: var(--ink-soft); font-size: 14.5px; margin: 0 0 18px; }

/* ---------- dashboard ---------- */
.bar { display: flex; align-items: center; gap: 10px; padding: 14px 28px; }
.wordmark { font-weight: 750; font-size: 17px; letter-spacing: -.02em; }
.wordmark-xl { font-size: 26px; }
.logo-lg { display: inline-flex; }
.dash { max-width: 1060px; margin: 0 auto; padding: 18px 28px 80px; }
.dash-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 22px; }
.dash-head h1 { font-size: 26px; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.doc-card {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px; color: var(--ink); min-height: 130px;
  transition: border-color .12s, box-shadow .12s, transform .1s;
}
.doc-card:hover { border-color: #d9d3cb; box-shadow: var(--shadow); transform: translateY(-1px); }
.doc-card-title { font-weight: 650; font-size: 15.5px; }
.doc-card-excerpt { font-size: 13px; color: var(--ink-soft); line-height: 1.5; flex: 1;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.doc-card-foot { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--ink-faint); }
.dash-empty { text-align: center; padding: 90px 0; color: var(--ink-soft); }
.dash-empty p { margin: 0 0 16px; }

/* ---------- landing ---------- */
.landing {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  gap: 70px; padding: 40px; flex-wrap: wrap;
}
.landing-hero { max-width: 520px; }
.wordmark-row { display: flex; align-items: center; gap: 10px; margin-bottom: 34px; }
.landing h1 { font-size: 46px; line-height: 1.08; letter-spacing: -.03em; margin-bottom: 16px; }
.landing-sub { font-size: 16.5px; line-height: 1.65; color: var(--ink-soft); margin: 0 0 24px; }
.landing-cta-row { display: flex; align-items: center; gap: 14px; margin: 0 0 26px; flex-wrap: wrap; }
.btn-lg { padding: 12px 22px; font-size: 15.5px; border-radius: 10px; }
.landing-cta-note { font-size: 13px; color: var(--ink-faint); max-width: 220px; line-height: 1.4; }
.landing-points { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.landing-points li { font-size: 14.5px; line-height: 1.55; color: var(--ink-soft); padding-left: 22px; position: relative; }
.landing-points li::before { content: '❧'; position: absolute; left: 0; color: var(--accent); }
.landing-points strong { color: var(--ink); }
.landing-points code { font-family: var(--mono); font-size: .9em; background: #f1ede8; padding: 2px 5px; border-radius: 4px; }
.auth-card {
  width: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 26px; box-shadow: var(--shadow);
}
.auth-tabs { display: flex; background: #efebe5; border-radius: 9px; padding: 3px; gap: 2px; margin-bottom: 18px; }
.auth-tab { flex: 1; padding: 7px; border-radius: 7px; font-size: 13.5px; font-weight: 550; color: var(--ink-soft); }
.auth-tab.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(28,27,26,.12); }
.auth-card label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.auth-card .text-input { margin-top: 5px; }
.auth-err { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  #editor { padding: 24px 20px 40vh; }
  .doc-title { width: 30vw; }
  body.panel-open #panel {
    position: fixed; right: 0; top: 49px; bottom: 0; width: min(340px, 88vw);
    background: var(--paper); box-shadow: var(--shadow-lg); z-index: 20;
  }
  .tool-btn { padding: 7px 8px; }
}
@media (max-width: 700px) {
  #topbar { flex-wrap: wrap; row-gap: 4px; padding: 8px 10px; }
  .doc-title { width: auto; flex: 1; min-width: 100px; }
  #topbar .card-spacer { flex: 0; flex-basis: 100%; height: 0; order: 5; }
  .presence, .mode-group, .tool-btn { order: 6; }
  .tool-btn { font-size: 12.5px; padding: 6px 7px; }
  .mode-btn { padding: 4px 9px; font-size: 12.5px; }
  body.panel-open #panel { top: auto; height: 70dvh; border-radius: 14px 14px 0 0; border-top: 1px solid var(--line); }
  .landing { gap: 30px; padding: 28px 20px; }
  .landing h1 { font-size: 34px; }
  .auth-card { width: 100%; max-width: 380px; }
}
