/* KB. Bolt's foundation (type, shell, cards, buttons, forms), with KB's own
   accent: colors are tokens, and dark mode redefines them. Everything wraps;
   the phone rules below enlarge targets and stack the shell. No page scrolls
   sideways at 390 px. */
:root {
  --ground: #F3F3EF;
  --surface: #FFFFFF;
  --surface-2: #F6F7F4;
  --line: #DEDFDA;
  --line-soft: #ECEDE9;
  --ink: #16181B;
  --ink-2: #2E3238;
  --muted: #4F545B;
  --accent: #3A4FA0;
  --accent-ink: #2F418A;
  --accent-soft: #E7EAF6;
  --accent-line: #C3CAEB;
  --on-accent: #FFFFFF;
  --amber: #8A5300;
  --amber-soft: #FBEFD9;
  --danger: #A3261B;
  --hover: #E8E9E4;
  --shadow: 0 12px 40px rgb(22 24 27 / 0.18);
  /* Your words (annotations, your notes, your takeaways and tags): teal, set
     apart from KB's indigo; your highlights are a marker's yellow. */
  --mine: #0B5E5A;
  --mine-soft: #E3F1EE;
  --mine-line: #8CC7BC;
  --mark: #FFE987;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #111314;
    --surface: #1A1D1F;
    --surface-2: #202426;
    --line: #2E3336;
    --line-soft: #262A2D;
    --ink: #ECEDEA;
    --ink-2: #D5D7D3;
    --muted: #A3A8AD;
    --accent: #8C9CF0;
    --accent-ink: #AEB9F5;
    --accent-soft: #1F2440;
    --accent-line: #363F6E;
    --on-accent: #0E1122;
    --amber: #E3A852;
    --amber-soft: #3A2C14;
    --danger: #F08A80;
    --hover: #24292B;
    --shadow: 0 12px 40px rgb(0 0 0 / 0.5);
    --mine: #6CCBC2;
    --mine-soft: #15302D;
    --mine-line: #2F6660;
    --mark: #5E4E10;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 15px/1.45 "IBM Plex Sans", system-ui, sans-serif;
}
a { color: var(--accent-ink); }
a:hover { color: var(--ink); }
h1, h2, h3, p { margin: 0; }
code { font: 13px "IBM Plex Mono", monospace; background: var(--surface); border: 1px solid var(--line); padding: 0 4px; border-radius: 4px; overflow-wrap: anywhere; }
img { max-width: 100%; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.url { overflow-wrap: anywhere; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; min-height: 44px; text-decoration: none; color: var(--ink); font-weight: 600; font-size: 20px; letter-spacing: -0.02em; }
.brand img { display: block; border-radius: 7px; }
.topbar-links { margin-left: auto; display: flex; gap: 4px; }
.topbar-links a { padding: 10px; border-radius: 8px; text-decoration: none; color: var(--ink-2); font-size: 14px; }
.topbar-links a:hover { background: var(--hover); }
.topbar-links a.is-active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }

/* Shell: the sections down the side, the page beside them */
.shell { display: flex; gap: 24px; max-width: 1280px; margin: 0 auto; padding: 24px; align-items: flex-start; }
.nav { position: sticky; top: 86px; flex: 0 0 220px; display: flex; flex-direction: column; gap: 2px; max-height: calc(100vh - 110px); overflow-y: auto; }
.nav-link { display: flex; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: 8px; color: var(--ink-2); text-decoration: none; font-size: 14px; }
.nav-link:hover { background: var(--hover); color: var(--ink); }
.nav-link.is-active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.nav-count { color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.nav-label { font: 500 12px "IBM Plex Mono", monospace; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 14px 10px 4px; }
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 16px; }

