/* Marginalia — tokens from "UI Design Reference — iOS Markdown Reader".
   D15 resolved: Newsreader (content) + Manrope (chrome) in both themes.
   D13 resolved: 3 shared semantic highlight colours + optional 4th (plum). */

:root {
  --bg: #FAF9F6;
  --surface: #FFFFFF;
  --surface-2: #F1EFEB;
  --surface-3: #E9E6E1;
  --hair: #E5E5EA;
  --text: #1C1C1E;
  --text-2: #636366;
  --text-3: #8E8E93;
  --accent: #C2593F;
  --accent-ink: #9D3D26;
  --accent-soft: rgba(194, 89, 63, .12);
  --ink: #1E293B;
  --blue: #007AFF;
  --ok: #34A853;
  --code-bg: #F3F2EF;
  --code-text: #1C1C1E;
  --frost: rgba(250, 249, 246, .82);
  --scrim: rgba(0, 0, 0, .3);
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .06);
  --shadow-hud: 0 8px 30px rgba(0, 0, 0, .14);

  --hl-yellow: #FEF08A; --hl-yellow-ink: #854D0E; --spine-yellow: #EAB308;
  --hl-green: #BBF7D0;  --hl-green-ink: #166534;  --spine-green: #22C55E;
  --hl-blue: #BAE6FD;   --hl-blue-ink: #075985;   --spine-blue: #3B82F6;
  --hl-purple: #E9D5FF; --hl-purple-ink: #6B21A8; --spine-purple: #A855F7;

  --serif: 'Newsreader', 'Iowan Old Style', 'Charter', Georgia, serif;
  --sans: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --read-size: 19px;
  --read-lh: 1.65;
  --measure: 680px;
  --gutter: 20px;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="sepia"]) {
    --bg: #0d1117; --surface: #161b22; --surface-2: #21262d; --surface-3: #2a313a; --hair: #30363d;
    --text: #e6edf3; --text-2: #c9d1d9; --text-3: #8b949e;
    --accent: #e06c4b; --accent-ink: #f08a6c; --accent-soft: rgba(224, 108, 75, .16);
    --ink: #e6edf3; --blue: #58a6ff; --ok: #3fb950;
    --code-bg: #090d13; --code-text: #e6edf3;
    --frost: rgba(13, 17, 23, .82); --scrim: rgba(0, 0, 0, .55);
    --shadow: none; --shadow-hud: 0 8px 30px rgba(0, 0, 0, .5);
    --hl-yellow: #d9770633; --hl-yellow-ink: #fbbf24; --spine-yellow: #d97706;
    --hl-green: #2ea04333;  --hl-green-ink: #56d364;  --spine-green: #2ea043;
    --hl-blue: #388bfd33;   --hl-blue-ink: #79c0ff;   --spine-blue: #388bfd;
    --hl-purple: #8957e533; --hl-purple-ink: #d2a8ff; --spine-purple: #8957e5;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --surface: #161b22; --surface-2: #21262d; --surface-3: #2a313a; --hair: #30363d;
  --text: #e6edf3; --text-2: #c9d1d9; --text-3: #8b949e;
  --accent: #e06c4b; --accent-ink: #f08a6c; --accent-soft: rgba(224, 108, 75, .16);
  --ink: #e6edf3; --blue: #58a6ff; --ok: #3fb950;
  --code-bg: #090d13; --code-text: #e6edf3;
  --frost: rgba(13, 17, 23, .82); --scrim: rgba(0, 0, 0, .55);
  --shadow: none; --shadow-hud: 0 8px 30px rgba(0, 0, 0, .5);
  --hl-yellow: #d9770633; --hl-yellow-ink: #fbbf24; --spine-yellow: #d97706;
  --hl-green: #2ea04333;  --hl-green-ink: #56d364;  --spine-green: #2ea043;
  --hl-blue: #388bfd33;   --hl-blue-ink: #79c0ff;   --spine-blue: #388bfd;
  --hl-purple: #8957e533; --hl-purple-ink: #d2a8ff; --spine-purple: #8957e5;
  color-scheme: dark;
}
:root[data-theme="sepia"] {
  --bg: #F4ECD8; --surface: #FBF5E6; --surface-2: #EDE3CB; --surface-3: #E4D8BC; --hair: #E0D3B6;
  --text: #3B2F20; --text-2: #6B5A44; --text-3: #94826A;
  --accent: #B5523A; --accent-ink: #8E3A25; --accent-soft: rgba(181, 82, 58, .12);
  --code-bg: #EDE3CB; --code-text: #3B2F20; --frost: rgba(244, 236, 216, .85);
}

