/* ─── Theme tokens (shared with homepage) ──────────────────────────────── */
:root {
  /* Default = dark */
  --bg: #0a0a0a;
  --surface: #161616;
  --surface-alt: #121212;
  --border: #262626;
  --text: #ededed;
  --muted: #9aa0a6;
  --accent: #60a5fa;
  --accent-dark: #3b82f6;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4),
            0 12px 32px rgba(0, 0, 0, 0.4);

  --font-serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --font-sans:  "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
                Roboto, Helvetica, Arial, sans-serif;
  --font-mono:  "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo,
                Consolas, monospace;

  --article-font-size: 17px;
  --article-line-height: 1.75;
  --max-w: 1280px;
}

[data-theme="light"] {
  --bg: #fafaf7;
  --surface: #ffffff;
  --surface-alt: #f0f0ea;
  --border: #d8d8d0;
  --text: #16181d;
  --muted: #5b6472;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04),
            0 8px 24px rgba(15, 23, 42, 0.06);
}

[data-text-size="small"]    { --article-font-size: 15px; }
[data-text-size="standard"] { --article-font-size: 17px; }
[data-text-size="large"]    { --article-font-size: 19px; }

html { color-scheme: dark; }
[data-theme="light"] { color-scheme: light; }

/* ─── Reset / base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background 0.25s ease, color 0.25s ease;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; }
img { display: block; max-width: 100%; height: auto; }

/* ─── Top bar ──────────────────────────────────────────────────────────── */
.article-top {
  padding: 28px 0 0;
}

.article-top-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 32px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 14px;
  text-decoration: none;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.back-link:hover { color: var(--text); border-color: var(--text); }

/* ─── Layout ───────────────────────────────────────────────────────────── */
.article-page {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 220px;
  gap: 64px;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 24px 32px 80px;
  align-items: start;
}

.article-sidebar {
  position: sticky;
  top: 32px;
}

/* ─── Sidebar shared chrome ────────────────────────────────────────────── */
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.sidebar-title {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.005em;
}

.sidebar-toggle {
  font-size: 11px;
  color: var(--muted);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.sidebar-toggle:hover { color: var(--text); border-color: var(--text); }

.article-sidebar.is-collapsed .sidebar-body { display: none; }
.article-sidebar.is-collapsed .sidebar-head { margin-bottom: 0; }

/* ─── Contents (TOC) ───────────────────────────────────────────────────── */
.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border-left: 1px solid var(--border);
}

.toc-list li { position: relative; }

.toc-list a {
  display: block;
  padding: 8px 14px;
  font-size: 14px;
  color: var(--muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  margin-left: -1px;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.toc-list a:hover { color: var(--text); }

.toc-list a.is-active {
  color: var(--text);
  border-left-color: var(--accent);
  font-weight: 500;
}

.toc-list .nested {
  list-style: none;
  padding: 0 0 0 14px;
  margin: 0;
}
.toc-list .nested a { font-size: 13px; }

.toc-group { display: flex; align-items: center; }
.toc-group a { flex: 1; }
.toc-chevron {
  margin-right: 8px;
  padding: 2px;
  color: var(--muted);
  transition: transform 0.2s ease;
}
.toc-chevron svg { width: 14px; height: 14px; }
.toc-group.is-open .toc-chevron { transform: rotate(180deg); }
.toc-group:not(.is-open) + .nested { display: none; }

/* ─── Article body ─────────────────────────────────────────────────────── */
.article-body { max-width: 720px; margin: 0 auto; }

.article-eyebrow {
  display: block;
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 18px;
}

.article-title {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: clamp(34px, 4.5vw, 52px);
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0 0 24px;
}

.article-lead {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(18px, 1.8vw, 22px);
  line-height: 1.55;
  color: var(--muted);
  margin: 0 0 28px;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  color: var(--muted);
  font-size: 14px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border);
}
.article-meta .sep { opacity: 0.5; }

.article-section { padding-top: 56px; }

.article-section h2 {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 26px;
  letter-spacing: -0.015em;
  margin: 0 0 20px;
}

.article-section h3 {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 19px;
  margin: 32px 0 12px;
}

.article-section p,
.article-section ul,
.article-section ol {
  font-size: var(--article-font-size);
  line-height: var(--article-line-height);
  margin: 0 0 20px;
  color: var(--text);
}

.article-section ul, .article-section ol {
  padding-left: 22px;
}
.article-section li { margin-bottom: 8px; }

.article-section blockquote {
  border-left: 3px solid var(--accent);
  padding: 4px 0 4px 18px;
  margin: 24px 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: calc(var(--article-font-size) + 1px);
  color: var(--muted);
}

.article-section code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 5px;
}

.article-section pre {
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.6;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  overflow-x: auto;
  margin: 0 0 24px;
}
.article-section pre code {
  background: none;
  border: 0;
  padding: 0;
}

.article-section a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.article-footer {
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

/* ─── Appearance panel ─────────────────────────────────────────────────── */
.appearance-group { margin-bottom: 20px; }
.appearance-group:last-child { margin-bottom: 0; }

.appearance-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: capitalize;
  margin-bottom: 6px;
}

.appearance-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
}

.appearance-option input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  margin: 0;
  flex-shrink: 0;
  transition: border-color 0.2s ease;
}

.appearance-option input[type="radio"]::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  transform: scale(0);
  transition: transform 0.15s ease;
}

.appearance-option input[type="radio"]:checked {
  border-color: var(--accent);
}
.appearance-option input[type="radio"]:checked::before {
  transform: scale(1);
}

/* ─── Theme toggle (floating, top-right) ───────────────────────────────── */
/* Reuses the same icons as the homepage */

/* ─── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 1060px) {
  .article-page {
    grid-template-columns: 200px minmax(0, 1fr);
    gap: 40px;
  }
  .article-sidebar.appearance {
    position: fixed;
    bottom: 16px;
    right: 16px;
    top: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 18px;
    box-shadow: var(--shadow);
    max-width: 240px;
  }
  .article-sidebar.appearance.is-collapsed {
    padding: 8px 14px;
  }
}

@media (max-width: 760px) {
  .article-page {
    grid-template-columns: 1fr;
    gap: 24px;
    padding: 16px 20px 64px;
  }
  .article-sidebar.contents {
    position: static;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 18px;
  }
  .article-sidebar.appearance {
    bottom: 12px;
    right: 12px;
    max-width: 200px;
    font-size: 13px;
  }
  .article-top { padding: 20px 20px 0; }
  .article-section { padding-top: 40px; }
  .article-section h2 { font-size: 22px; }
}
