/* ExzLearn — reading-first design. Tokens at top, components below. */

:root {
  --bg: #faf9f6;
  --surface: #ffffff;
  --surface-2: #f3f1ec;
  --ink: #1c1f23;
  --ink-2: #3f454d;
  --muted: #6b7079;
  --line: #e7e3db;
  --brand: #0f766e;
  --brand-ink: #0b5e58;
  --brand-soft: #e5f3f0;
  --on-brand: #ffffff;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --bad: #be123c;
  --bad-soft: #fde8ec;
  --t0: #0f766e; --t0-soft: #e5f3f0;
  --t1: #b45309; --t1-soft: #fdf1e3;
  --t2: #6d28d9; --t2-soft: #f1ebfd;
  --t3: #be185d; --t3-soft: #fce9f2;
  --code-bg: #f6f4ef;
  --shadow: 0 1px 2px rgba(20, 20, 15, .04), 0 4px 16px rgba(20, 20, 15, .05);
  --radius: 14px;
  --font: "IBM Plex Sans Thai", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  --topbar: 60px;
  --cat: var(--brand);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1214; --surface: #161a1d; --surface-2: #1c2125; --ink: #ebe8e3; --ink-2: #c7cacd; --muted: #8d949b; --line: #2a3035;
    --brand: #2dd4bf; --brand-ink: #5eead4; --brand-soft: rgba(45, 212, 191, .12); --on-brand: #06201d;
    --ok: #4ade80; --ok-soft: rgba(74, 222, 128, .12); --bad: #fb7185; --bad-soft: rgba(251, 113, 133, .12);
    --t0: #2dd4bf; --t0-soft: rgba(45, 212, 191, .11);
    --t1: #fbbf24; --t1-soft: rgba(251, 191, 36, .11);
    --t2: #a78bfa; --t2-soft: rgba(167, 139, 250, .12);
    --t3: #f472b6; --t3-soft: rgba(244, 114, 182, .11);
    --code-bg: #12161a; --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: #0f1214; --surface: #161a1d; --surface-2: #1c2125; --ink: #ebe8e3; --ink-2: #c7cacd; --muted: #8d949b; --line: #2a3035;
  --brand: #2dd4bf; --brand-ink: #5eead4; --brand-soft: rgba(45, 212, 191, .12); --on-brand: #06201d;
  --ok: #4ade80; --ok-soft: rgba(74, 222, 128, .12); --bad: #fb7185; --bad-soft: rgba(251, 113, 133, .12);
  --t0: #2dd4bf; --t0-soft: rgba(45, 212, 191, .11);
  --t1: #fbbf24; --t1-soft: rgba(251, 191, 36, .11);
  --t2: #a78bfa; --t2-soft: rgba(167, 139, 250, .12);
  --t3: #f472b6; --t3-soft: rgba(244, 114, 182, .11);
  --code-bg: #12161a; --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: calc(var(--topbar) + 16px); }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 17px; line-height: 1.7;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  min-height: 100vh; display: flex; flex-direction: column;
}
main { flex: 1; }
a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3, h4 { line-height: 1.35; font-weight: 700; letter-spacing: -.005em; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
kbd { font-family: var(--mono); font-size: .72rem; padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; color: var(--muted); background: var(--surface); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }
.skip { position: absolute; left: -999px; top: 8px; background: var(--brand); color: var(--on-brand); padding: 8px 14px; border-radius: 8px; z-index: 100; }
.skip:focus { left: 8px; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.wrap.narrow { max-width: 820px; padding-top: 28px; padding-bottom: 56px; }
.center { text-align: center; }
.eyebrow { font-size: .8rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--brand-ink); margin: 0 0 .5rem; }
.lead { font-size: 1.1rem; color: var(--ink-2); margin: .4rem 0 0; }

/* ---------- Buttons / badges ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 500; font-size: .95rem; color: var(--ink); text-decoration: none !important; transition: background .15s, border-color .15s, color .15s; }
.btn svg { width: 18px; height: 18px; }
.btn:hover { border-color: var(--brand); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-ink); }
.btn.is-on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-ink); }
.btn.is-on svg { fill: currentColor; }
.btn-primary.is-on { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.icon-btn { position: relative; display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; color: var(--ink-2); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.icon-btn .count { position: absolute; top: 3px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--brand); color: var(--on-brand); font-size: .68rem; font-weight: 700; line-height: 18px; text-align: center; }
.badge { display: inline-block; font-size: .78rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: var(--t0-soft); color: var(--t0); white-space: nowrap; }
.badge.level-intermediate { background: var(--t1-soft); color: var(--t1); }
.badge.level-advanced { background: var(--t3-soft); color: var(--t3); }
.tag { font-size: .85rem; color: var(--muted); background: var(--surface-2); padding: 2px 10px; border-radius: 999px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Top bar ---------- */
.read-progress { position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 60; pointer-events: none; }
.read-progress span { display: block; height: 100%; width: 0; background: var(--cat); transition: width .1s linear; }
.topbar { position: sticky; top: 0; z-index: 50; height: var(--topbar); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--line); }
.topbar-inner { height: 100%; max-width: 1440px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none !important; font-size: 1.15rem; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--brand); color: var(--on-brand); font-weight: 700; font-size: 1.05rem; }
.brand-name { font-weight: 500; }
.brand-name b { font-weight: 700; color: var(--brand-ink); }
.search-trigger { margin-left: auto; display: flex; align-items: center; gap: 10px; width: min(340px, 40vw); padding: 7px 10px 7px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--muted); cursor: pointer; font-size: .92rem; }
.search-trigger:hover { border-color: var(--brand); }
.search-trigger span { flex: 1; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 2px; }

