/* ============================================================
   wesslen.github.io — style.css
   Dark editorial theme for a data science / GenAI blog
   ============================================================ */

/* ── Google Fonts ────────────────────────────────────────── */
@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,400;0,600;1,400&family=IBM+Plex+Sans:ital,wght@0,300;0,400;0,500;0,600;1,400&display=swap");

/* ── CSS Custom Properties (dark mode default) ───────────── */
:root {
  --bg: #0d1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #38bdf8;
  --accent-dim: rgba(56, 189, 248, 0.12);
  --accent-glow: rgba(56, 189, 248, 0.25);
  --accent2: #a78bfa; /* violet — citations, secondary detail */
  --accent2-dim: rgba(167, 139, 250, 0.12);
  --code-bg: #1e2530;
  --code-text: #38bdf8; /* inline code color — same as accent in dark */
  --radius: 6px;
  --transition: 0.2s ease;
  --font-sans: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", "Fira Code", monospace;
}

/* ── Light Mode ──────────────────────────────────────────── */
[data-theme="light"] {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --border: #d0d7de;
  --text: #1f2328;
  --muted: #656d76;
  --accent: #0969da;
  --accent-dim: rgba(9, 105, 218, 0.08);
  --accent-glow: rgba(9, 105, 218, 0.2);
  --accent2: #7c3aed; /* deeper violet for light mode */
  --accent2-dim: rgba(124, 58, 237, 0.08);
  --code-bg: #eef1f6; /* more distinct from page bg */
  --code-text: #0550ae; /* deeper blue — better contrast on light */
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  transition:
    background var(--transition),
    color var(--transition);
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: opacity var(--transition);
}
a:hover {
  opacity: 0.8;
}

img {
  max-width: 100%;
  display: block;
}

/* ── Reading Progress Bar ────────────────────────────────── */
#progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: var(--accent);
  z-index: 1000;
  transition: width 0.1s linear;
  box-shadow: 0 0 8px var(--accent-glow);
}

/* ── Site Header ─────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(13, 17, 23, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  transition: background var(--transition);
}

[data-theme="light"] .site-header {
  background: rgba(246, 248, 250, 0.85);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-title {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}

.site-title .cursor {
  display: inline-block;
  color: var(--accent);
  animation: blink 1.1s step-end infinite;
  margin-left: 1px;
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ── Theme Toggle ────────────────────────────────────────── */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  border-radius: var(--radius);
  width: 44px; /* 44px minimum touch target */
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  touch-action: manipulation; /* remove 300ms tap delay */
  transition:
    border-color var(--transition),
    color var(--transition),
    background var(--transition);
}
.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

/* ── Hero / Dot-Grid ─────────────────────────────────────── */
.hero {
  position: relative;
  padding: 4rem 1.5rem 3.5rem;
  overflow: hidden;
}

/* Dot-grid background (notebook feel) */
.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, var(--border) 1px, transparent 1px);
  background-size: 24px 24px;
  opacity: 0.5;
  pointer-events: none;
}

/* Fade edges of dot grid */
.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 40%, var(--bg) 85%);
  pointer-events: none;
}

.hero-content {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0 auto;
}

.hero-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 0.75rem;
}

.hero h1 {
  font-family: var(--font-mono);
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.03em;
  margin-bottom: 1rem;
  color: var(--text);
}

.hero-desc {
  font-size: 1.05rem;
  color: var(--muted);
  max-width: 540px;
}

/* ── Layout ──────────────────────────────────────────────── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ── Post List ───────────────────────────────────────────── */
.posts-section {
  padding: 2rem 1.5rem 4rem;
}

.posts-header {
  max-width: 760px;
  margin: 0 auto 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
  width: 100%;
}

.post-list {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  list-style: none;
}

/* ── Post Card ───────────────────────────────────────────── */
.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition:
    border-color var(--transition),
    box-shadow var(--transition),
    transform var(--transition);
}

/* Left accent bar on hover */
.post-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
  transform: scaleY(0);
  transition: transform 0.2s ease;
  transform-origin: bottom;
}

