/* ============================================================
   Muuuchen Tech Wiki — Visual Redesign (2026)
   Tone: Linear / Vercel / Stripe / Apple — 极简黑白 + 单一薄荷高亮
   Notes:
   - 纯留白、hairline、克制动效（reveal + blur-to-focus）
   - 禁止粒子/浮夸装饰
   ============================================================ */

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
}

img,
svg,
video,
canvas {
  display: block;
  max-width: 100%;
}

button,
input,
textarea,
select {
  font: inherit;
}

:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent);
  outline-offset: 2px;
}

::selection {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

/* ---------- Tokens ---------- */
:root {
  /* Layout */
  --topbar-h: 66px;
  --container: 1600px;
  --gutter: 48px;
  --gap: 64px;
  --sidebar-w: 240px;
  --toc-w: 220px;
  --section-gap: 120px;

  --radius-sm: 4px;
  --radius: 6px;

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  /* JS-driven parallax */
  --parallax-y: 0px;
}

/* Dark theme tokens (default) */
[data-theme="dark"] {
  --bg: #0a0b0f;
  --bg-elev: #0f1015;

  --panel: rgba(255, 255, 255, 0.03);
  --panel-strong: rgba(255, 255, 255, 0.06);

  --text-1: rgba(255, 255, 255, 0.94);
  --text-2: rgba(255, 255, 255, 0.72);
  --text-3: rgba(255, 255, 255, 0.56);
  --text-4: rgba(255, 255, 255, 0.38);
  --text-muted: rgba(255, 255, 255, 0.60);

  --line-1: rgba(255, 255, 255, 0.06);
  --line-2: rgba(255, 255, 255, 0.08);
  --line-3: rgba(255, 255, 255, 0.12);

  --card-border: rgba(255, 255, 255, 0.08);
  --card-border-hover: rgba(255, 255, 255, 0.16);
  --card-fill: rgba(255, 255, 255, 0.02);
  --card-glow: rgba(255, 255, 255, 0.04);

  --accent: #a3f7bf;
  --accent-dim: rgba(163, 247, 191, 0.55);
  --accent-glow: rgba(163, 247, 191, 0.14);

  --topbar-bg: rgba(10, 11, 15, 0.72);
  --modal-backdrop: rgba(0, 0, 0, 0.62);
  --modal-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);

  --code-bg: #08090c;
  --code-border: rgba(255, 255, 255, 0.10);
  --inline-code-bg: rgba(255, 255, 255, 0.06);
  --inline-code-fg: var(--text-1);

  --kbd-bg: rgba(255, 255, 255, 0.06);
  --kbd-fg: var(--text-3);

  --float-btn-bg: rgba(255, 255, 255, 0.96);
  --float-btn-fg: #0a0b0f;

  --btn-primary-bg: rgba(255, 255, 255, 0.96);
  --btn-primary-fg: #0a0b0f;
  --btn-primary-border: rgba(255, 255, 255, 0.96);
  --btn-primary-hover-bg: color-mix(in srgb, rgba(255, 255, 255, 0.96) 92%, var(--accent) 8%);

  --bg-beam: color-mix(in srgb, var(--accent) 18%, transparent);
  --bg-dot: rgba(255, 255, 255, 0.03);
  --bg-decor-opacity: 0.22;

  /* Compatibility vars referenced by inline styles in app.js */
  --grad-1: var(--accent);
  --gradient: linear-gradient(90deg, var(--accent), var(--accent));
}

