:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #dfe3e8;
  --accent: #0f766e;
  --accent-soft: #e0f2ef;
  --warn-bg: #fff8e6;
  --warn-line: #f5d78e;
  --warn-text: #7a4b00;
  --paper: #ffffff;
  --page-bg: #e5e7eb;
  --danger: #b42318;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418;
    --panel: #1a1f25;
    --text: #e5e7eb;
    --muted: #9aa3ae;
    --line: #2c333b;
    --accent: #2dd4bf;
    --accent-soft: #123a36;
    --warn-bg: #2b2412;
    --warn-line: #5c4a1a;
    --warn-text: #f3d48b;
    --paper: #1d232a;
    --page-bg: #0d1013;
    --danger: #f97066;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, .button {
  font: inherit;
  font-size: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
button:hover, .button:hover { border-color: var(--accent); text-decoration: none; }
button:disabled { opacity: .55; cursor: not-allowed; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
input[type="text"], input[type="number"], input[type="search"] {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}
.notice {
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  color: var(--warn-text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}
.muted { color: var(--muted); }
.error { color: var(--danger); }

/* ---------- top bar & auth ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 16px; color: var(--text); }
.spacer { flex: 1; }
.auth { display: flex; align-items: center; gap: 8px; font-size: 14px; position: relative; }
.auth img { width: 24px; height: 24px; border-radius: 50%; }
.auth-menu {
  position: absolute;
  right: 0;
  top: 40px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px;
  display: none;
  flex-direction: column;
  min-width: 150px;
  z-index: 30;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.auth-menu.open { display: flex; }
.auth-menu a { padding: 8px 10px; border-radius: 6px; color: var(--text); }
.auth-menu a:hover { background: var(--accent-soft); text-decoration: none; }

/* ---------- home ---------- */
.home { max-width: 960px; margin: 0 auto; padding: 28px 16px 60px; }
.home h1 { font-size: 26px; margin: 0 0 6px; }
.home h2 { font-size: 18px; margin: 32px 0 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  color: var(--text);
  display: block;
}
.card:hover { border-color: var(--accent); text-decoration: none; }
.card .title { font-weight: 650; }
.card .meta { font-size: 13px; color: var(--muted); margin-top: 4px; }
.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.bar span { display: block; height: 100%; background: var(--accent); }
.search-row { display: flex; gap: 8px; }
.search-row input { flex: 1; }
.results { margin-top: 12px; display: grid; gap: 8px; }
.result {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.result .form { font-weight: 650; min-width: 60px; }
.result .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--muted); }
.disclaimer { margin-top: 40px; font-size: 12px; color: var(--muted); }

/* ---------- viewer ---------- */
.viewer-shell { display: grid; grid-template-columns: 300px minmax(0, 1fr); grid-template-rows: 100vh; height: 100vh; height: 100dvh; grid-template-rows: 100dvh; }
.side {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.side .doc-title { font-weight: 700; line-height: 1.4; }
.side .doc-meta { font-size: 12px; color: var(--muted); }
.toc { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.toc a { display: flex; gap: 8px; padding: 6px 8px; border-radius: 6px; color: var(--text); line-height: 1.35; }
.toc a:hover { background: var(--accent-soft); text-decoration: none; }
.toc a.active { background: var(--accent-soft); font-weight: 650; }
.toc .pg { margin-left: auto; color: var(--muted); font-size: 12px; }
.main { display: grid; grid-template-rows: auto minmax(0, 1fr); min-width: 0; min-height: 0; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 7px 12px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }
.pager { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.pager input { width: 70px; text-align: center; padding: 6px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.scroller { min-height: 0; overflow: auto; background: var(--page-bg); padding: 18px 12px 60px; }
.page { margin: 0 auto 22px; max-width: 840px; }
.page-head { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.page-head .badge { padding: 1px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.page-head button { padding: 3px 9px; font-size: 12px; }
.placeholder { height: 900px; background: var(--paper); opacity: .6; border-radius: 4px; }
.en-wrap { overflow: hidden; }
.en-wrap.fixed { width: 816px; }
.en-wrap.fixed > div { margin: 0 !important; }
.en-wrap.flow { background: #fff; color: #000; padding: 40px 48px; }
.en-wrap img { max-width: 100%; height: auto; }
.zh-page {
  background: var(--paper);
  padding: 36px 44px;
  border-radius: 4px;
  font-size: 15.5px;
  line-height: 1.85;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.zh-page h3 { font-size: 17px; margin: 18px 0 8px; line-height: 1.5; }
.zh-page p { margin: 0 0 12px; text-align: justify; }
.zh-page figure { margin: 12px 0; text-align: center; }
.zh-page figure img { max-width: 100%; height: auto; background: #fff; }
.zh-page .table-wrap { overflow-x: auto; margin: 10px 0 16px; }
.zh-page table { border-collapse: collapse; width: 100%; font-size: 13.5px; line-height: 1.5; }
.zh-page th, .zh-page td { border-bottom: 1px solid var(--line); padding: 5px 8px; vertical-align: top; text-align: left; }
.zh-page th { font-weight: 650; }
.zh-page td.num, .zh-page th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.zh-page .untranslated { color: var(--muted); }
.zh-page .en-line { display: block; color: var(--muted); font-size: 13px; line-height: 1.6; margin-top: 2px; }
.zh-page.empty { color: var(--muted); text-align: center; }
.menu-toggle { display: none; }

.modal { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 40; }
.modal.open { display: flex; }
.dialog { background: var(--panel); border-radius: 14px; width: min(460px, 100%); padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.dialog h3 { margin: 0 0 12px; }
.dialog .field { margin: 12px 0; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.dialog .field > label { font-size: 14px; }
.dialog .field input[type="number"] { width: 90px; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 50;
  max-width: calc(100vw - 32px);
  display: none;
}
.toast.show { display: block; }
#print-root { display: none; }

@media (max-width: 900px) {
  .viewer-shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 25% 0 0; z-index: 35; transform: translateX(-105%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .side.open { transform: none; }
  .menu-toggle { display: inline-flex; }
  .zh-page { padding: 22px 16px; }
  .zh-page p { text-align: left; }
  .en-wrap.flow { padding: 20px 16px; }
  .scroller { padding: 12px 6px 60px; }
  .toolbar .hide-sm { display: none; }
}

@media print {
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block !important; }
  body { background: #fff; color: #000; }
  .print-page { break-after: page; }
  .print-page:last-child { break-after: auto; }
  .print-page .en-wrap.fixed { width: auto; zoom: 1 !important; }
  .print-page .en-wrap.fixed > div { border: 0 !important; box-shadow: none !important; }
  .print-page .zh-page { box-shadow: none; padding: 0; background: #fff; color: #000; }
  .print-page .zh-page th, .print-page .zh-page td { border-color: #ccc; }
  .print-page .zh-page .untranslated, .print-page .zh-page .en-line { color: #555; }
}
