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

:root {
  color-scheme: light;
  --bg: #f7f8f6;
  --paper: #fffefa;
  --sidebar: #eef2ef;
  --sidebar-strong: #e5ebe7;
  --surface: #ffffff;
  --surface-subtle: #f3f5f2;
  --border: #dfe5df;
  --border-strong: #c7d0ca;
  --text: #18201c;
  --text-muted: #65716b;
  --text-faint: #9aa49e;
  --accent: #315fef;
  --accent-soft: #e8edff;
  --accent-ink: #1737a6;
  --accent-glow: rgba(49, 95, 239, 0.2);
  --green: #2c7a5b;
  --amber: #a36a18;
  --code-bg: #f1f4f1;
  --code-text: #24312b;
  --pre-bg: #111713;
  --pre-text: #edf5ef;
  --quote-bg: #edf5ef;
  --quote-text: #35433b;
  --table-head: #f0f4f1;
  --table-hover: #fafbf8;
  --scroll-thumb: #cfd8d2;
  --nav-hover: rgba(255, 255, 255, 0.62);
  --nav-active: #ffffff;
  --body-wash-1: rgba(49, 95, 239, 0.04);
  --body-wash-2: rgba(44, 122, 91, 0.08);
  --shadow: 0 18px 48px rgba(44, 54, 48, 0.08);
  --read-progress: 0%;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #09090b;
  --paper: #09090b;
  --sidebar: #0c0c0f;
  --sidebar-strong: #09090b;
  --surface: #18181b;
  --surface-subtle: #27272a;
  --border: #27272a;
  --border-strong: #3f3f46;
  --text: #fafafa;
  --text-muted: #d4d4d8;
  --text-faint: #a1a1aa;
  --accent: #fafafa;
  --accent-soft: #27272a;
  --accent-ink: #fafafa;
  --accent-glow: rgba(250, 250, 250, 0.12);
  --green: #e4e4e7;
  --amber: #fafafa;
  --code-bg: #18181b;
  --code-text: #f4f4f5;
  --pre-bg: #09090b;
  --pre-text: #fafafa;
  --quote-bg: #18181b;
  --quote-text: #e4e4e7;
  --table-head: #18181b;
  --table-hover: #18181b;
  --scroll-thumb: #3f3f46;
  --nav-hover: #18181b;
  --nav-active: #18181b;
  --body-wash-1: transparent;
  --body-wash-2: transparent;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.3);
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  display: flex;
  background:
    linear-gradient(90deg, var(--body-wash-1), transparent 38%),
    radial-gradient(circle at 82% 10%, var(--body-wash-2), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family: "Instrument Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 320px;
  right: 0;
  height: 3px;
  z-index: 10;
  background:
    linear-gradient(90deg, var(--accent) var(--read-progress), transparent 0),
    var(--border);
}

body.sidebar-collapsed::before {
  left: 0;
}

.sidebar {
  width: 320px;
  min-width: 320px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: color-mix(in srgb, var(--sidebar) 92%, white);
  border-right: 1px solid var(--border);
  transition: width 220ms ease, min-width 220ms ease, border-color 220ms ease, opacity 180ms ease;
  will-change: width;
}

body.sidebar-collapsed .sidebar {
  width: 0;
  min-width: 0;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  border-right-color: transparent;
}

:root[data-theme="dark"] .sidebar {
  background: color-mix(in srgb, var(--sidebar) 92%, black);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 76px;
  padding: 16px 16px 14px;
  background: var(--sidebar-strong);
  border-bottom: 1px solid var(--border);
}

.reader-kicker {
  color: var(--text-faint);
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  font-weight: 650;
  line-height: 1.2;
  text-transform: uppercase;
}

.reader-title {
  margin-top: 4px;
  color: var(--text);
  font-family: "Newsreader", Georgia, serif;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
}

.reader-toolbar {
  position: sticky;
  top: 3px;
  z-index: 9;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 10px 24px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 76%, transparent);
  backdrop-filter: blur(16px);
}

.icon-button,
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.icon-button {
  width: 38px;
  min-width: 38px;
  padding: 7px;
}