/* Light theme tokens */
[data-theme="light"] {
  --bg: #fafafa;
  --bg-elev: #ffffff;

  --panel: rgba(0, 0, 0, 0.03);
  --panel-strong: rgba(0, 0, 0, 0.06);

  --text-1: rgba(10, 11, 15, 0.94);
  --text-2: rgba(10, 11, 15, 0.72);
  --text-3: rgba(10, 11, 15, 0.56);
  --text-4: rgba(10, 11, 15, 0.38);
  --text-muted: rgba(10, 11, 15, 0.60);

  --line-1: rgba(0, 0, 0, 0.06);
  --line-2: rgba(0, 0, 0, 0.08);
  --line-3: rgba(0, 0, 0, 0.12);

  --card-border: rgba(0, 0, 0, 0.08);
  --card-border-hover: rgba(0, 0, 0, 0.16);
  --card-fill: rgba(0, 0, 0, 0.02);
  --card-glow: rgba(0, 0, 0, 0.04);

  --accent: #0f7a4a;
  --accent-dim: rgba(15, 122, 74, 0.55);
  --accent-glow: rgba(15, 122, 74, 0.10);

  --topbar-bg: rgba(255, 255, 255, 0.72);
  --modal-backdrop: rgba(0, 0, 0, 0.38);
  --modal-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);

  --code-bg: #f7f7f5;
  --code-border: rgba(0, 0, 0, 0.10);
  --inline-code-bg: rgba(0, 0, 0, 0.05);
  --inline-code-fg: var(--accent);

  --kbd-bg: rgba(0, 0, 0, 0.06);
  --kbd-fg: rgba(10, 11, 15, 0.70);

  --float-btn-bg: #0a0b0f;
  --float-btn-fg: #ffffff;

  --btn-primary-bg: #0a0b0f;
  --btn-primary-fg: #ffffff;
  --btn-primary-border: #0a0b0f;
  --btn-primary-hover-bg: color-mix(in srgb, #0a0b0f 90%, var(--accent) 10%);

  /* keep decorative background nearly invisible */
  --bg-beam: color-mix(in srgb, var(--accent) 7%, transparent);
  --bg-dot: rgba(0, 0, 0, 0.03);
  --bg-decor-opacity: 0.12;

  --grad-1: var(--accent);
  --gradient: linear-gradient(90deg, var(--accent), var(--accent));
}

/* ---------- Base ---------- */
html {
  background: var(--bg);
  color: var(--text-1);
  transition: background 0.35s ease, color 0.35s ease;
}

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

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

body {
  background: var(--bg);
  color: var(--text-1);
  padding-top: var(--topbar-h);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.65;
  letter-spacing: 0.002em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  transition: background 0.35s ease, color 0.35s ease;
}

/* Background glow (soft, diffused) + dot-grid layer */
body::before,
body::after {
  content: "";
  position: fixed;
  inset: -40vh -20vw;
  pointer-events: none;
}

/* Soft glow layer (diffuse, drifts slowly) */
body::before {
  z-index: -2;

  background-image:
    radial-gradient(
      ellipse 60vw 40vh at 30% 45%,
      rgba(163, 247, 191, 0.18) 0%,
      rgba(163, 247, 191, 0.10) 30%,
      rgba(163, 247, 191, 0.03) 60%,
      transparent 80%
    ),
    radial-gradient(
      ellipse 58vw 42vh at 72% 56%,
      rgba(120, 120, 255, 0.10) 0%,
      rgba(120, 120, 255, 0.05) 35%,
      rgba(120, 120, 255, 0.02) 65%,
      transparent 82%
    );
  background-size: 120% 120%, 120% 120%;
  background-position: 30% 55%, 70% 62%;

  filter: blur(190px);
  opacity: var(--bg-decor-opacity);

  transform: translate3d(0, var(--parallax-y), 0);
  will-change: background-position;
  animation: glow-drift 28s var(--ease) infinite alternate;
  transition: opacity 0.35s ease;
}

/* Light theme: keep glow cleaner */
[data-theme="light"] body::before {
  background-image:
    radial-gradient(
      ellipse 60vw 40vh at 30% 48%,
      rgba(15, 122, 74, 0.12) 0%,
      rgba(15, 122, 74, 0.06) 32%,
      rgba(15, 122, 74, 0.02) 62%,
      transparent 82%
    ),
    radial-gradient(
      ellipse 58vw 42vh at 72% 58%,
      rgba(120, 120, 255, 0.06) 0%,
      rgba(120, 120, 255, 0.03) 36%,
      rgba(120, 120, 255, 0.01) 66%,
      transparent 84%
    );
}

/* Dot-grid layer (not blurred) */
body::after {
  z-index: -1;

  background-image: radial-gradient(circle, var(--bg-dot) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: 0 0;

  opacity: 0.9;
}

@keyframes glow-drift {
  0% {
    background-position: 28% 58%, 74% 60%;
  }
  100% {
    background-position: 34% 50%, 68% 66%;
  }
}

a {
  color: inherit;
  text-decoration: none;
}

/* Scrollbar (subtle) */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--line-3);
  background-clip: content-box;
}

/* ---------- Reveal motion (IntersectionObserver) ---------- */
.reveal {
  opacity: 0;
  transform: translateY(20px);
  filter: blur(6px);
  transition: all 0.9s cubic-bezier(0.16, 1, 0.3, 1);
}