/* ---- base --------------------------------------------------------------- */

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 var(--sans); -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; -webkit-tap-highlight-color: transparent; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

#app { min-height: 100vh; min-height: 100dvh; }
.view { max-width: var(--measure); margin: 0 auto; padding: 4px var(--gutter) calc(var(--tabs-h) + var(--safe-b) + 32px); outline: none; }
body.reading .view { padding-bottom: calc(var(--safe-b) + 96px); }

/* ---- nav (frosted) -------------------------------------------------------- */

.nav {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-t) + 10px) var(--gutter) 10px;
  background: var(--frost); -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  border-bottom: .5px solid transparent; transition: border-color .2s;
}
.nav.scrolled { border-bottom-color: var(--hair); }
.nav-inner { max-width: var(--measure); margin: 0 auto; display: flex; align-items: center; gap: 10px; min-height: 44px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.glyph {
  width: 36px; height: 36px; border-radius: 9px; background: var(--ink); color: var(--bg);
  display: grid; place-items: center; flex: none;
}
:root[data-theme="dark"] .glyph { background: var(--surface-2); color: var(--accent); }
@media (prefers-color-scheme: dark) { :root:not([data-theme]) .glyph { background: var(--surface-2); color: var(--accent); } }
.glyph svg { width: 20px; height: 20px; }
.brand-text { min-width: 0; line-height: 1.1; }
.brand-text small { display: block; font-size: 13px; color: var(--text-2); }
.brand-text b { display: block; font: 600 19px/1.15 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 40px; height: 40px; border-radius: 20px; display: grid; place-items: center; color: var(--text); flex: none; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn.on { color: var(--accent); }
.icon-btn.on svg { fill: currentColor; }
.status-dot { width: 32px; height: 32px; border-radius: 16px; background: var(--accent); color: #fff; display: grid; place-items: center; font: 700 13px var(--sans); flex: none; }
.status-dot.off { background: var(--text-3); }

/* ---- tab bar ------------------------------------------------------------- */

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(var(--safe-b) + 6px);
  background: var(--frost); -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  border-top: .5px solid var(--hair);
}
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; font-size: 12px; color: var(--text-2); }
.tabs a.active { color: var(--accent); }
body.reading .tabs { display: none; }

/* ---- headings & common blocks ------------------------------------------- */

.eyebrow { font: 600 12px/1 var(--sans); letter-spacing: .09em; text-transform: uppercase; color: var(--accent); margin: 14px 0 6px; }
.page-title { font: 600 34px/1.1 var(--serif); margin: 0 0 18px; letter-spacing: -.01em; }
.section-label { display: flex; align-items: center; gap: 8px; margin: 26px 2px 10px; font: 600 13px var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); }
.section-label .pill { text-transform: none; letter-spacing: 0; font-weight: 500; }
.section-label .grow { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); font-size: 12px; font-weight: 500; white-space: nowrap; }
.pill.accent { background: var(--accent-soft); color: var(--accent-ink); }
.pill.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.pill svg { width: 14px; height: 14px; }
.card { background: var(--surface); border-radius: 12px; border: .5px solid var(--hair); box-shadow: var(--shadow); }
.muted { color: var(--text-3); }
.mono { font-family: var(--mono); }
.empty { text-align: center; color: var(--text-3); padding: 40px 12px; }
.empty b { display: block; font: 500 20px var(--serif); color: var(--text-2); margin-bottom: 6px; }

