/* ==========================================================================
   FONTS
   Self-hosted IBM Plex family. No external requests.
   Serif for body prose; Mono for all UI chrome, metadata, and headings.
   ========================================================================== */

@font-face {
  font-family: "IBM Plex Serif";
  src: url("/assets/fonts/ibm-plex-serif/IBMPlexSerif-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Serif";
  src: url("/assets/fonts/ibm-plex-serif/IBMPlexSerif-Italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Serif";
  src: url("/assets/fonts/ibm-plex-serif/IBMPlexSerif-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Serif";
  src: url("/assets/fonts/ibm-plex-serif/IBMPlexSerif-BoldItalic.woff2") format("woff2");
  font-weight: 700;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("/assets/fonts/ibm-plex-mono/IBMPlexMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("/assets/fonts/ibm-plex-mono/IBMPlexMono-Italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

/* ==========================================================================
   DESIGN TOKENS
   All site-wide values live here. Change one var to change the whole site.
   ========================================================================== */

:root {
  /* Colors */
  --bg:           #f8f7f2;
  --fg:           #111111;
  --accent:       #b91c1c;
  --border:       #111111;
  --border-muted: #ccccc4;
  --muted:        #5c5c5c;
  --code-bg:      #eeeee8;

  /* Typography */
  --font-serif: "IBM Plex Serif", ui-serif, Georgia, Cambria, serif;
  --font-mono:  "IBM Plex Mono", ui-monospace, "Cascadia Code", "Fira Code", monospace;

  /* Reading geometry -- 66ch is optimal for sustained reading (Bayle & Ripoll, 2004) */
  --measure:     66ch;
  --site-width:  1120px;

  /* Spacing scale */
  --sp-1:  0.25rem;
  --sp-2:  0.5rem;
  --sp-3:  0.75rem;
  --sp-4:  1rem;
  --sp-6:  1.5rem;
  --sp-8:  2rem;
  --sp-12: 3rem;
  --sp-16: 4rem;
  --sp-24: 6rem;

  /* Type scale (Major Third: 1.25 ratio) */
  --text-xs:   0.64rem;
  --text-sm:   0.8rem;
  --text-base: 1.0625rem;
  --text-md:   1.25rem;
  --text-lg:   1.5625rem;
  --text-xl:   1.953rem;
  --text-2xl:  2.441rem;
}

/* Dark mode via system preference */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #0d0c0a;
    --fg:           #e8e7e0;
    --accent:       #e05252;
    --border:       #e8e7e0;
    --border-muted: #2e2e2a;
    --muted:        #8a8a80;
    --code-bg:      #1c1c18;
  }
}

/* Manual override -- toggled by JS, wins over system preference */
:root[data-theme="dark"] {
  --bg:           #0d0c0a;
  --fg:           #e8e7e0;
  --accent:       #e05252;
  --border:       #e8e7e0;
  --border-muted: #2e2e2a;
  --muted:        #8a8a80;
  --code-bg:      #1c1c18;
}

:root[data-theme="light"] {
  --bg:           #f8f7f2;
  --fg:           #111111;
  --accent:       #b91c1c;
  --border:       #111111;
  --border-muted: #ccccc4;
  --muted:        #5c5c5c;
  --code-bg:      #eeeee8;
}

/* ==========================================================================
   RESET
   ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  hanging-punctuation: first last;
}

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

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

/* ==========================================================================
   BASE
   ========================================================================== */

body {
  background-color: var(--bg);
  color: var(--fg);
  font-family: var(--font-serif);
  font-size: var(--text-base);
  line-height: 1.75;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.15s ease, color 0.15s ease;
}

@media (prefers-reduced-motion: reduce) {
  body { transition: none; }
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

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

a:hover {
  text-decoration: none;
}

main {
  flex: 1;
  outline: none;
}

/* ==========================================================================
   LAYOUT UTILITIES
   ========================================================================== */

.site-container {
  width: 100%;
  max-width: var(--site-width);
  margin: 0 auto;
  padding-inline: var(--sp-8);
}

.reading-container {
  max-width: var(--measure);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   READING PROGRESS BAR
   Progressive enhancement -- only visible with JS enabled.
   ========================================================================== */

#reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  z-index: 100;
  opacity: 0;
  transition: transform 0.1s linear, opacity 0.2s ease;
}

#reading-progress.visible {
  opacity: 1;
}

/* ==========================================================================
   SITE HEADER
   ========================================================================== */

.site-header {
  border-bottom: 1px solid var(--border);
  padding-block: var(--sp-4);
  position: sticky;
  top: 0;
  background-color: var(--bg);
  z-index: 10;
}

.site-header-inner {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-8);
}

.site-name {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 400;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--fg);
  text-decoration: none;
}

.site-name:hover {
  color: var(--accent);
  text-decoration: none;
}

.site-nav {
  display: flex;
  align-items: baseline;
  gap: var(--sp-8);
  flex-wrap: wrap;
  list-style: none;
}

.site-nav a {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
}

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

.site-nav a[aria-current="page"] {
  color: var(--fg);
  border-bottom: 1px solid var(--fg);
}

.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--muted);
  padding: 0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1;
}

