/* ===== CSS Variables ===== */
:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface2: #eef0f3;
  --border: #d0d7de;
  --text: #1f2328;
  --text2: #656d76;
  --accent: #7c3aed;
  --accent2: #0969da;
  --code-bg: #f0f2f5;
  --radius: 10px;
  --max-content: 820px;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text2: #8b949e;
  --accent: #a78bfa;
  --accent2: #58a6ff;
  --code-bg: #1c2128;
}

/* Theme toggle button */
.nav-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text2);
  cursor: pointer;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}
.nav-theme-toggle:hover { color: var(--text); background: var(--surface2); border-color: var(--text2); }
.nav-theme-toggle svg { width: 18px; height: 18px; }

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

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 1.05rem;
  line-height: 1.75;
  min-height: 100vh;
}

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

img { max-width: 100%; }

/* ===== Background Decoration ===== */
.bg-decor {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.bg-decor span {
  position: absolute;
  border-radius: 20px;
}
.bg-decor span:nth-child(1) {
  width: 420px; height: 420px;
  top: -90px; right: -70px;
  border: 1.5px solid rgba(124,58,237,0.1);
  transform: rotate(18deg);
}
.bg-decor span:nth-child(2) {
  width: 230px; height: 230px;
  top: 110px; right: 90px;
  border: 1px solid rgba(124,58,237,0.07);
  background: rgba(124,58,237,0.022);
  transform: rotate(10deg);
}
.bg-decor span:nth-child(3) {
  width: 320px; height: 200px;
  top: 38%; left: -90px;
  border: 1.5px solid rgba(9,105,218,0.09);
  transform: rotate(-12deg);
}
.bg-decor span:nth-child(4) {
  width: 180px; height: 180px;
  top: 28%; right: 14%;
  border: 1px solid rgba(124,58,237,0.06);
  background: rgba(124,58,237,0.018);
  transform: rotate(24deg);
}
.bg-decor span:nth-child(5) {
  width: 480px; height: 280px;
  bottom: -70px; left: -110px;
  border: 1px solid rgba(9,105,218,0.08);
  transform: rotate(-16deg);
}
.bg-decor span:nth-child(6) {
  width: 260px; height: 260px;
  bottom: 8%; right: -40px;
  border: 1.5px solid rgba(124,58,237,0.08);
  background: rgba(124,58,237,0.016);
  transform: rotate(8deg);
}

/* ===== Top Nav ===== */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 8px 1.5rem;
  pointer-events: none;
}

.nav-bar {
  max-width: 900px;
  margin: 0 auto;
  background: rgba(255,255,255,0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 0 0.5rem 0 1.25rem;
  height: 46px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  box-shadow: 0 4px 24px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
  pointer-events: all;
}

/* Left - portfolio link */
.nav-portfolio {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text2);
  text-decoration: none;
  letter-spacing: -0.01em;
  transition: color 0.15s;
  white-space: nowrap;
}
.nav-portfolio:hover { color: var(--accent); text-decoration: none; }
.nav-portfolio svg { width: 11px; height: 11px; }

/* Center - site logo */
.nav-logo {
  font-weight: 800;
  font-size: 1rem;
  color: var(--text);
  letter-spacing: -0.03em;
  text-decoration: none;
  justify-self: center;
}
.nav-logo:hover { text-decoration: none; }
.nav-logo span { color: var(--accent); }

/* Right area - dropdown + about + toggle */
.nav-right { justify-self: end; display: flex; align-items: center; gap: 0.25rem; }

/* Series dropdown */
.nav-dropdown { position: relative; }

.nav-dropdown-btn {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  background: none;
  border: none;
  color: var(--text2);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  transition: color 0.2s, background 0.2s;
  font-family: inherit;
}
.nav-dropdown-btn:hover { color: var(--text); background: var(--surface2); }
.nav-dropdown-btn svg { width: 14px; height: 14px; transition: transform 0.2s; }
.nav-dropdown.open .nav-dropdown-btn svg { transform: rotate(180deg); }
.nav-dropdown.open .nav-dropdown-btn { color: var(--text); background: var(--surface2); }

.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem;
  min-width: 240px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  z-index: 200;
  list-style: none;
}
.nav-dropdown.open .nav-dropdown-menu { display: block; }

