html {
  --sidebar-w: 252px;
  --content-max: 680px;
  --header-h: 52px;
  --mono: "JetBrains Mono", "Cascadia Mono", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --accent: #c45c00;
  --overlay: rgba(0, 0, 0, 0.45);
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 12px);
  scrollbar-width: thin;
}

html[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f7f7f7;
  --text: #2d2d2d;
  --heading: #111111;
  --muted: #666666;
  --ghost: #999999;
  --rule: #e6e6e6;
  --code-bg: #f3f3f3;
  --code-border: #e0e0e0;
  --pre-bg: #f8f8f8;
  --link: #3873ad;
  --link-hover: #245a8a;
  --pager-bg: #f7f7f7;
  --scroll-track: #f0f0f0;
  --scroll-thumb: #c8c8c8;
  --scroll-thumb-hover: #a8a8a8;
  --sidebar-active: #ececec;
  --kw: #8959a8;
  --ty: #c82829;
  --fn: #4271ae;
  --str: #718c00;
  --attr: #4271ae;
}

html[data-theme="dark"] {
  --bg: #121212;
  --surface: #1a1a1a;
  --text: #d4d4d4;
  --heading: #fafafa;
  --muted: #9e9e9e;
  --ghost: #616161;
  --rule: #2e2e2e;
  --code-bg: #1e1e1e;
  --code-border: #383838;
  --pre-bg: #161616;
  --link: #6cb6ff;
  --link-hover: #9cd2ff;
  --pager-bg: #1a1a1a;
  --scroll-track: #1a1a1a;
  --scroll-thumb: #484848;
  --scroll-thumb-hover: #626262;
  --sidebar-active: #2a2a2a;
  --overlay: rgba(0, 0, 0, 0.65);
  --kw: #c792ea;
  --ty: #f07178;
  --fn: #82aaff;
  --str: #c3e88d;
  --attr: #82aaff;
}

html { scrollbar-color: var(--scroll-thumb) var(--scroll-track); }

* { box-sizing: border-box; margin: 0; padding: 0; }

*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: var(--scroll-track); border-radius: 999px; }
*::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 999px;
  border: 2px solid var(--scroll-track);
}
*::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); }

body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

body.nav-open { overflow: hidden; }

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }

code, pre { font-family: var(--mono); font-size: 0.9em; }

code {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 4px;
  padding: 2px 6px;
}

pre {
  background: var(--pre-bg);
  border: 1px solid var(--code-border);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  line-height: 1.55;
  margin: 16px 0;
}
pre code { background: none; border: none; padding: 0; font-size: 13px; }

.syntax .kw { color: var(--kw); }
.syntax .ty { color: var(--ty); }
.syntax .fn { color: var(--fn); }
.syntax .str { color: var(--str); }
.syntax .attr { color: var(--attr); }
.syntax .cmt { color: var(--ghost); font-style: italic; }

/* sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 35;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

body.nav-open .sidebar-overlay {
  opacity: 1;
  pointer-events: auto;
}

.doc-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--rule);
  z-index: 40;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-brand {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--rule);
  flex-shrink: 0;
}

.sidebar-brand a {
  font-weight: 700;
  font-size: 15px;
  color: var(--heading);
  text-decoration: none;
}
.sidebar-brand a:hover { color: var(--link); text-decoration: none; }

.sidebar-ver {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--ghost);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 10px 16px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  margin-bottom: 2px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  border-left: 3px solid transparent;
}
.sidebar-link:hover {
  background: var(--pager-bg);
  color: var(--link);
  text-decoration: none;
}
.sidebar-link.active {
  background: var(--sidebar-active);
  color: var(--heading);
  font-weight: 600;
  border-left-color: var(--accent);
}

.sidebar-num {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ghost);
  width: 20px;
  flex-shrink: 0;
}

.sidebar-foot {
  padding: 12px 14px 16px;
  border-top: 1px solid var(--rule);
  flex-shrink: 0;
}

.sidebar-theme {
  width: 100%;
  justify-content: center;
}

/* main shell */
.doc-shell {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.doc-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 clamp(16px, 4vw, 28px);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}

