:root {
  color-scheme: light;
  --ink: #222;
  --muted: #666;
  --green: #148472;
  --green-dark: #10725f;
  --green-tint: #eef8f5;
  --line: #efefef;
  --surface: #fff;
  --topbar-height: 55px;
  --rail-width: 64px;
  --sidebar-width: 202px;
  --toolbar-height: 54px;
  --bottom-height: 49px;
  --page-width: 634px;
  font-family: 'Microsoft YaHei', 'PingFang SC', 'Noto Sans CJK SC', system-ui, sans-serif;
  color: var(--ink);
  background: var(--surface);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }
html {
  scroll-padding-top: calc(var(--topbar-height) + var(--toolbar-height) + 18px);
  scroll-padding-bottom: calc(var(--bottom-height) + 16px);
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 12px;
  z-index: 20;
  padding: 10px 14px;
  background: #fff;
  transform: translateY(-160%);
}
.skip-link:focus { transform: translateY(0); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.topbar-content {
  min-height: calc(var(--topbar-height) - 1px);
  padding-right: 19px;
  display: flex;
  align-items: center;
  gap: 19px;
}
.brand-link {
  flex: 0 0 var(--rail-width);
  display: grid;
  place-items: center;
  min-height: calc(var(--topbar-height) - 1px);
  text-decoration: none;
  color: var(--green);
}
.brand-mark {
  width: 29px;
  height: 29px;
  object-fit: contain;
  display: grid;
  place-items: center;
  font-size: 23px;
  font-weight: 700;
  line-height: 1;
}
.copy-button, .directory-toggle, .page-tools {
  display: flex;
  align-items: center;
}
.search-area {
  position: relative;
  flex: 0 1 617px;
  min-width: 0;
}
.search-form {
  display: flex;
  align-items: stretch;
  min-height: 38px;
  border: 1px solid #353535;
  border-radius: 5px;
  background: var(--surface);
}
.search-form input {
  flex: 1;
  width: 100%;
  min-width: 0;
  padding: 0 14px;
  border: 0;
  border-radius: 6px 0 0 6px;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
}
.search-form input::placeholder { color: var(--muted); opacity: 1; }
.search-form:focus-within { border-color: var(--green); }
.search-form input:focus-visible { outline-offset: -2px; }
.search-submit {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  padding: 0 8px;
  border: 0;
  border-radius: 0 4px 4px 0;
  background: #fff;
  color: #333;
}
.search-submit span:last-child:not(.search-icon) { display: none; }
.search-submit:hover { background: var(--green-tint); color: var(--green-dark); }
.search-icon {
  position: relative;
  width: 11px;
  height: 11px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  margin-right: 3px;
}
.search-icon::after {
  position: absolute;
  content: '';
  width: 6px;
  height: 1.5px;
  top: 7px;
  left: 6px;
  transform: rotate(45deg);
  transform-origin: left;
  background: currentColor;
}
.search-panel {
  position: absolute;
  inset: calc(100% + 8px) auto auto 0;
  width: max(100%, 320px);
  border: 1px solid #dedede;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 8px 18px rgb(0 0 0 / 10%);
  overflow: hidden;
}
.search-panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 4px 14px;
  background: #fafafa;
  border-bottom: 1px solid var(--line);
}
#search-count { margin: 0; font-size: 13px; }
.close-search {
  background: transparent;
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  font-size: 13px;
  padding: 8px 10px;
  min-height: 36px;
}
.close-search:hover { background: var(--green-tint); }
.search-results {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: min(54dvh, 364px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.search-results li + li { border-top: 1px solid var(--line); }
.search-results a {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 11px;
  padding: 10px 14px;
  text-decoration: none;
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}
.search-results a:hover, .search-results a:focus-visible { background: var(--green-tint); }
.search-results a:focus-visible { outline-offset: -3px; }
.result-page { color: var(--muted); font-variant-numeric: tabular-nums; }
.search-results mark { border-radius: 2px; background: #f8e8a8; color: inherit; }
.copy-button, .directory-toggle {
  justify-content: center;
  gap: 7px;
  flex: none;
  border: 1px solid #87b7ad;
  border-radius: 5px;
  background: #fff;
  color: var(--green-dark);
  padding: 0 13px;
  min-height: 37px;
  font-size: 13px;
  font-weight: 600;
}
.copy-button:hover, .directory-toggle:hover, .page-button:not(:disabled):hover { background: var(--green-tint); }
.link-icon { position: relative; width: 15px; height: 15px; transform: rotate(-43deg); }
.link-icon::before, .link-icon::after {
  content: '';
  position: absolute;
  left: 4px;
  width: 7px;
  height: 9px;
  border: 1.4px solid currentColor;
  border-radius: 6px;
}
.link-icon::before { top: 0; border-bottom-color: transparent; }
.link-icon::after { bottom: 0; border-top-color: transparent; }

.workspace {
  display: grid;
  grid-template-columns: var(--rail-width) var(--sidebar-width) minmax(0, 1fr);
  min-height: calc(100dvh - var(--topbar-height));
}
.navigation-rail {
  position: sticky;
  top: var(--topbar-height);
  align-self: start;
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - var(--topbar-height));
  background: #fafafa;
  border-right: 1px solid var(--line);
  padding: 10px 3px;
}
.rail-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 56px;
  color: #292929;
  border-radius: 5px;
  text-align: center;
  text-decoration: none;
  font-size: 12px;
  line-height: 1.2;
}
.rail-link:hover, .rail-link[aria-current] { background: var(--green-tint); color: var(--green-dark); }
.rail-symbol { display: grid; place-items: center; width: 18px; height: 18px; font-size: 17px; }
.rail-symbol > svg { width: 100%; height: 100%; }
.sidebar {
  position: sticky;
  top: var(--topbar-height);
  align-self: start;
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - var(--topbar-height) - var(--bottom-height));
  max-height: calc(100dvh - var(--topbar-height) - var(--bottom-height));
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 15px 11px 15px 15px;
  font-size: 12px;
}
.sidebar > nav[aria-labelledby='outline-title'] { display: flex; flex-direction: column; min-height: 0; }
.side-heading { margin: 0 4px 7px; font-size: 13px; font-weight: 600; }
.outline { list-style: none; margin: 0; padding: 3px 2px; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.outline li + li { margin-top: 1px; }
.outline a, .resource {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 6px;
  border-radius: 4px;
  text-decoration: none;
  line-height: 1.5;
}
.outline a { border-left: 2px solid transparent; color: #555; }
.outline a:hover, .resource:hover { background: #f5f5f5; }
.outline a[aria-current] { border-left-color: var(--green); background: var(--green-tint); color: var(--green-dark); font-weight: 600; }
.outline .subsection a { padding-left: 17px; }
.related { flex: none; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.resource { min-height: 38px; color: var(--ink); }
.resource > :nth-child(2) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resource-type {
  flex: 0 0 14px;
  height: 15px;
  border: 1px solid #bcd8e9;
  border-radius: 3px;
  background: #eef6fd;
  color: #3078b4;
  text-align: center;
  font: 700 10px/13px system-ui, sans-serif;
}
.resource-offsite { margin-left: auto; font-size: 13px; flex: none; line-height: 1; color: var(--muted); }

.reader { min-width: 0; }
.reader-toolbar {
  position: sticky;
  top: var(--topbar-height);
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-height: var(--toolbar-height);
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.view-label { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; color: var(--ink); }
.toolbar-stamp { color: var(--muted); font-size: 12px; }
.directory-toggle { display: none; }
.menu-icon { width: 12px; height: 10px; border-block: 1px solid currentColor; }
.menu-icon::after { content: ''; display: block; margin-top: 3px; border-top: 1px solid currentColor; }
.page-tools { gap: 5px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.pagination { margin-right: 6px; white-space: nowrap; }
#current-page { color: var(--ink); font-weight: 700; }
.pagination-divider { margin: 0 3px; color: var(--muted); }
.page-button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid #e5e5e5;
  border-radius: 4px;
  background: #fff;
  color: #333;
}
.page-button:disabled { color: #858585; background: #fafafa; cursor: default; }
.chevron { width: 7px; height: 7px; border: solid currentColor; border-width: 0 1.5px 1.5px 0; }
.chevron.prev { transform: rotate(135deg); }
.chevron.next { transform: rotate(-45deg); }

.pages { width: min(calc(100% - 72px), var(--page-width)); margin: 0 auto calc(var(--bottom-height) + 38px); }
.sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  background: #fff;
  padding: 33px 0 26px;
}
.sheet + .sheet { margin-top: 15px; border-top: 1px solid var(--line); }
.sheet-content {
  flex: 1;
  color: #252525;
  font-family: 'Noto Serif CJK SC', 'Source Han Serif SC', 'Songti SC', SimSun, 'Microsoft YaHei', serif;
  font-size: 22px;
  line-height: 1.86;
  overflow-wrap: anywhere;
}
.sheet-content h1 { margin: 0 0 11px; text-align: center; font-size: 23px; font-weight: 400; line-height: 1.65; }
.sheet-content h2, .sheet-content h3 { margin: 17px 0 7px; line-height: 1.55; }
.sheet-content h2 { font-size: 22px; }
.sheet-content h3 { font-size: 21px; }
.sheet-content p { margin: 0 0 8px; text-indent: 2em; }
.sheet-content p.continuation { text-indent: 0; }
.sheet-content p:last-child { margin-bottom: 0; }
.sheet-content :target { color: var(--green-dark); }
.sheet-content p:target { background: #fff5cd; outline: 4px solid #fff5cd; }
.page-footer { margin: 28px 0 0; color: var(--muted); text-align: center; font: 12px system-ui, sans-serif; }

.bottom-bar {
  position: fixed;
  z-index: 3;
  inset: auto 0 0 var(--rail-width);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: var(--bottom-height);
  padding: 4px 18px 4px 16px;
  border-top: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 -2px 6px rgb(0 0 0 / 3%);
}
.bottom-actions { display: flex; align-items: center; gap: 9px; margin-left: auto; }
.text-action, .download-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex: none;
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 5px;
  background: #fff;
  color: #424242;
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
}
.text-action:hover, .text-action[aria-pressed='true'] { color: var(--green-dark); background: var(--green-tint); }
.download-button { min-width: 122px; background: var(--green); color: #fff; font-weight: 600; }
.download-button:hover { background: var(--green-dark); }
.reading-focus .workspace { grid-template-columns: minmax(0, 1fr); }
.reading-focus .navigation-rail, .reading-focus .sidebar, .reading-focus .directory-toggle { display: none; }
.reading-focus .bottom-bar { left: 0; }

.share-dialog { width: min(440px, calc(100% - 32px)); padding: 22px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); }
.share-dialog::backdrop { background: rgb(0 0 0 / 32%); }
.share-dialog h2 { margin: 0 0 15px; font-size: 18px; }
.share-dialog label { display: block; margin-bottom: 7px; font-size: 13px; }
.share-dialog input { width: 100%; margin-bottom: 14px; padding: 9px; border: 1px solid #ddd; border-radius: 4px; }
.copy-feedback { position: fixed; z-index: 8; right: 18px; bottom: calc(var(--bottom-height) + 12px); margin: 0; padding: 10px 16px; border-radius: 6px; color: #fff; background: #292929; font-size: 14px; }

@media (max-width: 800px) {
  :root { --topbar-height: 56px; --toolbar-height: 48px; --bottom-height: 94px; --rail-width: 44px; }
  .topbar-content { position: relative; padding: 0 12px 0 5px; gap: 4px; }
  .brand-mark { width: 27px; height: 27px; }
  .search-area { position: static; flex: 1 1 0; }
  .search-form { min-height: 40px; }
  .search-form input { font-size: 16px; }
  .search-submit { min-width: 44px; padding: 0 9px; }
  .search-panel { inset: calc(100% + 3px) 12px auto; width: auto; }
  .close-search { min-height: 44px; }
  .copy-button { min-height: 44px; padding: 0 8px; }
  .workspace { display: block; }
  .navigation-rail { display: none; }
  .sidebar { position: static; min-height: 0; max-height: none; padding: 15px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .outline a, .resource { min-height: 43px; }
  .related { margin-bottom: 10px; padding-bottom: 11px; }
  .resource > :nth-child(2) { white-space: normal; }
  .enhanced .sidebar {
    visibility: hidden;
    position: fixed;
    z-index: 4;
    inset: calc(var(--topbar-height) + var(--toolbar-height)) 0 auto 0;
    max-height: calc(100dvh - var(--topbar-height) - var(--toolbar-height) - var(--bottom-height));
    overflow-y: auto;
    box-shadow: 0 5px 13px rgb(0 0 0 / 12%);
  }
  .enhanced .workspace.directory-open .sidebar { visibility: visible; }
  .enhanced .directory-toggle { display: flex; min-height: 40px; margin-left: auto; }
  .reading-focus.enhanced .directory-toggle { display: none; }
  .reader-toolbar { padding: 0 13px; }
  .view-label { font-size: 13px; }
  .toolbar-stamp { display: none; }
  .bottom-bar { left: 0; flex-wrap: wrap; justify-content: center; gap: 0 5px; padding: 2px 8px 4px; }
  .page-tools { width: 100%; justify-content: center; }
  .page-button { width: 40px; height: 40px; }
  .bottom-actions { width: 100%; justify-content: center; gap: 5px; margin-left: 0; }
  .text-action, .download-button { min-height: 44px; padding: 0 7px; }
  .download-button { min-width: 85px; }
  .pages { width: min(calc(100% - 34px), var(--page-width)); }
  .sheet { padding: 27px 0 18px; }
  .sheet + .sheet { margin-top: 11px; }
  .sheet-content { font-size: 16px; line-height: 1.8; }
  .sheet-content h1 { font-size: 22px; margin-bottom: 16px; }
  .sheet-content h2 { font-size: 17px; }
  .sheet-content h3 { font-size: 16px; }
  .page-footer { margin-top: 23px; }
}

@media (max-width: 350px) {
  .bottom-actions { gap: 3px; }
  .bottom-actions .copy-button { gap: 4px; padding: 0 6px; }
  .text-action, .download-button { padding: 0 5px; }
  .download-button { min-width: 72px; }
}

@media print {
  :root { background: #fff; }
  .topbar, .navigation-rail, .sidebar, .reader-toolbar, .bottom-bar, .skip-link, .copy-feedback { display: none !important; }
  .workspace { display: block; }
  .pages { width: auto; margin: 0; }
  .sheet { min-height: auto; border: 0; box-shadow: none; padding: 0; }
  .sheet + .sheet { break-before: page; margin-top: 0; border-top: 0; }
}