.nav-dropdown-menu li a {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.85rem;
  border-radius: 7px;
  color: var(--text2);
  font-size: 0.88rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.nav-dropdown-menu li a:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.nav-dropdown-menu li a svg { width: 15px; height: 15px; flex-shrink: 0; }

/* About link */
.nav-about {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text2);
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  transition: color 0.2s, background 0.2s;
  text-decoration: none;
  white-space: nowrap;
}
.nav-about:hover { color: var(--text); background: var(--surface2); text-decoration: none; }

/* Mobile toggle */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: 6px;
}
.nav-toggle svg { width: 20px; height: 20px; }

/* Mobile menu panel */
.mobile-menu {
  display: none;
  position: fixed;
  top: 62px; /* 8px + 46px + 8px */
  left: 0; right: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem 1.5rem;
  z-index: 99;
  box-shadow: 0 8px 20px rgba(0,0,0,0.08);
}
.mobile-menu.open { display: block; }

.mobile-menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.mobile-menu-grid a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text2);
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
}
.mobile-menu-grid a:hover { border-color: var(--accent); color: var(--text); text-decoration: none; }
.mobile-menu-grid a svg { width: 14px; height: 14px; flex-shrink: 0; }

.mobile-menu-footer {
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
  display: flex;
  gap: 1rem;
}
.mobile-menu-footer a {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text2);
}

/* ===== Reading Progress Bar ===== */
#progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  z-index: 200;
  transition: width 0.1s linear;
}

/* ===== Hero ===== */
.hero {
  text-align: center;
  padding: 6rem 1.5rem 4rem;
  max-width: 800px;
  margin: 0 auto;
}

.hero h1 {
  font-size: clamp(2.2rem, 5.5vw, 3.6rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.15;
  margin-bottom: 1.25rem;
}

.hero h1 .gradient-text {
  background: linear-gradient(135deg, #8b5cf6, #58a6ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero p {
  color: var(--text2);
  font-size: 1.15rem;
  max-width: 520px;
  margin: 0 auto 2rem;
  line-height: 1.7;
}

.hero-cta {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.75rem 1.75rem;
  border-radius: 99px;
  text-decoration: none;
  margin-bottom: 3.5rem;
  transition: opacity 0.18s, transform 0.18s;
}
.hero-cta:hover { opacity: 0.88; transform: translateY(-2px); }

.hero-stats {
  display: flex;
  gap: 0;
  justify-content: center;
  flex-wrap: wrap;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  max-width: 420px;
  margin: 0 auto;
}

.stat {
  text-align: center;
  flex: 1;
  padding: 1.25rem 1rem;
}
.stat + .stat {
  border-left: 1px solid var(--border);
}
.stat-num {
  display: block;
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.04em;
  line-height: 1;
  margin-bottom: 0.35rem;
}
.stat-label {
  color: var(--text2);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}

/* ===== Section Headings ===== */
.section-title {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.4rem;
}
.section-subtitle {
  color: var(--text2);
  margin-bottom: 2rem;
}

/* ===== Series Grid ===== */
.series-section {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem 5rem;
}

.series-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
}

/* ── Card shell ── */
.series-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--card-color, var(--accent));
  border-radius: 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.22s, box-shadow 0.22s;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
}

.series-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 20px 50px rgba(0,0,0,0.13);
  text-decoration: none;
}


/* ── Card body ── */
.card-body {
  padding: 1.4rem 1.4rem 1.3rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

/* Title + parts count on same row */
.card-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.6rem;
}

.card-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

/* Parts count pill - mirrors the price badge in the reference */
.card-count-badge {
  flex-shrink: 0;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 0.3rem 0.85rem;
  border-radius: 99px;
  background: rgba(var(--card-rgb, 124,58,237), 0.1);
  color: var(--card-color, var(--accent));
  border: 1.5px solid rgba(var(--card-rgb, 124,58,237), 0.22);
}

.card-desc {
  color: var(--text2);
  font-size: 0.875rem;
  line-height: 1.6;
  flex: 1;
}