.reveal.revealed {
  opacity: 1;
  transform: none;
  filter: blur(0);
}

@media (prefers-reduced-motion: reduce) {
  .reveal {
    opacity: 1;
    transform: none;
    filter: none;
    transition: none;
  }
}

/* ---------- Reading progress ---------- */
#reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0;
  background: var(--accent);
  z-index: 300;
}

/* ---------- Topbar ---------- */
.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--topbar-h);
  z-index: 200;
  overflow: visible;

  /* Soft fade-out to avoid hard edge against background glow */
  background: linear-gradient(
    180deg,
    var(--topbar-bg) 0%,
    color-mix(in srgb, var(--topbar-bg) 86%, transparent) 65%,
    transparent 100%
  );
  backdrop-filter: blur(26px) saturate(180%);
  -webkit-backdrop-filter: blur(26px) saturate(180%);
  border-bottom: none;

  transition: background 0.3s ease;
}

/* Extra soft blend strip under the bar */
.topbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -24px;
  height: 24px;
  pointer-events: none;
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--topbar-bg) 34%, transparent) 0%,
    transparent 100%
  );
}

.topbar-inner {
  height: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 var(--gutter);

  display: flex;
  align-items: center;
  gap: 28px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: "Space Grotesk", Inter, system-ui, sans-serif;
  font-weight: 500;
  font-size: 14px;
  letter-spacing: -0.01em;
}

.brand-mark {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--text-1);
}

.brand-text .dot {
  color: var(--accent);
}

.top-nav {
  display: flex;
  align-items: center;
  gap: 18px;
  flex: 1;
}

.top-nav a {
  font-size: 13.5px;
  color: var(--text-3);
  letter-spacing: 0.01em;
  transition: color 180ms var(--ease);
}

.top-nav a:hover {
  color: var(--text-1);
}

.top-nav a.active {
  color: var(--text-1);
}

/* hide decorative icons in nav — keep pure editorial */
.top-nav a i {
  display: none;
}

.top-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;

  color: var(--text-3);
  border: 1px solid transparent;
  background: transparent;

  transition:
    color 180ms var(--ease),
    border-color 180ms var(--ease),
    box-shadow 180ms var(--ease);
}

.icon-btn:hover {
  color: var(--text-1);
  border-color: var(--line-2);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 10%, transparent);
}

.icon-btn i {
  font-size: 17px;
}

.mobile-only {
  display: none;
}

.desktop-only {
  display: inline-flex;
}

/* ---------- Layout ---------- */
.layout {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 var(--gutter);

  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  gap: var(--gap);
  align-items: start;
  transition: grid-template-columns 300ms var(--ease-out);
}

.sidebar,
.toc-rail {
  position: sticky;
  top: calc(var(--topbar-h) + 28px);
  max-height: calc(100vh - var(--topbar-h) - 40px);
  overflow: auto;
  padding: 56px 0 56px;
}

.main {
  min-height: calc(100vh - var(--topbar-h));
  padding: 56px 0 160px;
}

/* Desktop: global sidebar collapse */
@media (min-width: 901px) {
  .sidebar-collapsed .layout {
    grid-template-columns: 0px minmax(0, 1fr) var(--toc-w);
  }

  .sidebar-collapsed .sidebar {
    width: 0;
    padding: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
    transform: translateX(-10px);
  }
}

/* ---------- Sidebar (pure whitespace) ---------- */
.sidebar {
  background: transparent;
  border: none;
  transition: opacity 300ms var(--ease-out), transform 300ms var(--ease-out);
}

.sidebar-section + .sidebar-section {
  margin-top: 44px;
}

.sidebar-title {
  margin: 0 0 16px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-4);
  font-weight: 500;
}

.sidebar-title i {
  display: none;
}

