/* howtolivebetter: a long reference for slow, careful readers. Legibility first.
   Literata for reading (Vietnamese and long-form tuned), Public Sans for labels, Noto Serif SC for Chinese. */
:root {
  --paper: #f4f7f4;
  --card: #ffffff;
  --ink: #15201c;
  --muted: #44534d;
  --rule: #c5d1ca;
  --chip: #e8efeb;
  --accent: #0a5a48;
  --accent-ink: #ffffff;
  --tier3: #0a5a48;
  --tier2: #2f6f5d;
  --amber: #7a4300;
  --amber-bg: #fbefd9;
  --focus: #0a5a48;
  --serif: "Literata", "Noto Serif SC", "Songti SC", "Noto Serif CJK SC", Georgia, serif;
  --sans: "Public Sans", "Noto Serif SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  --measure: 40rem;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f1613;
    --card: #16211c;
    --ink: #e9f1ed;
    --muted: #b3c2bb;
    --rule: #2f4039;
    --chip: #1f2d27;
    --accent: #6fd1b2;
    --accent-ink: #08130f;
    --tier3: #6fd1b2;
    --tier2: #4fae93;
    --amber: #f2c27a;
    --amber-bg: #33260f;
    --focus: #6fd1b2;
  }
}
* { box-sizing: border-box; }
html { font-size: 112.5%; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 1rem/1.75 var(--serif); font-optical-sizing: auto;
  overflow-wrap: break-word; word-break: normal;
}
:lang(zh), [lang="zh"] { word-break: normal; }
a { color: var(--accent); text-underline-offset: 0.18em; text-decoration-thickness: 0.08em; }
a:hover { text-decoration-thickness: 0.16em; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--accent-ink); padding: 0.6rem 1rem; z-index: 10; }
.skip:focus { left: 0; }

.top { border-bottom: 1px solid var(--rule); background: var(--card); }
.bar { max-width: 58rem; margin: 0 auto; padding: 0.7rem 1rem; display: flex; flex-wrap: wrap; gap: 0.5rem 1.4rem; align-items: baseline; font-family: var(--sans); }
.brand { font: 700 1.15rem/1.3 var(--serif); color: var(--ink); text-decoration: none; margin-right: auto; }
.bar nav { display: flex; gap: 1.2rem; }
.bar a { font-size: 0.95rem; }
.langsw { font-weight: 600; border: 1px solid var(--accent); padding: 0.1rem 0.7rem; border-radius: 999px; text-decoration: none; }

main { max-width: 58rem; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
h1, h2, h3 { line-height: 1.3; font-weight: 700; }
h1 { font-size: 1.9rem; margin: 0.4rem 0 1rem; }
h2 { font-size: 1.4rem; margin: 2rem 0 0.7rem; }
.num { font-family: var(--sans); font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 700; }

.hero h1 { font-size: 2.3rem; margin-bottom: 0.4rem; }
.hero .tag { font-size: 1.15rem; max-width: var(--measure); color: var(--muted); margin: 0 0 0.6rem; }
.progress { font-family: var(--sans); margin: 0 0 1rem; }

/* search */
.search { margin: 1.2rem 0; padding: 1rem; background: var(--card); border: 1px solid var(--rule); border-radius: 10px; font-family: var(--sans); }
.qrow { display: flex; gap: 0.5rem; }
.qrow input[type=search] { flex: 1; min-width: 0; font: inherit; font-size: 1.05rem; padding: 0.65rem 0.8rem; border: 2px solid var(--rule); border-radius: 8px; background: var(--paper); color: var(--ink); }
button, .btn { font: 600 1rem var(--sans); padding: 0.6rem 1.1rem; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-block; }
.filters { margin-top: 0.8rem; }
.filters summary { cursor: pointer; font-weight: 600; padding: 0.4rem 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(11.5rem, 1fr)); gap: 0.7rem 1rem; margin-top: 0.6rem; }
.sel { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.9rem; color: var(--muted); }
.sel select { font: inherit; font-size: 1rem; padding: 0.5rem; border: 2px solid var(--rule); border-radius: 8px; background: var(--paper); color: var(--ink); }
.chk { display: flex; align-items: center; gap: 0.5rem; font-size: 1rem; }
.chk input { width: 1.2rem; height: 1.2rem; accent-color: var(--accent); }
.count { font-family: var(--sans); font-weight: 600; }
.note { background: var(--amber-bg); color: var(--ink); border-left: 4px solid var(--amber); padding: 0.7rem 1rem; border-radius: 4px; max-width: var(--measure); }

.hits { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.8rem; }
.hit { background: var(--card); border: 1px solid var(--rule); border-radius: 10px; padding: 0.8rem 1rem; }
.hit .hl { font-weight: 700; font-size: 1.08rem; text-decoration: none; display: block; margin-bottom: 0.3rem; }
.hit .hl:hover { text-decoration: underline; }
.snip { margin: 0.4rem 0 0; color: var(--muted); font-size: 0.95rem; line-height: 1.6; }