.theme-toggle:hover {
  color: var(--fg);
}

/* ==========================================================================
   SKIP NAVIGATION (accessibility -- keyboard users)
   ========================================================================== */

.skip-nav {
  position: absolute;
  top: -100%;
  left: var(--sp-4);
  background: var(--fg);
  color: var(--bg);
  padding: var(--sp-2) var(--sp-4);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-decoration: none;
  z-index: 200;
  letter-spacing: 0.05em;
}

.skip-nav:focus {
  top: var(--sp-4);
}

/* ==========================================================================
   SITE FOOTER
   ========================================================================== */

.site-footer {
  border-top: 1px solid var(--border-muted);
  padding-block: var(--sp-8);
  margin-top: var(--sp-24);
}

.site-footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-8);
  flex-wrap: wrap;
}

.site-footer p,
.site-footer a {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--muted);
  text-decoration: none;
}

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

.footer-feeds {
  display: flex;
  gap: var(--sp-4);
}

/* ==========================================================================
   HOME PAGE
   ========================================================================== */

.home-lede {
  padding-block: var(--sp-24);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.home-lede-pitch {
  max-width: 60ch;
  margin-bottom: var(--sp-8);
}

.home-lede-pitch p {
  font-family: var(--font-serif);
  font-size: clamp(1.1rem, 2.5vw, 1.35rem);
  line-height: 1.65;
  color: var(--fg);
}

.home-lede-pitch p + p {
  margin-top: var(--sp-6);
}

.home-lede-pitch p:last-child {
  font-weight: 700;
}

.home-lede-links {
  display: flex;
  gap: var(--sp-6);
  flex-wrap: wrap;
}

.home-lede-links a {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--accent);
  padding-bottom: 1px;
  border-bottom: 1px solid currentColor;
}

.home-lede-links a:hover {
  color: var(--fg);
  text-decoration: none;
}

/* -- Domain index section */

.home-domains {
  padding-block: var(--sp-12);
}

.section-label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--sp-8);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--border-muted);
  display: block;
}

.domain-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 0 var(--sp-8);
  padding-block: var(--sp-8);
  border-bottom: 1px solid var(--border-muted);
}

.domain-row:last-of-type {
  border-bottom: none;
}

.domain-row-info {
  grid-column: 1;
  grid-row: 1;
}

.domain-row-count {
  grid-column: 2;
  grid-row: 1;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--muted);
  white-space: nowrap;
  padding-top: 0.2rem;
  text-align: right;
}

.domain-row-posts-preview {
  grid-column: 1 / -1;
  grid-row: 2;
  margin-top: var(--sp-4);
}

.domain-row-title {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: var(--sp-2);
}

.domain-row-title a {
  color: var(--fg);
  text-decoration: none;
}

.domain-row-title a:hover {
  color: var(--accent);
}

.domain-row-desc {
  font-family: var(--font-serif);
  font-size: var(--text-sm);
  color: var(--muted);
  max-width: 58ch;
  line-height: 1.6;
}

