/* ──────────────────────────────────────────────────────────────────────────
   codeministry / blog
   Editorial typography on the parchment-and-walnut palette derived from
   the librarian banner artwork.
   ────────────────────────────────────────────────────────────────────────── */

:root {
  --bg:           #F4ECDD;
  --bg-deep:      #EBE0CC;
  --surface:      #FBF5E7;
  --surface-2:   rgba(251, 245, 231, 0.78);
  --ink:          #1B1714;
  --ink-soft:     #3A3128;
  --ink-muted:    #6B5E4F;
  --rule:         #D9CDB5;
  --rule-soft:    #E5DCC8;
  --accent:       #B8893A;
  --accent-deep:  #8A6325;
  --accent-glow:  rgba(184, 137, 58, 0.18);
  --shadow:       0 1px 1px rgba(27, 23, 20, 0.05), 0 12px 30px -16px rgba(27, 23, 20, 0.25);
  --shadow-soft:  0 8px 30px -20px rgba(27, 23, 20, 0.5);
  --grain:        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' seed='4'/><feColorMatrix values='0 0 0 0 0.42 0 0 0 0 0.31 0 0 0 0 0.18 0 0 0 0.32 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.55'/></svg>");

  --serif:  "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, "Hoefler Text", Garamond, "Times New Roman", serif;
  --sans:   system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono:   ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --measure:        36rem;
  --container:      min(72rem, 92vw);
  --nav-h:          3.5rem;

  --ease: cubic-bezier(0.32, 0.72, 0.18, 1);
}

[data-theme="dark"] {
  --bg:           #1A1612;
  --bg-deep:      #120F0C;
  --surface:      #231D17;
  --surface-2:   rgba(35, 29, 23, 0.78);
  --ink:          #EFE3CC;
  --ink-soft:     #D7C9AE;
  --ink-muted:    #A89478;
  --rule:         #3A2F25;
  --rule-soft:    #2C241C;
  --accent:       #D8AE5C;
  --accent-deep:  #F0C870;
  --accent-glow:  rgba(216, 174, 92, 0.22);
  --shadow:       0 1px 1px rgba(0, 0, 0, 0.35), 0 18px 40px -20px rgba(0, 0, 0, 0.7);
  --shadow-soft:  0 8px 40px -22px rgba(0, 0, 0, 0.8);
  --grain:        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' seed='4'/><feColorMatrix values='0 0 0 0 0.85 0 0 0 0 0.7 0 0 0 0 0.42 0 0 0 0.06 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.7'/></svg>");
}

/* ─── Reset & base ─────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  background-image: var(--grain);
  background-size: 240px 240px;
  background-attachment: fixed;
  font-feature-settings: "kern", "liga", "calt";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  transition: background-color 280ms var(--ease), color 280ms var(--ease);
}

::selection { background: var(--accent); color: var(--bg); }
img { max-width: 100%; height: auto; display: block; }

a {
  color: inherit;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color 160ms var(--ease), text-decoration-color 160ms var(--ease);
}
a:hover, a:focus-visible {
  color: var(--accent-deep);
  text-decoration-color: currentColor;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.005em;
  margin: 0;
}

p { margin: 0 0 1.05em; }
code, pre, kbd, samp { font-family: var(--mono); }

.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--ink); color: var(--bg);
  padding: 0.5rem 0.85rem;
  z-index: 100;
}
.skip:focus { left: 0.5rem; top: 0.5rem; }

/* ─── Nav (same shape as the librarian) ────────────────────────────────── */

.site-nav {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 1.25rem;
  padding: 0.65rem clamp(1rem, 3vw, 2rem);
  min-height: var(--nav-h);
  background: var(--surface-2);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--rule-soft);
}
.brand {
  display: inline-flex; align-items: baseline; gap: 0.55rem;
  text-decoration: none;
  font-family: var(--serif);
  font-size: 1.08rem;
  color: var(--ink);
}
.brand-mark { color: var(--accent); font-size: 1.35rem; line-height: 1; transform: translateY(2px); }
.brand:hover .brand-mark { color: var(--accent-deep); }
.site-nav nav { display: flex; gap: 1.15rem; margin-left: auto; flex-wrap: wrap; }
.site-nav nav a {
  font-size: 0.9rem; text-decoration: none;
  color: var(--ink-soft); padding: 0.25rem 0; position: relative;
  transition: color 160ms var(--ease);
}
.site-nav nav a::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -3px;
  height: 1px; background: var(--accent);
  transform: scaleX(0); transform-origin: left;
  transition: transform 220ms var(--ease);
}
.site-nav nav a:hover, .site-nav nav a:focus-visible { color: var(--ink); }
.site-nav nav a:hover::after, .site-nav nav a:focus-visible::after { transform: scaleX(1); }

