/* ── TOKENS ── */
:root,
[data-theme="dark"] {
  --bg: #0d0d0f;
  --surface: #141418;
  --border: #242430;
  --accent: #e8613a;
  --accent-dim: rgba(232, 97, 58, 0.12);
  --accent2: #5b8af5;
  --text: #e8e6e0;
  --text-dim: #8a8880;
  --text-mid: #b5b2aa;
  --code-bg: #1a1a22;
  --good: #4caf82;
  --bad: #e05555;
  --grain-opacity: 0.4;
}

[data-theme="light"] {
  --bg: #f7f5f0;
  --surface: #f0ede6;
  --border: #d5d0c6;
  --accent: #c9501f;
  --accent-dim: rgba(201, 80, 31, 0.10);
  --accent2: #3a65d4;
  --text: #1c1a16;
  --text-dim: #7a756d;
  --text-mid: #4a4640;
  --code-bg: #f0ede6;
  --good: #2d8a5e;
  --bad: #c03030;
  --grain-opacity: 0.15;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: 17px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

/* ── GRAIN OVERLAY ── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
  opacity: var(--grain-opacity);
}

/* ── THEME TOGGLE ── */
.theme-toggle {
  position: fixed;
  top: 24px;
  right: 24px;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  z-index: 10000;
}
.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ── LAYOUT ── */
.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 28px;
}

/* ── NAVIGATION ── */
.site-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}

.nav-back {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  text-decoration: none;
  transition: color 0.15s ease;
}
.nav-back:hover { color: var(--accent); }

.nav-logo {
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  text-decoration: none;
  transition: color 0.15s ease;
}
.nav-logo:hover { color: var(--text); }

/* ── HOME PAGE ── */
header.home-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}

.home-logo {
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--text);
  font-weight: 500;
  flex-shrink: 0;
}

.home-desc {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  font-weight: 400;
  text-align: right;
  line-height: 1.6;
}

/* ── POST LIST ── */
.post-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 80px;
  animation: fadeUp 0.9s 0.08s ease both;
}

.post-card {
  display: block;
  padding: 28px 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  transition: border-color 0.15s ease;
}
.post-card:hover .post-title { color: var(--accent); }
.post-card:first-child { border-top: none; }

.post-category {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  display: block;
  margin-bottom: 10px;
}

.post-title {
  font-family: 'Instrument Serif', serif;
  font-size: 1.5rem;
  font-weight: 400;
  color: var(--text);
  line-height: 1.25;
  margin-bottom: 10px;
  transition: color 0.15s ease;
}

.post-subtitle {
  font-size: 0.92rem;
  color: var(--text-dim);
  font-weight: 300;
  line-height: 1.65;
  margin-bottom: 14px;
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.06em;
}

/* ── ARTICLE HEADER ── */
header {
  padding: 80px 0 60px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 64px;
  animation: fadeUp 0.8s ease both;
}

.eyebrow {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.eyebrow::after {
  content: '';
  display: inline-block;
  height: 1px;
  width: 40px;
  background: var(--accent);
  opacity: 0.5;
}

h1 {
  font-family: 'Instrument Serif', serif;
  font-size: clamp(2.2rem, 5vw, 3.2rem);
  line-height: 1.18;
  font-weight: 400;
  color: var(--text);
  margin-bottom: 24px;
  letter-spacing: -0.01em;
}

h1 em,
.post-card .post-title em {
  font-style: italic;
  color: var(--accent);
}

.subtitle {
  font-size: 1.05rem;
  color: var(--text-mid);
  font-weight: 300;
  max-width: 560px;
  line-height: 1.7;
}

.meta {
  margin-top: 32px;
  display: flex;
  align-items: center;
  gap: 20px;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.06em;
}
.meta-dot { color: var(--border); }

/* ── ARTICLE BODY ── */
article {
  animation: fadeUp 0.9s 0.1s ease both;
  padding-bottom: 80px;
}

article p {
  color: var(--text-mid);
  margin-bottom: 1.6em;
  font-weight: 300;
}

article p strong {
  color: var(--text);
  font-weight: 500;
}

article ul,
article ol {
  margin: 0 0 1.6em 1.4em;
  color: var(--text-mid);
  font-weight: 300;
  line-height: 1.9;
}

article ul li,
article ol li {
  margin-bottom: 0.3em;
}

article ul li strong,
article ol li strong {
  color: var(--text);
  font-weight: 500;
}

article code {
  font-family: 'DM Mono', monospace;
  font-size: 0.82em;
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--text);
}

/* ── SECTION HEADINGS ── */
article h2 {
  font-family: 'Instrument Serif', serif;
  font-size: 1.7rem;
  font-weight: 400;
  color: var(--text);
  margin-bottom: 6px;
  margin-top: 64px;
  line-height: 1.3;
}

.section-label {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 14px;
  display: block;
}

/* ── CALLOUT BOXES ── */
.callout {
  border-left: 3px solid var(--accent);
  background: var(--accent-dim);
  padding: 18px 22px;
  border-radius: 0 6px 6px 0;
  margin: 32px 0;
}
.callout p {
  margin: 0;
  color: var(--text);
  font-size: 0.95rem;
}
.callout > div > p:last-child { margin-bottom: 0; }
.callout-title {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
  display: block;
}
.callout.info {
  border-left-color: var(--accent2);
  background: rgba(91, 138, 245, 0.08);
}
.callout.info .callout-title { color: var(--accent2); }

