:root {
  --bg: #f7f7fb;
  --bg-elevated: #ffffff;
  --bg-sidebar: #ffffff;
  --text: #1a1a24;
  --text-muted: #5b5b6b;
  --border: #e4e4ec;
  --accent: #6d5ef8;
  --accent-2: #22c1d6;
  --accent-soft: #efedff;
  --code-bg: #efedfd;
  --shadow: 0 1px 2px rgba(20, 20, 40, 0.04), 0 8px 24px rgba(20, 20, 40, 0.04);
  --radius: 14px;
  --sidebar-w: 270px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0e0e14;
  --bg-elevated: #17171f;
  --bg-sidebar: #14141c;
  --text: #eeeef4;
  --text-muted: #a2a2b5;
  --border: #2a2a38;
  --accent: #8b7bff;
  --accent-2: #38d9e8;
  --accent-soft: #211f3a;
  --code-bg: #201f36;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0e14;
    --bg-elevated: #17171f;
    --bg-sidebar: #14141c;
    --text: #eeeef4;
    --text-muted: #a2a2b5;
    --border: #2a2a38;
    --accent: #8b7bff;
    --accent-2: #38d9e8;
    --accent-soft: #211f3a;
    --code-bg: #201f36;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  background: var(--code-bg);
  padding: 0.1em 0.4em;
  border-radius: 5px;
  font-size: 0.9em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text);
}