/* ---------- Home ---------- */
.hero { padding: 72px 0 48px; background: radial-gradient(1000px 360px at 50% -80px, var(--brand-soft), transparent 70%); text-align: center; }
.hero h1 { font-size: clamp(2.2rem, 5.5vw, 3.6rem); margin: 0; line-height: 1.25; }
.hero .accent { color: var(--brand-ink); }
.hero .lead { max-width: 620px; margin: 18px auto 0; }
.hero-search { margin: 30px auto 0; display: flex; align-items: center; gap: 12px; width: min(560px, 100%); padding: 14px 16px 14px 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); color: var(--muted); cursor: pointer; font-size: 1.05rem; }
.hero-search:hover { border-color: var(--brand); }
.hero-search span { flex: 1; text-align: left; }
.hero-stats { margin: 18px 0 0; color: var(--muted); font-size: .95rem; }
.hero-stats b { color: var(--ink); }
.block { margin: 48px 0; }
.section-title { font-size: 1.35rem; margin: 0 0 16px; }
.continue { margin-top: 8px; }
.continue-label { font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.continue-link { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-radius: var(--radius); background: var(--brand-soft); border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent); color: var(--ink); text-decoration: none !important; }
.continue-link strong { font-size: 1.05rem; }
.continue-link .muted { flex: 1; }
.continue-link svg { color: var(--brand-ink); }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; }
.cat-card { display: flex; flex-direction: column; gap: 6px; padding: 20px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); color: var(--ink); text-decoration: none !important; transition: transform .15s, border-color .15s, box-shadow .15s; position: relative; overflow: hidden; }
.cat-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--cat); }
.cat-card:hover { transform: translateY(-2px); border-color: var(--cat); box-shadow: var(--shadow); }
.cat-icon { font-size: 1.8rem; line-height: 1; }
.cat-icon.big { font-size: 2.8rem; }
.cat-title { font-weight: 700; font-size: 1.15rem; margin-top: 6px; }
.cat-desc { color: var(--ink-2); font-size: .95rem; flex: 1; }
.cat-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; font-size: .85rem; color: var(--muted); }
.cat-progress { display: block; width: 90px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.cat-progress.wide { width: 200px; }
.cat-progress span { display: block; height: 100%; width: 0; background: var(--cat); border-radius: 3px; transition: width .4s; }

/* ---------- Lesson lists ---------- */
.lesson-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.lesson-row { display: flex; align-items: center; gap: 16px; padding: 16px 18px; color: var(--ink); text-decoration: none !important; border-top: 1px solid var(--line); }
.lesson-row:first-child { border-top: 0; }
.lesson-row:hover { background: var(--surface-2); }
.lesson-idx { position: relative; flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: .9rem; }
.tick { display: none; }
.is-read .lesson-idx, .is-read .side-idx { background: var(--ok-soft); color: transparent; }
.is-read .tick { display: grid; place-items: center; position: absolute; inset: 0; color: var(--ok); }
.is-read .tick svg { width: 16px; height: 16px; stroke-width: 3; }
.lesson-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lesson-row-main strong { font-weight: 600; font-size: 1.05rem; }
.lesson-row-main .muted { font-size: .92rem; }
.lesson-row-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: .85rem; flex: none; }

