:root {
  color-scheme: light;
  --font-sans: 'Inter', 'SF Pro Text', 'SF Pro Display', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', 'Menlo', 'Consolas', 'Liberation Mono', monospace;
  --bg-canvas: #f4f6fb;
  --bg-gradient: radial-gradient(120% 120% at 0% 0%, rgba(59, 130, 246, 0.12), transparent),
    radial-gradient(140% 140% at 90% 10%, rgba(236, 72, 153, 0.08), transparent);
  --sidebar-surface: rgba(255, 255, 255, 0.96);
  --surface-raised: rgba(255, 255, 255, 0.88);
  --surface-card: rgba(255, 255, 255, 0.92);
  --surface-muted: rgba(255, 255, 255, 0.7);
  --border-subtle: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.16);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --accent-ring: rgba(37, 99, 235, 0.18);
  --shadow-soft: 0 24px 48px rgba(15, 23, 42, 0.12);
  --shadow-strong: 0 28px 80px rgba(15, 23, 42, 0.22);
  --code-bg: #0f172a;
  --code-fg: #e2e8f0;
  --code-border: rgba(148, 163, 184, 0.35);
  --selection-bg: rgba(37, 99, 235, 0.2);
  --selection-fg: inherit;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg-canvas: #030712;
  --bg-gradient: radial-gradient(120% 120% at 0% 0%, rgba(37, 197, 94, 0.12), transparent),
    radial-gradient(140% 140% at 85% 15%, rgba(96, 165, 250, 0.1), transparent);
  --sidebar-surface: rgba(15, 23, 42, 0.9);
  --surface-raised: rgba(15, 23, 42, 0.78);
  --surface-card: rgba(15, 23, 42, 0.82);
  --surface-muted: rgba(15, 23, 42, 0.65);
  --border-subtle: rgba(148, 163, 184, 0.15);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text-primary: #e2e8f0;
  --text-secondary: #cbd5f5;
  --text-muted: rgba(148, 163, 184, 0.68);
  --accent: #60a5fa;
  --accent-strong: #93c5fd;
  --accent-soft: rgba(96, 165, 250, 0.18);
  --accent-ring: rgba(96, 165, 250, 0.32);
  --shadow-soft: 0 28px 72px rgba(2, 6, 23, 0.55);
  --shadow-strong: 0 32px 90px rgba(2, 6, 23, 0.7);
  --code-bg: #020617;
  --code-fg: #f8fafc;
  --code-border: rgba(96, 165, 250, 0.35);
  --selection-bg: rgba(96, 165, 250, 0.3);
  --selection-fg: #0b1120;
}

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

html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.7;
  background: var(--bg-gradient), var(--bg-canvas);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--selection-bg);
  color: var(--selection-fg);
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s ease, box-shadow 0.2s ease;
}

a:hover,
a:focus-visible {
  color: var(--accent-strong);
  box-shadow: 0 1px 0 0 currentColor;
}

button {
  font: inherit;
  color: inherit;
  border: none;
  background: transparent;
  cursor: pointer;
}

.page {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
  position: relative;
}

.sidebar {
  flex: 0 0 290px;
  width: 290px;
  background: var(--sidebar-surface);
  border-right: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 2.5rem 1.9rem 1.75rem;
  overflow-y: auto;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.08);
  transition: flex-basis 0.28s ease, padding 0.28s ease, opacity 0.24s ease,
    transform 0.3s ease, box-shadow 0.3s ease;
  z-index: 1000;
}

.page.sidebar-collapsed .sidebar {
  flex-basis: 0;
  width: 0;
  padding-left: 0;
  padding-right: 0;
  border-right: none;
  box-shadow: none;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}

.page.sidebar-collapsed .sidebar-inner {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.page.sidebar-collapsed .main {
  border-left: none;
}

.sidebar::-webkit-scrollbar {
  width: 8px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.35);
  border-radius: 999px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  opacity: 1;
  transition: opacity 0.22s ease;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 1.75rem;
}

.brand-title {
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-primary);
}

