/* ========================================
   Brandon Chui's Website - Main Stylesheet
   ======================================== */

/* Self-hosted fonts (Latin subset). `swap` renders fallback immediately, then swaps when loaded. */
@font-face {
  font-family: 'Fira Code';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/FiraCode-400.woff2') format('woff2');
}
/* Variable fonts: one file covers every weight, so declare the full wght range once. */
@font-face {
  font-family: 'Source Serif 4';
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url('/fonts/SourceSerif4-var.woff2') format('woff2');
}
@font-face {
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/fonts/Montserrat-var.woff2') format('woff2');
}

/* ========================================
   CSS Custom Properties (Light/Dark Theme)
   ======================================== */
:root {
  /* Light Mode Colors */
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --border-color: #e5e7eb;
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --code-bg: rgba(0, 0, 0, 0.05);
  --code-text: #b45309;
  --code-border: #e5e7eb;

  /* Reading text: page body, headings and meta on every page. Nav and chrome keep the tokens above. */
  --prose-text: #374151;
  --prose-heading: #111827;
  --meta-text: #6b7280;

  /* Typography */
  --font-heading: 'Montserrat', sans-serif;
  --font-body: 'Source Serif 4', Georgia, serif;
  --font-code: 'Fira Code', monospace;

  /* Spacing */
  --sidebar-width: 280px;
  --nav-height: 64px;
  --content-max-width: 800px;
  /* Post prose stays at a ~68 character measure; code blocks bleed past it by --code-bleed each side. */
  --prose-measure: 640px;
  --code-bleed: 1.5rem;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 300ms ease;
}

[data-theme="dark"] {
  --bg-primary: #1C1C1C;
  --bg-secondary: #222222;
  --border-color: #333333;
  --text-primary: #d1d5db;
  --text-secondary: #a1a1aa;
  /* #8a8a8a keeps small grey text at 4.5:1+ on both dark backgrounds (#737373 was 3.4–3.6:1). */
  --text-muted: #8a8a8a;
  --accent: #ffffff;
  --accent-hover: #ffffff;
  --code-bg: #282828;
  --code-text: #ebdbb2;
  --code-border: #3c3836;
  /* Brighter, slightly warm prose: #a1a1aa was 6.6:1 and #737373 meta text 3.6:1 (below AA). */
  --prose-text: #e2e2df;
  --prose-heading: #ffffff;
  --meta-text: #a3a3a3;
  /* Native scrollbars (and any browser-rendered controls) match the theme. */
  color-scheme: dark;
}

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

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--accent-hover);
}

img {
  max-width: 100%;
  height: auto;
}

/* ========================================
   Typography
   ======================================== */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 1rem;
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }

p {
  margin-bottom: 1rem;
}

code, pre {
  font-family: var(--font-code);
}

:not(pre) > code {
  background-color: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--code-border);
  padding: 0.2em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
}

pre {
  background-color: var(--bg-secondary);
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
}

pre code {
  background: none;
  padding: 0;
  border: none;
}

.code-block-wrapper {
  position: relative;
  margin: 1.5rem 0;
}

.code-block-wrapper pre,
.blog-post-content .code-block-wrapper pre {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  margin: 0;
}

.code-annotation {
  font-family: var(--font-code);
  font-size: 0.75rem;
  color: var(--meta-text);
  background-color: var(--border-color);
  padding: 0.35rem 1rem;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
  border: 1px solid var(--border-color);
  border-bottom: none;
  line-height: 1.4;
}

.callout {
  border-left: 3px solid var(--border-color);
  background-color: var(--bg-secondary);
  border-radius: 0 6px 6px 0;
  padding: 0.75rem 1rem;
  margin: 1.5rem 0;
  font-size: 1rem;
  line-height: 1.6;
}

.callout-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--meta-text);
  margin-bottom: 0.35rem;
}

.callout-content p:last-child {
  margin-bottom: 0;
}

pre mark {
  display: block;
  background-color: rgba(255, 255, 255, 0.06);
  border-left: 2px solid var(--text-muted);
  margin: 0 -1rem;
  padding: 0 calc(1rem - 2px);
  color: inherit;
}

pre.giallo code {
  display: flex;
  flex-direction: column;
}

.giallo-l {
  display: block;
  margin: 0 -1rem;
  padding: 0 1rem;
}

/* Blank source lines come out as empty spans; give them a line box so they keep their height. */
.giallo-l:empty::after {
  content: "\200b";
}

/* Highlighted lines (hl_lines=...) — dual-theme class output sets `.z-l-hl` / `.z-d-hl` on the line span.
   Override the theme-provided bg with a neutral semi-transparent gray so the highlight
   is visible against both gruvbox-dark and the off-white github-light code block. */
