/* papercripts: a textbook page someone has already studied for you. Rules: DESIGN.md.
   Layout: a slim top bar, then one sheet of paper per screen on a grey desk; reading text in
   one column, labels in the margin. */
:root {
  --pc-paper: #ffffff; --pc-ink: #1f2433; --pc-muted: #646a78; --pc-rule: #e4e6ec;
  --pc-marker: #ffe066; --pc-marker-ink: #1f2433; --pc-flag: #ffc2d6; --pc-accent: #2b4c9b;
  --pc-serif: "Literata", "Noto Serif", Georgia, serif;
  --pc-sans: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --pc-hand: "Patrick Hand", cursive; /* home page step numbers only */
  --button-ink: #ffffff; --desk: #f4f5f7;
  --pc-hl-1-bg: #e3e9f7; --pc-hl-1-ink: #2b4c9b; --pc-hl-2-bg: #1f2433; --pc-hl-2-ink: #ffffff;
  --pc-hl-3-bg: #dcefe4; --pc-hl-3-ink: #1f5a3d; --pc-hl-4-bg: #f3e6d3; --pc-hl-4-ink: #6b4a1c;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --pc-paper: #171a21; --pc-ink: #e8e6e1; --pc-muted: #a3a8b4; --pc-rule: #2c313c;
  --pc-marker: rgba(255, 214, 0, 0.32); --pc-marker-ink: #fff6d0; --pc-flag: rgba(255, 120, 170, 0.3);
  --pc-accent: #9fb6ff; --button-ink: #111522; --desk: #111318; color-scheme: dark;
  --pc-hl-1-bg: rgba(159, 182, 255, 0.16); --pc-hl-1-ink: #c9d6ff; --pc-hl-2-bg: #e8e6e1; --pc-hl-2-ink: #111522;
  --pc-hl-3-bg: rgba(110, 200, 150, 0.18); --pc-hl-3-ink: #bfe8cf; --pc-hl-4-bg: rgba(230, 190, 130, 0.18); --pc-hl-4-ink: #f0d9b5;
} }
:root[data-theme="dark"] {
  --pc-paper: #171a21; --pc-ink: #e8e6e1; --pc-muted: #a3a8b4; --pc-rule: #2c313c;
  --pc-marker: rgba(255, 214, 0, 0.32); --pc-marker-ink: #fff6d0; --pc-flag: rgba(255, 120, 170, 0.3);
  --pc-accent: #9fb6ff; --button-ink: #111522; --desk: #111318; color-scheme: dark;
  --pc-hl-1-bg: rgba(159, 182, 255, 0.16); --pc-hl-1-ink: #c9d6ff; --pc-hl-2-bg: #e8e6e1; --pc-hl-2-ink: #111522;
  --pc-hl-3-bg: rgba(110, 200, 150, 0.18); --pc-hl-3-ink: #bfe8cf; --pc-hl-4-bg: rgba(230, 190, 130, 0.18); --pc-hl-4-ink: #f0d9b5;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--desk); color: var(--pc-ink); font: 16px/1.6 var(--pc-sans);
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: env(safe-area-inset-top, 0px) calc(56px + var(--tray-space, 0px) + env(safe-area-inset-bottom, 0px));
}
a { color: var(--pc-accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--pc-accent); outline-offset: 3px; border-radius: 2px; }
.wrap { max-width: 860px; margin: 0 auto; display: grid; gap: 14px; }

/* Top bar */
.topbar { display: flex; align-items: baseline; justify-content: space-between; gap: 8px 20px; flex-wrap: wrap; padding: 16px 0 2px; }
.wordmark { font: 600 20px/1 var(--pc-serif); color: var(--pc-ink); text-decoration: none; letter-spacing: -0.01em; }
.nav { display: flex; gap: 18px; font-size: 14px; }
.nav a { color: var(--pc-muted); text-decoration: none; padding: 8px 0; }
.nav a[aria-current="page"] { color: var(--pc-ink); font-weight: 600; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 6px; }