#theme-toggle {
  appearance: none; background: transparent;
  border: 1px solid var(--rule); color: var(--ink-soft);
  width: 2.25rem; height: 2.25rem;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; border-radius: 2px;
  transition: color 160ms var(--ease), border-color 160ms var(--ease), background-color 160ms var(--ease);
}
#theme-toggle:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-glow); }
#theme-toggle .icon-moon { display: none; }
[data-theme="dark"] #theme-toggle .icon-sun { display: none; }
[data-theme="dark"] #theme-toggle .icon-moon { display: inline-block; }

/* ─── Article ─────────────────────────────────────────────────────────── */

main {
  width: var(--container);
  margin: 0 auto;
  padding: 0 0 4rem;
}

article {
  position: relative;
}

.post-banner {
  margin: 0 calc(-1 * ((100vw - var(--container)) / 2));
  margin-top: 0;
  width: 100vw;
  max-width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
  aspect-ratio: 16 / 7;
  overflow: hidden;
  border-bottom: 1px solid var(--rule);
}
.post-banner img {
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: center 30%;
}

.post-head {
  max-width: var(--measure);
  margin: clamp(2.25rem, 6vw, 4rem) auto clamp(1.5rem, 3vw, 2.25rem);
  text-align: center;
  position: relative;
}
.post-folio {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 1.4rem;
}
.post-folio .folio-num { color: var(--accent); }

.post-head h1 {
  font-size: clamp(1.85rem, 5vw, 3.4rem);
  line-height: 1.08;
  letter-spacing: -0.015em;
  margin: 0 0 1.25rem;
  overflow-wrap: break-word;
  hyphens: auto;
}
.post-head h1::after {
  content: ""; display: block;
  width: 3rem; height: 1px;
  background: var(--accent);
  margin: 1.2rem auto 0;
}

.post-meta {
  font-family: var(--sans);
  font-size: 0.82rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0;
  display: inline-flex; gap: 0.7rem; align-items: baseline;
}

/* ─── Prose ───────────────────────────────────────────────────────────── */

.prose {
  max-width: var(--measure);
  margin: 0 auto;
  font-family: var(--serif);
  font-size: 1.18rem;
  line-height: 1.68;
  color: var(--ink-soft);
}
[data-theme="dark"] .prose { color: var(--ink); }

.prose > p:first-of-type::first-letter {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 4.2em;
  line-height: 0.86;
  float: left;
  margin: 0.05em 0.14em 0 0;
  color: var(--accent-deep);
  padding: 0.05em 0.05em 0 0;
}

.prose h2 {
  font-size: 1.7rem;
  margin: 2.8rem 0 1rem;
  line-height: 1.2;
  color: var(--ink);
}
.prose h2::after {
  content: ""; display: block; width: 1.75rem; height: 1px;
  background: var(--accent);
  margin-top: 0.55rem;
}
.prose h3 {
  font-size: 1.3rem;
  margin: 2.2rem 0 0.7rem;
  line-height: 1.25;
  color: var(--ink);
}

.prose a {
  color: var(--ink);
  text-decoration-color: var(--accent);
}
.prose a:hover { color: var(--accent-deep); }

.prose strong { color: var(--ink); font-weight: 600; }
.prose em { font-style: italic; }

.prose ul, .prose ol {
  padding-left: 1.4rem;
  margin: 0 0 1.2em;
}
.prose li { margin-bottom: 0.35em; }
.prose ul li::marker { color: var(--accent); }
.prose ol li::marker { color: var(--accent); font-family: var(--mono); font-size: 0.9em; }

.prose blockquote {
  margin: 1.8rem 0;
  padding: 0.6rem 0 0.6rem 1.4rem;
  border-left: 2px solid var(--accent);
  font-style: italic;
  color: var(--ink);
}
.prose blockquote p:last-child { margin-bottom: 0; }

.prose hr {
  border: none;
  text-align: center;
  margin: 2.5rem 0;
  position: relative;
}
.prose hr::before {
  content: "§";
  color: var(--accent);
  font-family: var(--serif);
  font-size: 1.2rem;
}

.prose code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  padding: 0.08em 0.38em;
  border-radius: 2px;
  color: var(--ink);
}

