:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --text: #1f2328;
  --muted: #5d6470;
  --line: #e2dfd6;
  --brand: #1f5fbf;
  --brand-soft: #e6effc;
  --accent: #c2410c;
  --accent-soft: #fdeee6;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #a16207;
  --warn-soft: #fdf6dc;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 6px 20px rgba(0,0,0,.05);
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --mono: "JetBrains Mono", Consolas, "Courier New", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a; --surface: #1c1f25; --surface-2: #242830; --text: #e8e9ec; --muted: #a2a8b3;
    --line: #2f343d; --brand: #7aa7f0; --brand-soft: #1d2a40; --accent: #f59e6b; --accent-soft: #3a2519;
    --ok: #5fd08a; --ok-soft: #173023; --warn: #e8c35a; --warn-soft: #33290f;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14161a; --surface: #1c1f25; --surface-2: #242830; --text: #e8e9ec; --muted: #a2a8b3;
  --line: #2f343d; --brand: #7aa7f0; --brand-soft: #1d2a40; --accent: #f59e6b; --accent-soft: #3a2519;
  --ok: #5fd08a; --ok-soft: #173023; --warn: #e8c35a; --warn-soft: #33290f;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 17px; line-height: 1.8; -webkit-font-smoothing: antialiased; }
img { max-width: 100%; }
a { color: var(--brand); text-underline-offset: 3px; }
h1, h2, h3, h4 { line-height: 1.35; margin: 1.6em 0 .6em; }
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin-top: .2em; letter-spacing: .01em; }
h2 { font-size: clamp(1.35rem, 3vw, 1.75rem); padding-top: .4em; border-top: 1px solid var(--line); }
h3 { font-size: 1.2rem; }
p, li { max-width: 72ch; }
code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: .1em .4em; border-radius: 6px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 2.5rem 0; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 50; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: .6rem 1rem; display: flex; align-items: center; gap: 1rem; }
.logo { font-weight: 800; color: var(--text); text-decoration: none; white-space: nowrap; display: flex; align-items: center; gap: .5rem; }
.logo-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: .85rem; }
.nav { display: flex; gap: .2rem; flex-wrap: wrap; margin-left: auto; }
.nav a { color: var(--muted); text-decoration: none; padding: .35rem .7rem; border-radius: 8px; font-size: .92rem; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 8px; padding: .35rem .6rem; cursor: pointer; font: inherit; font-size: .9rem; }
.menu-btn { display: none; }
@media (max-width: 960px) {
  .menu-btn { display: inline-block; margin-left: auto; }
  .nav { display: none; position: absolute; left: 0; right: 0; top: 100%; background: var(--surface); border-bottom: 1px solid var(--line); flex-direction: column; padding: .5rem 1rem 1rem; }
  .nav.open { display: flex; }
}

/* ---------- layout ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding-inline: 1rem; padding-block: 1.5rem 4rem; }
.with-toc { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 2.5rem; }
.toc { position: sticky; top: 80px; align-self: start; font-size: .9rem; max-height: calc(100vh - 100px); overflow: auto; }
.toc strong { display: block; margin-bottom: .4rem; color: var(--muted); font-size: .8rem; letter-spacing: .08em; }
.toc a { display: block; color: var(--muted); text-decoration: none; padding: .25rem .6rem; border-left: 2px solid var(--line); }
.toc a:hover, .toc a.on { color: var(--brand); border-left-color: var(--brand); }
@media (max-width: 960px) { .with-toc { grid-template-columns: 1fr; } .toc { display: none; } }

.hero { padding: 2.5rem 0 1rem; }
.eyebrow { display: inline-block; font-size: .82rem; font-weight: 700; letter-spacing: .08em; color: var(--accent); background: var(--accent-soft); padding: .2rem .7rem; border-radius: 99px; }
.lead { font-size: 1.15rem; color: var(--muted); max-width: 65ch; }
.meta { font-size: .85rem; color: var(--muted); }

/* ---------- components ---------- */
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); margin: 1.2rem 0; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem 1.3rem; box-shadow: var(--shadow); }
.card h3, .card h4 { margin-top: 0; }
.card p:last-child, .card ul:last-child { margin-bottom: 0; }
a.card { color: inherit; text-decoration: none; transition: transform .15s, border-color .15s; display: block; }
a.card:hover { transform: translateY(-2px); border-color: var(--brand); }
.card .num { font-size: .8rem; font-weight: 800; color: var(--brand); letter-spacing: .1em; }
.tag { display: inline-block; font-size: .78rem; padding: .05rem .55rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); margin: 0 .25rem .25rem 0; }
.tag.blue { background: var(--brand-soft); color: var(--brand); }
.tag.orange { background: var(--accent-soft); color: var(--accent); }
.tag.green { background: var(--ok-soft); color: var(--ok); }

