:root {
  --bg: #ffffff;
  --panel: #f7f8fa;
  --panel-strong: #eef1f4;
  --text: #20242c;
  --muted: #697386;
  --line: #e4e7eb;
  --accent: #5b5bd6;
  --accent-soft: #eeeeff;
  --code-bg: #16181d;
  --code-text: #e7eaf0;
  --shadow: 0 18px 50px rgb(20 24 35 / 12%);
  --topbar: 64px;
  --sidebar: 280px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar) + 22px); }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); }
button, input { font: inherit; }
button { cursor: pointer; }

.topbar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 30;
  height: var(--topbar);
  display: grid;
  grid-template-columns: var(--sidebar) minmax(240px, 620px) 1fr;
  align-items: center;
  gap: 24px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(16px);
}

.brand { display: flex; align-items: center; gap: 11px; color: var(--text); font-weight: 700; text-decoration: none; }
.brand-mark {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 9px;
  color: white;
  background: linear-gradient(140deg, #7777e8, #4444bd);
  font-weight: 800;
  box-shadow: 0 5px 16px rgb(91 91 214 / 28%);
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--muted);
  background: var(--panel);
}
.search-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-wrap input { width: 100%; border: 0; outline: 0; color: var(--text); background: transparent; }

.top-actions { justify-self: end; display: flex; gap: 4px; }
.text-button, .icon-button {
  border: 0;
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--muted);
  background: transparent;
}
.text-button:hover, .icon-button:hover { color: var(--text); background: var(--panel-strong); }
.mobile-only { display: none; }

.layout {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 820px) 220px;
  justify-content: center;
  min-height: 100vh;
  padding-top: var(--topbar);
}

.sidebar, .outline {
  position: sticky;
  top: var(--topbar);
  height: calc(100vh - var(--topbar));
  overflow: auto;
  padding: 30px 24px 60px;
}
.sidebar { border-right: 1px solid var(--line); }
.outline { border-left: 1px solid var(--line); }
.sidebar-title { margin: 0 10px 12px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
#toc a, .outline a {
  display: block;
  margin: 2px 0;
  border-radius: 7px;
  padding: 7px 10px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
  text-decoration: none;
}
#toc a[data-level="3"] { padding-left: 25px; font-size: 13px; }
#toc a[data-level="4"] { padding-left: 39px; font-size: 12px; }
#toc a:hover, #toc a.active, .outline a:hover { color: var(--accent); background: var(--accent-soft); }
.outline a { padding: 5px 0 5px 13px; border-left: 1px solid var(--line); border-radius: 0; font-size: 12px; }

.content { width: 100%; min-width: 0; padding: 54px 64px 120px; outline: 0; }
.content > :first-child { margin-top: 0; }
.content h1, .content h2, .content h3, .content h4 { position: relative; color: var(--text); line-height: 1.25; letter-spacing: -.025em; }
.content h1 { margin: 0 0 18px; font-size: clamp(36px, 5vw, 52px); }
.content h2 { margin: 64px 0 20px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 30px; }
.content h3 { margin: 42px 0 15px; font-size: 23px; }
.content h4 { margin: 30px 0 12px; font-size: 18px; }
.heading-anchor { position: absolute; right: 100%; padding-right: 8px; color: var(--accent); opacity: 0; text-decoration: none; }
h1:hover .heading-anchor, h2:hover .heading-anchor, h3:hover .heading-anchor, h4:hover .heading-anchor { opacity: 1; }
.content p, .content li { color: var(--text); font-size: 16px; line-height: 1.75; }
.content p { margin: 12px 0 20px; }
.content ul, .content ol { padding-left: 24px; }
.content li + li { margin-top: 6px; }
.content a { color: var(--accent); text-underline-offset: 3px; }
.content blockquote { margin: 24px 0; padding: 2px 18px; border-left: 3px solid var(--accent); background: var(--accent-soft); }
.content hr { margin: 50px 0; border: 0; border-top: 1px solid var(--line); }

