:root {
  --bg: #f7f6f3; --panel: #ffffff; --ink: #1d1d1f; --dim: #6b6b70; --line: #e3e1dc; --accent: #2f6fde;
  --accent-ink: #ffffff; --open: #b26b00; --done: #2e7d4f; --warn: #b3261e; --mark: #fff1a8; --code: #f0eee9;
  --scratch: #fff7e0;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17171a; --panel: #212125; --ink: #ececf0; --dim: #9a9aa2; --line: #333338; --accent: #6ea1ff;
    --accent-ink: #0d1424; --open: #f0b35a; --done: #6fcf97; --warn: #ff8a80; --mark: #5c5220; --code: #2c2c31;
    --scratch: #3a3220;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font: 0.88em/1.45 ui-monospace, "SF Mono", Menlo, monospace; background: var(--code); border-radius: 4px; }
code { padding: 0.08em 0.3em; }
pre { padding: 10px 12px; overflow-x: auto; }
pre code { background: none; padding: 0; }
img { max-width: 100%; border-radius: 6px; border: 1px solid var(--line); }
/* Screenshots fit the screen: never taller than most of it (a phone shot stays a phone's width),
   a click shows one whole. */
.md img { display: inline-block; vertical-align: top; width: auto; height: auto; max-height: min(55vh, 520px); margin: 8px 12px 8px 0; cursor: zoom-in; }
#lightbox { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,0.82); display: flex; align-items: center; justify-content: center; cursor: zoom-out; padding: 16px; }
#lightbox img { max-width: 100%; max-height: 100%; border: 0; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 2px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.4em 0; }
blockquote { margin: 0.6em 0; padding: 0.1em 1em; border-left: 3px solid var(--line); color: var(--dim); }
.dim { color: var(--dim); }
.missing { color: var(--dim); font-style: italic; }

header { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
.bar { max-width: 920px; margin: 0 auto; padding: 8px 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--ink); letter-spacing: 0.02em; }
#project { font: inherit; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; }
#project[hidden] { display: none; }
nav { display: flex; gap: 2px; flex-wrap: wrap; }
nav a { padding: 4px 10px; border-radius: 999px; color: var(--dim); }
nav a.on { background: var(--panel); color: var(--ink); box-shadow: 0 0 0 1px var(--line); text-decoration: none; }
.badge { display: inline-block; min-width: 1.5em; padding: 0 0.4em; margin-left: 4px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 0.75em; text-align: center; line-height: 1.5; }
#search { margin-left: auto; }
#search input { font: inherit; width: 12em; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); }
/* The inbox spans every project: a mail icon at the top right, outside the project's tabs (N4). */
#mail { position: relative; display: inline-flex; align-items: center; padding: 3px 6px; border-radius: 8px; color: var(--dim); }
#mail:hover, #mail.on { color: var(--ink); text-decoration: none; }
#mail.on { background: var(--panel); box-shadow: 0 0 0 1px var(--line); }
#mail .badge { position: absolute; top: -4px; right: -8px; margin: 0; }
#mail .badge[hidden] { display: none; }
/* Buttons stay out of a selection, so a quoted card doesn't carry "Read Done". */
button, select.act, .marks { -webkit-user-select: none; user-select: none; }

main { max-width: 920px; margin: 0 auto; padding: 16px 16px calc(80px + env(safe-area-inset-bottom)); }
h1 { font-size: 1.5em; line-height: 1.25; margin: 0.3em 0 0.2em; }
h2 { font-size: 1.2em; margin: 1.6em 0 0.5em; }
.md h1, .md h2, .md h3 { font-size: 1.05em; margin: 1.1em 0 0.3em; }
.md > :first-child { margin-top: 0; }
.md ul, .md ol { padding-left: 1.3em; }
.md li { margin: 0.2em 0; }
.table { overflow-x: auto; }
table { border-collapse: collapse; font-size: 0.92em; }
th, td { border: 1px solid var(--line); padding: 4px 8px; vertical-align: top; text-align: left; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin: 12px 0; }
.card.q { border-left: 4px solid var(--open); }
.card.q.closed { border-left-color: var(--done); }
.group { margin: 22px 0 6px; font-weight: 600; }
.group .dim { font-weight: 400; }
.meta { font-size: 0.85em; color: var(--dim); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.id { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.85em; }
.st { font-size: 0.78em; padding: 0 7px; border-radius: 999px; border: 1px solid currentColor; }
.st.open { color: var(--open); }
.st.closed { color: var(--done); }
.qtitle { font-weight: 600; margin: 4px 0; }
.entry { margin: 10px 0 0; padding: 8px 12px; border-radius: 8px; background: var(--code); }
.entry.answer { background: color-mix(in srgb, var(--done) 14%, var(--panel)); }
.entry.verdict { background: color-mix(in srgb, var(--accent) 14%, var(--panel)); }
.entry.scratch { background: var(--scratch); }
.entry .who { font-size: 0.8em; color: var(--dim); }

form.write { margin-top: 12px; }
textarea { width: 100%; min-height: 4.5em; font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); resize: vertical; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
button, select.act { font: inherit; padding: 5px 14px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); cursor: pointer; }
button.quiet, select.act { background: transparent; color: var(--ink); border-color: var(--line); }
button:disabled { opacity: 0.5; cursor: default; }

ul.items { list-style: none; padding: 0; margin: 6px 0; }
ul.items li { padding: 3px 0; }
ul.items ul.items { padding-left: 1.2em; border-left: 1px solid var(--line); margin-left: 0.3em; }
.needs { font-size: 0.85em; color: var(--open); }
.why { color: var(--dim); }
.hit { margin: 10px 0; }
.hit .snip { color: var(--dim); font-size: 0.92em; }
.batch { margin: 10px 0; }
.batch ul { margin: 4px 0; padding-left: 1.2em; font-size: 0.9em; color: var(--dim); overflow-wrap: anywhere; }
details summary { cursor: pointer; color: var(--dim); }
.more { display: block; margin: 16px auto; }

#toasts { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 10; width: min(92vw, 520px); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; display: flex; gap: 12px; align-items: center; box-shadow: 0 4px 18px rgba(0,0,0,0.2); }
.toast.err { background: var(--warn); color: #fff; }
.toast button { margin-left: auto; padding: 2px 10px; background: transparent; color: inherit; border-color: currentColor; }

/* Item references: a mention is a link once the item is known to exist; previews on hover. */
a.ref { color: inherit; pointer-events: none; }
a.ref.ok { color: var(--accent); pointer-events: auto; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.9em; border-bottom: 1px dotted currentColor; }
a.ref.ok:hover, a.ref.lit { text-decoration: none; background: color-mix(in srgb, var(--accent) 14%, transparent); border-radius: 3px; }
#peek { position: absolute; z-index: 15; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; box-shadow: 0 6px 24px rgba(0,0,0,0.16); font-size: 0.92em; pointer-events: none; }
#peek .qtitle { margin: 2px 0; }
/* The margin: a note per item mentioned, joined to its mention. */
#margin { position: absolute; top: 0; left: 0; width: 100%; pointer-events: none; z-index: 3; }
#margin svg { position: absolute; inset: 0; overflow: visible; }
#margin path { fill: none; stroke: var(--line); stroke-width: 1.2; }
#margin path.lit { stroke: var(--accent); stroke-width: 1.6; }
#margin circle { fill: var(--line); }
#margin circle.lit { fill: var(--accent); }
.mnote { position: absolute; pointer-events: auto; display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 0.8em; line-height: 1.4; color: var(--ink); }
.mnote:hover, .mnote.lit { border-color: var(--accent); text-decoration: none; }
.mnote .qtitle { font-weight: 600; margin: 1px 0; }
.mnote .dim { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
/* Send note. */
#note-button { position: fixed; right: calc(16px + env(safe-area-inset-right)); bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 12; border-radius: 999px; padding: 8px 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.18); }
#note-panel { position: fixed; right: 16px; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 13; width: min(440px, calc(100vw - 32px)); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; box-shadow: 0 8px 32px rgba(0,0,0,0.22); }
#note-panel select { max-width: 100%; flex: 1; min-width: 0; }
#note-panel [data-close] { padding: 3px 9px; }
#note-panel .quote { display: flex; gap: 6px; align-items: flex-start; margin: 8px 0; font-size: 0.88em; color: var(--dim); }
#note-panel textarea { margin-top: 8px; }

@media (max-width: 600px) {
  /* The mail icon keeps the top row's right end; the tabs and search wrap below it. */
  #mail { margin-left: auto; margin-right: 6px; }
  nav { order: 1; }
  #search { margin-left: 0; width: 100%; order: 2; }
  #search input { width: 100%; }
  /* A phone's width is for the words: thin margins, and a card inside a card barely inset. */
  .bar { padding: 6px 10px; gap: 8px; }
  main { padding: 10px 8px calc(72px + env(safe-area-inset-bottom)); }
  .card { padding: 12px; margin: 10px 0; }
  article.card { padding: 12px 10px; }
  .card .card { padding: 10px; margin: 10px 0; }
  /* Send note: the pencil alone, in the corner, so it hides less of what's under it. */
  #note-button { padding: 10px 14px; right: calc(10px + env(safe-area-inset-right)); bottom: calc(12px + env(safe-area-inset-bottom)); }
  #note-button .label { display: none; }
  nav a { padding: 4px 8px; }
}
/* The read copy (T25): how fresh it is, in the header; pairing; devices. */
.copy { font-size: 0.78em; color: var(--dim); border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; white-space: nowrap; }
.copy[hidden] { display: none; }
.copy b { color: var(--warn); font-weight: 600; }
#pair input { display: block; width: 100%; font: inherit; padding: 6px 10px; margin: 4px 0; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.row-between { display: flex; gap: 12px; align-items: center; justify-content: space-between; }

/* The inbox: a batch marked read stays, quieter; snoozed and proposed fold away. */
.card.batch.read { opacity: 0.62; }
.card.batch.read:hover, .card.batch.read:focus-within { opacity: 1; }
.card.batch ul { margin: 6px 0 0; }
.marks { margin-left: auto; display: flex; gap: 6px; }
.marks button, .marks select.act { padding: 1px 10px; font-size: 0.95em; border-radius: 6px; }
details.later { margin: 10px 0; }
details.later summary { cursor: pointer; color: var(--dim); }
details.later .row { margin: 6px 0; }
/* A comment sent with Accept or Drop (N3): one line until it's used. */
textarea.comment { min-height: 0; margin-top: 8px; padding: 5px 10px; font-size: 0.95em; }
textarea.comment:focus, textarea.comment:not(:placeholder-shown) { min-height: 4.5em; }
/* A margin note folds to its id line (T40). */
.mnote .fold { float: right; margin: -2px -4px 0 6px; padding: 0 6px; border-radius: 5px; color: var(--dim); font-weight: 600; cursor: pointer; }
.mnote .fold:hover { background: var(--code); color: var(--ink); }
.mnote.folded .qtitle, .mnote.folded .dim, .mnote.folded .needs { display: none; }
/* A box with a kept draft (T37). */
textarea.draft { border-color: var(--open); }
/* Inbox projects fold (N6): the heading is the toggle. */
details.qgroup > summary { list-style: none; cursor: pointer; color: inherit; }
details.qgroup > summary::-webkit-details-marker { display: none; }
details.qgroup > summary::before { content: '▾'; display: inline-block; width: 1.1em; color: var(--dim); transition: transform 0.15s; }
details.qgroup:not([open]) > summary::before { transform: rotate(-90deg); }
details.inbox > summary { list-style: none; cursor: pointer; color: inherit; }
details.inbox > summary::-webkit-details-marker { display: none; }
details.inbox > summary h2::before { content: '▾'; display: inline-block; width: 1.1em; color: var(--dim); transition: transform 0.15s; }
details.inbox:not([open]) > summary h2::before { transform: rotate(-90deg); }
details.inbox > summary[hidden] { display: none; }
time[title] { cursor: help; border-bottom: 1px dotted transparent; }
time[title]:hover { border-bottom-color: currentColor; }
/* What mentions an item (T42): in the left margin when the window has room for it. */
.mentions { margin: 10px 0; font-size: 0.88em; }
.mentions ul.items li { padding: 2px 0; }
@media (min-width: 1500px) {
  main { position: relative; }
  .mentions { position: absolute; right: calc(100% + 12px); top: 16px; width: 250px; margin: 0; }
}
/* Signing in: the header's project, tabs, search and inbox wait until there's someone to show. */
body.signed-out .bar > :not(.brand) { display: none; }
body.signed-out #note-button { display: none; }
body.signed-out #mail { display: none; }