.theme-switch { align-self: center; margin-left: -8px; color: var(--pc-muted); }
.theme-switch:hover { color: var(--pc-ink); }
.tool svg { width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.wordmark { margin-right: auto; }
@media (max-width: 599px) { /* the wordmark and the button, then the links */
  .tool.theme-switch { order: 1; margin: -6px -9px -6px 0; width: 44px; height: 44px; }
  .topbar .nav { order: 2; width: 100%; }
}

/* The sheet */
.page { background: var(--pc-paper); border: 1px solid var(--pc-rule); border-radius: 4px;
  padding: 28px clamp(18px, 5vw, 56px) 40px; display: grid; gap: 22px; min-width: 0; }

/* Drawn icons: home steps and the 404 page share one ink style. */
.ink-icon { overflow: visible; }
.ink-icon path, .ink-icon circle, .ink-icon rect { fill: none; stroke: var(--pc-ink); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.ink-icon .marker { stroke: var(--pc-marker); stroke-width: 10; }
.ink-icon .dots { stroke-dasharray: 2 7; }
.ink-icon .ghost { stroke: var(--pc-muted); stroke-dasharray: 5 6; }
.ink-icon text { font: 52px var(--pc-hand); fill: var(--pc-ink); stroke: none; }

/* Type */
.paper-title { margin: 0; font: 600 clamp(22px, 3.4vw, 30px)/1.25 var(--pc-serif); letter-spacing: -0.01em; text-wrap: balance; max-width: 32ch; }
.h2 { margin: 0; font: 600 17px/1.4 var(--pc-serif); }
.h2 small { font: 400 13px var(--pc-sans); color: var(--pc-muted); margin-left: 8px; }
.reading { margin: 0; font: 16.5px/1.7 var(--pc-serif); max-width: 62ch; }
.original { margin: 0; font: 14.5px/1.65 var(--pc-sans); color: var(--pc-muted); max-width: 70ch; }
.meta { margin: 0; color: var(--pc-muted); font-size: 14px; max-width: 70ch; }
.muted { color: var(--pc-muted); }
.small { font-size: 13.5px; }
.lead { margin: 0; font: 18px/1.65 var(--pc-serif); max-width: 52ch; }
.stack { display: grid; gap: 8px; min-width: 0; }
.stack-lg { display: grid; gap: 18px; min-width: 0; }

/* Highlighter (DESIGN.md: yellow = read first, pink = check this) */
.mark {
  background-image: linear-gradient(100deg, transparent 0 0.4%, var(--pc-marker) 1.2% 98.4%, transparent 99.4%);
  background-repeat: no-repeat; background-size: 100% 78%; background-position: 0 70%;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
  padding: 0 0.18em; margin: 0 -0.18em; color: var(--pc-marker-ink); border-radius: 0.2em 0.5em 0.3em 0.45em;
}
.mark.flag { background-image: linear-gradient(100deg, transparent 0 0.4%, var(--pc-flag) 1.2% 98.4%, transparent 99.4%); color: var(--pc-ink); }
.mark.drawn { animation: draw 0.7s cubic-bezier(.3,.7,.3,1) both 0.15s; }
@keyframes draw { from { background-size: 0% 78%; } to { background-size: 100% 78%; } }
@media (prefers-reduced-motion: reduce) { .mark.drawn { animation: none; } }

/* Buttons */
.btn { font: 600 15px/1 var(--pc-sans); border: 0; border-radius: 6px; padding: 15px 20px; min-height: 48px;
  background: var(--pc-ink); color: var(--button-ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; }
.btn.secondary { background: none; color: var(--pc-ink); border: 1px solid var(--pc-ink); }
.btn:disabled { opacity: 0.55; cursor: default; }
.link { font: 500 14px/1.2 var(--pc-sans); color: var(--pc-accent); background: none; border: 0; padding: 8px 0; min-height: 36px;
  cursor: pointer; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.link:hover { text-decoration-thickness: 2px; }
.link.quiet { color: var(--pc-muted); }
/* Buttons and links inside grid stacks keep their own width, aligned left (DESIGN.md: left-aligned). */
.stack > .link, .stack > .btn, .stack > a, .row-body > .link, .page > .link { justify-self: start; text-align: left; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; }

/* Choice chips (onboarding, field filter): outlined, ink when chosen. */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font: 500 14px/1.2 var(--pc-sans); padding: 10px 14px; min-height: 40px; border-radius: 999px;
  border: 1px solid var(--pc-rule); background: var(--pc-paper); color: var(--pc-muted); cursor: pointer; }
.chip[aria-pressed="true"] { border-color: var(--pc-ink); color: var(--pc-ink); font-weight: 600; box-shadow: inset 0 0 0 1px var(--pc-ink); }

/* Field list (DESIGN.md "Field list"): domains, one row per field, a press opens its subfields. */
.field-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 28px 40px; align-items: start; }
.fl-domain h3 { margin: 0 0 4px; font: 600 16px/1.4 var(--pc-serif); }
.fl-domain ul { margin: 0; padding: 0; list-style: none; }
.fl-domain li + li { border-top: 1px solid var(--pc-rule); }
.fl-field > summary { display: flex; align-items: baseline; gap: 12px; padding: 11px 0; min-height: 44px; cursor: pointer; list-style: none; }
.fl-field > summary::-webkit-details-marker { display: none; }
.fl-field > summary::before { content: ""; flex: none; width: 6px; height: 6px; margin: 0 2px 2px 0; border: solid var(--pc-muted);
  border-width: 0 1.5px 1.5px 0; transform: rotate(-45deg); transition: transform 0.15s; }
.fl-field[open] > summary::before { transform: rotate(45deg); }
.fl-name { flex: 1; font: 600 15px/1.4 var(--pc-sans); color: var(--pc-ink); }
.fl-field > summary:hover .fl-name { color: var(--pc-accent); }
.fl-note { flex: none; font: 13px/1.4 var(--pc-sans); color: var(--pc-muted); }
.fl-note.on { color: var(--pc-ink); font-weight: 600; }
.fl-note.on::before { content: "✓ "; content: "✓ " / ""; }
.fl-subs { gap: 6px; padding: 2px 0 16px 18px; }
.fl-subs .chip { font-size: 13px; padding: 7px 12px; min-height: 34px; }
@media (prefers-reduced-motion: reduce) { .fl-field > summary::before { transition: none; } }
.fields-more > .hint { margin: 2px 0 16px; }
.fields-more > summary { display: inline-block; font: 500 14px/1.2 var(--pc-sans); color: var(--pc-accent); cursor: pointer; padding: 8px 0; min-height: 36px;
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }

/* Search */
.search { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.search input { font: 16px/1.4 var(--pc-sans); color: var(--pc-ink); background: var(--pc-paper); min-width: 0;
  border: 1px solid var(--pc-rule); border-radius: 6px; padding: 12px 14px; min-height: 48px; }
.search input:focus { border-color: var(--pc-ink); outline: none; box-shadow: inset 0 0 0 1px var(--pc-ink); }
.search .btn { padding-inline: 18px; }
.hint { margin: 0; font-size: 13px; color: var(--pc-muted); }

/* Upload: a native file input hidden behind a secondary button, and an agreement checkbox. */
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
.visually-hidden:focus-visible + label { outline: 2px solid var(--pc-accent); outline-offset: 3px; }
label.btn { display: inline-flex; align-items: center; cursor: pointer; }
.check { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: start; font-size: 14px; line-height: 1.55; max-width: 62ch; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--pc-ink); }
.gsi { min-height: 44px; }

/* Feed: entries on one sheet, separated by rules (no nested cards). */
.feed { list-style: none; margin: 0; padding: 0; display: grid; }
.entry { display: grid; gap: 6px; padding: 20px 0; border-top: 1px solid var(--pc-rule); min-width: 0; }
.entry:first-child { border-top: 0; padding-top: 4px; }
.entry-title { margin: 0; font: 600 18.5px/1.38 var(--pc-serif); text-wrap: pretty; }
.entry-title a { color: var(--pc-ink); text-decoration: none; }
.entry-title a:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 4px; }
.entry-en { margin: 0; font-size: 13.5px; color: var(--pc-muted); }
.entry-meta { margin: 0; font-size: 13.5px; color: var(--pc-muted); }
.avail { margin: 0; font-size: 13px; color: var(--pc-ink); font-weight: 500; }
.avail::before { content: "✓ "; }
.entry .actions { gap: 4px 18px; margin-top: 2px; }
.filter-note { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin: 0; font-size: 14px; }
.end { margin: 0; padding: 16px 0 0; border-top: 1px solid var(--pc-rule); font-size: 14px; color: var(--pc-muted); }

/* Margin-note rows (quick read sections, saved list groups) */
.row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px 0; padding-top: 18px; border-top: 1px dashed var(--pc-rule); }
.row-label { margin: 0; font: 600 14px/1.4 var(--pc-sans); }
.row-label .sub { display: block; font-weight: 400; font-size: 12.5px; color: var(--pc-muted); }
.row-body { min-width: 0; display: grid; gap: 10px; max-width: 62ch; }
@media (min-width: 720px) {
  .row { grid-template-columns: 10.5rem minmax(0, 1fr); column-gap: 1.75rem; }
  .row-label { text-align: right; padding-top: 3px; }
}