.category-tree {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cat-node,
.cat-child,
.cat-viewall {
  user-select: none;
  cursor: pointer;
}

.cat-node {
  display: flex;
  align-items: center;
  gap: 8px;

  padding: 7px 0 7px 10px;
  margin-left: -10px;

  border-left: 2px solid transparent;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.4;

  transition: color 180ms var(--ease), border-color 180ms var(--ease);
}

.cat-node:hover {
  color: var(--text-1);
}

.cat-node.open {
  color: var(--text-1);
}

.cat-node.active {
  color: var(--text-1);
  border-left-color: var(--accent);
}

.cat-arrow {
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  color: var(--text-4);
}

.cat-arrow i {
  font-size: 14px;
  transition: transform 200ms var(--ease), color 200ms var(--ease);
}

.cat-node.open .cat-arrow i {
  transform: rotate(90deg);
  color: var(--text-2);
}

.cat-name {
  flex: 1;
  min-width: 0;
}

.cat-count {
  margin-left: auto;
  min-width: 26px;
  text-align: right;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  color: var(--text-4);
}

.cat-children {
  padding-left: 0;
  margin: 2px 0 12px;

  /* Reliable accordion: max-height + overflow clip.
     Avoids the fragile grid `0fr/1fr` fraction trick, which could collapse the
     open row (or fail to clip the closed one) inside the sticky overflow:auto
     sidebar on tall article pages, causing sub-titles to overlap the
     categories below. A category has at most a handful of children, so the
     open cap is comfortably larger than any real content height. */
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  visibility: hidden;
  transition:
    max-height 260ms var(--ease-out),
    opacity 200ms var(--ease-out),
    visibility 0ms linear 260ms;
}

.cat-children.open {
  max-height: 720px;
  opacity: 1;
  visibility: visible;
  transition:
    max-height 260ms var(--ease-out),
    opacity 200ms var(--ease-out),
    visibility 0ms linear 0ms;
}

/* Remove phantom vertical space while collapsed */
.cat-children:not(.open) {
  margin-top: 0;
  margin-bottom: 0;
}

.cat-children-inner {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-top: 6px;

  /* File-tree guide line: children hang under a 1px vertical rule that
     sits near the parent arrow's center. */
  margin-left: 8px;
  padding-left: 18px;
  border-left: 1px solid var(--line-2);
}

.cat-viewall,
.cat-child {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;

  padding: 5px 0 5px 2px;
  border-left: none;
  font-size: 13px;
  color: var(--text-4);
  transition: color 160ms var(--ease);
}

/* Accent segment on the guide line for the active child (file-tree feel) */
.cat-viewall.active::before,
.cat-child.active::before {
  content: "";
  position: absolute;
  left: -19px;
  top: 50%;
  transform: translateY(-50%);
  width: 2px;
  height: 15px;
  border-radius: 1px;
  background: var(--accent);
}

.cat-viewall {
  color: var(--text-4);
  font-size: 12px;
  letter-spacing: 0.01em;
}

.cat-viewall:hover,
.cat-child:hover {
  color: var(--text-2);
}

.cat-viewall.active,
.cat-child.active {
  color: var(--accent);
  font-weight: 500;
}

/* Sidebar tag cloud: no chip UI, just text */
.sidebar .tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.sidebar .tag-chip {
  border: none;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-4);
  font-size: 12.5px;
  letter-spacing: 0.01em;
}

.sidebar .tag-chip:hover {
  color: var(--text-2);
}

.sidebar-footer {
  margin-top: 56px;
  padding-top: 22px;
  border-top: 1px solid var(--line-1);
  color: var(--text-4);
  font-size: 11.5px;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

.sidebar-footer .mini {
  display: none; /* remove decorative emoji line */
}

/* ---------- Hero ---------- */
.hero {
  padding: 72px 0 64px;
}

.hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;

  font-size: 12px;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-3);

  margin-bottom: 22px;
}

.hero-eyebrow .pulse {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
}

.hero h1 {
  font-family: "Space Grotesk", Inter, system-ui, sans-serif;
  font-size: clamp(40px, 5.5vw, 64px);
  font-weight: 500;
  line-height: 1.08;
  letter-spacing: -0.03em;
  margin: 0 0 18px;
}

/* No rainbow, only one restrained emphasis */
.hero h1 .grad {
  color: var(--text-1);
  font-style: italic;
  position: relative;
  white-space: nowrap;
}

.hero h1 .grad::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0.08em;
  height: 1px;
  background: color-mix(in srgb, var(--accent) 85%, transparent);
}

.hero .lead {
  max-width: 720px;
  font-size: 16px;
  line-height: 1.7;
  color: var(--text-2);
  letter-spacing: -0.008em;
  margin: 0 0 26px;
}