/* ---------- Category / page heads ---------- */
.crumbs { display: flex; flex-wrap: wrap; gap: 8px; font-size: .88rem; color: var(--muted); margin-bottom: 14px; }
.crumbs a { color: var(--muted); }
.cat-head { display: flex; gap: 20px; align-items: flex-start; margin-bottom: 28px; }
.cat-head h1, .page-head h1 { margin: 0; font-size: clamp(1.8rem, 4vw, 2.4rem); }
.cat-meter { display: flex; align-items: center; gap: 12px; margin-top: 14px; font-size: .9rem; }
.page-head { margin-bottom: 24px; }
.page-actions { display: flex; gap: 8px; margin-top: 16px; }

/* ---------- Lesson layout ---------- */
.lesson-layout { display: grid; grid-template-columns: 250px minmax(0, 46rem) 220px; gap: 48px; justify-content: center; max-width: 1440px; margin: 0 auto; padding: 32px 24px 64px; }
.sidebar, .toc-wrap { position: sticky; top: calc(var(--topbar) + 24px); align-self: start; max-height: calc(100vh - var(--topbar) - 48px); overflow-y: auto; }
.side-cat { display: flex; gap: 8px; align-items: center; font-weight: 700; color: var(--ink); margin-bottom: 12px; font-size: 1rem; }
.side-list { list-style: none; margin: 0; padding: 0; }
.side-list a { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 10px; color: var(--ink-2); font-size: .93rem; line-height: 1.5; text-decoration: none !important; }
.side-list a:hover { background: var(--surface-2); color: var(--ink); }
.side-list a[aria-current="page"] { background: color-mix(in srgb, var(--cat) 12%, transparent); color: var(--ink); font-weight: 600; }
.side-idx { position: relative; flex: none; width: 22px; height: 22px; margin-top: 1px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-size: .75rem; font-weight: 600; }
.side-idx .tick svg { width: 13px; height: 13px; }
.toc-title { font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.toc li a { display: block; padding: 5px 0 5px 14px; margin-left: -2px; border-left: 2px solid transparent; color: var(--muted); font-size: .88rem; line-height: 1.5; text-decoration: none !important; }
.toc li.d3 a { padding-left: 26px; font-size: .84rem; }
.toc li a:hover { color: var(--ink); }
.toc li a.active { color: var(--cat); border-left-color: var(--cat); font-weight: 600; }

.lesson-title { font-size: clamp(1.9rem, 4.2vw, 2.6rem); margin: 0; }
.lesson-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin: 20px 0 8px; padding-bottom: 20px; border-bottom: 1px solid var(--line); font-size: .9rem; }
.meta-item { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.meta-item svg { width: 16px; height: 16px; }
.spacer { flex: 1; }

/* ---------- Prose (reading text) ---------- */
.prose { font-size: 1.125rem; line-height: 1.85; color: var(--ink); }
.prose > * + * { margin-top: 1.1em; }
.prose p { margin: 0; }
.prose p + p { margin-top: 1em; }
.prose h2 { font-size: 1.55rem; margin: 2.4em 0 .6em; padding-top: .2em; position: relative; display: flex; align-items: center; gap: 8px; }
.prose h3 { font-size: 1.22rem; margin: 1.8em 0 .4em; }
.prose h2 .hlink, .prose h3 .hlink { color: inherit; text-decoration: none; }
.prose h2 .hlink:hover::after, .prose h3 .hlink:hover::after { content: " #"; color: var(--muted); font-weight: 400; }
.hbm { flex: none; display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; opacity: .35; transition: opacity .15s, background .15s, color .15s; }
.hbm svg { width: 18px; height: 18px; }
.prose h2:hover .hbm, .hbm:focus-visible, .hbm.is-on { opacity: 1; }
.hbm:hover { background: var(--surface-2); color: var(--ink); }
.hbm.is-on { color: var(--cat); }
.hbm.is-on svg { fill: currentColor; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li + li { margin-top: .35em; }
.prose li::marker { color: var(--muted); }
.prose strong { font-weight: 700; }
.prose blockquote { margin-left: 0; margin-right: 0; padding: .2em 0 .2em 1.1em; border-left: 3px solid var(--line); color: var(--ink-2); }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2.4em 0; }
.prose img { max-width: 100%; height: auto; border-radius: 12px; }
.prose :not(pre) > code { font-family: var(--mono); font-size: .86em; padding: .12em .4em; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); word-break: break-word; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.prose table { width: 100%; border-collapse: collapse; font-size: .98rem; line-height: 1.6; }
.prose th, .prose td { padding: 10px 14px; text-align: left; border-top: 1px solid var(--line); vertical-align: top; }
.prose thead th { border-top: 0; background: var(--surface-2); font-weight: 600; }

/* Code blocks */
.code { border: 1px solid var(--line); border-radius: 12px; background: var(--code-bg); overflow: hidden; }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px 6px 14px; border-bottom: 1px solid var(--line); font-size: .78rem; color: var(--muted); font-family: var(--mono); }
.code-copy { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 2px 8px; border-radius: 6px; font-family: var(--font); font-size: .8rem; }
.code-copy:hover { background: var(--surface-2); color: var(--ink); }
.code pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
.code code { font-family: var(--mono); font-size: .88rem; line-height: 1.7; }
.diagram { padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow-x: auto; text-align: center; }
.diagram pre { margin: 0; }

