/* ---------- tokens ---------- */
:root {
  --bg: #fbfaf7;
  --panel: #ffffff;
  --ink: #1b1b19;
  --muted: #6d6b66;
  --faint: #a3a19b;
  --line: #e7e4dc;
  --line-strong: #d4d0c6;
  --accent: #2f5be8;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --hl: rgba(255, 205, 0, .32);
  --hl-2: rgba(255, 180, 0, .45);
  --hl-active: rgba(255, 180, 0, .62);
  --code-bg: #f3f1eb;
  --add-bg: #e9f7ec; --add-ink: #1a7f37; --add-strong: #b7ebc3;
  --del-bg: #fdecec; --del-ink: #c0392b; --del-strong: #ffc9c9;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px -8px rgba(0,0,0,.12);
  --shadow-lg: 0 2px 4px rgba(0,0,0,.06), 0 14px 36px -10px rgba(0,0,0,.2);
  --sans: Geist, Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131312;
    --panel: #1c1c1a;
    --ink: #ebe9e3;
    --muted: #9c9a92;
    --faint: #6a6862;
    --line: #2a2a27;
    --line-strong: #3a3935;
    --accent: #7c9eff;
    --accent-ink: #0d1330;
    --danger: #ff7b6b;
    --hl: rgba(255, 205, 0, .22);
    --hl-2: rgba(255, 180, 0, .32);
    --hl-active: rgba(255, 190, 0, .48);
    --code-bg: #232321;
    --add-bg: #14261a; --add-ink: #5fd484; --add-strong: #1f4a2a;
    --del-bg: #2c1816; --del-ink: #ff8a7a; --del-strong: #5a2622;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px -8px rgba(0,0,0,.6);
    --shadow-lg: 0 2px 4px rgba(0,0,0,.5), 0 14px 36px -10px rgba(0,0,0,.8);
    color-scheme: dark;
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
button { font: inherit; color: inherit; }
kbd {
  font: 11px/1 var(--mono); padding: 2px 5px; border: 1px solid var(--line-strong);
  border-bottom-width: 2px; border-radius: 4px; background: var(--panel); color: var(--muted);
}
code, pre { font-family: var(--mono); }
[hidden] { display: none !important; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: 8px; border: 1px solid transparent;
  font-size: 14px; font-weight: 500; line-height: 1.2; cursor: pointer; white-space: nowrap;
  text-decoration: none !important; transition: background .12s, border-color .12s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ink); color: var(--bg); }
