/* ─── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0a0b0f;
  --bg2:       #111318;
  --bg3:       #181b22;
  --border:    rgba(255,255,255,0.07);
  --border-hi: rgba(255,255,255,0.14);

  --text:      #e8e9ee;
  --text-2:    #9a9daa;
  --text-3:    #555865;

  --purple:    #a78bfa;
  --purple-bg: rgba(167,139,250,0.08);
  --teal:      #34d399;
  --teal-bg:   rgba(52,211,153,0.07);
  --amber:     #fbbf24;
  --amber-bg:  rgba(251,191,36,0.07);
  --coral:     #f87171;
  --coral-bg:  rgba(248,113,113,0.07);
  --pink:      #f472b6;
  --blue:      #60a5fa;

  --mono: 'DM Mono', 'Fira Code', monospace;
  --serif: 'Instrument Serif', Georgia, serif;
  --display: 'Syne', sans-serif;

  --max: 860px;
  --radius: 10px;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
}

/* ─── Background grid ──────────────────────────────────── */
.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, black, transparent 70%);
}

/* ─── Hero ─────────────────────────────────────────────── */
.hero {
  position: relative;
  z-index: 1;
  max-width: var(--max);
  margin: 0 auto;
  padding: 96px 32px 64px;
}

.hero-eyebrow {
  display: flex;
  gap: 8px;
  margin-bottom: 28px;
}

.tag {
  font-family: var(--display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  border: 1px solid var(--border-hi);
  padding: 3px 10px;
  border-radius: 20px;
}

.hero h1 {
  font-family: var(--display);
  font-size: clamp(32px, 5vw, 54px);
  font-weight: 800;
  line-height: 1.1;
  color: #fff;
  margin-bottom: 24px;
  letter-spacing: -0.02em;
}

.hero h1 em {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  color: var(--purple);
}

.hero-lead {
  font-family: var(--mono);
  font-size: 16px;
  color: var(--text-2);
  line-height: 1.7;
  margin-bottom: 20px;
}

.hero-meta {
  font-size: 13px;
  color: var(--text-3);
  display: flex;
  gap: 8px;
  align-items: center;
}

.hero-meta .sep { opacity: 0.4; }

/* ─── Main layout ──────────────────────────────────────── */
main {
  position: relative;
  z-index: 1;
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 32px 80px;
}

/* ─── Section ──────────────────────────────────────────── */
.section {
  margin-bottom: 72px;
}

.section-label {
  font-family: var(--display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--teal);
  margin-bottom: 10px;
  opacity: 0.8;
}

.section h2 {
  font-family: var(--display);
  font-size: 26px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 14px;
  letter-spacing: -0.02em;
}

.section > p {
  color: var(--text-2);
  margin-bottom: 28px;
  line-height: 1.8;
}

code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: rgba(255,255,255,0.07);
  border: 1px solid var(--border-hi);
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--teal);
}

/* ─── Intro section ────────────────────────────────────── */
.intro-section {
  position: relative;
  z-index: 1;
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 32px 64px;
}

.intro-lead {
  font-size: 16px;
  color: var(--text-2);
  line-height: 1.8;
  max-width: 640px;
  margin-bottom: 32px;
}

.risk-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 32px;
}

@media (max-width: 520px) {
  .risk-grid { grid-template-columns: 1fr; }
}

.risk-card {
  background: var(--bg2);
  padding: 20px 22px 18px;
  position: relative;
  transition: background 0.15s;
}

.risk-card:hover { background: var(--bg3); }

.risk-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 2px; height: 100%;
  background: var(--accent, var(--text-3));
}

.risk-card.r { --accent: var(--coral); }
.risk-card.a { --accent: var(--amber); }
.risk-card.p { --accent: var(--purple); }
.risk-card.g { --accent: #6b7280; }

.risk-label {
  font-family: var(--display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent, var(--text-3));
  margin-bottom: 8px;
}

.risk-desc {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.65;
}

.intro-terminal {
  background: var(--bg2);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 32px;
}

.intro-terminal-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 11px 16px;
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid var(--border);
}

.terminal-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
}

.terminal-dot:nth-child(1) { background: var(--coral); opacity: 0.7; }
.terminal-dot:nth-child(2) { background: var(--amber); opacity: 0.7; }
.terminal-dot:nth-child(3) { background: var(--teal); opacity: 0.7; }