/* highlight.js tokens */
.hljs-comment, .hljs-quote { color: var(--muted); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-meta .hljs-keyword { color: var(--t2); }
.hljs-string, .hljs-attr-value, .hljs-regexp, .hljs-addition { color: var(--ok); }
.hljs-number, .hljs-literal, .hljs-symbol, .hljs-bullet { color: var(--t1); }
.hljs-title, .hljs-title.function_, .hljs-section { color: var(--t0); }
.hljs-attr, .hljs-attribute, .hljs-variable, .hljs-template-variable, .hljs-property { color: var(--t3); }
.hljs-type, .hljs-class .hljs-title, .hljs-title.class_ { color: var(--t1); }
.hljs-deletion { color: var(--bad); }
.hljs-meta { color: var(--muted); }

/* ---------- INFO blocks ---------- */
.keypoints { padding: 18px 22px; border-radius: var(--radius); background: color-mix(in srgb, var(--cat) 8%, var(--surface)); border: 1px solid color-mix(in srgb, var(--cat) 28%, transparent); }
.keypoints-title { font-weight: 700; color: var(--cat); margin-bottom: 6px; font-size: 1rem; }
.keypoints ul { margin: 0; }
.keypoints p { margin: 0; }

.callout { padding: 14px 18px; border-radius: 12px; border-left: 4px solid var(--t0); background: var(--t0-soft); }
.callout-title { font-weight: 700; font-size: .98rem; margin-bottom: 2px; }
.callout-body > * { margin: 0; }
.callout-body > * + * { margin-top: .6em; }
.callout-tip { border-color: var(--t0); background: var(--t0-soft); }
.callout-info, .callout-note { border-color: var(--t2); background: var(--t2-soft); }
.callout-warning { border-color: var(--t1); background: var(--t1-soft); }
.callout-danger { border-color: var(--bad); background: var(--bad-soft); }
.callout-example { border-color: var(--t3); background: var(--t3-soft); }

.info { margin-left: 0; margin-right: 0; padding: 0; }
.info-caption { font-size: .85rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }

.flow-track { display: flex; align-items: stretch; gap: 0; padding: 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); overflow-x: auto; }
.flow-node { flex: 1 1 0; min-width: 120px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; padding: 14px 10px; border-radius: 12px; background: color-mix(in srgb, var(--cat) 8%, var(--surface)); border: 1px solid color-mix(in srgb, var(--cat) 25%, transparent); line-height: 1.45; }
.flow-node strong { font-size: 1rem; }
.flow-node small { font-size: .82rem; color: var(--ink-2); }
.flow-idx { width: 24px; height: 24px; border-radius: 50%; background: var(--cat); color: var(--on-brand); display: grid; place-items: center; font-size: .75rem; font-weight: 700; }
.flow-arrow { flex: 0 0 28px; position: relative; align-self: center; height: 2px; background: var(--muted); margin: 0 4px; }
.flow-arrow::after { content: ""; position: absolute; right: -1px; top: -5px; border: 6px solid transparent; border-left: 8px solid var(--muted); border-right: 0; }