/* Shimmer overlay on hover */
.post-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 0%, var(--accent-dim) 40%, transparent 70%);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.post-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  transform: translateY(-1px);
}
.post-card:hover::before {
  transform: scaleY(1);
}
.post-card:hover::after {
  opacity: 1;
}

.post-card a {
  color: inherit;
  text-decoration: none;
}
.post-card a::after {
  content: "";
  position: absolute;
  inset: 0;
}

.card-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap; /* let date + badge wrap on very small screens */
  gap: 0.5rem 1rem;
  margin-bottom: 0.6rem;
}

.card-date {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.05em;
}

.read-time-badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--muted);
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.15em 0.65em;
}

.card-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.4rem;
  line-height: 1.35;
}

.card-desc {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 0.9rem;
}

/* ── Tag Pills ───────────────────────────────────────────── */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tag {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  padding: 0.2em 0.65em;
  border-radius: 20px;
  border: 1px solid;
  font-weight: 400;
  /* Color set dynamically via JS hue rotation */
}

/* ── Post Page Layout ────────────────────────────────────── */
.post-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem 5rem;
}

@media (min-width: 1200px) {
  .post-layout {
    grid-template-columns: 1fr 240px;
    gap: 4rem;
    align-items: start;
  }
}

/* ── Back Link ───────────────────────────────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 2rem;
  transition: color var(--transition);
}
.back-link:hover {
  color: var(--accent);
  opacity: 1;
}
.back-link svg {
  width: 14px;
  height: 14px;
}

/* ── Post Header ─────────────────────────────────────────── */
.post-header {
  margin-bottom: 2.5rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.post-eyebrow {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.9rem;
  flex-wrap: wrap;
}

.post-date {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
}

.post-read-time {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.2em 0.75em;
}

.post-title {
  font-family: var(--font-mono);
  font-size: clamp(1.5rem, 3.5vw, 2rem);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.02em;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.post-description {
  font-size: 1rem;
  color: var(--muted);
  margin-bottom: 1rem;
  line-height: 1.65;
}

/* ── Prose ───────────────────────────────────────────────── */
.prose {
  font-size: 1rem;
  line-height: 1.8;
  color: var(--text);
  word-break: break-word; /* prevent long URLs from blowing out mobile layout */
  overflow-wrap: break-word;
}

/* h2: left accent bar — from Charlotte's content-slide title treatment */
.prose h2 {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text);
  margin: 2.5rem 0 0.75rem;
  padding-bottom: 0.4rem;
  padding-left: 0.85rem;
  border-left: 3px solid var(--accent);
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.01em;
}

.prose h3 {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin: 2rem 0 0.6rem;
  padding-left: 0.6rem;
  border-left: 2px solid var(--accent2);
}

.prose p {
  margin-bottom: 1.25rem;
}

.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--accent-dim);
  text-underline-offset: 3px;
  transition: text-decoration-color var(--transition);
}
.prose a:hover {
  text-decoration-color: var(--accent);
}

.prose blockquote {
  margin: 1.75rem 0;
  padding: 1rem 1.5rem;
  border-left: 3px solid var(--accent);
  background: var(--accent-dim);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--muted);
  font-style: italic;
}
.prose blockquote p {
  margin-bottom: 0;
}

/* ── GitHub-style Alerts ─────────────────────────────────── */
.prose .gh-alert {
  margin: 1.75rem 0;
  padding: 0.85rem 1.25rem;
  border-left: 4px solid;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-style: normal;
  color: var(--text);
}
.prose .gh-alert p {
  margin-bottom: 0.35rem;
}
.prose .gh-alert p:last-child {
  margin-bottom: 0;
}
.prose .gh-alert-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}

/* NOTE — blue */
.prose .gh-alert-note {
  background: rgba(56, 189, 248, 0.08);
  border-color: var(--accent);
}
.prose .gh-alert-note .gh-alert-title {
  color: var(--accent);
}

/* TIP — green */
.prose .gh-alert-tip {
  background: rgba(63, 185, 80, 0.08);
  border-color: #3fb950;
}
.prose .gh-alert-tip .gh-alert-title {
  color: #3fb950;
}
[data-theme="light"] .gh-alert-tip {
  background: rgba(31, 136, 61, 0.08);
  border-color: #1a7f37;
}
[data-theme="light"] .gh-alert-tip .gh-alert-title {
  color: #1a7f37;
}