.z-l-hl,
.z-d-hl {
  display: block;
  margin: 0 -1rem;
  padding-left: calc(1rem - 2px);
  padding-right: 1rem;
  border-left: 2px solid var(--text-muted);
  background-color: rgba(127, 127, 127, 0.18) !important;
}

/* github-light's code background is pure white — same as page bg. Tint it so the block stands out. */
[data-theme="light"] .z-l-code {
  background-color: var(--bg-secondary);
}

[data-theme="light"] pre mark {
  background-color: rgba(0, 0, 0, 0.04);
}

/* ========================================
   Layout Structure
   ======================================== */

/* Desktop Sidebar Layout (>1280px) */
.layout {
  display: flex;
  min-height: 100vh;
  /* `clip` (not `hidden`) — `hidden` creates a scroll container that breaks
     `position: sticky` on descendants like the right-side TOC. */
  overflow-x: clip;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: 2rem;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-header {
  text-align: center;
  margin-bottom: 2rem;
}

.profile-pic {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--border-color);
  margin-bottom: 1rem;
}

.site-title {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--prose-heading);
  margin-bottom: 0.25rem;
}

/* Role sits between the name and the tagline: a step brighter and heavier than the tagline. */
.site-role {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--meta-text);
  margin-bottom: 0.5rem;
}

.site-tagline {
  font-size: 0.875rem;
  font-style: italic;
  color: var(--text-muted);
}

/* Sidebar Navigation */
.sidebar-nav {
  flex: 1;
}

.sidebar-nav ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.875rem;
}

/* Plain words: the current page in the heading colour, the rest in meta grey. */
.sidebar-nav a {
  font-size: 1.125rem;
  color: var(--meta-text);
  transition: color var(--transition-fast);
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  color: var(--prose-heading);
}

.sidebar-nav a.active {
  font-weight: 600;
}

/* Dark Mode Toggle in Sidebar */
.sidebar-footer {
  padding-top: 1rem;
}

.sidebar-social {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.sidebar-social a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--text-muted);
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.sidebar-social a:hover {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}

.sidebar-social svg {
  width: 18px;
  height: 18px;
}

/* Main Content Area */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.content-wrapper {
  flex: 1;
  padding: 2rem;
  max-width: var(--content-max-width);
  margin: 0 auto;
  width: 100%;
}

/* ========================================
   Top Navigation (Tablet: 640px - 1280px)
   ======================================== */
.top-nav {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0 1.5rem;
  z-index: 100;
  transition: transform var(--transition-normal);
}

.top-nav.hidden {
  transform: translateY(-100%);
}

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

.top-nav-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.top-nav-brand img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.nav-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border: 2px solid var(--border-color);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.nav-avatar:hover {
  border-color: var(--text-muted);
  color: var(--accent);
}

.nav-avatar-lg {
  width: 120px;
  height: 120px;
  font-size: 3rem;
  margin: 0 auto 1rem;
}

/* The pixel avatar stands on its own in the sidebar, no ring. */
.sidebar .nav-avatar-lg {
  border: 0;
  background: none;
}

/* 32x32 pixel-art avatar: scale by whole multiples with no smoothing so the pixels stay crisp. */
.nav-avatar img {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
}

.nav-avatar-lg img {
  width: 96px;
  height: 96px;
}

.top-nav-brand span {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text-primary);
}

.top-nav-links {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  list-style: none;
}

.top-nav-links a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-primary);
  font-weight: 500;
  padding: 0.5rem;
  transition: color var(--transition-fast);
}

.top-nav-links a:hover,
.top-nav-links a.active {
  color: var(--accent);
}

/* ========================================
   Mobile Navigation (<640px)
   ======================================== */
.mobile-nav {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0 1rem;
  z-index: 100;
}

.mobile-nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.mobile-nav-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text-primary);
}

/* Hamburger Button */
.hamburger {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  width: 28px;
  height: 24px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  z-index: 110;
}

.hamburger span {
  width: 100%;
  height: 3px;
  background-color: var(--text-primary);
  border-radius: 2px;
  transition: all var(--transition-fast);
}

.hamburger.active span:nth-child(1) {
  transform: rotate(45deg) translate(6px, 6px);
}

.hamburger.active span:nth-child(2) {
  opacity: 0;
}

.hamburger.active span:nth-child(3) {
  transform: rotate(-45deg) translate(6px, -6px);
}