.layout {
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 28px 20px 40px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  padding: 0 6px;
}
.brand-mark { font-size: 30px; line-height: 1; }
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; color: var(--text-muted); }

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-list a {
  display: block;
  padding: 8px 10px;
  border-radius: 9px;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-list a:hover { background: var(--accent-soft); color: var(--text); text-decoration: none; }
.nav-list a.active { background: var(--accent-soft); color: var(--accent); }

.nav-divider {
  padding: 18px 10px 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.sidebar-footer {
  margin-top: 28px;
  padding: 0 10px;
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

.overlay { display: none; }

/* ---------- Content ---------- */
.content {
  flex: 1;
  min-width: 0;
  padding: 56px 56px 80px;
}

.hero {
  padding-bottom: 40px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 48px;
}

.eyebrow {
  display: inline-block;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 5px 12px;
  border-radius: 999px;
  margin-bottom: 18px;
}

h1 {
  font-size: clamp(32px, 4.4vw, 52px);
  line-height: 1.12;
  margin: 0 0 20px;
  letter-spacing: -0.01em;
}

.gradient-text {
  background: linear-gradient(100deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.lede {
  font-size: 18px;
  color: var(--text-muted);
  max-width: 66ch;
  margin: 0 0 32px;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}

.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px;
  box-shadow: var(--shadow);
}
.stat-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 4px;
}
.stat-label { font-size: 13px; color: var(--text-muted); }

/* ---------- Blocks / sections ---------- */
.block {
  margin-bottom: 64px;
  scroll-margin-top: 24px;
}
.block-end { margin-bottom: 32px; }

.source-divider {
  background: linear-gradient(135deg, var(--accent-soft), transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 28px 8px;
}
.divider-title {
  font-size: 22px;
  margin: 0 0 14px;
}

h2 {
  display: flex;
  align-items: baseline;
  gap: 14px;
  font-size: 26px;
  margin: 0 0 18px;
  letter-spacing: -0.01em;
}

.num {
  font-size: 14px;
  font-weight: 800;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 3px 8px;
  font-variant-numeric: tabular-nums;
}

h3 { font-size: 16.5px; margin: 0 0 6px; }
.sub-h { font-size: 18px; margin: 28px 0 12px; }

p { margin: 0 0 16px; color: var(--text); max-width: 76ch; }
p.fine-print { font-size: 13.5px; color: var(--text-muted); }

/* ---------- Fact grid / feature grid / cards ---------- */
.fact-grid, .feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.fact, .feature-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.fact p, .feature-card p { margin: 0; font-size: 14px; color: var(--text-muted); }

.feature-card { position: relative; padding-top: 44px; }
.f-num {
  position: absolute;
  top: 16px; left: 20px;
  font-size: 12px;
  font-weight: 800;
  color: var(--accent-2);
  border: 1px solid var(--border);
  width: 22px; height: 22px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin: 20px 0;
}
.pro-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px;
}
.pro-card h4 { margin: 0 0 8px; font-size: 15px; }
.pro-card p { margin: 0; font-size: 14px; color: var(--text-muted); }

/* ---------- Callouts ---------- */
.callout {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-2);
  border-radius: var(--radius);
  padding: 16px 20px;
  font-size: 14.5px;
  color: var(--text-muted);
  margin: 20px 0;
  max-width: 78ch;
}
.callout strong { color: var(--text); }
.callout.accent { border-left-color: var(--accent); }

/* ---------- Steps (self-improvement loop) ---------- */
.steps {
  list-style: none;
  margin: 24px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.steps li {
  display: flex;
  gap: 18px;
  padding: 16px 4px;
  border-bottom: 1px solid var(--border);
}
.steps li:last-child { border-bottom: none; }
.step-num {
  flex-shrink: 0;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 14px;
}
.steps h3 { margin-bottom: 4px; }
.steps p { margin: 0; font-size: 14.5px; color: var(--text-muted); }

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 20px 0;
  background: var(--bg-elevated);
}
table { border-collapse: collapse; width: 100%; min-width: 560px; }
th, td {
  text-align: left;
  padding: 12px 16px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 11.5px;
  letter-spacing: 0.03em;
  background: var(--accent-soft);
}
tr:last-child td { border-bottom: none; }
.muted { color: var(--text-muted); font-weight: 400; text-transform: none; letter-spacing: 0; }

/* ---------- Lists ---------- */
.plain-list, .check-list {
  margin: 16px 0;
  padding-left: 0;
  list-style: none;
  max-width: 76ch;
}
.plain-list.numbered { counter-reset: item; }
.plain-list.numbered li {
  counter-increment: item;
  padding-left: 34px;
  position: relative;
  margin-bottom: 12px;
  font-size: 14.5px;
  color: var(--text-muted);
}
.plain-list.numbered li::before {
  content: counter(item);
  position: absolute;
  left: 0; top: 0;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.plain-list:not(.numbered) li {
  padding-left: 20px;
  position: relative;
  margin-bottom: 10px;
  font-size: 14.5px;
  color: var(--text-muted);
}
.plain-list:not(.numbered) li::before {
  content: "\2192";
  position: absolute;
  left: 0;
  color: var(--accent);
}

.check-list li {
  padding-left: 26px;
  position: relative;
  margin-bottom: 10px;
  font-size: 14.5px;
  color: var(--text-muted);
}
.check-list li::before {
  content: "\2713";
  position: absolute;
  left: 0; top: 1px;
  color: var(--accent-2);
  font-weight: 800;
}

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding-top: 24px;
  font-size: 12.5px;
  color: var(--text-muted);
}

/* ---------- Theme toggle ---------- */
.theme-toggle-wrap {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 40;
}
.theme-toggle {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* ---------- Mobile nav toggle ---------- */
.nav-toggle {
  display: none;
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 41;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.nav-toggle span {
  width: 18px; height: 2px;
  background: var(--text);
  border-radius: 2px;
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .content { padding: 90px 24px 60px; }
  .nav-toggle { display: flex; }
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    z-index: 42;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    width: 82vw;
    max-width: 320px;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 41;
  }
  .overlay.open { display: block; }
}

@media (max-width: 560px) {
  .content { padding: 84px 16px 48px; }
  h1 { font-size: 30px; }
  h2 { font-size: 21px; flex-wrap: wrap; }
}

/* ---------- Chat Widget ---------- */
.chat-widget {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
}

.chat-fab {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(109, 94, 248, 0.4);
  transition: transform 0.15s ease;
}
.chat-fab:hover { transform: scale(1.06); }
.chat-fab svg { width: 24px; height: 24px; }
.chat-fab .chat-icon-close { display: none; }
.chat-widget.open .chat-fab .chat-icon-open { display: none; }
.chat-widget.open .chat-fab .chat-icon-close { display: block; }

.chat-panel {
  position: absolute;
  right: 0;
  bottom: 70px;
  width: min(380px, calc(100vw - 40px));
  height: min(560px, calc(100vh - 140px));
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-panel[hidden] { display: none; }

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--accent-soft);
  flex-shrink: 0;
}
.chat-header-title { font-weight: 700; font-size: 14.5px; }
.chat-header-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }
.chat-close {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
}
.chat-close:hover { background: var(--border); }
.chat-close svg { width: 16px; height: 16px; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-msg {
  max-width: 88%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.chat-msg-bot {
  align-self: flex-start;
  background: var(--accent-soft);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.chat-msg-user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg-error {
  align-self: flex-start;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12.5px;
}
.chat-msg-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: var(--accent-soft);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.chat-msg-typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: chatTyping 1s infinite ease-in-out;
}
.chat-msg-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-msg-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatTyping {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  resize: none;
  max-height: 100px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}
.chat-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.chat-send {
  width: 36px; height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.chat-send:disabled { opacity: 0.5; cursor: default; }
.chat-send svg { width: 16px; height: 16px; }

@media (max-width: 560px) {
  .chat-widget { right: 14px; bottom: 14px; }
  .chat-panel { bottom: 66px; }
}