/* Question block ("Bài này có hữu ích…", "Bạn có sẵn sàng trả…") */
.question { display: grid; gap: 10px; padding: 18px 0 0; border-top: 1px solid var(--pc-rule); }
.question .actions .btn { padding: 12px 16px; min-height: 44px; }

/* Full-PDF progress: an ink line filling a rule-coloured track. */
.progress { height: 4px; border-radius: 2px; background: var(--pc-rule); overflow: hidden; max-width: 62ch; }
/* Quota meter (profile): share of today's limit used. Blue, then marker yellow, then pink. */
.quota { display: grid; gap: 6px; }
.quota p { margin: 0; }
.meter { height: 8px; border-radius: 4px; background: var(--pc-rule); overflow: hidden; max-width: 62ch; }
.meter span { display: block; height: 100%; min-width: 0; border-radius: 4px; background: var(--pc-accent); transition: width 0.6s ease; }
.meter[data-level="near"] span { background: var(--pc-marker); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--pc-ink) 18%, transparent); }
.meter[data-level="out"] span { background: var(--pc-flag); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--pc-ink) 18%, transparent); }
@media (prefers-reduced-motion: reduce) { .meter span { transition: none; } }
.progress span { display: block; height: 100%; width: 0; background: var(--pc-ink); transition: width 0.6s ease; }
@media (prefers-reduced-motion: reduce) { .progress span { transition: none; } }

