/* ═══════════════════════════════════════════════════════════════════
   AI Agent 學習站 — 樣式
   主題採 CSS 變數；內容樣式假設 pipeline 產出的章節片段結構。
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --bg: #ffffff; --fg: #22272e; --muted: #59636e; --accent: #008b8b;
  --accent-light: #e4f2f2; --code-bg: #f4f6f8; --border: #d5dbe1;
  --header-bg: rgba(255,255,255,.94); --card-bg: #ffffff; --ok: #2da44e;
}
html[data-theme="sepia"] {
  --bg: #f6efdf; --fg: #40382a; --muted: #7d7260; --accent: #0d7d7d;
  --accent-light: #ebe1c9; --code-bg: #efe6d2; --border: #dbcfb2;
  --header-bg: rgba(246,239,223,.94); --card-bg: #fbf6ea; --ok: #4b8f42;
}
html[data-theme="dark"] {
  --bg: #0f1317; --fg: #d5dce2; --muted: #8b949e; --accent: #3fbdbd;
  --accent-light: #14282a; --code-bg: #1a2027; --border: #2d343c;
  --header-bg: rgba(15,19,23,.94); --card-bg: #161c22; --ok: #3fb950;
}
html[data-theme="ink"] {
  --bg: #000000; --fg: #c9d1d9; --muted: #7d8590; --accent: #2dd4bf;
  --accent-light: #062622; --code-bg: #101214; --border: #26292d;
  --header-bg: rgba(0,0,0,.94); --card-bg: #0b0d0f; --ok: #3fb950;
}
html[data-theme="violet"] {
  --bg: #14101f; --fg: #d9d2ea; --muted: #8f86a8; --accent: #a78bfa;
  --accent-light: #241b38; --code-bg: #1c1629; --border: #322847;
  --header-bg: rgba(20,16,31,.94); --card-bg: #191325; --ok: #3fb950;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: "Noto Sans TC","PingFang TC","Microsoft JhengHei",system-ui,sans-serif;
  line-height: var(--lh, 1.85); font-size: var(--fs, 17px);
  overflow-wrap: break-word;
}
html[data-font="serif"] body {
  font-family: "Noto Serif TC","Noto Serif CJK TC","PMingLiU",serif;
}
button { font-family: inherit; }

/* ── header ── */
#hdr {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  display: flex; align-items: center; gap: .3em;
  background: var(--header-bg); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: .45em .55em; padding-top: max(.45em, env(safe-area-inset-top));
}
#hdr .title {
  flex: 1; font-size: .85em; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#hdr button {
  background: none; border: none; color: var(--fg); font-size: 1.2em;
  padding: .25em .5em; cursor: pointer; border-radius: .45em; line-height: 1;
}
#hdr button:active { background: var(--accent-light); }
#progress {
  position: fixed; top: 0; left: 0; height: 3px; z-index: 40;
  background: var(--accent); width: 0%; transition: width .1s linear;
}