.intro-terminal-title {
  margin-left: 6px;
  font-size: 11px;
  color: var(--text-3);
}

.intro-terminal-body {
  padding: 20px 24px 22px;
  font-size: 13.5px;
  line-height: 2;
}

.t-line { display: flex; align-items: baseline; gap: 4px; }
.t-comment { color: var(--text-3); font-style: italic; }
.t-prompt { color: var(--teal); }
.t-cmd { color: var(--text); }
.t-danger { color: var(--coral); }

.intro-close {
  font-size: 16px;
  color: var(--text-2);
  line-height: 1.8;
  max-width: 640px;
  padding-left: 20px;
  border-left: 2px solid var(--purple);
}

/* ─── Diagram card ─────────────────────────────────────── */
.diagram-card {
  background: var(--bg2);
  border: 1px solid var(--border-hi);
  border-radius: 14px;
  padding: 12px;
  overflow: hidden;
}

/* ─── File tree ────────────────────────────────────────── */
.file-tree {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  font-family: var(--mono);
  font-size: 14px;
}

.tree-line {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  color: var(--text-2);
}

.tree-line.root { color: #fff; font-weight: 500; }
.tree-line.highlight-dir .tree-name { color: var(--teal); }

.indent-1 { padding-left: 20px; }
.indent-2 { padding-left: 44px; }

.tree-connector { color: var(--text-3); }
.tree-name { color: var(--text); }
.tree-comment { color: var(--text-3); font-size: 12px; margin-left: 8px; }
.tree-comment.danger { color: var(--coral); }

/* ─── Code blocks ──────────────────────────────────────── */
.code-block {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}

.code-filename {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-3);
}

.copy-btn {
  font-family: var(--display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: none;
  border: 1px solid var(--border-hi);
  color: var(--text-3);
  padding: 3px 10px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s;
}

.copy-btn:hover {
  color: var(--text);
  border-color: rgba(255,255,255,0.25);
}

.copy-btn.copied {
  color: var(--teal);
  border-color: rgba(52,211,153,0.35);
}

pre {
  padding: 20px 24px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--text-2);
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
  border-radius: 0;
}

/* Syntax highlight colors */
.kw  { color: #c792ea; }
.var { color: #82aaff; }
.val { color: var(--amber); }
.str { color: #c3e88d; }
.key { color: var(--blue); }
.op  { color: var(--text-3); }
.comment { color: #546e7a; font-style: italic; }

/* ─── Badge ─────────────────────────────────────────────── */
.badge {
  font-family: var(--display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 20px;
}

.badge.danger {
  background: var(--coral-bg);
  border: 1px solid rgba(248,113,113,0.25);
  color: var(--coral);
}

/* ─── Callout ───────────────────────────────────────────── */
.callout {
  display: flex;
  gap: 14px;
  padding: 16px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.7;
}

.callout-tip {
  background: var(--amber-bg);
  border: 1px solid rgba(251,191,36,0.2);
  color: var(--text-2);
}

.callout-icon { font-size: 18px; flex-shrink: 0; margin-top: 1px; }
.callout strong { color: var(--amber); }

/* ─── Two-col ───────────────────────────────────────────── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 600px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ─── Steps ─────────────────────────────────────────────── */
.steps {
  display: flex;
  flex-direction: column;
  gap: 1px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.step {
  display: flex;
  gap: 24px;
  padding: 22px 24px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.step:last-child { border-bottom: none; }
.step:hover { background: var(--bg3); }

.step-number {
  font-family: var(--display);
  font-size: 28px;
  font-weight: 800;
  color: var(--text-3);
  line-height: 1;
  min-width: 48px;
  padding-top: 2px;
  opacity: 0.5;
}

.step:hover .step-number { color: var(--purple); opacity: 1; }

.step-content h3 {
  font-family: var(--display);
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 6px;
}

.step-content p {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.7;
}

/* ─── Rules grid ────────────────────────────────────────── */
.rules-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 600px) {
  .rules-grid { grid-template-columns: 1fr; }
}

.rule-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  transition: border-color 0.2s;
}

.rule-card:hover { border-color: var(--border-hi); }

.rule-icon {
  font-size: 22px;
  margin-bottom: 12px;
  display: block;
}

.rule-card h3 {
  font-family: var(--display);
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 8px;
}

.rule-card p {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.7;
}

/* ─── Summary box ───────────────────────────────────────── */
.summary-box {
  background: linear-gradient(135deg, rgba(167,139,250,0.08), rgba(52,211,153,0.06));
  border: 1px solid rgba(167,139,250,0.2);
  border-radius: 14px;
  padding: 32px 36px;
}

.summary-title {
  font-family: var(--display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--purple);
  margin-bottom: 20px;
  opacity: 0.8;
}

.summary-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.summary-list li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  font-size: 15px;
  color: var(--text-2);
}

.check {
  color: var(--teal);
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}

/* ─── Footer ────────────────────────────────────────────── */
footer {
  position: relative;
  z-index: 1;
  max-width: var(--max);
  margin: 0 auto;
  padding: 24px 32px 48px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-3);
  font-family: var(--display);
  letter-spacing: 0.05em;
}

/* ─── Scrollbar ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 3px; }

/* ─── Animations ────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.hero { animation: fadeUp 0.5s ease both; }
.section { animation: fadeUp 0.5s ease both; }
.section:nth-child(2) { animation-delay: 0.08s; }
.section:nth-child(3) { animation-delay: 0.14s; }
.section:nth-child(4) { animation-delay: 0.18s; }

/* ─── Selection ─────────────────────────────────────────── */
::selection {
  background: rgba(167,139,250,0.3);
  color: #fff;
}

/* ─── Article root & loading ────────────────────────────── */
.article-root {
  position: relative;
  z-index: 1;
}

.article-loading {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  padding: 120px 32px;
}

.article-loading-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-3);
  animation: dot-pulse 1.2s ease-in-out infinite;
}

.article-loading-dot:nth-child(2) { animation-delay: 0.2s; }
.article-loading-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
  40%           { opacity: 1;   transform: scale(1); }
}