.hero-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Keep hero to two CTAs (GitHub is already in topbar) */
.hero-actions .btn:nth-child(3) {
  display: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;

  height: 42px;
  padding: 0 18px;
  border-radius: 999px;

  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: 0.01em;

  color: var(--text-1);
  border: 1px solid color-mix(in srgb, var(--text-1) 20%, transparent);
  background: transparent;

  transition:
    transform 200ms var(--ease),
    border-color 200ms var(--ease),
    box-shadow 200ms var(--ease),
    background 200ms var(--ease),
    color 200ms var(--ease);
}

.btn i {
  font-size: 16px;
  opacity: 0.85;
}

.btn:hover {
  border-color: color-mix(in srgb, var(--text-1) 34%, transparent);
  box-shadow: 0 0 40px var(--card-glow);
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
  border-color: var(--btn-primary-border);
}

.btn-primary:hover {
  background: var(--btn-primary-hover-bg);
  border-color: var(--btn-primary-border);
}

/* Keyboard hint (subtle, no extra DOM) */
.hero-actions::after {
  content: "⌘ K  搜索";
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  color: var(--text-4);
  font-size: 11.5px;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  letter-spacing: 0.06em;
}

/* Hero footer: hairline via stats grid */
.stats-grid {
  margin-top: 56px;
  padding-top: 28px;
  border-top: 1px solid var(--line-1);

  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  background: var(--card-fill);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px 18px 16px;

  transition:
    transform 220ms var(--ease),
    border-color 220ms var(--ease),
    box-shadow 220ms var(--ease),
    background 220ms var(--ease),
    color 220ms var(--ease);
}

.stat-card:hover {
  border-color: var(--card-border-hover);
  box-shadow: 0 0 40px var(--card-glow);
  transform: translateY(-2px);
}

.stat-label {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-4);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

.stat-label i {
  display: none;
}

.stat-value {
  margin-top: 12px;
  font-family: "Space Grotesk", Inter, system-ui, sans-serif;
  font-size: 44px;
  line-height: 1;
  letter-spacing: -0.03em;
  font-weight: 400;
}

.stat-sub {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-3);
}

/* ---------- Sections ---------- */
.section {
  margin-top: var(--section-gap);
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;

  padding-bottom: 18px;
  margin-bottom: 30px;
  border-bottom: 1px solid var(--line-1);
}

.section-head h2 {
  margin: 0;
  font-family: "Space Grotesk", Inter, system-ui, sans-serif;
  font-size: 24px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.section-head a.more {
  font-size: 13px;
  color: var(--text-3);
  letter-spacing: 0.01em;
  transition: color 180ms var(--ease);
}

.section-head a.more:hover {
  color: var(--text-1);
}

.section-head a.more i {
  font-size: 14px;
}

/* ---------- Cards / Grids ---------- */
.articles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.article-card {
  position: relative;
  display: flex;
  flex-direction: column;

  padding: 18px 18px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--card-border);
  background: var(--card-fill);

  transition:
    transform 220ms var(--ease),
    border-color 220ms var(--ease),
    box-shadow 220ms var(--ease),
    background 220ms var(--ease),
    color 220ms var(--ease);
}

.article-card:hover {
  border-color: var(--card-border-hover);
  box-shadow: 0 0 40px var(--card-glow);
  transform: translateY(-2px);
}

/* Card content: category label · title · excerpt · bottom meta */
.article-meta-row {
  order: 4;
  margin-top: auto;

  display: flex;
  align-items: center;
  gap: 12px;

  font-size: 11px;
  color: var(--text-4);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  letter-spacing: 0.02em;
}

.article-meta-row i {
  display: none;
}

.article-cat {
  position: absolute;
  top: 16px;
  left: 18px;

  display: inline-flex;
  align-items: center;
  gap: 6px;

  font-size: 12px;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
}

.article-cat i {
  display: none;
}

.article-card h3 {
  margin: 26px 0 10px;
  font-family: "Space Grotesk", Inter, system-ui, sans-serif;
  font-size: 19px;
  font-weight: 500;
  letter-spacing: -0.015em;
  line-height: 1.3;
}