/* Mobile Menu Overlay */
.mobile-menu-overlay {
  position: fixed;
  top: var(--nav-height);
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-primary);
  z-index: 99;
  padding: 2rem;
  transform: translateX(-100%);
  transition: transform var(--transition-normal);
}

.mobile-menu-overlay.active {
  transform: translateX(0);
}

/* Role and tagline sit above the links, stacked like the desktop sidebar header. */
.mobile-menu-intro {
  text-align: center;
  margin-bottom: 2rem;
}

/* Same plain-word menu as the desktop sidebar: current page in the heading colour. */
.mobile-menu-overlay ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.mobile-menu-overlay ul a {
  display: block;
  padding: 0.75rem 1.5rem;
  font-size: 1.375rem;
  color: var(--meta-text);
  transition: color var(--transition-fast);
}

.mobile-menu-overlay ul a:hover,
.mobile-menu-overlay ul a.active {
  color: var(--prose-heading);
}

.mobile-menu-overlay ul a.active {
  font-weight: 600;
}

/* ========================================
   Dark Mode Toggle Button
   ======================================== */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: none;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-muted);
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.theme-toggle:hover {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

.theme-toggle .sun-icon {
  display: none;
}

.theme-toggle .moon-icon {
  display: block;
}

[data-theme="dark"] .theme-toggle .sun-icon {
  display: block;
}

[data-theme="dark"] .theme-toggle .moon-icon {
  display: none;
}

/* ========================================
   Home Page Styles
   ======================================== */
.home-intro {
  text-align: center;
  padding: 3rem 0;
}

.home-intro h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

.home-intro p {
  font-size: 1.125rem;
  color: var(--text-muted);
  max-width: 600px;
  margin: 0 auto 2rem;
}

/* Navigation Cards Grid */
.nav-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
  margin-top: 2rem;
}

.nav-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.nav-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
  border-color: var(--accent);
}

[data-theme="dark"] .nav-card:hover {
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.nav-card h3 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.nav-card p {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 0;
}

.nav-card a {
  display: block;
  color: inherit;
  text-decoration: none;
}

/* ========================================
   Footer
   ======================================== */
.footer {
  padding: 2rem;
  border-top: none;
  text-align: center;
}

.footer::before {
  display: none;
}

.footer-social {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.footer-social a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--bg-secondary);
  color: var(--text-muted);
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.footer-social a:hover {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}

.footer-social svg {
  width: 20px;
  height: 20px;
}

.footer-copyright {
  font-size: 0.875rem;
  color: var(--text-muted);
}

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

/* Tablet: 640px - 1280px */
@media (max-width: 1280px) {
  .sidebar {
    display: none;
  }

  .top-nav {
    display: block;
  }

  .main-content {
    margin-left: 0;
    padding-top: var(--nav-height);
  }

  .content-wrapper {
    padding: 1.5rem;
  }
}

/* Mobile: < 640px */
@media (max-width: 640px) {
  .top-nav {
    display: none;
  }

  .mobile-nav {
    display: block;
  }

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

  .home-intro h1 {
    font-size: 2rem;
  }

  .home-intro p {
    font-size: 1rem;
  }

  h1 { font-size: 2rem; }
  h2 { font-size: 1.5rem; }
  h3 { font-size: 1.25rem; }

  .mobile-menu-overlay .sidebar-social a,
  .mobile-menu-overlay .sidebar-social .theme-toggle {
    width: 48px;
    height: 48px;
  }

  .mobile-menu-overlay .sidebar-social svg {
    width: 24px;
    height: 24px;
  }
}

/* ========================================
   Utility Classes
   ======================================== */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.container {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 0 1rem;
}

/* ========================================
   Projects Page Styles
   ======================================== */

/* Screenshot first, text beside it; whitespace separates projects instead of rules. */
.projects-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2.25rem;
}

.project-row a {
  display: flex;
  align-items: flex-start;
  gap: 1.75rem;
  color: inherit;
  text-decoration: none;
}

.project-thumb {
  flex-shrink: 0;
  width: 224px;
  height: 126px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border-color);
}

.project-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  padding-top: 0.25rem;
}

.project-title {
  font-size: 1.125rem;
  font-weight: 500;
  line-height: 1.3;
  color: var(--prose-heading);
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 0.2em;
  transition: text-decoration-color var(--transition-fast);
}

.project-row a:hover .project-title,
.project-row a:focus-visible .project-title {
  text-decoration-color: currentColor;
}

.project-desc {
  font-size: 1.0625rem;
  line-height: 1.55;
  color: var(--prose-text);
}