/* ── home ── */
#home { max-width: 44em; margin: 0 auto; padding: 4.2em 1.05em 3em; }
#home .lib-title {
  text-align: center; margin: 0 0 .1em; font-size: 1.45em; font-weight: 800;
  letter-spacing: .05em;
}
#home .lib-sub {
  text-align: center; color: var(--muted); font-size: .84em; margin-bottom: 1.6em;
}
.home-sec {
  margin: 2em 0 .6em; font-size: .8em; font-weight: 700;
  letter-spacing: .16em; color: var(--muted);
}
.home-sec small { letter-spacing: 0; font-weight: 400; }
.card {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 14px; overflow: hidden;
}
.resume-card {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: var(--card-bg); border: 1px solid var(--border);
  border-left: 4px solid var(--accent); border-radius: 14px;
  padding: 1em 1.15em; font-size: 1em; color: var(--fg); line-height: 1.6;
}
.resume-card:active { background: var(--accent-light); }
.resume-card .rc-label { font-size: .74em; color: var(--muted); letter-spacing: .1em; }
.resume-card .rc-title { font-weight: 800; margin: .15em 0; font-size: 1.05em; }
.resume-card .rc-sub { font-size: .82em; color: var(--muted); }
.resume-card .rc-sub b { color: var(--accent); font-weight: 700; }
/* 學習路徑 */
.path-head { padding: 1em 1.15em .2em; }
.pbar {
  height: 7px; background: var(--code-bg); border-radius: 4px;
  border: 1px solid var(--border); overflow: hidden;
}
.pbar-fill {
  height: 100%; width: 0%; background: var(--bk, var(--accent));
  border-radius: 4px; transition: width .3s;
}
.pbar-label { font-size: .76em; color: var(--muted); margin-top: .35em; }
.stage { border-top: 1px solid var(--border); }
.stage:first-of-type { border-top: none; }
.stage summary {
  list-style: none; cursor: pointer; padding: .8em 1.15em;
  display: flex; align-items: center; gap: .6em;
}
.stage summary::before { content: "▸"; color: var(--muted); font-size: .8em; }
.stage[open] summary::before { content: "▾"; }
.stage-name { font-weight: 700; flex: 1; font-size: .95em; }
.stage-count { font-size: .78em; color: var(--muted); }
.stage.done .stage-name::after { content: " ✓"; color: var(--ok); }
.stage-desc { margin: 0; padding: 0 1.15em .4em 2.3em; font-size: .84em; color: var(--muted); }
.steps { list-style: none; margin: 0; padding: .2em 1em .4em; }
.step {
  display: flex; align-items: center; gap: .55em; padding: .5em .3em;
  border-top: 1px dashed var(--border); cursor: pointer;
}
.step-check {
  width: 1.05em; height: 1.05em; border: 2px solid var(--border);
  border-radius: 50%; flex-shrink: 0; position: relative;
}
.step.done .step-check { border-color: var(--ok); background: var(--ok); }
.step.done .step-check::after {
  content: "✓"; color: #fff; font-size: .72em; position: absolute;
  top: 50%; left: 50%; transform: translate(-50%, -52%);
}
.step-badge {
  font-size: .66em; color: var(--bk); border: 1px solid var(--bk);
  padding: 0 .5em; border-radius: 2em; flex-shrink: 0;
}
.step-title { flex: 1; font-size: .88em; line-height: 1.45; }
.step.done .step-title { color: var(--muted); }
.step-min { font-size: .72em; color: var(--muted); flex-shrink: 0; }
.stage-quiz { padding: 0 1.05em .9em; }
.quiz-btn {
  width: 100%; padding: .55em; cursor: pointer; font-size: .87em;
  border: 1px dashed var(--border); background: transparent;
  color: var(--accent); border-radius: 8px;
}
/* 零碎快讀 */
#quickreads { display: flex; flex-direction: column; gap: .45em; }
.qr-item {
  display: flex; align-items: baseline; gap: .55em; cursor: pointer;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 10px; padding: .6em .9em; font-size: .88em;
}
.qr-item .qr-badge {
  font-size: .76em; color: var(--qr, var(--accent));
  border: 1px solid var(--qr, var(--accent));
  padding: 0 .5em; border-radius: 2em; flex-shrink: 0;
}
.qr-item .qr-title {
  flex: 1; font-weight: 600; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.qr-item .qr-min { font-size: .78em; color: var(--muted); flex-shrink: 0; }
/* 書庫 */
.book-card { margin: .7em 0; }
.card-head { padding: 1em 1.15em .85em; cursor: pointer; }
.card-level {
  display: inline-block; font-size: .7em; color: var(--bk);
  border: 1px solid var(--bk); border-radius: 2em; padding: .08em .7em;
  margin-bottom: .5em; letter-spacing: .06em;
}
.card-title { font-size: 1.12em; font-weight: 800; line-height: 1.4; }
.card-sub { color: var(--muted); font-size: .84em; margin: .1em 0 .1em; }
.card-meta { font-size: .76em; color: var(--muted); margin-bottom: .6em; }
.card-head .pbar-fill { background: var(--bk); }
.card-toc summary {
  list-style: none; padding: .65em 1.15em; cursor: pointer;
  color: var(--bk); font-size: .87em; border-top: 1px dashed var(--border);
}
.card-toc summary::before { content: "▸ "; }
.card-toc[open] summary::before { content: "▾ "; }
.card-toc .toc { padding: 0 1.15em 1em; }
/* toc */
.toc { list-style: none; margin: 0; padding: 0; }
.toc-grp { margin: 1em 0 .3em; font-size: .76em; letter-spacing: .1em; color: var(--muted); }
.toc-ch { margin: .5em 0; }
.toc-ch > a {
  color: var(--fg); text-decoration: none; font-weight: 600; font-size: .93em;
  display: flex; align-items: baseline; gap: .5em;
}
.toc-ch > a > .toc-pct { margin-left: auto; font-size: .68em; color: var(--accent); font-weight: 400; flex-shrink: 0; }
.toc-ch > a > .toc-min { font-size: .72em; color: var(--muted); font-weight: 400; flex-shrink: 0; }
.toc-ch > a > .toc-pct:empty + .toc-min { margin-left: auto; }
.toc-ch > a.done::before { content: "✓ "; color: var(--ok); font-weight: 700; }
.toc-ch.current > a { color: var(--accent); }
.toc-secs { list-style: none; padding-left: 1em; display: none; margin: .2em 0; }
.toc-ch.current .toc-secs { display: block; }
.toc-secs li { margin: .3em 0; font-size: .85em; }
.toc-secs a { color: var(--muted); text-decoration: none; }
/* 書籤與筆記列表 */
.bm-item, .nb-item {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 10px; padding: .65em .9em; margin: .45em 0; cursor: pointer;
  display: flex; align-items: flex-start; gap: .6em;
}
.bm-body, .nb-body { flex: 1; min-width: 0; }
.bm-loc, .nb-loc { font-size: .76em; color: var(--accent); }
.bm-label { font-size: .9em; font-weight: 600; line-height: 1.5; }
.bm-item button, .nb-item button {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: .95em; padding: 0 .1em; flex-shrink: 0;
}
.nb-note {
  font-size: .86em; line-height: 1.6;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.nb-hls { font-size: .74em; color: var(--muted); margin-top: .2em; }
.list-empty { font-size: .84em; color: var(--muted); padding: .3em .2em; }
.stat-line {
  text-align: center; font-size: .8em; color: var(--muted); margin: 2.4em 0 .5em;
}
.stat-line b { color: var(--accent); font-weight: 700; }
#goal-chip { cursor: pointer; text-decoration: underline dotted; }
.stat-line .goal-met { color: var(--ok); }

/* ── drawer ── */
#drawer {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 50;
  width: min(85vw, 340px); background: var(--bg);
  border-right: 1px solid var(--border);
  transform: translateX(-103%); transition: transform .22s ease;
  overflow-y: auto; padding: 1em 1em 2.5em;
  padding-top: max(1em, env(safe-area-inset-top));
}
#drawer.open { transform: none; box-shadow: 0 0 32px rgba(0,0,0,.35); }
#drawer .drawer-book { font-weight: 800; color: var(--accent); margin: .3em 0 .2em; }
#drawer .drawer-home {
  display: block; margin: .6em 0 1em; font-size: .85em; color: var(--muted);
  text-decoration: none;
}
#mask {
  position: fixed; inset: 0; z-index: 45; background: rgba(0,0,0,.42);
  opacity: 0; pointer-events: none; transition: opacity .22s;
}
#mask.show { opacity: 1; pointer-events: auto; }