.search {
  display: flex; align-items: center; gap: 10px; height: 46px; padding: 0 14px;
  background: var(--surface-2); border-radius: 12px; color: var(--text-3);
}
.search input { flex: 1; border: 0; background: none; outline: none; font-size: 16px; color: var(--text); min-width: 0; }
.search input::placeholder { color: var(--text-3); }

.segmented { display: flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: 11px; margin: 14px 0; }
.segmented button { flex: 1; min-height: 36px; border-radius: 8px; font-size: 14px; font-weight: 500; color: var(--text-2); display: flex; align-items: center; justify-content: center; gap: 6px; }
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); font-weight: 600; }
.segmented .live { width: 8px; height: 8px; border-radius: 4px; background: var(--ok); }
.segmented .live.off { background: var(--text-3); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 99px; font-weight: 600; }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active { filter: brightness(.92); }
.btn.ghost { color: var(--text-2); }
.btn.outline { border: 1px solid var(--hair); background: var(--surface); }
.btn.block { display: flex; width: 100%; border-radius: 14px; min-height: 52px; font-size: 16px; }
.btn.danger { color: #D93025; }

/* ---- library -------------------------------------------------------------- */

.resume { position: relative; padding: 18px; margin: 4px 0 6px; border-radius: 16px; background: linear-gradient(160deg, var(--accent-soft), var(--surface-2) 55%); border: .5px solid var(--hair); }
.resume-top { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-2); }
.resume-top .grow { flex: 1; }
.resume-pct { font: 600 14px var(--sans); color: var(--accent); display: flex; align-items: center; gap: 8px; }
.bar { width: 60px; height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.resume-path { margin: 14px 0 2px; font-size: 14px; color: var(--text-2); }
.resume-title { font: 600 24px/1.2 var(--serif); margin: 0 0 14px; overflow-wrap: anywhere; }
.preview { background: var(--surface); border-radius: 12px; padding: 12px 14px 12px 16px; border-left: 3px solid var(--accent); }
.preview-head { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--accent-ink); margin-bottom: 6px; }
.preview-head svg { width: 15px; height: 15px; }
.preview-head .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview p { margin: 0; font: italic 18px/1.5 var(--serif); color: var(--text); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.resume-foot { display: flex; align-items: center; gap: 10px; margin-top: 16px; font-size: 14px; color: var(--text-2); }
.resume-foot svg { width: 18px; height: 18px; color: var(--blue); }
.resume-foot .grow { flex: 1; }

.tree { display: flex; flex-direction: column; gap: 10px; }
.folder { overflow: hidden; }
.row { display: flex; align-items: center; gap: 14px; padding: 14px 16px; width: 100%; text-align: left; min-height: 64px; }
.row:active { background: var(--surface-2); }
.row .ico { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); flex: none; }
.row .ico.c1 { background: color-mix(in srgb, var(--blue) 14%, transparent); color: var(--blue); }
.row .ico.c2 { background: var(--accent-soft); color: var(--accent); }
.row .ico.c3 { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.row .ico svg { width: 20px; height: 20px; }
.row .txt { flex: 1; min-width: 0; }
.row .name { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 8px; }
.row .name span:first-child { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
/* The title flexes and the badge never shrinks it: on a phone the badge used to win
   the line and truncate titles to ~5 characters (Arbit…, Burd…, Char…). */
.row .name .pill { flex: 0 0 auto; }
.row .meta { font-size: 13px; color: var(--text-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; display: flex; align-items: center; gap: 6px; }
.row .meta .meta-txt { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta .pill { flex: 0 0 auto; font-size: 11px; padding: 2px 8px; gap: 4px; }
.row .meta .pill svg { width: 12px; height: 12px; }
.row .size { font: 13px var(--mono); color: var(--text-3); white-space: nowrap; }
.row .chev { color: var(--text-3); width: 18px; height: 18px; transition: transform .2s; }
.folder.open > .row .chev { transform: rotate(90deg); }
.folder-body { padding: 0 10px 10px; display: flex; flex-direction: column; gap: 8px; }
.folder-body .row { background: var(--surface); border: .5px solid var(--hair); border-radius: 10px; min-height: 58px; padding: 10px 12px; }
.folder-body .folder { border: .5px solid var(--hair); border-radius: 10px; background: var(--surface); }
.folder-body .folder > .row { border: 0; }
.row .dot-active { width: 8px; height: 8px; border-radius: 4px; background: var(--accent); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); margin: 26px 0 0; padding: 16px 6px; border-radius: 14px; background: var(--surface-2); text-align: center; }
.stats div + div { border-left: 1px solid var(--hair); }
.stats b { display: block; font: 600 24px/1.2 var(--serif); }
.stats div:nth-child(2) b { color: var(--accent); }
.stats div:nth-child(3) b { color: var(--blue); }
.stats span { font-size: 13px; color: var(--text-2); }
.foot { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 18px 0 4px; font-size: 13px; color: var(--text-3); }
.foot svg { width: 14px; height: 14px; }
.drop { border: 1.5px dashed var(--hair); border-radius: 14px; padding: 22px; text-align: center; color: var(--text-2); }
.drop p { margin: 6px 0 14px; font-size: 14px; }
.search-hit .meta { white-space: normal; }
.search-hit .meta .meta-txt { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; white-space: normal; }

/* ---- reader --------------------------------------------------------------- */

.frontmatter { margin: 6px 0 22px; padding: 14px 16px; border-radius: 8px; background: var(--surface-2); font: 14px/1.5 var(--mono); }
.fm-head { display: flex; align-items: center; gap: 8px; width: 100%; color: var(--text-2); letter-spacing: .04em; }
.fm-head svg { width: 16px; height: 16px; }
.fm-head .grow { flex: 1; text-align: left; }
.fm-head .sync { font: 12px var(--sans); letter-spacing: 0; display: flex; align-items: center; gap: 6px; }
.fm-head .sync::before { content: ''; width: 6px; height: 6px; border-radius: 3px; background: var(--accent); }
.fm-body { margin-top: 10px; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; }
.fm-body dt { color: var(--text-2); }
.fm-body dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }
.fm-body .tag { color: var(--accent-ink); margin-right: 8px; }
.fm-body .chip { background: color-mix(in srgb, var(--blue) 14%, transparent); color: var(--blue); padding: 1px 8px; border-radius: 4px; font-size: 13px; }
.frontmatter.closed .fm-body { display: none; }

.md { font: var(--read-size)/var(--read-lh) var(--serif); color: var(--text); overflow-wrap: break-word; hanging-punctuation: first; }
.md > :first-child { margin-top: 0; }
.md p { margin: 0 0 1em; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 1.6em 0 .55em; letter-spacing: -.005em; scroll-margin-top: 90px; }
.md h1 { font-size: 1.85em; line-height: 1.15; }
.md h2 { font-size: 1.32em; }
.md h3 { font-size: 1.12em; }
.md h4, .md h5, .md h6 { font-size: 1em; }
.md h1 + p > em:only-child { color: var(--text-2); }
.md a { color: var(--accent-ink); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); text-underline-offset: 3px; }
.md a.wikilink { text-decoration-style: dotted; }
.md a.wikilink.missing { color: var(--text-3); }
.md ul, .md ol { padding-left: 1.35em; margin: 0 0 1em; }
.md li { margin: .25em 0; }
.md li > p { margin: 0 0 .4em; }
.md li.task { list-style: none; margin-left: -1.35em; display: flex; gap: .55em; align-items: baseline; }
.md li.task > .tick { flex: none; width: 1.05em; height: 1.05em; border-radius: 4px; border: 1.5px solid var(--text-3); display: inline-grid; place-items: center; transform: translateY(.15em); }
.md li.task.done > .tick { background: var(--accent); border-color: var(--accent); }
.md li.task.done > .tick::after { content: ''; width: .3em; height: .55em; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }
.md li.task.done { color: var(--text-2); }
.md blockquote { margin: 1.4em 0; padding: 16px 18px; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 8px 8px 0; font-style: italic; color: var(--text); }
.md blockquote p:last-child { margin-bottom: 0; }
.md blockquote.callout { font-style: normal; }
.md blockquote .callout-title { font: 600 13px var(--sans); text-transform: uppercase; letter-spacing: .06em; color: var(--accent-ink); margin-bottom: 6px; font-style: normal; }
.md code { font: .82em var(--mono); background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
.md .code { margin: 1.4em 0; border-radius: 8px; background: var(--code-bg); overflow: hidden; border: .5px solid var(--hair); }
.md .code-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; font: 13px var(--mono); color: var(--text-3); border-bottom: .5px solid var(--hair); }
.md .code-head .dots { display: flex; gap: 6px; }
.md .code-head .dots i { width: 10px; height: 10px; border-radius: 5px; background: var(--surface-3); }
.md .code-head .lang { flex: 1; }
.md .code-head button { display: flex; align-items: center; gap: 4px; font: 12px var(--sans); color: var(--text-3); }
.md .code-head button svg { width: 14px; height: 14px; }
.md pre { margin: 0; padding: 14px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.md pre code { background: none; padding: 0; font-size: 13.5px; line-height: 1.6; color: var(--code-text); white-space: pre; }
.md table { border-collapse: collapse; margin: 1.2em 0; font: 15px/1.45 var(--sans); display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border-bottom: .5px solid var(--hair); padding: 8px 12px; text-align: left; vertical-align: top; }
.md th { font-weight: 600; color: var(--text-2); border-bottom-width: 1px; white-space: nowrap; }
.md hr { border: 0; height: 1px; background: var(--hair); margin: 2em 0; }
.md img { max-width: 100%; border-radius: 8px; display: block; margin: 1em auto; }
.md del { color: var(--text-3); }

mark.hl { color: inherit; padding: .08em 0; border-radius: 3px; -webkit-box-decoration-break: clone; box-decoration-break: clone; cursor: pointer; }
mark.hl.yellow { background: var(--hl-yellow); }
mark.hl.green { background: var(--hl-green); }
mark.hl.blue { background: var(--hl-blue); }
mark.hl.purple { background: var(--hl-purple); }
mark.hl.block { background: none; border-bottom: 2px dashed var(--spine-yellow); border-radius: 0; }
mark.hl.flash { animation: flash 1.2s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 35%, transparent); } 100% { box-shadow: 0 0 0 0 transparent; } }
mark.hl.has-note.end::after {
  content: attr(data-n); display: inline-grid; place-items: center; width: 1.25em; height: 1.25em; margin-left: .25em;
  border-radius: 50%; background: var(--hl-yellow); color: var(--hl-yellow-ink); font: 600 .55em/1 var(--sans); vertical-align: super;
}
.bm-flag { position: absolute; left: calc(var(--gutter) * -0.5 - 6px); width: 3px; height: 1.4em; border-radius: 2px; background: var(--accent); }
.reader-wrap { position: relative; }

