/* Format. Warm paper, one blue, nothing that competes with the words.
   Contrast ratios are measured on --bg. */

:root {
  color-scheme: light;
  --bg: #f8f6f1;
  --bg-raised: #ffffff;
  --bg-hover: #efebe3;
  --line: #e4dfd5;
  --line-input: #8a8377;      /* 3.4:1, field edges (WCAG 1.4.11) */
  --text: #1f1d1a;            /* 15.6:1 */
  --text-dim: #5c574f;        /* 6.6:1 */
  --text-faint: #6b665d;      /* 5.3:1 */
  --mark: #a39d92;            /* Markdown marks: quiet on purpose, the text beside them carries meaning */
  --accent: #1559d0;          /* 5.8:1 */
  --accent-soft: rgba(21, 89, 208, .12);
  --pasted: #8a3ea6;          /* 6.2:1, text that arrived by paste */
  --pasted-soft: rgba(138, 62, 166, .14);
  --flag: #a3620b;            /* 4.6:1, Style Check underline */
  --strike: #9b958b;
  --shadow-menu: 0 1px 2px rgba(60, 45, 20, .08), 0 8px 28px rgba(60, 45, 20, .14);
  --shadow-sheet: 0 2px 6px rgba(60, 45, 20, .08), 0 24px 64px rgba(60, 45, 20, .18);
  --mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  --serif: ui-serif, 'New York', 'Iowan Old Style', Charter, 'Bitstream Charter', Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;
  --dur: 160ms;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --measure: 66ch;
  --type: 18px;
  /* The website's surfaces (site.css), for the sign-in, account and replay pages. */
  --bg-tint: #f0ede6;
  --line-strong: #cdc6b8;
  --accent-ink: #ffffff;      /* white on --accent 6.1:1 */
  --shadow-card: 0 1px 2px rgba(60, 45, 20, .06), 0 6px 20px rgba(60, 45, 20, .08);
  /* Layout Page: the desk around the sheet, from each theme's own ground, so every theme gets one. */
  --canvas: color-mix(in srgb, var(--bg) 94%, var(--text));
  --shadow-paper: 0 0 0 1px rgba(0, 0, 0, .05), 0 1px 2px rgba(0, 0, 0, .05), 0 12px 36px -10px rgba(0, 0, 0, .16);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #161513;
    --bg-raised: #23211e;
    --bg-hover: #2b2925;
    --line: #34312b;
    --line-input: #777166;
    --text: #ede9e2;          /* 15.1:1 */
    --text-dim: #aba59b;      /* 7.5:1 */
    --text-faint: #958f85;    /* 5.7:1 */
    --mark: #6d685f;
    --accent: #57a8ff;        /* 7.3:1 */
    --accent-soft: rgba(87, 168, 255, .16);
    --pasted: #d49bf0;        /* 8.6:1 */
    --pasted-soft: rgba(212, 155, 240, .14);
    --flag: #e0a24a;
    --strike: #6d685f;
    --shadow-menu: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 28px rgba(0, 0, 0, .5);
    --shadow-sheet: 0 2px 6px rgba(0, 0, 0, .4), 0 24px 64px rgba(0, 0, 0, .55);
    --bg-tint: #1f1d1a;
    --line-strong: #45413a;
    --accent-ink: #0b1a2e;    /* 7.9:1 on --accent */
    --shadow-card: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
    --canvas: color-mix(in srgb, var(--bg) 60%, #000);
    --shadow-paper: 0 0 0 1px rgba(255, 255, 255, .07), 0 1px 2px rgba(0, 0, 0, .3), 0 16px 44px -10px rgba(0, 0, 0, .6);
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #161513;
  --bg-raised: #23211e;
  --bg-hover: #2b2925;
  --line: #34312b;
  --line-input: #777166;
  --text: #ede9e2;
  --text-dim: #aba59b;
  --text-faint: #958f85;
  --mark: #6d685f;
  --accent: #57a8ff;
  --accent-soft: rgba(87, 168, 255, .16);
  --pasted: #d49bf0;
  --pasted-soft: rgba(212, 155, 240, .14);
  --flag: #e0a24a;
  --strike: #6d685f;
  --shadow-menu: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 28px rgba(0, 0, 0, .5);
  --shadow-sheet: 0 2px 6px rgba(0, 0, 0, .4), 0 24px 64px rgba(0, 0, 0, .55);
  --bg-tint: #1f1d1a;
  --line-strong: #45413a;
  --accent-ink: #0b1a2e;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
  --canvas: color-mix(in srgb, var(--bg) 60%, #000);
  --shadow-paper: 0 0 0 1px rgba(255, 255, 255, .07), 0 1px 2px rgba(0, 0, 0, .3), 0 16px 44px -10px rgba(0, 0, 0, .6);
}
@media (prefers-reduced-motion: reduce) {
  :root { --dur: 0ms; }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.skip { position: absolute; left: -999px; top: 8px; }
.skip:focus { left: 8px; z-index: 50; background: var(--bg-raised); padding: 8px 12px; border-radius: var(--r-md); }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
kbd { font: 12px var(--sans); color: var(--text-faint); }

/* Bar: present when you reach for it, gone while you type. */
.bar {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  height: 52px; padding: 0 12px; padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  transition: opacity var(--dur) var(--ease);
}
body.typing .bar:not(:focus-within) { opacity: 0; }
/* The live word count: in the bar, and in the corner while the bar is hidden for typing. Off in View, the bar says Stats. */
.count-off { display: none; }
body.hide-count #wordCount { display: none; }
body.hide-count .count-off { display: inline; }
.live-count {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 20; pointer-events: none;
  padding: 5px 11px; border-radius: 999px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  color: var(--text-faint); font: 500 13px/1.2 var(--sans); font-variant-numeric: tabular-nums;
  opacity: 0; transition: opacity var(--dur) var(--ease);
}
body.typing:not(.hide-count) .live-count { opacity: 1; }
.bar-start, .bar-end { display: flex; align-items: center; gap: 2px; min-width: 0; }
.doc-title {
  color: var(--text-faint); font-size: 14px; margin-left: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw;
}
.icon-btn, .text-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; min-width: 36px; padding: 0 10px; border: 0; border-radius: var(--r-md);
  background: transparent; color: var(--text-dim); font-size: 14px;
  transition: background var(--dur), color var(--dur);
}
.icon-btn { padding: 0; }
.icon-btn:hover, .text-btn:hover, .text-btn[aria-expanded='true'] { background: var(--bg-hover); color: var(--text); }
.text-btn.strong { color: var(--accent); font-weight: 600; }
.count { font-variant-numeric: tabular-nums; }

/* Menus and popovers */
.dropdown { position: relative; }
.menu, .pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
  min-width: 248px; padding: 6px;
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-menu);
}
.pop { position: fixed; top: 58px; right: 12px; width: 300px; padding: 16px; }
.menu > button {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  height: 36px; padding: 0 10px; border: 0; border-radius: var(--r-sm);
  background: none; font-size: 14px; text-align: left;
}
.menu > button:hover, .menu > button:focus-visible { background: var(--bg-hover); outline: none; }
.menu > button[aria-checked]::before {
  content: ''; width: 14px; height: 14px; margin-right: 8px; flex: none;
  border-radius: 4px; border: 1px solid var(--line-input);
}
.menu > button[aria-checked='true']::before {
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M3.5 7.2l2.3 2.3 4.7-5' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E") center/14px;
  border-color: var(--accent);
}
.menu > button span:first-of-type { flex: 1; }
.menu-val { color: var(--text-faint); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 4px; }
.menu-label { margin: 6px 10px 6px; font: 11px var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--text-faint); }

.seg { display: flex; gap: 2px; padding: 2px; margin: 0 4px 4px; background: var(--bg-hover); border-radius: var(--r-md); border: 0; }
.seg button, .seg label span {
  flex: 1; display: flex; align-items: center; justify-content: center;
  height: 30px; border: 0; border-radius: var(--r-sm); background: none; font-size: 13px; color: var(--text-dim);
}
.seg button[aria-checked='true'], .seg input:checked + span { background: var(--bg-raised); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.seg label { flex: 1; display: flex; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.seg.wide { margin: 0 0 16px; padding: 2px; }
.seg.wide span { height: 34px; font-size: 14px; }
.seg legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 16px; }
.stats dt { font: 10.5px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--text-faint); }
.stats dd { margin: 4px 0 0; font: 700 22px/1.2 var(--sans); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.goal { display: grid; grid-template-columns: 1fr 96px; align-items: center; gap: 8px; padding: 12px 0; border-top: 1px solid var(--line); }
.goal label { font-size: 14px; color: var(--text-dim); }
.goal input { height: 32px; padding: 0 8px; border: 1px solid var(--line-input); border-radius: var(--r-sm); background: var(--bg); text-align: right; }
.meter, .share { grid-column: 1 / -1; height: 4px; border-radius: 4px; background: var(--bg-hover); overflow: hidden; }
.meter span, .share span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 300ms var(--ease); }
.share { background: var(--pasted); margin-top: 8px; }
.share span { background: var(--text); }
.authors { padding-top: 12px; border-top: 1px solid var(--line); }
.authors-line { display: flex; align-items: center; gap: 8px; margin: 0 0 4px; font-size: 14px; color: var(--text-dim); }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-typed { background: var(--text); }
.dot-pasted { background: var(--pasted); }

/* The page */
.stage { display: flex; min-height: 100dvh; }
.sheet { flex: 1; min-width: 0; padding: max(16vh, 96px) 24px 50vh; }
.editor {
  position: relative; max-width: var(--measure); margin: 0 auto;
  font: var(--type)/1.75 var(--mono); letter-spacing: .01em;
  font-variant-ligatures: none; tab-size: 4;
}
.mirror, .editor textarea {
  font: inherit; letter-spacing: inherit; tab-size: inherit;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: normal;
  margin: 0; padding: 0; border: 0;
}
/* The mirror draws the text; the transparent textarea on top takes input,
   selection and the caret. Same font, same box, so they line up exactly. */
.mirror { color: var(--text); min-height: 60vh; pointer-events: none; }
.editor textarea {
  position: absolute; inset: 0; width: 100%; height: 100%;
  resize: none; overflow: hidden; outline: none;
  background: transparent; color: transparent;
  caret-color: var(--accent);
  -webkit-text-fill-color: transparent;
}
.editor textarea::placeholder { color: var(--text-faint); -webkit-text-fill-color: var(--text-faint); }
.editor textarea::selection { background: var(--accent-soft); }

.md-mark { color: var(--mark); }
.md-h { font-weight: 700; }
.md-b { font-weight: 700; }
.md-i { font-style: italic; }
.md-code { color: var(--text-dim); }
body.show-authorship .au-pasted { color: var(--pasted); }
body.show-authorship .au-pasted.md-mark { color: color-mix(in srgb, var(--pasted) 55%, var(--bg)); }
body.show-style .st-filler { color: var(--strike); text-decoration: line-through; text-decoration-color: var(--strike); }
body.show-style .st-wordy, body.show-style .st-cliche { text-decoration: underline wavy var(--flag); text-decoration-thickness: 1px; text-underline-offset: 4px; }
.fo-dim { opacity: .3; transition: opacity 120ms; }