.article-excerpt {
  font-size: 13.5px;
  color: var(--text-muted);
  line-height: 1.65;

  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Remove extra footer UI for cards (keep page clean) */
.article-card .article-footer-row {
  display: none;
}

/* Feature grid */
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.feature-card {
  border-radius: var(--radius);
  border: 1px solid var(--card-border);
  background: var(--card-fill);
  padding: 22px 20px;

  transition:
    transform 220ms var(--ease),
    border-color 220ms var(--ease),
    box-shadow 220ms var(--ease),
    background 220ms var(--ease),
    color 220ms var(--ease);
}

.feature-card:hover {
  border-color: var(--card-border-hover);
  box-shadow: 0 0 40px var(--card-glow);
  transform: translateY(-2px);
}

.feature-icon {
  display: none; /* remove icon decoration, keep text-only */
}

.feature-card h3 {
  margin: 0 0 10px;
  font-family: "Space Grotesk", Inter, system-ui, sans-serif;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.feature-card p {
  margin: 0;
  color: var(--text-2);
  font-size: 13.5px;
  line-height: 1.7;
}

/* ---------- Article list / tags / about ---------- */
.page-head {
  margin: 18px 0 44px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line-1);
}

.page-head h1 {
  margin: 0 0 12px;
  font-family: "Space Grotesk", Inter, system-ui, sans-serif;
  font-size: clamp(44px, 6vw, 72px);
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 1.02;
}

.page-head h1 .grad {
  font-style: italic;
  position: relative;
}

.page-head h1 .grad::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0.08em;
  height: 1px;
  background: color-mix(in srgb, var(--accent) 70%, transparent);
}

.page-head .subtitle {
  margin: 0;
  color: var(--text-3);
  font-size: 14px;
  letter-spacing: 0.01em;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;

  padding: 0 0 18px;
  margin: 0 0 24px;
  border-bottom: 1px solid var(--line-1);
}

.filter-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-4);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;

  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: transparent;

  color: var(--text-3);
  font-size: 13px;
  letter-spacing: 0.01em;

  cursor: pointer;
  transition: border-color 180ms var(--ease), color 180ms var(--ease), background 180ms var(--ease);
}

.tag-chip:hover {
  color: var(--text-1);
  border-color: var(--line-3);
}

.tag-chip.active {
  color: var(--text-1);
  border-color: color-mix(in srgb, var(--accent) 70%, var(--line-3));
}

.empty {
  margin-top: 28px;
  padding: 70px 18px;
  border: 1px solid var(--line-1);
  border-radius: var(--radius);
  color: var(--text-3);
  text-align: center;
}

.empty i {
  display: none;
}

/* ---------- Article detail ---------- */
.article-detail {
  max-width: min(920px, 100%);
}

.article-hero {
  padding: 12px 0 40px;
  border-bottom: 1px solid var(--line-1);
  margin-bottom: 52px;
}

.article-hero .meta-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

/* The .article-cat rule uses position:absolute for the article-CARD corner.
   Inside the article-detail hero it must flow normally in the flex row,
   otherwise it is pulled out of flow and overlaps the sibling subcategory
   tag (.tag-mini) at the same top-left coordinate. */
.article-hero .meta-top .article-cat {
  position: static;
  top: auto;
  left: auto;
}

.article-hero .meta-top .tag-mini {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
}

.article-hero h1 {
  margin: 0 0 18px;
  font-family: "Space Grotesk", Inter, system-ui, sans-serif;
  font-size: clamp(34px, 4.6vw, 56px);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1.06;
}

.article-hero .meta-bottom {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;

  color: var(--text-4);
  font-size: 12px;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

.article-hero .meta-bottom i {
  display: none;
}

.article-tags .tag-mini {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  color: var(--text-3);
  font-size: 12px;
}

.article-content {
  font-size: 15.5px;
  line-height: 1.9;
  color: var(--text-2);
  letter-spacing: -0.003em;
}

.article-content p {
  margin: 1em 0;
}

.article-content h1,
.article-content h2,
.article-content h3,
.article-content h4 {
  margin: 2.1em 0 0.7em;
  color: var(--text-1);
  font-family: "Space Grotesk", Inter, system-ui, sans-serif;
  letter-spacing: -0.015em;
  scroll-margin-top: calc(var(--topbar-h) + 26px);
}

.article-content h2 {
  font-size: 24px;
}

.article-content h3 {
  font-size: 18px;
}

.article-content h4 {
  font-size: 15.5px;
}

.article-content a {
  color: var(--text-1);
  border-bottom: 1px solid var(--accent-dim);
  padding-bottom: 1px;
  transition: border-color 180ms var(--ease), color 180ms var(--ease);
}

.article-content a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.article-content strong {
  color: var(--text-1);
  font-weight: 600;
}

.article-content blockquote {
  margin: 1.7em 0;
  padding: 0 0 0 16px;
  border-left: 1px solid var(--accent);
  color: var(--text-2);
}

.article-content ul,
.article-content ol {
  margin: 1em 0;
  padding-left: 1.3em;
}

.article-content li {
  margin: 0.35em 0;
}

.article-content li::marker {
  color: var(--text-4);
}

.article-content img {
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-1);
  margin: 1.6em auto;
}

