/* ============================================================================
   base.css — the design system + all shared components.

   Everything visual is driven by CSS custom properties, so the whole look
   (colour, type, spacing) can be re-skinned by editing the tokens in :root
   without touching a single layout. Section-specific bits live in
   articles.css / blog.css / book.css; syntax colours in chroma.css.

   Editorial theme: serif reading column on warm paper, a clean sans for UI,
   one restrained accent per content shape, full light + dark support.
   ========================================================================== */

/* --- Design tokens: light (default) --------------------------------------- */
:root {
  /* Palette — taken from the WordPress site this replaced (Penscratch): a white page,
     grey ink, hairline grey rules, and one teal for every link. */
  --bg:        #ffffff;
  --surface:   #f7f7f7;   /* asides, code, quiet panels */
  --surface-2: #ffffff;   /* cards that should read as "raised" off the page */
  --fg:        #666666;
  --fg-strong: #444444;   /* headings — the old theme used #666 for these too, but our
                             headings are larger, so they take a little more weight */
  --muted:     #999999;
  --line:      #eeeeee;
  --line-soft: #f4f4f4;

  /* One accent for the whole site, as the old theme had: its link teal. */
  --accent: #1c7c7c;

  /* Type */
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua",
                Charter, Georgia, Cambria, "Times New Roman", serif;
  --font-ui:    system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                Helvetica, Arial, sans-serif;
  --font-mono:  ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas,
                "Liberation Mono", monospace;

  /* Rhythm & shape */
  --measure: 40rem;   /* comfortable serif reading width (~68ch)  */
  --wrap:    46rem;   /* general single-column pages              */
  --wide:    64rem;   /* content + side aside                     */
  --radius:  8px;
  --radius-lg: 14px;
  --shadow:  0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.05);

  color-scheme: light;
}

