/* ==========================================================================
   seismos — base layout, typography, and dark theme
   Hand-written plain CSS, no preprocessor, no build step (ADR-0007).
   Scope (M3 #7): document shell, type scale, colors, base elements.
   Post-list cards (#8) and Chroma token colors (#10) live elsewhere.
   ========================================================================== */

/* --------------------------------------------------------------------------
   0. Web fonts — self-hosted WOFF2, Latin subset (static/fonts/, SIL OFL)
      Source Serif 4 (body) + Victor Mono (code). font-display: swap so text
      paints immediately in the fallback stack, then swaps in.
   -------------------------------------------------------------------------- */
@font-face {
  font-family: "Source Serif 4";
  font-style: normal; font-weight: 400; font-display: swap;
  src: url("/fonts/source-serif-4-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Source Serif 4";
  font-style: normal; font-weight: 600; font-display: swap;
  src: url("/fonts/source-serif-4-latin-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Source Serif 4";
  font-style: italic; font-weight: 400; font-display: swap;
  src: url("/fonts/source-serif-4-latin-400-italic.woff2") format("woff2");
}
@font-face {
  font-family: "Victor Mono";
  font-style: normal; font-weight: 400; font-display: swap;
  src: url("/fonts/victor-mono-latin-400-normal.woff2") format("woff2");
}

/* --------------------------------------------------------------------------
   1. Design tokens
   -------------------------------------------------------------------------- */
:root {
  /* Fonts — self-hosted primaries with graceful system fallbacks */
  --font-body: "Source Serif 4", Georgia, Cambria, "Times New Roman", serif;
  --font-mono: "Victor Mono", ui-monospace, "Cascadia Code", "SF Mono",
               SFMono-Regular, Menlo, Consolas, monospace;

  /* Catppuccin Mocha (WCAG AA against --bg for body/meta/accent text) */
  --bg:          #1e1e2e;  /* base */
  --bg-elev:     #181825;  /* mantle — code/inline/table surface */
  --border:      #313244;  /* surface0 */
  --fg:          #bac2de;  /* subtext1 — body */
  --fg-strong:   #cdd6f4;  /* text — headings, site title */
  --muted:       #a6adc8;  /* subtext0 — meta, dates, tags */
  --accent:      #89b4fa;  /* blue — links, focus */
  --accent-hover:#b4befe;  /* lavender */
  --accent-soft: rgba(137, 180, 250, 0.15);
  --selection:   rgba(137, 180, 250, 0.30);

  /* Type scale (base 17px, ~1.25 ratio) */
  --fs-base: 1.0625rem;
  --fs-sm:   0.9rem;
  --fs-h4:   1.1rem;
  --fs-h3:   1.3rem;
  --fs-h2:   1.6rem;
  --fs-h1:   2.2rem;
  --lh-body: 1.7;
  --lh-head: 1.25;

  /* Rhythm & layout */
  --measure: 48rem;
  --space:   1.25rem;
  --radius:  6px;
}

/* --------------------------------------------------------------------------
   2. Reset / normalize (minimal — the platform reset already ran)
   -------------------------------------------------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

::selection { background: var(--selection); }

/* --------------------------------------------------------------------------
   3. Layout primitives
   -------------------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: var(--space);
}

main {
  flex: 1 0 auto;
  padding-block: 2.5rem 3.5rem;
}

/* Skip link — visible only when focused */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 0.5rem 0.85rem;
  background: var(--accent);
  color: #11111b;
  font-weight: 600;
  border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus {
  left: 0;
}

/* main gets a focus target but no visible outline when programmatically focused */
main:focus { outline: none; }

/* --------------------------------------------------------------------------
   4. Header & footer
   -------------------------------------------------------------------------- */
.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1.25rem;
  padding-block: 1.1rem;
}
.site-title {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--fg-strong);
  text-decoration: none;
}
.site-title:hover { color: var(--accent); }

.site-nav {
  display: flex;
  gap: 1.25rem;
  font-size: var(--fs-sm);
}
.site-nav a {
  color: var(--muted);
  text-decoration: none;
}
.site-nav a:hover,
.site-nav a:focus-visible { color: var(--accent); }

.site-footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: var(--fs-sm);
  padding-block: 1.75rem;
}
.site-footer p { margin: 0; }

/* --------------------------------------------------------------------------
   5. Typography — headings, prose, lists
   -------------------------------------------------------------------------- */
