:root {
  --sidebar-width: 320px;
  --top-height: 88px;
  --toc-width: 276px;
  --bg: #f7fbff;
  --panel: #ffffff;
  --panel-soft: #fbfdff;
  --ink: #152238;
  --muted: #627189;
  --line: #dce7f5;
  --line-strong: #bfd0e6;
  --green: #1f66d1;
  --green-soft: #e8f1ff;
  --blue: #1f66d1;
  --blue-soft: #e8f1ff;
  --amber: #a76621;
  --amber-soft: #f5e6d3;
  --red: #a94943;
  --shadow: 0 14px 30px rgba(21, 34, 56, 0.08);
  color-scheme: light;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  height: 100vh;
  min-height: 720px;
}

.side-panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  min-width: 0;
  overflow: hidden;
}

.side-panel {
  display: flex;
  flex-direction: column;
}

.layout-resize {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--sidebar-width) - 4px);
  z-index: 20;
  width: 8px;
  background: transparent;
  cursor: col-resize;
}

.layout-resize::before {
  display: none;
  content: none;
}

.layout-resize:hover::before,
body.is-resizing .layout-resize::before {
  background: transparent;
}

body.is-resizing {
  cursor: col-resize;
  user-select: none;
}

.content-shell {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background: #fff;
}

.toc-panel {
  position: absolute;
  top: calc(var(--top-height) + 16px);
  right: 16px;
  z-index: 8;
  width: var(--toc-width);
  max-height: calc(100vh - var(--top-height) - 34px);
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

.brand-bar { position: relative; }
.directory-toggle, .search-matches { display: none; }
.version-directory {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  height: var(--top-height);
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.brand:hover {
  background: #f6faff;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-weight: 750;
  letter-spacing: 0;
}

.brand h1,
.reader-top h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.3;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.search-area,
.filter-block {
  padding: 16px 20px 0;
}

.filter-block {
  padding-bottom: 16px;
}

.filter-title {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.sync-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

#syncStatus:empty { display: none; }

.reader-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;
  flex: none;
  min-height: 32px;
  padding: 5px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--green);
  font: inherit;
  font-size: 14px;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  line-height: 20px;
}

.reader-button:hover:not(:disabled) { border-color: var(--green); }
.reader-button:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.reader-button:disabled { color: var(--muted); cursor: default; }
#syncStatus { font-size: 12px; line-height: 1.5; color: var(--muted); }

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 8px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
  outline: none;
}

input {
  height: 38px;
  padding: 0 12px;
}

input::placeholder {
  color: #9aa9bd;
  font-size: 14px;
}

textarea {
  min-height: 112px;
  padding: 11px 12px;
  resize: vertical;
  line-height: 1.6;
}

input:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(31, 102, 209, 0.12);
}

.icon-button {
  width: 34px;
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.year-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.year-filters button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  text-decoration: none;
}

.year-filters button {
  height: 30px;
  padding: 0 11px;
  font-size: 12px;
}

.year-filters button.active {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green);
  font-weight: 700;
}

.result-summary {
  margin: 8px 20px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 16px 0 12px;
  color: var(--ink);
  font-size: 20px;
  font-weight: 760;
}

.result-summary[hidden] {
  display: none;
}

.doc-list {
  flex: 1;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  padding: 16px 12px;
}

.result-summary:not([hidden]) + .doc-list {
  border-top: 0;
}

.doc-year-divider {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 14px 8px 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 780;
  line-height: 1.4;
}

.doc-year-divider:first-child {
  margin-top: 0;
}

.doc-year-divider i {
  display: block;
  height: 1px;
  flex: 1;
  background: var(--line);
}

.doc-item {
  width: 100%;
  margin: 0 0 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  padding: 11px 10px;
  text-align: left;
  color: var(--ink);
}

.doc-item:hover {
  background: var(--panel-soft);
  border-color: var(--line);
}

.doc-item.active {
  background: #eef5ff;
  border-color: rgba(31, 102, 209, 0.26);
}

