/* Dark is the site's default look (not just OS-driven) -- light is an
   explicit opt-in via the theme toggle, not the other way around. */
:root {
  --paper: #10161d;
  --paper-raised: #171f28;
  --ink: #e6ecf1;
  --ink-soft: #b7c2cc;
  --muted: #7c8b9a;
  --line: #263241;
  --line-strong: #33445a;
  --copper: #d68a4d;
  --copper-ink: #f0b581;
  --ok: #6fbf95;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
  --radius: 3px;
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Code", "SF Mono", "Fira Code", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
  --paper: #10161d;
  --paper-raised: #171f28;
  --ink: #e6ecf1;
  --ink-soft: #b7c2cc;
  --muted: #7c8b9a;
  --line: #263241;
  --line-strong: #33445a;
  --copper: #d68a4d;
  --copper-ink: #f0b581;
  --ok: #6fbf95;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
}
:root[data-theme="light"] {
  --paper: #eef1f3;
  --paper-raised: #e2e7ea;
  --ink: #172230;
  --ink-soft: #3c4a5a;
  --muted: #67788a;
  --line: #c7d0d6;
  --line-strong: #a9b5bd;
  --copper: #b25f27;
  --copper-ink: #7d3f16;
  --ok: #3f7a5c;
  --shadow: 0 1px 0 rgba(23, 34, 48, 0.05);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
}
body { -webkit-font-smoothing: antialiased; }

a { color: var(--copper); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible {
  outline: 2px solid var(--copper);
  outline-offset: 2px;
}

/* ---------- title block ---------- */
header.titleblock {
  max-width: 920px;
  margin: 44px auto 0;
  padding: 0 20px;
}
.tb-grid {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper-raised);
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr;
  box-shadow: var(--shadow);
}
.tb-cell { padding: 10px 14px; border-left: 1px solid var(--line); }
.tb-cell:first-child { border-left: none; }
.tb-label {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  display: block;
  margin-bottom: 3px;
}
.tb-value { font-family: var(--mono); font-size: 12.5px; color: var(--ink-soft); }
.tb-site { font-family: var(--sans); font-weight: 700; font-size: 20px; letter-spacing: -0.01em; }
.tb-site a { color: var(--ink); }
.tb-site a:hover { text-decoration: none; }
.tb-site span { color: var(--copper); }

nav.primary {
  max-width: 920px;
  margin: 14px auto 0;
  padding: 0 20px;
  display: flex;
  gap: 22px;
  align-items: center;
  font-family: var(--mono);
  font-size: 12.5px;
}
nav.primary a { color: var(--ink-soft); }
nav.primary a.current { color: var(--copper); }
nav.primary .spacer { flex: 1; }
nav.primary .rss { color: var(--muted); }

/* ---------- sheet dividers ---------- */
.sheet-label {
  max-width: 920px;
  margin: 40px auto 10px;
  padding: 0 20px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sheet-label::after { content: ""; flex: 1; border-top: 1px dashed var(--line-strong); }

/* ---------- intro / bio ---------- */
.intro {
  max-width: 920px;
  margin: 22px auto 0;
  padding: 18px 20px 4px;
  border-bottom: 1px solid var(--line);
}
.intro p {
  font-size: 15.5px;
  line-height: 1.65;
  color: var(--ink-soft);
  max-width: 74ch;
  margin: 0 0 14px;
}
.intro strong { color: var(--ink); font-weight: 600; }

/* ---------- post index ---------- */
.index { max-width: 920px; margin: 0 auto; padding: 6px 20px 30px; }
.index-row {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 18px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}
.index-row:first-child { padding-top: 8px; }
.index-date {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  padding-top: 2px;
}
.index-title { margin: 0 0 6px; font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.index-title a { color: var(--ink); }
.index-title a:hover { color: var(--copper); text-decoration: none; }
.index-dek { margin: 0 0 9px; font-size: 14px; line-height: 1.55; color: var(--ink-soft); max-width: 66ch; }
.empty { color: var(--muted); font-size: 14px; padding: 20px 0; }

.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.03em;
  color: var(--muted);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 2px 7px;
}

/* ---------- post detail ---------- */
article.post { max-width: 860px; margin: 0 auto; padding: 8px 20px 60px; }
.post-meta {
  display: flex;
  gap: 16px;
  align-items: baseline;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  margin: 22px 0 10px;
  flex-wrap: wrap;
}
.post-meta .tags { margin-left: auto; }
h1.post-title { font-size: 30px; line-height: 1.22; letter-spacing: -0.015em; margin: 0 0 22px; max-width: 26ch; }

.post-body p, .post-body ul, .post-body ol {
  font-size: 16.5px;
  line-height: 1.7;
  color: var(--ink-soft);
  max-width: 74ch;
  margin: 0 0 20px;
}
.post-body ul, .post-body ol { padding-left: 1.3em; }
.post-body li { margin-bottom: 8px; }
.post-body strong { color: var(--ink); font-weight: 600; }
.post-body h2, .post-body h3 {
  max-width: 74ch;
  letter-spacing: -0.01em;
  margin: 34px 0 14px;
}
.post-body h2 { font-size: 22px; }
.post-body h3 { font-size: 18px; }
.post-body blockquote {
  max-width: 70ch;
  margin: 0 0 20px;
  padding-left: 16px;
  border-left: 3px solid var(--line-strong);
  color: var(--muted);
  font-style: italic;
}
.post-body img { max-width: 100%; border-radius: var(--radius); }
.post-body hr { border: none; border-top: 1px dashed var(--line-strong); max-width: 74ch; margin: 32px 0; }

/* ---------- footnotes ---------- */
.post-body sup a.footnote-ref {
  font-family: var(--mono);
  font-size: 0.7em;
  color: var(--copper);
}
.post-body .footnotes {
  max-width: 74ch;
  font-size: 13.5px;
  color: var(--muted);
}
.post-body .footnotes hr { margin: 32px 0 16px; }
.post-body .footnotes ol { font-size: inherit; color: inherit; margin: 0; }
.post-body .footnotes li { margin-bottom: 10px; }
.post-body .footnotes li p { font-size: inherit; color: inherit; max-width: none; margin: 0; }
.post-body .footnote-backref {
  font-family: var(--mono);
  color: var(--muted);
  margin-left: 2px;
}
.post-body .footnote-backref:hover { color: var(--copper); }
.post-body code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1px 5px;
  color: var(--copper-ink);
}
.post-body pre code { background: none; border: none; padding: 0; color: inherit; }