.post-preview-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.post-preview-item {
  display: flex;
  align-items: baseline;
  gap: var(--sp-4);
}

.post-preview-item a {
  font-family: var(--font-serif);
  font-size: var(--text-sm);
  color: var(--fg);
  text-decoration: none;
  flex: 1;
}

.post-preview-item a:hover {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.post-preview-date {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ==========================================================================
   POST LIST (used on domain pages, post related section, home)
   ========================================================================== */

.post-list {
  list-style: none;
}

.post-list-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--sp-6);
  align-items: baseline;
  padding-block: var(--sp-4);
  border-bottom: 1px solid var(--border-muted);
}

.post-list-item:last-child {
  border-bottom: none;
}

.post-list-item-title {
  font-family: var(--font-serif);
  font-size: var(--text-base);
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: var(--sp-1);
}

.post-list-item-title a {
  color: var(--fg);
  text-decoration: none;
}

.post-list-item-title a:hover {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.post-list-item-excerpt {
  font-size: var(--text-sm);
  color: var(--muted);
  line-height: 1.55;
}

.post-list-item-meta {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  align-items: flex-end;
}

/* ==========================================================================
   DOMAIN PAGE
   ========================================================================== */

.domain-header {
  padding-block: var(--sp-16) var(--sp-12);
  border-bottom: 1px solid var(--border);
}

.breadcrumb {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  display: inline-block;
  margin-bottom: var(--sp-6);
}

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

.domain-title {
  font-family: var(--font-mono);
  font-size: clamp(1.1rem, 3vw, var(--text-xl));
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.2;
  margin-bottom: var(--sp-4);
}

.domain-desc {
  font-family: var(--font-serif);
  font-size: var(--text-base);
  color: var(--muted);
  max-width: 60ch;
  line-height: 1.65;
}

.domain-posts {
  padding-block: var(--sp-8);
}

/* ==========================================================================
   SINGLE POST
   ========================================================================== */

.post-header {
  padding-block: var(--sp-16) var(--sp-8);
  border-bottom: 1px solid var(--border);
  max-width: var(--measure);
}

.post-domain-link {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  display: inline-block;
  margin-bottom: var(--sp-6);
}

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

.post-title {
  font-family: var(--font-serif);
  font-size: clamp(1.5rem, 4.5vw, var(--text-2xl));
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin-bottom: var(--sp-6);
  color: var(--fg);
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-6);
  align-items: baseline;
}

.post-meta-item {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.post-meta-sep {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--border-muted);
}

/* -- Body prose */

.post-body {
  max-width: var(--measure);
  padding-block: var(--sp-12);
  font-size: var(--text-base);
  line-height: 1.8;
}

.post-body > * + * {
  margin-top: 1.4em;
}

.post-body p { }

.post-body h2 {
  font-family: var(--font-serif);
  font-size: var(--text-md);
  font-weight: 700;
  line-height: 1.25;
  margin-top: 2.5em;
  margin-bottom: 0.6em;
}

.post-body h3 {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 2.5em;
  margin-bottom: 0.8em;
}

.post-body h4 {
  font-family: var(--font-serif);
  font-size: var(--text-base);
  font-weight: 700;
  margin-top: 2em;
  margin-bottom: 0.5em;
}

.post-body blockquote {
  border-left: 3px solid var(--border);
  padding-left: var(--sp-6);
  margin-block: 2em;
  color: var(--muted);
  font-style: italic;
}

.post-body blockquote cite {
  display: block;
  font-style: normal;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--muted);
  margin-top: var(--sp-2);
  letter-spacing: 0.04em;
}

.post-body code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--code-bg);
  padding: 0.1em 0.4em;
  border-radius: 2px;
}

.post-body pre {
  background: var(--code-bg);
  border-left: 3px solid var(--border);
  padding: var(--sp-6);
  overflow-x: auto;
  margin-block: 2em;
  tab-size: 2;
}

.post-body pre code {
  background: none;
  padding: 0;
  font-size: var(--text-sm);
  line-height: 1.6;
}

.post-body ul,
.post-body ol {
  padding-left: 1.6em;
}