/* IMPORTANT — violet */
.prose .gh-alert-important {
  background: rgba(167, 139, 250, 0.1);
  border-color: var(--accent2);
}
.prose .gh-alert-important .gh-alert-title {
  color: var(--accent2);
}

/* WARNING — amber */
.prose .gh-alert-warning {
  background: rgba(210, 153, 34, 0.1);
  border-color: #d29922;
}
.prose .gh-alert-warning .gh-alert-title {
  color: #d29922;
}
[data-theme="light"] .gh-alert-warning {
  background: rgba(154, 103, 0, 0.08);
  border-color: #9a6700;
}
[data-theme="light"] .gh-alert-warning .gh-alert-title {
  color: #9a6700;
}

/* CAUTION — red */
.prose .gh-alert-caution {
  background: rgba(248, 81, 73, 0.08);
  border-color: #f85149;
}
.prose .gh-alert-caution .gh-alert-title {
  color: #f85149;
}
[data-theme="light"] .gh-alert-caution {
  background: rgba(207, 34, 46, 0.08);
  border-color: #cf222e;
}
[data-theme="light"] .gh-alert-caution .gh-alert-title {
  color: #cf222e;
}

.prose ul,
.prose ol {
  margin: 0.75rem 0 1.25rem 1.25rem;
}
.prose li {
  margin-bottom: 0.35rem;
}

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

.prose strong {
  color: var(--text);
  font-weight: 600;
}
.prose em {
  color: var(--muted);
}

/* ── Inline Code ─────────────────────────────────────────── */
.prose code:not(pre code) {
  font-family: var(--font-mono);
  font-size: 0.855em;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.2em 0.55em;
  color: var(--code-text);
}

/* ── Code Blocks ─────────────────────────────────────────── */
.prose pre {
  position: relative;
  margin: 1.5rem 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

/* Language label tab */
.prose pre[data-lang]::before {
  content: attr(data-lang);
  position: absolute;
  top: 0;
  right: 3rem; /* leave room for copy button */
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0.3rem 0.6rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  border-left: 1px solid var(--border);
  border-radius: 0 0 0 4px;
  z-index: 2;
}

.prose pre code {
  display: block;
  overflow-x: auto;
  padding: 1.4rem 1.75rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.65;
  background: var(--code-bg) !important;
  -webkit-overflow-scrolling: touch; /* smooth momentum scroll on iOS */
}

/* Copy button */
.copy-btn {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 4px;
  padding: 0.25rem 0.55rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  cursor: pointer;
  opacity: 0;
  transition:
    opacity var(--transition),
    color var(--transition),
    border-color var(--transition);
  z-index: 5;
}

.prose pre:hover .copy-btn {
  opacity: 1;
}
.copy-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}
.copy-btn.copied {
  color: #3fb950;
  border-color: #3fb950;
}

/* ── Tables ──────────────────────────────────────────────── */

/* Wrapper div injected by wrapTables() — owns the scroll */
.table-scroll-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.75rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.885rem;
  /* margin/border/overflow now owned by wrapper */
  margin: 0;
  border: none;
  border-radius: 0;
}

.prose thead {
  background: var(--surface);
}

.prose thead th {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0.75rem 1.1rem;
  border-bottom: 2px solid var(--accent);
  text-align: left;
  white-space: nowrap;
  font-weight: 600;
}

.prose tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.prose tbody tr:last-child {
  border-bottom: none;
}
.prose tbody tr:hover {
  background: var(--accent-dim);
}

.prose tbody td {
  padding: 0.65rem 1.1rem;
  vertical-align: top;
  line-height: 1.55;
  /* Override the prose-level word-break so long table content
     triggers horizontal scroll instead of mid-word breaking */
  word-break: normal;
  overflow-wrap: normal;
}

/* ── Callout / Key-Insight Box ───────────────────────────── */
/* Usage: <div class="callout">text</div> in markdown */
.callout {
  margin: 1.75rem 0;
  padding: 1.1rem 1.4rem;
  background: var(--accent-dim);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.975rem;
  line-height: 1.7;
  color: var(--text);
}