/* ── DEFINITION BOXES ── */
.definition {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 22px;
  margin: 28px 0;
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px 16px;
  align-items: start;
}
.definition-icon {
  width: 36px;
  height: 28px;
  background: var(--accent-dim);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin-top: 2px;
  flex-shrink: 0;
  white-space: nowrap;
}
.definition-term {
  font-weight: 500;
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 4px;
  font-family: 'Bricolage Grotesque', sans-serif;
}
.definition-desc {
  font-size: 0.88rem;
  color: var(--text-mid);
  line-height: 1.6;
  margin: 0;
  font-weight: 300;
}
.definition-desc p { margin: 0; font-size: inherit; color: inherit; }
.definition-desc p:last-child { margin-bottom: 0; }

/* ── CODE BLOCKS ── */
.code-block {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin: 28px 0;
  font-family: 'DM Mono', monospace;
  font-size: 13px;
}
.code-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.code-label {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.code-label.bad { color: var(--bad); }
.code-label.good { color: var(--good); }
.code-label.neutral { color: var(--text-dim); }
.code-dots { display: flex; gap: 6px; }
.code-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
}
.code-body-wrapper { overflow-x: auto; }
.code-complexity {
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  letter-spacing: 0.06em;
  font-family: 'DM Mono', monospace;
}
.code-complexity.bad { color: var(--bad); background: rgba(224, 85, 85, 0.06); }
.code-complexity.good { color: var(--good); background: rgba(76, 175, 130, 0.06); }

/* ── CHROMA SYNTAX HIGHLIGHT OVERRIDES ── */
.code-block .highlight { margin: 0; }
.code-block .highlight pre {
  background: transparent !important;
  padding: 18px 32px !important;
  margin: 0;
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  line-height: 1.6;
  overflow-x: auto;
}
.code-block .highlight code {
  background: transparent;
  border: none;
  padding: 0;
  font-size: 13px;
}

/* ── COMPARISON TABLE ── */
.compare-table {
  width: 100%;
  border-collapse: collapse;
  margin: 32px 0;
  font-size: 0.9rem;
}
.compare-table th {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-weight: 400;
}
.compare-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-mid);
  font-weight: 300;
  vertical-align: top;
}
.compare-table tr:last-child td { border-bottom: none; }
.compare-table td:first-child {
  font-weight: 500;
  color: var(--text);
  font-size: 0.88rem;
  white-space: nowrap;
}

/* ── TAGS ── */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.08em;
}
.tag.bad { background: rgba(224, 85, 85, 0.12); color: var(--bad); }
.tag.good { background: rgba(76, 175, 130, 0.12); color: var(--good); }
.tag.neutral { background: var(--surface); color: var(--text-dim); border: 1px solid var(--border); }

/* ── PILLAR CARDS ── */
.pillars {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin: 32px 0;
}
.pillar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 22px;
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 16px;
  align-items: start;
}
.pillar-num {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: 6px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  flex-shrink: 0;
}
.pillar-title {
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
  font-size: 0.95rem;
}
.pillar-desc {
  font-size: 0.88rem;
  color: var(--text-mid);
  margin: 0;
  font-weight: 300;
  line-height: 1.6;
}
.pillar-desc p { font-size: inherit; color: inherit; margin: 0; }

/* ── DIVIDER ── */
article hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 56px 0;
}

/* ── FOOTNOTE ── */
.footnote {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  margin: 28px 0;
  font-size: 0.88rem;
  color: var(--text-dim);
  font-weight: 300;
  line-height: 1.65;
}
.footnote p { font-size: inherit; color: inherit; margin: 0; }
.footnote strong { color: var(--text-mid); font-weight: 500; }

/* ── CONCLUSION BOX ── */
.conclusion {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px;
  margin-top: 64px;
}
.conclusion h2 {
  margin-top: 0;
  margin-bottom: 16px;
}
.conclusion p {
  margin-bottom: 1em;
}
.conclusion p:last-child { margin-bottom: 0; }

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

/* ── DIAGRAMS ── */
.diagram {
  margin: 32px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.diagram-inner {
  padding: 24px;
  display: flex;
  justify-content: center;
  overflow-x: auto;
  background: var(--surface);
}
.diagram-inner svg {
  max-width: 100%;
  height: auto;
  display: block;
}
.diagram-caption {
  display: block;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* dark is the default — hide light variant unless explicitly in light mode */
.diagram-light { display: none; }
[data-theme="light"] .diagram-light { display: flex; }
[data-theme="light"] .diagram-dark  { display: none; }

/* ── LIGHT MODE: CODE BLOCK OVERRIDES ── */
/* Nord embeds inline background/color on <pre> — force override for light mode */
[data-theme="light"] .code-block .highlight pre {
  background-color: var(--code-bg) !important;
  color: var(--text) !important;
}
/* Tag colours stay semantic */
[data-theme="light"] .tag.bad { background: rgba(192, 48, 48, 0.10); }
[data-theme="light"] .tag.good { background: rgba(45, 138, 94, 0.12); }

/* ── RESPONSIVE ── */
@media (max-width: 600px) {
  .container { padding: 0 18px; }
  header { padding: 48px 0 40px; }
  h1 { font-size: 2rem; }
  .conclusion { padding: 24px; }
  header.home-header { flex-direction: column; gap: 6px; }
  .home-desc { text-align: left; }
  .theme-toggle { top: 16px; right: 16px; }
}
