/* =====================================================================
   build.allanninal.dev
   Clean, white, minimalist. Monochrome. No rounded corners.
   Mobile-first. Breakpoints: 640px (tablet), 1024px (desktop).
   ===================================================================== */

:root {
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;

  --bg: #ffffff;
  --bg-code: #f5f5f5;
  --text: #111111;
  --text-muted: #555555;
  --text-faint: #888888;
  --border: #e5e5e5;
  --border-strong: #111111;

  --max-prose: 68ch;
  --max-wide: 1100px;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-12: 3rem;
  --space-16: 4rem;

  color-scheme: light;
}

/* ---------- Reset ---------- */

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: clamp(1rem, 0.95rem + 0.2vw, 1.0625rem);
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img, picture, svg, video {
  display: block;
  max-width: 100%;
  height: auto;
}

a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover { text-decoration-thickness: 2px; }

a:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

/* ---------- Layout ---------- */

.container {
  width: 100%;
  max-width: var(--max-wide);
  margin: 0 auto;
  padding-inline: var(--space-4);
}

@media (min-width: 640px)  { .container { padding-inline: var(--space-6); } }
@media (min-width: 1024px) { .container { padding-inline: var(--space-8); } }

.prose {
  max-width: var(--max-prose);
  margin: 0 auto;
}

/* ---------- Header ---------- */

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  padding-block: var(--space-4);
}

.site-header__inner {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  align-items: flex-start;
}

@media (min-width: 640px) {
  .site-header__inner {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-6);
  }
}

.site-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.site-title a {
  color: var(--text);
  text-decoration: none;
}

.site-nav {
  display: flex;
  gap: var(--space-6);
  flex-wrap: wrap;
}

.site-nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9375rem;
}

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

/* ---------- Hero ---------- */

.hero {
  padding-block: var(--space-12) var(--space-8);
}

@media (min-width: 1024px) {
  .hero { padding-block: var(--space-16) var(--space-12); }
}

.hero h1 {
  font-size: clamp(1.75rem, 1.4rem + 1.6vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0 0 var(--space-4);
  max-width: 24ch;
}

.hero p {
  font-size: clamp(1.0625rem, 1rem + 0.4vw, 1.1875rem);
  color: var(--text-muted);
  max-width: 56ch;
  margin: 0;
}

/* ---------- Sections ---------- */

.section {
  padding-block: var(--space-8);
  border-top: 1px solid var(--border);
}

@media (min-width: 1024px) { .section { padding-block: var(--space-12); } }

.section__label {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-faint);
  margin: 0 0 var(--space-6);
}

/* ---------- Post list ---------- */

.post-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: var(--space-8);
}

.post-list__item {
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--space-8);
}

.post-list__item:last-child { border-bottom: none; padding-bottom: 0; }

.post-list__title {
  font-size: clamp(1.25rem, 1.1rem + 0.6vw, 1.5rem);
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0 0 var(--space-2);
  line-height: 1.3;
}

.post-list__title a {
  color: var(--text);
  text-decoration: none;
}

.post-list__title a:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }

.post-list__meta {
  font-size: 0.875rem;
  color: var(--text-faint);
  margin: 0 0 var(--space-2);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.post-list__excerpt {
  color: var(--text-muted);
  margin: 0;
  font-size: 0.9375rem;
}

/* ---------- Article ---------- */

.article-header {
  padding-block: var(--space-12) var(--space-6);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-8);
}

@media (min-width: 1024px) {
  .article-header { padding-block: var(--space-16) var(--space-8); }
}