.post-body li + li {
  margin-top: 0.35em;
}

.post-body strong {
  font-weight: 700;
}

.post-body em {
  font-style: italic;
}

.post-body hr {
  border: none;
  border-top: 1px solid var(--border-muted);
  margin-block: var(--sp-12);
}

.post-body a {
  color: var(--accent);
}

/* Anchored headings */
.heading-anchor {
  margin-left: var(--sp-2);
  opacity: 0;
  color: var(--muted);
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 0.7em;
  font-style: normal;
  transition: opacity 0.15s ease;
}

.post-body h2:hover .heading-anchor,
.post-body h3:hover .heading-anchor,
.post-body h4:hover .heading-anchor,
.about-body h2:hover .heading-anchor,
.about-body h3:hover .heading-anchor {
  opacity: 1;
}

/* -- Related posts */

.post-related {
  max-width: var(--measure);
  margin-top: var(--sp-12);
  padding-top: var(--sp-8);
  border-top: 1px solid var(--border-muted);
}

/* -- Post footer */

.post-footer {
  border-top: 1px solid var(--border-muted);
  padding-top: var(--sp-8);
  max-width: var(--measure);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-4);
  flex-wrap: wrap;
}

.raw-link,
.post-footer a {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--muted);
  text-decoration: none;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.raw-link:hover,
.post-footer a:hover {
  color: var(--accent);
}

/* ==========================================================================
   ABOUT PAGE
   ========================================================================== */

.about-header {
  padding-block: var(--sp-16) var(--sp-12);
  border-bottom: 1px solid var(--border);
}

.about-title {
  font-family: var(--font-mono);
  font-size: clamp(1.1rem, 3vw, var(--text-xl));
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.about-body {
  max-width: var(--measure);
  padding-block: var(--sp-12);
  font-size: var(--text-base);
  line-height: 1.8;
}

.about-body > * + * {
  margin-top: 1.4em;
}

.about-body h2 {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 2.5em;
  margin-bottom: 0.8em;
}

.about-body a { color: var(--accent); }

/* ==========================================================================
   SITEMAP PAGE
   ========================================================================== */

.sitemap-body {
  padding-block: var(--sp-12);
}

.sitemap-section {
  margin-bottom: var(--sp-8);
}

.sitemap-section h2 {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--sp-4);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--border-muted);
}

.sitemap-section ul {
  list-style: none;
}

.sitemap-section li {
  padding-block: var(--sp-1);
}

.sitemap-section a {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--fg);
  text-decoration: none;
}

.sitemap-section a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 640px) {
  .site-container {
    padding-inline: var(--sp-4);
  }

  .site-header-inner {
    flex-direction: column;
    gap: var(--sp-2);
  }

  .site-nav {
    gap: var(--sp-4);
  }

  .domain-row {
    grid-template-columns: 1fr;
  }

  .domain-row-count {
    text-align: left;
    grid-row: auto;
  }

  .post-list-item {
    grid-template-columns: 1fr;
    gap: var(--sp-1);
  }

  .post-list-item-meta {
    align-items: flex-start;
    text-align: left;
  }

  .site-footer-inner {
    flex-direction: column;
    gap: var(--sp-4);
  }

  .post-footer {
    flex-direction: column;
  }
}

/* ==========================================================================
   PRINT
   ========================================================================== */

@media print {
  :root {
    --bg: #ffffff;
    --fg: #000000;
    --accent: #000000;
    --border: #000000;
    --border-muted: #cccccc;
    --muted: #555555;
    --code-bg: #f0f0f0;
  }

  .site-header,
  .site-footer,
  .post-footer,
  #reading-progress,
  .theme-toggle,
  .skip-nav {
    display: none;
  }

  .post-body a::after {
    content: " (" attr(href) ")";
    font-size: 0.75em;
    font-family: var(--font-mono);
    color: #555555;
  }

  .post-body a[href^="#"]::after {
    content: "";
  }

  .post-title {
    font-size: 1.75rem;
  }

  body {
    font-size: 11pt;
    line-height: 1.6;
  }
}
