:root {
  color-scheme: light dark;
  --bg: #fbfbf9;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #5f6670;
  --line: #d9dce1;
  --head: #eef0f3;
  --accent: #1f5fa8;
  --mark: #ffe58a;
  --key: #e8f0fb; --key-bar: #2e5c9a;
  --warn: #fdf3e1; --warn-bar: #b36f05;
  --ex: #f1f3f5; --ex-bar: #6b7280;
  --note: #eef7f1; --note-bar: #3b8a5a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181c;
    --surface: #1d2126;
    --text: #e6e8eb;
    --muted: #a0a7b0;
    --line: #363c44;
    --head: #2a2f36;
    --accent: #7db3ee;
    --mark: #7a6210;
    --key: #1c2a3c; --key-bar: #7db3ee;
    --warn: #372b17; --warn-bar: #e0a54a;
    --ex: #262a30; --ex-bar: #a0a7b0;
    --note: #1b2f24; --note-bar: #6cc093;
  }
}

* { box-sizing: border-box; }
html { scroll-padding-top: 72px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.75 "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
}
a { color: var(--accent); }
code, pre { font-family: Consolas, Menlo, monospace; font-size: .9em; }
pre { background: var(--head); padding: 12px 14px; overflow-x: auto; border-radius: 6px; }
h1 { font-size: 1.75rem; line-height: 1.35; }
h2 { font-size: 1.3rem; line-height: 1.4; margin-top: 2em; }
h3 { font-size: 1.05rem; margin-top: 1.6em; }
mark { background: var(--mark); color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.note, .meta { color: var(--muted); font-size: .9rem; }

.site-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; gap: 4px 20px; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.site-header nav { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.site-header nav a { color: var(--muted); text-decoration: none; }
.site-header nav a[aria-current] { color: var(--text); font-weight: 700; }

.table-wrap { overflow-x: auto; margin: 1em 0; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; background: var(--surface); }
th, td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
th { background: var(--head); white-space: nowrap; }
table.grid td { text-align: center; background: var(--key); }
.terms td:nth-child(n+3) { white-space: nowrap; }

.box { margin: 1em 0; padding: 10px 14px; border-left: 4px solid; border-radius: 0 6px 6px 0; }
.box p { margin: .25em 0; }
.box-label { display: block; font-size: .85rem; }
.box.key { background: var(--key); border-color: var(--key-bar); }
.box.key .box-label { color: var(--key-bar); }
.box.warn { background: var(--warn); border-color: var(--warn-bar); }
.box.warn .box-label { color: var(--warn-bar); }
.box.ex { background: var(--ex); border-color: var(--ex-bar); }
.box.ex .box-label { color: var(--ex-bar); }
.box.note { background: var(--note); border-color: var(--note-bar); }
.box.note .box-label { color: var(--note-bar); }
.check { list-style: "☐  "; }

.book { display: grid; grid-template-columns: 270px minmax(0, 1fr); max-width: 1180px; margin: 0 auto; }
.toc {
  position: sticky; top: 53px; align-self: start;
  max-height: calc(100vh - 53px); overflow-y: auto;
  padding: 16px; border-right: 1px solid var(--line); font-size: .88rem;
}
.toc a { display: block; padding: 3px 6px; color: var(--text); text-decoration: none; border-radius: 4px; }
.toc a.toc-1 { font-weight: 700; margin-top: 10px; }
.toc a.toc-2 { padding-left: 16px; color: var(--muted); }
.toc a[aria-current] { background: var(--head); color: var(--text); }
.toc-actions { padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.toc-actions a { color: var(--accent); }
.content { padding: 8px 32px 80px; min-width: 0; }
.content h1 { margin-top: 2em; padding-top: .5em; border-top: 2px solid var(--line); }
.content h1:first-child { margin-top: .5em; border-top: 0; }

.home, .lookup { max-width: 900px; margin: 0 auto; padding: 16px 16px 80px; }
.hero h1 { margin-bottom: .3em; }
.hero label { display: block; font-weight: 700; margin-top: 1.2em; }
.search-row { display: flex; gap: 8px; margin-top: 6px; }
input[type="search"] {
  flex: 1; min-width: 0; padding: 10px 12px; font: inherit;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px;
}
button {
  padding: 8px 16px; font: inherit; cursor: pointer;
  color: var(--text); background: var(--head);
  border: 1px solid var(--line); border-radius: 6px;
}
button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-top: 28px; }
.card { display: block; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; color: var(--text); text-decoration: none; }
.card:hover { border-color: var(--accent); }
.card h2 { margin: 0 0 4px; font-size: 1.1rem; }
.card p { margin: 0; color: var(--muted); font-size: .92rem; }
.section-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; margin-top: 2em; }
.section-head h2 { margin: 0; }
.sort { display: flex; gap: 6px; }
.hit { padding: 10px 0; border-bottom: 1px solid var(--line); }
.hit p { margin: 2px 0 0; font-size: .92rem; }

@media (max-width: 800px) {
  .book { display: block; }
  .toc { position: static; max-height: 260px; border-right: 0; border-bottom: 1px solid var(--line); }
  .content { padding: 8px 16px 60px; }
  html { scroll-padding-top: 90px; }
}