.content code {
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: .15em .38em;
  color: #b42362;
  background: var(--panel);
  font: .88em ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
.code-frame { position: relative; margin: 22px 0 30px; }
.content pre {
  overflow: auto;
  margin: 0;
  border: 1px solid #2a2e37;
  border-radius: 11px;
  padding: 22px;
  background: var(--code-bg);
  box-shadow: 0 8px 28px rgb(12 14 18 / 12%);
}
.content pre code { display: block; border: 0; padding: 0; color: var(--code-text); background: transparent; font-size: 13px; line-height: 1.65; white-space: pre; }
.code-label { position: absolute; top: 9px; left: 12px; color: #9aa3b5; font: 11px ui-monospace, monospace; text-transform: uppercase; }
.code-frame.has-label pre { padding-top: 38px; }
.copy-button { position: absolute; top: 8px; right: 8px; border: 1px solid #383e49; border-radius: 7px; padding: 6px 9px; color: #b9c0cc; background: #23262d; font-size: 12px; }
.copy-button:hover { color: white; background: #30343d; }

.table-wrap { overflow-x: auto; margin: 22px 0 30px; border: 1px solid var(--line); border-radius: 10px; }
.content table { width: 100%; border-collapse: collapse; font-size: 14px; }
.content th { color: var(--muted); background: var(--panel); font-size: 12px; letter-spacing: .04em; text-align: left; text-transform: uppercase; }
.content th, .content td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.content tr:last-child td { border-bottom: 0; }

.loading { padding: 80px 0; color: var(--muted); text-align: center; }
.empty-search { margin: 80px auto; color: var(--muted); text-align: center; }
.search-hidden { display: none !important; }

.login-layer { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(16px); }
.login-layer.hidden { display: none; }
.login-card { width: min(100%, 410px); border: 1px solid var(--line); border-radius: 16px; padding: 34px; background: var(--bg); box-shadow: var(--shadow); }
.login-card .brand-mark { margin-bottom: 22px; }
.login-card h1 { margin: 0 0 8px; font-size: 27px; }
.login-card p { color: var(--muted); line-height: 1.55; }
.login-card label { display: block; margin: 24px 0 7px; font-size: 13px; font-weight: 650; }
.login-card input { width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 12px; color: var(--text); background: var(--panel); outline: 0; }
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card button { width: 100%; margin-top: 13px; border: 0; border-radius: 9px; padding: 12px; color: white; background: var(--accent); font-weight: 700; }
.login-card button:hover { filter: brightness(1.06); }
.form-error { min-height: 22px; margin: 12px 0 0 !important; color: #c93434 !important; font-size: 13px; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 80; transform: translateY(20px); border: 1px solid var(--line); border-radius: 9px; padding: 10px 14px; color: var(--text); background: var(--bg); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .18s ease; }
.toast.visible { transform: translateY(0); opacity: 1; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --panel: #181b20;
    --panel-strong: #22262d;
    --text: #e7eaf0;
    --muted: #98a1b2;
    --line: #2b3038;
    --accent: #9696ff;
    --accent-soft: #242443;
    --shadow: 0 18px 60px rgb(0 0 0 / 38%);
  }
  .content code { color: #ff94bc; }
}

@media (max-width: 1120px) {
  .layout { grid-template-columns: var(--sidebar) minmax(0, 820px); }
  .outline { display: none; }
  .topbar { grid-template-columns: var(--sidebar) minmax(220px, 1fr) auto; }
}

@media (max-width: 760px) {
  :root { --topbar: 58px; }
  .topbar { grid-template-columns: auto 1fr auto; gap: 10px; padding: 0 14px; }
  .mobile-only { display: inline-block; }
  .brand > span:last-child, .search-wrap, .top-actions .text-button:not(#logout) { display: none; }
  .layout { display: block; }
  .sidebar { position: fixed; z-index: 25; top: var(--topbar); bottom: 0; left: 0; width: min(86vw, 320px); height: auto; transform: translateX(-105%); background: var(--bg); box-shadow: var(--shadow); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 38px 22px 90px; }
  .content h2 { margin-top: 50px; font-size: 27px; }
  .content pre { padding: 18px 15px; }
  .heading-anchor { display: none; }
}