/* Tag pills */
.card-tags {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.card-tag {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.22rem 0.7rem;
  border-radius: 99px;
  background: rgba(var(--card-rgb, 124,58,237), 0.08);
  color: var(--card-color, var(--accent));
  border: 1px solid rgba(var(--card-rgb, 124,58,237), 0.2);
}

/* Full-width CTA button */
.card-cta-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.8rem 1.25rem;
  border-radius: 99px;
  background: var(--surface2);
  color: var(--card-color, var(--accent));
  border: 1.5px solid rgba(var(--card-rgb, 124,58,237), 0.25);
  font-weight: 700;
  font-size: 0.875rem;
  letter-spacing: 0.01em;
  transition: background 0.2s, color 0.2s;
  margin-top: 0.2rem;
}
.series-card:hover .card-cta-btn {
  background: rgba(var(--card-rgb, 124,58,237), 0.1);
}

/* ── Standalone series-icon (series page header etc.) ── */
.series-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  flex-shrink: 0;
  width: 40px;
  height: 40px;
}
.series-icon svg {
  width: 22px;
  height: 22px;
  stroke-width: 1.75;
}

/* Generic badge (kept for series page) */
.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 99px;
  background: var(--surface2);
  color: var(--text2);
  border: 1px solid var(--border);
}

.badge-parts { color: var(--accent); border-color: rgba(124,58,237,0.25); background: rgba(124,58,237,0.07); }

/* ===== Article List (Series Index Page) ===== */
.series-index {
  max-width: 760px;
  margin: 2rem auto;
  padding: 0 1.5rem 5rem;
}

.series-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.series-header .series-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  margin-bottom: 1.25rem;
}
.series-header .series-icon svg {
  width: 30px;
  height: 30px;
}

.series-header h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 0.6rem;
}

.series-header p {
  color: var(--text2);
  font-size: 1rem;
  margin-bottom: 1rem;
}

.article-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.article-item {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.2s, transform 0.15s;
}

.article-item:hover {
  border-color: rgba(88,166,255,0.4);
  transform: translateX(4px);
  text-decoration: none;
}

.article-num {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text2);
}

.article-title {
  font-weight: 500;
  font-size: 0.97rem;
}

/* ===== Article Page ===== */

/* Single centered container used by header, body, and nav */
.article-content {
  max-width: var(--max-content);
  margin: 0 auto;
  padding: 0 1.5rem;
}

.article-header {
  border-bottom: 1px solid var(--border);
  padding: 3rem 0 2rem;           /* vertical only - horizontal handled by .article-content */
}
.article-header .article-content {
  padding-top: 0;
  padding-bottom: 0;
}

.article-breadcrumb {
  font-size: 0.83rem;
  color: var(--text2);
  margin-bottom: 1rem;
}
.article-breadcrumb a { color: var(--text2); }
.article-breadcrumb a:hover { color: var(--text); text-decoration: none; }
.article-breadcrumb span { margin: 0 0.35rem; }

.article-header h1 {
  font-size: clamp(1.5rem, 3.5vw, 2.25rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.25;
}

.article-body {
  padding: 2rem 0 4rem;           /* vertical only - horizontal handled by .article-content */
}

/* At wide viewports, nudge content left so TOC sidebar doesn't overlap */
@media (min-width: 1300px) {
  .article-content {
    margin-left: max(1.5rem, calc(50vw - var(--max-content) / 2 - 20px));
    margin-right: 260px;          /* reserve space for 220px TOC + gap */
  }
}

/* ===== Prose Styles ===== */
.prose {
  overflow-wrap: break-word;
  word-break: break-word;
}

.prose img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.prose h1, .prose h2, .prose h3, .prose h4 {
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
  margin-top: 2.5rem;
  margin-bottom: 0.75rem;
  color: var(--text);
  overflow-wrap: break-word;
}
.prose h1 { font-size: 2rem; }
.prose h2 { font-size: 1.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
.prose h3 { font-size: 1.2rem; }
.prose h4 { font-size: 1rem; }

.prose p { margin-bottom: 1.25rem; }
.prose ul, .prose ol { padding-left: 1.6rem; margin-bottom: 1.25rem; }
.prose li { margin-bottom: 0.35rem; }

.prose blockquote {
  border-left: 3px solid var(--accent);
  padding: 0.75rem 1.25rem;
  margin: 1.5rem 0;
  background: rgba(124,58,237,0.05);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text2);
  font-style: italic;
}

/* Scrollable table wrapper injected by JS on mobile */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.5rem 0;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.table-wrapper table { margin: 0; border: none; border-radius: 0; }

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.prose th {
  background: var(--surface2);
  padding: 0.65rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.prose td {
  padding: 0.65rem 1rem;
  border-top: 1px solid var(--border);
}
.prose tr:nth-child(even) td { background: rgba(255,255,255,0.02); }

.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

/* ===== Code ===== */
.prose code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.85em;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.15em 0.45em;
  color: #7c3aed;
}

.prose pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  overflow-x: auto;
  margin: 1.5rem 0;
  position: relative;
}
.prose pre code {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font-size: 0.9rem;
  line-height: 1.7;
}