/* Page heading */
.page-head { display: flex; flex-direction: column; gap: 4px; }
.kicker { font: 500 12px "IBM Plex Mono", monospace; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.kicker a { color: inherit; }
h1 { font-size: 28px; font-weight: 600; letter-spacing: -0.015em; line-height: 1.2; overflow-wrap: anywhere; }
.lede { color: var(--muted); max-width: 70ch; text-wrap: pretty; }

/* Layout grid: a main column and a side one, stacking when there's no room */
.grid { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.col-main { flex: 999 1 460px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.col-side { flex: 1 1 280px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; min-width: 0; }
.card.narrow { max-width: 560px; }
.card-title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.card-title span { color: var(--muted); font-weight: 400; }
.card > p + p, .card > p + form, .card > form + p { margin-top: 10px; }
/* A card you're sent to by its id (#secrets, #keys) lands below the sticky top bar, as in Bolt */
section.card[id] { scroll-margin-top: 96px; }
.card-foot { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line-soft); }
.sub-title { font-size: 14px; font-weight: 600; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.list li { padding: 8px 0; border-top: 1px solid var(--line-soft); font-size: 14px; overflow-wrap: anywhere; }
.list li:first-child { border-top: 0; padding-top: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line-soft); color: var(--ink-2); font: 12px "IBM Plex Mono", monospace; text-decoration: none; }
.actions-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; }

/* Buttons */
.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--accent-line); background: var(--surface); color: var(--accent-ink);
  font: 600 14px "IBM Plex Sans", sans-serif; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--accent-soft); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.btn-small, button.btn.btn-small { min-height: 36px; padding: 0 10px; font-size: 13px; }
/* As specific as button.btn, so a button_to's button takes them too */
.btn-quiet, button.btn-quiet { border-color: var(--line); color: var(--ink-2); font-weight: 500; }
.btn-quiet:hover { background: var(--hover); }
.btn-primary, button.btn-primary, input.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover, input.btn-primary:hover { background: var(--accent-ink); color: var(--on-accent); }
form.button_to { display: inline-flex; margin: 0; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 12px; }
.form .btn { align-self: flex-start; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 13px; font-weight: 500; color: var(--ink-2); }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], input[type=search], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink);
  font: 15px "IBM Plex Sans", sans-serif;
}
textarea { resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.field-set { border: 0; margin: 0; padding: 0; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.field-set legend { padding: 0; margin-bottom: 8px; font: 500 12px "IBM Plex Mono", monospace; text-transform: uppercase; color: var(--muted); }
.field-set + .field-set { margin-top: 6px; }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: 14px; font-weight: 400; color: var(--ink-2); min-width: 0; }
.check input, .check-inline input { flex: none; width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--accent); }
.check span { min-width: 0; overflow-wrap: anywhere; }
.check-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); }
.setting-state { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; font-size: 13px; }
.setting-summary { color: var(--accent-ink); font-weight: 500; overflow-wrap: anywhere; }
.inline-form { display: flex; gap: 8px; align-items: center; min-width: 0; }
.inline-form > :first-child { flex: 1 1 auto; min-width: 0; }
.inline-form .btn { flex: none; }

/* Flash */
.flash { padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-ink); border: 1px solid var(--accent-line); font-size: 14px; overflow-wrap: anywhere; }
.flash-alert { background: var(--amber-soft); color: var(--amber); border-color: var(--amber); }

/* Sign in, and the Allow page */
.auth-main { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px 16px; }
.auth-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 16px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.auth-brand img { border-radius: 16px; }
.connect-card { text-wrap: pretty; }
.connect-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.connect-card .connect-actions .btn { flex: 1 1 0; align-self: stretch; }
.connect-id { text-align: center; overflow-wrap: anywhere; }

/* Connected apps and keys */
.connections { list-style: none; margin: 0; padding: 0; }
.connections li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; padding: 10px 0; border-top: 1px solid var(--line-soft); }
.connections li:first-child { border-top: 0; padding-top: 0; }
.connections li > div { min-width: 0; }
.connection-name { font-weight: 500; overflow-wrap: anywhere; }
.new-key { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; padding: 12px; border: 1px solid var(--accent-line); border-radius: 10px; background: var(--accent-soft); }

