:root {
  color-scheme: light dark;
  --font-serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-sans: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --font-display: "UnifrakturMaguntia", "Playfair Display", Georgia, serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --radius: 2px;
  --max-width: 72rem;
  --measure: min(70ch, 100%);
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-8: 3rem;
}

html[data-theme="light"] {
  --bg: #f7f3ea;
  --bg-elevated: #fffdf8;
  --text: #1a1a1a;
  --text-muted: #3d3d3d;
  --border: #2a2a2a;
  --border-soft: #c9c0b0;
  --link: #1e3a5f;
  --link-hover: #0f172a;
  --accent: #8b1538;
  --accent-soft: #f3e8ec;
  --focus: #1e3a5f;
  --tag-bg: #ebe4d6;
  --tag-text: #1a1a1a;
  --status-bg: #e8f0e8;
  --status-text: #1a3d1a;
  --rule: #2a2a2a;
  --paper-texture: linear-gradient(180deg, #faf6ee 0%, #f7f3ea 40%, #f5f0e6 100%);
}

html[data-theme="dark"] {
  --bg: #2a2620;
  --bg-elevated: #342f28;
  --text: #f5ecd8;
  --text-muted: #d4c9b0;
  --border: #d4c9b0;
  --border-soft: #5c5548;
  --link: #c9e4ff;
  --link-hover: #f5ecd8;
  --accent: #e8a0b0;
  --accent-soft: #4a3038;
  --focus: #f5d08a;
  --tag-bg: #3f3a32;
  --tag-text: #f5ecd8;
  --status-bg: #2d4030;
  --status-text: #dcefdc;
  --rule: #d4c9b0;
  --paper-texture: linear-gradient(180deg, #2f2b24 0%, #2a2620 50%, #252119 100%);
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-serif);
  font-size: 1.125rem;
  line-height: 1.65;
  color: var(--text);
  background: var(--paper-texture);
  display: flex;
  flex-direction: column;
}

a {
  color: var(--link);
  text-decoration-thickness: 0.06em;
  text-underline-offset: 0.18em;
}

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

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

.kicker,
.kicker-link,
.post-card__meta,
.pm-article__meta dt,
.masthead__dateline,
.section-teaser .kicker {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.skip-link:focus {
  left: var(--space-4);
  top: var(--space-4);
  width: auto;
  height: auto;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-elevated);
  border: 2px solid var(--focus);
  z-index: 1000;
  font-family: var(--font-sans);
}

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

.rule {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 0;
}

.rule--double {
  border-top-width: 3px;
  border-bottom: 1px solid var(--rule);
  height: 5px;
  background: transparent;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  border-bottom: 1px solid var(--border-soft);
}

.site-header__inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) var(--space-3);
}

.masthead__dateline {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
  color: var(--text-muted);
  text-align: center;
}

.masthead__dateline-sep {
  opacity: 0.5;
}

.masthead__title-wrap {
  margin: var(--space-3) 0;
  text-align: center;
}

.masthead__title {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 7vw, 3.75rem);
  font-weight: 400;
  line-height: 1;
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.02em;
}

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

.site-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding-top: var(--space-3);
  font-family: var(--font-sans);
}

.site-nav__menu-toggle {
  display: none;
  min-height: 44px;
  min-width: 44px;
  border: 1px solid var(--border-soft);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 1.1rem;
}

.site-nav__links {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
}

.site-nav__links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: var(--space-2) var(--space-1);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.site-nav__links a:hover,
.site-nav__links a[aria-current="page"] {
  color: var(--accent);
  text-decoration: underline;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  border: 1px solid var(--border-soft);
  background: var(--bg-elevated);
  color: var(--text);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  font: inherit;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.theme-toggle:focus-visible,
.site-nav__menu-toggle:focus-visible,
a:focus-visible,
button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.site-main {
  flex: 1;
  width: min(100%, var(--max-width));
  margin: 0 auto;
  padding: var(--space-6) var(--space-4) var(--space-8);
}

.site-footer {
  border-top: 3px double var(--rule);
  padding: var(--space-5) var(--space-4);
  color: var(--text-muted);
  text-align: center;
  font-size: 0.95rem;
  font-family: var(--font-sans);
}

.site-footer__meta {
  font-size: 0.82rem;
  margin-top: var(--space-2);
}

.front-mast {
  max-width: var(--measure);
  margin: 0 auto var(--space-6);
  text-align: center;
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--border-soft);
}

.front-mast__headline {
  font-family: var(--font-serif);
  font-size: clamp(1.75rem, 4vw, 2.35rem);
  font-weight: 700;
  line-height: 1.2;
  margin: var(--space-2) 0;
}

.front-mast__deck {
  margin: 0;
  color: var(--text-muted);
  font-size: 1.125rem;
  line-height: 1.65;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border-soft);
}

.section-heading__title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 700;
}

.section-heading__title--solo {
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border-soft);
}

.text-link {
  font-weight: 600;
  white-space: nowrap;
}

.lead-story,
.front-columns,
.front-sections {
  margin-bottom: var(--space-8);
}

.front-columns__grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-5);
  column-rule: 1px solid var(--border-soft);
}

.front-columns__grid .post-card {
  break-inside: avoid;
  padding: 0 var(--space-3);
  border: none;
  background: transparent;
  box-shadow: none;
}

.front-columns__grid .post-card + .post-card {
  border-left: 1px solid var(--border-soft);
}