.info-steps ol { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0; }
.info-steps li { display: flex; gap: 16px; position: relative; padding-bottom: 18px; margin: 0; }
.info-steps li:not(:last-child)::before { content: ""; position: absolute; left: 17px; top: 38px; bottom: 2px; width: 2px; background: var(--line); }
.step-num { flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--cat); color: var(--on-brand); font-weight: 700; z-index: 1; }
.step-body { flex: 1; min-width: 0; padding: 10px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.step-body > * { margin: 0; }
.step-body > * + * { margin-top: .5em; }
.step-body p { line-height: 1.7; }

.info-grid { display: grid; gap: 14px; }
.info-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.info-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.info-card { border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); overflow: hidden; }
.info-card-title { padding: 10px 16px; font-weight: 700; font-size: 1.02rem; }
.info-card-body { padding: 12px 16px 14px; font-size: 1rem; line-height: 1.7; }
.info-card-body > * { margin: 0; }
.info-card-body > * + * { margin-top: .5em; }
.info-card-body ul { padding-left: 1.2em; }
.tone-0 .info-card-title { background: var(--t0-soft); color: var(--t0); }
.tone-1 .info-card-title { background: var(--t1-soft); color: var(--t1); }
.tone-2 .info-card-title { background: var(--t2-soft); color: var(--t2); }
.tone-3 .info-card-title { background: var(--t3-soft); color: var(--t3); }
.is-compare .info-grid.cols-2 { position: relative; column-gap: 44px; }
.is-compare .info-grid.cols-2::after { content: "VS"; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--ink); color: var(--bg); font-size: .72rem; font-weight: 700; letter-spacing: .04em; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { padding: 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); }
.stat-num { font-size: 1.8rem; font-weight: 700; line-height: 1.2; }
.stat.tone-0 .stat-num { color: var(--t0); }
.stat.tone-1 .stat-num { color: var(--t1); }
.stat.tone-2 .stat-num { color: var(--t2); }
.stat.tone-3 .stat-num { color: var(--t3); }
.stat-label { font-size: .92rem; color: var(--ink-2); line-height: 1.5; margin-top: 4px; }

.term { margin: 0; padding: 12px 16px; border-radius: 12px; border: 1px dashed var(--line); }
.term dt { font-weight: 700; font-family: var(--mono); font-size: .95rem; color: var(--cat); }
.term dd { margin: 4px 0 0; }