/* Setup steps and commands to copy */
.setup { display: flex; flex-direction: column; gap: 10px; }
.setup .card-title { margin-bottom: 0; }
.setup > p + p { margin-top: 0; }
.setup-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; }
.setup-steps p { margin: 0 0 6px; }
.command-box { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-width: 0; }
/* Long commands scroll inside their box rather than break mid-word, so they can be read and retyped. */
.command { display: block; width: 100%; max-width: 100%; margin: 0; font: 12.5px/1.5 "IBM Plex Mono", monospace; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; white-space: pre; overflow-x: auto; }
/* A key is one long word: it wraps, so all of it shows. */
output.command { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Phone */
@media (max-width: 720px) {
  .topbar { padding: 8px 16px; gap: 10px; }
  .topbar-links a { padding: 12px 8px; }
  .shell { flex-direction: column; align-items: stretch; padding: 12px 16px 24px; gap: 12px; }
  .card.narrow { max-width: none; }
  .nav {
    position: static; flex: none; width: 100%; max-height: none;
    flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 4px;
  }
  .nav-label { display: none; }
  .nav-link { flex: none; white-space: nowrap; min-height: 44px; align-items: center; background: var(--surface); border: 1px solid var(--line); }
  h1 { font-size: 24px; }
  .btn, button.btn, .btn.btn-small, button.btn.btn-small { min-height: 44px; padding: 0 12px; }
  input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], select { min-height: 44px; }
  .check, .check-inline { min-height: 44px; align-items: center; }
  .check input { margin-top: 0; }
}

/* A touch screen at any width (an iPad) gets the phone's tap sizes, though not its layout */
@media (pointer: coarse) {
  .btn, button.btn, .btn.btn-small, button.btn.btn-small { min-height: 44px; }
  input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], input[type=search], select { min-height: 44px; }
  .check, .check-inline { min-height: 44px; align-items: center; }
  .nav-link, .topbar-links a { min-height: 44px; align-items: center; }
  .topbar-links a { display: inline-flex; }
  .kicker a, .card-link, .facts a { display: inline-block; padding: 15px 0; margin: -15px 0; position: relative; }
}

/* ── The library ─────────────────────────────────────────────────────────
   Notes, items, tags, topics, entities, collections. KB's text is plain ink;
   yours (annotations, your notes, takeaways and tags) carries the teal of
   --mine, and your highlights the marker's yellow, wherever it shows. */
