:root {
  --bg: #f8fafc;
  --sidebar-bg: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --card-bg: #ffffff;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --radius: 10px;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --sidebar-bg: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --accent: #818cf8;
  --accent-hover: #6366f1;
  --card-bg: #1e293b;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  font-size: 16px;
  background-image: radial-gradient(circle at 1px 1px, rgba(0,0,0,0.015) 1px, transparent 0);
  background-size: 20px 20px;
}

[data-theme="dark"] body {
  background-image: radial-gradient(circle at 1px 1px, rgba(255,255,255,0.02) 1px, transparent 0);
}

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 1.75rem 1.25rem;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}

.sidebar-header h1 {
  font-size: 1.2rem;
  font-weight: 650;
  margin-bottom: 1.75rem;
  letter-spacing: -0.02em;
}

.sidebar nav a {
  display: block;
  padding: 0.65rem 0.9rem;
  color: var(--text);
  text-decoration: none;
  border-radius: 8px;
  margin-bottom: 0.3rem;
  font-size: 0.95rem;
  transition: background 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar nav a:hover { background: rgba(79, 70, 229, 0.08); }
.sidebar nav a.active {
  background: var(--accent);
  color: white;
  font-weight: 500;
}

.sidebar-footer { margin-top: auto; padding-top: 1.25rem; }

#themeToggle {
  width: 100%;
  padding: 0.6rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}
#themeToggle:hover { background: rgba(0,0,0,0.03); }

.content-wrapper {
  flex: 1;
  min-width: 0;
  padding-right: 240px;
}

main {
  padding: 2.5rem 3rem;
  max-width: 780px;
}

.toc {
  width: 240px;
  padding: 2.5rem 1.5rem 2rem 1.25rem;
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--sidebar-bg);
  border-left: 1px solid var(--border);
  z-index: 5;
}

.toc h4 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  font-weight: 600;
}

.toc a {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.35rem 0.5rem 0.35rem 0.75rem;
  border-left: 2px solid transparent;
  margin-left: -0.75rem;
  border-radius: 0 6px 6px 0;
}

.toc a:hover,
.toc a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(79, 70, 229, 0.06);
  font-weight: 600;
}

h1 {
  font-size: 2rem;
  margin-bottom: 0.75rem;
  letter-spacing: -0.025em;
  font-weight: 650;
}
h2 {
  font-size: 1.5rem;
  margin: 2.25rem 0 0.85rem;
  letter-spacing: -0.02em;
  font-weight: 600;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}
h3 {
  font-size: 1.2rem;
  margin: 1.5rem 0 0.6rem;
  font-weight: 600;
}
p { margin-bottom: 1rem; }
ul, ol { margin: 0.5rem 0 1rem 1.5rem; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
.card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  border-color: #cbd5e1;
}
[data-theme="dark"] .card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  border-color: #475569;
}

.callout {
  background: var(--card-bg);
  border-left: 4px solid var(--accent);
  padding: 1.1rem 1.4rem;
  margin: 1.5rem 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  box-shadow: var(--shadow);
}

pre, code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.15rem 0.4rem;
  font-size: 0.9em;
}
pre { padding: 1rem; overflow-x: auto; margin: 1rem 0; }

@media (max-width: 900px) {
  .toc { display: none; }
  .content-wrapper { padding-right: 0; }
}
@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  main { padding: 1.5rem; max-width: none; }
}
