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

:root {
  --bg:        #000;
  --surface:   #161618;
  --surface2:  #1e1e20;
  --border:    rgba(255,255,255,0.07);
  --text:      #f5f5f7;
  --text2:     #98989d;
  --accent:    #e8613a;
  --blue:      #4a9eff;
  --sidebar-w: 260px;
  --nav-h:     52px;
  --font:      -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", sans-serif;
  --mono:      "SF Mono", "Fira Code", Consolas, monospace;
}

html { scroll-behavior: smooth; font-size: 16px; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--font); -webkit-font-smoothing: antialiased;
}

/* NAV */
.top-nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: var(--nav-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px 0 calc(var(--sidebar-w) + 24px);
  background: rgba(0,0,0,0.88);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
}
.nav-logo {
  font-size: 16px; font-weight: 700; letter-spacing: -0.4px;
  color: var(--text); text-decoration: none;
}
.nav-logo em { font-style: normal; color: var(--accent); }
.nav-logo .nav-section { color: var(--text2); font-weight: 400; font-size: 13px; margin-left: 8px; }
.lang-toggle {
  display: flex; gap: 2px; background: var(--surface); border-radius: 8px; padding: 3px;
}
.lang-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text2); font-size: 12px; font-weight: 500;
  padding: 4px 10px; border-radius: 5px;
  transition: all 0.15s; text-decoration: none; display: inline-block;
}
.lang-btn.active { background: var(--surface2); color: var(--text); }
.lang-btn:hover:not(.active) { color: var(--text); }
.hamburger {
  display: none; flex-direction: column; gap: 5px;
  background: none; border: none; cursor: pointer; padding: 4px;
}
.hamburger span { width: 20px; height: 2px; background: var(--text); border-radius: 1px; display: block; }

/* LAYOUT */
.layout { display: flex; margin-top: var(--nav-h); min-height: calc(100vh - var(--nav-h)); }

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  position: fixed; top: var(--nav-h); bottom: 0; left: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto; overscroll-behavior: contain;
  padding: 12px 0 72px;
}
.sidebar-top { padding: 0 16px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.sidebar-home {
  font-size: 12px; color: var(--text2); text-decoration: none;
  display: flex; align-items: center; gap: 6px; padding: 6px 0;
}
.sidebar-home:hover { color: var(--text); }
.toc-section { margin-bottom: 2px; }
.toc-section-title {
  display: block; padding: 8px 16px 3px;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em; color: var(--text2);
}
.toc-section ul { list-style: none; }
.toc-section ul li a {
  display: block; padding: 6px 16px 6px 20px;
  font-size: 13px; color: var(--text2); text-decoration: none;
  border-left: 2px solid transparent; margin-left: 4px;
  transition: all 0.12s; border-radius: 0 4px 4px 0;
}
.toc-section ul li a:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.toc-section ul li.active a {
  color: var(--text); border-left-color: var(--accent);
  background: rgba(232,97,58,0.09);
}
.sidebar-footer {
  position: fixed; bottom: 0; left: 0; width: var(--sidebar-w);
  padding: 10px 16px; background: var(--surface);
  border-top: 1px solid var(--border); border-right: 1px solid var(--border);
}
.sidebar-pdf {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text2); text-decoration: none;
  padding: 7px 10px; border-radius: 6px; background: var(--surface2); transition: all 0.15s;
}
.sidebar-pdf:hover { color: var(--text); }

/* CONTENT */
.content {
  flex: 1; margin-left: var(--sidebar-w);
  padding: 48px 60px 80px; max-width: 880px; min-width: 0;
}
.content h1 {
  font-size: 2rem; font-weight: 700; letter-spacing: -0.5px;
  color: var(--text); margin-bottom: 20px; line-height: 1.2;
}
.content h2 {
  font-size: 1.3rem; font-weight: 600; letter-spacing: -0.2px;
  color: var(--text); margin: 36px 0 14px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.content h3 { font-size: 1.05rem; font-weight: 600; color: var(--text); margin: 24px 0 10px; }
.content h4 { font-size: 0.95rem; font-weight: 600; color: var(--text2); margin: 18px 0 8px; }
.content p { font-size: 0.975rem; line-height: 1.72; color: var(--text); margin-bottom: 14px; }
.content ul, .content ol { margin: 0 0 14px 22px; }
.content li { font-size: 0.975rem; line-height: 1.68; color: var(--text); margin-bottom: 4px; }
.content a { color: var(--blue); text-decoration: none; }
.content a:hover { text-decoration: underline; }
.content strong { font-weight: 600; }
.content blockquote {
  border-left: 3px solid var(--accent); background: rgba(232,97,58,0.07);
  padding: 10px 16px; margin: 16px 0; border-radius: 0 6px 6px 0;
}
.content blockquote p { margin: 0; color: var(--text2); font-size: 0.95rem; }
.content code {
  font-family: var(--mono); font-size: 0.87em;
  background: var(--surface2); padding: 2px 5px; border-radius: 3px; color: #e6db74;
}
.content pre {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 16px; margin: 16px 0; overflow-x: auto;
}
.content pre code { background: none; padding: 0; font-size: 0.85rem; line-height: 1.6; color: var(--text); }
.content table { width: 100%; border-collapse: collapse; margin: 20px 0; font-size: 0.9rem; }
.content th {
  text-align: left; padding: 9px 14px; background: var(--surface); color: var(--text2);
  font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}
.content td { padding: 9px 14px; border-bottom: 1px solid var(--border); }
.content tr:last-child td { border-bottom: none; }
.content tr:hover td { background: rgba(255,255,255,0.02); }
.content hr { border: none; border-top: 1px solid var(--border); margin: 28px 0; }

/* SCREENSHOTS */
.content img:not(.inline-icon) {
  max-width: 260px; height: auto; border-radius: 16px;
  display: inline-block; margin: 8px 6px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  vertical-align: top;
}
/* INLINE ICONS */
img.inline-icon {
  display: inline-block; height: 1.15em; width: auto;
  vertical-align: middle; margin: 0 2px -1px;
  border-radius: 3px; box-shadow: none !important; max-width: none !important;
}

/* CHAPTER NAV */
.chapter-nav {
  display: flex; justify-content: space-between; gap: 12px;
  margin-top: 56px; padding-top: 24px; border-top: 1px solid var(--border);
}
.chapter-nav a {
  display: flex; flex-direction: column; gap: 3px;
  padding: 12px 16px; border-radius: 8px;
  background: var(--surface); color: var(--text2);
  text-decoration: none; font-size: 13px;
  border: 1px solid var(--border); transition: all 0.15s;
  max-width: 260px; min-width: 0;
}
.chapter-nav a:hover { color: var(--text); border-color: rgba(255,255,255,0.14); }
.chapter-nav .nav-dir { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; }
.chapter-nav .nav-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chapter-nav .next-link { text-align: right; margin-left: auto; }

/* MOBILE */
.sidebar-overlay { display: none; position: fixed; inset: 0; z-index: 150; background: rgba(0,0,0,0.6); }
@media (max-width: 780px) {
  .top-nav { padding-left: 16px; }
  .hamburger { display: flex; }
  .sidebar { transform: translateX(-100%); transition: transform 0.25s ease; z-index: 160; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .sidebar-footer { display: none; }
  .content { margin-left: 0; padding: 24px 18px 60px; }
  .content img:not(.inline-icon) { max-width: min(260px, 100%); }
}