.callout strong {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: block;
  margin-bottom: 0.4rem;
}

/* ── Citations & Footnotes ───────────────────────────────── */
/* Inline superscript: [^1] renders as <sup class="cite-ref"> */
.cite-ref {
  line-height: 0;
  vertical-align: super;
  font-size: 0.72em;
}

.cite-ref a {
  font-family: var(--font-mono);
  color: var(--accent2);
  text-decoration: none;
  padding: 0.05em 0.2em;
  border-radius: 3px;
  border: 1px solid var(--accent2-dim);
  background: var(--accent2-dim);
  font-size: 1em;
  transition:
    background var(--transition),
    border-color var(--transition);
}

.cite-ref a:hover {
  background: rgba(167, 139, 250, 0.22);
  border-color: var(--accent2);
  opacity: 1;
  text-decoration: none;
}

[data-theme="light"] .cite-ref a:hover {
  background: rgba(124, 58, 237, 0.15);
}

/* References section at end of post */
.citations {
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--border);
}

.citations-heading {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  /* override all prose h2 decoration */
  border: none !important;
  border-left: none !important;
  border-bottom: none !important;
  padding: 0 !important;
  margin: 0 0 1rem !important;
}

.cite-num {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent2);
  flex-shrink: 0;
  min-width: 1.5rem;
  font-weight: 600;
}

.cite-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.cite-list li {
  font-size: 0.865rem;
  color: var(--muted);
  line-height: 1.6;
  display: flex;
  gap: 0.65rem;
  align-items: baseline;
}

.cite-list li a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--accent-dim);
  word-break: break-all;
}

.cite-back {
  font-size: 0.85em;
  color: var(--accent2) !important;
  text-decoration: none !important;
  margin-left: 0.4rem;
  flex-shrink: 0;
}
.cite-back:hover {
  opacity: 0.7;
}

/* ── YouTube Embeds ──────────────────────────────────────── */
/* Inline syntax: [youtube: VIDEO_ID] or [youtube: VIDEO_ID?t=120] */
.yt-embed {
  margin: 2rem 0;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.yt-embed iframe {
  width: 100%;
  height: 100%;
  display: block;
  border: none;
}

.yt-caption {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.4rem;
  letter-spacing: 0.02em;
}

/* ── TOC Sidebar ─────────────────────────────────────────── */
.toc-sidebar {
  display: none;
}

@media (min-width: 1200px) {
  .toc-sidebar {
    display: block;
    position: sticky;
    top: 72px;
    max-height: calc(100vh - 90px);
    overflow-y: auto;
    border-left: 1px solid var(--border);
    padding-left: 1.5rem;
  }
}

.toc-title {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.85rem;
}

.toc-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.toc-item a {
  font-size: 0.82rem;
  color: var(--muted);
  display: block;
  padding: 0.2rem 0;
  line-height: 1.4;
  transition:
    color var(--transition),
    padding-left var(--transition);
  border-left: 2px solid transparent;
  padding-left: 0.6rem;
  margin-left: -0.6rem;
}

.toc-item a:hover,
.toc-item a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  opacity: 1;
}

.toc-item.h3 a {
  padding-left: 1.4rem;
  margin-left: -0.6rem;
  font-size: 0.78rem;
}

/* Mobile TOC toggle */
.toc-mobile {
  margin-bottom: 2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

@media (min-width: 1200px) {
  .toc-mobile {
    display: none;
  }
}

.toc-mobile-toggle {
  width: 100%;
  background: var(--surface);
  border: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.85rem 1rem;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  touch-action: manipulation; /* remove 300ms tap delay */
  min-height: 44px; /* minimum touch target height */
}

.toc-mobile-toggle .toc-chevron {
  transition: transform 0.2s ease;
  font-size: 0.7rem;
  color: var(--muted);
}
.toc-mobile.open .toc-chevron {
  transform: rotate(180deg);
}

.toc-mobile-body {
  display: none;
  padding: 0.5rem 1rem 1rem;
  background: var(--surface);
}
.toc-mobile.open .toc-mobile-body {
  display: block;
}

.toc-mobile-body .toc-list {
  gap: 0.15rem;
}

/* ── Footer ──────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
}
.site-footer a {
  color: var(--muted);
}
.site-footer a:hover {
  color: var(--accent);
  opacity: 1;
}
.footer-disclaimer {
  margin-top: 0.5rem;
  font-size: 0.65rem;
  opacity: 0.6;
  line-height: 1.5;
}

/* ── Loading / Error States ──────────────────────────────── */
.loading-state,
.error-state {
  text-align: center;
  padding: 4rem 1.5rem;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--muted);
}