.article-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.8em 0;
  font-size: 13.5px;
  border-top: 1px solid var(--line-2);
  border-bottom: 1px solid var(--line-2);
}

.article-content th,
.article-content td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-1);
  text-align: left;
}

.article-content th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-4);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

.article-content tr:last-child td {
  border-bottom: none;
}

/* Inline code */
.article-content code:not(pre code) {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-size: 0.88em;

  padding: 1px 6px;
  border-radius: 4px;

  background: var(--inline-code-bg);
  border: 1px solid var(--line-1);
  color: var(--inline-code-fg);
}

/* Code blocks */
.article-content pre {
  position: relative;
  margin: 1.7em 0;
  border-radius: var(--radius);
  border: 1px solid var(--code-border);
  background: var(--code-bg) !important;
  overflow: hidden;
  transition: background 0.3s ease, border-color 0.3s ease;
}

.article-content pre code {
  display: block;
  padding: 22px 20px 18px !important;
  padding-top: 34px !important;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.7;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace !important;
  background: transparent !important;
}

.code-lang {
  position: absolute;
  top: 10px;
  left: 20px;
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-4);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;

  display: inline-flex;
  align-items: center;
  gap: 6px;

  height: 28px;
  padding: 0 10px;

  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: transparent;

  color: var(--text-4);
  font-size: 11px;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  letter-spacing: 0.02em;

  opacity: 0.0;
  transition: opacity 180ms var(--ease), border-color 180ms var(--ease), color 180ms var(--ease);
}

.article-content pre:hover .copy-btn {
  opacity: 1;
}

.copy-btn:hover {
  color: var(--text-2);
  border-color: var(--line-3);
}

.copy-btn.copied {
  opacity: 1;
  color: var(--accent);
  border-color: var(--accent-dim);
}

/* KaTeX */
.article-content .katex-display {
  margin: 1.7em 0;
  padding: 16px 16px;
  border: 1px solid var(--line-1);
  border-radius: var(--radius);
  background: var(--card-fill);
  overflow-x: auto;
}

/* Anchor link in headings */
.anchor-link {
  color: inherit;
}

.anchor-link:hover {
  color: var(--accent);
}

/* Article navigation */
.article-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 72px;
}

.article-nav a {
  border-radius: var(--radius);
  border: 1px solid var(--card-border);
  background: var(--card-fill);
  padding: 18px 18px;

  display: flex;
  flex-direction: column;
  gap: 8px;

  transition:
    transform 220ms var(--ease),
    border-color 220ms var(--ease),
    box-shadow 220ms var(--ease),
    background 220ms var(--ease),
    color 220ms var(--ease);
}

.article-nav a:hover {
  border-color: var(--card-border-hover);
  box-shadow: 0 0 40px var(--card-glow);
  transform: translateY(-2px);
}

.article-nav a.next {
  text-align: right;
}

.article-nav .dir {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-4);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

.article-nav .title {
  color: var(--text-1);
  font-family: "Space Grotesk", Inter, system-ui, sans-serif;
  font-size: 14.5px;
  letter-spacing: -0.01em;
  line-height: 1.4;
}

/* ---------- TOC rail ---------- */
.toc-rail {
  display: none;
}

.toc-rail.active {
  display: block;
}

.toc-title {
  margin: 0 0 16px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-4);
  font-weight: 500;
}

.toc-title i {
  display: none;
}

.toc {
  display: flex;
  flex-direction: column;
}

.toc a {
  display: block;
  padding: 6px 0 6px 12px;
  border-left: 1px solid var(--line-1);

  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-4);

  transition: color 180ms var(--ease), border-color 180ms var(--ease);
}

.toc a:hover {
  color: var(--text-2);
  border-left-color: var(--line-3);
}

.toc a.active {
  color: var(--text-1);
  border-left-color: var(--accent);
}

.toc .toc-h3 {
  padding-left: 22px;
  font-size: 12px;
}

