:root {
  color-scheme: light dark;
  --bg: #fafaf9;
  --fg: #1c1917;
  --muted: #78716c;
  --border: #e7e5e4;
  --card: #ffffff;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --accent-weak: #dbeafe;
  --danger: #b91c1c;
  --radius: 6px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0a09;
    --fg: #fafaf9;
    --muted: #a8a29e;
    --border: #292524;
    --card: #1c1917;
    --accent: #60a5fa;
    --accent-fg: #0c0a09;
    --accent-weak: #1e3a8a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--fg);
  background: var(--bg);
}

.app { display: flex; flex-direction: column; height: 100vh; min-height: 0; }
.muted { color: var(--muted); font-size: 0.875em; }
.error { color: var(--danger); font-size: 0.875em; margin: 0.5rem 0 0; }

/* ---------------------------------------------------------------------------
   Account chip — top-right, only when signed in
   --------------------------------------------------------------------------- */
.account-chip {
  position: fixed; top: 0.75rem; right: 0.75rem;
  z-index: 20;
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.85em;
  background: var(--card); border: 1px solid var(--border);
  padding: 0.25rem 0.6rem 0.25rem 0.75rem;
  border-radius: 999px;
}
.account-email { font-weight: 500; }
/* Don't overlap the doc header buttons. The brand link doubles as the
   "back to landing" affordance, so signing out is one click away. */
[data-state="doc"] .account-chip { display: none !important; }

/* ---------------------------------------------------------------------------
   Card states (signin, landing, claim)
   --------------------------------------------------------------------------- */
.card-state {
  flex: 1; display: grid; place-items: center; padding: 2rem;
}
.card {
  width: 100%; max-width: 420px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 2rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.04);
}
.card h1 { margin: 0 0 0.25rem; font-size: 1.75rem; letter-spacing: -0.02em; }
.card form { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1rem; }

.field { display: block; }
.field > span { display: block; font-weight: 500; margin-bottom: 0.25rem; font-size: 0.9em; }
.field > span small { color: var(--muted); font-weight: 400; }
.field input {
  width: 100%; padding: 0.55rem 0.75rem;
  border: 1px solid var(--border); background: var(--bg); color: var(--fg);
  border-radius: var(--radius); font: inherit;
}
.field input:focus { border-color: var(--accent); outline: 2px solid var(--accent-weak); outline-offset: -1px; }

button {
  font: inherit; color: var(--fg); background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.45rem 0.85rem; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary {
  background: var(--accent); color: var(--accent-fg); border-color: var(--accent);
}
button.primary:hover:not(:disabled) { filter: brightness(1.1); }
button.primary-block { width: 100%; padding: 0.7rem; font-size: 1em; }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--card); border-color: var(--border); }
button.ghost-block {
  width: 100%; padding: 0.7rem; font-size: 0.95em;
  background: transparent; border: 1px solid var(--border); color: var(--muted);
}
button.ghost-block:hover { color: var(--fg); border-color: var(--accent); }
button.back-btn {
  background: transparent; border: none; color: var(--muted);
  padding: 0.4rem 0; font-size: 0.875em; cursor: pointer;
  align-self: flex-start;
}
button.back-btn:hover { color: var(--fg); }

.link-btn {
  background: transparent; border: none; color: var(--accent);
  text-decoration: underline; cursor: pointer; padding: 0.25rem 0; font: inherit;
  text-align: left; align-self: flex-start;
  font-size: 0.875em;
}

