/* Ngày tháng — the reader. Phone first: the book is opened from Facebook, mostly on a phone. */
:root {
  --fs: 19px;
  --lh: 1.85;
  --serif: "Literata", "Noto Serif", Georgia, "Times New Roman", serif;
  --sans: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --measure: 36rem;
  --gutter: 20px;
  --paper: #f8f1e3; --surface: #fffaf0; --ink: #2d261e; --muted: #72675a; --line: #e2d6bf; --accent: #a31f2b; --on-accent: #fffaf0;
  color-scheme: light;
}
[data-theme="light"] { --paper: #ffffff; --surface: #f6f6f4; --ink: #1f1f1f; --muted: #646464; --line: #e4e4e0; --accent: #a31f2b; --on-accent: #ffffff; }
[data-theme="paper"] { --paper: #f8f1e3; --surface: #fffaf0; --ink: #2d261e; --muted: #72675a; --line: #e2d6bf; --accent: #a31f2b; --on-accent: #fffaf0; }
[data-theme="dark"]  { --paper: #16140f; --surface: #211e18; --ink: #d9d2c5; --muted: #9a9184; --line: #38332a; --accent: #ef8f8f; --on-accent: #1a1610; color-scheme: dark; }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: 72px; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------------------------------------------------------------- top bar + progress */
.bar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 4px; min-height: 52px; padding: 0 8px 0 var(--gutter); background: var(--paper); border-bottom: 1px solid var(--line); transition: transform .22s ease; }
.bar--away { transform: translateY(-100%); }
.bar__home { flex: 1 1 auto; min-width: 0; font-family: var(--serif); font-weight: 600; font-size: 17px; color: var(--ink); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar__btn { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; padding: 0 10px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--ink); text-decoration: none; }
.bar__btn:hover { background: var(--surface); }
.prog { position: fixed; top: 0; left: 0; right: 0; z-index: 11; height: 3px; pointer-events: none; }
.prog i { display: block; height: 100%; background: var(--accent); transform: scaleX(0); transform-origin: 0 50%; }
html:not(.js) [data-js-only] { display: none; }

/* ---------------------------------------------------------------- chapter */
.chapter { max-width: calc(var(--measure) + var(--gutter) * 2); margin: 0 auto; padding: 44px var(--gutter) 24px; }
.chapter__no { margin: 0 0 8px; font-size: 14px; font-weight: 600; color: var(--accent); }
.chapter h1 { margin: 0 0 8px; font-family: var(--serif); font-size: clamp(30px, 8vw, 40px); line-height: 1.2; font-weight: 600; letter-spacing: -.005em; text-wrap: balance; }
.chapter__meta { margin: 0 0 36px; font-size: 14px; color: var(--muted); }
.prose { font-family: var(--serif); font-size: var(--fs); line-height: var(--lh); font-optical-sizing: auto; overflow-wrap: break-word; }
[data-font="sans"] .prose { font-family: var(--sans); }
.prose p { margin: 0 0 1em; text-wrap: pretty; }

.finish { max-width: calc(var(--measure) + var(--gutter) * 2); margin: 0 auto; padding: 12px var(--gutter) 24px; }
.pager { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.pager a { display: flex; flex-direction: column; justify-content: center; gap: 4px; min-height: 84px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); text-decoration: none; }
.pager a:hover { border-color: var(--accent); }
.pager small { font-size: 13px; color: var(--muted); }
.pager b { font-family: var(--serif); font-size: 16px; font-weight: 600; line-height: 1.3; }
.pager__next { grid-column: 2; text-align: right; background: var(--accent) !important; border-color: var(--accent) !important; color: var(--on-accent) !important; }
.pager__next small { color: inherit; opacity: .85; }
.tools { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 20px; margin: 20px 0 0; font-size: 14px; }
.tools a, .tools button { display: inline-flex; align-items: center; min-height: 44px; font-weight: 600; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }

.author-note { max-width: calc(var(--measure) + var(--gutter) * 2); margin: 12px auto 0; padding: 0 var(--gutter); }
.author-note div { padding: 20px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.author-note p { margin: 0 0 10px; }
.author-note p:last-child { margin: 0; }

.foot { margin-top: 36px; padding: 20px var(--gutter) calc(24px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); text-align: center; font-size: 14px; color: var(--muted); }
.foot a { color: inherit; }

.resume { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 12; display: flex; align-items: center; transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px); border-radius: 8px; background: var(--ink); box-shadow: 0 6px 24px rgba(0, 0, 0, .25); }
.resume[hidden] { display: none; }
.resume button { min-height: 48px; padding: 0 18px; font-size: 15px; font-weight: 600; color: var(--paper); }

/* ---------------------------------------------------------------- panels */
dialog { color: var(--ink); background: var(--paper); border: 1px solid var(--line); padding: 0; }
dialog::backdrop { background: rgba(20, 15, 8, .5); }
.sheet { width: 100%; max-width: 440px; margin: auto auto 0; border-radius: 12px 12px 0 0; border-bottom: 0; }
.sheet__in { padding: 8px 20px calc(20px + env(safe-area-inset-bottom)); }
.sheet__head { display: flex; align-items: center; justify-content: space-between; min-height: 52px; font-weight: 600; }
.row { display: grid; grid-template-columns: 92px minmax(0, 1fr); align-items: center; gap: 12px; padding: 8px 0; font-size: 14px; color: var(--muted); }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1 1 0; min-width: 0; min-height: 44px; padding: 0 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 600; }
.seg button[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); color: var(--accent); }
.seg .size-label { flex: 1 1 0; display: flex; align-items: center; justify-content: center; font-size: 14px; color: var(--ink); }
.panel { width: min(100vw, 400px); max-width: none; height: 100%; max-height: none; margin: 0 0 0 auto; border-width: 0 0 0 1px; }
.panel__head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; min-height: 56px; padding: 0 8px 0 20px; background: var(--paper); border-bottom: 1px solid var(--line); font-weight: 600; }