.theme-toggle {
  min-width: 86px;
  padding: 7px 9px;
}

.icon-button:hover,
.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--text);
  box-shadow: 0 0 0 4px var(--accent-glow);
}

.icon-button:focus-visible,
.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.sidebar-toggle-icon {
  position: relative;
  width: 15px;
  height: 12px;
  flex: 0 0 auto;
  background:
    linear-gradient(var(--text-muted), var(--text-muted)) left 0 top 0 / 15px 2px no-repeat,
    linear-gradient(var(--text-muted), var(--text-muted)) left 0 top 5px / 15px 2px no-repeat,
    linear-gradient(var(--text-muted), var(--text-muted)) left 0 top 10px / 15px 2px no-repeat;
}

body.sidebar-collapsed .sidebar-toggle-icon {
  background:
    linear-gradient(var(--accent), var(--accent)) left 0 top 0 / 15px 2px no-repeat,
    linear-gradient(var(--accent), var(--accent)) left 0 top 5px / 15px 2px no-repeat,
    linear-gradient(var(--accent), var(--accent)) left 0 top 10px / 15px 2px no-repeat;
}

.theme-toggle-track {
  position: relative;
  width: 34px;
  height: 18px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
}

.theme-toggle-knob {
  position: absolute;
  top: 50%;
  left: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  transform: translateY(-50%);
  transition: transform 180ms ease, background 180ms ease;
}

:root[data-theme="dark"] .theme-toggle-knob {
  transform: translate(15px, -50%);
  background: var(--amber);
}

.nav {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 28px;
}

.nav::-webkit-scrollbar,
.main::-webkit-scrollbar {
  width: 8px;
}

.nav::-webkit-scrollbar-thumb,
.main::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border: 2px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}

.nav-item {
  position: relative;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  min-height: 44px;
  margin-bottom: 3px;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.nav-item:hover {
  background: var(--nav-hover);
  border-color: var(--border);
  color: var(--text);
}

.nav-item.active {
  background: var(--nav-active);
  border-color: var(--border-strong);
  color: var(--text);
  box-shadow: 0 10px 30px rgba(28, 38, 32, 0.06);
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 999px;
  background: var(--accent);
}

.num {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
  line-height: 1.35;
}

.nav-item.active .num {
  color: var(--accent);
}

.nav-label {
  min-width: 0;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.32;
}

.main {
  position: relative;
  flex: 1;
  height: 100vh;
  overflow-y: auto;
}

.article {
  width: min(1120px, calc(100vw - 380px));
  margin: 0 auto;
  padding: 42px 48px 120px;
  transition: width 220ms ease, padding 220ms ease;
}

body.sidebar-collapsed .article {
  width: min(1120px, calc(100vw - 96px));
}

.article-hero {
  display: grid;
  max-width: 780px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border);
}

.article-hero h1 {
  max-width: 760px;
  font-family: "Newsreader", Georgia, serif;
  font-size: clamp(30px, 3.4vw, 44px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: 0;
}

.article-layout {
  display: grid;
  grid-template-columns: minmax(0, 760px) 220px;
  gap: 72px;
  align-items: start;
  padding-top: 42px;
}

.article-content {
  min-width: 0;
  color: var(--text);
  font-size: 17px;
  line-height: 1.78;
}

.article-content h2,
.article-content h3 {
  scroll-margin-top: 34px;
}

.article-content h2 {
  margin: 44px 0 16px;
  font-family: "Newsreader", Georgia, serif;
  font-size: 24px;
  font-weight: 650;
  line-height: 1.12;
}

.article-content h2:first-child {
  margin-top: 0;
}

.article-content h3 {
  margin: 28px 0 10px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.35;
}

.article-content p {
  margin-bottom: 18px;
}

.article-content strong {
  font-weight: 700;
}

.article-content em {
  color: var(--text-muted);
}

.article-content a {
  color: var(--accent-ink);
  text-decoration: none;
  border-bottom: 1px solid rgba(49, 95, 239, 0.28);
}

.article-content a:hover {
  border-bottom-color: var(--accent);
}

.article-content ul,
.article-content ol {
  margin: 0 0 22px;
  padding-left: 24px;
}

.article-content li {
  margin-bottom: 8px;
  padding-left: 4px;
}

.article-content li::marker {
  color: var(--green);
}

.article-content blockquote {
  margin: 26px 0;
  padding: 18px 22px;
  border-left: 3px solid var(--green);
  background: var(--quote-bg);
  border-radius: 0 8px 8px 0;
  color: var(--quote-text);
}

.article-content blockquote p:last-child {
  margin-bottom: 0;
}

.article-content code {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.84em;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--code-bg);
  color: var(--code-text);
}