.doc-item-title strong {
  display: block;
  font-size: 16px;
  line-height: 1.42;
}

.doc-item-meta {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.doc-item small {
  display: block;
  margin-top: 7px;
  color: #536277;
  font-size: 14px;
  line-height: 1.55;
}

.doc-item mark {
  border-radius: 3px;
  padding: 0 2px;
  background: #fff0a8;
  color: inherit;
}

.reader-panel {
  height: 100%;
  min-width: 0;
  overflow-y: auto;
  background: #ffffff;
}

.reader-top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: flex-start;
  gap: 14px;
  align-items: center;
  min-height: var(--top-height);
  padding: 0 34px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}

.reader-top h2 {
  flex: 0 1 auto;
  max-width: min(620px, 58%);
  min-width: 0;
  overflow: hidden;
  font-size: 24px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-actions {
  display: flex;
  flex: 1 1 auto;
  gap: 10px;
  align-items: center;
  justify-content: flex-start;
  min-width: 0;
}

.doc-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 8px;
  min-height: 24px;
}

.doc-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
}

.doc-meta span:nth-child(1) {
  background: var(--blue-soft);
  color: var(--blue);
}

.doc-meta span:nth-child(2) {
  background: var(--amber-soft);
  color: var(--amber);
}

.doc-meta span:nth-child(3) {
  background: var(--green-soft);
  color: var(--green);
}

#sourceLink { margin-left: auto; }

.reader-button[hidden] {
  display: none;
}

.outline-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px 6px 16px;
  background: var(--panel);
  font-size: 14px;
}

.outline-action, .outline-branch {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 400;
}

.outline-action {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 13px;
  white-space: nowrap;
}

.outline-action[hidden] { display: none; }

.section-nav { padding: 0 8px 8px; }
.outline-children { margin-left: 14px; }
.outline-row { display: flex; align-items: center; }
.outline-row > a:only-child { margin-left: 24px; }
.outline-row a, .outline-row .outline-branch {
  display: block;
  flex: 1;
  min-width: 0;
  padding: 6px 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  text-decoration: none;
}

.outline-row a[aria-current="location"] { color: var(--blue); }
.outline-action:hover, .outline-branch:hover, .outline-row a:hover {
  background: var(--blue-soft);
  color: var(--blue);
}

.outline-branch {
  text-align: left;
}

.outline-branch::before {
  display: inline-block;
  margin: 0 12px 2px 3px;
  content: "";
  width: 6px;
  height: 6px;
  border: solid currentColor;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(-45deg);
}
.outline-branch[aria-expanded="true"]::before { transform: rotate(45deg); }

.toc-panel[data-mode="rail"] {
  width: 36px;
  border: 0;
  overflow: hidden;
  background: transparent;
}

.outline-rail {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: space-around;
  gap: 0;
  min-height: 36px;
  height: min(var(--rail-height, 36px), 52vh);
  padding: 4px;
  border: 0;
  background: transparent;
}
.outline-rail[hidden] { display: none; }
.outline-rail span, .outline-rail:empty::before {
  content: "";
  width: 12px;
  height: 2px;
  background: var(--line-strong);
}
.outline-rail .major-tick { width: 20px; }
.outline-rail .current-tick { background: var(--blue); }
.toc-panel[data-mode="preview"] { box-shadow: -6px 8px 20px rgba(21, 34, 56, .08); }
.toc-panel[data-mode="preview"] .outline-action svg { transform: scaleX(-1); }

.section-nav-empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.reading-column {
  margin-inline-end: calc(var(--toc-width) + 16px);
  padding: 36px clamp(20px, 3vw, 64px) 80px;
}

.doc-content {
  max-width: 820px;
  margin-inline: auto;
  overflow-wrap: anywhere;
  line-height: 1.85;
  font-size: 16px;
}

.doc-content h1,
.doc-content h2,
.doc-content h3,
.doc-content h4 {
  margin: 28px 0 12px;
  line-height: 1.35;
  letter-spacing: 0;
}