/* ---------------------------------------------------------------- table of contents */
.toc { list-style: none; margin: 0; padding: 0; }
.toc a { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: baseline; gap: 8px; min-height: 52px; padding: 13px 20px; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.toc a:hover { background: var(--surface); }
.toc a[aria-current="page"] { background: var(--surface); box-shadow: inset 3px 0 0 var(--accent); }
.toc__n { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.toc__t { font-family: var(--serif); font-size: 17px; line-height: 1.35; }
.toc__m { font-size: 13px; color: var(--muted); white-space: nowrap; }
.is-done .toc__n { color: var(--accent); }
.is-done .toc__t { color: var(--muted); }

/* ---------------------------------------------------------------- landing */
.hero { display: grid; gap: 28px; justify-items: center; max-width: 880px; margin: 0 auto; padding: 32px var(--gutter) 12px; text-align: center; }
.hero__cover { display: block; width: min(58vw, 240px); height: auto; border-radius: 3px; box-shadow: 0 14px 34px rgba(40, 50, 60, .28); }
.hero__kicker { margin: 0 0 6px; font-size: 14px; font-weight: 600; color: var(--accent); }
.hero h1 { margin: 0; font-family: var(--serif); font-size: clamp(40px, 11vw, 60px); line-height: 1.1; font-weight: 600; }
.hero__by { margin: 8px 0 14px; font-size: 16px; color: var(--muted); }
.hero__facts { margin: 0 0 22px; font-size: 14px; color: var(--muted); }
.actions { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 360px; margin: 0 auto; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 52px; padding: 10px 20px; border: 1px solid var(--accent); border-radius: 8px; font-weight: 600; text-align: center; text-decoration: none; line-height: 1.3; }
.btn--main { background: var(--accent); color: var(--on-accent); }
.btn--alt { color: var(--accent); }
.quote { max-width: calc(var(--measure) + var(--gutter) * 2); margin: 28px auto 0; padding: 0 var(--gutter); font-family: var(--serif); font-size: 18px; line-height: 1.75; }
.quote h2 { margin: 0 0 12px; font-family: var(--serif); font-size: 24px; font-weight: 600; }
.quote p { margin: 0 0 .9em; text-wrap: pretty; }
.quote p:last-child { margin-bottom: 0; }
.contents { max-width: calc(var(--measure) + var(--gutter) * 2); margin: 36px auto 0; }
.contents h2 { margin: 0; padding: 0 var(--gutter) 12px; font-family: var(--serif); font-size: 24px; font-weight: 600; border-bottom: 1px solid var(--line); }

/* ---------------------------------------------------------------- paper book */
.order { max-width: 34rem; margin: 0 auto; padding: 28px var(--gutter) 12px; }
.order__book { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 18px; align-items: center; margin-bottom: 26px; }
.order__book img { display: block; width: 96px; height: auto; border-radius: 2px; box-shadow: 0 6px 16px rgba(40, 50, 60, .25); }
.order h1 { margin: 0 0 6px; font-family: var(--serif); font-size: 28px; line-height: 1.2; font-weight: 600; }
.order__book p { margin: 0 0 6px; font-size: 14px; color: var(--muted); }
.order__book .order__price { margin: 0; font-size: 20px; font-weight: 600; color: var(--accent); }
.order__price span { display: block; font-size: 14px; font-weight: 400; color: var(--muted); }
.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 5px; font-size: 14px; font-weight: 600; }
.field label span { font-weight: 400; color: var(--muted); }
.field input, .field textarea { display: block; width: 100%; min-height: 48px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit; font-size: 16px; }
.field textarea { resize: vertical; }
.field input:focus-visible, .field textarea:focus-visible { outline-offset: 0; }
.field [aria-invalid="true"] { border-color: var(--accent); }
.field__error { margin: 4px 0 0; font-size: 14px; color: var(--accent); }
.field__error:empty { display: none; }
.field--trap { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.order__total { display: flex; justify-content: space-between; align-items: baseline; margin: 20px 0 12px; font-size: 15px; }
.order__total b { font-size: 22px; color: var(--accent); }
.order__problem { margin: 0 0 12px; font-size: 15px; color: var(--accent); }
.order__problem:empty { display: none; }
.order .btn { width: 100%; }
.order .btn:disabled { opacity: .6; cursor: progress; }
.pay { outline: none; }
.pay p { margin: 0 0 14px; }
.pay__qr { display: block; width: min(100%, 300px); height: auto; margin: 6px auto 8px; border-radius: 8px; background: #fff; }
.pay__link { text-align: center; font-size: 14px; }
.pay__list { margin: 0 0 16px; border-top: 1px solid var(--line); }
.pay__list div { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 10px; align-items: center; min-height: 48px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.pay__list dt { font-size: 14px; color: var(--muted); }
.pay__list dd { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.pay__list button { flex: none; min-height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 13px; font-weight: 600; }

@media (min-width: 760px) {
  :root { --gutter: 32px; }
  .hero { grid-template-columns: 260px minmax(0, 1fr); gap: 48px; align-items: center; justify-items: start; padding-top: 56px; text-align: left; }
  .hero__cover { width: 260px; }
  .actions { flex-flow: row wrap; max-width: none; margin: 0; }
  .actions .btn { flex: 0 1 auto; }
  .sheet { margin: auto; border-radius: 12px; border-bottom: 1px solid var(--line); }
  .chapter { padding-top: 64px; }
}
@media (prefers-reduced-motion: reduce) { .bar { transition: none; } }
@media print { .bar, .prog, .finish, .foot, .resume, dialog { display: none !important; } }

/* ---------------------------------------------------------------- foreword */
.chapter__sub { margin: 0 0 8px; font-family: var(--serif); font-size: 20px; line-height: 1.35; color: var(--accent); }
.sign { margin-top: 2em; text-align: right; font-size: .9em; line-height: 1.5; }
.sign p { margin: 0 0 .15em; text-wrap: balance; }

/* ---------------------------------------------------------------- connect with the author */
.connect { max-width: calc(var(--measure) + var(--gutter) * 2); margin: 32px auto 0; padding: 0 var(--gutter); }
.connect h2 { margin: 0 0 12px; font-family: var(--serif); font-size: 24px; font-weight: 600; }
.connect__links { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.connect .btn { padding: 10px 6px; font-size: 15px; white-space: nowrap; }