.banner { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; background: var(--surface); border: .5px solid var(--hair); margin: 12px 0; font-size: 14px; }
.banner .txt { flex: 1; min-width: 0; }
.banner b { font-weight: 600; }
.banner small { display: block; color: var(--text-3); font: 12px var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.banner .ok-ico { width: 30px; height: 30px; border-radius: 15px; display: grid; place-items: center; background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); flex: none; }
.banner .ok-ico.warn { background: var(--accent-soft); color: var(--accent); }
.banner .ok-ico svg { width: 16px; height: 16px; }
.banner.warn { border-color: color-mix(in srgb, var(--accent) 40%, var(--hair)); }

.progress-pill {
  position: fixed; z-index: 25; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 14px); width: min(calc(100% - 2 * var(--gutter)), 460px);
  padding: 10px 16px 9px; border-radius: 99px; text-align: left;
  background: var(--frost); -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  box-shadow: var(--shadow-hud); border: .5px solid var(--hair);
}
.progress-pill .row1 { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.progress-pill .row1 svg { width: 16px; height: 16px; color: var(--accent); }
.progress-pill .row1 .grow { flex: 1; }
.progress-pill .row1 .mono { font-size: 12px; color: var(--text-2); }
.progress-pill .track { height: 4px; margin-top: 7px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.progress-pill .track i { display: block; height: 100%; background: var(--accent); border-radius: 2px; transition: width .15s; }

/* ---- HUD ------------------------------------------------------------------ */

.hud {
  position: absolute; z-index: 40; display: flex; align-items: center; gap: 6px; padding: 6px;
  border-radius: 99px; background: var(--frost); -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  box-shadow: var(--shadow-hud); border: .5px solid var(--hair);
  -webkit-user-select: none; user-select: none; animation: pop .14s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.97); } }