.loading-dots::after {
  content: "";
  animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots {
  0% {
    content: "";
  }
  25% {
    content: ".";
  }
  50% {
    content: "..";
  }
  75% {
    content: "...";
  }
  100% {
    content: "";
  }
}

/* ── Highlight.js overrides ──────────────────────────────── */
.hljs {
  background: var(--code-bg) !important;
  padding: 0 !important;
}

/* Light mode: ensure hljs tokens are readable on light bg */
[data-theme="light"] .hljs {
  color: #24292e;
}

/* ── Responsive tweaks ───────────────────────────────────── */

/* Tablet: 641px – 1199px ---------------------------------- */
@media (min-width: 641px) and (max-width: 1199px) {
  /* Constrain line length so text doesn't span the full tablet width */
  .prose {
    max-width: 680px;
  }
  /* Give the hero a comfortable mid-range padding */
  .hero {
    padding: 3rem 2rem 2.5rem;
  }
  .posts-section {
    padding: 2rem 2rem 4rem;
  }
  .post-layout {
    padding: 2rem 2rem 5rem;
  }
}

/* Small mobile: ≤ 640px ------------------------------------ */
@media (max-width: 640px) {
  /* Shrink site title so it fits alongside the 44px toggle */
  .site-title {
    font-size: 0.9rem;
  }

  .post-layout {
    padding: 1.5rem 1rem 4rem;
  }
  .posts-section {
    padding: 1.5rem 1rem 4rem;
  }
  .hero {
    padding: 2.5rem 1rem 2rem;
  }
  .post-card {
    padding: 1.2rem 1.25rem;
  }

  .prose pre code {
    padding: 1.1rem 1.25rem;
    font-size: 0.82rem;
  }
  .yt-embed {
    margin: 1.5rem 0;
  }

  /* Tighten blockquote / alert padding on narrow screens */
  .prose blockquote,
  .prose .gh-alert {
    padding: 0.75rem 1rem;
  }
}

/* Tiny: ≤ 360px (Galaxy S8, SE 1st gen, etc.) ------------- */
@media (max-width: 360px) {
  .site-title {
    font-size: 0.8rem;
    letter-spacing: -0.01em;
  }
  .hero h1 {
    font-size: 1.35rem;
  }
  .post-card {
    padding: 1rem;
  }
}

/* ── Nav Link (About etc. in site header) ────────────────── */
.nav-link {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  padding: 0.25rem 0.6rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  transition:
    color var(--transition),
    border-color var(--transition),
    background var(--transition);
  white-space: nowrap;
}
.nav-link:hover,
.nav-link.active {
  color: var(--accent);
  border-color: var(--border);
  background: var(--accent-dim);
  opacity: 1;
}

/* ── Tag Filter Bar (index.html) ─────────────────────────── */
.tag-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 1.75rem;
}

.tag-filter-btn {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  padding: 0.3rem 0.75rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition:
    color var(--transition),
    border-color var(--transition),
    background var(--transition);
  touch-action: manipulation;
}

.tag-filter-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tag-filter-btn.active[data-tag="__all__"] {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

/* ── Collapsible References (post.html) ──────────────────── */
.citations-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  margin-bottom: 1rem;
}

.citations-toggle:hover .citations-heading {
  color: var(--accent);
}

.citations-chevron {
  font-size: 0.7rem;
  color: var(--muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.citations-toggle[aria-expanded="false"] .citations-chevron {
  transform: rotate(-90deg);
}

.cite-list.collapsed {
  display: none;
}

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