:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-solid: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --border: rgba(0, 0, 0, 0.11);
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.12);
  --code-bg: #f1f2f4;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.10);
  --reader-font-size: 18px;
  --reader-line-height: 1.72;
  --sidebar-width: 340px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #161618;
    --panel: rgba(34, 34, 37, 0.78);
    --panel-solid: #242428;
    --text: #f5f5f7;
    --muted: #a1a1a6;
    --border: rgba(255, 255, 255, 0.12);
    --accent: #5e9eff;
    --accent-soft: rgba(94, 158, 255, 0.17);
    --code-bg: #1d1d20;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.42);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161618;
  --panel: rgba(34, 34, 37, 0.78);
  --panel-solid: #242428;
  --text: #f5f5f7;
  --muted: #a1a1a6;
  --border: rgba(255, 255, 255, 0.12);
  --accent: #5e9eff;
  --accent-soft: rgba(94, 158, 255, 0.17);
  --code-bg: #1d1d20;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.42);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f5f7;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-solid: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --border: rgba(0, 0, 0, 0.11);
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.12);
  --code-bg: #f1f2f4;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.10);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(10, 132, 255, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(48, 209, 88, 0.08), transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

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

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 180ms ease;
}

body.sidebar-hidden .app-shell {
  grid-template-columns: 0 minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 20px 18px 18px;
  overflow: visible;
  border-right: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(22px) saturate(180%);
  transition: opacity 160ms ease, transform 160ms ease;
  min-width: 0;
}

body.sidebar-hidden .sidebar {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-12px);
  padding-left: 0;
  padding-right: 0;
  border-right: 0;
}

.sidebar-reveal {
  position: fixed;
  left: 0;
  top: 50%;
  z-index: 30;
  display: none;
  width: 24px;
  height: 58px;
  border: 1px solid var(--border);
  border-left: 0;
  border-radius: 0 8px 8px 0;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(180%);
  cursor: pointer;
  transform: translateY(-50%);
}

body.sidebar-hidden .sidebar-reveal {
  display: block;
}