.callout { border-radius: var(--radius); padding: 1rem 1.2rem; margin: 1.2rem 0; border: 1px solid var(--line); background: var(--surface); border-left: 5px solid var(--brand); }
.callout.tip { border-left-color: var(--ok); background: var(--ok-soft); }
.callout.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.callout.key { border-left-color: var(--accent); background: var(--accent-soft); }
.callout > strong:first-child { display: block; margin-bottom: .2rem; }
.callout p { margin: .3rem 0; }

.table-wrap { overflow-x: auto; margin: 1.2rem 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .93rem; min-width: 640px; }
th, td { text-align: left; padding: .7rem .9rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface-2); font-weight: 700; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }

.prompt { position: relative; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.1rem; padding-top: 2.3rem; margin: 1rem 0; white-space: pre-wrap; font-family: var(--font); font-size: .95rem; line-height: 1.75; overflow-x: auto; }
.prompt::before { content: attr(data-label); position: absolute; top: .55rem; left: 1rem; font-size: .75rem; font-weight: 700; color: var(--muted); letter-spacing: .06em; }
.copy-btn { position: absolute; top: .45rem; right: .5rem; font-size: .78rem; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 7px; padding: .15rem .6rem; cursor: pointer; font-family: var(--font); }
.copy-btn.done { background: var(--ok); color: #fff; border-color: var(--ok); }

.steps { counter-reset: step; list-style: none; padding: 0; }
.steps > li { counter-increment: step; position: relative; padding-left: 2.8rem; margin-bottom: 1rem; }
.steps > li::before { content: counter(step); position: absolute; left: 0; top: .1rem; width: 2rem; height: 2rem; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .9rem; }

details { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .8rem 1.1rem; margin: .7rem 0; }
details summary { cursor: pointer; font-weight: 700; }
details[open] summary { margin-bottom: .5rem; }

.lab { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.4rem 1.5rem; margin: 1.8rem 0; box-shadow: var(--shadow); }
.lab-head { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-bottom: .5rem; }
.lab-head h3 { margin: 0; flex: 1 1 260px; }

/* diagram */
.layers { display: grid; gap: .5rem; max-width: 560px; margin: 1.5rem auto; text-align: center; }
.layers div { border-radius: 12px; padding: .8rem; font-weight: 700; }
.l1 { background: var(--surface-2); } .l2 { background: var(--brand-soft); color: var(--brand); margin-inline: 8%; }
.l3 { background: var(--accent-soft); color: var(--accent); margin-inline: 16%; } .l4 { background: var(--ok-soft); color: var(--ok); margin-inline: 24%; }
.layers small { display: block; font-weight: 400; font-size: .82rem; opacity: .85; }

.flow { display: flex; flex-wrap: wrap; align-items: stretch; gap: .5rem; margin: 1.2rem 0; }
.flow > div { flex: 1 1 140px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .8rem; text-align: center; font-size: .92rem; position: relative; }
.flow > div b { display: block; color: var(--brand); }

/* forms (prompt builder / quiz) */
.builder label { display: block; font-weight: 700; margin: .9rem 0 .3rem; }
.builder label span { font-weight: 400; color: var(--muted); font-size: .85rem; }
.builder input, .builder textarea, .builder select { width: 100%; font: inherit; font-size: .95rem; padding: .6rem .8rem; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.builder textarea { min-height: 70px; resize: vertical; }
.btn { display: inline-block; font: inherit; font-weight: 700; border: 0; background: var(--brand); color: #fff; padding: .6rem 1.2rem; border-radius: 10px; cursor: pointer; text-decoration: none; }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--brand); }
.btn-row { display: flex; gap: .6rem; flex-wrap: wrap; margin: 1rem 0; }

.quiz-q { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.3rem; margin: 1rem 0; }
.quiz-q p { margin-top: 0; font-weight: 700; }
.quiz-q label { display: block; padding: .45rem .7rem; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.quiz-q label:hover { background: var(--surface-2); }
.quiz-q label.right { background: var(--ok-soft); border-color: var(--ok); }
.quiz-q label.wrong { background: var(--accent-soft); border-color: var(--accent); }
.quiz-q .explain { margin-top: .6rem; font-size: .92rem; color: var(--muted); }
.score { font-size: 1.2rem; font-weight: 800; }

.footer { border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; }
.footer .wrap { padding-block: 2rem; }
.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3rem; flex-wrap: wrap; }
.pager a { flex: 1 1 220px; border: 1px solid var(--line); border-radius: 12px; padding: .8rem 1rem; text-decoration: none; background: var(--surface); }
.pager a small { display: block; color: var(--muted); }
.pager a.next { text-align: right; }

/* Course reading and practice surfaces */
.content { min-width: 0; }
.field { display: block; font-weight: 700; margin: 1rem 0; }
.field textarea { display: block; width: 100%; padding: .8rem; margin-top: .4rem; font: inherit; font-weight: 400; color: var(--text); background: var(--surface); border: 1px solid var(--muted); border-radius: 8px; resize: vertical; }
fieldset { min-width: 0; padding: 1.2rem; margin: 1.5rem 0; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
legend { font-weight: 700; padding: 0 .4rem; }
.option { display: block; padding: .7rem .3rem; cursor: pointer; }
.option input { width: 1.1rem; height: 1.1rem; accent-color: var(--brand); }
.explanation { padding: .8rem; border-left: 4px solid var(--brand); background: var(--brand-soft); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
h2[id] { scroll-margin-top: 100px; }
.skip-link { position: fixed; top: -100px; left: 1rem; z-index: 999; background: var(--surface); padding: .7rem; }
.skip-link:focus { top: 1rem; }
.copy-btn,.tag,.eyebrow,.card .num,.toc strong { font-size: .875rem; }
.prompt { overflow-wrap: anywhere; padding-top: 3rem; }
.hero { border-bottom: 3px solid var(--brand); padding-bottom: 1.7rem; margin-bottom: 1.7rem; }
.hero h1 { max-width: 24ch; }
.logo { white-space: normal; }
.logo-mark { flex-shrink: 0; }
.menu-btn,.theme-btn { flex-shrink: 0; }
@media(max-width: 600px) { .grid.two,.grid { grid-template-columns: minmax(0,1fr); } .logo { max-width: 65%; font-size: .9rem; } .wrap { padding-inline: 1rem; } .hero { padding-top: 1rem; } .btn { max-width: 100%; } .layers .l4 { margin-inline: 8%; } }
@media(prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { transition: none !important; } }
@media print { .topbar,.toc,.pager,.copy-btn,.skip-link { display: none !important; } .with-toc { display: block; } :root { --bg: white; --surface: white; --text: black; --muted: #333; } body { background: white; color: black; font-size: 12pt; } .wrap { padding: 0; } .card,.callout,fieldset { break-inside: avoid; box-shadow: none; } .table-wrap { overflow: visible; } table { min-width: 0; } a { color: black; } }