.article-header__meta {
  font-size: 0.875rem;
  color: var(--text-faint);
  margin: 0 0 var(--space-4);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.article-header h1 {
  font-size: clamp(1.875rem, 1.4rem + 2vw, 2.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0 0 var(--space-4);
}

.article-header__lede {
  font-size: clamp(1.0625rem, 1rem + 0.4vw, 1.1875rem);
  color: var(--text-muted);
  margin: 0;
  max-width: 60ch;
}

article h2 {
  font-size: clamp(1.375rem, 1.2rem + 0.8vw, 1.625rem);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.25;
  margin: var(--space-12) 0 var(--space-4);
}

article h3 {
  font-size: clamp(1.125rem, 1.05rem + 0.4vw, 1.25rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: var(--space-8) 0 var(--space-3);
}

article p { margin: 0 0 var(--space-4); }

article ul, article ol {
  margin: 0 0 var(--space-4);
  padding-left: 1.5rem;
}

article li { margin-bottom: var(--space-2); }

article li > ul, article li > ol { margin-top: var(--space-2); }

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

article blockquote {
  margin: var(--space-6) 0;
  padding-left: var(--space-4);
  border-left: 1px solid var(--text);
  color: var(--text-muted);
  font-style: italic;
}

article hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--space-12) 0;
}

/* ---------- Diagrams (inline SVG figures) ---------- */

figure {
  margin: var(--space-12) 0;
}

.diagram-wrap {
  /* On narrow screens allow horizontal scroll so SVG labels don't shrink past readability */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding-block: var(--space-4);
}

.diagram {
  display: block;
  width: 100%;
  height: auto;
  /* Below this width, SVG keeps native size and the wrap scrolls */
  min-width: 560px;
  margin: 0 auto;
}

@media (min-width: 640px) {
  .diagram { min-width: 0; }
  .diagram-wrap { overflow-x: visible; padding-block: var(--space-6); }
}

/* Wide variant for dense technical diagrams — break out of prose column */
.diagram--wide {
  display: block;
  margin: 0 auto;
  max-width: 1280px;
  width: 100%;
  height: auto;
  /* Below this width on the wrap, horizontal scroll engages */
  min-width: 1080px;
}

.diagram-wrap--wide {
  /* Full-bleed: pull out of the prose column to use the full viewport width */
  width: 100vw;
  position: relative;
  left: 50%;
  margin-left: -50vw;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-inline: var(--space-6);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

/* Prevent the full-bleed wrap from creating a body horizontal scrollbar */
html, body { overflow-x: clip; }

figcaption {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: var(--space-3);
  font-style: italic;
}

/* ---------- Code ---------- */

code, kbd, samp, pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

:not(pre) > code {
  background: var(--bg-code);
  padding: 0.15em 0.4em;
  font-size: 0.875em;
}

pre {
  background: var(--bg-code);
  padding: var(--space-4);
  overflow-x: auto;
  margin: 0 0 var(--space-4);
  line-height: 1.5;
}

pre code {
  background: transparent;
  padding: 0;
  font-size: 0.875rem;
}

/* ---------- Callout (minimal: hairline left border, no fill) ---------- */

.callout {
  border-left: 1px solid var(--text);
  padding: var(--space-2) 0 var(--space-2) var(--space-6);
  margin: var(--space-8) 0;
}

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

.callout__label {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 var(--space-2);
}

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  padding-block: var(--space-8);
  margin-top: var(--space-16);
  color: var(--text-muted);
  font-size: 0.875rem;
}

.site-footer__inner {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

@media (min-width: 640px) {
  .site-footer__inner {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
}

.site-footer a { color: var(--text-muted); }
.site-footer a:hover { color: var(--text); }

/* ---------- Utilities ---------- */

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--text);
  color: var(--bg);
  padding: var(--space-2) var(--space-4);
  text-decoration: none;
  z-index: 100;
}

.skip-link:focus {
  left: var(--space-4);
  top: var(--space-4);
}

.back-link {
  display: inline-block;
  margin-top: var(--space-12);
  font-size: 0.9375rem;
  color: var(--text-muted);
  text-decoration: none;
}

.back-link:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.back-link::before { content: "\2190 \00a0"; }

/* ---------- Series TOC (list of other posts in the series) ---------- */

.series-toc {
  margin-top: var(--space-12);
  padding-top: var(--space-8);
  border-top: 1px solid var(--border);
}

.series-toc__heading {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-faint);
  margin: 0 0 var(--space-4);
  font-weight: 700;
}

.series-toc__list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: var(--space-3);
}

.series-toc__item {
  display: grid;
  grid-template-columns: 5rem 1fr;
  gap: var(--space-3);
  align-items: baseline;
  font-size: 0.9375rem;
  line-height: 1.4;
}

.series-toc__part {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  font-weight: 700;
}

.series-toc__title a {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.series-toc__title a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.series-toc__item--current .series-toc__title {
  color: var(--text-muted);
  font-weight: 600;
}

.series-toc__here {
  display: inline-block;
  margin-left: var(--space-2);
  font-size: 0.8125rem;
  font-style: italic;
  font-weight: 400;
  color: var(--text-faint);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Print stylesheet ---------- */

@media print {
  :root {
    --bg: #ffffff;
    --text: #000000;
    --text-muted: #333333;
    --text-faint: #666666;
    --border: #cccccc;
  }

  html, body {
    background: #ffffff;
    color: #000000;
    font-size: 11pt;
    line-height: 1.5;
  }

  /* Hide site chrome that doesn't belong on paper */
  .site-header,
  .site-footer,
  .skip-link,
  .back-link,
  .site-nav {
    display: none !important;
  }

  /* Remove containers' max-width — let content flow */
  .container,
  .prose {
    max-width: 100%;
    padding: 0;
    margin: 0;
  }

  /* Tighten article header */
  .article-header {
    padding-block: 0 var(--space-4);
    margin-bottom: var(--space-6);
  }

  /* Diagrams: always visible at full size, no scroll needed on paper */
  .diagram-wrap {
    overflow: visible !important;
    border: none;
    padding: 0;
    page-break-inside: avoid;
  }

  .diagram {
    min-width: 0 !important;
    max-width: 100%;
    page-break-inside: avoid;
  }

  figure {
    page-break-inside: avoid;
    margin-block: var(--space-6);
  }

  /* Avoid awkward heading orphans */
  h1, h2, h3 {
    page-break-after: avoid;
    page-break-inside: avoid;
  }

  /* Show URLs after links */
  article a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 9pt;
    color: #666666;
  }

  /* Series TOC: keep, but flatten styling */
  .series-toc {
    page-break-before: always;
    border-top: 1pt solid #cccccc;
  }

  .callout {
    border-left: 1pt solid #000000;
    page-break-inside: avoid;
  }

  pre {
    border: 1pt solid #cccccc;
    page-break-inside: avoid;
    white-space: pre-wrap;
    word-wrap: break-word;
  }
}