/* 3D animation figure */
.anim { margin-left: 0; margin-right: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.anim-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 12px 16px 0; }
.anim-title { font-weight: 700; font-size: 1.02rem; }
.anim-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
.anim-chip { font-size: .78rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: color-mix(in srgb, var(--cat) 12%, transparent); color: var(--cat); white-space: nowrap; }
.anim-stage { position: relative; height: 360px; margin: 8px 12px 0; border-radius: 12px; background: radial-gradient(ellipse at 50% 35%, var(--surface) 0%, var(--surface-2) 100%); cursor: grab; touch-action: pan-y; }
.anim-stage:active { cursor: grabbing; }
.anim-stage canvas { display: block; width: 100% !important; height: 100% !important; border-radius: 12px; }
.anim-fallback { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: .95rem; }
.anim-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 10px 16px; font-size: .88rem; }
.anim-btn { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 3px 12px; cursor: pointer; font-size: .85rem; color: var(--ink); }
.anim-btn:hover { border-color: var(--cat); }
.anim-readout { font-family: var(--mono); font-size: .8rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.anim-hint { margin-left: auto; color: var(--muted); font-size: .8rem; }
.anim-body { padding: 0 16px 14px; font-size: 1rem; line-height: 1.75; color: var(--ink-2); }
.anim-body > * { margin: 0; }
.anim-body > * + * { margin-top: .5em; }

/* Quiz */
.quiz { padding: 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.quiz-head { margin-bottom: 12px; }
.quiz-badge { display: inline-block; font-size: .75rem; font-weight: 700; color: var(--t2); background: var(--t2-soft); padding: 2px 10px; border-radius: 999px; }
.quiz-q { font-weight: 600; font-size: 1.08rem; margin-top: 8px; line-height: 1.6; }
.quiz-opts { display: flex; flex-direction: column; gap: 8px; }
.quiz-opt { display: flex; align-items: flex-start; gap: 12px; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; text-align: left; line-height: 1.55; font-size: 1rem; transition: border-color .15s, background .15s; }
.quiz-opt:hover:not(:disabled) { border-color: var(--brand); }
.quiz-opt:disabled { cursor: default; }
.quiz-letter { flex: none; width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; background: var(--surface-2); font-size: .8rem; font-weight: 700; margin-top: 1px; }
.quiz-opt.is-correct { border-color: var(--ok); background: var(--ok-soft); }
.quiz-opt.is-correct .quiz-letter { background: var(--ok); color: var(--surface); }
.quiz-opt.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.quiz-opt.is-wrong .quiz-letter { background: var(--bad); color: var(--surface); }
.quiz-exp { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); font-size: 1rem; line-height: 1.7; }
.quiz-exp > * { margin: 0; }
.quiz-exp::before { content: attr(data-verdict); display: block; font-weight: 700; margin-bottom: 4px; }
.quiz-exp.ok::before { color: var(--ok); }
.quiz-exp.bad::before { color: var(--bad); }

/* Finish + pager */
.finish { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--line); }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 28px; }
.pager-link { display: flex; flex-direction: column; gap: 4px; padding: 14px 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none !important; }
.pager-link:hover { border-color: var(--cat); }
.pager-link .muted { display: inline-flex; align-items: center; gap: 4px; font-size: .85rem; }
.pager-link .muted svg { width: 16px; height: 16px; }
.pager-link.next { text-align: right; align-items: flex-end; }

/* ---------- Bookmarks page ---------- */
.bm-group { margin: 28px 0; }
.bm-group h2 { font-size: 1.1rem; margin: 0 0 10px; }
.bm-item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--line); }
.bm-item:first-child { border-top: 0; }
.bm-item a { flex: 1; min-width: 0; display: flex; flex-direction: column; color: var(--ink); text-decoration: none !important; }
.bm-item a:hover strong { color: var(--brand-ink); }
.bm-item .muted { font-size: .88rem; }
.bm-remove { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 6px 10px; border-radius: 8px; font-size: .88rem; }
.bm-remove:hover { background: var(--bad-soft); color: var(--bad); }
.empty { text-align: center; padding: 48px 20px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); }
.empty svg { width: 36px; height: 36px; margin-bottom: 8px; }