/* Copy button */
.copy-btn {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text2);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}
.copy-btn:hover { background: var(--accent); color: #fff; border-color: transparent; }

/* Mermaid */
.mermaid {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 1.5rem 0;
  text-align: center;
  overflow-x: auto;
}

/* ===== TOC (Table of Contents) ===== */
#toc-sidebar {
  position: fixed;
  right: 1.5rem;
  top: 80px;
  width: 220px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  font-size: 0.8rem;
  line-height: 1.5;
  display: none;
}

@media (min-width: 1300px) {
  #toc-sidebar { display: block; }
}

#toc-sidebar ul {
  list-style: none;
  padding: 0;
}

#toc-sidebar li { margin-bottom: 0.3rem; }

#toc-sidebar a {
  color: var(--text2);
  display: block;
  padding: 0.2rem 0.6rem;
  border-left: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  border-radius: 0 4px 4px 0;
}

#toc-sidebar a:hover,
#toc-sidebar a.active {
  color: var(--accent2);
  border-left-color: var(--accent2);
  text-decoration: none;
  background: rgba(88,166,255,0.07);
}

#toc-sidebar .toc-h3 { padding-left: 1.2rem; }

.toc-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--text2);
  margin-bottom: 0.5rem;
  padding-left: 0.6rem;
}

/* ===== Prev / Next Navigation ===== */
.article-nav {
  border-top: 1px solid var(--border);
  padding: 2rem 1.5rem 3rem;
  max-width: var(--max-content);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

@media (min-width: 1300px) {
  .article-nav {
    margin-left: max(1.5rem, calc(50vw - var(--max-content) / 2 - 20px));
    margin-right: 260px;
  }
}

.nav-prev, .nav-next { flex: 1; min-width: 0; }
.nav-next { display: flex; justify-content: flex-end; }

.nav-card {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1.25rem;
  text-decoration: none;
  color: var(--text);
  max-width: 340px;
  width: 100%;
  transition: border-color 0.18s, box-shadow 0.18s, transform 0.18s;
}
.nav-card:hover {
  border-color: var(--accent2);
  box-shadow: 0 4px 20px rgba(0,0,0,0.07);
  transform: translateY(-2px);
  text-decoration: none;
}
.nav-card.next { flex-direction: row-reverse; text-align: right; }

.nav-card-arrow {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: var(--accent2);
  transition: background 0.18s;
}
.nav-card:hover .nav-card-arrow { background: rgba(9,105,218,0.1); }

.nav-card-text { min-width: 0; }

.nav-direction {
  font-size: 0.7rem;
  color: var(--text2);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.25rem;
}
.nav-title {
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Loading / Error ===== */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 40vh;
  gap: 1rem;
  color: var(--text2);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-state {
  text-align: center;
  padding: 4rem 1.5rem;
  color: var(--text2);
}
.error-state h2 { color: #f87171; margin-bottom: 0.5rem; }

/* ===== Back to Top ===== */
#back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text2);
  font-size: 1.1rem;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s, transform 0.2s;
  z-index: 50;
}
#back-to-top:hover { background: var(--accent); color: #fff; border-color: transparent; transform: translateY(-2px); }
#back-to-top.visible { display: flex; }

/* ===== About Section ===== */
.about-section {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem 5rem;
}

.about-card {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 2.5rem;
  position: relative;
  overflow: hidden;
}
.about-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, #7c3aed, #0969da);
}

.about-avatar {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c3aed, #0969da);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.2rem;
  color: #fff;
  letter-spacing: -0.03em;
}

.about-body { flex: 1; }

.about-name {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}

.about-roles {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.about-role {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.25rem 0.75rem;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text2);
}
.about-role svg { width: 13px; height: 13px; }

.about-bio {
  color: var(--text2);
  font-size: 0.95rem;
  line-height: 1.7;
  margin-bottom: 1.25rem;
  max-width: 580px;
}

.about-links {
  display: flex;
  gap: 0.75rem;
}
.about-links a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text2);
  border: 1px solid var(--border);
  background: var(--surface2);
  padding: 0.35rem 0.85rem;
  border-radius: 8px;
  transition: color 0.2s, border-color 0.2s;
  text-decoration: none;
}
.about-links a:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }
.about-links a svg { width: 15px; height: 15px; }