/* Dropzone — also acts as a click target for the file input. */
.dropzone {
  display: block; margin: 1rem 0; padding: 1.75rem 1rem;
  border: 1.5px dashed var(--border); border-radius: 10px;
  text-align: center; background: var(--bg); cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.is-dragging { border-color: var(--accent); background: var(--accent-weak); }
.dropzone input[type="file"] { display: none; }
.dropzone p { margin: 0; }
.dropzone .dropzone-primary { font-weight: 500; margin-bottom: 0.25rem; }
.dropzone code { font-family: var(--mono); background: var(--border); padding: 0 4px; border-radius: 4px; }

/* ---------------------------------------------------------------------------
   Doc state
   --------------------------------------------------------------------------- */
.doc { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.doc-header {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.5rem 1rem; border-bottom: 1px solid var(--border);
  background: var(--card);
}
.brand-link {
  text-decoration: none; color: var(--muted);
  font-size: 1.1em; line-height: 1; padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
}
.brand-link:hover { color: var(--fg); background: var(--bg); }
.doc-title {
  font-weight: 500; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 50ch;
}
.sealed-icon { font-size: 0.95em; opacity: 0.85; }
.header-spacer { flex: 1; }
.header-actions { display: flex; align-items: center; gap: 0.4rem; position: relative; }

.share-wrap, .menu-wrap { position: relative; }

.popover {
  position: absolute; top: calc(100% + 8px); right: 0;
  min-width: 340px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  padding: 1rem;
  z-index: 50;
}
.popover-heading {
  margin: 0 0 0.75rem; font-size: 0.9em; font-weight: 600;
  color: var(--fg);
}
.share-popover { min-width: 360px; }
.share-option { display: flex; flex-direction: column; gap: 0.4rem; }
.share-option-head { display: flex; align-items: center; gap: 0.5rem; font-size: 0.95em; }
.share-option-icon { font-size: 1.05em; }
.share-option-sub { margin: 0; font-size: 0.85em; }
.share-option button { align-self: flex-start; }
.popover-rule { border: none; border-top: 1px solid var(--border); margin: 0.85rem 0; }

/* Tooltip dot — small "i" with native title hover for details. */
.info-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px;
  border-radius: 50%; border: 1px solid var(--border);
  font: 600 10px var(--mono); color: var(--muted);
  cursor: help; user-select: none;
}
.info-dot:hover { color: var(--fg); border-color: var(--accent); }

.seal-creator-hint {
  margin-top: 1rem; font-size: 0.8em;
  font-family: var(--mono); word-break: break-all;
}

.menu {
  position: absolute; top: calc(100% + 8px); right: 0;
  min-width: 200px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  padding: 0.25rem;
  z-index: 50;
  display: flex; flex-direction: column;
}
.menu button {
  text-align: left; background: transparent; border: none; border-radius: 4px;
  padding: 0.45rem 0.65rem; font-size: 0.9em;
}
.menu button:hover { background: var(--bg); }

.presence { display: flex; gap: 4px; }
.avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white;
  font-size: 0.7em; font-weight: 600;
  border: 1px solid var(--card);
  cursor: default; user-select: none;
}
.avatar-more { background: var(--muted); color: white; }

.doc-panes {
  flex: 1; display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  min-height: 0;
}
@media (max-width: 800px) { .doc-panes { grid-template-columns: 1fr; } }
.pane { min-height: 0; overflow: auto; }
.pane-md { padding: 2rem 2.5rem; }
.markdown-body { max-width: 820px; margin: 0 auto; }
.pane-comments {
  border-left: 1px solid var(--border);
  background: var(--card);
  display: flex; flex-direction: column; min-height: 0;
}

.comments-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--border);
  font-size: 0.875em; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
}
.unread-indicator {
  background: var(--accent); color: var(--accent-fg); border: none;
  padding: 2px 10px; border-radius: 999px; font-size: 0.75em; cursor: pointer;
  text-transform: none; letter-spacing: 0;
}

.comments { flex: 1; overflow-y: auto; padding: 0.5rem 1rem; }
.comment {
  padding: 0.6rem 0; border-bottom: 1px solid var(--border);
  animation: fade-in 200ms ease;
}
.comment:last-child { border-bottom: none; }
.comment-head {
  display: flex; gap: 0.5rem; align-items: baseline; font-size: 0.875em;
}
.comment-author { font-weight: 600; }
.comment-time { color: var(--muted); font-size: 0.75em; }
.comment-body { margin-top: 0.25rem; white-space: pre-wrap; word-wrap: break-word; }
.comment.pending { opacity: 0.6; }

.typing {
  padding: 0.25rem 1rem 0;
  color: var(--muted);
  font-size: 0.8em; font-style: italic;
  min-height: 1.4em;
}

.compose {
  border-top: 1px solid var(--border); padding: 0.75rem 1rem;
  display: flex; flex-direction: column; gap: 0.5rem; background: var(--card);
}
.compose textarea {
  width: 100%; resize: vertical; min-height: 60px;
  padding: 0.5rem; border: 1px solid var(--border); background: var(--bg);
  color: var(--fg); border-radius: var(--radius); font: inherit;
}
.compose-row { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }

/* ---------------------------------------------------------------------------
   Modals (seal, invite)
   --------------------------------------------------------------------------- */