/* ---------- Search palette ---------- */
.palette { position: fixed; inset: 0; z-index: 90; display: flex; justify-content: center; align-items: flex-start; padding: 10vh 16px 16px; }
.palette[hidden] { display: none; }
.palette-backdrop { position: absolute; inset: 0; background: rgba(10, 12, 14, .45); backdrop-filter: blur(2px); }
.palette-box { position: relative; width: min(640px, 100%); max-height: 72vh; display: flex; flex-direction: column; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 24px 60px rgba(0, 0, 0, .25); overflow: hidden; }
.palette-input { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); color: var(--muted); }
.palette-input input { flex: 1; border: 0; outline: 0; background: transparent; font: inherit; font-size: 1.08rem; color: var(--ink); min-width: 0; }
.palette-input input::-webkit-search-cancel-button { display: none; }
.palette-input kbd { cursor: pointer; }
.palette-results { overflow-y: auto; padding: 8px; }
.result { display: block; padding: 10px 12px; border-radius: 10px; color: var(--ink); text-decoration: none !important; }
.result.active, .result:hover { background: var(--brand-soft); }
.result-top { display: flex; align-items: center; gap: 8px; }
.result-title { font-weight: 600; }
.result-cat { font-size: .8rem; color: var(--muted); margin-left: auto; white-space: nowrap; }
.result-sub { font-size: .88rem; color: var(--ink-2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.result-sub mark, .result-title mark { background: color-mix(in srgb, var(--t1) 25%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.result-section { font-size: .82rem; color: var(--brand-ink); margin-top: 2px; }
.palette-empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- Toast / footer ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 95; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; padding: 10px 18px; border-radius: 999px; background: var(--ink); color: var(--bg); font-size: .92rem; font-weight: 500; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.footer { border-top: 1px solid var(--line); margin-top: 32px; }
.footer-inner { max-width: 1120px; margin: 0 auto; padding: 22px 20px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; font-size: .88rem; color: var(--ink-2); }

/* ---------- Responsive ---------- */
.only-mobile { display: none; }
@media (max-width: 1240px) {
  .lesson-layout { grid-template-columns: 240px minmax(0, 46rem); gap: 40px; }
  .toc-wrap { display: none; }
}
@media (max-width: 960px) {
  .lesson-layout { grid-template-columns: minmax(0, 1fr); padding: 20px 16px 48px; max-width: 760px; }
  .page-lesson .only-mobile { display: inline-grid; }
  .sidebar { position: fixed; top: var(--topbar); left: 0; bottom: 0; height: calc(100dvh - var(--topbar)); width: min(320px, 86vw); max-height: none; z-index: 45; padding: 20px 16px; background: var(--surface); border-right: 1px solid var(--line); transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
}
@media (max-width: 720px) {
  body { font-size: 16px; }
  .prose { font-size: 1.06rem; line-height: 1.85; }
  .wrap { padding: 0 16px; }
  .search-trigger { width: auto; margin-left: auto; border: 0; background: transparent; padding: 8px; }
  .search-trigger span, .search-trigger kbd { display: none; }
  .brand-name { display: none; }
  .hero { padding: 48px 0 32px; }
  .hero-search kbd { display: none; }
  .info-grid.cols-2, .info-grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
  .is-compare .info-grid.cols-2::after { display: none; }
  .flow-track { flex-direction: column; align-items: stretch; }
  .flow-track { padding: 12px; }
  .flow-node { min-width: 0; display: grid; grid-template-columns: 24px 1fr; column-gap: 12px; row-gap: 0; align-items: center; text-align: left; padding: 10px 14px; }
  .flow-idx { grid-row: span 2; }
  .flow-node small { grid-column: 2; }
  .flow-arrow { flex: 0 0 16px; width: 2px; height: 16px; margin: 3px 0 3px 25px; align-self: flex-start; }
  .flow-arrow::after { right: auto; left: -5px; top: auto; bottom: -1px; border: 6px solid transparent; border-top: 8px solid var(--muted); border-bottom: 0; }
  .lesson-row { gap: 12px; padding: 14px; }
  .lesson-row-meta { display: none; }
  .cat-head { flex-direction: column; gap: 8px; }
  .pager { grid-template-columns: 1fr; }
  .lesson-meta .btn span { display: none; }
  .hbm { opacity: .6; }
  .anim-stage { height: 280px; margin: 8px 8px 0; touch-action: pan-y; }
  .anim-hint { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