.tag {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  background-color: var(--bg-secondary);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

a.tag-link {
  text-decoration: none;
  transition: color var(--transition-fast), border-color var(--transition-fast), background-color var(--transition-fast);
}

a.tag-link:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
  background-color: var(--bg-primary);
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

.tag-cloud-item {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem;
}

.tag-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  background-color: var(--border-color);
  padding: 0.05rem 0.4rem;
  border-radius: 3px;
}

@media (max-width: 640px) {
  /* Stack: full-width screenshot, then the text. */
  .project-row a {
    flex-direction: column;
    gap: 0.75rem;
  }

  .project-thumb {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
  }

  .project-info {
    padding-top: 0;
  }
}

/* ========================================
   Blog Page Styles
   ======================================== */

.blog-header {
  margin-bottom: 2.25rem;
}

/* Page titles share the post title style. */
.blog-header h1 {
  font-size: 2.5rem;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1.1;
  color: var(--prose-heading);
}

.blog-header h1 {
  margin-bottom: 0.75rem;
}

.blog-header p {
  font-size: 1.125rem;
  line-height: 1.6;
  color: var(--prose-text);
  margin: 0;
}

/* Blog Search */
.blog-search {
  margin-bottom: 1.5rem;
}

.blog-search-input-wrapper {
  position: relative;
}

.blog-search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  width: 16px;
  height: 16px;
}

.blog-search-input {
  width: 100%;
  padding: 0.6rem 0.75rem 0.6rem 2.25rem;
  font-family: var(--font-body);
  font-size: 0.875rem;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  outline: none;
  transition: border-color var(--transition-fast);
}

.blog-search-input::placeholder {
  color: var(--text-muted);
}

.blog-search-input:focus {
  border-color: var(--text-muted);
}

/* Tag pills container */
.blog-tag-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height var(--transition-normal), opacity var(--transition-normal), margin var(--transition-normal);
  margin-top: 0;
}

.blog-tag-pills-visible {
  max-height: 200px;
  opacity: 1;
  margin-top: 0.75rem;
}

/* Tag pill button */
.blog-tag-pill {
  cursor: pointer;
  font-family: var(--font-body);
  transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.blog-tag-pill:hover {
  border-color: var(--text-muted);
  color: var(--text-primary);
}

.tag-active {
  background-color: var(--text-primary);
  color: var(--bg-primary);
  border-color: var(--text-primary);
}

.tag-active:hover {
  background-color: var(--text-primary);
  color: var(--bg-primary);
  border-color: var(--text-primary);
}

/* Inline blog tags next to titles */
.blog-tags {
  display: inline;
  margin-left: 0.5rem;
}

.blog-inline-tag {
  padding: 0.1rem 0.4rem;
  vertical-align: middle;
}

@media (max-width: 768px) {
  .blog-tags {
    display: none;
  }
}

/* Search result count */
.blog-search-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  display: none;
}

.blog-table-wrapper {
  width: 100%;
  overflow-x: auto;
}

.blog-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.blog-table thead tr {
  border-bottom: 1px solid var(--border-color);
}

.blog-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 400;
  font-size: 0.875rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.blog-table th.col-date {
  width: 120px;
}

.blog-table th.col-readtime {
  width: 100px;
  text-align: right;
}

/* Hide read time header on mobile */
@media (max-width: 768px) {
  .blog-table th.col-readtime {
    display: none;
  }
}

.blog-row {
  border-bottom: 1px solid var(--border-color);
  transition: background-color var(--transition-fast);
}

.blog-row:last-child {
  border-bottom: none;
}

.blog-row:hover {
  background-color: var(--bg-secondary);
}

.blog-cell {
  padding: 0;
}