@media (max-width: 768px) {
  .about-card { flex-direction: column; padding: 1.5rem; }
}

/* ===== Footer ===== */
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--text2);
  font-size: 0.88rem;
}

.footer-links {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.footer-links a { color: var(--text2); }
.footer-links a:hover { color: var(--text); text-decoration: none; }

/* ===== Responsive ===== */

/* ── Tablet and below (≤768px) ── */
@media (max-width: 768px) {
  /* Nav - pill shrinks, portfolio hides, logo stays center */
  .site-nav { padding: 8px 1rem; }
  .nav-bar { border-radius: 16px; padding: 0 0.4rem 0 1rem; grid-template-columns: 1fr auto; }
  .nav-portfolio { display: none; }
  .nav-logo { justify-self: start; white-space: nowrap; }
  .nav-about { display: none; }
  .nav-dropdown { display: none; }
  .nav-toggle { display: flex; }

  /* Homepage hero */
  .hero { padding: 3rem 1rem 2rem; }
  .hero h1 { font-size: 1.75rem; }
  .hero p { font-size: 1rem; }
  .stat-num { font-size: 1.5rem; }

  /* Series grid → single column */
  .series-grid { grid-template-columns: 1fr; }
  .mobile-menu-grid { grid-template-columns: 1fr; }

  /* Series index */
  .series-index { padding: 0 1rem 3rem; }
  .series-header h1 { font-size: 1.5rem; }
  .article-item { padding: 0.85rem 1rem; }
  .article-item:hover { transform: none; }

  /* Article page */
  .article-header { padding: 1.75rem 0 1.25rem; }
  .article-body { padding: 1.5rem 0 3rem; }
  .article-content { padding: 0 1rem; }

  /* Prev/next → stacked */
  .article-nav { flex-direction: column; padding: 1.5rem 1rem; }
  .nav-card { max-width: 100%; }

  /* About card → vertical */
  .about-card { flex-direction: column; padding: 1.5rem; }
  .about-section { padding: 0 1rem 3rem; }

  /* Series section */
  .series-section { padding: 1.5rem 1rem 3rem; }

  /* Misc */
  #back-to-top { bottom: 1rem; right: 1rem; }
}

/* ── Small phones (≤480px) ── */
@media (max-width: 480px) {
  .hero { padding: 2rem 1rem 1.5rem; }
  .hero h1 { font-size: 1.5rem; }
  .stat-num { font-size: 1.3rem; }

  .nav-logo { font-size: 1rem; }

  .article-content { padding: 0 0.875rem; }
  .article-header { padding: 1.25rem 0 1rem; }
  .article-header h1 { font-size: 1.35rem; }
  .article-body { padding: 1.25rem 0 2.5rem; }

  .prose h2 { font-size: 1.25rem; }
  .prose h3 { font-size: 1.05rem; }
  .prose pre { padding: 0.875rem 1rem; font-size: 0.82rem; }
  .prose code { font-size: 0.82em; }

  .series-section { padding: 1rem 0.875rem 2.5rem; }
  .series-header h1 { font-size: 1.3rem; }
  .series-index { padding: 0 0.875rem 2.5rem; }

  .about-card { padding: 1.25rem; }
  .about-section { padding: 0 0.875rem 2.5rem; }
  .about-name { font-size: 1.1rem; }

  .mobile-menu-grid { grid-template-columns: 1fr; gap: 0.35rem; }
  .mobile-menu { padding: 0.875rem 1rem 1.25rem; }

  .article-nav { padding: 1.25rem 0.875rem; }
  .nav-card { padding: 0.85rem 1rem; }
}

/* ===== Highlight.js overrides ===== */
.hljs { background: var(--code-bg) !important; }
.prose pre { background: var(--code-bg); }