.card-link { font-size: 13px; font-weight: 400; color: var(--accent-ink); }
.sub-title { margin: 14px 0 4px; font: 500 12px "IBM Plex Mono", monospace; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.sub-title:first-of-type { margin-top: 0; }
.section-title { font-size: 15px; font-weight: 600; }
.stack { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.empty-state p { max-width: 60ch; }
.narrow-form { max-width: 760px; }
.count-list li { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.count-list li > :first-child { min-width: 0; }
.count-list li .muted { flex: none; font-variant-numeric: tabular-nums; font-size: 13px; }
.collection-description { display: block; }
.facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; margin: 10px 0 0; font-size: 13px; }
.facts div { display: contents; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.item-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 6px; font-size: 13px; color: var(--muted); min-width: 0; }
.item-meta a { color: var(--muted); }
.item-meta a:hover { color: var(--ink); }
.status-tag { display: inline-block; border: 1px solid var(--line); font: 500 11px "IBM Plex Mono", monospace; text-transform: uppercase; letter-spacing: 0.03em; padding: 1px 6px; border-radius: 5px; background: var(--surface-2); color: var(--muted); }
.status-tag.status-proposed { border-style: dashed; background: transparent; }
form.inline-button { display: inline; }
.link-button { padding: 0; border: 0; background: none; color: var(--muted); font: inherit; font-size: 13px; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; cursor: pointer; }
.link-button:hover { color: var(--ink); text-decoration-color: currentColor; }
summary.link-button { list-style: none; display: inline; }
summary.link-button::-webkit-details-marker { display: none; }

/* Chips: KB's in indigo, yours in teal; KB's tags are dashed */
.chip-kb { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-ink); }
.chip-mine { background: var(--mine-soft); border-color: var(--mine-line); color: var(--mine); }
a.chip:hover { border-color: var(--accent-line); color: var(--accent-ink); }
.chip-protected { background: var(--surface); border-color: var(--line); color: var(--ink-2); }
.chip-protected::before { content: "\1F512\FE0E"; margin-right: 4px; font-size: 10px; }
.chip-tag-link { color: var(--ink-2); }
.chip-count { color: var(--muted); }
.chip-topic { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-ink); font-family: "IBM Plex Sans", sans-serif; font-size: 13px; }
.chip-topic.is-mine { background: var(--mine-soft); border-color: var(--mine-line); color: var(--mine); }
.chip-entity { font-family: "IBM Plex Sans", sans-serif; font-size: 13px; }
.entity-kind { font: 500 11px "IBM Plex Mono", monospace; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.chip-filter { display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 0 10px; border-radius: 16px; background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-ink); font: 13px "IBM Plex Sans", sans-serif; }
.memberships { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.memberships .chip { display: inline-flex; align-items: center; gap: 2px; padding: 0 0 0 10px; font-size: 13px; max-width: 100%; }
.memberships .chip a { display: flex; align-items: center; min-height: 34px; min-width: 0; padding: 0 2px 0 0; color: inherit; text-decoration: none; overflow-wrap: anywhere; }
.memberships .chip a:hover { text-decoration: underline; }
.chip-group { background: var(--surface); border-color: var(--line); color: var(--ink-2); font-family: "IBM Plex Sans", sans-serif; }
.chip-tag.is-mine { background: var(--mine-soft); border: 1px solid var(--mine-line); color: var(--mine); }
.chip-tag.is-kb { background: transparent; border: 1px dashed var(--accent-line); color: var(--accent-ink); }
.legend-mine { color: var(--mine); font-weight: 500; }
.legend-kb { color: var(--accent-ink); font-weight: 500; }
.chip-remove { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border: 0; border-radius: 50%; background: none; color: var(--muted); font: 16px/1 "IBM Plex Sans", sans-serif; cursor: pointer; }
.chip-remove:hover { color: var(--danger); background: var(--hover); }
.card-status { margin-top: 8px; }
.tag-cloud { gap: 6px; }
.tag-cloud .chip { font-size: 13px; padding: 2px 9px; }

/* Add to… (as in Bolt) */
.add-to { position: relative; display: flex; flex-direction: column; gap: 6px; }
.add-to-menu {
  position: absolute; left: 0; right: 0; top: 44px; z-index: 20; max-height: 320px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  padding: 6px; display: flex; flex-direction: column; gap: 2px;
}
.add-to [hidden] { display: none !important; }
.menu-item { width: 100%; min-height: 36px; padding: 0 8px; border: 0; border-radius: 6px; background: none; color: var(--ink); font: 14px "IBM Plex Sans", sans-serif; text-align: left; cursor: pointer; }
.menu-item:hover { background: var(--hover); }
.add-to-menu .menu-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.add-to-menu .menu-item > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.add-to-menu .menu-item.is-selected { background: var(--accent-soft); }
.add-to-menu .menu-item .muted { flex: none; font-size: 12px; }
.add-to-menu .menu-item:disabled { color: var(--muted); cursor: default; background: none; }

/* Tabs (as in Bolt) */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); text-decoration: none; font-size: 14px; }
.tab span { color: var(--muted); }
.tab.is-active { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-ink); font-weight: 600; }
.tab.is-active span { color: inherit; opacity: 0.8; font-weight: 400; }