/* --- Design tokens: dark -------------------------------------------------- */
/* The old theme had no dark mode; this is the same palette inverted, with the teal
   lifted enough to stay readable on a dark ground. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #1c1c1c;
    --surface:   #252525;
    --surface-2: #232323;
    --fg:        #c9c9c9;
    --fg-strong: #e8e8e8;
    --muted:     #8f8f8f;
    --line:      #383838;
    --line-soft: #2c2c2c;

    --accent: #5fb3b3;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 18px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}
/* Explicit toggle wins over the OS preference in both directions. */
:root[data-theme="dark"] {
  --bg:        #1c1c1c;
  --surface:   #252525;
  --surface-2: #232323;
  --fg:        #c9c9c9;
  --fg-strong: #e8e8e8;
  --muted:     #8f8f8f;
  --line:      #383838;
  --line-soft: #2c2c2c;
  --accent: #5fb3b3;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 18px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

/* --- Reset-ish ------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 112.5%; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1rem;
  line-height: 1.72;
  color: var(--fg);
  background: var(--bg);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1 0 auto; }

.muted { color: var(--muted); }
.wrap  { max-width: var(--wrap); margin: 0; padding: 3rem 1.5rem; }

/* --- Per-shape accent ----------------------------------------------------- */
/* One teal across the whole site, and a plain white page in every section — the old
   theme worked that way. The body classes (shape-blog, shape-articles, …) are still on
   every page, so a section can be given its own accent or tint here if wanted:
       body.shape-articles { --accent: #35548a; } */

/* --- Typography ----------------------------------------------------------- */
h1, h2, h3, h4 {
  font-family: var(--font-serif);
  color: var(--fg-strong);
  line-height: 1.18;
  font-weight: 700;
  letter-spacing: -0.01em;
}
h1 { font-size: clamp(1.9rem, 1.4rem + 2.2vw, 2.7rem); margin: 0 0 0.6rem; }
h2 { font-size: 1.5rem; margin: 2.2rem 0 0.7rem; }
h3 { font-size: 1.2rem; margin: 1.8rem 0 0.5rem; }
p  { margin: 0 0 1.1rem; }

/* Links fade to grey on hover rather than brightening, as the old theme's did. */
a { color: var(--accent); text-underline-offset: 0.14em; text-decoration-thickness: 0.06em; }
a:hover { color: var(--muted); }

hr { border: 0; border-top: 1px solid var(--line); margin: 2.5rem 0; }
small { font-size: 0.82rem; }

/* --- Prose (rendered .Content) ------------------------------------------- */
.prose { font-size: 1.06rem; }
.prose > :first-child { margin-top: 0; }
.prose h2 { padding-top: 0.2rem; }
.prose a { text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.prose a:hover { text-decoration-color: var(--accent); }
.prose ul, .prose ol { padding-left: 1.3rem; margin: 0 0 1.1rem; }
.prose li { margin: 0.3rem 0; }
.prose img { max-width: 100%; height: auto; border-radius: var(--radius); }
.prose blockquote {
  margin: 1.4rem 0; padding: 0.3rem 1.2rem;
  border-left: 3px solid var(--line);
  color: var(--muted); font-style: italic;
}
.prose blockquote p:last-child { margin-bottom: 0; }
.prose table {
  border-collapse: collapse; width: 100%; margin: 1.4rem 0;
  font-family: var(--font-ui); font-size: 0.92rem;
}
.prose th, .prose td { border: 1px solid var(--line); padding: 0.5rem 0.7rem; text-align: left; }
.prose th { background: var(--surface); font-weight: 600; }

/* Code — monospace, tinted panels; token colours come from chroma.css */
code, kbd, samp { font-family: var(--font-mono); font-size: 0.88em; }
.prose :not(pre) > code {
  background: var(--surface); border: 1px solid var(--line-soft);
  padding: 0.08em 0.36em; border-radius: 5px;
}
.prose pre {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.9rem 1.1rem;
  overflow-x: auto; margin: 1.3rem 0; line-height: 1.55;
}
.prose pre code { background: none; border: 0; padding: 0; font-size: 0.85rem; }

/* --- Top navigation ------------------------------------------------------- */
.topnav {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1.5rem;
  padding: 0.7rem clamp(1rem, 4vw, 2rem);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  -webkit-backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 3px solid var(--line);
  font-family: var(--font-ui);
}
.topnav .brand {
  font-weight: 700; font-size: 1.02rem; letter-spacing: -0.01em;
  color: var(--fg-strong); text-decoration: none; white-space: nowrap;
}
.topnav .brand:hover { color: var(--accent); }
.topnav .nav-links { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.topnav .nav-links a {
  text-decoration: none; color: var(--muted);
  font-size: 0.92rem; padding: 0.3rem 0.6rem; border-radius: 6px;
}
.topnav .nav-links a:hover { color: var(--fg-strong); background: var(--surface); }
.topnav .nav-links a.active { color: var(--accent); font-weight: 600; }

/* Copyright footer — page chrome, aligned with the nav's horizontal padding. */
.site-footer {
  margin-top: 3rem;
  padding: 1.5rem clamp(1rem, 4vw, 2rem);
  border-top: 1px solid var(--line);
  color: var(--muted); font-size: 0.85rem; font-family: var(--font-ui);
}
.site-footer p { margin: 0; }

/* --- Content with a side column ------------------------------------------ */
/* Shared by posts and articles: the reading column, with categories and backlinks in a
   right-hand column where the viewport allows and stacked underneath where it doesn't.
   Comments keep the content column at every width — they are prose, not metadata.
   Source order is content, aside, comments, so the stacked order reads sensibly too. */
.entry {
  display: grid;
  grid-template-columns: minmax(0, 42rem) 15rem;
  gap: 1rem 2.5rem;
  max-width: 62rem; margin: 0; padding: 2.5rem 1.5rem;
}
.entry > .article,
.entry > .post { min-width: 0; }
.entry-aside { display: flex; flex-direction: column; gap: 1.1rem; }
.entry-comments { grid-column: 1; min-width: 0; }
/* Nothing in the side column → drop it and keep the reading width left-aligned. */
.entry:not(:has(.entry-aside > *)) { grid-template-columns: 1fr; max-width: 44rem; }
/* The panel follows the reader down a long post; static once stacked. */
.entry-aside .backlinks { position: sticky; top: 4rem; }

@media (max-width: 62rem) {
  .entry { grid-template-columns: 1fr; max-width: 44rem; gap: 1.5rem; }
  .entry-aside .backlinks { position: static; }
}

/* --- Categories (foot of a page, or the side column) --------------------- */
/* Plain sentences of links, not chips beside the title. */
.terms {
  margin: 1.8rem 0 0; padding-top: 0.9rem;
  border-top: 1px solid var(--line);
  font-family: var(--font-ui); font-size: 0.86rem; color: var(--muted);
}
/* In the side column it is a panel in its own right, so it needs no divider above. */
.entry-aside .terms { margin: 0; padding-top: 0; border-top: 0; }

/* --- Backlinks panel ------------------------------------------------------ */
.backlinks {
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 0.9rem 1.1rem;
  background: var(--surface); font-family: var(--font-ui); font-size: 0.9rem;
}
.backlinks h3 {
  margin: 0 0 0.55rem; font-family: var(--font-ui);
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--muted); font-weight: 700;
}
.backlinks ul { list-style: none; padding: 0; margin: 0; }
.backlinks li { margin: 0.4rem 0; line-height: 1.4; }
.backlinks a { text-decoration: none; color: var(--accent); }
.backlinks a:hover { color: var(--muted); text-decoration: underline; }
.backlinks-sub {
  margin: 0.9rem 0 0.35rem; padding-top: 0.75rem;
  border-top: 1px solid var(--line);
  font-family: var(--font-ui); font-size: 0.85rem; font-weight: 600;
  letter-spacing: 0; color: var(--fg-strong);
}
/* First group sits directly under the heading — no divider needed there. */
.backlinks h3 + .backlinks-sub { margin-top: 0; padding-top: 0; border-top: 0; }

/* --- Comments ------------------------------------------------------------- */
/* Shared across sections, like .backlinks: comments render on posts, articles and
   standalone pages alike. Replies are marked by an indent rule rather than a box per
   comment, so a deep thread stays readable and the markup stays a plain nested list. */
.comments { margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.comments > h2 {
  margin: 0 0 1.3rem;
  font-family: var(--font-ui); font-size: 0.8rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
}
.comment-list { list-style: none; padding: 0; margin: 0; }
.comment-list .comment-list {
  margin: 1.3rem 0 0; padding-left: 1.2rem;
  border-left: 2px solid var(--line-soft);
}
.comment + .comment { margin-top: 1.6rem; }
.comment-meta {
  margin: 0 0 0.3rem;
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.6rem;
  font-family: var(--font-ui); font-size: 0.82rem; color: var(--muted);
}
.comment-author { font-weight: 600; color: var(--fg-strong); text-decoration: none; }
a.comment-author:hover { color: var(--accent); }
.comment-link { text-decoration: none; color: var(--line); }
.comment-link:hover { color: var(--accent); }
.comment > .prose { font-size: 1rem; }
.comment > .prose > :last-child { margin-bottom: 0; }
/* Arriving by permalink should make it obvious which comment was linked. */
.comment:target > .comment-meta .comment-author { color: var(--accent); }

/* --- Section cards (home) ------------------------------------------------- */
.shape-cards {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  margin-top: 1.5rem;
}
.shape-card {
  display: block; padding: 1.2rem 1.3rem;
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--surface-2); text-decoration: none; color: inherit;
  transition: border-color .15s, transform .15s;
}
.shape-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.shape-card h2 { margin: 0 0 0.35rem; font-size: 1.2rem; }
.shape-card p { margin: 0; color: var(--muted); font-size: 0.95rem; font-family: var(--font-ui); }

/* --- Home page ------------------------------------------------------------ */
.home { max-width: var(--wide); margin: 0; padding: 3rem 1.5rem; }
.home-intro { max-width: var(--measure); }
.home-intro h1 { font-size: clamp(2.1rem, 1.5rem + 3vw, 3.1rem); }
.home-intro .lede { font-size: 1.12rem; }

.home-cols {
  display: grid; gap: 2.5rem 3rem;
  grid-template-columns: 1.3fr 1fr; margin: 3rem 0 1rem;
}
.home-cols h2 {
  font-family: var(--font-ui); font-size: 0.8rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
  border-bottom: 1px solid var(--line); padding-bottom: 0.5rem; margin: 0 0 0.9rem;
}

.post-list { list-style: none; padding: 0; margin: 0; }
.post-list li { margin: 0.7rem 0; display: flex; gap: 0.9rem; align-items: baseline; }
.post-list time {
  color: var(--muted); font-family: var(--font-ui); font-size: 0.78rem;
  white-space: nowrap; flex: 0 0 4.2rem;
}
.post-list a { text-decoration: none; font-size: 1.02rem; }
.post-list a:hover { text-decoration: underline; }
.more { margin-top: 1.1rem; font-family: var(--font-ui); font-size: 0.9rem; }
.more a { text-decoration: none; font-weight: 600; }

.cat-list { list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 0.15rem; }
.cat-list li { margin: 0; }
.cat-list a { text-decoration: none; font-weight: 600; }
.cat-list a:hover { text-decoration: underline; }
.cat-list .muted { font-family: var(--font-ui); font-size: 0.82rem; }

/* --- Responsive ----------------------------------------------------------- */
@media (max-width: 44rem) {
  .home-cols { grid-template-columns: 1fr; gap: 1.8rem; }
  .topnav { gap: 0.8rem; }
  .topnav .brand { font-size: 0.98rem; }
}

/* --- Accessibility -------------------------------------------------------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: #fff; padding: 0.5rem 1rem; z-index: 100;
  font-family: var(--font-ui); text-decoration: none;
}
.skip-link:focus { left: 0.5rem; top: 0.5rem; border-radius: 6px; }