.blog-link {
  display: flex;
  width: 100%;
  padding: 0.75rem 1rem;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.blog-date {
  flex-shrink: 0;
  width: 120px;
  font-size: 0.8125rem;
  color: var(--meta-text);
  white-space: nowrap;
}

.blog-row:hover .blog-date {
  color: var(--text-primary);
}

.blog-title {
  flex: 1;
  min-width: 0;
  font-size: 1.125rem;
  font-weight: 500;
  color: var(--prose-heading);
  transition: color var(--transition-fast);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.blog-row:hover .blog-title {
  color: var(--prose-heading);
  white-space: normal;
  overflow: visible;
}

.blog-readtime {
  flex-shrink: 0;
  width: 100px;
  text-align: right;
  font-size: 0.8125rem;
  color: var(--meta-text);
  white-space: nowrap;
}

.blog-row:hover .blog-readtime {
  color: var(--text-primary);
}

/* Hide read time on mobile */
@media (max-width: 768px) {
  .blog-readtime {
    display: none;
  }

  .blog-header h1 {
    font-size: 2rem;
  }
}

.blog-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem;
}

/* ========================================
   Blog Post Page Styles
   ======================================== */

.blog-post {
  /* Padding gives code blocks room to bleed past the text on both sides without being clipped;
     the negative margin keeps the text itself on the page's left edge. */
  max-width: calc(var(--prose-measure) + 2 * var(--code-bleed));
  min-width: 0;
  padding-inline: var(--code-bleed);
  margin-left: calc(-1 * var(--code-bleed));
  overflow: hidden;
}

/* Everything sits in the prose measure; only code blocks extend, evenly on both sides. */
.blog-post > :not(.blog-post-content),
.blog-post .blog-post-content > * {
  max-width: var(--prose-measure);
  margin-left: 0;
  margin-right: auto;
}

.blog-post .blog-post-content > :is(pre, .code-block-wrapper) {
  max-width: none;
  margin-left: calc(-1 * var(--code-bleed));
  margin-right: calc(-1 * var(--code-bleed));
}

.blog-post-header {
  margin-bottom: 2.25rem;
}

.blog-post-header h1 {
  font-size: 2.5rem;
  font-weight: 900;
  letter-spacing: 0;
  margin-bottom: 0.5rem;
  line-height: 1.1;
  color: var(--prose-heading);
}

.blog-post-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--meta-text);
}

.blog-post-meta .separator {
  color: var(--meta-text);
}

.blog-post-updated {
  font-style: italic;
  font-size: 0.8125rem;
  color: var(--meta-text);
  margin-top: 0.25rem;
}

.blog-post-content {
  line-height: 1.75;
  color: var(--prose-text);
  /* Words longer than the column (long URLs, unbroken strings) break instead
     of overflowing the layout. */
  overflow-wrap: break-word;
}

.blog-post-content .zola-anchor {
  color: inherit;
  text-decoration: none;
}

.blog-post-content h2 {
  font-family: var(--font-body);
  font-size: 1.875rem;
  line-height: 1.2;
  margin-top: 3.5rem;
  margin-bottom: 0.875rem;
  color: var(--prose-heading);
}

/* H3 used to match body size; give sub-sections their own step in the scale. */
.blog-post-content h3 {
  font-family: var(--font-body);
  font-size: 1.375rem;
  line-height: 1.3;
  margin-top: 2.5rem;
  margin-bottom: 0.625rem;
  color: var(--prose-heading);
}

.blog-post-content h4 {
  font-family: var(--font-body);
  font-size: 1.125rem;
  margin-top: 1.75rem;
  margin-bottom: 0.5rem;
  color: var(--prose-heading);
}

.blog-post-content p {
  margin-bottom: 1.5rem;
  font-size: 1.125rem;
}

.blog-post-content strong {
  color: var(--prose-heading);
}

/* Blockquotes (mostly "> **Note:**") read like the note callout: upright, full contrast. */
.blog-post-content blockquote {
  border-left: 3px solid var(--border-color);
  background-color: var(--bg-secondary);
  border-radius: 0 6px 6px 0;
  padding: 0.875rem 1.125rem;
  margin: 1.75rem 0;
  color: var(--prose-text);
}

.blog-post-content blockquote p,
.blog-post-content .callout p {
  font-size: 1.125rem;
  margin-bottom: 0.75rem;
}

.blog-post-content blockquote p:last-child {
  margin-bottom: 0;
}

.blog-post-content ul,
.blog-post-content ol {
  margin-bottom: 1.5rem;
  padding-left: 1.5rem;
  font-size: 1.125rem;
}

.blog-post-content li {
  margin-bottom: 0.5rem;
}

.blog-post-content li::marker {
  color: var(--meta-text);
}

.post-figure {
  margin: 1.75rem 0;
}

.blog-post-content .post-figure img {
  display: block;
  margin: 0;
}

.post-figure figcaption {
  margin-top: 0.625rem;
  font-size: 0.9375rem;
  font-style: italic;
  line-height: 1.5;
  text-align: center;
  color: var(--meta-text);
}

.blog-post-content a {
  color: #6b8aaf;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.blog-post-content a:hover {
  color: #8fafc8;
}

.blog-post-content img,
.blog-post-content video {
  border-radius: 6px;
  margin: 1.5rem 0;
  max-width: 100%;
  height: auto;
}

.blog-post-content video {
  display: block;
  width: 100%;
}

/* SVGs (typically equations/diagrams) declare tiny intrinsic sizes; let them
   fill the content column via the viewBox instead of using their hardcoded width. */