.brand-title:hover {
  color: var(--accent);
}

.brand-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.toc {
  flex: 1;
  margin: 0;
}

.toc-empty {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin: 0;
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.toc-item {
  margin: 0;
}

.toc-item a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  border-radius: 0.75rem;
  border: 1px solid transparent;
  color: var(--text-secondary);
  background: transparent;
  transition: background 0.2s ease, color 0.2s ease, border 0.2s ease, box-shadow 0.2s ease;
}

.toc-item a::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--border-subtle);
  flex-shrink: 0;
  transition: transform 0.2s ease, background 0.2s ease;
}

.toc-item.level-h2 a {
  font-size: 0.93rem;
  padding-left: 1.2rem;
}

.toc-item.level-h3 a {
  font-size: 0.87rem;
  padding-left: 2rem;
}

.toc-item a:hover {
  background: var(--accent-soft);
  border-color: var(--accent-soft);
  color: var(--accent-strong);
}

.toc-item a:hover::before {
  transform: scale(1.2);
  background: var(--accent);
}

.toc-item a.is-active {
  background: var(--accent-soft);
  border-color: var(--accent-ring);
  color: var(--accent-strong);
  box-shadow: 0 10px 24px var(--accent-ring);
}

.toc-item a.is-active::before {
  transform: scale(1.3);
  background: var(--accent-strong);
}

.sidebar-footer {
  margin-top: 1.5rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg-gradient), var(--bg-canvas);
  position: relative;
}

.topbar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.35rem clamp(1.6rem, 4vw, 2.5rem) 1rem;
  background: var(--surface-raised);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  z-index: 900;
}

.topbar-title {
  font-weight: 600;
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-primary);
}

.topbar-title:hover {
  color: var(--accent);
}

.spacer {
  flex: 1;
}

.icon-button {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 0.8rem;
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  background: var(--surface-card);
  transition: transform 0.2s ease, border 0.2s ease, color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: var(--accent-ring);
  color: var(--accent-strong);
  background: var(--accent-soft);
  box-shadow: 0 10px 26px var(--accent-ring);
}

.icon {
  font-size: 1.05rem;
  line-height: 1;
}

.icon-menu::before {
  content: '☰';
}

.icon-theme::before {
  content: '☀';
  font-size: 1rem;
}

:root[data-theme='dark'] .icon-theme::before {
  content: '☾';
}