/* Lists of notes */
.note-list.card { padding-top: 6px; padding-bottom: 6px; }
.note-list > .card-title { padding-top: 10px; }
.note-row { padding: 12px 0; border-top: 1px solid var(--line-soft); min-width: 0; }
.note-list > .note-row:first-child, .note-list > .card-title + .note-row, .note-list > .collection-entry:first-child .note-row { border-top: 0; }
.note-row-title { font-size: 15px; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
.note-row-title a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.note-row-title a:hover { color: var(--accent-ink); text-decoration-color: currentColor; }
.note-row-summary { margin-top: 3px; color: var(--ink-2); font-size: 14px; overflow-wrap: anywhere; }
.collection-entry { display: flex; align-items: flex-start; gap: 12px; border-top: 1px solid var(--line-soft); }
.collection-entry:first-child { border-top: 0; }
.collection-entry .note-row { flex: 1 1 auto; border-top: 0; }
.collection-entry form.button_to { flex: none; margin-top: 12px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px 12px; padding: 12px 14px; }
.filters .field { flex: 1 1 150px; }
.active-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; font-size: 13px; color: var(--muted); }
.pager-links { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* Rendered Markdown */
.prose { font-size: 15px; line-height: 1.6; overflow-wrap: anywhere; min-width: 0; }
.prose > * + * { margin-top: 0.75em; }
.prose h3, .prose h4, .prose h5, .prose h6 { margin-top: 1.2em; font-size: 15px; font-weight: 600; line-height: 1.35; }
.prose h3 { font-size: 16px; }
.prose ul, .prose ol { margin-bottom: 0; padding-left: 1.4em; }
.prose li + li { margin-top: 0.35em; }
.prose blockquote { margin-left: 0; margin-right: 0; padding-left: 12px; border-left: 3px solid var(--line); color: var(--ink-2); }
.prose img { display: block; max-width: 100%; height: auto; border-radius: 8px; }
.prose pre { max-width: 100%; overflow-x: auto; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); }
.prose pre code { border: 0; padding: 0; background: none; overflow-wrap: normal; }
.prose table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 14px; }
.prose th, .prose td { padding: 4px 10px; border: 1px solid var(--line); text-align: left; }
.prose hr { border: 0; border-top: 1px solid var(--line); }
.note-link { color: var(--accent-ink); text-decoration-style: dotted; text-underline-offset: 3px; }
.note-link-missing { color: var(--ink-2); }
.image-link::before { content: "\2197\FE0E "; }

/* A note's page */
.note-page { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.note-meta { margin-top: 8px; }
.note-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.takeaways { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.takeaway { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line-soft); scroll-margin-top: 96px; }
.takeaway:first-child { border-top: 0; padding-top: 2px; }
.takeaway:target { background: var(--accent-soft); box-shadow: -18px 0 var(--accent-soft), 18px 0 var(--accent-soft); }
.takeaway-number { flex: none; width: 22px; padding-top: 2px; font: 500 12px/1.6 "IBM Plex Mono", monospace; color: var(--muted); text-align: right; }
.takeaway-body { flex: 1 1 auto; min-width: 0; }
.takeaway .prose { font-size: 15px; line-height: 1.55; }
.takeaway-meta { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.takeaway.is-mine .takeaway-body { padding-left: 10px; border-left: 3px solid var(--mine-line); }
.takeaway.is-mine .takeaway-number { color: var(--mine); }

/* Your words: their own card, their own voice */
.words { border-color: var(--mine-line); }
.words > .card-title { color: var(--mine); }
.words-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.word { padding: 10px 0; border-top: 1px solid var(--line-soft); scroll-margin-top: 96px; min-width: 0; }
.word:first-child { border-top: 0; padding-top: 0; }
.word-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; font-size: 13px; color: var(--muted); }
.word-head a { color: var(--muted); }
.word-kind { font: 500 11px "IBM Plex Mono", monospace; text-transform: uppercase; letter-spacing: 0.04em; color: var(--mine); }
.word-date { margin-left: auto; }
.word-quote { margin: 6px 0 0; padding: 2px 0 2px 10px; border-left: 3px solid var(--mark); color: var(--ink-2); font-size: 14px; overflow-wrap: anywhere; }
.word-body { margin-top: 6px; padding: 8px 12px; border-left: 3px solid var(--mine); border-radius: 0 8px 8px 0; background: var(--mine-soft); color: var(--ink); font-size: 15px; overflow-wrap: anywhere; }
.word-body > * + * { margin-top: 0.6em; }
.word-body ul, .word-body ol { margin-bottom: 0; padding-left: 1.3em; }
.word-missing { margin-top: 6px; color: var(--amber); }
.word-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 6px; }
.word-actions:empty { display: none; }
.word-edit[open] { flex-basis: 100%; }
.word-edit-form { margin-top: 8px; }
.word.is-lit { animation: lit 2s ease-out; }
.words-feed li { display: flex; flex-direction: column; }
@keyframes lit { from { background: var(--mine-soft); box-shadow: -10px 0 var(--mine-soft), 10px 0 var(--mine-soft); } }