.blog-post-content img[src$=".svg"] {
  width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
  border-radius: 0;
}

/* Auto-invert monochrome SVGs (equations, line diagrams) for dark mode.
   Opt out by either:
     - suffixing filename ".color.svg" (SVG already has theme-neutral colors)
     - using the {{ <svg /> }} component (theme-swappable via JS, .theme-svg class) */
[data-theme="dark"] .blog-post-content img[src$=".svg"]:not([src$=".color.svg"]):not([src$=".dark.svg"]):not(.theme-svg) {
  filter: invert(1) hue-rotate(180deg);
}

.blog-post-content pre {
  font-size: 0.9375rem;
  line-height: 1.6;
  margin: 1.75rem 0;
  border: 1px solid var(--border-color);
}

/* Inline code scales with the surrounding text; block code keeps the pre size.
   No border: posts use ~4 inline spans per 100 words, and outlined chips turn a paragraph busy. */
.blog-post-content :not(pre) > code {
  font-size: 0.85em;
  border: 0;
  padding: 0.15em 0.35em;
}

.blog-post-content pre code {
  font-size: inherit;
}

.blog-post-tags {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 3rem;
}

.blog-post-tags-icon {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.blog-post-footer {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.top-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  transition: color var(--transition-fast);
}

.top-link:hover {
  color: var(--text-primary);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  transition: color var(--transition-fast);
}

.back-link:hover {
  color: var(--text-primary);
}

@media (max-width: 768px) {
  /* Keep the title above H2 in the scale on small screens. */
  .blog-post-header h1 {
    font-size: 2rem;
  }

  .blog-post-content h2 {
    font-size: 1.5rem;
  }

  /* The bleed equals the page gutter here, so code runs edge to edge: drop the rounded sides. */
  .blog-post .blog-post-content > :is(pre, .code-block-wrapper) {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .blog-post-content img {
    max-width: 100%;
    height: auto;
  }
}

/* ========================================
   Series sentences (top: "This is part N of ...", bottom: "That was part N ...")
   ======================================== */

.series-line {
  font-style: italic;
  font-size: 1.125rem;
  line-height: 1.67;
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

.series-line-end {
  margin-top: 2.5rem;
  margin-bottom: 0;
}

.series-line a {
  color: #6b8aaf;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.series-line a:hover {
  color: #8fafc8;
}

/* ========================================
   About Page Styles
   ======================================== */

/* About reuses the blog post layout; only the photo and the link line are its own. */
.about-pic {
  display: block;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 1.5rem;
}

.about-links {
  margin-top: 0.25rem;
}

.about-links a {
  color: var(--meta-text);
  text-decoration: underline;
  text-decoration-color: var(--border-color);
  text-underline-offset: 3px;
  transition: color var(--transition-fast), text-decoration-color var(--transition-fast);
}

.about-links a:hover {
  color: var(--prose-heading);
  text-decoration-color: currentColor;
}

.blog-post-content .about-updated {
  margin-top: -0.5rem;
  font-size: 0.8125rem;
  color: var(--meta-text);
}

/* ========================================
   Blog Post Table of Contents
   ======================================== */

/* The rail is fixed to the window edge, so the article keeps the normal single-column layout. */
.blog-post-layout {
  display: block;
}

/* --- TOC Sidebar (wide screens): a rail of dashes that opens on hover --- */
.toc-sidebar {
  display: block;
}

/* Pinned to the right edge of the window at its vertical middle (Substack-style). */
.toc-sticky {
  position: fixed;
  right: 0;
  top: 50vh;
  transform: translateY(-50%);
  z-index: 20;
}

.toc-rail {
  background: none;
  border: 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.625rem;
  /* Clear of the scrollbar; the padding still counts as hover area out to the edge. */
  padding: 0.5rem 1rem 0.5rem 1.5rem;
}

.toc-dash {
  width: 18px;
  height: 2px;
  padding: 0;
  border: 0;
  border-radius: 1px;
  background-color: var(--border-color);
  transition: background-color var(--transition-fast), width var(--transition-fast);
}

.toc-dash.toc-dash-sub {
  width: 10px;
}

/* Hovering (or keyboard focus, or the panel being open) lights the rail up so it reads as clickable. */
.toc-rail:hover .toc-dash,
.toc-rail:focus-visible .toc-dash,
.toc-sticky.is-open .toc-dash {
  background-color: var(--text-muted);
}

.toc-dash.active,
.toc-rail:hover .toc-dash.active,
.toc-rail:focus-visible .toc-dash.active,
.toc-sticky.is-open .toc-dash.active {
  width: 24px;
  background-color: var(--text-primary);
}

.toc-panel {
  position: absolute;
  top: 50%;
  right: 0.5rem;
  width: 280px;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  padding: 1rem 1rem 1rem 0.5rem;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transform: translate(6px, -50%);
  transition: opacity var(--transition-fast), transform var(--transition-fast), visibility var(--transition-fast);
  z-index: 20;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

[data-theme="light"] .toc-panel {
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

/* Opened and closed by main.js (click the rail; click outside, Escape or pick a section to close). */
.toc-sticky.is-open .toc-panel {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(-50%);
}

.toc-panel::-webkit-scrollbar {
  width: 4px;
}

.toc-panel::-webkit-scrollbar-track {
  background: transparent;
}

.toc-panel::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 2px;
}

.toc-sidebar-title {
  padding-left: 0.75rem;
}

.toc-sidebar-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--meta-text);
  margin-bottom: 0.75rem;
}

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

.toc-sidebar ul ul {
  padding-left: 0.75rem;
}

/* --- TOC Inline (narrow screens, collapsed by default) --- */
.toc-inline {
  display: none;
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.75rem 1.25rem;
  margin-bottom: 2rem;
}

.toc-inline[open] {
  padding-bottom: 1rem;
}

.toc-inline-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--meta-text);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toc-inline-title::-webkit-details-marker {
  display: none;
}

.toc-inline-title::after {
  content: '>';
  font-size: 0.625rem;
  transition: transform var(--transition-fast);
}

.toc-inline[open] .toc-inline-title::after {
  transform: rotate(90deg);
}

.toc-inline ul {
  margin-top: 0.5rem;
}

.toc-inline ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-inline ul ul {
  padding-left: 0.75rem;
}

.toc-inline .toc-link {
  font-size: 0.8125rem;
}

/* --- Shared TOC link styles --- */
.toc-link {
  display: block;
  font-size: 0.9375rem;
  line-height: 1.4;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.2rem 0 0.2rem 0.625rem;
  border-left: 2px solid transparent;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.toc-link:hover {
  color: var(--text-primary);
}

.toc-link.active {
  color: var(--text-primary);
  border-left-color: var(--text-primary);
}

/* Top-level sections read brighter than sub-sections so the outline scans at a glance. */
.toc-panel .toc-link {
  color: var(--text-secondary);
}

.toc-panel .toc-link-sub {
  color: var(--text-muted);
}

.toc-panel .toc-link:hover,
.toc-panel .toc-link.active {
  color: var(--text-primary);
}

/* --- Responsive: below 1080px --- */
@media (max-width: 1080px) {
  .toc-sidebar {
    display: none;
  }

  .toc-inline {
    display: block;
  }
}

/* Phones get no contents at all (like Substack): the post just starts. Tablets keep the dropdown. */
@media (max-width: 640px) {
  .toc-inline {
    display: none;
  }
}

/* --- Tablet: account for fixed top-nav --- */
@media (min-width: 1081px) and (max-width: 1280px) {
  .toc-sticky {
    top: calc(50vh + var(--nav-height) / 2);
  }

  .toc-panel {
    max-height: calc(100vh - var(--nav-height) - 2rem);
  }
}

/* ============================================
   WebGPU Demo Embeds
   ============================================ */
.gpu-demo-wrapper {
  margin: 2rem 0;
}

.gpu-demo {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
}

.gpu-demo canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.gpu-demo-fallback {
  display: none;
  position: absolute;
  inset: 0;
  place-content: center;
  place-items: center;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  text-align: center;
  padding: 1rem;
}

.gpu-demo-caption {
  margin-top: 0.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ========================================
   External link indicator (arrow on outbound links)
   ======================================== */

/* main.js adds .external-link to links that leave the current host. */
.external-link::after {
  content: "↗";
  display: inline-block;
  font-size: 0.75em;
  margin-left: 0.15em;
  color: var(--text-muted);
  text-decoration: none;
}

/* ========================================
   Copy-to-clipboard buttons on code blocks
   ======================================== */

.blog-post-content pre {
  position: relative;
}

.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  /* Neutral semi-transparent so it reads on both gruvbox-dark and gruvbox-light backgrounds. */
  background: rgba(127, 127, 127, 0.18);
  color: currentColor;
  border: 1px solid rgba(127, 127, 127, 0.3);
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition-fast), background-color var(--transition-fast);
}

.blog-post-content pre:hover .copy-btn,
.copy-btn:focus-visible {
  opacity: 1;
}

.copy-btn:hover {
  background: rgba(127, 127, 127, 0.32);
}

.copy-btn svg {
  width: 16px;
  height: 16px;
  pointer-events: none;
}

.copy-btn .copy-btn-check {
  display: none;
}

.copy-btn.copied {
  opacity: 1;
  color: #86c98a;
}

.copy-btn.copied .copy-btn-copy {
  display: none;
}

.copy-btn.copied .copy-btn-check {
  display: block;
}

/* ========================================
   Image lightbox (click to zoom)
   ======================================== */

.blog-post-content img {
  cursor: zoom-in;
}

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: zoom-out;
  padding: 2rem;
}