.hud .sw { width: 32px; height: 32px; border-radius: 16px; display: grid; place-items: center; }
.hud .sw i { width: 22px; height: 22px; border-radius: 11px; border: 2px solid rgba(0, 0, 0, .08); }
.hud .sw.on i { outline: 2px solid var(--text); outline-offset: 2px; }
.hud .sep { width: 1px; height: 22px; background: var(--hair); margin: 0 2px; }
.hud .act { height: 34px; padding: 0 12px; border-radius: 17px; display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; color: var(--text); }
.hud .act svg { width: 17px; height: 17px; }
.hud .act.primary { background: var(--accent); color: #fff; }
.sw-yellow { background: #FACC15; } .sw-green { background: #6EE7B7; } .sw-blue { background: #7DD3FC; } .sw-purple { background: #C4B5FD; }

/* ---- sheets --------------------------------------------------------------- */

.scrim { position: fixed; inset: 0; z-index: 50; background: var(--scrim); animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; z-index: 51; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 560px;
  max-height: 88vh; max-height: 88dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--surface); border-radius: 16px 16px 0 0; padding: 8px 20px calc(var(--safe-b) + 20px);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .15); animation: up .24s cubic-bezier(.2, .9, .3, 1);
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet .grab { width: 38px; height: 5px; border-radius: 3px; background: var(--surface-3); margin: 0 auto 12px; }
.sheet h3 { font: 600 20px var(--serif); margin: 4px 0 14px; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.sheet-head .dot { width: 12px; height: 12px; border-radius: 6px; }
.sheet-head .t { font-weight: 600; font-size: 16px; white-space: nowrap; }
.sheet-head .count { white-space: nowrap; }
.sheet-head .grow { flex: 1; }
.sheet-head .count { font-size: 13px; color: var(--text-2); }
.quote-card { padding: 12px 14px; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 10px 10px 0; font: italic 16px/1.5 var(--serif); max-height: 140px; overflow: auto; }
.field-label { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-2); margin: 16px 0 8px; }
.editor { background: var(--surface-2); border-radius: 12px; padding: 12px 14px 8px; }
.editor textarea { width: 100%; min-height: 84px; border: 0; background: none; resize: vertical; outline: none; font-size: 16px; line-height: 1.5; }
.editor .tools { display: flex; align-items: center; gap: 4px; }
.editor .tools button { min-width: 34px; height: 30px; border-radius: 6px; font: 600 14px var(--mono); color: var(--accent-ink); }
.editor .tools button:active { background: var(--surface-3); }
.editor .tools .grow { flex: 1; }
.editor .tools .count { font-size: 12px; color: var(--text-3); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-btn { height: 32px; padding: 0 12px; border-radius: 16px; border: 1px solid var(--hair); font-size: 13px; font-weight: 600; letter-spacing: .03em; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; }
.chip-btn.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.sheet-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 18px; }
.sheet-actions .grow { flex: 1; }
.swatches { display: flex; gap: 10px; }
.swatches button { width: 34px; height: 34px; border-radius: 17px; border: 2px solid transparent; }
.swatches button.on { border-color: var(--text); }
.input { width: 100%; height: 46px; border-radius: 10px; border: .5px solid var(--hair); background: var(--surface-2); padding: 0 14px; font-size: 16px; outline: none; }
.input:focus { border-color: var(--accent); }
.toc a { display: block; padding: 9px 0; border-bottom: .5px solid var(--hair); font: 17px/1.3 var(--serif); }
.toc a.l3 { padding-left: 16px; font-size: 15px; color: var(--text-2); }
.toc a.l4, .toc a.l5, .toc a.l6 { padding-left: 32px; font-size: 14px; color: var(--text-3); }
.toc a.here { color: var(--accent-ink); }
.menu button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 4px; border-bottom: .5px solid var(--hair); font-size: 16px; }
.menu button svg { width: 20px; height: 20px; color: var(--text-2); }
.menu button.danger, .menu button.danger svg { color: #D93025; }

/* ---- highlights list ------------------------------------------------------ */

.hl-head { display: flex; align-items: center; gap: 8px; margin: 2px 0 4px; font-size: 15px; color: var(--text-2); flex-wrap: wrap; }
.hl-head svg { width: 18px; height: 18px; color: var(--accent); }
.hl-head b { color: var(--text); font-weight: 600; }
.filters { display: flex; gap: 8px; align-items: center; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters label { position: relative; display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border-radius: 18px; border: 1px solid var(--hair); background: var(--surface); font-size: 14px; white-space: nowrap; color: var(--text); }
.filters label svg { width: 15px; height: 15px; color: var(--text-2); }
.filters select { position: absolute; inset: 0; opacity: 0; font-size: 16px; }
.filters .dot { width: 10px; height: 10px; border-radius: 5px; background: conic-gradient(var(--spine-yellow) 0 25%, var(--spine-green) 0 50%, var(--spine-blue) 0 75%, var(--spine-purple) 0); }
.hl-list { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
.hl-card { position: relative; padding: 16px 16px 12px 20px; overflow: hidden; }
.hl-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--spine, var(--spine-yellow)); }
.hl-card.yellow { --spine: var(--spine-yellow); --badge: var(--hl-yellow); --badge-ink: var(--hl-yellow-ink); }
.hl-card.green { --spine: var(--spine-green); --badge: var(--hl-green); --badge-ink: var(--hl-green-ink); }
.hl-card.blue { --spine: var(--spine-blue); --badge: var(--hl-blue); --badge-ink: var(--hl-blue-ink); }
.hl-card.purple { --spine: var(--spine-purple); --badge: var(--hl-purple); --badge-ink: var(--hl-purple-ink); }
.hl-card .top { display: flex; align-items: center; gap: 8px; min-height: 28px; padding-right: 36px; }
.hl-card .top:empty { display: none; }
.hl-card .more { position: absolute; top: 10px; right: 8px; }
.hl-card .top:empty + blockquote { margin-top: 2px; padding-right: 28px; }
.hl-card .top .grow { flex: 1; }
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 12px; font: 600 12px var(--sans); letter-spacing: .06em; text-transform: uppercase; background: var(--badge); color: var(--badge-ink); }
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 4px; background: var(--spine); }
.badge.status { background: var(--accent-soft); color: var(--accent-ink); }
.badge.status::before { background: var(--accent); }
.hl-card blockquote { margin: 10px 0 12px; font: italic 19px/1.45 var(--serif); color: var(--text); }
.hl-card .your-note { border: .5px solid var(--hair); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }
.hl-card .your-note small { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--accent-ink); margin-bottom: 2px; }
.hl-card .your-note small svg { width: 15px; height: 15px; }
.hl-card .your-note p { margin: 0; font: 17px/1.4 var(--serif); color: var(--text-2); white-space: pre-wrap; }
.hl-card .foot-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-3); }
.hl-card .foot-row .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hl-card .jump { color: var(--accent-ink); font-weight: 600; display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.hl-card .jump svg { width: 16px; height: 16px; }
.group-head { display: flex; align-items: center; gap: 8px; margin: 22px 2px 0; font: 600 17px var(--serif); }
.group-head .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bm-row { display: flex; align-items: center; gap: 14px; padding: 14px 14px; }
.bm-row .ico { width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.bm-row .ico svg { width: 20px; height: 20px; }
.bm-row .txt { flex: 1; min-width: 0; }
.bm-row b { display: block; font: 600 18px/1.25 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bm-row small { display: block; font-size: 13px; color: var(--text-3); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bm-row small .mono { color: var(--accent-ink); }
.export-cap { text-align: center; font-size: 13px; color: var(--text-3); margin: 10px 0 0; }
.export-cap code { font: 12px var(--mono); background: var(--surface-2); padding: 2px 6px; border-radius: 4px; color: var(--text-2); }

/* ---- settings ------------------------------------------------------------- */

.group { margin: 0 0 22px; overflow: hidden; }
.group-title { font: 600 13px var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); margin: 22px 4px 8px; }
.set-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; min-height: 52px; }
.set-row + .set-row { border-top: .5px solid var(--hair); }
.set-row .grow { flex: 1; min-width: 0; }
.set-row small { display: block; color: var(--text-3); font-size: 13px; margin-top: 2px; overflow-wrap: anywhere; }
.set-row input[type="range"] { width: 100%; accent-color: var(--accent); }
.set-row .val { font: 13px var(--mono); color: var(--text-2); min-width: 44px; text-align: right; }
.set-row .segmented { margin: 0; flex: 1; }
.set-col { display: block; }
.set-col .lbl { display: flex; justify-content: space-between; margin-bottom: 8px; }
.preview-text { padding: 16px; font: var(--read-size)/var(--read-lh) var(--serif); }
.preview-text mark { background: var(--hl-yellow); color: inherit; border-radius: 3px; padding: .08em 0; }

/* ---- toast ---------------------------------------------------------------- */

.toast {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-b) + var(--tabs-h) + 18px);
  max-width: min(calc(100% - 32px), 420px); padding: 11px 18px; border-radius: 16px; background: var(--ink); color: var(--bg);
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow-hud); animation: pop .16s ease-out; text-align: center;
}
:root[data-theme="dark"] .toast { background: var(--surface-3); color: var(--text); }
@media (prefers-color-scheme: dark) { :root:not([data-theme]) .toast { background: var(--surface-3); color: var(--text); } }
body.reading .toast { bottom: calc(var(--safe-b) + 84px); }