/* Your highlights in KB's text: the marker's yellow; one with words beside it is underlined in your teal */
mark.mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0; cursor: pointer; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
mark.mark-marginalia, mark.mark-snippet { box-shadow: inset 0 -2px var(--mine); }
mark.mark.is-lit { animation: lit-mark 2s ease-out; }
@keyframes lit-mark { 0%, 30% { outline: 2px solid var(--mine); outline-offset: 1px; } }

/* The bar a selection opens */
.annotate-bar {
  position: absolute; z-index: 30; width: min(420px, calc(100vw - 16px));
  padding: 10px 12px; border: 1px solid var(--mine-line); border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow);
}
.annotate-bar[hidden], .annotate-bar [hidden] { display: none !important; }
.annotate-form { display: flex; flex-direction: column; gap: 8px; }
.annotate-quote { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.annotate-write { display: flex; flex-direction: column; gap: 6px; }
.annotate-write[hidden] { display: none; }
.annotate-write textarea { border-color: var(--mine-line); }
.annotate-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.annotate-status { position: fixed; left: 50%; bottom: 20px; z-index: 40; transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 8px 14px; border-radius: 10px; background: var(--ink); color: var(--ground); font-size: 14px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.annotate-status.is-shown { opacity: 1; }

/* Links between notes */
.links-group { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; margin: 14px 0 4px; font: 500 12px "IBM Plex Mono", monospace; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.links-group span { text-transform: none; letter-spacing: 0; font-family: "IBM Plex Sans", sans-serif; }
.card-title + .links-group { margin-top: 0; }
.links-list { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; }
.link-row { padding: 10px 0 10px 12px; border-top: 1px solid var(--line-soft); border-left: 3px solid var(--accent); min-width: 0; }
.link-row.is-candidate { border-left: 3px dashed var(--accent-line); }
.link-row:first-child { border-top: 0; }
.link-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
.link-kind { flex: none; font: 500 12px "IBM Plex Mono", monospace; color: var(--accent-ink); }
.link-kind-contradicts { color: var(--amber); }
.link-title { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.link-ends { margin-top: 3px; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.link-ends a { color: var(--muted); }
.link-claim { color: var(--ink-2); }
.link-why { margin-top: 4px; font-size: 14px; color: var(--ink-2); overflow-wrap: anywhere; }
.link-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.links-more { margin-top: 8px; }
.links-more > summary { list-style: none; }
.links-more > summary::-webkit-details-marker { display: none; }
.links-more[open] > summary { display: none; }

/* Where it came from; whether it's protected */
.sources-list li { display: flex; flex-direction: column; }
.source-title { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.protection { padding: 8px 12px; border-left: 3px solid var(--line); border-radius: 0 8px 8px 0; background: var(--surface-2); font-size: 14px; color: var(--ink-2); }
/* KB's words about whether a note is yours: KB's indigo, never your teal */
.protection.is-protected { border-left-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.source-note { margin-bottom: 10px; }
.source-text { font-size: 14px; color: var(--ink-2); content-visibility: auto; contain-intrinsic-size: auto 2000px; }

/* Topics */
.topic-tree, .topic-tree ul { list-style: none; margin: 0; padding: 0; }
.topic-tree ul { margin: 4px 0 4px 14px; padding-left: 12px; border-left: 1px solid var(--line-soft); }
.topic-tree li { padding: 4px 0; }
.topic-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.topic-line a { font-weight: 500; }
.is-mine-card { border-color: var(--mine-line); }
.mine-prose { padding-left: 12px; border-left: 3px solid var(--mine); }
.addendum { border-style: dashed; border-color: var(--accent-line); }
.versions { margin-top: 12px; font-size: 13px; }
.versions-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.version-body { margin-top: 6px; font-size: 13px; }
.mine-count { color: var(--mine); }
.entity-line { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }

/* The note form */
.note-form textarea { line-height: 1.5; }
.takeaways-list { display: flex; flex-direction: column; gap: 10px; }
.takeaway-field[hidden] { display: none; }
.takeaway-field-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.takeaways-fields > .btn { align-self: flex-start; }

@media (max-width: 720px) {
  .annotate-bar { position: fixed; left: 8px; right: 8px; bottom: 8px; top: auto !important; width: auto; }
  .annotate-status { top: 70px; bottom: auto; }
  .chip-remove { width: 40px; height: 40px; }
  .memberships .chip a { min-height: 40px; }
  .add-to-menu { top: 48px; }
  .add-to-menu .menu-item, .menu-item { min-height: 44px; }
  .tab { min-height: 44px; }
  .link-button { padding: 10px 0; }
  .filters .field { flex-basis: 140px; }
  .filters select { min-height: 44px; }
  .collection-entry { flex-direction: column; gap: 0; }
  .collection-entry form.button_to { margin: 0 0 12px; }
  .takeaway:target { box-shadow: none; }
  .word-date { margin-left: 0; }
  .chip-filter { min-height: 40px; }
}

/* Search: its box, and the passages that matched (KB's indigo, never your highlights' yellow) */
.search-box { margin-top: 10px; max-width: 640px; }
.search-box input[type=search] { min-height: 44px; font-size: 16px; }
.search-form { display: flex; flex-direction: column; gap: 10px; }
.search-form .search-box { margin-top: 0; max-width: none; }
.search-filters > summary { font-size: 13px; }
.search-filters .filters { padding: 10px 0 0; }
.search-snippet { margin-top: 3px; color: var(--ink-2); font-size: 14px; overflow-wrap: anywhere; }
.search-snippet mark { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; border-radius: 2px; padding: 0 1px; }
/* A one-field form whose label is hidden: the field takes the row */
.inline-form input[type=text], .inline-form input[type=search] { flex: 1 1 auto; min-width: 0; }
/* Your words among a note's facts (what you asked a research task) */
.facts dd.mine-fact { color: var(--mine); font-weight: 500; }
.facts-list { margin: 0; padding-left: 1.1em; display: flex; flex-direction: column; gap: 2px; }

/* Your tags in list rows are as much yours as on the note */
.chip-tag-link.is-mine { background: var(--mine-soft); border-color: var(--mine-line); color: var(--mine); }
/* Every field looks the same, dates included; placeholders readable in both modes */
input[type=date] { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: 15px "IBM Plex Sans", sans-serif; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
/* A takeaway's field grows with its text */
.takeaway-field textarea { field-sizing: content; min-height: 4.5em; }

@media (max-width: 720px) {
  /* Chips and small links are comfortable to tap on a phone */
  a.chip, .chip-protected { display: inline-flex; align-items: center; gap: 0.4em; min-height: 36px; padding: 0 11px; font-size: 13px; }
  .item-meta, .chips, .tag-cloud { gap: 8px 10px; }
  .kicker a, .card-link, .active-filters > a:not(.chip), .word-head a, .word-actions a, .item-meta a:not(.chip), .link-ends a, .facts a {
    /* Positioned, so the heading below doesn't cover the bottom of its tap area */
    display: inline-block; padding: 12px 0; margin: -12px 0; position: relative;
  }
  .kicker { padding: 4px 0; }
  /* A breadcrumb's 12 px line needs more around it to make 44 px */
  .kicker a { padding: 15px 0; margin: -15px 0; }
  input[type=date] { min-height: 44px; }
  /* The sections strip fades at the edge with more beyond it (nav controller) */
  .nav { -webkit-mask-image: linear-gradient(to right, #000 85%, transparent); mask-image: linear-gradient(to right, #000 85%, transparent); }
  .nav.is-scrolled { -webkit-mask-image: linear-gradient(to right, transparent, #000 12%, #000 85%, transparent); mask-image: linear-gradient(to right, transparent, #000 12%, #000 85%, transparent); }
  .nav.is-scrolled.at-end { -webkit-mask-image: linear-gradient(to right, transparent, #000 12%); mask-image: linear-gradient(to right, transparent, #000 12%); }
  .nav.at-end:not(.is-scrolled) { -webkit-mask-image: none; mask-image: none; }
}

/* An item's page: on one column, what's written from it comes before its long source text */
.item-grid { container-type: inline-size; }
@container (max-width: 755px) {
  .item-grid > .col-side { order: -1; }
}

/* A list row's tags, on their own line under its facts */
.row-tags { margin: 6px 0 0; }

@media (max-width: 720px) {
  /* Lists are tapped by the row: the link takes the row's height */
  .count-list li { padding: 0; }
  .count-list li > a:first-child, .count-list .entity-line > a, .topic-line > a { display: inline-block; padding: 11px 0; }
  .count-list li > a:first-child, .count-list li > .entity-line { flex: 1 1 auto; }
  .topic-tree li { padding: 0; }
  .note-row-title a { padding: 9px 0; }
  .versions-list summary { padding: 10px 0; }
  .word-actions { column-gap: 22px; }
}

/* On one column the cards go in the order a reader on a phone wants them,
   not column by column: a note's text and your words, then your tags and
   collections, the body, links, sources, its place and its protection; a
   topic's page, what's inside it and whose it is, then its notes. */
.note-columns, .topic-columns { container-type: inline-size; }
@container (max-width: 755px) {
  .note-grid, .topic-grid { flex-direction: column; flex-wrap: nowrap; align-items: stretch; }
  .note-grid > .col-main, .note-grid > .col-side, .topic-grid > .col-main, .topic-grid > .col-side { display: contents; }
  .note-grid .note-summary { order: 1; }
  .note-grid #takeaways { order: 2; }
  .note-grid #your_words { order: 3; }
  .note-grid #note_tags { order: 4; }
  .note-grid #note_collections { order: 5; }
  .note-grid .note-body { order: 6; }
  .note-grid #links { order: 7; }
  .note-grid #note_sources { order: 8; }
  .note-grid #note_places { order: 9; }
  .note-grid #note_about { order: 10; }
  .topic-grid .topic-page { order: 1; }
  .topic-grid .addendum { order: 2; }
  .topic-grid .topic-inside { order: 3; }
  .topic-grid .topic-about { order: 4; }
  .topic-grid .topic-notes { order: 5; }
}
/* Change, Show in the text and Remove sit on one line, the same height */
.word-actions > .link-button, .word-actions > form.inline-button, .word-edit:not([open]) { display: inline-flex; align-items: center; }
.word-edit:not([open]) > summary.link-button { display: inline-block; }
/* What a piece of your writing is on, under its kind and date */
.word-on { margin-top: 2px; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.word-on a { color: var(--ink-2); }
@media (max-width: 720px) {
  .count-list li a { display: inline-block; padding: 11px 0; }
  .card-link { padding: 12px 8px; margin: -12px -8px; }
  .word-on a { padding: 10px 0; }
}
/* Your own note's cards say so */
.card-title .mine-label { font: 500 11px "IBM Plex Mono", monospace; text-transform: uppercase; letter-spacing: 0.04em; color: var(--mine); }
@media (max-width: 720px) {
  /* The home's Recent shows its first five; the ways in follow, and All → has the rest */
  .recent-list > .note-row:nth-of-type(n+6) { display: none; }
}
