/* ---------- Tokens (from the original book) ---------- */
:root {
  --bg: #faf7f2; --surface: #ffffff; --surface-2: #f3eee6; --text: #221d17; --muted: #6d6358; --faint: #9a8f82;
  --border: #e6ddd0; --accent: #c2410c; --accent-ink: #9a3412; --accent-soft: #fdeee2; --es: #8a3412;
  --good: #15803d; --good-soft: #e8f5ec; --bad: #b91c1c; --bad-soft: #fbecec; --info: #1d5f8f; --info-soft: #e8f1f8;
  --amber: #a16207; --amber-soft: #fbf3df; --lvl-a: #2f7d55; --lvl-b: #2563a8; --lvl-c: #7444b8;
  --shadow: 0 1px 2px rgba(60,40,20,.06), 0 4px 16px rgba(60,40,20,.06);
  --serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15120e; --surface: #1d1914; --surface-2: #26211a; --text: #ece4d8; --muted: #b0a493; --faint: #7f7466;
    --border: #353027; --accent: #f08a4b; --accent-ink: #f6a877; --accent-soft: #3a2518; --es: #f3b98f;
    --good: #5fc98a; --good-soft: #17291e; --bad: #f07a7a; --bad-soft: #321a1a; --info: #7db8e3; --info-soft: #172634;
    --amber: #e3b45c; --amber-soft: #2e2615; --lvl-a: #5fc98a; --lvl-b: #6aa6ea; --lvl-c: #b394ec;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15120e; --surface: #1d1914; --surface-2: #26211a; --text: #ece4d8; --muted: #b0a493; --faint: #7f7466;
  --border: #353027; --accent: #f08a4b; --accent-ink: #f6a877; --accent-soft: #3a2518; --es: #f3b98f;
  --good: #5fc98a; --good-soft: #17291e; --bad: #f07a7a; --bad-soft: #321a1a; --info: #7db8e3; --info-soft: #172634;
  --amber: #e3b45c; --amber-soft: #2e2615; --lvl-a: #5fc98a; --lvl-b: #6aa6ea; --lvl-c: #b394ec;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25); color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 120px; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 17px; line-height: 1.6; }
a { color: var(--accent-ink); text-decoration-thickness: 1px; text-underline-offset: 3px; }
button { font: inherit; color: inherit; }
.i { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: #fff; padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; top: 8px; }
.muted { color: var(--muted); }

/* ---------- Header ---------- */
.site-head { position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.head-row { max-width: 1200px; margin: 0 auto; padding: 10px 16px 4px; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); min-width: 0; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; background: var(--accent); color: #fff; display: grid; place-items: center; font-family: var(--serif); font-size: 1.25rem; font-weight: 700; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: 1rem; }
.brand-text small { color: var(--muted); font-size: .75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-actions { margin-left: auto; display: flex; gap: 4px; }
.icon-btn { background: none; border: 1px solid transparent; border-radius: 9px; padding: 8px; cursor: pointer; color: var(--muted); display: grid; place-items: center; font-size: .75rem; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.top-nav { max-width: 1200px; margin: 0 auto; padding: 2px 12px 8px; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; font-size: .88rem; }
.top-nav::-webkit-scrollbar { display: none; }
.top-nav a { padding: 4px 10px; border-radius: 99px; text-decoration: none; color: var(--muted); white-space: nowrap; }
.top-nav a:hover { color: var(--text); background: var(--surface-2); }
.top-nav a[aria-current] { color: var(--accent-ink); background: var(--accent-soft); font-weight: 600; }

/* ---------- Layout ---------- */
.wrap { max-width: 1200px; margin: 0 auto; padding: 20px 16px 40px; }
.main { min-width: 0; outline: none; }
.no-side .main { max-width: 820px; margin: 0 auto; }
@media (min-width: 1000px) {
  .with-side { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 48px; }
  .with-side .main { max-width: 780px; }
  .side { position: sticky; top: 110px; align-self: start; max-height: calc(100vh - 130px); overflow-y: auto; }
}
@media (max-width: 999px) { .side { margin-top: 32px; border-top: 1px solid var(--border); padding-top: 20px; } }

/* ---------- Breadcrumbs, headings ---------- */
.crumbs ol { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-wrap: wrap; gap: 4px; font-size: .82rem; color: var(--muted); }
.crumbs li + li::before { content: "›"; margin-right: 4px; color: var(--faint); }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent-ink); text-decoration: underline; }
.page-head { margin-bottom: 18px; }
.kicker { margin: 0 0 6px; font-size: .85rem; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.kicker a { color: var(--muted); }
h1 { font-family: var(--serif); font-size: clamp(1.7rem, 4vw, 2.4rem); line-height: 1.15; margin: 0 0 8px; letter-spacing: -.01em; text-wrap: balance; }
h2 { font-family: var(--serif); font-size: 1.45rem; line-height: 1.25; margin: 1.8em 0 .5em; text-wrap: balance; }
h3 { font-size: 1.08rem; margin: 1.4em 0 .4em; }
.lead { font-size: 1.12rem; color: var(--muted); margin: 6px 0 0; }
.lvl { display: inline-block; font: 700 .72rem/1 var(--sans); padding: 4px 7px; border-radius: 6px; color: #fff; letter-spacing: .03em; }
.lvl-a { background: var(--lvl-a); } .lvl-b { background: var(--lvl-b); } .lvl-c { background: var(--lvl-c); }
:root[data-theme="dark"] .lvl { color: #15120e; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .lvl { color: #15120e; } }

/* ---------- Prose ---------- */
.prose { font-family: var(--serif); font-size: 1.06rem; line-height: 1.7; }
.prose h2, .prose h3 { font-family: var(--serif); }
.prose em { color: var(--es); }
.prose strong em, .prose em strong { color: var(--accent-ink); }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li { margin: .3em 0; }
.prose code { font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.prose blockquote { margin: 1.3em 0; padding: 14px 18px; background: var(--accent-soft); border-left: 4px solid var(--accent); border-radius: 0 10px 10px 0; }
.prose blockquote p { margin: 0; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }
.lede { font-size: 1.12rem; }
.x-bad { color: var(--bad); font-weight: 700; font-family: var(--sans); }
.x-good { color: var(--good); font-weight: 700; font-family: var(--sans); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 1.2em 0 1.5em; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: .9rem; line-height: 1.45; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-weight: 650; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td[data-align="center"], th[data-align="center"] { text-align: center; }
td[data-align="right"], th[data-align="right"] { text-align: right; }

/* ---------- Boxes ---------- */
.box { margin: 2em 0; padding: 18px 20px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.box-title { display: flex; align-items: center; gap: 9px; margin: 0 0 10px; font-size: 1.2rem; }
.box ul, .box ol { font-family: var(--serif); }
.box em { color: var(--es); }
.sec-watch { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.sec-watch .box-title { color: var(--bad); }
.sec-listen { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.sec-listen .box-title { color: var(--info); }
.sec-examples { background: var(--amber-soft); border-color: color-mix(in srgb, var(--amber) 25%, transparent); }
.sec-examples .box-title { color: var(--amber); }
.sec-practice .box-title { color: var(--good); }
.practice { padding-left: 1.4em; }
.practice > li { margin: 0 0 14px; }
.practice .q p { margin: 0 0 6px; }
.reveal summary { cursor: pointer; display: inline-block; font: 600 .82rem var(--sans); color: var(--accent-ink); background: var(--accent-soft); padding: 4px 10px; border-radius: 99px; list-style: none; }
.reveal summary::-webkit-details-marker { display: none; }
.reveal[open] summary { background: var(--good-soft); color: var(--good); }
.reveal-body { margin-top: 8px; padding: 10px 14px; border-left: 3px solid var(--good); background: var(--good-soft); border-radius: 0 8px 8px 0; }
.reveal-body p { margin: 0; }
.more-practice { font-size: .92rem; margin: 6px 0 0; color: var(--muted); }

/* ---------- FAQ, related, cards ---------- */
.faq-item { border-top: 1px solid var(--border); padding: 4px 0 8px; }
.faq-item h3 { font-family: var(--sans); }
.faq-item p { margin: .3em 0; }
.cards { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.card { display: flex; flex-direction: column; gap: 4px; height: 100%; padding: 14px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); text-decoration: none; color: var(--text); transition: border-color .15s, transform .15s; }
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card strong { font-size: .98rem; line-height: 1.3; }
.card span { color: var(--muted); font-size: .86rem; line-height: 1.45; }
.card .tag { font: 700 .72rem var(--sans); color: var(--accent-ink); letter-spacing: .04em; }
.related h2 { font-size: 1.25rem; }

/* ---------- Prev / next ---------- */
.pn { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 36px 0 0; }
.pn a { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); text-decoration: none; color: var(--text); font-weight: 600; font-size: .92rem; line-height: 1.35; }
.pn a:hover { border-color: var(--accent); }
.pn small { display: block; font-weight: 400; color: var(--muted); font-size: .78rem; }
.pn-next { justify-content: flex-end; text-align: right; grid-column: 2; }
@media (max-width: 560px) { .pn { grid-template-columns: 1fr; } .pn-next { grid-column: 1; } }

/* ---------- Side TOC ---------- */
.toc { font-size: .88rem; }
.toc-head { font-weight: 700; margin: 0 0 8px; }
.toc-head a { color: var(--text); text-decoration: none; }
.toc ol { list-style: none; padding: 0; margin: 0; }
.toc li a { display: flex; gap: 8px; padding: 6px 8px; border-radius: 7px; color: var(--muted); text-decoration: none; line-height: 1.35; }
.toc li a:hover { background: var(--surface-2); color: var(--text); }
.toc li a[aria-current] { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.num { font: 600 .76rem/1.6 var(--sans); color: var(--faint); min-width: 2.4em; flex: none; }

/* ---------- Level hub ---------- */
.ch-block { border-top: 1px solid var(--border); padding-top: 4px; }
.ch-block h2 { font-size: 1.3rem; margin-top: 1.2em; }
.ch-block h2 a { color: var(--text); text-decoration: none; }
.ch-block h2 a:hover { color: var(--accent-ink); }
.lesson-list { list-style: none; padding: 0; columns: 2 280px; column-gap: 24px; }
.lesson-list a { display: flex; gap: 6px; padding: 3px 0; text-decoration: none; break-inside: avoid; }
.lesson-list a:hover { text-decoration: underline; }

/* ---------- Home ---------- */
.hero { padding: 28px 0 8px; }
.hero h1 { font-size: clamp(2rem, 5vw, 3rem); max-width: 18ch; }
.hero .lead { max-width: 60ch; }
.hero-cta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.btn { display: inline-block; padding: 11px 18px; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 600; text-decoration: none; }
.btn:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--accent-ink); border: 1px solid var(--border); }
:root[data-theme="dark"] .btn:not(.btn-ghost) { color: #15120e; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn:not(.btn-ghost) { color: #15120e; } }
.levels { list-style: none; padding: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.level-card { display: flex; flex-direction: column; gap: 6px; padding: 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); text-decoration: none; color: var(--text); box-shadow: var(--shadow); }
.level-card:hover { border-color: var(--accent); }
.level-card .lvl { align-self: flex-start; }
.level-card span:last-child { color: var(--muted); font-size: .86rem; }

/* ---------- Guides ---------- */
.guide-toc { border: 1px solid var(--border); border-radius: 12px; padding: 12px 18px; background: var(--surface); font-size: .92rem; margin-bottom: 20px; }
.guide-toc p { margin: 0 0 4px; font-weight: 700; }
.guide-toc ol { margin: 0; padding-left: 1.3em; columns: 2 220px; }

/* ---------- Vocabulary quiz ---------- */
.quiz-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 10px 0 0; font-size: .86rem; color: var(--muted); }
.quiz-bar button { border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 4px 12px; cursor: pointer; }
.quiz-bar button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.quizzing td.qhide { color: transparent; background: var(--surface-2); cursor: pointer; }
.quizzing td.qhide * { color: transparent !important; }
.quizzing tr.shown td.qhide { color: inherit; background: var(--good-soft); }
.quizzing tr.shown td.qhide * { color: inherit !important; }

/* ---------- Ads ---------- */
.ad { margin: 28px 0; min-height: 100px; text-align: center; }
.ad-sidebar { margin-top: 24px; min-height: 250px; }
.ad-demo { display: grid; place-items: center; border: 2px dashed var(--border); border-radius: 12px; color: var(--faint); font-size: .8rem; }
@media (max-width: 999px) { .ad-sidebar { display: none; } }

/* ---------- Search ---------- */
.search-modal { position: fixed; inset: 0; z-index: 60; background: rgba(20,14,8,.45); display: flex; justify-content: center; align-items: flex-start; padding: 10vh 16px 16px; }
.search-panel { width: 100%; max-width: 620px; background: var(--surface); border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.3); overflow: hidden; }
.search-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); color: var(--muted); }
.search-row input { flex: 1; border: 0; background: none; font: inherit; font-size: 1.05rem; color: var(--text); outline: none; padding: 6px 0; min-width: 0; }
.search-results { max-height: 60vh; overflow-y: auto; }
.search-results a { display: block; padding: 10px 16px; border-bottom: 1px solid var(--border); text-decoration: none; color: var(--text); }
.search-results a:hover, .search-results a.sel { background: var(--accent-soft); }
.search-results small { display: block; color: var(--muted); font-size: .8rem; }
.search-results .empty { padding: 16px; color: var(--muted); }

/* ---------- Footer ---------- */
.site-foot { border-top: 1px solid var(--border); background: var(--surface); padding: 28px 16px 36px; font-size: .9rem; }
.foot-grid { max-width: 1200px; margin: 0 auto; display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.site-foot h2 { font-family: var(--sans); font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.site-foot ul { list-style: none; padding: 0; margin: 0; }
.site-foot li { margin: 4px 0; }
.site-foot a { color: var(--text); text-decoration: none; }
.site-foot a:hover { color: var(--accent-ink); text-decoration: underline; }
.foot-note { max-width: 1200px; margin: 22px auto 0; color: var(--muted); font-size: .8rem; }

@media print { .site-head, .side, .ad, .pn, .site-foot, .related { display: none !important; } .reveal-body { display: block; } }
