:root {
  /* Slate accent — kept as specified */
  --accent: #5c7a9e;         /* spec token */
  --accent-bg: oklch(92% 0.01 235);        /* light hover surface */
  --accent-visited: #3d5a75;
  --text: #1f1f1f;
  --bg: #ffffff;
  --muted: #666;
  --border: #e0e0e0;
  --code-bg: #f6f6f6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #7da3c9;         /* 6.58:1 on #141414 */
    --accent-bg: oklch(22% 0.02 235);      /* dark hover surface */
    --accent-visited: #6b93b8;
    --text: #d8d8d8;
    --bg: #141414;
    --muted: #888;
    --border: #2e2e2e;
    --code-bg: #1e1e1e;
  }
}

html {
  color-scheme: light dark;
  scrollbar-gutter: stable;
}

body {
  font-family: Georgia, Charter, "Bitstream Charter", serif;
  font-size: 1.1rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  max-width: 68ch;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

/* Screen-reader-only utility */
.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;
}

/* Skip link (a11y) */
.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  padding: 0.5rem 1rem;
  background: var(--bg);
  color: var(--accent);
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.85rem;
  border: 1px solid var(--accent);
  z-index: 100;
  text-decoration: none;
}
.skip-link:focus {
  top: 0;
}

/* Focus styles */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}
nav a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.post-item h2 a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Navigation */
header {
  margin-bottom: 3.5rem;
}
nav {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.875rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 0.4rem;
}
nav a {
  color: var(--text);
  text-decoration: none;
  padding: 0.5rem 0;
}
nav a:hover { color: var(--accent); }
nav a:visited { opacity: 1; color: var(--text); }
nav a[aria-current="page"] {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}
nav .sep {
  color: var(--border);
  user-select: none;
}

/* Links */
a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }
a:visited { color: var(--accent-visited); }

/* Headings */
h1, h2, h3, h4 {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-weight: 600;
  line-height: 1.3;
  margin-top: 0;
}
* + h1, * + h2, * + h3, * + h4 { margin-top: 2rem; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }

/* Site tagline — the homepage's typographic peak. Without a visible h1 the
   landing page had no element above 1rem, so it read as uniformly flat. */
.site-tagline {
  font-size: 1.75rem;
  line-height: 1.25;
  margin: 0 0 1.25rem;
  max-width: 20ch;
}

/* Lead and meta */
.lead {
  color: var(--text);
  font-size: 1.15rem;
  margin: 0 0 0.75rem;
  max-width: 58ch;
}
.byline {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 3rem;
}

/* Post list — unified mono heading + hover tint */
.post-list {
  display: flex;
  flex-direction: column;
}

/* Negative margin + matching padding so the hover tint has horizontal
   breathing room while the text stays aligned to the prose column. */
.post-item {
  padding: 1.25rem 0.85rem;
  margin: 0 -0.85rem;
  border-top: 1px solid var(--border);
  background: transparent;
  transition: background 160ms ease;
}
.post-item:hover {
  background: var(--accent-bg);
}
.post-item:last-child {
  border-bottom: 1px solid var(--border);
}

.post-item h2 {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1.35;
  margin: 0 0 0.3rem;
}
.post-item h2 a {
  color: var(--text);
}
.post-item h2 a:hover {
  color: var(--accent);
  text-decoration: none;
}
.post-item h2 a:visited {
  opacity: 1;
}

/* Homepage groups — observations / mechanisms / artifacts */
.stage { margin-bottom: 2.5rem; }

.stage-bar {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin: 0 0 1rem;
  font-size: 0.8rem;
}
* + .stage-bar { margin-top: 0; }

.stage-name {
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}
.stage-name:hover { text-decoration: underline; text-underline-offset: 3px; }
.stage-name:visited { color: var(--accent); }

.stage-count {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.stage-rule {
  flex: 1;
  height: 1px;
  background: var(--border);
}

.stage-gloss {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--muted);
  white-space: nowrap;
}

.entry { margin-bottom: 1.25rem; }
.entry:last-of-type { margin-bottom: 0; }

.entry-title {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.35;
  margin: 0 0 0.15rem;
}
.entry-title a { color: var(--text); }
.entry-title a:hover { color: var(--accent); text-decoration: none; }
.entry-title a:visited { color: var(--text); }

.entry-sub {
  font-size: 0.95rem;
  color: var(--muted);
  margin: 0;
  max-width: 62ch;
}
.entry-date {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.78rem;
  white-space: nowrap;
}

.stage-more,
.stage-empty,
.stage-all {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0.9rem 0 0;
}