.modal {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--fg);
  padding: 0;
  max-width: 520px;
  width: 92%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.4); }
.modal-body { padding: 1.5rem; }
.modal-body h2 { margin: 0 0 0.5rem; font-size: 1.25rem; }
.modal-intro { margin: 0 0 1rem; line-height: 1.4; }
.modal-actions {
  display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1.25rem;
}
.modal-cancel { background: transparent; border-color: transparent; color: var(--muted); }
.modal-cancel:hover { color: var(--fg); border-color: var(--border); }

.seal-recipients { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.4rem; }
.seal-recipient-row { display: flex; gap: 0.4rem; }
.seal-recipient-row input {
  flex: 1; padding: 0.4rem 0.6rem;
  border: 1px solid var(--border); background: var(--bg); color: var(--fg);
  border-radius: var(--radius); font: inherit;
}
.seal-recipient-row .seal-remove {
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  font-size: 1.1em; padding: 0 0.4rem;
}
.seal-add {
  background: transparent; border: 1px dashed var(--border); color: var(--muted);
  width: 100%; padding: 0.4rem; margin-top: 0.4rem; cursor: pointer;
}
.seal-add:hover { color: var(--fg); border-color: var(--accent); }

.seal-links { display: flex; flex-direction: column; gap: 0.6rem; }
.seal-link-row {
  display: flex; flex-direction: column; gap: 0.25rem;
  padding: 0.6rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg);
}
.seal-link-email {
  font-weight: 600; font-size: 0.9em;
  display: flex; align-items: center; gap: 0.5rem;
}
.seal-mode-badge {
  font-size: 0.7em;
  padding: 2px 8px; border-radius: 999px;
  font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.seal-mode-fragment { background: #fef3c7; color: #92400e; }
@media (prefers-color-scheme: dark) {
  .seal-mode-fragment { background: #451a03; color: #fcd34d; }
}
#paste-body {
  width: 100%; min-height: 240px;
  padding: 0.6rem; font: 0.875em var(--mono);
  border: 1px solid var(--border); background: var(--bg); color: var(--fg);
  border-radius: var(--radius); resize: vertical;
}

.seal-link-url-row { display: flex; gap: 0.4rem; align-items: center; }
.seal-link-url {
  flex: 1; font-family: var(--mono); font-size: 0.7em;
  background: var(--card); padding: 0.4rem; border: 1px solid var(--border);
  border-radius: 4px; word-break: break-all; user-select: all;
}

/* ---------------------------------------------------------------------------
   Toast + debug strip
   --------------------------------------------------------------------------- */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: var(--fg); color: var(--bg); padding: 0.5rem 1rem;
  border-radius: var(--radius); font-size: 0.875em;
  animation: toast-in 200ms ease;
  z-index: 100;
}

.debug-strip {
  position: fixed; bottom: 0; left: 0; right: 0;
  padding: 0.25rem 0.75rem;
  background: rgba(0, 0, 0, 0.05);
  border-top: 1px solid var(--border);
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  display: flex; gap: 1rem;
  z-index: 90;
}
@media (prefers-color-scheme: dark) {
  .debug-strip { background: rgba(255, 255, 255, 0.04); }
}
.debug-strip a { color: var(--accent); text-decoration: none; }
.debug-strip a:hover { text-decoration: underline; }

@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------------------------------------------------------------------------
   GitHub-ish markdown styling
   --------------------------------------------------------------------------- */
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 { line-height: 1.25; }
.markdown-body h1 { font-size: 2em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.markdown-body h2 { font-size: 1.5em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.markdown-body h3 { font-size: 1.25em; }
.markdown-body pre {
  background: var(--card); border: 1px solid var(--border);
  padding: 0.75rem 1rem; border-radius: var(--radius); overflow: auto;
  font-family: var(--mono); font-size: 0.875em;
}
.markdown-body code { font-family: var(--mono); font-size: 0.875em; }
.markdown-body p > code, .markdown-body li > code {
  background: var(--card); border: 1px solid var(--border);
  padding: 0 4px; border-radius: 4px;
}
.markdown-body blockquote {
  margin: 1em 0; padding: 0 1em; border-left: 4px solid var(--border); color: var(--muted);
}
.markdown-body table { border-collapse: collapse; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 0.3em 0.75em; }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 1.5em 0; }
.markdown-body img { max-width: 100%; }
.markdown-body input[type="checkbox"] { margin-right: 0.35em; }