.article-content pre {
  margin: 24px 0;
  padding: 18px 20px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--pre-bg);
  color: var(--pre-text);
  box-shadow: var(--shadow);
}

.article-content pre code {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
}

.article-content hr {
  height: 1px;
  margin: 34px 0;
  border: 0;
  background: linear-gradient(90deg, transparent, var(--border-strong), transparent);
}

.article-content table {
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 20px 0 30px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  border-spacing: 0;
  border-collapse: separate;
  background: var(--surface);
  box-shadow: 0 14px 36px rgba(44, 54, 48, 0.06);
  font-size: 14px;
  line-height: 1.48;
}

.article-content thead {
  background: var(--table-head);
}

.article-content th,
.article-content td {
  min-width: 150px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.article-content th {
  color: var(--text-muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

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

.article-content tbody tr:hover {
  background: var(--table-hover);
}

.toc {
  position: sticky;
  top: 42px;
  display: grid;
  gap: 4px;
  padding-left: 18px;
  border-left: 1px solid var(--border);
}

.toc-label {
  margin-bottom: 8px;
  color: var(--text-faint);
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.toc-link {
  padding: 7px 0;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  text-decoration: none;
}

.toc-link.h3 {
  padding-left: 12px;
  font-weight: 500;
}

.toc-link:hover {
  color: var(--accent-ink);
}

.welcome {
  min-height: 62vh;
  display: grid;
  place-content: center;
  gap: 12px;
  text-align: center;
}

.welcome h1 {
  font-family: "Newsreader", Georgia, serif;
  font-size: 62px;
  line-height: 0.95;
}

.welcome p {
  color: var(--text-muted);
  font-size: 16px;
}

.welcome .subtitle {
  color: var(--text-faint);
  font-size: 13px;
}

@media (max-width: 1320px) {
  body::before {
    left: 280px;
  }

  .sidebar {
    width: 280px;
    min-width: 280px;
  }

  .article {
    width: min(100%, calc(100vw - 280px));
    padding: 56px 32px 96px;
  }

  body.sidebar-collapsed .article {
    width: min(100%, calc(100vw - 64px));
  }

  .article-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .toc {
    display: none;
  }
}

@media (max-width: 760px) {
  html,
  body {
    overflow: auto;
  }

  body {
    display: block;
  }

  body::before {
    left: 0;
  }

  .sidebar {
    width: 100%;
    min-width: 0;
    height: auto;
    max-height: 42vh;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  body.sidebar-collapsed .sidebar {
    width: 100%;
    max-height: 0;
    opacity: 0;
    border-bottom-color: transparent;
  }

  .sidebar-header {
    min-height: auto;
    padding: 12px 14px;
  }

  .reader-toolbar {
    top: 3px;
    min-height: 54px;
    padding: 8px 12px;
  }

  .nav {
    padding: 10px 10px 14px;
  }

  .nav-item {
    min-height: auto;
  }

  .main {
    height: auto;
    min-height: 58vh;
    overflow: visible;
  }

  .article {
    width: 100%;
    padding: 32px 22px 76px;
  }

  body.sidebar-collapsed .article {
    width: 100%;
  }

  .article-hero {
    gap: 14px;
    padding-bottom: 26px;
  }

  .article-hero h1 {
    font-size: clamp(29px, 8vw, 38px);
  }

  .article-layout {
    padding-top: 30px;
  }

  .article-content {
    font-size: 16px;
  }
}