.menu-btn {
  display: none;
  width: 38px;
  height: 38px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-shrink: 0;
}
.menu-btn span {
  display: block;
  width: 15px;
  height: 2px;
  background: var(--heading);
  border-radius: 1px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
body.nav-open .menu-btn span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
body.nav-open .menu-btn span:nth-child(2) { opacity: 0; }
body.nav-open .menu-btn span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.doc-header .logo {
  font-weight: 600;
  color: var(--heading);
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
}
.doc-header .logo:hover { text-decoration: none; color: var(--link); }

.doc-header .sep { color: var(--ghost); }

.doc-header .section-label {
  color: var(--muted);
  font-size: 13px;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-header .actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-link {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--surface);
  text-decoration: none;
}
.header-link:hover { color: var(--heading); text-decoration: none; }

.theme-toggle {
  background: var(--surface);
  border: 1px solid var(--rule);
  color: var(--muted);
  font-family: var(--sans);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.theme-toggle:hover { color: var(--heading); }

.doc-wrap {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 36px clamp(20px, 4vw, 32px) 32px;
  flex: 1;
}

.doc-meta {
  font-size: 12px;
  color: var(--ghost);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

.doc-wrap h1 {
  font-size: clamp(1.6rem, 5vw, 2rem);
  color: var(--heading);
  line-height: 1.25;
  margin-bottom: 16px;
}

.doc-wrap h2 {
  font-size: 1.2rem;
  color: var(--heading);
  margin: 32px 0 12px;
}

.doc-wrap h3 {
  font-size: 1rem;
  color: var(--heading);
  margin: 24px 0 8px;
}

.doc-wrap p { margin: 12px 0; }

.doc-wrap ul, .doc-wrap ol { margin: 12px 0 12px 22px; }
.doc-wrap li { margin: 6px 0; }

.lead {
  font-size: 1.05rem;
  color: var(--muted);
  margin-bottom: 20px;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 16px 0;
  border: 1px solid var(--rule);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 420px;
}

th, td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule);
}

th {
  background: var(--surface);
  color: var(--heading);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

.chapter-list {
  list-style: none;
  margin: 20px 0 0;
  padding: 0;
}

.chapter-list li { border-bottom: 1px solid var(--rule); }

.chapter-list a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 4px;
  color: var(--text);
  text-decoration: none;
}
.chapter-list a:hover { color: var(--link); text-decoration: none; }

.chapter-list .num {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ghost);
}

.chapter-list .title { font-weight: 500; }

.doc-pager {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 8px clamp(20px, 4vw, 32px) 40px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.pager {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 18px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--pager-bg);
  text-decoration: none;
  min-height: 72px;
  justify-content: center;
}
.pager:hover { border-color: var(--ghost); text-decoration: none; }

.pager .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ghost);
}

.pager .title {
  font-size: 15px;
  font-weight: 600;
  color: var(--heading);
}

.pager.next { text-align: right; align-items: flex-end; }
.pager.disabled { visibility: hidden; pointer-events: none; }

.doc-footer {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 clamp(20px, 4vw, 32px) 36px;
  font-size: 13px;
  color: var(--ghost);
  text-align: center;
}

/* desktop: hide header theme (sidebar has it) */
@media (min-width: 901px) {
  .doc-header .theme-toggle { display: none; }
  .sidebar-overlay { display: none !important; }
  .chapter-list { display: none; }
}

/* mobile */
@media (max-width: 900px) {
  .sidebar-overlay { display: block; }

  .doc-sidebar {
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 8px 0 28px rgba(0, 0, 0, 0.15);
  }
  body.nav-open .doc-sidebar { transform: translateX(0); }

  .doc-shell { margin-left: 0; }

  .menu-btn { display: inline-flex; }

  .doc-header .sep,
  .doc-header .section-label { display: none; }

  .sidebar-foot { display: none; }
  .doc-header .theme-toggle { display: inline-flex; }
}

@media (max-width: 560px) {
  .doc-wrap { padding-top: 28px; }
  .doc-pager { grid-template-columns: 1fr; }
  .pager.next { text-align: left; align-items: flex-start; }
  pre { padding: 12px; font-size: 12px; }
  .doc-header .header-link { display: none; }
}