.btn.primary:hover { background: #000; }
@media (prefers-color-scheme: dark) { .btn.primary:hover { background: #fff; } }
.btn.ghost { border-color: var(--line-strong); background: transparent; color: var(--ink); }
.btn.ghost:hover { background: var(--panel); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
button.link {
  background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: inherit;
}
button.link:hover { text-decoration: underline; text-underline-offset: 2px; }
button.link.danger { color: var(--danger); }
.pill {
  display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 999px; background: var(--add-bg); color: var(--add-ink); margin-left: 6px; vertical-align: 1px;
}
.muted { color: var(--muted); }

.brand { font: 500 13px var(--mono); color: var(--muted); letter-spacing: -.01em; }
.brand:hover { color: var(--ink); text-decoration: none; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: 54px; padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.top .actions { display: flex; align-items: center; gap: 14px; min-width: 0; font-size: 14px; }
.top .actions > a:not(.btn) { color: var(--muted); }
.top .actions > a:not(.btn):hover { color: var(--ink); }
.top .meta { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .meta a { color: var(--muted); }
.top .meta .ver { font-family: var(--mono); font-size: 12px; padding: 2px 6px; border-radius: 5px; background: var(--code-bg); color: var(--ink); }
.top .dot { margin: 0 6px; color: var(--faint); }
@media (max-width: 720px) {
  .top { padding: 0 14px; }
  .top .meta { display: none; }
  .top .actions { gap: 10px; }
}

/* ---------- stage / grid ---------- */
.stage {
  position: relative;
  display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 44px; align-items: start;
  max-width: 1200px; margin: 0 auto; padding: 36px 24px 120px;
}
.stage.single { display: block; max-width: 900px; }
.col { min-width: 0; }
@media (max-width: 1023px) {
  .stage { grid-template-columns: minmax(0, 1fr); gap: 32px; padding: 24px 16px 100px; }
}

.flash {
  margin: 0 0 22px; padding: 10px 14px; border-radius: 9px;
  background: var(--add-bg); color: var(--add-ink); font-size: 14px; border: 1px solid var(--add-strong);
}
.flash strong { font-weight: 600; }
.flash a, .flash button.link { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.flash.warn { background: #fff7db; color: #7a5b00; border-color: #f2e2a4; }
.flash.error { background: var(--del-bg); color: var(--del-ink); border-color: var(--del-strong); }
@media (prefers-color-scheme: dark) { .flash.warn { background: #2c2510; color: #f2d27a; border-color: #4d3f13; } }
form.inline { display: inline; }
.docfoot {
  display: flex; justify-content: space-between; gap: 12px; margin-top: 56px; padding-top: 16px;
  border-top: 1px solid var(--line); color: var(--faint); font-size: 13px;
}
.pagetitle { font-size: 22px; font-weight: 600; letter-spacing: -.02em; margin: 6px 0 20px; }

/* ---------- rendered markdown ---------- */
.md {
  font-size: 17px; line-height: 1.7; max-width: 72ch; overflow-wrap: break-word;
}
.md > :first-child { margin-top: 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 {
  font-weight: 650; letter-spacing: -.022em; line-height: 1.25; margin: 2em 0 .6em; scroll-margin-top: 70px;
}
.md h1 { font-size: 2.05em; margin-top: .4em; }
.md h2 { font-size: 1.5em; padding-bottom: .3em; border-bottom: 1px solid var(--line); }
.md h3 { font-size: 1.2em; }
.md h4 { font-size: 1.02em; }
.md h5, .md h6 { font-size: .95em; color: var(--muted); }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md table, .md hr { margin: 0 0 1.15em; }
.md ul, .md ol { padding-left: 1.6em; }
.md li { margin: .25em 0; }
.md li > p { margin-bottom: .5em; }
.md ul.task-list { list-style: none; padding-left: .4em; }
.md li.task input { margin: 0 .55em 0 0; vertical-align: -1px; accent-color: var(--accent); }
.md blockquote {
  padding: .1em 0 .1em 1.1em; border-left: 3px solid var(--line-strong); color: var(--muted);
}
.md blockquote > :last-child { margin-bottom: 0; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 2.4em 0; }
.md img { max-width: 100%; height: auto; border-radius: 8px; }
.md code {
  font-size: .86em; background: var(--code-bg); padding: .15em .4em; border-radius: 5px;
}
.md pre {
  position: relative; background: var(--code-bg); border-radius: 10px; padding: 16px 18px;
  overflow-x: auto; font-size: .82em; line-height: 1.6; border: 1px solid var(--line);
}
.md pre code { background: none; padding: 0; font-size: inherit; border-radius: 0; }
.md pre[data-lang]::after {
  content: attr(data-lang); position: absolute; top: 8px; right: 12px;
  font: 500 10px/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--faint);
}
.md table { border-collapse: collapse; display: block; overflow-x: auto; font-size: .92em; }
.md th, .md td { border: 1px solid var(--line); padding: .45em .8em; text-align: left; vertical-align: top; }
.md th { background: var(--code-bg); font-weight: 600; }
.md a { text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent); text-underline-offset: 2px; }
.md a:hover { text-decoration-color: var(--accent); }
.md ::selection { background: rgba(47, 91, 232, .22); }

.md pre.mermaid {
  background: transparent; border: 0; padding: 8px 0; text-align: center; font-size: .8em; color: var(--muted);
}
.md pre.mermaid.rendered { color: inherit; }
.md pre.mermaid svg { max-width: 100%; height: auto; }

/* highlight.js tokens */
.hljs-comment, .hljs-quote { color: var(--faint); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-name, .hljs-built_in, .hljs-doctag { color: #a626a4; }
.hljs-string, .hljs-title.function_ .hljs-string, .hljs-attr, .hljs-symbol, .hljs-bullet, .hljs-addition, .hljs-meta .hljs-string { color: #50a14f; }
.hljs-number, .hljs-regexp, .hljs-link, .hljs-variable, .hljs-template-variable { color: #986801; }
.hljs-title, .hljs-section, .hljs-selector-id, .hljs-selector-class, .hljs-type, .hljs-class .hljs-title { color: #4078f2; }
.hljs-attribute, .hljs-tag, .hljs-meta { color: #e45649; }
.hljs-deletion { color: var(--del-ink); }
.hljs-emphasis { font-style: italic; } .hljs-strong { font-weight: 600; }
@media (prefers-color-scheme: dark) {
  .hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-name, .hljs-built_in, .hljs-doctag { color: #c678dd; }
  .hljs-string, .hljs-attr, .hljs-symbol, .hljs-bullet, .hljs-addition { color: #98c379; }
  .hljs-number, .hljs-regexp, .hljs-link, .hljs-variable, .hljs-template-variable { color: #d19a66; }
  .hljs-title, .hljs-section, .hljs-selector-id, .hljs-selector-class, .hljs-type { color: #61afef; }
  .hljs-attribute, .hljs-tag, .hljs-meta { color: #e06c75; }
}

/* ---------- comment highlights ---------- */
mark.hl {
  background: var(--hl); color: inherit; border-radius: 2px; cursor: pointer;
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
  transition: background .12s;
}
mark.hl mark.hl { background: var(--hl-2); }
mark.hl:hover, mark.hl.active, mark.hl.pending { background: var(--hl-active); }
mark.hl.pending { outline: 2px solid var(--hl-active); outline-offset: 1px; }

.sel-btn {
  position: absolute; z-index: 30;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: 999px; border: 0;
  background: var(--ink); color: var(--bg); font-size: 13px; font-weight: 500; cursor: pointer;
  box-shadow: var(--shadow-lg); animation: pop .12s ease-out;
}
.sel-btn:hover { background: var(--accent); color: var(--accent-ink); }
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.96); } to { opacity: 1; transform: none; } }

/* ---------- threads sidebar ---------- */
.threads { position: relative; min-width: 0; }
.thread {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; box-shadow: var(--shadow); font-size: 13px; line-height: 1.45;
  transition: top .18s cubic-bezier(.2,.7,.2,1), border-color .12s, box-shadow .12s, opacity .12s;
  cursor: default;
}
.thread.active { border-color: var(--accent); box-shadow: var(--shadow-lg); z-index: 2; }
.thread.resolved { opacity: .7; }
.thread.resolved.active { opacity: 1; }
@media (min-width: 1024px) {
  .thread { position: absolute; left: 0; right: 0; }
  .thread:not(.active) .quote:not(.orphan-quote) { display: none; }
}
@media (max-width: 1023px) {
  .threads:not(:empty)::before {
    content: "Comments"; display: block; font-size: 13px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .06em; color: var(--muted); margin: 0 0 12px;
  }
  .thread + .thread { margin-top: 10px; }
  .sel-hint { display: none; }
}
.thread .quote {
  margin: 0 0 8px; padding: 1px 0 1px 9px; border-left: 3px solid var(--hl-active);
  color: var(--muted); font-size: 12px; line-height: 1.4; white-space: pre-line;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.thread .note { font-size: 11.5px; color: var(--faint); margin: 0 0 6px; }
.thread .orphan-note { color: #7a5b00; }
@media (prefers-color-scheme: dark) { .thread .orphan-note { color: #f2d27a; } }
.thread .spacer { flex: 1; }

.comment + .comment { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.comment .chead { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; min-height: 20px; }
.comment .author { font-weight: 600; }
.comment time { color: var(--faint); font-size: 11.5px; }
.comment .cbody { white-space: pre-wrap; overflow-wrap: break-word; }
.thread .icon {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px;
  background: none; border: 0; color: var(--faint); cursor: pointer; padding: 0;
}
.thread .icon:hover { background: var(--code-bg); color: var(--ink); }
.thread .icon.check:hover, .thread .icon.check.on { color: var(--add-ink); }
.thread .icon.x { opacity: 0; }
.comment:hover .icon.x, .thread.active .icon.x { opacity: 1; }
.thread .icon.x:hover { color: var(--danger); }

.thread form { margin-top: 8px; }
.thread textarea, .thread input[type=text] {
  width: 100%; font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line);
  border-radius: 7px; padding: 6px 9px; resize: none; line-height: 1.4;
}
.thread textarea:focus, .thread input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: -1px; border-color: var(--accent); }
.thread .row { display: flex; gap: 6px; margin-top: 6px; align-items: center; }
.thread .row input { flex: 1; min-width: 0; font-size: 12.5px; padding: 5px 8px; }
.thread .as { color: var(--faint); font-size: 12px; }
.thread .as b { color: var(--muted); font-weight: 500; }
.thread form.reply:not(.open) .row { display: none; }
.thread form.reply:not(.open) { margin-top: 4px; }
.thread form.reply:not(.open) textarea {
  background: transparent; border-color: transparent; padding: 4px 0 0; color: var(--faint); height: auto;
}
.thread form.reply:not(.open) textarea:hover { color: var(--muted); }
.thread.composing { border-color: var(--accent); }

/* ---------- editor ---------- */
.editor textarea {
  display: block; width: 100%; min-height: 62vh; padding: 20px 22px;
  font: 14.5px/1.65 var(--mono); color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; resize: vertical; tab-size: 2;
  box-shadow: var(--shadow);
}
.editor textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: -1px; border-color: var(--accent); }
.editor .bar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-top: 12px; }
.editor .hint { color: var(--muted); font-size: 13px; display: inline-flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.editor .grow { flex: 1; }
.editor input.name {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 7px 10px; width: 200px; max-width: 45vw;
}
.editor input.name:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: -1px; border-color: var(--accent); }
form.danger { margin-top: 48px; text-align: right; font-size: 13px; }

/* ---------- home ---------- */
.is-paste { padding-top: 7vh; }
.intro { margin-bottom: 26px; }
.intro h1 { font-size: clamp(26px, 4vw, 34px); font-weight: 650; letter-spacing: -.03em; line-height: 1.1; margin: 0 0 10px; }
.intro p { margin: 0; color: var(--muted); font-size: 16px; line-height: 1.6; max-width: 62ch; }
.is-home .editor textarea { min-height: 52vh; }
.foot { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 40px; color: var(--faint); font-size: 13px; }
.foot a { color: var(--muted); }
.foot a:hover { color: var(--ink); }
.foot code { font-size: 12px; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }

/* ---------- history ---------- */
.history { width: 100%; border-collapse: collapse; font-size: 14px; }
.history th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 0 12px 10px; border-bottom: 1px solid var(--line); }
.history td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.history td:first-child a { font-family: var(--mono); font-weight: 600; }
.history .num { font-variant-numeric: tabular-nums; color: var(--muted); }
.history .ops { text-align: right; white-space: nowrap; }
.history .ops a, .history .ops button { margin-left: 14px; font-size: 13px; }
.history th:last-child, .history td:last-child { text-align: right; }

/* ---------- diff ---------- */
.diffbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; font-size: 14px; color: var(--muted); flex-wrap: wrap; }
.diffbar select { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line-strong); border-radius: 7px; padding: 5px 8px; margin-left: 6px; }
.diffbar .arrow { color: var(--faint); }
.diffbar .counts { margin-left: auto; font-family: var(--mono); font-size: 13px; }
.diffbar .add { color: var(--add-ink); font-weight: 600; } .diffbar .del { color: var(--del-ink); font-weight: 600; }
.diffwrap { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; box-shadow: var(--shadow); }
table.diff { width: 100%; border-collapse: collapse; font: 13px/1.6 var(--mono); }
table.diff td { padding: 0 14px 0 0; vertical-align: top; white-space: pre-wrap; overflow-wrap: anywhere; }
table.diff td.n { width: 1%; min-width: 44px; padding: 0 10px; text-align: right; color: var(--faint); user-select: none; border-right: 1px solid var(--line); font-size: 12px; }
table.diff td.c { padding-left: 8px; }
table.diff .sign { display: inline-block; width: 1.2em; color: var(--faint); user-select: none; }
table.diff tr.add { background: var(--add-bg); } table.diff tr.add .sign { color: var(--add-ink); }
table.diff tr.del { background: var(--del-bg); } table.diff tr.del .sign { color: var(--del-ink); }
table.diff ins { background: var(--add-strong); text-decoration: none; border-radius: 3px; }
table.diff del { background: var(--del-strong); text-decoration: none; border-radius: 3px; }
table.diff tr.folded { display: none; }
table.diff tr.fold-toggle td { padding: 4px 12px; background: var(--code-bg); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
table.diff tr.fold-toggle button { background: none; border: 0; color: var(--accent); cursor: pointer; font: 12px var(--sans); }
.empty { color: var(--muted); padding: 24px; }