/* Ways to go deeper — subject index + the chronological view */
.deeper {
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.deeper .stage-all { margin: 0; }

.topics {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.1rem;
}
.topics-label {
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.7rem;
  color: var(--muted);
  margin-right: 0.7rem;
}
.topics a { color: var(--muted); text-decoration: none; }
.topics a:hover { color: var(--accent); text-decoration: underline; }
.topics a:visited { color: var(--muted); }
.topics-count {
  font-size: 0.7rem;
  color: var(--accent);
  margin-left: 0.2rem;
  font-variant-numeric: tabular-nums;
}

/* Meta */
.meta {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.1rem 0 0.35rem;
}
.type { color: var(--accent); }

/* Summary */
.summary {
  font-size: 0.95rem;
  color: var(--muted);
  margin: 0.2rem 0 0.3rem;
}

/* Tags */
.tags {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0.2rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.tags code,
.tags span {
  background: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
}
/* Tags link into the /writing filter — they looked clickable before but
   were inert <span>s. */
.tags a {
  color: var(--muted);
  text-decoration: none;
}
.tags a:hover {
  color: var(--accent);
  text-decoration: underline;
}
.tags a:visited { color: var(--muted); }

/* Filters — tame readability */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  margin-bottom: 2rem;
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.8rem;
  color: var(--text);
  opacity: 0.85;
  align-items: center;
}
.filters label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.filters select {
  font-family: inherit;
  font-size: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
  cursor: pointer;
}
.filters select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  color: var(--text);
}

/* Post footer */
.post-footer {
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}
.post-nav {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.82rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.post-nav a {
  color: var(--muted);
  text-decoration: none;
  max-width: 48%;
  line-height: 1.4;
}
.post-nav a:hover { color: var(--accent); }
.post-nav-next { margin-left: auto; text-align: right; }
.post-nav-meta {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
}
.post-nav-meta a { color: var(--muted); }
.post-nav-meta a:hover { color: var(--accent); }

/* Empty state */
.empty {
  color: var(--muted);
  font-size: 0.95rem;
  font-style: italic;
}

/* Post page */
.post-header {
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}
.post-header h1 {
  margin-top: 0;
  font-size: 2rem;
  line-height: 1.25;
}

/* Prose */
.prose p { margin: 1rem 0; }
.prose img,
.prose video {
  display: block;
  max-width: 100%;
  margin: 2rem auto;
  border-radius: 3px;
}
.prose figure {
  margin: 2rem 0;
  text-align: center;
}
.prose figcaption {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.5rem;
}
.prose blockquote {
  margin: 1.5rem 0;
  padding-left: 1.25rem;
  border-left: 2px solid var(--border);
  color: var(--muted);
  font-style: italic;
}
.prose blockquote p { margin: 0.5rem 0; }
.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.25rem 0; /* P2: tighten prose rhythm */
}

/* Tables */
.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin: 1.5rem 0;
  overflow-x: auto;
  display: block;
}
.prose th,
.prose td {
  text-align: left;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.prose th {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

/* Code */
code {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.85em;
  background: var(--code-bg);
  padding: 0.1em 0.3em;
  border-radius: 3px;
}
pre {
  overflow-x: auto;
  margin: 1.5rem 0;
  border-radius: 4px;
  background: var(--code-bg); /* P1: plain fenced code keeps contrast in dark mode */
}

pre code {
  background: none;
  padding: 0;
  font-size: 0.85rem;
}

/* Shiki code blocks — dual theme. Shiki emits both palettes as custom
   properties (defaultColor: false), so light mode no longer gets a dark
   block sitting next to light-background plain fences. */
.shiki {
  padding: 1rem 1.25rem;
  overflow-x: auto;
  border-radius: 4px;
  font-size: 0.85rem;
  line-height: 1.6;
}
.shiki,
.shiki span {
  color: var(--shiki-light);
  background-color: var(--shiki-light-bg);
}
@media (prefers-color-scheme: dark) {
  .shiki,
  .shiki span {
    color: var(--shiki-dark);
    background-color: var(--shiki-dark-bg);
  }
}

/* Mermaid — surface, not card */
.mermaid {
  margin: 2rem 0;
  padding: 1rem;
  text-align: center;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
}
.mermaid svg {
  max-width: 100%;
  height: auto;
}

/* Demo iframes */
iframe {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin: 1.5rem 0;
}

/* Site footer */
footer {
  margin-top: 4rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.8rem;
  color: var(--muted);
}
footer p { margin: 0; }
footer a { color: var(--muted); }
footer a:hover { color: var(--accent); }
footer a:visited { color: var(--muted); }

/* Responsive */
@media (max-width: 480px) {
  body { font-size: 1rem; padding: 1.25rem 1rem 3rem; }
  nav { gap: 0 0.75rem; }
  nav .sep { display: none; }
  .filters select { font-size: 1rem; }
  .filters { flex-wrap: wrap; }
  header { margin-bottom: 2rem; }
  /* Scaled down but still a real hierarchy — the old rules flattened
     every heading back to ~1.1rem, undoing the scale on mobile. */
  h1 { font-size: 1.4rem; }
  .site-tagline { font-size: 1.4rem; max-width: none; }
  .lead { font-size: 1.05rem; }
  .post-header h1 { font-size: 1.5rem; }
  .post-item h2 { font-size: 1.1rem; }
  .post-item { padding: 1.1rem 0.75rem; margin: 0 -0.75rem; }
}