.lightbox-overlay.active {
  display: flex;
}

.lightbox-img {
  max-width: 95vw;
  max-height: 95vh;
  width: auto;
  height: auto;
  border-radius: 6px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ========================================
   Footnotes (Zola w/ bottom_footnotes = true)
   ======================================== */

.footnote-reference {
  font-size: 0.75em;
  margin-left: 0.1em;
}

.footnote-reference a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 0 0.2em;
  border-radius: 3px;
  background: var(--bg-secondary);
}

.footnote-reference a:hover {
  color: var(--text-primary);
}

.blog-post-content .footnotes {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

.blog-post-content .footnotes-list {
  padding-left: 1.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.blog-post-content .footnotes-list li {
  margin-bottom: 0.5rem;
  padding-left: 0.25rem;
}

.blog-post-content .footnotes-list p {
  margin: 0 !important;
  font-size: 0.875rem !important;
  display: inline;
}

.blog-post-content .footnotes-list a {
  text-decoration: none;
  color: var(--text-muted);
  margin-left: 0.4em;
}

.blog-post-content .footnotes-list a:hover {
  color: var(--text-primary);
}

/* ========================================
   404 page
   ======================================== */

.page-404 {
  text-align: center;
  padding: 4rem 1rem;
  max-width: 480px;
  margin: 0 auto;
}

.page-404 h1 {
  font-family: var(--font-heading);
  font-size: 4rem;
  font-weight: 900;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.page-404 p {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

.page-404-links {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9375rem;
}

.page-404-links span {
  color: var(--border-color);
}

/* ========================================
   Permalink-on-heading-hover (#)
   ======================================== */

.blog-post-content h2,
.blog-post-content h3,
.blog-post-content h4 {
  position: relative;
}

.blog-post-content h2 .zola-anchor::before,
.blog-post-content h3 .zola-anchor::before,
.blog-post-content h4 .zola-anchor::before {
  content: "#";
  position: absolute;
  left: -1.4rem;
  color: var(--text-muted);
  font-weight: 400;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.blog-post-content h2:hover .zola-anchor::before,
.blog-post-content h3:hover .zola-anchor::before,
.blog-post-content h4:hover .zola-anchor::before,
.blog-post-content .zola-anchor:focus-visible::before {
  opacity: 1;
}

/* On narrow screens the anchor would overflow the column padding; suppress. */
@media (max-width: 768px) {
  .blog-post-content h2 .zola-anchor::before,
  .blog-post-content h3 .zola-anchor::before,
  .blog-post-content h4 .zola-anchor::before {
    display: none;
  }
}

/* ========================================
   Print stylesheet
   ======================================== */

@media print {
  /* Hide site chrome */
  .sidebar,
  .top-nav,
  .mobile-nav,
  .mobile-menu-overlay,
  .hamburger,
  .theme-toggle,
  .sidebar-social,
  .blog-search,
  .toc-sidebar,
  .toc-inline,
  .blog-post-tags,
  .blog-post-footer,
  .series-line,
  .copy-btn,
  .lightbox-overlay {
    display: none !important;
  }

  /* Reclaim full page width */
  .main-content,
  .content-wrapper,
  .blog-post-layout,
  .blog-post {
    margin: 0 !important;
    padding: 0 !important;
    max-width: 100% !important;
    display: block !important;
  }

  body {
    color: #000;
    background: #fff;
    font-size: 11pt;
    line-height: 1.5;
  }

  /* Headings stay tight to following content (avoid orphan headings) */
  .blog-post-content h2,
  .blog-post-content h3,
  .blog-post-content h4 {
    page-break-after: avoid;
    color: #000;
  }

  /* Don't split code blocks, figures, or images across pages */
  .blog-post-content pre,
  .blog-post-content figure,
  .blog-post-content img {
    page-break-inside: avoid;
    max-width: 100% !important;
  }

  /* Show the URL after external links so the printed copy preserves them */
  .external-link::after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
    color: #555;
    word-break: break-all;
  }

  /* Plain link styling for print */
  a {
    color: #000;
    text-decoration: underline;
  }
}