.prose pre {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-left: 2px solid var(--accent);
  border-radius: 3px;
  padding: 1rem 1.2rem;
  overflow-x: auto;
  font-size: 0.86rem;
  line-height: 1.65;
  box-shadow: var(--shadow-soft);
  margin: 1.4rem 0;
  font-family: var(--mono);
}
.prose pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
  color: var(--ink);
}

.prose img {
  margin: 1.8rem auto;
  border-radius: 3px;
  border: 1px solid var(--rule);
  box-shadow: var(--shadow);
}

.prose figure {
  margin: 1.8rem 0;
}
.prose figcaption {
  font-family: var(--sans);
  font-size: 0.85rem;
  text-align: center;
  color: var(--ink-muted);
  margin-top: 0.55rem;
  font-style: italic;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.8rem 0;
  font-family: var(--sans);
  font-size: 0.95rem;
}
.prose th, .prose td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--rule);
}
.prose th {
  font-family: var(--serif);
  color: var(--ink);
  border-bottom: 2px solid var(--accent);
}

.post-end {
  text-align: center;
  margin: 3rem auto 0;
  color: var(--accent);
  font-size: 1.5rem;
}

/* ─── More posts (the index) ──────────────────────────────────────────── */

.more {
  max-width: var(--container);
  margin: clamp(3.5rem, 8vw, 6rem) auto 0;
  padding-top: clamp(2rem, 4vw, 3rem);
  border-top: 1px solid var(--rule);
}
.more h2 {
  font-size: 1.4rem;
  margin: 0 0 1.8rem;
  font-family: var(--serif);
  color: var(--ink);
}
.more h2::after {
  content: ""; display: block; width: 2.5rem; height: 1px;
  background: var(--accent);
  margin-top: 0.5rem;
}

.post-index {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(20rem, 100%), 1fr));
  gap: 1.1rem;
}

.post-card {
  position: relative;
}
.post-card a {
  display: block;
  text-decoration: none;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-top: 2px solid var(--accent);
  border-radius: 2px;
  padding: 1.3rem 1.3rem 1.2rem;
  height: 100%;
  transition: transform 220ms var(--ease), box-shadow 220ms var(--ease), border-color 220ms var(--ease);
}
.post-card a:hover,
.post-card a:focus-visible {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--rule);
  border-top-color: var(--accent-deep);
}

.post-card time {
  display: block;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  color: var(--ink-muted);
  margin-bottom: 0.55rem;
}
.post-card h3 {
  font-family: var(--serif);
  font-size: 1.18rem;
  line-height: 1.22;
  margin: 0 0 0.55rem;
  letter-spacing: -0.005em;
}
.post-card p {
  font-family: var(--sans);
  font-size: 0.92rem;
  color: var(--ink-soft);
  line-height: 1.55;
  margin: 0 0 0.85rem;
}
.post-card-meta {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  color: var(--ink-muted);
  text-transform: uppercase;
}

.post-card.is-current a {
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  cursor: default;
  pointer-events: none;
}
.post-card.is-current a:hover { transform: none; box-shadow: none; }
.post-card.is-current .post-card-meta { color: var(--accent-deep); }

/* ─── Footer ──────────────────────────────────────────────────────────── */

footer {
  width: var(--container);
  margin: clamp(3.5rem, 8vw, 6rem) auto 3rem;
  text-align: center;
  font-size: 0.88rem;
  color: var(--ink-muted);
}
.foot-rule {
  width: 6rem;
  height: 1px;
  background: var(--accent);
  margin: 0 auto 1.5rem;
  position: relative;
}
.foot-rule::before, .foot-rule::after {
  content: "✦";
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  font-size: 0.7rem;
}
.foot-rule::before { left: -1.2rem; }
.foot-rule::after  { right: -1.2rem; }
footer p { margin: 0; }
footer a { color: var(--ink-soft); }

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

@media (max-width: 44rem) {
  .site-nav { gap: 0.5rem; padding: 0.55rem 0.85rem; }
  .site-nav nav { gap: 0.75rem; font-size: 0.82rem; }
  .site-nav nav a { font-size: 0.82rem; }
  .brand-name { display: none; }

  .post-banner { aspect-ratio: 16 / 10; }

  .prose {
    font-size: 1.08rem;
    line-height: 1.62;
  }
  .prose > p:first-of-type::first-letter { font-size: 3.5em; }
  .prose h2 { font-size: 1.45rem; }
  .prose h3 { font-size: 1.18rem; }
}

/* ─── Reduced motion ──────────────────────────────────────────────────── */

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