/* Preview: the same words, set as a page. */
.preview {
  flex: 1; min-width: 0; padding: max(16vh, 96px) 32px 30vh;
  border-left: 1px solid var(--line); background: var(--bg-raised);
}
body.previewing .preview { position: sticky; top: 0; height: 100dvh; overflow-y: auto; }
.prose { max-width: 62ch; margin: 0 auto; font: 18px/1.65 var(--serif); color: var(--text); }
.prose h1, .prose h2, .prose h3 { font-weight: 600; line-height: 1.25; letter-spacing: -.01em; margin: 1.6em 0 .5em; }
.prose h1 { font-size: 1.7em; margin-top: 0; }
.prose h2 { font-size: 1.3em; }
.prose h3 { font-size: 1.1em; }
.prose p { margin: 0 0 1em; }
.prose p.cite { padding-left: 2em; text-indent: -2em; }
.prose blockquote { margin: 0 0 1em; padding-left: 1.2em; border-left: 2px solid var(--line); color: var(--text-dim); }
.prose a { color: var(--accent); }
.prose code, .prose pre { font: .85em var(--mono); }
.prose pre { padding: 12px 14px; background: var(--bg-hover); border-radius: var(--r-md); overflow-x: auto; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.prose ul, .prose ol { padding-left: 1.4em; margin: 0 0 1em; }
.empty-preview { color: var(--text-faint); font: 15px var(--sans); text-align: center; }

/* Documents drawer */
.drawer {
  position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(320px, 86vw);
  display: flex; flex-direction: column;
  background: var(--bg-raised); border-right: 1px solid var(--line); box-shadow: var(--shadow-sheet);
  padding-top: env(safe-area-inset-top);
  animation: slide var(--dur) var(--ease);
}
@keyframes slide { from { transform: translateX(-16px); opacity: 0; } }
.scrim { position: fixed; inset: 0; z-index: 35; background: rgba(20, 16, 10, .18); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px 20px; }
.wordmark { font: 500 20px var(--serif); letter-spacing: -.02em; white-space: nowrap; }
.doc-list { list-style: none; margin: 0; padding: 4px 8px; overflow-y: auto; flex: 1; }
.doc-item { position: relative; }
.doc-item > button.open {
  display: block; width: 100%; padding: 10px 40px 10px 12px; border: 0; border-radius: var(--r-md);
  background: none; text-align: left;
}
.doc-item > button.open:hover { background: var(--bg-hover); }
.doc-item[aria-current='true'] > button.open { background: var(--accent-soft); }
.doc-name { display: block; font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-sub { display: block; font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }
.doc-item .del { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); opacity: 0; }
.doc-item:hover .del, .doc-item .del:focus-visible { opacity: 1; }
@media (hover: none) { .doc-item .del { opacity: 1; } }
.drawer-foot { padding: 12px 20px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.sync { margin: 0 0 4px; font-size: 13px; color: var(--text-faint); display: flex; align-items: center; gap: 8px; }
.sync::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--line-input); }
.sync.on::before { background: #2f9e5b; }
.link-btn { padding: 0; border: 0; background: none; color: var(--accent); font-size: 14px; min-height: 32px; }
.link-btn:hover { text-decoration: underline; }

/* Buttons, fields, dialogs */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 36px; padding: 0 14px; border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--bg-raised); font-size: 14px; font-weight: 500;
}
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme='dark'] .btn.primary { color: #0b1a2e; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .btn.primary { color: #0b1a2e; } }
.btn.primary:hover { filter: brightness(1.06); }

.dialog {
  width: min(460px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line); border-radius: var(--r-xl);
  background: var(--bg-raised); color: var(--text); box-shadow: var(--shadow-sheet);
}
.dialog::backdrop { background: rgba(20, 16, 10, .28); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 0 24px; }
.dialog-head h2 { margin: 0; font: 700 20px/1.25 var(--sans); letter-spacing: -.02em; }
.dialog-body { padding: 16px 24px 8px; }
.dialog-body p { margin: 0 0 12px; color: var(--text-dim); }
.dialog-foot { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 24px 24px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: grid; gap: 6px; min-width: 0; font-size: 13px; color: var(--text-dim); }
.field:first-child { grid-column: 1 / -1; }
.field input {
  width: 100%; min-width: 0; height: 40px; padding: 0 12px; border: 1px solid var(--line-input); border-radius: var(--r-md);
  background: var(--bg); color: var(--text); font-size: 15px;
}
.field input:focus { outline: 2px solid transparent; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.hint { font-size: 13px; color: var(--text-faint) !important; margin-top: 12px !important; }
.hint code { font: 12px var(--mono); }
.keys { margin: 0; }
.keys div { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
.keys div:last-child { border: 0; }
.keys dd { margin: 0; }
.keys kbd { font-size: 13px; color: var(--text-dim); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 8px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: 999px; background: var(--text); color: var(--bg); font-size: 14px;
  transition: opacity var(--dur), transform var(--dur) var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Split view on wide screens; preview takes the page on narrow ones. */
@media (max-width: 900px) {
  body.previewing .sheet { display: none; }
  body.previewing .preview { border: 0; position: static; height: auto; }
}
@media (max-width: 720px) {
  :root { --type: 16px; }
  .sheet { padding: 88px 16px 50vh; }
  .preview { padding: 88px 16px 30vh; }
  .doc-title { display: none; }
  .text-btn { padding: 0 8px; }
  .pop { left: 12px; right: 12px; width: auto; }
  .fields { grid-template-columns: 1fr; }
  .dialog { margin: auto auto 0; width: 100vw; max-width: 100vw; border-radius: var(--r-xl) var(--r-xl) 0 0; }
  .dialog-foot .btn { flex: 1 1 40%; height: 44px; }
}

/* Paper, for print and for See paper. Only #print is printed. */
#print { display: none; }
@media print {
  body > *:not(#print) { display: none !important; }
  body { background: #fff; color: #000; }
  #print { display: block; }
  @page { size: letter; margin: 1in; }
}
.paper { font: 12pt/2 'Times New Roman', Times, serif; color: #000; }
.paper p { margin: 0; text-indent: .5in; orphans: 2; widows: 2; }
.paper .mla-head p, .paper .apa-lines p { text-indent: 0; }
.paper .paper-title { font: inherit; text-align: center; margin: 0; }
.paper h2, .paper h3, .paper h4 { font: inherit; font-weight: bold; margin: 0; break-after: avoid; }
.paper-mla h2 { font-weight: normal; text-decoration: underline; }
.paper-apa h2 { text-align: center; }
.paper p.cite { padding-left: .5in; text-indent: -.5in; }
.paper h2:has(+ p.cite), .paper h1:has(+ p.cite) { break-before: page; text-align: center; font-weight: normal; text-decoration: none; }
.paper blockquote { margin: 0 0 0 .5in; }
.paper blockquote p { text-indent: 0; }
.paper ul, .paper ol { margin: 0; padding-left: .5in; }
.paper a { color: inherit; text-decoration: none; }
.paper hr { border: 0; text-align: center; }
.paper hr::after { content: '*'; }
.paper code, .paper pre { font: 11pt 'Courier New', monospace; white-space: pre-wrap; }
.apa-title { min-height: 9in; padding-top: 2in; text-align: center; break-after: page; }
.apa-title .paper-title { font-weight: bold; margin-bottom: 2em; }
.paper-apa .apa-repeat { font-weight: bold; }
.paper-plain { font: 12pt/1.5 Georgia, 'Times New Roman', serif; }
.paper-plain p { text-indent: 0; margin-bottom: .8em; }
.paper-plain .paper-title { font-size: 18pt; font-weight: bold; text-align: left; margin-bottom: .6em; }
/* APA abstract: its own page between the title page and the text. */
.apa-abstract { break-after: page; }
.apa-abstract h2 { text-align: center; font-weight: bold; }
.apa-abstract p { text-indent: 0; }
.apa-abstract p.keywords { text-indent: .5in; }
/* An appendix starts a new page after the reference list. */
.paper h2.appendix { break-before: page; text-align: center; font-weight: bold; text-decoration: none; }
/* A paper that is a list (annotated bibliography): the title stays on page one; an annotation sits under its entry, an inch in for MLA (Handbook 5.132), half an inch for APA. */
.paper.paper-list h1.paper-title { break-before: auto; }
.paper.paper-apa.paper-list h1.paper-title, .paper.paper-turabian.paper-list h1.paper-title { font-weight: bold; }
.paper-list.paper-mla blockquote { margin-left: 1in; }

/* Tables: label and title above, horizontal rules only, notes below (APA 7.10 to 7.14, MLA 9, Turabian 26.2). */
.paper figure.tbl { margin: 12pt 0; break-inside: avoid; }
.paper .tbl p { text-indent: 0; }
.paper .tbl-label, .paper .tbl-title { break-after: avoid; }
.paper .tbl table { width: 100%; border-collapse: collapse; border-top: 1px solid #000; border-bottom: 1px solid #000; line-height: 1.25; }
.paper .tbl th { font-weight: normal; border-bottom: 1px solid #000; }
.paper .tbl th, .paper .tbl td { padding: 3pt 5pt; text-align: left; vertical-align: top; }
.pg-flow .paper figure.tbl { break-inside: avoid-column; }
/* Column alignment, from the delimiter row or the style's default (a data attribute: the page allows no inline styles). */
.paper .tbl [data-align='center'], .prose [data-align='center'], .live [data-align='center'] { text-align: center; }
.paper .tbl [data-align='right'], .prose [data-align='right'], .live [data-align='right'] { text-align: right; }
/* Figures: the image fits the text width and never splits across pages (APA 7.22 to 7.28, MLA 9, Turabian 26.3). */
.paper figure.pfig { margin: 12pt 0; break-inside: avoid; }
.paper .pfig p { text-indent: 0; }
.paper .fig-label, .paper .fig-title { break-after: avoid; }
.paper .fig-img { line-height: 0; margin: 6pt 0; }
.paper .fig-img img { max-width: 100%; max-height: 7in; width: auto; height: auto; }
.paper .pfig-center .fig-img { text-align: center; }
.pg-flow .paper figure.pfig { break-inside: avoid-column; }
/* MLA and APA endnotes: double spaced, each indented like a paragraph, its number raised. */
.paper-mla ol.cite-list, .paper-apa ol.cite-list { line-height: 2; list-style: none; counter-reset: fn; }
.paper-mla ol.cite-list li, .paper-apa ol.cite-list li { margin-bottom: 0; counter-increment: fn; }
.paper-mla ol.cite-list li::before, .paper-apa ol.cite-list li::before { content: counter(fn) ' '; font-size: 8pt; vertical-align: super; line-height: 0; }
.paper.paper-apa h2:has(+ ol.cite-list) { font-weight: bold; }

/* ---- Live page: formatted as you type ---- */
.live {
  max-width: var(--measure); margin: 0 auto; min-height: 60vh; outline: none;
  font: var(--type)/1.75 var(--mono); letter-spacing: .01em; color: var(--text);
  caret-color: var(--accent); overflow-wrap: break-word;
  /* Lines run to the edge: a word too long for what is left of the line is hyphenated there. Lines never rewrap behind the caret. */
  -webkit-hyphens: auto; hyphens: auto;
}
.live > :first-child { margin-top: 0; }
.live p, .live blockquote, .live ul, .live ol, .live pre { margin: 0 0 1em; }
.live h1 { font: 700 1.55em/1.3 var(--mono); letter-spacing: -.01em; margin: 0 0 .9em; }
.live h2 { font: 700 1.2em/1.4 var(--mono); margin: 1.6em 0 .6em; }
.live h3 { font: 700 1em/1.5 var(--mono); margin: 1.4em 0 .4em; }
.live blockquote { padding-left: 1.2em; border-left: 2px solid var(--line-input); color: var(--text-dim); }
.live ul, .live ol { padding-left: 1.6em; }
.live li { margin: 0 0 .25em; }
.live a { color: var(--accent); }
.live code, .live pre { font-family: var(--mono); color: var(--text-dim); }
.live pre { white-space: pre-wrap; padding: 12px 14px; background: var(--bg-hover); border-radius: var(--r-md); }
.live hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
/* A table on the live page: plain cells to type in; the style's rules come at export. */
.live table { width: 100%; table-layout: fixed; border-collapse: collapse; margin: 0 0 1em; font-size: .88em; line-height: 1.5; -webkit-hyphens: manual; hyphens: manual; overflow-wrap: anywhere; }
.live th, .live td { border: 1px solid color-mix(in srgb, var(--line-input) 60%, var(--bg)); padding: 6px 10px; text-align: left; vertical-align: top; min-width: 2em; }
.live th { font-weight: 700; background: var(--bg-hover); }
.live p.tbl-cap, .live p.tbl-note { font-size: .88em; color: var(--text-dim); }
.live p.tbl-cap { margin-bottom: .5em; }
/* A figure on the live page: the image at the column width, on white (papers are white) in either theme. Click it for its bar. */
.live figure.fig { margin: 0 0 1em; line-height: 0; cursor: pointer; border-radius: 8px; }
.live figure.fig img { display: block; max-width: 100%; max-height: 75vh; height: auto; border-radius: 6px; background: #fff; box-shadow: 0 0 0 1px var(--line); transition: box-shadow .15s; }
.live figure.fig img:not([src]) { width: 100%; aspect-ratio: 3 / 2; background: var(--bg-hover); box-shadow: none; }
.live figure.fig[data-state] { position: relative; }
.live figure.fig[data-state]::after { position: absolute; inset: 0; display: grid; place-items: center; font: 13px/1.4 var(--sans); color: var(--text-faint); padding: 16px; text-align: center; }
.live figure.fig[data-state='loading']::after { content: 'Loading image\2026'; }
.live figure.fig[data-state='missing']::after { content: 'This image is not on this device yet. It loads when you are online.'; }
.live figure.fig::selection, .live figure.fig *::selection { background: transparent; }
.live figure.fig.is-selected img { box-shadow: 0 0 0 2px var(--accent), 0 0 0 6px var(--accent-soft); }
.live p.fig-cap, .live p.fig-note { font-size: .88em; color: var(--text-dim); }
.live p.fig-cap { margin-bottom: .5em; }
.prose figure.fig { margin: 0 0 1em; }
.prose figure.fig img { max-width: 100%; height: auto; background: #fff; border-radius: 6px; }
.prose p.fig-cap, .prose p.fig-note { font-size: .9em; color: var(--text-dim); margin-bottom: .5em; }
.fig-bar button { padding: 0 10px; font-size: 14px; }
.fig-preview { display: block; max-width: 100%; max-height: 200px; margin: 0 auto 14px; border-radius: 6px; background: #fff; box-shadow: 0 0 0 1px var(--line); }
.fig-preview:not([src]) { display: none; }
.fig-dialog .field { margin-bottom: 12px; }
.fig-dialog textarea { min-height: 60px; }
/* A note written in place: its number, then its words, small, in a quiet tint. Numbered with Chicago's citation notes. */
.live { counter-reset: fn; }
.live cite.cite-note, .live .fn { counter-increment: fn; }
.live .fn { font-size: .82em; line-height: 1.5; color: var(--text-dim); background: var(--accent-soft); border-radius: 4px; padding: .1em .35em; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.live .fn::before { content: counter(fn); color: var(--accent); font-weight: 700; font-size: .8em; vertical-align: super; line-height: 0; margin-right: .3em; }
.md-fn { color: var(--text-dim); }
.prose table { width: 100%; border-collapse: collapse; margin: 0 0 1em; font-size: .9em; line-height: 1.45; }
.prose th, .prose td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.prose th { border-bottom-color: var(--line-input); font-weight: 600; }
.prose p.tbl-cap, .prose p.tbl-note { font-size: .9em; color: var(--text-dim); margin-bottom: .5em; }
.prose .fn { font-size: .85em; color: var(--text-dim); }
.prose .fn::before { content: '['; }
.prose .fn::after { content: ']'; }
.live::selection, .live *::selection { background: var(--accent-soft); }
.live.is-empty > p:first-child::before { content: 'Start writing. Select words to format them.'; color: var(--text-faint); pointer-events: none; float: left; height: 0; -webkit-hyphens: manual; hyphens: manual; }
body.show-authorship ::highlight(pasted) { color: var(--pasted); }
body.show-style ::highlight(st-filler) { color: var(--strike); text-decoration: line-through; }
body.show-style ::highlight(st-flag) { text-decoration: underline wavy var(--flag); text-underline-offset: 4px; }
::highlight(dim) { color: color-mix(in srgb, var(--text) 28%, var(--bg)); }

/* Format bubble: appears over a selection */
.bubble {
  position: absolute; left: 0; top: 0; z-index: 25;
  display: flex; align-items: center; gap: 2px; padding: 4px;
  background: var(--text); color: var(--bg); border-radius: var(--r-md); box-shadow: var(--shadow-menu);
}
.bubble button {
  height: 32px; min-width: 32px; padding: 0 9px; border: 0; border-radius: var(--r-sm);
  background: none; color: inherit; font-size: 14px; opacity: .78;
}
.bubble button:hover, .bubble button[aria-pressed='true'] { opacity: 1; background: color-mix(in srgb, var(--bg) 18%, transparent); }
.bubble b, .bubble i { font-size: 15px; font-family: var(--serif); }
.bubble-sep { width: 1px; height: 18px; margin: 0 3px; background: currentColor; opacity: .25; }
@media (hover: none) { .bubble button { height: 40px; min-width: 40px; } }

/* Sources panel: a sheet on the right, the page shifts over on wide screens. */
.badge {
  display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px;
  margin-left: 2px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600;
}
.panel {
  position: fixed; inset: 0 0 0 auto; z-index: 30; width: min(400px, 100vw);
  display: flex; flex-direction: column; overflow-y: auto;
  background: var(--bg-raised); border-left: 1px solid var(--line); box-shadow: var(--shadow-sheet);
  padding-top: env(safe-area-inset-top);
  animation: slide-r var(--dur) var(--ease);
}
@keyframes slide-r { from { transform: translateX(16px); opacity: 0; } }
@keyframes sheet-in { from { transform: translateX(100%); } }
@media (min-width: 1180px) { body.panel-open .stage { margin-right: 400px; } }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 4px 20px; position: sticky; top: 0; background: var(--bg-raised); z-index: 1; }
.panel-head h2 { margin: 0; font: 700 20px/1.25 var(--sans); letter-spacing: -.02em; }
.panel-body { padding: 8px 20px 24px; }
.panel .seg.wide { margin-bottom: 16px; }
.panel .seg button { height: 34px; font-size: 14px; }
.lookup { display: grid; gap: 6px; margin-bottom: 16px; }
.lookup-row { display: flex; gap: 8px; }
.lookup-row input { flex: 1; }
.lookup-row .btn { height: 40px; }
.lookup-status { margin: 0; min-height: 0; font-size: 13px; color: var(--text-dim); }
.lookup-status:empty { display: none; }
.lookup .link-btn { justify-self: start; }
/* Title search under the Sources box (lib/sourcefind.js): a popover, so nothing below moves. */
.lookup-row { position: relative; }
.find-box { flex: 1; min-width: 0; }
.find-hits {
  position: absolute; z-index: 5; top: calc(100% + 6px); left: 0; right: 0; margin: 0; padding: 6px; list-style: none;
  max-height: min(380px, 55vh); overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg-raised); border: 1px solid var(--line-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-menu);
}
.find-hits[hidden] { display: none; }
.find-hits[aria-busy='true'] .find-hit { opacity: .55; }
.find-hit { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 9px 10px; border-radius: var(--r-md); cursor: pointer; transition: background var(--dur), opacity var(--dur); }
.find-hit[aria-selected='true'] { background: var(--accent-soft); }
@media (hover: hover) { .find-hit:hover { background: var(--bg-hover); } .find-hit[aria-selected='true']:hover { background: var(--accent-soft); } }
.find-title { grid-column: 1; grid-row: 1; font-size: 14.5px; font-weight: 600; line-height: 1.35; color: var(--text); overflow-wrap: anywhere; }
.find-meta { grid-column: 1 / -1; grid-row: 2; font-size: 12.5px; line-height: 1.4; color: var(--text-dim); overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.find-kind { grid-column: 2; grid-row: 1; align-self: start; margin-top: 1px; padding: 1px 7px; border-radius: 999px; white-space: nowrap; font: 600 10px/1.6 var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); background: var(--bg-tint); }
.find-note { padding: 10px; font-size: 13.5px; color: var(--text-dim); }
/* Several lines pasted at once, each with how it went. */
.bulk { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 10px 12px 12px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg); }
.bulk[hidden] { display: none; }
.bulk-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 240px; overflow-y: auto; }
.bulk-list li { display: flex; align-items: baseline; gap: 10px; font-size: 13px; }
.bulk-q { flex: 1; min-width: 0; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bulk-state { flex: none; color: var(--text-faint); }
.bulk-list li[data-state='ok'] .bulk-state { color: #2f7d4f; }
:root[data-theme='dark'] .bulk-list li[data-state='ok'] .bulk-state { color: #7ccf9b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .bulk-list li[data-state='ok'] .bulk-state { color: #7ccf9b; } }
.bulk-list li[data-state='look'] .bulk-state { color: var(--accent); }
.bulk .btn { justify-self: start; }
.source.flash { animation: source-flash 1.6s var(--ease); }
@keyframes source-flash { 0%, 40% { background: var(--accent-soft); } 100% { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .source.flash { animation: none; outline: 2px solid var(--accent); outline-offset: 2px; } }
.source-files { display: flex; flex-wrap: wrap; gap: 4px 20px; margin: 12px 0 0; }
.source-files[hidden] { display: none; }
.source-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
/* Typed citations that match these sources, linked in one tap. */
.link-row { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; padding: 10px 12px 10px 14px; border-radius: var(--r-md); background: var(--bg-hover); }
.link-row[hidden] { display: none; }
.link-row p { flex: 1; margin: 0; font-size: 13.5px; line-height: 1.4; color: var(--text-dim); }
.link-row .btn { flex: none; }
.source { padding: 14px 0; border-bottom: 1px solid var(--line); }
.source-entry { margin: 0 0 10px; padding-left: 1.5em; text-indent: -1.5em; font: 15px/1.55 var(--serif); overflow-wrap: break-word; }
.source-actions { display: flex; align-items: center; gap: 6px; }
.page-input { width: 64px; height: 32px; padding: 0 8px; border: 1px solid var(--line-input); border-radius: var(--r-sm); background: var(--bg); font-size: 14px; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.source-actions .icon-btn { margin-left: auto; }
#sourceForm { display: grid; gap: 12px; }
#sourceForm[hidden] { display: none; }
.entry-preview { padding: 12px 14px; border-radius: var(--r-md); background: var(--bg-hover); font: 15px/1.55 var(--serif); padding-left: calc(14px + 1.5em); text-indent: -1.5em; min-height: 48px; overflow-wrap: anywhere; }
.field select, .field textarea {
  width: 100%; min-width: 0; padding: 8px 12px; border: 1px solid var(--line-input); border-radius: var(--r-md);
  background: var(--bg); color: var(--text); font: 15px/1.4 var(--sans); resize: vertical;
}
.field select { height: 40px; padding: 0 10px; }
.field select:focus, .field textarea:focus, .page-input:focus { outline: 2px solid transparent; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#sourceForm .field:first-child { grid-column: auto; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.row3[hidden] { display: none; }
/* Source fields: full width, except small ones (year, pages) three to a row. */
.src-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 8px; }
.src-fields:empty { display: none; }
#sourceForm .src-fields > *, #sourceForm .src-fields > .field:not(.small) { grid-column: 1 / -1; }
#sourceForm .src-fields > .field.small { grid-column: auto; }
.more-fields { border-top: 1px solid var(--line); padding-top: 4px; }
.more-fields > summary {
  display: flex; align-items: center; gap: 6px; min-height: 40px; cursor: pointer; list-style: none;
  font-size: 13.5px; font-weight: 500; color: var(--text-dim); border-radius: var(--r-sm);
}
.more-fields > summary::-webkit-details-marker { display: none; }
.more-fields > summary::before {
  content: ''; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg); transition: transform .15s ease; margin: 0 4px 0 2px;
}
.more-fields[open] > summary::before { transform: rotate(45deg); }
.more-fields > summary:hover { color: var(--text); }
.more-fields > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.more-fields[open] > .src-fields { padding: 4px 0 4px; }
.source-note { margin: -4px 0 10px; font-size: 12.5px; color: var(--text-faint); }
.form-foot { display: flex; gap: 8px; padding-top: 4px; }
@media (max-width: 720px) {
  /* Full width, it slides in whole and solid, so the page never shows through it. */
  .panel { width: 100vw; animation: sheet-in .34s cubic-bezier(.2, .8, .2, 1); }
  .bar .text-btn#sourcesBtn { padding: 0 6px; }
}
.paper-apa h2:has(+ p.cite) { font-weight: bold; }
.field-error { font-size: 13px; color: #b3261e; }
:root[data-theme='dark'] .field-error { color: #ff9a95; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .field-error { color: #ff9a95; } }
.field input[aria-invalid='true'] { border-color: #c4392b; }

/* Citation chips: one unit to edit, drawn in the paper's style; they wrap and hyphenate like the words around them. */
.live cite {
  font-style: normal; color: var(--text-dim); cursor: default; -webkit-box-decoration-break: clone; box-decoration-break: clone;
  border-radius: 4px; box-shadow: inset 0 -1px 0 var(--line-input);
}
.live cite.cite-note { vertical-align: super; font-size: .68em; line-height: 0; color: var(--accent); box-shadow: none; padding: 0 .1em; }
.live cite.cite-missing { color: #b3261e; }
/* One note for several sources: the number sits on the last chip. A name in the sentence with no page in MLA: a small mark keeps the citation findable. */
.live cite.cite-joined { display: none; }
.live cite.cite-empty { display: inline-block; width: .4em; height: .4em; margin: 0 .12em; border-radius: 50%; vertical-align: .18em; background: var(--line-input); box-shadow: none; }
.style-field { margin-bottom: 16px; }
/* Export styles: toggle chips that wrap at any width. Chosen reads by fill and edge, not color alone. */
.style-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.style-chip {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line-input); background: var(--bg); color: var(--text); font-size: 14px; font-weight: 500;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.style-chip .pro-tag { margin-left: 0; }
@media (hover: hover) { .style-chip:hover { background: var(--bg-hover); } }
.style-chip[aria-pressed='true'] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.style-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.style-several { margin-top: 6px; font-size: 14px; }
.style-multi { margin: 4px 0 0 !important; }
.style-multi[hidden] { display: none; }
@media (max-width: 720px) { .style-chip { height: 44px; } }
#exportDialog .btn:disabled { opacity: .45; cursor: default; }
#exportDialog .btn:disabled:hover { background: var(--bg-raised); }
#exportDialog .btn.primary:disabled:hover { background: var(--accent); filter: none; }
.tb-title { min-height: 9in; padding-top: 2.6in; text-align: center; break-after: page; }
.tb-title .paper-title { font-weight: bold; margin-bottom: 3in; }
.tb-lines p { text-indent: 0; line-height: 1.5; }
.paper-turabian .paper-title { text-align: center; }
.paper-turabian h2 { text-align: center; }
.paper sup.fnref { font-size: 8pt; line-height: 0; }
.paper ol.cite-list { padding-left: 0; list-style-position: inside; line-height: 1.15; }
.paper ol.cite-list li { text-indent: .5in; margin-bottom: 12pt; }
.paper h2:has(+ ol.cite-list) { break-before: page; text-align: center; font-weight: normal; text-decoration: none; }
.paper-turabian h2:has(+ p.cite), .paper-turabian h2:has(+ ol.cite-list) { font-weight: bold; }
.save-state { margin-left: 10px; font-size: 13px; color: var(--text-faint); white-space: nowrap; transition: opacity var(--dur); }
.save-state[data-state='saved'] { opacity: .7; }
@media (max-width: 720px) { .save-state { margin-left: 4px; } }
.who { display: grid; gap: 8px; margin-top: 10px; }
.who-line { margin: 0; font-size: 13.5px; color: var(--text-dim); }
.who-btn { text-decoration: none; justify-self: start; }
.who .link-btn { justify-self: start; text-decoration: none; display: inline-flex; align-items: center; }
.who-email { margin: 0; font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.pro-list { margin: 0 0 8px; padding-left: 1.2em; color: var(--text); }
.pro-list li { margin: 4px 0; }
.dialog-foot a.btn { text-decoration: none; }
.dialog-foot a.btn:not(.primary) { color: var(--text); }
.case-hint { display: grid; gap: 6px; padding: 10px 12px; border-radius: var(--r-md); background: var(--accent-soft); font-size: 13.5px; }
.case-hint p { margin: 0; color: var(--text-dim); }
.case-hint #caseText { color: var(--text); font-weight: 500; }
.case-hint .hint { margin: 0 !important; }
.case-hint .btn { justify-self: start; }
.paste-check { margin-top: 12px; padding: 12px 14px; border-radius: var(--r-md); background: color-mix(in srgb, var(--flag) 12%, transparent); }
.paste-check-head { margin: 0 0 6px !important; color: var(--text) !important; font-weight: 600; font-size: 14px; }
.paste-check ul { margin: 0 0 6px; padding-left: 1.1em; font-size: 13.5px; color: var(--text-dim); }
.paste-check .hint { margin: 0 !important; }
.report-row { display: flex; align-items: center; gap: 12px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.report-row > div { flex: 1; }
.report-row p { margin: 0 !important; }
.report-name { font-weight: 600; color: var(--text) !important; font-size: 14px; }
.report-row .hint { margin-top: 2px !important; }
/* Proof you wrote it (View menu) */
.report-row[hidden], .proof-link[hidden], .proof-more a[hidden] { display: none; }
.proof-lead { margin: 0 0 6px; }
.proof-stat { margin: 0; font: 13px/1.5 var(--mono); color: var(--text-dim); }
.proof-link { margin-top: 12px; }
.proof-more { display: flex; flex-wrap: wrap; gap: 4px 20px; margin: 18px 0 0 !important; font-size: 14px; }
.proof-more a { display: inline-flex; align-items: center; min-height: 32px; color: var(--accent); text-decoration: none; }
.proof-more a:hover { text-decoration: underline; }
@media (max-width: 640px) { .proof-more a { min-height: 44px; } }
.feedback-body { display: grid; gap: 14px; }
.feedback-body .field-error { margin: 0; }
.feedback-body textarea { min-height: 120px; }
.check-row { display: flex; align-items: flex-start; gap: 10px; margin-top: 14px; font-size: 14px; line-height: 1.4; color: var(--text); cursor: pointer; }
.check-row[hidden] { display: none; }
.check-row input { flex: none; width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--accent); cursor: pointer; }
@media (pointer: coarse) { .check-row { min-height: 44px; align-items: center; } .check-row input { margin: 0; } }
.pro-tag { margin-left: 4px; padding: 1px 6px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 600; letter-spacing: .04em; }
@media print {
  .report { font: 11pt/1.5 Georgia, 'Times New Roman', serif; color: #000; }
  .report h1 { font-size: 22pt; margin: 0 0 4pt; }
  .report h2 { font-size: 13pt; margin: 18pt 0 6pt; }
  .report-eyebrow { font: 9pt ui-monospace, Menlo, monospace; letter-spacing: .1em; text-transform: uppercase; color: #555; margin: 0 0 6pt; }
  .report-who, .report-dates { color: #333; margin: 0 0 8pt; }
  .report-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8pt; margin: 12pt 0; padding: 10pt 0; border-block: 1px solid #ccc; }
  .report-stats dt { font: 8pt ui-monospace, Menlo, monospace; text-transform: uppercase; letter-spacing: .06em; color: #555; }
  .report-stats dd { margin: 2pt 0 0; font-size: 16pt; }
  .report-chart { width: 100%; height: 1.4in; border-bottom: 1px solid #ccc; }
  .report-pastes li { margin-bottom: 6pt; }
  .report-pastes span { font: 8pt ui-monospace, Menlo, monospace; text-transform: uppercase; color: #8a3ea6; margin-left: 4pt; }
  .report-replay { display: flex; align-items: center; gap: 12pt; }
  .report-replay svg { width: 1.2in; height: 1.2in; }
  .report-replay svg, .report-replay svg * { stroke: none; }
  .report-replay p { font: 9pt ui-monospace, Menlo, monospace; word-break: break-all; }
  .report-foot { margin-top: 24pt; font-size: 9pt; color: #555; }
}
.drawer-links { display: grid; justify-items: start; gap: 2px; padding: 6px 20px 10px; border-top: 1px solid var(--line); }
.keep-safe { margin-left: 8px; font-size: 13px; color: var(--accent); text-decoration: none; white-space: nowrap; }
.keep-safe:hover { text-decoration: underline; }
.save-state[data-state='stuck'] { color: var(--flag); }
.toast { display: flex; align-items: center; gap: 12px; }
.toast.has-action { pointer-events: auto; }
.toast-action { border: 0; background: none; color: inherit; font: 600 14px var(--sans); text-decoration: underline; padding: 4px 2px; cursor: pointer; }
.tab-banner {
  position: fixed; left: 50%; top: 64px; z-index: 22; transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 32px);
  padding: 10px 12px 10px 16px; border-radius: var(--r-lg); border: 1px solid var(--line);
  background: var(--bg-raised); box-shadow: var(--shadow-menu); font-size: 14px;
}
.tab-banner p { margin: 0; color: var(--text-dim); }
@media (max-width: 720px) { .tab-banner { flex-direction: column; align-items: stretch; text-align: center; } }
.banner-actions { display: flex; gap: 8px; flex: none; }
.banner-actions .btn { white-space: nowrap; }
@media (max-width: 720px) {
  .card-banner { width: calc(100vw - 32px); }
  .banner-actions .btn { flex: 1; height: 44px; }
}
.trash-list { list-style: none; margin: 0; padding: 0; }
.trash-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.trash-list li > div { flex: 1; min-width: 0; }
.trash-name { margin: 0 !important; color: var(--text) !important; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trash-sub { margin: 2px 0 0 !important; font-size: 13px; color: var(--text-faint) !important; }

/* The drawn wordmark (public/brand). Its height follows the .wordmark font size;
   ink follows the text color and the caret takes the accent, so both themes work. */
.wordmark-svg { display: block; height: .9em; width: auto; }
.wm-ink { fill: currentColor; }
.wm-accent { fill: var(--accent); }

/* Phones: the bar keeps the tools you reach for. The save line shows only when
   something needs attention; "Keep it safe" lives in the Documents drawer. */
.text-btn { white-space: nowrap; }
.bar-start { min-width: 0; }
@media (max-width: 720px) {
  .keep-safe { display: none; }
  .save-state:not([data-state='stuck']) { display: none; }
  .save-state[data-state='stuck'] { max-width: 38vw; overflow: hidden; text-overflow: ellipsis; }
}
/* A count badge never runs into the word count beside it ("1" + "245 words" read as 1245). */
.bar-end { gap: 6px; }
#sourcesBtn .badge { margin-left: 4px; }
.bar-end > * { flex: none; }
@media (max-width: 380px) {
  .text-btn { padding: 0 6px; font-size: 13.5px; }
  .bar-end { gap: 2px; }
  /* No room for words: a save problem shows as an amber dot (its message is in the drawer). */
  .save-state[data-state='stuck'] { font-size: 0; width: 8px; height: 8px; margin-left: 6px; border-radius: 50%; background: var(--flag); }
}
@media (max-width: 359px) { .wc-unit { display: none; } }
@media (max-width: 720px) {
  .save-state[data-state='stuck'] { font-size: 0; width: 8px; height: 8px; max-width: none; margin-left: 6px; border-radius: 50%; background: var(--flag); }
}

/* Theme picker: a small live page per theme, in the side Appearance shows. */
.theme-dialog { width: min(560px, calc(100vw - 32px)); }
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.theme-card {
  display: grid; gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--bg-raised); text-align: left; cursor: pointer; transition: border-color var(--dur), box-shadow var(--dur);
}
.theme-card:hover { border-color: var(--line-input); }
.theme-card[aria-checked='true'] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.theme-preview {
  display: grid; gap: 4px; padding: 12px; min-height: 72px; border-radius: var(--r-md);
  font: 12px/1.45 var(--mono); outline: 1px solid color-mix(in srgb, currentColor 14%, transparent); outline-offset: -1px;
}
.theme-preview b { font-weight: 700; }
.theme-line { display: block; }
.theme-caret { display: inline-block; width: 2px; height: 1.1em; margin-left: 2px; vertical-align: -2px; border-radius: 1px; }
.theme-name { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 0 4px 2px; font-size: 14px; font-weight: 600; color: var(--text); }
@media (max-width: 720px) { .theme-grid { grid-template-columns: repeat(2, 1fr); } }
.install-steps { margin: 4px 0 0; padding-left: 1.3em; display: grid; gap: 8px; color: var(--text); }
.install-steps li::marker { color: var(--accent); font-weight: 700; }

/* Writing together: each writer's color, for their caret, their initials and,
   with Authorship on, a quiet underline under what they wrote. Your own
   writing stays plain. Six colors, none of them the accent or the pasted purple. */
:root { --p0: #0f7b6c; --p1: #c2410c; --p2: #4d7c0f; --p3: #be185d; --p4: #8a5a2b; --p5: #52606d; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) { --p0: #4fd1bd; --p1: #fb923c; --p2: #a3e635; --p3: #f472b6; --p4: #d6a874; --p5: #a3b1c2; }
}
:root[data-theme='dark'] { --p0: #4fd1bd; --p1: #fb923c; --p2: #a3e635; --p3: #f472b6; --p4: #d6a874; --p5: #a3b1c2; }
.pc-0 { --pc: var(--p0); } .pc-1 { --pc: var(--p1); } .pc-2 { --pc: var(--p2); }
.pc-3 { --pc: var(--p3); } .pc-4 { --pc: var(--p4); } .pc-5 { --pc: var(--p5); }

.sheet { position: relative; }
.carets { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.pc { position: absolute; left: 0; top: 0; width: 2px; margin-left: -1px; border-radius: 1px; background: var(--pc); transition: transform 80ms linear; }
.pc-name {
  position: absolute; left: -1px; bottom: 100%; margin-bottom: 1px; padding: 1px 6px;
  border-radius: 5px 5px 5px 0; background: var(--pc); color: var(--bg);
  font: 600 11px/1.45 var(--sans); white-space: nowrap; opacity: 0; transition: opacity 400ms var(--ease);
}
.pc.is-moving .pc-name { opacity: 1; }
::highlight(sel-0) { background-color: color-mix(in srgb, var(--p0) 22%, transparent); }
::highlight(sel-1) { background-color: color-mix(in srgb, var(--p1) 22%, transparent); }
::highlight(sel-2) { background-color: color-mix(in srgb, var(--p2) 22%, transparent); }
::highlight(sel-3) { background-color: color-mix(in srgb, var(--p3) 22%, transparent); }
::highlight(sel-4) { background-color: color-mix(in srgb, var(--p4) 22%, transparent); }
::highlight(sel-5) { background-color: color-mix(in srgb, var(--p5) 22%, transparent); }
body.show-authorship ::highlight(by-0) { text-decoration: underline 1.5px color-mix(in srgb, var(--p0) 45%, transparent); text-underline-offset: 5px; }
body.show-authorship ::highlight(by-1) { text-decoration: underline 1.5px color-mix(in srgb, var(--p1) 45%, transparent); text-underline-offset: 5px; }
body.show-authorship ::highlight(by-2) { text-decoration: underline 1.5px color-mix(in srgb, var(--p2) 45%, transparent); text-underline-offset: 5px; }
body.show-authorship ::highlight(by-3) { text-decoration: underline 1.5px color-mix(in srgb, var(--p3) 45%, transparent); text-underline-offset: 5px; }
body.show-authorship ::highlight(by-4) { text-decoration: underline 1.5px color-mix(in srgb, var(--p4) 45%, transparent); text-underline-offset: 5px; }
body.show-authorship ::highlight(by-5) { text-decoration: underline 1.5px color-mix(in srgb, var(--p5) 45%, transparent); text-underline-offset: 5px; }
body.show-authorship .au-by { text-decoration: underline 1.5px color-mix(in srgb, var(--pc) 45%, transparent); text-underline-offset: 5px; }
.au-p0 { --pc: var(--p0); } .au-p1 { --pc: var(--p1); } .au-p2 { --pc: var(--p2); }
.au-p3 { --pc: var(--p3); } .au-p4 { --pc: var(--p4); } .au-p5 { --pc: var(--p5); }

/* Who is here: initials beside Share. */
.people { display: flex; align-items: center; padding: 0 2px; }
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--pc, var(--text-faint)); color: var(--bg); box-shadow: 0 0 0 2px var(--bg);
  font: 600 11px/1 var(--sans);
}
.people .avatar + .avatar { margin-left: -6px; }
.avatar-more { background: var(--bg-hover); color: var(--text-dim); }
.avatar-sm { width: 30px; height: 30px; font-size: 12.5px; box-shadow: none; }
#shareBtn .share-icon, #insertBtn .insert-icon { display: none; }
#insertBtn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
@media (max-width: 720px) {
  #insertBtn .insert-word { display: none; }
  #insertBtn .insert-icon { display: block; }
  #insertBtn { min-width: 32px; padding: 0 4px; }
}
@media (max-width: 720px) {
  #shareBtn .share-word { display: none; }
  #shareBtn .share-icon { display: block; }
  #shareBtn { min-width: 32px; padding: 0 4px; }
}
/* Phones: the bar keeps its tools; who is here shows as carets on the page. */
@media (max-width: 480px) {
  .people { display: none; }
  .bar { padding: 0 8px; }
  .bar-end { gap: 0; }
  .text-btn { padding: 0 6px; }
}
.writers-line { margin: 8px 0 0; font-size: 13px; color: var(--text-dim); }

/* Share */
.share-loading { color: var(--text-faint) !important; }
.share-link { display: flex; gap: 8px; margin-bottom: 4px; }
.share-link input, .share-invite input {
  flex: 1; min-width: 0; height: 40px; padding: 0 12px; border: 1px solid var(--line-input); border-radius: var(--r-md);
  background: var(--bg); color: var(--text); font-size: 15px;
}
.share-link input { font: 13px var(--mono); color: var(--text-dim); }
.share-link input:focus, .share-invite input:focus { outline: 2px solid transparent; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.share-link .btn, .share-invite .btn { height: 40px; flex: none; }
.share-invite { display: grid; gap: 6px; margin-top: 16px; }
.share-invite .field { font-size: 13px; }
.share-label { margin: 20px 0 2px !important; padding: 0; }
.people-list { list-style: none; margin: 0; padding: 0; }
.people-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.person > div { min-width: 0; }
.person-name { margin: 0 !important; color: var(--text) !important; font-size: 14px; font-weight: 500; }
.person-email { margin: 0 !important; font-size: 12.5px; color: var(--text-faint) !important; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-role { font: 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--text-faint); flex: none; }
.leave-btn { margin-top: 8px; color: #b3261e; }
:root[data-theme='dark'] .leave-btn { color: #ff9a95; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .leave-btn { color: #ff9a95; } }
@media (max-width: 720px) {
  .share-link .btn, .share-invite .btn, .people-list .btn { height: 44px; }
  .link-btn { min-height: 44px; }
}
/* Give a friend a month of Pro, at the foot of Share. */
.gift-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; padding: 12px 14px; border-radius: var(--r-md); background: var(--accent-soft); }
.gift-row p { margin: 0 !important; font-size: 13.5px; line-height: 1.45; color: var(--text-dim) !important; }
.gift-row strong { color: var(--text); font-weight: 600; }
.gift-row .btn { flex: none; }
@media (max-width: 720px) {
  .gift-row { flex-direction: column; align-items: stretch; }
  .gift-row .btn { height: 44px; }
}

/* Pro: with three choices, the first (the trial, or the semester) takes a row of its own and the other two share one. */
.pro-foot .btn:first-child:nth-last-child(3) { flex: 1 1 100%; }
.pro-foot .btn:first-child:nth-last-child(3) ~ .btn { flex: 1 1 40%; }
/* On a phone, "$12 for the semester" needs the whole width: three full rows, never a label on two lines. */
@media (max-width: 520px) { .pro-foot .btn:first-child:nth-last-child(3) ~ .btn { flex-basis: 100%; } }
@media print {
  .report-writers { margin: 0; padding-left: 1.2em; }
  .report-writers span { font: 9pt ui-monospace, Menlo, monospace; color: #555; margin-left: 4pt; }
  .report-note { font-size: 9pt; color: #555; margin: 4pt 0 0; }
}

/* See paper: white Letter pages, as they print, on the tinted ground in either theme. */
.paper-dialog { width: min(920px, calc(100vw - 32px)); height: min(1100px, calc(100dvh - 32px)); max-height: none; }
.paper-dialog .dialog-inner { display: flex; flex-direction: column; height: 100%; }
.paper-dialog .dialog-head { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.paper-head-text { min-width: 0; }
.paper-meta { margin: 2px 0 0; font-size: 13px; color: var(--text-faint); }
.paper-stage { --pg-s: 1; flex: 1; min-height: 0; overflow: auto; padding: 24px; background: var(--bg-tint); overscroll-behavior: contain; }
.paper-dialog .dialog-foot { padding-top: 12px; border-top: 1px solid var(--line); }
.pg-wrap { width: calc(8.5in * var(--pg-s)); height: calc(11in * var(--pg-s)); margin: 0 auto 20px; }
.pg-wrap:last-child { margin-bottom: 0; }
.pg {
  position: relative; width: 8.5in; height: 11in; transform: scale(var(--pg-s)); transform-origin: 0 0;
  background: #fff; color: #000; border-radius: 2px; overflow: hidden;
  box-shadow: 0 0 0 1px rgba(40, 30, 10, .08), 0 2px 10px rgba(40, 30, 10, .1);
}
:root[data-theme='dark'] .pg { box-shadow: 0 0 0 1px rgba(255, 255, 255, .06), 0 2px 14px rgba(0, 0, 0, .5); }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .pg { box-shadow: 0 0 0 1px rgba(255, 255, 255, .06), 0 2px 14px rgba(0, 0, 0, .5); } }
/* Where Chrome prints the running head: the bottom of the top margin, a quarter inch up. */
.pg-head { position: absolute; top: 0; right: 1in; height: .75in; display: flex; align-items: flex-end; font: 12pt/normal 'Times New Roman', Times, serif; color: #000; }
.pg-body { position: absolute; top: 1in; left: 1in; width: 6.5in; height: 9in; overflow: hidden; }
.pg-flow { width: 6.5in; height: 9in; column-width: 6.5in; column-gap: 1in; column-fill: auto; }
.pg-probe { position: absolute; left: -10000px; top: 0; visibility: hidden; pointer-events: none; }
.pg-end { height: 0; }
.pg-flow .paper h2:has(+ p.cite), .pg-flow .paper h1:has(+ p.cite), .pg-flow .paper h2:has(+ ol.cite-list) { break-before: column; }
.pg-flow .apa-title, .pg-flow .tb-title, .pg-flow .apa-abstract { break-after: column; }
.pg-flow .paper h2.appendix { break-before: column; }
.pg-flow .paper.paper-list h1.paper-title { break-before: auto; }
.pg-flow .paper h2, .pg-flow .paper h3, .pg-flow .paper h4 { break-after: avoid-column; }
.see-btn { width: 100%; height: 44px; margin-top: 14px; gap: 8px; }
.see-btn svg { width: 18px; height: 18px; }
.export-note { margin: 0 24px !important; padding-top: 4px; }
@media (max-width: 720px) {
  .paper-dialog { height: calc(100dvh - env(safe-area-inset-top) - 12px); }
  .paper-stage { padding: 16px; }
  .pg-wrap { margin-bottom: 12px; }
}

/* First open: the paper's heading, then the page. Skippable, never in the way. */
.starter {
  /* As wide as the page's text: --measure counted in the editor's mono characters (0.6em each). */
  max-width: calc(var(--type) * 0.6 * 66); margin: 0 auto 40px; padding: 22px 22px 18px;
  border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--bg-raised); box-shadow: var(--shadow-card);
}
.starter-title { margin: 0; font: 700 20px/1.25 var(--sans); letter-spacing: -.02em; }
.starter-sub { margin: 6px 0 16px; font-size: 14px; color: var(--text-dim); }
.starter-foot { display: flex; align-items: center; gap: 18px; margin-top: 16px; }
.starter-guide { margin-left: auto; color: var(--text-faint); }
@media (max-width: 720px) {
  .starter { padding: 18px 16px 14px; margin-bottom: 28px; }
  .starter-foot .btn { height: 44px; }
  .starter .field input { height: 44px; font-size: 16px; }
}

/* One calm note under the bar: open in a real browser, or keep your paper with an account. */
.notice {
  position: fixed; left: 50%; top: calc(64px + env(safe-area-inset-top)); z-index: 22; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; width: max-content; max-width: min(560px, calc(100vw - 32px));
  padding: 10px 8px 10px 16px; border-radius: var(--r-lg); border: 1px solid var(--line);
  background: var(--bg-raised); box-shadow: var(--shadow-menu); font-size: 14px; line-height: 1.4;
  animation: notice-in .28s var(--ease);
}
.notice p { margin: 0; color: var(--text); }
.notice-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.notice-actions a.btn { text-decoration: none; }
.notice-x { color: var(--text-faint); }
@keyframes notice-in { from { opacity: 0; transform: translate(-50%, -6px); } }
@media (max-width: 720px) {
  .notice { left: 16px; right: 16px; width: auto; max-width: none; transform: none; flex-wrap: wrap; padding: 12px 8px 10px 14px; animation: none; }
  .notice p { flex: 1 1 100%; padding-right: 4px; }
  .notice-actions { flex: 1 1 100%; justify-content: flex-end; gap: 8px; }
  .notice-actions .btn { height: 44px; padding: 0 18px; }
  .notice-x { width: 44px; height: 44px; }
}
.inapp-box { margin-bottom: 16px; padding: 12px 14px; border-radius: var(--r-md); background: var(--accent-soft); }
.inapp-box p { margin: 0 0 10px !important; color: var(--text) !important; font-size: 14px; }
.pro-price { color: var(--text) !important; font-weight: 500; }
.sheet > .notice { position: static; transform: none; left: auto; right: auto; width: auto; max-width: var(--measure); margin: 0 auto 24px; box-shadow: var(--shadow-card); animation: none; }

/* Start a paper: import or blank, then the ready-made starts. */
.start-dialog { width: min(560px, calc(100vw - 32px)); }
.start-dialog .dialog-body { padding-bottom: 20px; }
.start-choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.start-choice {
  display: grid; justify-items: start; align-content: start; gap: 4px; min-height: 104px; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--bg); color: var(--text); text-align: left;
}
.start-choice:hover { border-color: var(--line-input); background: var(--bg-hover); }
.start-choice:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.start-choice svg { width: 22px; height: 22px; margin-bottom: 4px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.start-choice b { font-size: 15px; font-weight: 600; }
.start-choice small { font-size: 13px; line-height: 1.4; color: var(--text-faint); }
#startImport { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#startImport svg { color: var(--accent); }
.dialog-body .start-label { margin: 22px 0 6px; }
.tpl-list { list-style: none; margin: 0 -8px; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; outline: none; }
.tpl { display: grid; gap: 2px; width: 100%; padding: 9px 8px; border: 0; border-radius: var(--r-md); background: none; color: var(--text); text-align: left; }
.tpl:hover { background: var(--bg-hover); }
.tpl:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tpl-name { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; }
.tpl-tag { font: 600 10.5px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); }
.tpl-name .pro-tag { margin-left: 0; }
.tpl-blurb { font-size: 13px; line-height: 1.4; color: var(--text-faint); }
.start-drop { margin: 14px 0 0 !important; }
@media (max-width: 720px) {
  .start-dialog { width: 100vw; max-height: 92dvh; overflow-y: auto; }
  .start-choice { min-height: 96px; padding: 12px 14px; }
  .start-choices { grid-template-columns: 1fr 1fr; }
  #startPost { grid-column: 1 / -1; min-height: 0; }
  .tpl-list { grid-template-columns: 1fr; }
  .tpl { padding: 10px 8px; min-height: 44px; }
  .start-drop { display: none; }
}

/* First open: the other two ways to start, under the heading fields. */
.starter-alt { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.starter-alt-btn {
  display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg); color: var(--text); text-align: left;
}
.starter-alt-btn:hover { background: var(--bg-hover); border-color: var(--line-input); }
.starter-alt-btn svg { flex: none; width: 20px; height: 20px; fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.starter-alt-btn span { display: grid; min-width: 0; }
.starter-alt-btn b { font-size: 14px; font-weight: 600; }
.starter-alt-btn small { font-size: 12.5px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 520px) { .starter-alt { grid-template-columns: 1fr; } }

/* Documents: Import beside New, and two ways to start while the list is empty. */
.drawer-actions { display: flex; gap: 8px; }
.drawer-start { display: grid; gap: 8px; margin: 4px 20px 16px; padding: 16px; border: 1px dashed var(--line-input); border-radius: var(--r-lg); }
.drawer-start p { margin: 0 0 4px; font-size: 13.5px; line-height: 1.45; color: var(--text-dim); }
@media (max-width: 720px) { .drawer-actions .btn, .drawer-start .btn { height: 44px; } }

/* Dropping files anywhere on the app. */
.drop-zone {
  position: fixed; inset: 12px; z-index: 70; display: grid; place-items: center; pointer-events: none;
  border: 2px dashed var(--accent); border-radius: var(--r-xl); background: color-mix(in srgb, var(--bg) 82%, transparent);
}
.drop-zone p { margin: 0; padding: 10px 18px; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 600; font-size: 15px; }
:root[data-theme='dark'] .drop-zone p { color: #0b1a2e; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .drop-zone p { color: #0b1a2e; } }

/* @ to cite: a list at the caret. The page keeps the focus; rows only show and take taps. */
.atpop {
  position: fixed; z-index: 40; display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-menu);
  font: 14px/1.35 var(--sans); color: var(--text);
}
.atpop[hidden] { display: none; }
.at-list { overflow-y: auto; overscroll-behavior: contain; padding: 6px; }
.at-row { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; }
.at-row[aria-selected='true'] { background: var(--accent-soft); }
@media (hover: hover) { .at-row:hover { background: var(--bg-hover); } .at-row[aria-selected='true']:hover { background: var(--accent-soft); } }
.at-cite { font-family: var(--serif); font-size: 15px; overflow-wrap: anywhere; }
.at-cite sup { color: var(--accent); font-weight: 600; }
.at-note { color: var(--text-dim); }
.at-entry { color: var(--text-faint); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.at-act .at-cite { font-family: var(--sans); font-size: 14px; font-weight: 600; color: var(--accent); }
.at-head { margin: 8px 10px 4px; padding-top: 8px; border-top: 1px solid var(--line); font: 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--text-faint); }
.at-empty { margin: 0; padding: 10px; color: var(--text-faint); }
.at-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px 6px 6px; border-top: 1px solid var(--line); }
.at-mode { height: 28px; padding: 0 10px; border: 1px solid var(--line-input); border-radius: 14px; background: none; color: var(--text-dim); font-size: 12.5px; }
.at-mode[aria-pressed='true'] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.at-tip { color: var(--text-faint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (hover: none) { .at-row { padding: 11px 10px; } .at-mode { height: 34px; } }

/* ---- Layout (View): a letter page on the desk, the centered column, or the full window ---- */
/* Room for a scrollbar on both sides, so the page is centered in the window, not in what the scrollbar leaves. */
@media (min-width: 721px) {
  html:has(#sheet) { scrollbar-gutter: stable both-edges; }
  /* The dashboard covers the window and scrolls itself, so it needs no gutter. */
  html:has(#sheet):has(body.at-home) { scrollbar-gutter: auto; overflow: hidden; }
  /* Page: a letter sheet at the zoom where its 6.5 inch text block holds the 66-character line, with inch margins to scale. */
  :root[data-page='sheet'] body { background: var(--canvas); }
  :root[data-page='sheet'] .bar, :root[data-page='sheet'] .live-count { background: color-mix(in srgb, var(--canvas) 88%, transparent); }
  :root[data-page='sheet'] .stage { container-type: inline-size; padding: calc(76px + env(safe-area-inset-top)) 0 40vh; }
  :root[data-page='sheet'] .sheet {
    --page-w: min(calc(var(--type) * .6 * 66 * 8.5 / 6.5), 100cqw - 48px);
    --page-m: calc(var(--page-w) / 8.5);
    flex: none; align-self: flex-start; display: flex; flex-direction: column;
    width: var(--page-w); margin: 0 auto; padding: var(--page-m);
    aspect-ratio: 8.5 / 11; /* one page tall to start; it grows with the text */
    background: var(--bg); border-radius: 3px; box-shadow: var(--shadow-paper);
  }
  :root[data-page='sheet'] :is(.live, .editor, .starter, .sheet > .notice) { max-width: none; margin-inline: 0; }
  :root[data-page='sheet'] :is(.live, .editor) { flex: 1 0 auto; min-height: 8em; }
  /* A discussion post reads like a post, not a manuscript: a narrower card with no page shape. */
  :root[data-page='sheet'] .sheet[data-paper='post'] {
    --page-w: min(calc(var(--type) * .6 * 60 + 112px), 100cqw - 48px);
    --page-m: 56px;
    aspect-ratio: auto; min-height: 60vh; border-radius: var(--r-lg);
  }
  :root[data-page='sheet'] .deco-top { position: absolute; top: calc(var(--page-m) / 2 - .875em); left: var(--page-m); right: var(--page-m); margin: 0; }

  /* Full width: the window, with room at the sides. */
  :root[data-page='full'] .sheet { padding-inline: clamp(24px, 6vw, 96px); }
  :root[data-page='full'] :is(.live, .editor, .starter, .sheet > .notice) { max-width: none; }

  /* Centered: an empty paper's hint sits in the middle of the column, where the eye expects it. 43 characters, each 1ch and .01em apart. */
  :root[data-page='center'] .live.is-empty > p:first-child { text-indent: max(0px, calc(50% - 21.5ch - .215em)); }
  :root[data-page='center'] .live.is-empty > p:first-child::before { margin-left: max(0px, calc(50% - 21.5ch - .215em)); }
}

/* Page previews the paper style around the words: the running head, MLA's heading lines, the title where the style sets it. */
.deco { font: var(--type)/1.75 var(--mono); letter-spacing: .01em; color: var(--text); }
.deco-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 1.75em; margin-bottom: 1em; }
.deco-note {
  padding: 0; border: 0; background: none; font: 13px/1.4 var(--sans); letter-spacing: 0; color: var(--text-faint);
  text-decoration: underline; text-decoration-color: color-mix(in srgb, currentColor 40%, transparent); text-underline-offset: 3px;
}
.deco-note:hover { color: var(--text); }
.deco-run { margin-left: auto; color: var(--text-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.deco-head {
  display: grid; justify-items: start; width: calc(100% + .8em); margin: 0 -.4em; padding: 0 .4em;
  border: 0; border-radius: var(--r-sm); background: none; color: inherit; font: inherit; letter-spacing: inherit; text-align: left;
  transition: background var(--dur);
}
.deco-head:hover { background: var(--bg-hover); }
.deco-hint { color: var(--text-faint); }
.starter:not([hidden]) ~ .deco { display: none; }
:root[data-page='sheet'] .sheet:not([data-paper='plain'], [data-paper='post']) .live > h1:first-of-type { font-size: 1em; line-height: 1.75; text-align: center; margin: 0 0 1em; }
:root[data-page='sheet'] .sheet[data-paper='mla'] .live > h1:first-of-type { font-weight: 400; }

/* Paper style in the bar. */
.style-btn svg { width: 14px; height: 14px; margin: 0 -4px 0 -4px; }
.style-short { display: none; }
.menu > .style-item[aria-checked]::before { border: 0; border-radius: 0; }
.menu > .style-item[aria-checked='true']::before {
  background: var(--accent);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M3 7.4l2.6 2.6L11 4.5' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/14px no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M3 7.4l2.6 2.6L11 4.5' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/14px no-repeat;
}
.style-item .pro-tag { margin-left: 12px; }
#styleMenu { left: 0; right: auto; min-width: 290px; white-space: nowrap; }
@media (max-width: 720px) {
  #styleMenu { position: fixed; top: calc(58px + env(safe-area-inset-top)); left: 12px; right: 12px; min-width: 0; }
  .style-name, .style-btn svg { display: none; }
  .style-short { display: inline; }
  .bar .style-btn { padding: 0 6px; }
}
/* Phones: Sources turns into its icon, like Insert and Share, so the style fits beside it. */
.sources-icon { display: none; }
#sourcesBtn .sources-icon { width: 19px; height: 19px; stroke-linejoin: round; }
@media (max-width: 480px) {
  #sourcesBtn .sources-word { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  #sourcesBtn .sources-icon { display: block; }
  .bar .text-btn#sourcesBtn { min-width: 32px; padding: 0 4px; gap: 0; }
  .bar .text-btn { padding: 0 5px; }
  .bar .style-btn { font-size: 13px; }
}

/* The wordmark goes to the homepage. */
a.wordmark { display: inline-flex; align-items: center; min-height: 32px; margin-left: -6px; padding: 0 6px; border-radius: var(--r-sm); color: inherit; text-decoration: none; }
a.wordmark:hover { background: var(--bg-hover); }
a.wordmark:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The tour (lib/tour.js): the page dims around one control, and a small card says what it does. */
.tour { position: fixed; inset: 0; z-index: 80; }
.tour-hole {
  position: fixed; border-radius: var(--r-lg); pointer-events: none;
  box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--accent) 55%, transparent), 0 0 0 200vmax rgba(20, 16, 10, .42);
  transition: left .32s var(--ease), top .32s var(--ease), width .32s var(--ease), height .32s var(--ease);
}
:root[data-theme='dark'] .tour-hole { box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--accent) 55%, transparent), 0 0 0 200vmax rgba(0, 0, 0, .62); }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .tour-hole { box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--accent) 55%, transparent), 0 0 0 200vmax rgba(0, 0, 0, .62); } }
.tour-card {
  position: fixed; width: 320px; padding: 18px 20px 14px; border: 1px solid var(--line); border-radius: var(--r-xl);
  background: var(--bg-raised); color: var(--text); box-shadow: var(--shadow-sheet); outline: none;
  transition: left .32s var(--ease), top .32s var(--ease); animation: tour-in .24s var(--ease);
}
@keyframes tour-in { from { opacity: 0; transform: translateY(6px); } }
.tour-count { margin: 0 0 6px; font: 12px var(--sans); font-variant-numeric: tabular-nums; color: var(--text-faint); }
.tour-title { margin: 0 0 6px; font: 650 17px/1.3 var(--sans); letter-spacing: -.01em; }
.tour-text { margin: 0; font-size: 14.5px; line-height: 1.5; color: var(--text-dim); }
.tour-foot { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
.tour-space { flex: 1; }
.tour-foot .btn { height: 34px; padding: 0 14px; }
.tour-foot .btn[hidden] { display: none; }
.tour-skip { color: var(--text-dim); padding: 0 4px; }
body.touring .bar { opacity: 1 !important; }
/* Phones: a sheet along the bottom, with room for thumbs. */
.tour-card.sheet {
  left: 0; right: 0; bottom: 0; top: auto; width: auto; border-width: 1px 0 0; border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 20px 20px calc(16px + env(safe-area-inset-bottom)); transition: none; animation: tour-up .3s var(--ease);
}
@keyframes tour-up { from { transform: translateY(100%); } }
.tour-card.sheet .tour-foot .btn { height: 44px; padding: 0 20px; }
.tour-card.sheet .tour-skip { min-height: 44px; }
@media (prefers-reduced-motion: reduce) {
  .tour-hole, .tour-card { transition: none; animation: none; }
  .tour-card.sheet { animation: none; }
}

/* The account card at the foot of the drawer: opens the account sheet. */
.who-card {
  display: flex; align-items: center; gap: 10px; width: calc(100% + 16px); margin: 0 -8px; padding: 8px;
  border: 0; border-radius: var(--r-md); background: transparent; text-align: left; cursor: pointer;
  transition: background var(--dur);
}
.who-card:hover { background: var(--bg-hover); }
.who-text { display: grid; min-width: 0; flex: 1; }
.who-card .who-email { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-plan { font-size: 12.5px; color: var(--text-faint); }
.who-plan.is-pro, .acct-plan-name.is-pro { color: var(--accent); font-weight: 600; }
.avatar {
  flex: none; display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 14px; font-weight: 650;
}
.avatar-lg { width: 48px; height: 48px; font-size: 20px; }
.chev { flex: none; width: 16px; height: 16px; fill: none; stroke: var(--text-faint); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* The account sheet: grouped rows, like a settings screen. */
.acct-dialog { width: min(480px, calc(100vw - 32px)); }
.acct-dialog .dialog-body { padding-top: 12px; max-height: calc(100dvh - 200px); overflow-y: auto; }
.acct-who { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.acct-who-text { min-width: 0; }
.dialog-body .acct-email { margin: 0; color: var(--text); font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.dialog-body .acct-plan-name { margin: 2px 0 0; font-size: 13.5px; color: var(--text-faint); }
.group-label { margin: 18px 0 6px 2px; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); }
.acct-who + .group-label { margin-top: 0; }
.group { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--bg); overflow: hidden; }
.group-row {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 10px 14px;
  border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--text); text-align: left; text-decoration: none; font: inherit; cursor: pointer;
  transition: background var(--dur);
}
.group > .group-row:first-child, #acctBilling:first-child > .group-row:first-child { border-top: 0; }
.group-row:hover { background: var(--bg-hover); }
.group-row.plan-row { cursor: default; background: transparent; }
.row-text { display: grid; gap: 1px; min-width: 0; flex: 1; }
.row-title { font-size: 14.5px; font-weight: 500; }
.row-hint { font-size: 13px; color: var(--text-faint); }
.plan-row .row-hint { color: var(--text-dim); }
.group-row.danger .row-title, .group-row.alert .row-title { color: #b3261e; }
:root[data-theme='dark'] .group-row.danger .row-title, :root[data-theme='dark'] .group-row.alert .row-title { color: #ff9a95; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .group-row.danger .row-title, :root:not([data-theme='light']) .group-row.alert .row-title { color: #ff9a95; } }
.group-row[aria-busy='true'] { opacity: .6; cursor: progress; }
.dialog-body .group-foot { margin: 6px 2px 0; font-size: 12.5px; color: var(--text-faint); }
.acct-dialog .field-error { margin: 12px 0 0; }
.acct-foot .btn { flex: 1 1 0; white-space: nowrap; }
.acct-foot .btn[aria-busy='true'], .done-foot .btn[aria-busy='true'] { opacity: .6; cursor: progress; }
#acctSignOutAll { color: #b3261e; }
:root[data-theme='dark'] #acctSignOutAll { color: #ff9a95; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) #acctSignOutAll { color: #ff9a95; } }

/* Back from Checkout: one centered moment, then one way back to the paper. */
.done-dialog { width: min(440px, calc(100vw - 32px)); }
.done-dialog .dialog-inner { position: relative; }
.done-x { position: absolute; top: 12px; right: 12px; }
.done-hero { display: grid; justify-items: center; gap: 6px; padding: 40px 28px 4px; text-align: center; }
.done-hero h2 { margin: 12px 0 0; font: 700 24px/1.2 var(--sans); letter-spacing: -.025em; outline: none; }
.done-lead { margin: 0; max-width: 32ch; color: var(--text-dim); font-size: 15px; }
.done-mark { position: relative; width: 60px; height: 60px; }
.done-check { width: 60px; height: 60px; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.done-ring { stroke: var(--accent); stroke-width: 2.5; fill: var(--accent-soft); stroke-dasharray: 151; stroke-dashoffset: 0; }
.done-tick { stroke: var(--accent); stroke-width: 3.5; stroke-dasharray: 34; stroke-dashoffset: 0; }
.done-spin { display: none; position: absolute; inset: 0; border-radius: 50%; border: 2.5px solid var(--accent-soft); border-top-color: var(--accent); animation: done-spin .9s linear infinite; }
.done-dialog:not([data-state='on']) .done-check { display: none; }
.done-dialog[data-state='checking'] .done-spin, .done-dialog[data-state='processing']:not([data-waited]) .done-spin { display: block; }
/* Canceled, signed out, or not confirmable here: a quiet ring with a mark of its own, no spinner. */
.done-dialog[data-state='canceled'] .done-mark, .done-dialog[data-state='signin'] .done-mark, .done-dialog[data-state='problem'] .done-mark, .done-dialog[data-waited] .done-mark {
  border-radius: 50%; background: var(--bg-hover);
}
.done-dialog[data-state='canceled'] .done-mark::after, .done-dialog[data-state='signin'] .done-mark::after, .done-dialog[data-state='problem'] .done-mark::after, .done-dialog[data-waited] .done-mark::after {
  content: ''; position: absolute; left: 50%; top: 50%; width: 22px; height: 3px; margin: -1.5px 0 0 -11px; border-radius: 2px; background: var(--text-faint);
}
.done-body { padding: 22px 28px 4px; }
.done-body .group-label { margin-top: 0; }
.done-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.done-list li { position: relative; padding-left: 28px; color: var(--text); font-size: 14.5px; line-height: 1.4; }
.done-list li::before {
  content: ''; position: absolute; left: 0; top: 1px; width: 18px; height: 18px; border-radius: 50%; background: var(--accent-soft);
}
.done-list li::after {
  content: ''; position: absolute; left: 6px; top: 5px; width: 4px; height: 8px; border: solid var(--accent); border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.done-plan { margin-top: 20px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--bg); }
.dialog-body .done-plan p, .done-plan p { margin: 0; }
.done-plan-name { font-size: 14.5px; font-weight: 600; color: var(--text); }
.done-plan-when { margin-top: 2px !important; font-size: 13.5px; color: var(--text-dim); }
.done-foot { padding: 20px 28px 28px; }
.done-foot .btn { flex: 1 1 0; height: 44px; font-size: 15px; text-decoration: none; }
.done-foot a.btn:not(.primary) { color: var(--text); }

@keyframes done-spin { to { transform: rotate(360deg); } }
@keyframes done-pop { from { opacity: 0; transform: translateY(10px) scale(.97); } }
@keyframes done-ring { from { stroke-dashoffset: 151; fill-opacity: 0; } }
@keyframes done-tick { from { stroke-dashoffset: 34; } }
@keyframes done-rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes acct-in { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: no-preference) {
  .done-dialog.enter[open] { animation: done-pop 320ms var(--ease); }
  .done-dialog.enter[data-state='on'] .done-ring { animation: done-ring 520ms var(--ease) 80ms both; }
  .done-dialog.enter[data-state='on'] .done-tick { animation: done-tick 300ms var(--ease) 480ms both; }
  .done-dialog.enter[data-state='on'] .done-list li { animation: done-rise 360ms var(--ease) both; animation-delay: calc(520ms + var(--i, 0) * 60ms); }
  .done-dialog.enter[data-state='on'] .done-plan { animation: done-rise 360ms var(--ease) 860ms both; }
  .acct-dialog[open] { animation: acct-in 220ms var(--ease); }
}
@media (prefers-reduced-motion: reduce) {
  .done-spin { animation-duration: 2.4s; }
}
@media (max-width: 720px) {
  .acct-dialog, .done-dialog { width: 100vw; max-width: 100vw; }
  .acct-dialog .dialog-body { max-height: calc(100dvh - 180px); }
  .acct-foot { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  .done-foot { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .done-hero { padding-top: 36px; }
  .group-row { min-height: 56px; }
  .acct-foot .btn { flex-basis: 100%; }
}

/* ---------- Home: the sidebar and the Documents dashboard ----------
   The sidebar is always dark, in Format's own dark palette, so it reads as the frame around the papers in
   both themes. Contrast on --rail-bg: text 15.1:1, dim 7.5:1, accent 7.3:1, amber 8.0:1. */
.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; }
.home {
  --rail-bg: #161513; --rail-raised: #23211e; --rail-hover: #2b2925; --rail-line: #34312b;
  --rail-text: #ede9e2; --rail-dim: #aba59b; --rail-accent: #57a8ff; --rail-accent-ink: #0b1a2e; --rail-amber: #e0a24a;
  --rail-w: 248px;
  position: fixed; inset: 0; z-index: 21; display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr);
  background: var(--bg); color: var(--text);
}
:root[data-theme='dark'] .home { --rail-bg: #0e0d0c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .home { --rail-bg: #0e0d0c; } }
.rail {
  display: flex; flex-direction: column; gap: 6px; min-height: 0; overflow-y: auto;
  padding: 18px 14px calc(14px + env(safe-area-inset-bottom)); background: var(--rail-bg); color: var(--rail-text);
  border-right: 1px solid var(--rail-line);
}
.rail :focus-visible { outline-color: var(--rail-accent); }
.rail-mark { display: flex; align-items: center; min-height: 40px; padding: 0 8px; margin-bottom: 10px; }
.rail-mark img { display: block; height: 19px; width: auto; }
.rail-mark .rail-glyph { display: none; height: 24px; }
.rail-new {
  display: flex; align-items: center; justify-content: center; gap: 8px; height: 44px; margin-bottom: 14px;
  border: 0; border-radius: var(--r-md); background: var(--rail-accent); color: var(--rail-accent-ink); font-size: 14.5px; font-weight: 600;
}
.rail-new:hover { filter: brightness(1.08); }
.rail-new svg { stroke-width: 2; }
.rail-nav { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.rail-item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 40px; padding: 0 10px;
  border: 0; border-radius: var(--r-md); background: none; color: var(--rail-dim); font-size: 14px; font-weight: 500; text-align: left; text-decoration: none;
}
.rail-item:hover { background: var(--rail-hover); color: var(--rail-text); }
.rail-item[aria-current='page'] { background: var(--rail-raised); color: var(--rail-text); box-shadow: inset 3px 0 0 var(--rail-accent); }
.rail-item svg { flex: none; }
.rail-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.new-badge {
  margin-left: auto; padding: 1px 7px; border-radius: 999px; background: color-mix(in srgb, var(--rail-accent) 20%, transparent);
  color: var(--rail-accent); font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
}
.tpl-cards .new-badge { margin-left: 2px; background: var(--accent-soft); color: var(--accent); }
.rail-foot { margin-top: auto; display: grid; gap: 10px; padding-top: 16px; }
.usage { padding: 14px; border: 1px solid var(--rail-line); border-radius: var(--r-lg); background: var(--rail-raised); }
.usage-title { margin: 0 0 8px; font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--rail-dim); }
.meters { display: grid; gap: 10px; margin-bottom: 12px; }
.meter-row { display: grid; gap: 6px; width: 100%; padding: 2px 0; border: 0; background: none; color: inherit; text-align: left; }
.meter-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; }
.meter-num { font-variant-numeric: tabular-nums; font-weight: 600; }
.meter-track { display: block; height: 6px; border-radius: 999px; background: color-mix(in srgb, currentColor 16%, transparent); overflow: hidden; }
.meter-fill { display: block; height: 100%; border-radius: inherit; background: var(--meter, var(--rail-accent)); }
.meter-row[data-state='near'], .meter-row[data-state='full'] { --meter: var(--rail-amber); }
.meter-row[data-state='near'] .meter-num, .meter-row[data-state='full'] .meter-num { color: var(--rail-amber); }
.rail-up {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 38px;
  border: 1px solid color-mix(in srgb, var(--rail-accent) 55%, transparent); border-radius: var(--r-md); background: transparent;
  color: var(--rail-accent); font-size: 14px; font-weight: 600;
}
.rail-up:hover { background: color-mix(in srgb, var(--rail-accent) 14%, transparent); }
.rail-who { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border: 0; border-radius: var(--r-md); background: none; color: var(--rail-text); text-align: left; }
.rail-who:hover { background: var(--rail-hover); }
.rail-who .avatar { background: color-mix(in srgb, var(--rail-accent) 20%, transparent); color: var(--rail-accent); }
.rail-who-text { display: grid; }
.rail-email { font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.rail-plan { font-size: 12px; color: var(--rail-dim); }

.dash { min-width: 0; overflow-y: auto; padding: 28px clamp(16px, 4vw, 48px) 48px; }
.dash-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.dash-title { margin: 0; font: 700 26px/1.2 var(--sans); letter-spacing: -.025em; outline: none; }
.dash-back { max-width: 50%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; line-height: 34px; }
.dash-usage { display: grid; gap: 10px; margin: 0 0 16px; padding: 14px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--bg-raised); --rail-amber: var(--flag); --rail-accent: var(--accent); }
.dash-usage .dash-up { justify-self: start; }
.quick { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 26px; }
.quick-card {
  display: flex; align-items: center; gap: 14px; min-height: 76px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--bg-raised); color: var(--text); text-align: left; text-decoration: none; box-shadow: var(--shadow-card);
  transition: border-color var(--dur), transform var(--dur) var(--ease);
}
.quick-card:hover { border-color: var(--line-input); transform: translateY(-1px); }
.quick-icon { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
.quick-text { display: grid; gap: 2px; min-width: 0; }
.quick-text b { font-size: 14.5px; font-weight: 600; }
.quick-text small { font-size: 13px; line-height: 1.35; color: var(--text-faint); }
.dash-bar { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tab {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 12px; margin-bottom: -1px;
  border: 0; border-bottom: 2px solid transparent; background: none; color: var(--text-dim); font-size: 14.5px; font-weight: 500; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected='true'] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab-count { padding: 0 6px; border-radius: 999px; background: var(--bg-hover); color: var(--text-faint); font-size: 12px; font-weight: 600; }
.dash-tools { display: flex; align-items: center; gap: 8px; padding-bottom: 8px; }
.dash-sort select {
  height: 34px; padding: 0 28px 0 10px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg-raised); color: var(--text); font: 500 13.5px var(--sans);
}
.view-seg { display: flex; padding: 2px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg-raised); }
.view-seg button { display: grid; place-items: center; width: 32px; height: 28px; border: 0; border-radius: 6px; background: none; color: var(--text-faint); }
.view-seg button[aria-pressed='true'] { background: var(--accent-soft); color: var(--accent); }
.view-seg svg { width: 18px; height: 18px; }

.cards, .tpl-cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 18px; }
.card { position: relative; content-visibility: auto; contain-intrinsic-size: auto 300px; }
.card-open, .tpl-card {
  display: grid; width: 100%; padding: 0; border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden;
  background: var(--bg-raised); color: var(--text); text-align: left; transition: border-color var(--dur), box-shadow var(--dur);
}
.card-open:hover, .tpl-card:hover { border-color: var(--line-input); box-shadow: var(--shadow-card); }
.card[aria-current='true'] .card-open { border-color: var(--accent); }
.thumb { display: block; padding: 16px 18px 0; height: 168px; overflow: hidden; background: var(--canvas); border-bottom: 1px solid var(--line); }
.thumb-page {
  display: block; height: 100%; padding: 14px 14px 0; border-radius: 3px 3px 0 0; background: #fff; color: #222; box-shadow: 0 0 0 1px rgba(0, 0, 0, .06), 0 2px 6px rgba(0, 0, 0, .06);
  font: 7px/1.75 'Times New Roman', Times, var(--serif); overflow: hidden;
}
:root[data-theme='dark'] .thumb-page { background: #ece8e0; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .thumb-page { background: #ece8e0; } }
.thumb-title { display: block; margin-bottom: 4px; text-align: center; font-weight: 700; font-size: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb-text { display: block; text-indent: 2em; }
.card-body { display: grid; gap: 6px; padding: 12px 14px 14px; min-width: 0; }
.card-title { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; font-size: 14.5px; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
.tpl-card .card-title { padding-right: 0; display: flex; align-items: center; gap: 6px; }
.card-note { font-weight: 400; color: var(--text-faint); }
.card-meta, .card-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 12.5px; color: var(--text-faint); }
.style-badge { padding: 1px 6px; border-radius: 4px; background: var(--bg-hover); color: var(--text-dim); font: 600 10.5px/1.6 var(--mono); letter-spacing: .05em; text-transform: uppercase; }
.card-due { color: var(--flag); font-weight: 600; }
.card-del { position: absolute; right: 8px; top: 8px; width: 32px; height: 32px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg-raised); color: var(--text-dim); opacity: 0; display: grid; place-items: center; box-shadow: var(--shadow-card); }
.card:hover .card-del, .card-del:focus-visible { opacity: 1; }
.card-del:hover { background: var(--bg-hover); color: var(--text); }
@media (hover: none) { .card-del { opacity: 1; } }
.card-drop {
  display: grid; place-content: center; justify-items: center; gap: 4px; width: 100%; height: 100%; min-height: 248px; padding: 16px;
  border: 2px dashed var(--line-strong); border-radius: var(--r-lg); background: transparent; color: var(--text-dim); text-align: center;
  transition: border-color var(--dur), background var(--dur);
}
.card-drop:hover, body.dragging .card-drop { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.card-drop-icon { display: grid; place-items: center; width: 44px; height: 44px; margin-bottom: 6px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); }
.card-drop b { font-size: 15px; color: var(--text); }
.card-drop small { font-size: 13px; color: var(--text-faint); }
/* List: one row a paper, the thumbnail left out. */
.cards[data-view='list'] { grid-template-columns: 1fr; gap: 0; border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; background: var(--bg-raised); }
.cards[data-view='list'] .card { contain-intrinsic-size: auto 60px; border-top: 1px solid var(--line); }
.cards[data-view='list'] .card:first-child { border-top: 0; }
.cards[data-view='list'] .card-open { border: 0; border-radius: 0; box-shadow: none; }
.cards[data-view='list'] .card-open:hover { background: var(--bg-hover); }
.cards[data-view='list'] .thumb { display: none; }
.cards[data-view='list'] .card-body { grid-template-columns: minmax(0, 1fr) auto; align-items: center; padding: 12px 52px 12px 16px; }
.cards[data-view='list'] .card-sub { grid-column: 1 / -1; }
.cards[data-view='list'] .card-del { top: 50%; transform: translateY(-50%); right: 10px; border: 0; background: none; box-shadow: none; }
.cards[data-view='list'] .card-title { -webkit-line-clamp: 1; }
.cards[data-view='list'] .card-drop { min-height: 56px; grid-auto-flow: column; gap: 10px; border: 0; border-radius: 0; place-content: center start; padding: 0 16px; }
.cards[data-view='list'] .card-drop-icon { width: 30px; height: 30px; margin: 0; }
.cards[data-view='list'] .card-drop small::before { content: ' '; }
.dash-empty { margin: 24px 0; color: var(--text-faint); }
.tpl-cards .thumb-title { white-space: normal; }

/* Wide screens keep labels; tablets fold the sidebar to icons; phones get a bottom bar. */
@media (max-width: 1000px) {
  .home { --rail-w: 72px; }
  .rail { align-items: center; padding: 14px 8px; }
  .rail-mark img:first-child { display: none; }
  .rail-mark .rail-glyph { display: block; }
  .rail-label, .new-badge, .usage-title, .meters { display: none; }
  .rail-new, .rail-item, .rail-up { width: 48px; height: 44px; padding: 0; justify-content: center; }
  .rail-nav { justify-items: center; }
  .usage { padding: 0; border: 0; background: none; }
  .rail-who { justify-content: center; width: 48px; padding: 6px 0; }
  .dash-usage:not([hidden]) { display: grid; }
  .quick { grid-template-columns: 1fr; gap: 8px; }
  .quick-card { min-height: 60px; }
}
@media (min-width: 1001px) { .dash-usage { display: none !important; } }
@media (max-width: 640px) {
  .home { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .rail {
    grid-row: 2; flex-direction: row; justify-content: space-around; align-items: center; gap: 0; overflow: visible;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--rail-line);
  }
  .rail-mark, .rail-nav li:nth-child(n + 3), .usage, .rail-who { display: none !important; }
  .rail-nav { display: contents; }
  .rail-new { order: 2; width: 52px; height: 44px; margin: 0; border-radius: 14px; }
  .rail-nav li:nth-child(1) { order: 1; }
  .rail-nav li:nth-child(2) { order: 3; }
  .rail-foot { order: 4; margin: 0; padding: 0; }
  .rail-foot .rail-who { display: flex !important; }
  .rail-item { width: 52px; }
  .dash { padding: 16px 16px 24px; }
  .dash-title { font-size: 22px; }
  .dash-head { margin-bottom: 12px; }
  .dash-back { max-width: 55%; height: 44px; line-height: 42px; }
  .dash-bar { flex-direction: column; align-items: stretch; gap: 0; }
  .dash-tools { justify-content: space-between; padding: 8px 0; }
  .tab { height: 44px; }
  .cards, .tpl-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .thumb { height: 128px; padding: 10px 12px 0; }
  .card-drop { min-height: 190px; }
  .card-del { opacity: 1; width: 40px; height: 40px; right: 4px; top: 4px; }
  .cards[data-view='list'] .card-del { right: 4px; }
  .view-seg button { width: 44px; height: 38px; }
  .dash-sort select { height: 40px; }
}
@media (max-width: 380px) { .cards, .tpl-cards { grid-template-columns: 1fr; } }
@media print { .home { display: none !important; } }

.drawer-all {
  display: flex; align-items: center; gap: 10px; width: calc(100% - 24px); min-height: 40px; margin: 0 12px 6px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg); color: var(--text); font-size: 14px; font-weight: 500;
}
.drawer-all:hover { background: var(--bg-hover); }
@media (max-width: 720px) { .drawer-all { min-height: 44px; } }

/* ---------- The Upgrade to Pro modal: a real page on the left, the plans on the right ---------- */
.pro-dialog { width: min(820px, calc(100vw - 32px)); }
.pro-inner { display: grid; grid-template-columns: 300px minmax(0, 1fr); }
.pro-art { display: flex; flex-direction: column; justify-content: center; gap: 12px; padding: 28px 24px; background: var(--canvas); border-right: 1px solid var(--line); border-radius: var(--r-xl) 0 0 var(--r-xl); }
.pro-art img { display: block; width: 100%; height: auto; border-radius: 3px; box-shadow: var(--shadow-paper); }
.pro-art-note { margin: 0; font-size: 12.5px; color: var(--text-faint); text-align: center; }
.pro-main { min-width: 0; display: flex; flex-direction: column; }
.pro-main .dialog-head h2 { font-size: 22px; }
.pro-reason { color: var(--text) !important; }
.pro-reason:empty { display: none; }
.pro-dialog .pro-list { list-style: none; padding: 0; margin: 0 0 18px; display: grid; gap: 6px; }
.pro-dialog .pro-list li { position: relative; margin: 0; padding-left: 26px; font-size: 14.5px; }
.pro-dialog .pro-list li::before {
  content: ''; position: absolute; left: 0; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--accent-soft);
}
.pro-dialog .pro-list li::after {
  content: ''; position: absolute; left: 5px; top: 6px; width: 4px; height: 8px; border: solid var(--accent); border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.plan-rows { display: grid; gap: 8px; margin: 0 0 12px; padding: 0; border: 0; min-width: 0; }
.plan-opt {
  position: relative; display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 10px 14px; border: 1px solid var(--line-input);
  border-radius: var(--r-lg); background: var(--bg); cursor: pointer; transition: border-color var(--dur), background var(--dur);
}
.plan-opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.plan-opt input { flex: none; width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.plan-text { display: grid; gap: 1px; flex: 1; min-width: 0; }
.plan-text b { font-size: 14.5px; font-weight: 600; }
.plan-text small { font-size: 12.5px; color: var(--text-faint); }
.save-badge { margin-left: 4px; padding: 1px 7px; border-radius: 999px; background: color-mix(in srgb, #1f8a4c 16%, transparent); color: #17703d; font-size: 11px; font-weight: 700; letter-spacing: .02em; }
:root[data-theme='dark'] .save-badge { color: #7ccf9b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .save-badge { color: #7ccf9b; } }
.plan-price { flex: none; text-align: right; white-space: nowrap; }
.plan-price b { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.plan-price small { font-size: 12.5px; color: var(--text-faint); }
.plan-price s { color: var(--text-faint); font-size: 13px; }
.pro-dialog .pro-foot { display: grid; gap: 10px; padding-top: 4px; margin-top: auto; }
.pro-go { width: 100%; height: 44px; font-size: 15px; }
.pro-go[aria-busy='true'] { opacity: .7; cursor: progress; }
.pro-refund { margin: 0; font-size: 12.5px; color: var(--text-faint); text-align: center; }
@media (max-width: 720px) {
  .pro-dialog { width: 100vw; }
  .pro-inner { grid-template-columns: 1fr; }
  .pro-art { display: none; }
  .pro-main { max-height: calc(100dvh - 24px); overflow-y: auto; }
  .pro-dialog .pro-foot { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}

/* ---------- The sign-up survey: one question a step, over the blurred dashboard ---------- */
.survey { width: min(560px, calc(100vw - 32px)); }
.survey::backdrop { background: rgba(20, 16, 10, .32); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.survey-inner { padding: 22px 28px 24px; }
.survey-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.survey-count { margin: 0; font-size: 12.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); }
.survey-skip { color: var(--text-dim); }
.survey-bar { height: 4px; margin: 10px 0 20px; border-radius: 999px; background: var(--bg-hover); overflow: hidden; }
.survey-bar span { display: block; height: 100%; width: 20%; border-radius: inherit; background: var(--accent); transition: width 240ms var(--ease); }
.survey-title { margin: 0 0 4px; font: 700 22px/1.25 var(--sans); letter-spacing: -.02em; outline: none; }
.survey-sub { margin: 0 0 18px; color: var(--text-dim); }
.survey-opts { display: grid; gap: 8px; margin: 0 0 14px; padding: 0; border: 0; min-width: 0; }
.survey-opts.two { grid-template-columns: 1fr 1fr; }
.opt {
  display: flex; align-items: flex-start; gap: 12px; min-height: 56px; padding: 12px 14px; border: 1px solid var(--line-input); border-radius: var(--r-lg);
  background: var(--bg); cursor: pointer; transition: border-color var(--dur), background var(--dur);
}
.opt:hover { background: var(--bg-hover); }
.opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.opt:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.opt input { flex: none; width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--accent); }
.opt-text { display: grid; gap: 2px; min-width: 0; }
.opt-text b { font-size: 14.5px; font-weight: 600; }
.opt-text small { font-size: 13px; line-height: 1.35; color: var(--text-faint); }
.opt .pro-tag { vertical-align: 1px; }
.survey-date { margin: 0 0 14px; }
.survey-date input { width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--line-input); border-radius: var(--r-md); background: var(--bg); color: var(--text); font: 15px var(--sans); }
.survey-privacy { display: flex; align-items: flex-start; gap: 8px; margin: 0 0 18px; font-size: 12.5px; line-height: 1.45; color: var(--text-faint); }
.survey-privacy svg { flex: none; width: 15px; height: 15px; margin-top: 1px; }
.survey-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.survey-back { color: var(--text-dim); min-height: 44px; }
.survey-next { min-width: 132px; height: 44px; font-size: 15px; }
.survey-next:disabled { opacity: .45; cursor: not-allowed; filter: none; }
@media (max-width: 720px) {
  .survey { width: 100vw; }
  .survey-inner { padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); max-height: calc(100dvh - 16px); overflow-y: auto; }
  .survey-opts.two { grid-template-columns: 1fr; }
  .survey-skip { min-height: 44px; }
}
@media (prefers-reduced-motion: no-preference) { .survey[open] .survey-opts { animation: acct-in 200ms var(--ease); } }