h1, h2, h3, h4, h5, h6 {
  color: var(--fg-strong);
  line-height: var(--lh-head);
  font-weight: 650;
  letter-spacing: -0.015em;
  margin: 2.2rem 0 0.75rem;
}
h1 { font-size: var(--fs-h1); margin-top: 0; }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); }
h4 { font-size: var(--fs-h4); }

p, ul, ol, blockquote, pre, table { margin: 0 0 1.25rem; }

b, strong { font-weight: 600; }

.lede {
  font-size: 1.2rem;
  color: var(--muted);
  max-width: 40rem;
}

ul, ol { padding-left: 1.4rem; }
li { margin-bottom: 0.35rem; }
li::marker { color: var(--muted); }

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
  transition: color 0.15s ease;
}
a:hover { color: var(--accent-hover); }

blockquote {
  margin-inline: 0;
  padding: 0.25rem 0 0.25rem 1.1rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

/* --------------------------------------------------------------------------
   6. Code — baseline only; Chroma token colors land in #10
   -------------------------------------------------------------------------- */
code, pre, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

/* Inline code */
:not(pre) > code {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
  color: var(--fg-strong);
  word-break: break-word;
}

/* Code blocks — scroll horizontally within their own box (03 §4) */
pre {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  overflow-x: auto;
  line-height: 1.55;
}
pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: 0.875rem;
  color: inherit;
}

/* --------------------------------------------------------------------------
   7. Tables
   -------------------------------------------------------------------------- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
th, td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.7rem;
  text-align: left;
}
th {
  background: var(--bg-elev);
  color: var(--fg-strong);
  font-weight: 600;
}

/* Markdown tables are wrapped in .table-wrap (render hook) so a wide table
   scrolls horizontally on narrow screens instead of breaking the layout. */
.table-wrap {
  overflow-x: auto;
  margin: 0 0 1.25rem;
}
.table-wrap > table { margin: 0; }
.ta-left   { text-align: left; }
.ta-center { text-align: center; }
.ta-right  { text-align: right; }

/* --------------------------------------------------------------------------
   8. Home intro
   -------------------------------------------------------------------------- */
.home-intro { margin-bottom: 3rem; }
.home-intro h1 { letter-spacing: -0.02em; }

/* --------------------------------------------------------------------------
   9. Post list (home + tag pages)
   -------------------------------------------------------------------------- */
.post-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2.25rem;
}
.post-summary { margin: 0; }
.post-summary-title {
  font-size: 1.45rem;
  margin: 0 0 0.4rem;
}
.post-summary-title a {
  color: var(--fg-strong);
  text-decoration: none;
}
.post-summary-title a:hover { color: var(--accent); }
.post-summary-desc {
  margin: 0.5rem 0 0;
  color: var(--fg);
}
.empty-note { color: var(--muted); }

/* Shared byline */
.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1rem;
  font-size: var(--fs-sm);
  color: var(--muted);
}
.post-meta time { font-variant-numeric: tabular-nums; }
.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.75rem;
}
.post-tags a {
  color: var(--muted);
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}
.post-tags a:hover { color: var(--accent); }

/* --------------------------------------------------------------------------
   10. Post single
   -------------------------------------------------------------------------- */
.post-header {
  margin-bottom: 2.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}
.post-header h1 { margin-bottom: 0.75rem; }
.post-body > :first-child { margin-top: 0; }

.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.post-nav-cell { min-width: 0; }
.post-nav-newer { text-align: right; }
.post-nav a {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  text-decoration: none;
  color: var(--fg-strong);
}
.post-nav-newer a { align-items: flex-end; }
.post-nav-label {
  font-size: var(--fs-sm);
  color: var(--muted);
}
.post-nav-title { font-weight: 600; }
.post-nav a:hover .post-nav-title { color: var(--accent); }

/* --------------------------------------------------------------------------
   11. Page header + tag pages (taxonomy + term)
   -------------------------------------------------------------------------- */