.doc-content h1 {
  font-size: 26px;
}

.doc-content h2 {
  font-size: 22px;
  padding-top: 4px;
}

.doc-content h3 {
  font-size: 17px;
}

.doc-content p {
  margin: 10px 0;
}

.doc-content > :is(h1, h2) { margin: 48px 0 16px; }
.doc-content > :is(h3, h4) { margin: 36px 0 10px; }
.doc-content > :is(h1, h2) + :is(h2, h3, h4) { margin-top: 18px; }
.doc-content > :first-child { margin-top: 0; }

.doc-content > p, .guide-content p { margin: 12px 0; }
.doc-content li + li { margin-top: 4px; }
.doc-content li > p { margin: 4px 0; }
.doc-content pre { max-width: 100%; overflow-x: auto; }

.doc-content mark.search-hit {
  border-radius: 4px;
  padding: 0 2px;
  background: #fff0a8;
  color: inherit;
}

.doc-content mark.current-hit {
  background: #ffd76a;
  box-shadow: 0 0 0 3px rgba(255, 215, 106, 0.3);
}

.doc-content ul,
.doc-content ol {
  padding-left: 24px;
}

.doc-content table {
  width: 100% !important;
  max-width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.doc-content td,
.doc-content th {
  border: 1px solid var(--line);
  padding: 9px 10px;
  vertical-align: top;
  word-break: break-word;
}

.doc-content th {
  background: var(--panel-soft);
}

.doc-image {
  margin: 12px 0 24px;
}

.doc-image:has(+ .doc-image) {
  margin-bottom: 12px;
}

.doc-image img {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  margin-inline: auto;
  cursor: zoom-in;
}

.doc-image figcaption {
  display: none;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.doc-card {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin: 2px 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
}

.dashboard {
  display: grid;
  gap: 26px;
}

.dashboard-hero {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: #f8fbff;
}

.dashboard-kicker {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 12px;
  font-weight: 760;
}

.dashboard-hero h1 {
  margin-top: 0;
}

.dashboard-hero p:last-child {
  max-width: 680px;
  color: var(--muted);
}

.dashboard-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.dashboard-cards > div {
  display: grid;
  gap: 8px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--panel-soft);
}

.dashboard-card-value {
  display: flex;
  gap: 6px;
  align-items: baseline;
  min-width: 0;
}

.dashboard-cards strong {
  display: block;
  flex: 0 1 auto;
  min-width: 0;
  color: var(--green);
  font-size: 24px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.dashboard-cards span {
  display: block;
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 760;
  white-space: nowrap;
}

.dashboard-cards p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.dashboard-lower {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 28px;
  align-items: start;
}

.year-bars {
  display: grid;
  gap: 10px;
}

.year-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 54px;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.year-row div {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf3fb;
}

.year-row i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.year-row strong {
  color: var(--ink);
  font-weight: 700;
  text-align: right;
}

.dashboard-notes {
  display: grid;
  gap: 10px;
}

.dashboard-notes p {
  margin: 0;
  border-left: 3px solid var(--line);
  padding-left: 12px;
  color: var(--muted);
}

.dashboard-guide {
  border-top: 1px solid var(--line);
  padding-top: 28px;
}

.dashboard-section-head {
  display: flex;
  gap: 12px;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.dashboard-section-head h2 {
  margin: 0;
}

.dashboard-section-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.guide-content {
  max-width: 900px;
}

body.preview-open {
  overflow: hidden;
}

.image-preview {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  place-items: center;
  gap: 14px;
  padding: 52px 40px 32px;
  background: rgba(12, 22, 38, 0.78);
}

.image-preview[hidden] {
  display: none;
}

.image-preview img {
  max-width: min(1180px, 100%);
  max-height: 100%;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.28);
}

.preview-close {
  position: absolute;
  top: 18px;
  right: 22px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 22px;
}

.preview-caption {
  max-width: min(980px, 100%);
  color: rgba(255, 255, 255, 0.88);
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
}

.empty-state {
  padding: 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

@media (max-width: 1180px) {
  :root {
    --toc-width: 238px;
  }

  .app-shell {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: 0;
  }

  .dashboard-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-lower {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 780px) {
  .app-shell {
    display: block;
    height: auto;
    min-height: 100vh;
  }

  .layout-resize {
    display: none;
  }

  .side-panel,
  .reader-panel,
  .toc-panel {
    border: 0;
  }

  .side-panel {
    height: auto;
    border-bottom: 1px solid var(--line);
  }

  .brand { padding-right: 68px; }
  .directory-toggle, .drawer-close {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ink);
  }
  .directory-toggle {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
  }
  .menu-lines {
    width: 20px;
    height: 14px;
    border-block: 2px solid currentColor;
    display: grid;
    align-items: center;
  }
  .menu-lines::after { content: ""; border-top: 2px solid currentColor; }
  .search-area { padding-bottom: 16px; }
  .side-panel { position: relative; z-index: 9; overflow: visible; }
  .search-area { position: relative; }
  .search-matches:not([hidden]) {
    display: block;
    position: absolute;
    top: calc(100% - 10px);
    inset-inline: 20px;
    max-height: min(50dvh, 420px);
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: var(--panel);
    box-shadow: var(--shadow);
  }
  #matchCount {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    color: var(--muted);
    font-size: 13px;
  }
  #matchList .doc-item { margin: 0; border-radius: 0; }
  #matchList .doc-item + .doc-item { border-top-color: var(--line); }
  #matchList .doc-item small {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
  }
  .side-panel > .version-directory { display: none; }
  .directory-drawer {
    position: fixed;
    inset: 0 0 0 auto;
    margin: 0;
    width: min(88vw, 360px);
    max-width: none;
    height: 100%;
    height: 100dvh;
    max-height: none;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) 0;
    border: 0;
    border-left: 1px solid var(--line);
    background: var(--panel);
    color: var(--ink);
  }
  .directory-drawer[open] { display: flex; flex-direction: column; }
  .directory-drawer::backdrop { background: rgb(21 34 56 / 36%); }
  body:has(.directory-drawer[open]) { overflow: hidden; }
  .drawer-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px 8px 20px;
    border-bottom: 1px solid var(--line);
  }
  .drawer-heading h2 { margin: 0; font-size: 18px; }
  .drawer-close { font-size: 24px; }
  .directory-drawer .doc-list { overscroll-behavior: contain; }

  .content-shell {
    overflow: visible;
  }

  .reader-panel {
    height: auto;
    overflow: visible;
  }

  .toc-panel {
    position: static;
    width: auto;
    max-height: 320px;
    margin: 0 18px 18px;
    overflow-y: auto;
    border-top: 1px solid var(--line);
  }

  .toc-panel:not([data-mode="pinned"]) {
    position: fixed;
    top: 30vh;
    right: 4px;
    max-height: 60vh;
    margin: 0;
  }
  .toc-panel[data-mode="preview"] { width: min(300px, 88vw); }

  .reader-top {
    min-height: auto;
    padding: 18px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .reader-actions { grid-column: 1 / -1; grid-row: 2; }
  .sync-row { grid-column: 2; grid-row: 1; max-width: 44vw; }
  .reader-top h2 {
    max-width: 100%;
    white-space: normal;
    font-size: 20px;
  }

  .reading-column { margin-inline-end: 0; padding: 24px 18px 52px; }

  .section-nav {
    padding-left: 18px;
    padding-right: 18px;
  }

  .dashboard-cards,
  .dashboard-lower {
    grid-template-columns: 1fr;
  }

  .image-preview {
    padding: 56px 16px 24px;
  }
}


@media (max-width: 780px) and (prefers-reduced-motion: no-preference) {
  .directory-drawer[open] { animation: drawer-in 180ms ease-out; }
  @keyframes drawer-in { from { transform: translateX(100%); } }
}