.search input {
  width: 240px;
  padding: 0.55rem 1rem;
  border-radius: 0.85rem;
  border: 1px solid var(--border-subtle);
  background: var(--surface-card);
  color: var(--text-secondary);
  font-size: 0.95rem;
  transition: border 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.search input::placeholder {
  color: var(--text-muted);
}

.search input:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

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

.content-area {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: clamp(2.5rem, 6vw, 4rem) clamp(1.5rem, 4vw, 4rem) clamp(4rem, 7vw, 5rem);
}

.prose {
  width: min(920px, 100%);
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: 1.75rem;
  padding: clamp(2rem, 3vw, 3.25rem);
  box-shadow: var(--shadow-soft);
}

.prose > :first-child {
  margin-top: 0;
}

.prose > :last-child {
  margin-bottom: 0;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  color: var(--text-primary);
  line-height: 1.25;
  font-weight: 600;
  margin: 3rem 0 1.2rem;
  scroll-margin-top: 6.5rem;
}

.prose h1 {
  font-size: clamp(2.4rem, 5vw, 3.1rem);
  letter-spacing: -0.02em;
  margin-top: 0;
  background: linear-gradient(120deg, var(--accent-strong), var(--text-primary));
  -webkit-background-clip: text;
  color: transparent;
}

.prose h2 {
  font-size: clamp(1.9rem, 4vw, 2.3rem);
  letter-spacing: -0.01em;
}

.prose h3 {
  font-size: clamp(1.45rem, 3vw, 1.7rem);
}

.prose h4 {
  font-size: clamp(1.2rem, 2.5vw, 1.35rem);
}

.prose p {
  margin: 1.1rem 0;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

.prose ul,
.prose ol {
  margin: 1.1rem 0 1.1rem 1.25rem;
  padding-left: 0.9rem;
  color: var(--text-secondary);
  display: grid;
  gap: 0.5rem;
}

.prose li {
  margin: 0.3rem 0;
  overflow-wrap: anywhere;
}

.prose li::marker {
  color: var(--accent);
}

.prose strong {
  color: var(--text-primary);
  font-weight: 600;
}

.prose em {
  font-style: italic;
}

.prose blockquote {
  margin: 2rem 0;
  padding: 1.3rem 1.6rem;
  border-left: 4px solid var(--accent);
  border-radius: 0 1.2rem 1.2rem 0;
  background: var(--accent-soft);
  color: var(--text-secondary);
}

.prose code {
  font-family: var(--font-mono);
  background: var(--accent-soft);
  color: var(--accent-strong);
  padding: 0.15rem 0.45rem;
  border-radius: 0.45rem;
  font-size: 0.92rem;
}

.prose pre {
  background: var(--code-bg);
  color: var(--code-fg);
  font-family: var(--font-mono);
  padding: 1.4rem 1.6rem;
  border-radius: 1.1rem;
  overflow-x: auto;
  margin: 1.6rem 0;
  border: 1px solid var(--code-border);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02), 0 24px 48px rgba(2, 6, 23, 0.4);
}

.prose pre code {
  background: transparent;
  padding: 0;
  font-size: 0.95rem;
  color: inherit;
}

.prose hr {
  border: none;
  height: 1px;
  margin: 3rem 0;
  background: linear-gradient(90deg, transparent, var(--border-strong), transparent);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.8rem 0;
  font-size: 0.95rem;
  overflow: hidden;
  border-radius: 1rem;
  border: 1px solid var(--border-subtle);
  table-layout: fixed;
}

.prose th,
.prose td {
  padding: 0.85rem 1.2rem;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
  word-break: break-word;
  overflow-wrap: anywhere;
  vertical-align: top;
}

.prose th {
  background: var(--surface-muted);
  font-weight: 600;
  color: var(--text-primary);
}

.prose tr:nth-child(even) td {
  background: rgba(148, 163, 184, 0.06);
}

.prose kbd {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 0.2rem 0.5rem;
  border-radius: 0.45rem;
  background: var(--surface-muted);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  box-shadow: inset 0 -2px 0 rgba(15, 23, 42, 0.15);
}

.prose img,
.prose video,
.prose canvas,
.prose iframe {
  max-width: 100%;
  border-radius: 1.2rem;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-soft);
}

.prose details {
  border: 1px solid var(--border-subtle);
  border-radius: 1rem;
  padding: 1rem 1.2rem;
  background: var(--surface-muted);
  margin: 1.5rem 0;
}

.prose summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-primary);
}

.page-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 900;
}

.page-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 1200px) {
  .sidebar {
    width: 260px;
    flex-basis: 260px;
  }
}

@media (max-width: 960px) {
  .sidebar {
    flex: 0 0 auto;
    position: fixed;
    inset: 0 auto 0 0;
    height: 100%;
    transform: translateX(-102%);
    width: min(84vw, 320px);
    box-shadow: var(--shadow-strong);
    border-right: 1px solid var(--border-strong);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .main {
    min-height: 100vh;
  }

  .content-area {
    padding: clamp(2.25rem, 6vw, 3rem) clamp(1.25rem, 6vw, 3rem) clamp(3.5rem, 7vw, 4rem);
  }

  .prose {
    border-radius: 1.3rem;
    padding: clamp(1.75rem, 5vw, 2.4rem);
  }

  .search {
    display: none;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 1.1rem 1.25rem 0.85rem;
  }

  .topbar-title {
    font-size: 1rem;
  }

  .icon-button {
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 0.7rem;
  }

  .content-area {
    padding: 2rem 1.1rem 3rem;
  }

  .prose {
    border-radius: 1.1rem;
    padding: 1.6rem 1.4rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