.page-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}
.page-header h1 { margin-bottom: 0.4rem; }
.tag-title { font-weight: 600; }
.tag-name {
  font-family: var(--font-mono);
  color: var(--accent);
}
.page-meta {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.tag-cloud {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 0.75rem;
}
.tag-cloud li {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elev);
}
.tag-cloud a {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--fg);
  text-decoration: none;
}
.tag-cloud li:hover { border-color: var(--accent); }
.tag-cloud li:hover a { color: var(--accent); }
.tag-count {
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   12. Syntax highlighting (Chroma, class-based — markup.highlight.noClasses=false)
   Token colors are hand-tuned to sit on the code block's --bg-elev surface;
   the block box itself comes from the `pre` rule (section 6). Ordinary
   identifiers, operators, and punctuation stay at --fg on purpose — only
   keywords/types/strings/numbers/functions/comments carry color.
   -------------------------------------------------------------------------- */
:root {
  --hl-comment:  #9399b2;  /* overlay2 — comments (italic) */
  --hl-keyword:  #cba6f7;  /* mauve — keywords, preprocessor, word-operators */
  --hl-type:     #f9e2af;  /* yellow — types, classes, namespaces, tags */
  --hl-string:   #a6e3a1;  /* green — string literals */
  --hl-number:   #fab387;  /* peach — numeric literals, escapes */
  --hl-function: #89b4fa;  /* blue — function/decorator names (== accent) */
  --hl-builtin:  #94e2d5;  /* teal — builtins, constants, asm registers */
}

/* Comments */
.chroma .c, .chroma .ch, .chroma .cm, .chroma .c1, .chroma .cs { color: var(--hl-comment); font-style: italic; }
.chroma .cp { color: var(--hl-keyword); }   /* preprocessor: #include, #define */
.chroma .cpf { color: var(--hl-string); }   /* preprocessor file: <stdio.h> */

/* Keywords */
.chroma .k, .chroma .kd, .chroma .kn, .chroma .kp, .chroma .kr, .chroma .ow { color: var(--hl-keyword); }
.chroma .kc { color: var(--hl-builtin); }   /* true / false / nil / iota */
.chroma .kt { color: var(--hl-type); }       /* int, void, chan, struct */

/* Names */
.chroma .nf, .chroma .fm, .chroma .nd { color: var(--hl-function); }
.chroma .nb, .chroma .bp { color: var(--hl-builtin); }
.chroma .nc, .chroma .nn, .chroma .nt { color: var(--hl-type); }
.chroma .no { color: var(--hl-builtin); }    /* constants; asm registers */

/* Strings */
.chroma .s, .chroma .sb, .chroma .sc, .chroma .s2, .chroma .sh, .chroma .si,
.chroma .sx, .chroma .sr, .chroma .s1, .chroma .ss, .chroma .dl, .chroma .sa { color: var(--hl-string); }
.chroma .se { color: var(--hl-number); }     /* escape sequences: \n \x00 */

/* Numbers */
.chroma .m, .chroma .mb, .chroma .mf, .chroma .mh, .chroma .mi, .chroma .mo,
.chroma .il { color: var(--hl-number); }

/* Diff / generic (rarely used, cheap to cover) */
.chroma .gd { color: #f38ba8; }
.chroma .gi { color: var(--hl-string); }
.chroma .gu, .chroma .gh { color: var(--muted); }
.chroma .ge { font-style: italic; }
.chroma .gs { font-weight: 600; }

/* Line highlight (via {hl_lines=...}) */
.chroma .hl { display: block; background: var(--accent-soft); }

/* Line numbers — opt-in via {linenos=table} on long blocks (03 §3).
   In table mode the wrapper is a div.chroma; box it and flatten the inner
   pre cells so the block reads as one framed unit. */
.chroma .lnt, .chroma .ln {
  color: var(--muted);
  opacity: 0.5;
  user-select: none;
  -webkit-user-select: none;
  margin-right: 0.9em;
}
.highlight > div.chroma {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
.highlight .lntable { border-spacing: 0; width: 100%; margin: 0; }
.highlight .lntable td { padding: 0; border: 0; }
.highlight .lntable td.lntd:last-child { width: 100%; }
.highlight .lntable pre.chroma {
  background: none;
  border: 0;
  border-radius: 0;
  margin: 0;
}

/* --------------------------------------------------------------------------
   13. Error page (404)
   -------------------------------------------------------------------------- */
.error-page {
  text-align: center;
  padding-block: 3rem 2rem;
}
.error-code {
  font-family: var(--font-mono);
  font-size: clamp(3rem, 12vw, 5.5rem);
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--accent);
  margin: 0 0 0.5rem;
}
.error-page h1 { margin-top: 0; }
.error-page p { color: var(--muted); }

/* --------------------------------------------------------------------------
   14. Focus & motion
   -------------------------------------------------------------------------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

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

/* --------------------------------------------------------------------------
   15. Narrow-screen adjustments
   -------------------------------------------------------------------------- */
@media (max-width: 30rem) {
  /* Stack prev/next into a single column so titles aren't cramped */
  .post-nav {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }
  .post-nav-newer { text-align: left; }
  .post-nav-newer a { align-items: flex-start; }
}