/* ---------- callouts ---------- */
.note {
  max-width: 74ch;
  margin: 0 0 24px;
  border-left: 3px solid var(--copper);
  background: var(--paper-raised);
  padding: 12px 16px;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.note-label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--copper);
  display: block;
  margin-bottom: 6px;
}
.note p { margin: 0; font-size: 14.5px; color: var(--ink-soft); max-width: none; }

/* ---------- ascii diagram shortcode ---------- */
.diagram {
  max-width: 74ch;
  margin: 0 0 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raised);
  overflow-x: auto;
}
.diagram-cap {
  padding: 8px 14px 0;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.diagram pre {
  margin: 0;
  padding: 6px 20px 18px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--ink-soft);
  white-space: pre;
}

/* mermaid renders its own SVG with fixed ink colors (see mermaid-init.js), so
   it gets a fixed light "drafting paper" ground rather than the theme
   tokens -- it reads the same whether the site is in light or dark mode,
   like a print pinned to the page rather than a themed UI element. */
.mermaid-card { background: #e2e7ea; border-color: #a9b5bd; }
.mermaid-inset {
  margin: 4px 14px 16px;
  padding: 14px 4px 6px;
  background: #eef1f3;
  border: 1px solid #c7d0d6;
  border-radius: 2px;
  overflow-x: auto;
  /* Mermaid's flowchart/subgraph labels render as HTML inside a
     foreignObject, not SVG <text> -- without an explicit color here they
     inherit the page's ambient `color`, which in dark mode is a pale ink
     tone. Pale text on this light card reads as dim, so pin it. */
  color: #172230;
}
.mermaid-inset pre { margin: 0; }
.mermaid-inset svg { display: block; margin: 0 auto; max-width: 100%; height: auto; }
.mermaid-inset foreignObject div, .mermaid-inset foreignObject span { color: #172230 !important; }

/* ---------- syntax-highlighted code blocks (Chroma) ---------- */
.highlight {
  max-width: 74ch;
  margin: 0 0 26px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper-raised);
  overflow-x: auto;
}
.highlight pre { margin: 0; padding: 14px 16px; font-family: var(--mono); font-size: 13px; line-height: 1.6; }
.highlight .c, .highlight .c1, .highlight .cm, .highlight .cs { color: var(--muted); font-style: italic; }
.highlight .k, .highlight .kc, .highlight .kd, .highlight .kn,
.highlight .kp, .highlight .kr, .highlight .kt { color: var(--copper-ink); font-weight: 600; }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sa,
.highlight .sb, .highlight .sc, .highlight .dl, .highlight .sd,
.highlight .se, .highlight .sh, .highlight .si, .highlight .sx, .highlight .ss { color: var(--ok); }
.highlight .m, .highlight .mb, .highlight .mf, .highlight .mh,
.highlight .mi, .highlight .il, .highlight .mo { color: var(--ok); }
.highlight .nf, .highlight .nc, .highlight .nn, .highlight .nb, .highlight .bp { color: var(--ink); }
.highlight .o, .highlight .ow, .highlight .p { color: var(--ink-soft); }
.highlight .err { color: var(--copper); }

/* ---------- pagination ---------- */
.pagination { max-width: 920px; margin: 10px auto 30px; padding: 0 20px; }
.pagination ul { list-style: none; display: flex; gap: 10px; padding: 0; margin: 0; font-family: var(--mono); font-size: 12.5px; }
.pagination a { color: var(--ink-soft); }
.pagination a:hover { color: var(--copper); }

/* ---------- footer ---------- */
footer.site {
  max-width: 920px;
  margin: 30px auto 60px;
  padding: 18px 20px 0;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
}
footer.site a { color: var(--muted); }
footer.site a:hover { color: var(--copper); }
.footer-links { display: flex; gap: 16px; align-items: center; }
#theme-toggle {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 3px 8px;
  cursor: pointer;
}
#theme-toggle:hover { color: var(--copper); border-color: var(--copper); }

@media (max-width: 560px) {
  .tb-grid { grid-template-columns: 1fr; }
  .tb-cell { border-left: none; border-top: 1px solid var(--line); }
  .tb-cell:first-child { border-top: none; }
  .index-row { grid-template-columns: 1fr; gap: 4px; }
  h1.post-title { font-size: 25px; }
  footer.site { flex-direction: column; gap: 10px; align-items: flex-start; }
}