.brand {
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.doc-switcher {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.sidebar-kicker {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.doc-switcher select {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 9px;
  background: var(--panel-solid);
  color: var(--text);
  font-size: 17px;
  font-weight: 760;
  outline: none;
}

.doc-switcher p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.sidebar-edge-toggle {
  position: absolute;
  top: 22px;
  right: -13px;
  z-index: 4;
  width: 26px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(18px) saturate(180%);
  cursor: pointer;
}

.sidebar-edge-toggle:hover,
.sidebar-reveal:hover {
  color: var(--text);
  background: var(--accent-soft);
}

.sidebar-resizer {
  position: absolute;
  top: 0;
  right: -5px;
  z-index: 3;
  width: 10px;
  height: 100%;
  cursor: col-resize;
}

.sidebar-resizer::after {
  content: "";
  position: absolute;
  top: 84px;
  right: 4px;
  width: 2px;
  height: 54px;
  border-radius: 2px;
  background: transparent;
  transition: background 120ms ease;
}

.sidebar-resizer:hover::after,
body.resizing-sidebar .sidebar-resizer::after {
  background: var(--accent);
}

.sidebar-tools {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.search-box {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 680;
}

.search-box input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 13px;
  color: var(--text);
  background: var(--panel-solid);
  outline: none;
}

.theme-control select,
.font-control input {
  min-height: 32px;
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chip,
.icon-button,
.text-button {
  border: 1px solid var(--border);
  background: var(--panel-solid);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
}

.chip {
  max-width: 100%;
  min-height: 30px;
  padding: 4px 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.chip.active {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
}

.toc {
  height: calc(100vh - 184px);
  margin-top: 14px;
  overflow: auto;
  padding: 4px 4px 18px 0;
}

.toc a {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 10px 7px 14px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.35;
  transition: background 120ms ease, color 120ms ease;
}

.toc a::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 3px;
  background: transparent;
}

.toc a:hover,
.toc a.active {
  background: var(--accent-soft);
  color: var(--text);
}

.toc a.active::before {
  background: var(--accent);
}

.toc a.depth-2 {
  color: var(--text);
  font-weight: 720;
}

.toc a.depth-3 {
  margin-left: 10px;
  padding-left: 16px;
}

.toc a.depth-4 {
  margin-left: 22px;
  padding-left: 16px;
  font-size: 12px;
}

.content {
  min-width: 0;
  padding: 18px clamp(18px, 4vw, 54px) 54px;
}

.toolbar {
  position: sticky;
  top: 18px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 70px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(22px) saturate(180%);
  box-shadow: var(--shadow);
  transform: translateY(0);
  transition: transform 180ms ease, opacity 180ms ease, box-shadow 180ms ease;
  will-change: transform;
}

body.toolbar-hidden .toolbar {
  opacity: 0;
  pointer-events: none;
  transform: translateY(calc(-100% - 28px));
  box-shadow: none;
}

body.toolbar-hidden:not(.reader-mode) .toolbar:focus-within {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.toolbar-title {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

#docTitle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.font-control,
.theme-control {
  display: grid;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.font-control {
  grid-template-columns: auto 118px 24px;
}

.theme-control {
  grid-template-columns: auto 112px;
}

.font-control input {
  accent-color: var(--accent);
}

.theme-control select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 9px;
  background: var(--panel-solid);
  color: var(--text);
}

.icon-button {
  width: 38px;
  height: 38px;
  font-size: 20px;
}

.text-button {
  min-width: 58px;
  height: 38px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 720;
}

.text-button[aria-pressed="true"] {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
}

.status-strip {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin: 18px auto;
  max-width: 1120px;
  color: var(--muted);
  font-size: 13px;
}

#matchText:not(:empty)::before {
  content: " · ";
}

.article {
  max-width: 1120px;
  margin: 0 auto;
}

body.reader-mode .app-shell {
  grid-template-columns: 1fr;
}

body.reader-mode .sidebar,
body.reader-mode .sidebar-reveal,
body.reader-mode .status-strip {
  display: none;
}

body.reader-mode .content {
  padding-inline: clamp(18px, 9vw, 132px);
}

body.reader-mode .toolbar {
  max-width: 880px;
  margin: 0 auto;
  box-shadow: none;
}

body.reader-mode .article {
  max-width: 820px;
}

body.reader-mode .section {
  padding: 22px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.section {
  content-visibility: auto;
  contain-intrinsic-size: auto 760px;
  margin-bottom: 16px;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-solid);
  box-shadow: 0 6px 26px rgba(0, 0, 0, 0.05);
}

.section.lead {
  border-color: rgba(10, 132, 255, 0.24);
}

.section h1,
.section h2,
.section h3,
.section h4 {
  margin: 0 0 0.7em;
  line-height: 1.25;
  scroll-margin-top: 116px;
}

.section h1 { font-size: calc(var(--reader-font-size) * 1.75); }
.section h2 { font-size: calc(var(--reader-font-size) * 1.42); }
.section h3 { font-size: calc(var(--reader-font-size) * 1.18); }
.section h4 { font-size: calc(var(--reader-font-size) * 1.05); }

.section p,
.section li,
.section td,
.section th {
  font-size: var(--reader-font-size);
  line-height: var(--reader-line-height);
}

.section p {
  margin: 0 0 1em;
}

.section ul,
.section ol {
  margin: 0 0 1em 1.25em;
  padding: 0;
}

.section li + li {
  margin-top: 0.2em;
}

.section a {
  color: var(--accent);
  text-decoration: none;
}

.section a:hover {
  text-decoration: underline;
}

.table-wrap {
  overflow: auto;
  margin: 18px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th,
td {
  padding: 11px 13px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: var(--code-bg);
  font-weight: 760;
}

tr:last-child td {
  border-bottom: 0;
}

pre {
  overflow: auto;
  margin: 18px 0;
  padding: 16px;
  border-radius: 8px;
  background: var(--code-bg);
  border: 1px solid var(--border);
}

code {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
}

p code,
li code,
td code {
  padding: 0.12em 0.32em;
  border-radius: 6px;
  background: var(--code-bg);
}

blockquote {
  margin: 16px 0;
  padding: 12px 16px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 360px;
  padding: 32px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-solid);
}

.empty-state h2 {
  margin: 0;
}

.empty-state p {
  color: var(--muted);
}

mark {
  border-radius: 4px;
  padding: 0 0.15em;
  background: rgba(255, 204, 0, 0.42);
  color: inherit;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-resizer,
  .sidebar-edge-toggle {
    display: none;
  }

  .toc {
    height: auto;
    max-height: 260px;
  }

  .toolbar {
    top: 10px;
    align-items: stretch;
    flex-direction: column;
  }

  .controls,
  .font-control,
  .theme-control {
    width: 100%;
  }

  .font-control {
    grid-template-columns: auto minmax(0, 1fr) 28px;
  }

  .theme-control {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .status-strip {
    flex-direction: column;
  }

  .section {
    padding: 20px;
  }
}