/* ── settings sheet ── */
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--bg); border-top: 1px solid var(--border);
  border-radius: 14px 14px 0 0; padding: 1em 1.3em 1.8em;
  transform: translateY(106%); transition: transform .22s ease;
}
#sheet.open { transform: none; box-shadow: 0 -8px 32px rgba(0,0,0,.3); }
#sheet .row { display: flex; align-items: center; gap: .7em; margin: .9em 0; flex-wrap: wrap; }
#sheet .row > span:first-child { width: 3.2em; color: var(--muted); font-size: .86em; }
#sheet button {
  border: 1px solid var(--border); background: var(--bg); color: var(--fg);
  border-radius: 8px; padding: .38em .95em; font-size: .95em; cursor: pointer;
}
#sheet button.on { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
#fs-val { min-width: 3em; text-align: center; color: var(--muted); font-size: .9em; }
#sheet .mini { font-size: .85em; }

/* ── content ── */
#wrap { max-width: 42em; margin: 0 auto; padding: 3.7em 1.05em 2.5em; }
.ch-meta { text-align: center; font-size: .78em; color: var(--muted); margin: -.4em 0 1.4em; }
.chapter h1 {
  font-size: 1.5em; line-height: 1.45; color: var(--accent);
  text-align: center; border-bottom: 2px solid var(--accent);
  padding-bottom: .45em; margin: .9em 0 1em;
}
.chapter h2 {
  font-size: 1.26em; line-height: 1.45; margin: 1.9em 0 .7em;
  padding-bottom: .2em; border-bottom: 1px solid var(--border);
}
.chapter h3 { font-size: 1.1em; margin: 1.5em 0 .6em; color: var(--accent); }
.chapter h4 { font-size: 1.02em; margin: 1.2em 0 .5em; color: var(--muted); }
.header-section-number { font-size: .78em; color: var(--muted); font-weight: 400; margin-right: .45em; }
h1 .header-section-number { display: block; font-size: .55em; letter-spacing: .2em; margin: 0 0 .3em; }
.chapter a { color: var(--accent); }
.chapter p { margin: 0 0 .9em; text-align: justify; }
.chapter li { text-align: justify; }
.chapter figcaption, .chapter th, .chapter td { text-align: left; }
.fig { margin: 1.3em 0; text-align: center; cursor: zoom-in; }
.fig svg, .fig img { max-width: 100%; height: auto; background: #fff; border-radius: 8px; }
html[data-theme="dark"] .fig svg, html[data-theme="dark"] .fig img,
html[data-theme="ink"] .fig svg, html[data-theme="ink"] .fig img,
html[data-theme="violet"] .fig svg, html[data-theme="violet"] .fig img { box-shadow: 0 0 0 1px #2a3138; }
.fig figcaption { font-size: .84em; color: var(--muted); margin-top: .45em; }
.img-offline {
  padding: 1.8em 1em; background: var(--code-bg);
  border: 1px dashed var(--border); border-radius: 8px;
  color: var(--muted); font-size: .84em; text-align: center;
}
code, pre { font-family: "Cascadia Mono",Consolas,ui-monospace,monospace; }
:not(pre) > code {
  background: var(--code-bg); border-radius: .3em;
  padding: .08em .35em; font-size: .86em;
}
pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 10px; padding: .85em .95em; margin: 1em 0;
  font-size: .8em; line-height: 1.55;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
pre code { background: none; padding: 0; font-size: 1em; }
blockquote {
  margin: 1em 0; padding: .7em 1em; background: var(--accent-light);
  border-left: .25em solid var(--accent); border-radius: 0 10px 10px 0;
}
blockquote p { margin: .4em 0; }
.co-label { display: inline-block; margin-bottom: .1em; }
blockquote.co-warning { background: rgba(212, 153, 40, .13); border-left-color: #d49928; }
blockquote.co-caution { background: rgba(209, 36, 47, .1); border-left-color: #d1242f; }
blockquote.co-important { background: rgba(130, 80, 223, .1); border-left-color: #8250df; }
.chapter table {
  border-collapse: collapse; font-size: .84em; margin: 1em 0;
  display: block; overflow-x: auto; -webkit-overflow-scrolling: touch;
  cursor: zoom-in;
}
th, td {
  border: 1px solid var(--border); padding: .4em .6em; vertical-align: top;
  min-width: 6em; max-width: 24em;
}
th { background: var(--accent-light); text-align: left; }
ul, ol { padding-left: 1.5em; margin: .5em 0 .9em; }
li { margin: .32em 0; }
hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
math { font-size: 1.06em; }
sup, sub { line-height: 0; }
code .kw, code .cf { color: #9333cf; font-weight: 600; }
code .dt { color: #1e66d0; }
code .st, code .vs, code .ss { color: #0e8a4d; }
code .co { color: #8a919a; font-style: italic; }
code .fu { color: #b1590c; }
code .dv, code .bn, code .fl, code .cn { color: #c22f4e; }
code .im { color: #9333cf; }
code .at { color: #1e66d0; }
html[data-theme="dark"] code .kw, html[data-theme="dark"] code .cf,
html[data-theme="ink"] code .kw, html[data-theme="ink"] code .cf,
html[data-theme="violet"] code .kw, html[data-theme="violet"] code .cf { color: #c792ea; }
html[data-theme="dark"] code .dt, html[data-theme="ink"] code .dt, html[data-theme="violet"] code .dt { color: #82aaff; }
html[data-theme="dark"] code .st, html[data-theme="ink"] code .st, html[data-theme="violet"] code .st { color: #7ecf9c; }
html[data-theme="dark"] code .fu, html[data-theme="ink"] code .fu, html[data-theme="violet"] code .fu { color: #ffb86c; }
html[data-theme="dark"] code .dv, html[data-theme="ink"] code .dv, html[data-theme="violet"] code .dv { color: #ff7a93; }
.chapter a[href*="youtu"]:not(:has(img)):not(:has(figure)) {
  display: inline-block; background: var(--accent-light);
  border: 1px solid var(--accent); border-radius: 2em;
  padding: .2em .9em; text-decoration: none; font-size: .92em;
  margin: .1em 0;
}
.chapter a[href*="youtu"]:not(:has(img)):not(:has(figure))::before { content: "▶ "; }
/* 章末 */
#done-area { margin: 2.4em 0 0; text-align: center; }
#answers-link { margin-bottom: 1em; font-size: .9em; }
#answers-link a { color: var(--accent); cursor: pointer; text-decoration: underline; }
#btn-done {
  padding: .65em 1.6em; border-radius: 2em; font-size: .93em; cursor: pointer;
  border: 2px solid var(--ok); background: transparent; color: var(--ok);
  font-weight: 700;
}
#btn-done.done { background: var(--ok); color: #fff; }
#next-step-hint { margin-top: .8em; font-size: .85em; color: var(--muted); }
#next-step-hint a { color: var(--accent); cursor: pointer; text-decoration: underline; }
#chnav { display: flex; gap: .8em; margin: 1.6em 0 1em; }
#chnav button {
  flex: 1; padding: .75em .5em; font-size: .92em; text-align: left;
  border: 1px solid var(--border); background: var(--code-bg); color: var(--fg);
  border-radius: 10px; cursor: pointer; overflow: hidden;
}
#chnav button:disabled { opacity: .3; }
#chnav .lbl { display: block; font-size: .75em; color: var(--muted); margin-bottom: .2em; }
#chnav #next { text-align: right; }
#chnav span:not(.lbl) {
  display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── search ── */
#search {
  position: fixed; inset: 0; z-index: 60; background: var(--bg);
  display: none; flex-direction: column;
  padding-top: max(.5em, env(safe-area-inset-top));
}
#search.open { display: flex; }
#search .s-bar {
  display: flex; gap: .5em; align-items: center;
  padding: .5em .8em; border-bottom: 1px solid var(--border);
}
#search input {
  flex: 1; font-size: 1em; font-family: inherit;
  background: var(--code-bg); color: var(--fg);
  border: 1px solid var(--border); border-radius: 8px; padding: .55em .8em;
  outline: none;
}
#search input:focus { border-color: var(--accent); }
#search .s-close { background: none; border: none; color: var(--muted); font-size: 1em; padding: .4em .5em; cursor: pointer; }
#s-results { flex: 1; overflow-y: auto; padding: .5em .9em 2em; }
.s-hint { text-align: center; color: var(--muted); font-size: .85em; margin-top: 2.5em; }
.s-item { padding: .7em .4em; border-bottom: 1px dashed var(--border); cursor: pointer; }
.s-item .s-loc { font-size: .78em; color: var(--accent); margin-bottom: .15em; }
.s-item .s-snip { font-size: .88em; color: var(--muted); line-height: 1.6; }
.s-item .s-snip b { color: var(--fg); background: var(--accent-light); border-radius: .2em; padding: 0 .1em; }
mark.search-hit { background: #ffd763; color: #1f2328; border-radius: .15em; }
html[data-theme="dark"] mark.search-hit, html[data-theme="ink"] mark.search-hit,
html[data-theme="violet"] mark.search-hit { background: #a07800; color: #fff; }
mark.hl { background: rgba(45, 164, 78, .12); color: inherit; border-bottom: 2px solid var(--ok); }

/* ── FABs ── */
#fabs {
  position: fixed; right: .7em; bottom: .9em; z-index: 25;
  display: none; flex-direction: column; gap: .45em; align-items: flex-end;
}
#fabs.show { display: flex; }
#fabs button {
  border: 1px solid var(--border); background: var(--card-bg); color: var(--fg);
  border-radius: 2em; padding: .4em .7em; font-size: .8em; cursor: pointer;
  box-shadow: 0 3px 12px rgba(0,0,0,.18); opacity: .82;
}
#fabs button:active { opacity: 1; }
#fab-top { display: none; }
#fab-top.show { display: block; }

/* ── note sheet ── */
#notesheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--bg); border-top: 1px solid var(--border);
  border-radius: 14px 14px 0 0; padding: 1em 1.3em 1.6em;
  transform: translateY(106%); transition: transform .22s ease;
  max-height: 72vh; overflow-y: auto;
}
#notesheet.open { transform: none; box-shadow: 0 -8px 32px rgba(0,0,0,.3); }
#notesheet h3 { margin: .2em 0 .6em; font-size: 1em; color: var(--accent); }
#note-text {
  width: 100%; min-height: 7em; font-family: inherit; font-size: .92em;
  background: var(--code-bg); color: var(--fg); line-height: 1.7;
  border: 1px solid var(--border); border-radius: 8px; padding: .7em .8em;
  resize: vertical; outline: none;
}
#note-text:focus { border-color: var(--accent); }
#note-saved { font-size: .75em; color: var(--muted); text-align: right; margin: .3em 0 .8em; min-height: 1.2em; }
.hl-item {
  display: flex; gap: .6em; align-items: flex-start;
  font-size: .85em; padding: .5em 0; border-top: 1px dashed var(--border);
}
.hl-item .hl-text { flex: 1; color: var(--muted); line-height: 1.6; }
.hl-item button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1em; padding: 0 .2em; }

/* ── selection popover ── */
#selpop {
  position: fixed; z-index: 55; display: none;
  left: 50%; transform: translateX(-50%);
  bottom: calc(1.1em + env(safe-area-inset-bottom));
  background: var(--fg); color: var(--bg); border: none; border-radius: 2em;
  padding: .6em 1.4em; font-size: .92em; cursor: pointer;
  box-shadow: 0 4px 18px rgba(0,0,0,.35);
}

/* ── lightbox ── */
#lightbox {
  position: fixed; inset: 0; z-index: 70; background: rgba(10,12,14,.92);
  display: none; flex-direction: column;
}
#lightbox.open { display: flex; }
#lightbox .lb-bar {
  display: flex; align-items: center; gap: .6em; color: #cfd6dd;
  padding: .6em 1em; padding-top: max(.6em, env(safe-area-inset-top));
  font-size: .82em;
}
#lightbox .lb-bar span { flex: 1; }
#lightbox .lb-bar button {
  background: rgba(255,255,255,.12); color: #fff; border: none;
  border-radius: 8px; padding: .4em .9em; font-size: 1em; cursor: pointer;
}
#lb-body { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: .5em; text-align: center; }
#lb-body svg, #lb-body img { background: #fff; border-radius: 8px; display: block; margin: 0 auto; }
#lb-body .lb-tablewrap {
  display: inline-block; text-align: left;
  background: var(--bg); color: var(--fg);
  padding: 1em 1.2em; border-radius: 10px;
}
#lb-body table { display: table; width: max-content; border-collapse: collapse; cursor: default; font-size: 1em; }
#lb-body th, #lb-body td { max-width: 30em; }

/* ── quiz ── */
#quiz {
  position: fixed; inset: 0; z-index: 65; background: var(--bg);
  display: none; flex-direction: column;
  padding-top: max(.5em, env(safe-area-inset-top));
}
#quiz.open { display: flex; }
#quiz .q-bar { display: flex; align-items: center; gap: .6em; padding: .6em 1em; border-bottom: 1px solid var(--border); }
#quiz .q-bar span { flex: 1; font-weight: 800; color: var(--accent); }
#quiz .q-bar button { background: none; border: none; color: var(--muted); font-size: 1em; padding: .4em .5em; cursor: pointer; }
#quiz-body { flex: 1; overflow-y: auto; padding: .9em 1em 2em; }
.qz { border: 1px solid var(--border); border-radius: 10px; padding: .9em 1em; margin-bottom: 1em; background: var(--card-bg); }
.qz-q { font-weight: 700; margin-bottom: .6em; line-height: 1.6; }
.qz-tag { float: right; font-size: .75em; color: var(--ok); font-weight: 700; }
.qz-opt {
  display: block; width: 100%; text-align: left; margin: .45em 0;
  padding: .6em .8em; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--fg); cursor: pointer; font-size: .92em;
  line-height: 1.5;
}
.qz-opt:disabled { cursor: default; opacity: .85; }
.qz-opt.correct { border-color: var(--ok); background: rgba(63,185,80,.16); font-weight: 700; }
.qz-opt.wrong { border-color: #d1242f; background: rgba(209,36,47,.12); }
.qz-why {
  display: none; font-size: .84em; color: var(--muted); margin-top: .55em;
  border-top: 1px dashed var(--border); padding-top: .55em; line-height: 1.6;
}
.qz.answered .qz-why { display: block; }

/* ── videobox ── */
#videobox {
  position: fixed; inset: 0; z-index: 75; background: rgba(8,10,12,.95);
  display: none; flex-direction: column; justify-content: center;
}
#videobox.open { display: flex; }
#videobox .vb-bar {
  display: flex; align-items: center; gap: .6em; color: #cfd6dd;
  padding: .6em 1em; font-size: .85em;
  position: absolute; top: env(safe-area-inset-top, 0); left: 0; right: 0;
}
#videobox .vb-bar span { flex: 1; }
#videobox .vb-bar button {
  background: rgba(255,255,255,.12); color: #fff; border: none;
  border-radius: 8px; padding: .4em .9em; font-size: .95em; cursor: pointer;
}
#videobox .vb-body { width: 100%; padding: 0 .4em; }
#vb-iframe {
  display: block; width: 100%; aspect-ratio: 16 / 9; max-height: 80vh;
  border: none; border-radius: 10px; background: #000; margin: 0 auto;
  max-width: 60em;
}

/* ── toasts ── */
#toasts {
  position: fixed; top: calc(3.4em + env(safe-area-inset-top));
  left: 50%; transform: translateX(-50%); z-index: 80;
  display: flex; flex-direction: column; gap: .4em; align-items: center;
  pointer-events: none; width: max-content; max-width: 92vw;
}
.toast {
  background: var(--fg); color: var(--bg); border-radius: 2em;
  padding: .5em 1.2em; font-size: .85em; font-weight: 700;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
  animation: toastin .3s ease;
}
@keyframes toastin { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; } }