@media (min-width: 720px) {
  :root { --gutter: 28px; }
  .page-title { font-size: 38px; }
}
/* Narrow phones: a long note title gets TWO lines instead of one crushed line. */
@media (max-width: 560px) {
  .row .name { white-space: normal; }
  .row .name span:first-child {
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    line-height: 1.25; overflow: hidden;
  }
  /* Compact the offline badge to its tick so the meta line keeps its text. */
  .row .meta .pill { padding: 2px 6px; }
  .row .meta .pill-txt { display: none; }

  /* Reader nav fits a 4th action without squeezing the note title: tighter buttons,
     and drop the decorative file glyph — the article shows the title in full. */
  .nav-inner { gap: 6px; }
  .nav-inner .icon-btn { width: 36px; height: 36px; border-radius: 18px; }
  .nav-inner .icon-btn svg { width: 20px; height: 20px; }
  body.reading .nav-inner .brand { gap: 0; }
  body.reading .nav-inner .brand .glyph { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---- vault folder picker (Settings → Vault folder) ------------------------ */
.fs-path { font-size: 12px; color: var(--text-2); padding: 0 2px 10px; overflow-wrap: anywhere; }
.fs-path b { color: var(--accent); font-weight: 600; }
.fs-list { /* single scroll region: the sheet itself scrolls, not a nested box */ }
.fs-actions { position: sticky; bottom: 0; background: var(--surface); padding-top: 12px; }
.fs-row { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 10px 4px;
  background: none; border: 0; border-top: .5px solid var(--hair); color: inherit;
  font: inherit; text-align: left; cursor: pointer; }
.fs-row:first-child { border-top: 0; }
.fs-row:active { background: var(--surface-2); }
.fs-row > svg { width: 18px; height: 18px; color: var(--text-3); }
.fs-row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fs-row .chev { width: 15px; height: 15px; opacity: .45; }
.fs-empty, .fs-note { font-size: 12.5px; color: var(--text-3); padding: 12px 2px; }
