/* Vellum — editor styles */

:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #f9f8f5;
  --hover: rgba(20, 20, 30, .05);
  --ink: #1b1b1d;
  --ink-2: #48484e;
  --muted: #86868d;
  --line: #e7e5df;
  --line-2: #d6d3ca;
  --accent: #3046c9;
  --accent-ink: #ffffff;
  --accent-soft: rgba(48, 70, 201, .10);
  --danger: #c0392b;
  --ok: #2f7d4f;
  --warn: #b26a00;
  --shadow-sm: 0 1px 2px rgba(20, 20, 30, .06);
  --shadow: 0 1px 2px rgba(20, 20, 30, .05), 0 14px 36px rgba(20, 20, 30, .10);
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --top: 52px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111113; --surface: #19191c; --surface-2: #1f1f23; --hover: rgba(255, 255, 255, .06);
    --ink: #ececf0; --ink-2: #b8b8c0; --muted: #7d7d86; --line: #2a2a30; --line-2: #383840;
    --accent: #8d9dff; --accent-ink: #0c0e1a; --accent-soft: rgba(141, 157, 255, .15);
    --danger: #ff7b6d; --ok: #6fcf97; --warn: #f0b45a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4); --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 14px 36px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111113; --surface: #19191c; --surface-2: #1f1f23; --hover: rgba(255, 255, 255, .06);
  --ink: #ececf0; --ink-2: #b8b8c0; --muted: #7d7d86; --line: #2a2a30; --line-2: #383840;
  --accent: #8d9dff; --accent-ink: #0c0e1a; --accent-soft: rgba(141, 157, 255, .15);
  --danger: #ff7b6d; --ok: #6fcf97; --warn: #f0b45a;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4); --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 14px 36px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 var(--ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.i.big { width: 40px; height: 40px; stroke-width: 1.25; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line-2); background: var(--surface);
  cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn .i { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.sm { height: 32px; padding: 0 10px; }
.btn:disabled { opacity: .55; cursor: default; }

.ib {
  width: 36px; height: 36px; display: inline-grid; place-items: center; flex: none;
  border: 0; background: transparent; border-radius: 8px; cursor: pointer; color: var(--ink-2);
}
.ib:hover { background: var(--hover); color: var(--ink); }

/* ---------- Auth ---------- */
.auth {
  min-height: 100dvh; display: grid; place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 16px 24px;
  background: radial-gradient(1100px 560px at 50% -12%, var(--accent-soft), transparent 62%), var(--bg);
}
.auth-card {
  width: 100%; max-width: 410px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); padding: 28px;
}
.brand-lg { display: flex; align-items: center; gap: 10px; font: 600 24px/1 var(--serif); letter-spacing: -.01em; }
.brand-lg .i { width: 26px; height: 26px; color: var(--accent); }
.auth-sub { color: var(--muted); margin: 8px 0 20px; }
.seg {
  display: grid; grid-template-columns: 1fr 1fr; padding: 3px; margin-bottom: 18px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
}
.seg button { border: 0; background: transparent; height: 32px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 500; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

form label { display: block; font-size: 12.5px; font-weight: 500; color: var(--ink-2); margin-bottom: 12px; }
form label input:not([type=checkbox]) {
  display: block; width: 100%; margin-top: 6px; height: 40px; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: 8px; background: var(--surface); font-size: 15px;
}
form label input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.check { display: flex !important; gap: 10px; align-items: flex-start; font-weight: 400 !important; line-height: 1.45; }
.check input { margin-top: 3px; accent-color: var(--accent); flex: none; }
.reg-only { display: none; }
#authForm.register .reg-only { display: block; }

/* Human check (Cloudflare Turnstile on verify.html) */
.verified { display: none; align-items: center; gap: 8px; margin: 0 0 14px; padding: 9px 12px; border-radius: 8px; background: var(--accent-soft); color: var(--ink-2); font-size: 13px; }
.verified .i { width: 16px; height: 16px; color: var(--ok); }
#authForm.register.captcha-ok .verified { display: flex; }
.captcha-box { min-height: 72px; display: grid; place-items: center; margin-bottom: 4px; }
.back-btn { width: 100%; margin-top: 12px; text-decoration: none; color: var(--ink); }
.fine a { color: inherit; }
.meter { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; margin: -4px 0 6px; }
.meter span { display: block; height: 100%; width: 0; background: var(--danger); transition: width .2s, background .2s; }
.hint { font-size: 12px; color: var(--muted); margin: 0 0 12px; }
.msg { min-height: 1.2em; font-size: 13px; color: var(--danger); margin: 10px 0 0; }
.msg.neutral { color: var(--ink-2); }
#authSubmit { width: 100%; height: 42px; margin-top: 6px; }
.fine { font-size: 12px; color: var(--muted); margin: 16px 0 0; line-height: 1.5; }
.opt { color: var(--muted); font-weight: 400; }

/* ---------- App shell ---------- */
.app { height: 100dvh; display: grid; grid-template-rows: auto 1fr; }
.topbar {
  display: flex; align-items: center; gap: 4px; min-width: 0;
  height: calc(var(--top) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 10px 0;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font: 600 17px var(--serif); padding: 0 10px 0 4px; flex: none; }
.brand .i { color: var(--accent); }

.tabs {
  flex: 1; min-width: 0; height: 100%; display: flex; align-items: flex-end; gap: 2px;
  padding-top: 8px; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; flex: none; display: flex; align-items: center; gap: 6px;
  height: 100%; min-width: 120px; max-width: 220px; padding: 0 6px 0 12px;
  border: 1px solid transparent; border-bottom: 0; border-radius: 9px 9px 0 0;
  color: var(--muted); cursor: pointer; user-select: none; margin-bottom: -1px;
}
.tab:hover { background: var(--hover); color: var(--ink-2); }
.tab[aria-selected="true"] { background: var(--surface-2); border-color: var(--line); color: var(--ink); }
.tab .t { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tab .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; display: none; }
.tab.dirty .dot { display: block; }
.tab .x {
  width: 22px; height: 22px; display: grid; place-items: center; flex: none;
  border: 0; border-radius: 5px; background: transparent; color: inherit; cursor: pointer; opacity: .55;
}
.tab .x:hover { background: var(--hover); opacity: 1; }
.tab .x .i { width: 14px; height: 14px; }

.top-right { display: flex; align-items: center; gap: 2px; margin-left: 4px; flex: none; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; margin-right: 4px;
  border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line);
  font-size: 12px; color: var(--ink-2); white-space: nowrap;
}
.pill .i { width: 14px; height: 14px; color: var(--ok); }
.pill.saving .i { color: var(--muted); }
.pill.unsaved .i, .pill.offline .i { color: var(--warn); }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; min-width: 240px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 10px; border-radius: 7px; cursor: pointer; }
.menu button:hover { background: var(--hover); }
.menu-head { padding: 8px 10px 10px; margin-bottom: 4px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }

.body { display: grid; grid-template-columns: 264px 1fr; min-height: 0; }

/* ---------- Sidebar ---------- */
.sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--line); }
.side-head { display: flex; gap: 8px; padding: 12px; }
.search {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); color: var(--muted);
}
.search .i { width: 15px; height: 15px; }
.search input { border: 0; outline: 0; background: transparent; width: 100%; min-width: 0; color: var(--ink); }
.doclist { list-style: none; margin: 0; padding: 2px 8px 12px; overflow-y: auto; flex: 1; }
.doc { display: flex; align-items: center; border-radius: 8px; }
.doc:hover { background: var(--hover); }
.doc.active { background: var(--accent-soft); }
.doc .open { flex: 1; min-width: 0; border: 0; background: transparent; text-align: left; padding: 8px 10px; cursor: pointer; border-radius: 8px; }
.doc .title { display: block; font-weight: 500; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.doc .when { display: block; font-size: 12px; color: var(--muted); margin-top: 1px; }
.doc .del { opacity: 0; width: 30px; height: 30px; margin-right: 4px; }
.doc .del .i { width: 16px; height: 16px; }
.doc:hover .del, .doc:focus-within .del { opacity: 1; }
@media (hover: none) { .doc .del { opacity: .6; } }
.empty-list { padding: 24px 12px; color: var(--muted); font-size: 13px; text-align: center; }
.side-foot { display: flex; align-items: center; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }
.side-foot .i { width: 14px; height: 14px; color: var(--ok); }

/* ---------- Main ---------- */
.main { display: grid; grid-template-rows: auto 1fr auto; min-width: 0; min-height: 0; background: var(--bg); }

.toolbar {
  display: flex; align-items: center; gap: 2px; padding: 6px 8px; min-height: 46px;
  background: var(--surface-2); border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }
.toolbar.disabled { opacity: .45; pointer-events: none; }
.tb-group { display: flex; align-items: center; gap: 2px; padding: 0 6px; flex: none; border-right: 1px solid var(--line); }
.tb-group:last-child { border-right: 0; }
.tb {
  position: relative; min-width: 32px; height: 32px; padding: 0 6px; display: inline-grid; place-items: center;
  border: 0; background: transparent; border-radius: 6px; cursor: pointer; color: var(--ink-2); font-size: 15px;
}
.tb:hover { background: var(--hover); color: var(--ink); }
.tb.on { background: var(--accent-soft); color: var(--accent); }
.tb:disabled { opacity: .35; cursor: default; background: transparent; }
.tb b, .tb i, .tb u, .tb s { font-family: var(--serif); font-size: 16.5px; line-height: 1; }
.tb-sel {
  height: 32px; padding: 0 22px 0 8px; border: 1px solid transparent; border-radius: 6px; cursor: pointer;
  appearance: none; -webkit-appearance: none; color: var(--ink-2);
  background-color: transparent;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 12px) 14px, calc(100% - 8px) 14px;
  background-size: 4px 4px; background-repeat: no-repeat;
}
.tb-sel:hover { background-color: var(--hover); color: var(--ink); }
.tb-sel option { background: var(--surface); color: var(--ink); }
#blockSel { width: 116px; }
#fontSel { width: 112px; }
#sizeSel { width: 62px; }
#weightSel { width: 100px; }
.color input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.swatch { font: 600 16px/1.05 var(--serif); padding: 0 2px; border-bottom: 3px solid currentColor; }

