/* 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;
  --button-ink: #ffffff; --desk: #f4f5f7;
}
@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; } }
: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; }

* { 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 + 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; }

/* 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; }

/* Type */
.display { margin: 0; font: 600 clamp(28px, 6vw, 46px)/1.15 var(--pc-serif); letter-spacing: -0.015em; text-wrap: balance; max-width: 18ch; }
.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.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); }

/* 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; }

/* Landing */
.hero { display: grid; gap: 18px; padding-block: 8px 4px; }
.sample { display: grid; gap: 10px; padding: 18px 0; border-block: 1px solid var(--pc-rule); }
.sample .row-label { text-align: left; padding: 0; }
.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 + 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); }