/* Lists of related papers */
.refs { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.refs li { display: grid; gap: 2px; }
.refs a { font: 500 15px/1.45 var(--pc-serif); color: var(--pc-ink); text-decoration: none; }
.refs a:hover { text-decoration: underline; text-decoration-thickness: 1px; }
.refs .meta { font-size: 13px; }
.cite { overflow-wrap: anywhere; } /* long DOIs on a phone */

/* Home page (DESIGN.md "Home page") */
.page.home { gap: 72px; padding-top: clamp(40px, 7vw, 72px); container-type: inline-size; }
.home-hero { display: grid; justify-items: center; gap: 22px; text-align: center; }
/* The title never wraps by itself. From 720px: two lines, sized so the longest first line ("Hàng triệu bài tổng quan
   mở,", about 14.4em with the box padding) fits the sheet's content width (100cqw). Below 720px: four lines, the
   break spans (.brk) split each line in two, sized so the longest noun line fits. Either way the words only slide sideways. */
.home-title { margin: 0; font: 600 clamp(28px, calc((100vw - 56px) / 9.6), 40px)/1.12 var(--pc-serif); letter-spacing: -0.025em; }
@container (min-width: 1px) { .home-title { font-size: clamp(28px, 100cqw / 9.6, 40px); } }
.home-title .line { display: block; white-space: nowrap; }
.home-title .brk { display: block; }
@media (max-width: 719px) { .page.home { padding-inline: 12px; } }
@media (min-width: 720px) {
  .home-title { font-size: clamp(16px, calc((100vw - 70px) / 15.2), 60px); }
  @container (min-width: 1px) { .home-title { font-size: min(60px, 100cqw / 15.2); } }
  .home-title .brk { display: none; }
}
/* The rotating noun: a near-rectangle highlight whose width eases to the next word, words sliding up. */
.hl { position: relative; display: inline-block; vertical-align: bottom; height: 1.18em; padding: 0 0.16em;
  border-radius: 0.09em; background-color: var(--hl-bg); color: var(--hl-ink); overflow: hidden;
  transition: width 0.55s cubic-bezier(.65, 0, .35, 1), background-color 0.4s, color 0.4s; }
.hl-1 { --hl-bg: var(--pc-hl-1-bg); --hl-ink: var(--pc-hl-1-ink); }
.hl-2 { --hl-bg: var(--pc-hl-2-bg); --hl-ink: var(--pc-hl-2-ink); }
.hl-3 { --hl-bg: var(--pc-hl-3-bg); --hl-ink: var(--pc-hl-3-ink); }
.hl-4 { --hl-bg: var(--pc-hl-4-bg); --hl-ink: var(--pc-hl-4-ink); }
.hl .word { display: block; white-space: nowrap; line-height: 1.18em;
  transition: transform 0.55s cubic-bezier(.65, 0, .35, 1), opacity 0.4s ease; }
.hl .word.next, .hl .word.probe { position: absolute; left: 0.16em; top: 0; }
.hl .word.next { transform: translateY(100%); opacity: 0; }
.hl .word.probe { visibility: hidden; transition: none; }
.hl.go .word.cur { transform: translateY(-100%); opacity: 0; }
.hl.go .word.next { transform: translateY(0); opacity: 1; }
@media (prefers-reduced-motion: reduce) { .hl, .hl .word { transition: none; } }
.home-hero .lead { color: var(--pc-muted); }
.home-hero .actions { justify-content: center; }
.home-shot { display: grid; gap: 10px; }
.home-shot-bar { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border: 1px solid var(--pc-rule); border-bottom: 0;
  border-radius: 8px 8px 0 0; font: 500 13px var(--pc-sans); color: var(--pc-muted); margin-bottom: -10px; }
.home-shot-bar .tag { border: 1px solid var(--pc-rule); border-radius: 6px; padding: 3px 9px; }
.home-shot-bar .at { margin-left: auto; }
.home-spread { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 16px; background: var(--desk); border: 1px solid var(--pc-rule); border-radius: 0 0 8px 8px; }
.home-spread figure { margin: 0; display: grid; gap: 6px; min-width: 0; }
.home-spread img { display: block; width: 100%; height: auto; background: #ffffff; box-shadow: 0 0 0 1px var(--pc-rule); }
.home-spread figcaption { font: 500 12px var(--pc-sans); color: var(--pc-muted); }
.home-credit { margin: 0; font-size: 12.5px; color: var(--pc-muted); }
.home-sources { margin: -40px 0 0; display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: 6px 24px; font-size: 14px; color: var(--pc-muted); text-align: center; }
.home-sources b { font: 600 17px var(--pc-serif); color: var(--pc-ink); }
.home-sources span { flex-basis: 100%; font-size: 13px; }
.home-steps h2 { margin: 0 0 28px; font: 600 clamp(24px, 3.6vw, 30px)/1.2 var(--pc-serif); text-align: center; text-wrap: balance; }
.home-steps ol { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 28px; }
.step { display: grid; gap: 10px; align-content: start; padding-top: 20px; border-top: 1px solid var(--pc-rule); }
.step h3 { margin: 0; font: 600 18px/1.3 var(--pc-serif); }
.step p { margin: 0; font-size: 14.5px; color: var(--pc-muted); }
.step-num { font: 34px/1 var(--pc-hand); color: var(--pc-muted); }
.step-icon { width: 64px; height: 52px; }
.step .step-sample { margin-top: 4px; padding: 12px 14px; border: 1px solid var(--pc-rule); border-radius: 6px; font-size: 13.5px; color: var(--pc-ink); }
.step p.step-sample.reading { font: 14.5px/1.55 var(--pc-serif); }
.search-sample { display: flex; gap: 6px; }
.search-sample span { flex: 1; padding: 6px 9px; border: 1px solid var(--pc-rule); border-radius: 5px; color: var(--pc-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.search-sample b { padding: 6px 10px; border-radius: 5px; background: var(--pc-ink); color: var(--button-ink); font-weight: 600; }
.step-sample .bar { display: block; height: 4px; margin: 8px 0 6px; border-radius: 2px; background: var(--pc-rule); }
.step-sample .bar i { display: block; width: 72%; height: 100%; border-radius: 2px; background: var(--pc-ink); }
@media (max-width: 599px) {
  .home-spread { grid-template-columns: 1fr; }
  .home-spread figure:first-child, .home-shot-bar .tag { display: none; }
}
/* Not found page */
.page.not-found { justify-items: center; text-align: center; gap: 14px; padding-top: clamp(40px, 7vw, 72px); padding-bottom: clamp(40px, 7vw, 72px); }
.not-found .not-found-art { width: 120px; height: 96px; margin-bottom: 4px; }
.not-found .not-found-code { font: 36px/1 var(--pc-hand); color: var(--pc-muted); }
.not-found h1 { margin: 0; font: 600 clamp(28px, 5vw, 40px)/1.2 var(--pc-serif); text-wrap: balance; }
.not-found p { margin: 0; max-width: 46ch; text-wrap: pretty; }
.not-found .not-found-joke { font: 18px/1.6 var(--pc-serif); }
.not-found .not-found-note { font-size: 14.5px; color: var(--pc-muted); }
.not-found .actions { justify-content: center; margin-top: 10px; }
.points { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; max-width: 60ch; }
.points li { font-size: 15.5px; }
.points b { font-weight: 600; }

.loading-lines { display: grid; gap: 12px; max-width: 62ch; }
.loading-lines span { display: block; height: 0.62em; border-radius: 0.3em; background: var(--pc-rule); }
.toast { position: fixed; left: 50%; bottom: calc(16px + var(--tray-space, 0px) + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--pc-ink); color: var(--button-ink); font-size: 14px; padding: 10px 16px; border-radius: 6px; z-index: 60; max-width: calc(100% - 32px); }

/* Job tray (DESIGN.md): translations in progress, fixed at the lower right on every page. */
#app:focus { outline: none; }
.tray { position: fixed; z-index: 50; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  width: min(360px, calc(100vw - 32px)); max-height: min(60vh, 460px); display: grid; grid-template-rows: auto minmax(0, 1fr);
  background: var(--pc-paper); color: var(--pc-ink); border: 1px solid var(--pc-rule); border-radius: 6px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.08); }
.tray-head { display: flex; align-items: center; gap: 0 14px; padding: 2px 14px 2px 16px; min-width: 0; }
.tray:not(.collapsed) .tray-head { border-bottom: 1px solid var(--pc-rule); }
.tray-summary { margin: 0; flex: 1; min-width: 0; font: 600 14px/1.4 var(--pc-sans); padding: 8px 0; }
.tray-btn { min-width: 36px; flex: none; }
.tray-list { list-style: none; margin: 0; padding: 0 16px; overflow-y: auto; overscroll-behavior: contain; display: grid; align-content: start; }
.tray-row { display: grid; gap: 6px; padding: 12px 0 10px; border-top: 1px solid var(--pc-rule); min-width: 0; }
.tray-row:first-child { border-top: 0; }
.tray-name { font: 600 15px/1.4 var(--pc-serif); color: var(--pc-ink); text-decoration: none; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tray-name:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.tray-row .meta { font-size: 13.5px; line-height: 1.5; }
.tray-row .progress { margin-top: 2px; }
.tray-foot { display: grid; gap: 2px; }
.tray-foot .actions { gap: 0 18px; }
@media (max-width: 599px) {
  .tray { left: max(16px, env(safe-area-inset-left, 0px)); width: auto; max-height: 40vh; }
}

/* PDF viewer (#xem-…, DESIGN.md "PDF viewer"): a full-window reader (web/app/reader.js). The PDF
   pages stay white in both themes. */
:root { --viewer-gutter: color-mix(in srgb, var(--pc-muted) 62%, var(--desk)); --viewer-on: color-mix(in srgb, var(--pc-accent) 14%, var(--pc-paper)); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --viewer-gutter: color-mix(in srgb, var(--pc-rule) 60%, var(--desk)); } }
:root[data-theme="dark"] { --viewer-gutter: color-mix(in srgb, var(--pc-rule) 60%, var(--desk)); }
body:has(.reader) { overflow: hidden; }
body:has(.reader) :is(.topbar, .tray) { display: none; } /* the job tray (z-index 50) would sit over the reader */
.reader { position: fixed; inset: 0; z-index: 40; display: grid; grid-template: minmax(0, 1fr) / 256px minmax(0, 1fr);
  background: var(--desk); color: var(--pc-ink); font: 13px/1.5 var(--pc-sans);
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); }
.reader.no-side { grid-template-columns: minmax(0, 1fr); }
.reader.no-side .reader-side { display: none; }
.reader svg { width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.reader :focus-visible { outline-offset: -2px; }
.reader[data-view="both"] .only-one, .reader:not([data-view="both"]) .only-both,
.reader[data-view="vi"] .reader-main [data-side="en"], .reader[data-view="en"] .reader-main [data-side="vi"] { display: none; }

.reader-side { min-height: 0; display: flex; flex-direction: column; background: var(--pc-paper); border-right: 1px solid var(--pc-rule); }
.reader-side h1 { margin: 0; flex: none; padding: 0 18px; font: 600 16px/56px var(--pc-serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-side .seg { flex: none; margin: 0 12px 10px; }
.reader-side .seg button { flex: 1; }
.side-files { display: none; }
.thumbs { position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; border-top: 1px solid var(--pc-rule);
  padding: 6px 0 24px; display: grid; justify-items: center; align-content: start; gap: 6px; }
.thumb { width: 138px; padding: 9px 12px 6px; border: 0; border-radius: 6px; background: none; color: var(--pc-muted); cursor: pointer; display: grid; justify-items: center; gap: 6px; }
.thumb:hover, .thumb[aria-current] { background: var(--desk); }
.thumb-page { display: block; width: 112px; background: #ffffff; outline: 1px solid var(--pc-rule); overflow: hidden; }
.thumb-page canvas { display: block; width: 100%; height: 100%; }
.thumb-name { padding: 1px 8px; border-radius: 4px; }
.thumb[aria-current] .thumb-page { outline: 2px solid var(--pc-accent); }
.thumb[aria-current] .thumb-name { background: var(--pc-ink); color: var(--button-ink); font-weight: 500; }
/* Contents ("Mục lục"): sections indented by depth; the one being read is marked like a pressed button. */
.toc { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; border-top: 1px solid var(--pc-rule); padding: 6px 8px 24px; }
.toc ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.toc-item { width: 100%; min-height: 36px; padding: 7px 10px 7px calc(10px + var(--depth, 0) * 14px); border: 0; border-radius: 6px; background: none;
  color: var(--pc-ink); cursor: pointer; text-align: left; font: 400 13.5px/1.4 var(--pc-sans); overflow-wrap: anywhere; }
.toc-item[data-depth="0"] { font-weight: 500; }
.toc-item:hover { background: var(--desk); }
.toc-item[aria-current] { background: var(--viewer-on); color: var(--pc-accent); font-weight: 600; }

.reader-main { position: relative; min-width: 0; min-height: 0; display: grid; grid-template: 56px 34px minmax(0, 1fr) / minmax(0, 1fr); container-type: inline-size; }
.reader-bar { display: flex; align-items: center; gap: 8px; padding: 0 14px; border-bottom: 1px solid var(--pc-rule); }
.reader-bar .gap { flex: 1; }
.seg { display: inline-flex; flex: none; height: 38px; border: 1px solid var(--pc-rule); border-radius: 8px; background: var(--pc-paper); overflow: clip; }
.seg button, .tool { min-width: 36px; padding: 0 9px; border: 0; background: none; color: var(--pc-ink); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; font: 500 13px/1 var(--pc-sans); white-space: nowrap; }
.tool { flex: none; height: 36px; border-radius: 8px; }
.seg button + button { border-left: 1px solid var(--pc-rule); }
.seg.joined button + button { border-left: 0; }
.themes { justify-self: start; height: 44px; }
.themes button { padding: 0 14px; font-size: 14px; }
.seg button:hover, .tool:hover { background: color-mix(in srgb, var(--pc-ink) 6%, transparent); }
.seg button[aria-pressed="true"] { background: var(--viewer-on); color: var(--pc-accent); }
.seg button:disabled { opacity: 0.4; cursor: default; }
.seg .zoom-now { min-width: 54px; font-variant-numeric: tabular-nums; }
.menu-at { position: relative; }
.reader-menu { position: absolute; z-index: 3; right: 0; top: calc(100% + 6px); display: grid; min-width: 200px; padding: 5px;
  background: var(--pc-paper); border: 1px solid var(--pc-rule); border-radius: 8px; }
.reader-menu a, .side-files a, .side-share { min-height: 36px; display: flex; align-items: center; padding: 0 10px; border-radius: 5px; color: var(--pc-ink); text-decoration: none; font-weight: 500; }
.reader-menu a:hover, .side-files a:hover, .side-share:hover { background: var(--desk); }
.side-share { border: 0; background: none; font: inherit; font-weight: 500; text-align: left; cursor: pointer; }
.reader-find { position: absolute; z-index: 2; right: 14px; top: 62px; display: flex; align-items: center; gap: 4px; padding: 5px;
  background: var(--pc-paper); border: 1px solid var(--pc-rule); border-radius: 8px; max-width: calc(100% - 28px); }
.reader-find input { width: 220px; min-width: 0; height: 36px; padding: 0 10px; border: 1px solid var(--pc-rule); border-radius: 6px; background: none; color: var(--pc-ink); font: 400 14px var(--pc-sans); }
.reader-find input::-webkit-search-cancel-button { display: none; } /* the panel has its own close button */
.reader-find input:focus { outline: 0; border-color: var(--pc-ink); box-shadow: inset 0 0 0 1px var(--pc-ink); }
.find-count { min-width: 92px; padding: 0 6px; color: var(--pc-muted); text-align: center; white-space: nowrap; }

.reader-names, .reader-panes { display: grid; grid-template: minmax(0, 1fr) / var(--split, calc(50% - 3.5px)) 7px minmax(0, 1fr); min-height: 0; }
.reader:not([data-view="both"]) :is(.reader-names, .reader-panes) { grid-template-columns: minmax(0, 1fr); }
.reader-names { border-bottom: 1px solid var(--pc-rule); }
.pdf-name { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 0 14px; white-space: nowrap; overflow: hidden; color: var(--pc-muted); }
.pdf-name b { font-weight: 500; color: var(--pc-ink); overflow: hidden; text-overflow: ellipsis; }
.badge { flex: none; padding: 0 6px; border-radius: 4px; background: var(--viewer-on); color: var(--pc-accent); font: 600 12px/21px var(--pc-sans); }
.reader-panes { background: var(--viewer-gutter); }
.pdf-pane { position: relative; min-width: 0; overflow: auto scroll; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--pc-muted) transparent; }
.pdf-sheet { display: grid; justify-items: center; gap: 14px; width: max-content; min-width: 100%; padding: 14px; }
.divider { background: color-mix(in srgb, var(--pc-ink) 30%, var(--viewer-gutter)); cursor: col-resize; touch-action: none; }
.divider:hover, .divider:focus-visible { background: var(--pc-accent); outline: 0; }
.pdf-box { position: relative; overflow: hidden; background: #ffffff; color: #1f2433; }
.pdf-box > canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.pdf-broken { margin: 0; padding: 24px; font-size: 14px; }
.pdf-credit { padding: calc(56px * var(--s)); font: 400 calc(10.5px * var(--s))/1.6 var(--pc-sans); overflow-wrap: anywhere; }
.pdf-credit h2 { margin: calc(18px * var(--s)) 0; font: 600 calc(18px * var(--s))/1.35 var(--pc-serif); }
.pdf-credit p { margin: 0 0 calc(8px * var(--s)); }

/* PDF.js's invisible text layer (from its pdf_viewer.css), so text can be selected and copied. */
.pdf-text { position: absolute; overflow: clip; line-height: 1; text-align: initial; transform-origin: 0 0; -webkit-text-size-adjust: none; text-size-adjust: none; forced-color-adjust: none;
  --scale-round-x: 1px; --scale-round-y: 1px; --min-font-size: 1; --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size)); --min-font-size-inv: calc(1 / var(--min-font-size)); }
.pdf-text[data-main-rotation="90"] { transform: rotate(90deg) translateY(-100%); }
.pdf-text[data-main-rotation="180"] { transform: rotate(180deg) translate(-100%, -100%); }
.pdf-text[data-main-rotation="270"] { transform: rotate(270deg) translateX(-100%); }
.pdf-text :is(span, br) { position: absolute; color: transparent; white-space: pre; cursor: text; transform-origin: 0 0; }
.pdf-text span { --font-height: 0; --scale-x: 1; --rotate: 0deg; font-size: calc(var(--text-scale-factor) * var(--font-height));
  transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv)); }
.reader[data-select="en"] .pdf-pane[data-side="vi"], .reader[data-select="vi"] .pdf-pane[data-side="en"] { user-select: none; }
.pdf-text ::selection { background: color-mix(in srgb, #2b4c9b 28%, transparent); }
::highlight(pdf-find) { background-color: color-mix(in srgb, #2b4c9b 22%, transparent); }
::highlight(pdf-find-now) { background-color: color-mix(in srgb, #2b4c9b 50%, transparent); }

/* Tooltip (web/app/tooltip.js) */
.tip { position: fixed; z-index: 70; width: max-content; max-width: 250px; padding: 6px 10px; border-radius: 6px; background: var(--pc-ink); color: var(--button-ink);
  font: 12px/1.45 var(--pc-sans); text-wrap: balance; pointer-events: none; }
.tip kbd { margin-left: 8px; padding: 0 6px; border: 1px solid color-mix(in srgb, var(--button-ink) 45%, transparent); border-radius: 4px; font: 500 11px/1.5 var(--pc-sans); }

@container (max-width: 960px) { .lock span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); } }
@container (max-width: 780px) { .reader-bar .turns { display: none; } } /* the theme button too */
@container (max-width: 660px) { .reader-bar .flows { display: none; } }
@container (max-width: 600px) { .reader-bar .zoom-now { display: none; } }
@container (max-width: 560px) { .reader-bar { padding: 0 8px; gap: 5px; } .reader-bar .fold { display: none; } }
@media (max-width: 719px) {
  .reader, .reader.no-side { grid-template-columns: minmax(0, 1fr); }
  .reader .wide, .reader .zoom-now, .reader-names, .reader-bar .share { display: none; } /* share moves into the drawer */
  .reader-main { grid-template-rows: 52px minmax(0, 1fr); }
  .reader-bar { padding: 0 8px; gap: 5px; }
  .reader-side { position: fixed; z-index: 4; top: calc(52px + env(safe-area-inset-top, 0px)); bottom: 0; left: 0; width: min(256px, 80vw); }
  .reader-side h1 { line-height: 48px; }
  .side-files { display: grid; padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--pc-rule); }
  .reader-find { left: 8px; right: 8px; top: 58px; max-width: none; }
  .reader-find input { flex: 1; width: auto; font-size: 16px; } /* under 16px, iPhones zoom the page */
  .find-count { min-width: 0; }
  .pdf-sheet { padding: 8px; gap: 8px; }
}

/* Inside a foreign frame (app/frame-guard.js): only the note shows, nothing of the app can be clicked. */
html.framed body > :not(.frame-note) { display: none !important; }
.frame-note { max-width: 860px; margin: 0 auto; }