/* contents */
.chapters, .essays { padding-left: 0; list-style: none; display: grid; gap: 0.1rem 2rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 24rem), 1fr)); }
.chapters li, .essays li { padding: 0.35rem 0; border-bottom: 1px solid var(--rule); display: flex; gap: 0.6rem; justify-content: space-between; align-items: baseline; }
.chapters a, .essays a { text-decoration: none; }
.chapters a:hover, .essays a:hover { text-decoration: underline; }
.n { font-family: var(--sans); font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.todo a { color: var(--muted); }

/* the ledger: what an item costs and gives, as labelled cells */
.ledger { list-style: none; margin: 0.4rem 0 0.3rem; padding: 0; display: flex; flex-wrap: wrap; gap: 0.4rem; font-family: var(--sans); }
.chip { background: var(--chip); border-radius: 6px; padding: 0.15rem 0.6rem; font-size: 0.9rem; line-height: 1.5; }
.chip .k { color: var(--muted); }
.chip .v { font-weight: 700; }
.chip.benefit { outline: 2px solid var(--accent); outline-offset: -2px; }
.seals { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.3rem 0; font-family: var(--sans); font-size: 0.9rem; }
.seal { border: 2px solid var(--rule); border-radius: 999px; padding: 0.05rem 0.7rem; font-weight: 600; background: var(--card); }
.seal .pips { letter-spacing: 0.08em; }
.seal.t3 { border-color: var(--tier3); color: var(--tier3); }
.seal.t2 { border-color: var(--tier2); color: var(--tier2); }
.seal.t1 { color: var(--muted); }
.seal.gA { border-color: var(--tier3); }
.seal.disputed { border-color: var(--amber); background: var(--amber-bg); color: var(--ink); }
.who { margin: 0.2rem 0; font-family: var(--sans); font-size: 0.9rem; color: var(--muted); }
.who .k { font-weight: 700; }

/* chapter */
.crumb { font-family: var(--sans); font-size: 0.9rem; color: var(--muted); margin: 0; }
.prose { max-width: var(--measure); }
.prose p, .prose li { margin: 0.7rem 0; }
.prose table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 0.95rem; line-height: 1.55; }
.prose th, .prose td { border: 1px solid var(--rule); padding: 0.4rem 0.7rem; vertical-align: top; }
.prose th { background: var(--chip); text-align: left; }
.prose blockquote { margin: 1rem 0; padding: 0.1rem 1rem; border-left: 4px solid var(--rule); color: var(--muted); }
.prose pre, .prose code { font-size: 0.9em; }
.prose pre { overflow-x: auto; }
.doc.prose { max-width: 46rem; }
.tocitems { margin: 1rem 0 2rem; font-family: var(--sans); }
.tocitems summary { cursor: pointer; font-weight: 600; padding: 0.4rem 0; }
.tocitems ol { columns: 22rem; column-gap: 2rem; padding-left: 0; list-style: none; }
.tocitems li { break-inside: avoid; padding: 0.15rem 0; line-height: 1.45; }

.item { background: var(--card); border: 1px solid var(--rule); border-left: 5px solid var(--rule); border-radius: 10px; padding: 1rem 1.1rem 0.8rem; margin: 1.4rem 0; scroll-margin-top: 1rem; }
.item:target { border-left-color: var(--accent); outline: 3px solid var(--accent); outline-offset: 2px; }
.item h3 { font-size: 1.25rem; margin: 0 0 0.3rem; }
.item .perma { text-decoration: none; }
.item .perma:hover .num { text-decoration: underline; }
.item dl { margin: 0.6rem 0 0; max-width: var(--measure); }
.f { margin: 0.9rem 0; }
.f dt { font: 700 0.85rem/1.4 var(--sans); color: var(--muted); text-transform: none; letter-spacing: 0.02em; }
.f dd { margin: 0.1rem 0 0; }
.f dd p { margin: 0.3rem 0; }
.f-plain { background: var(--chip); border-radius: 8px; padding: 0.6rem 0.9rem; }
.f-plain dd { font-size: 1.05rem; }
.f-sources { margin: 0.6rem 0; font-size: 0.92rem; line-height: 1.6; max-width: var(--measure); }
.f-sources summary { cursor: pointer; font: 700 0.9rem var(--sans); color: var(--muted); padding: 0.3rem 0; }
.srcs { padding-left: 1.3rem; margin: 0.3rem 0; }
.srcs li { margin: 0.4rem 0; overflow-wrap: anywhere; }
.itemsw { margin: 0.3rem 0 0; font: 0.9rem var(--sans); text-align: right; }
a.ext { overflow-wrap: anywhere; }
.pn { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.8rem; margin: 2rem 0 0; font-family: var(--sans); }
.pn a { max-width: 100%; }

.stub { max-width: var(--measure); }
.stub .note { margin: 1rem 0; }

/* the notice that closes every page */
.notice { border-top: 2px solid var(--rule); background: var(--card); padding: 1.2rem 1rem 2rem; font: 0.9rem/1.65 var(--sans); }
.notice > p { max-width: 58rem; margin: 0.4rem auto; }
.notice .pub { color: var(--muted); }

#toast { position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%); background: var(--ink); color: var(--paper); font: 600 0.95rem var(--sans); padding: 0.5rem 1rem; border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
#toast.on { opacity: 1; }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

@media (max-width: 40rem) {
  html { font-size: 106.25%; }
  h1 { font-size: 1.6rem; }
  .hero h1 { font-size: 1.9rem; }
  .item { padding: 0.8rem 0.8rem 0.6rem; border-left-width: 4px; }
  .qrow { flex-direction: column; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chapters, .essays { grid-template-columns: 1fr; }
}
@media print { .top, .search, #toast, .itemsw { display: none; } .item { break-inside: avoid; } .f-sources[open] { display: block; } }

/* The book's "national" words do not mean the reader's country: said before anything else on the page. */
.scope { margin: 0 0 1.25rem; padding: .6rem .8rem; border-left: 3px solid currentColor; font-size: .95rem; line-height: 1.5; }