.canvas { position: relative; overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
.canvas.loading .page { opacity: .35; pointer-events: none; transition: opacity .15s; }
.page {
  max-width: 820px; margin: 28px auto 80px; padding: 56px 72px 72px; min-height: calc(100% - 108px);
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-sm);
}
.doc-title {
  display: block; width: 100%; padding: 0; margin: 0 0 18px; border: 0; outline: 0; background: transparent;
  font: 600 34px/1.15 var(--serif); letter-spacing: -.015em; color: var(--ink);
}
.doc-title::placeholder { color: var(--muted); opacity: .55; }

.editor {
  min-height: 50vh; outline: 0; caret-color: var(--accent);
  font: 16px/1.7 var(--ui); color: var(--ink); overflow-wrap: anywhere;
}
.editor > :first-child { margin-top: 0; }
.editor p, .editor div { margin: 0 0 .8em; }
.editor h1 { font: 650 2em/1.2 var(--serif); letter-spacing: -.015em; margin: 1.1em 0 .45em; }
.editor h2 { font: 600 1.55em/1.25 var(--serif); letter-spacing: -.01em; margin: 1em 0 .4em; }
.editor h3 { font: 600 1.22em/1.35 var(--ui); margin: 1em 0 .35em; }
.editor h4 { font: 650 .8em/1.4 var(--ui); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-2); margin: 1.3em 0 .35em; }
.editor blockquote {
  margin: 1em 0; padding: .15em 0 .15em 1.1em; border-left: 3px solid var(--accent);
  color: var(--ink-2); font-family: var(--serif); font-size: 1.08em;
}
.editor blockquote p { margin: 0 0 .4em; }
.editor pre {
  margin: 1em 0; padding: 12px 14px; white-space: pre-wrap;
  font: 13.5px/1.6 var(--mono); background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
}
.editor code { font-family: var(--mono); font-size: .9em; }
.editor a { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; cursor: pointer; }
.editor ul, .editor ol { padding-left: 1.6em; margin: 0 0 .8em; }
.editor li { margin: .2em 0; }
.editor li > p { margin: 0; }

.empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; color: var(--muted); }
.empty p { margin: 0 0 4px; }

.statusbar {
  display: flex; align-items: center; gap: 10px; padding: 0 16px calc(env(safe-area-inset-bottom));
  height: calc(30px + env(safe-area-inset-bottom));
  font-size: 12px; color: var(--muted); background: var(--surface-2); border-top: 1px solid var(--line);
}
.grow { flex: 1; }

/* ---------- Overlays ---------- */
.popover {
  position: fixed; z-index: 60; display: flex; align-items: center; gap: 2px;
  max-width: min(440px, calc(100vw - 24px)); padding: 5px 5px 5px 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); font-size: 13px;
}
.popover a { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; color: var(--accent); text-decoration: none; margin-right: 6px; }
.popover a span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.popover a:hover span { text-decoration: underline; }
.popover a .i { width: 14px; height: 14px; }
.popover button { height: 28px; padding: 0 9px; border: 0; background: transparent; border-radius: 6px; cursor: pointer; color: var(--ink-2); flex: none; }
.popover button:hover { background: var(--hover); color: var(--ink); }

dialog {
  width: min(420px, calc(100vw - 32px)); padding: 22px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 10, 15, .38); backdrop-filter: blur(2px); }
dialog h3 { margin: 0 0 14px; font: 600 19px var(--serif); }
dialog p { color: var(--ink-2); margin: 0 0 8px; line-height: 1.5; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.toast {
  position: fixed; left: 50%; bottom: calc(44px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 80;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 10px;
  background: var(--ink); color: var(--bg); font-size: 13px; box-shadow: var(--shadow);
}

.only-mobile { display: none; }
.scrim { display: none; }

/* ---------- Tablet & phone ---------- */
@media (max-width: 860px) {
  .only-mobile { display: inline-grid; }
  .topbar { flex-wrap: wrap; height: auto; padding: env(safe-area-inset-top) 6px 0; row-gap: 0; }
  .topbar > .ib, .topbar > .brand, .top-right { height: 48px; }
  .brand { padding-left: 2px; }
  .top-right { margin-left: auto; }
  .tabs { order: 10; flex: 1 0 100%; height: 40px; padding-top: 4px; }
  .tab { min-width: 104px; max-width: 180px; }
  .pill #statusText { display: none; }
  .pill { padding: 0 8px; }

  .body { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 40; width: min(86vw, 320px);
    padding-top: env(safe-area-inset-top); transform: translateX(-102%);
    transition: transform .22s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 39; background: rgba(0, 0, 0, .32); }

  .toolbar { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent); padding-right: 32px; }
  .page { margin: 0; padding: 22px 18px 72px; min-height: 100%; border: 0; border-radius: 0; box-shadow: none; }
  .doc-title { font-size: 27px; margin-bottom: 12px; }
  .editor { font-size: 17px; }
}
@media (max-width: 420px) {
  .brand span { display: none; }
}
@media (pointer: coarse) {
  .tb { min-width: 40px; height: 40px; }
  .tb-sel { height: 40px; background-position: calc(100% - 12px) 18px, calc(100% - 8px) 18px; }
  .ib { width: 40px; height: 40px; }
  .tab .x { width: 28px; height: 28px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