.article-error {
  max-width: var(--max);
  margin: 0 auto;
  padding: 120px 32px;
  color: var(--coral);
  font-family: var(--mono);
  font-size: 14px;
}

/* ─── Sidebar ───────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 240px;
  height: 100vh;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-inner {
  padding: 28px 0 40px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.sidebar-header {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.sidebar-title {
  font-family: var(--display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
}

.sidebar-list {
  list-style: none;
  padding: 8px 0;
  flex: 1;
}

.sidebar-article {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 12px 20px;
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.sidebar-article:hover {
  background: rgba(255,255,255,0.03);
  border-left-color: var(--border-hi);
}

.sidebar-article.active {
  background: var(--purple-bg);
  border-left-color: var(--purple);
}

.sidebar-article-tags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.sidebar-article-tag {
  font-family: var(--display);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 10px;
}

.sidebar-article.active .sidebar-article-tag {
  color: var(--purple);
  border-color: rgba(167,139,250,0.25);
  background: rgba(167,139,250,0.08);
}

.sidebar-article-title {
  font-family: var(--display);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-2);
  line-height: 1.4;
}

.sidebar-article.active .sidebar-article-title {
  color: #fff;
}

.sidebar-article-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
}

.sidebar-coming {
  margin-top: auto;
  padding: 20px 20px 0;
  border-top: 1px solid var(--border);
}

.sidebar-coming-label {
  font-family: var(--display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  display: block;
  margin-bottom: 8px;
}

.sidebar-coming-text {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.6;
  font-style: italic;
}

/* ─── Sidebar toggle (mobile) ───────────────────────────── */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;
  width: 38px;
  height: 38px;
  background: var(--bg2);
  border: 1px solid var(--border-hi);
  border-radius: 8px;
  color: var(--text-2);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.sidebar-toggle:hover {
  background: var(--bg3);
  color: var(--text);
}

/* ─── Sidebar overlay (mobile) ──────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.25s;
}

.sidebar-overlay.visible {
  opacity: 1;
}

/* ─── Layout: sidebar + content ─────────────────────────── */
@media (min-width: 1100px) {
  body {
    padding-left: 240px;
  }
}

@media (max-width: 1099px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 32px rgba(0,0,0,0.5);
  }

  .sidebar-toggle {
    display: flex;
  }

  .sidebar-overlay {
    display: block;
  }
}