.toc .toc-h4 {
  padding-left: 34px;
  font-size: 11.5px;
}

/* ---------- Back to top ---------- */
.back-to-top {
  position: fixed;
  right: 28px;
  bottom: 28px;
  z-index: 120;

  width: 44px;
  height: 44px;
  border-radius: 999px;

  background: var(--float-btn-bg);
  color: var(--float-btn-fg);

  display: inline-flex;
  align-items: center;
  justify-content: center;

  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);

  transition: background 0.3s ease, color 0.3s ease, opacity 200ms var(--ease), transform 200ms var(--ease), box-shadow 200ms var(--ease);
}

.back-to-top.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.back-to-top:hover {
  box-shadow: 0 0 40px var(--card-glow);
  transform: translateY(-2px);
}

/* ---------- Search modal ---------- */
.search-modal {
  position: fixed;
  inset: 0;
  z-index: 220;

  display: none;
  padding-top: 14vh;
  justify-content: center;
  align-items: flex-start;
}

.search-modal.open {
  display: flex;
}

.search-backdrop {
  position: absolute;
  inset: 0;
  background: var(--modal-backdrop);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background 0.3s ease;
}

.search-box {
  position: relative;
  width: min(680px, 92vw);
  border-radius: var(--radius);
  border: 1px solid var(--line-3);
  background: var(--bg-elev);
  overflow: hidden;
  box-shadow: var(--modal-shadow);
  transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.search-input-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 18px;
  border-bottom: 1px solid var(--line-1);
}

.search-input-wrap i {
  color: var(--text-4);
  font-size: 18px;
}

#search-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-1);
  font-size: 15.5px;
  letter-spacing: -0.01em;
}

#search-input::placeholder {
  color: var(--text-4);
}

kbd {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--line-2);
  color: var(--kbd-fg);
  background: var(--kbd-bg);
  transition: background 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.search-results {
  max-height: 52vh;
  overflow: auto;
  padding: 6px;
}

.search-item {
  display: block;
  padding: 12px 12px;
  border-radius: var(--radius);
  color: var(--text-1);
  transition: background 150ms var(--ease);
}

.search-item:hover,
.search-item.selected {
  background: color-mix(in srgb, var(--text-1) 5%, transparent);
}

.search-item .si-title {
  font-family: "Space Grotesk", Inter, system-ui, sans-serif;
  font-weight: 500;
  font-size: 14px;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-item .si-cat {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-size: 10px;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.search-item .si-preview {
  font-size: 12.5px;
  color: var(--text-3);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-item mark {
  background: color-mix(in srgb, var(--accent) 24%, transparent);
  color: var(--accent);
  padding: 0 2px;
  border-radius: 2px;
}

.search-footer {
  display: flex;
  gap: 18px;
  padding: 10px 16px;
  border-top: 1px solid var(--line-1);

  font-size: 11.5px;
  color: var(--text-4);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

.search-empty {
  padding: 44px 16px;
  color: var(--text-3);
  text-align: center;
}

/* ---------- Misc ---------- */
.page-enter {
  /* no global enter animation — reveal handles motion */
}

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .layout {
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 54px;
  }

  .toc-rail {
    display: none !important;
  }
}

@media (max-width: 900px) {
  :root {
    --gutter: 20px;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .topbar-inner {
    padding: 0 var(--gutter);
  }

  .top-nav {
    display: none;
  }

  .mobile-only {
    display: inline-flex;
  }

  .desktop-only {
    display: none;
  }

  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    width: 280px;
    height: calc(100vh - var(--topbar-h));

    padding: 26px 20px 26px;
    background: color-mix(in srgb, var(--bg) 86%, transparent);
    backdrop-filter: blur(18px) saturate(170%);
    -webkit-backdrop-filter: blur(18px) saturate(170%);
    border-right: 1px solid var(--line-2);

    transform: translateX(-100%);
    transition: transform 220ms var(--ease);
    z-index: 180;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .toc-rail {
    display: none !important;
  }

  .hero {
    padding: 62px 0 0;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .articles-grid {
    grid-template-columns: 1fr;
  }

  .article-nav {
    grid-template-columns: 1fr;
  }

  .back-to-top {
    right: 20px;
    bottom: 20px;
  }
}

@media (max-width: 500px) {
  .hero-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .btn {
    width: 100%;
  }

  .brand-text {
    display: none;
  }
}