.front-sections__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.section-teaser {
  display: block;
  padding: var(--space-4);
  border: 1px solid var(--border-soft);
  background: var(--bg-elevated);
  text-decoration: none;
  color: inherit;
  min-height: 44px;
}

.section-teaser:hover {
  border-color: var(--accent);
}

.section-teaser__title {
  display: block;
  font-family: var(--font-serif);
  font-size: 1.2rem;
  font-weight: 700;
  margin: var(--space-2) 0;
  color: var(--text);
}

.section-teaser__desc {
  display: block;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.55;
}

.post-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-5);
}

.post-grid--compact {
  grid-template-columns: 1fr;
}

.post-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.post-card--featured {
  border: 1px solid var(--border);
  border-top: 4px solid var(--accent);
  padding: var(--space-5) var(--space-5) var(--space-6);
  max-width: var(--measure);
  margin: 0 auto;
}

.post-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  color: var(--text-muted);
}

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

.post-card__title {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 700;
  line-height: 1.25;
}

.post-card--featured .post-card__title {
  font-size: clamp(1.35rem, 3vw, 1.85rem);
}

.post-card:not(.post-card--featured) .post-card__title {
  font-size: 1.15rem;
}

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

.post-card__title a:hover {
  color: var(--link);
  text-decoration: underline;
}

.post-card__project,
.post-card__summary,
.post-card__status {
  margin: 0;
  font-size: 1.05rem;
}

.post-card__summary {
  color: var(--text-muted);
}

.tag-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.tag {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--tag-text);
  padding: 0.2rem 0.55rem;
  font-family: var(--font-sans);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid var(--border-soft);
}

.status-pill {
  display: inline-block;
  background: var(--status-bg);
  color: var(--status-text);
  padding: 0.2rem 0.55rem;
  font-family: var(--font-sans);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid var(--border-soft);
}

.content-page,
.pm-article {
  max-width: var(--measure);
  margin: 0 auto;
}

.content-page__header h1 {
  font-family: var(--font-serif);
  font-size: clamp(1.6rem, 4vw, 2.1rem);
  font-weight: 700;
  line-height: 1.2;
}

.content-page__subtitle,
.pm-article__summary {
  color: var(--text-muted);
  font-size: 1.125rem;
}

.breadcrumb {
  color: var(--text-muted);
  font-size: 0.95rem;
  font-family: var(--font-sans);
}

.pm-article__id {
  color: var(--accent);
  font-family: var(--font-sans);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 0 var(--space-2);
}

.pm-article__meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-3);
  margin: var(--space-4) 0;
  padding: var(--space-3) 0;
  border-top: 1px solid var(--border-soft);
  border-bottom: 1px solid var(--border-soft);
}

.pm-article__meta dd {
  margin: 0;
  font-weight: 600;
}

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

.project-index__item a {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4);
  min-height: 44px;
  border: 1px solid var(--border-soft);
  background: var(--bg-elevated);
  text-decoration: none;
  color: inherit;
  font-family: var(--font-sans);
}

.project-index__item a:hover {
  border-color: var(--accent);
}

.project-index__name {
  font-weight: 700;
  font-family: var(--font-serif);
  font-size: 1.1rem;
}

.project-index__count {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.archive-year-block h2 {
  font-family: var(--font-serif);
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: var(--space-2);
}

.archive-month-list {
  list-style: none;
  padding: 0;
  margin: var(--space-3) 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.archive-month-list a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-soft);
  background: var(--bg-elevated);
  text-decoration: none;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
}

.empty-state {
  color: var(--text-muted);
  font-style: italic;
}

.prose {
  font-size: 1.125rem;
  line-height: 1.65;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  font-family: var(--font-serif);
  font-weight: 700;
  scroll-margin-top: 6rem;
}

.prose h2 {
  font-size: 1.45rem;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: var(--space-2);
  margin-top: var(--space-6);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
  margin: var(--space-4) 0;
  font-size: 0.95rem;
}

.prose th,
.prose td {
  border: 1px solid var(--border-soft);
  padding: var(--space-2) var(--space-3);
  text-align: left;
}

.prose th {
  background: var(--bg-elevated);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.prose pre {
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  padding: var(--space-3);
  overflow-x: auto;
  font-size: 0.9rem;
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

.prose blockquote {
  margin: var(--space-4) 0;
  padding: var(--space-3) var(--space-4);
  border-left: 4px solid var(--accent);
  background: color-mix(in srgb, var(--accent-soft) 40%, transparent);
  color: var(--text);
  font-style: italic;
}

.prose .mermaid {
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  padding: var(--space-4);
  overflow-x: auto;
}

@media (max-width: 900px) {
  .front-columns__grid {
    grid-template-columns: 1fr;
    column-rule: none;
  }

  .front-columns__grid .post-card + .post-card {
    border-left: none;
    border-top: 1px solid var(--border-soft);
    padding-top: var(--space-5);
  }

  .front-columns__grid .post-card {
    padding: var(--space-3) 0;
  }

  .front-sections__grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .site-nav__menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .site-nav {
    justify-content: space-between;
    width: 100%;
  }

  .site-nav__links {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .site-nav__links.is-open {
    display: flex;
  }

  .site-nav__links a,
  .theme-toggle {
    width: 100%;
    justify-content: center;
  }

  .masthead__dateline {
    font-size: 0.65rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
