/*
  RafaX stylesheet
  VOICE    a researcher's terminal: precise, calm, no ornament
  IDEA     a shell log turned magazine: raw markdown shows up as decoration (##, $, cd ..)
  PICTURE  live ASCII flames at the top, in the theme colours
  COLOUR   light = white paper + blue; dark = pure black + grey-green
  TYPE     IBM Plex Mono (brand, headings, code) + Source Serif 4 (long reading)
  LAYOUT   68ch reading column, dates hanging on the left in the list
*/

/* ---------- tokens ---------- */
:root,
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f4f7fc;
  --ink: #0f1626;
  --ink-2: #2b3445;
  --muted: #5d6779;
  --rule: #e2e8f2;
  --accent: #1d4ed8;
  --accent-strong: #0b2b85;
  --accent-soft: #e9f0ff;
  --selection: #c9dafd;

  --flame-1: #e4ecfd;
  --flame-2: #b7ccf7;
  --flame-3: #7ea4ee;
  --flame-4: #3d72e0;
  --flame-5: #1d4ed8;
  --flame-6: #0b2470;

  /* code highlighting */
  --c-comment: #8792a6;
  --c-keyword: #1d4ed8;
  --c-string: #0f7a6c;
  --c-number: #b2560a;
  --c-func: #0f1626;
  --c-attr: #0a66a3;
  --c-del: #b42318;
  --c-ins: #13803d;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --surface: #0a0d0b;
  --ink: #d8dfda;
  --ink-2: #b9c2bc;
  --muted: #84918a;
  --rule: #1c231f;
  --accent: #9db6a7;
  --accent-strong: #d1e4d8;
  --accent-soft: #111914;
  --selection: #2c3d33;

  --flame-1: #18201b;
  --flame-2: #2e3d34;
  --flame-3: #55695d;
  --flame-4: #84a090;
  --flame-5: #b4cdbe;
  --flame-6: #eefaf2;

  --c-comment: #5f6c65;
  --c-keyword: #9db6a7;
  --c-string: #d3c89c;
  --c-number: #cda6a2;
  --c-func: #eef3ef;
  --c-attr: #93b4c3;
  --c-del: #d8908a;
  --c-ins: #a3c9aa;
}

:root {
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --serif: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --wrap: 1120px;
  --read: 68ch;
  --radius: 6px;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; min-width: 0; }
html { scroll-padding-top: 80px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 17px/1.65 var(--serif);
  overflow-x: clip;
  transition: background-color .25s ease, color .25s ease;
}
::selection { background: var(--selection); }
a { color: var(--accent); text-underline-offset: .18em; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-strong); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
img { max-width: 100%; height: auto; }
.wrap { width: 100%; max-width: var(--wrap); margin-inline: auto; padding-inline: max(4vw, 18px); }
.dim { color: var(--muted); }
.skip {
  position: absolute; left: 12px; top: -60px; z-index: 50;
  background: var(--accent); color: var(--bg); padding: 8px 14px;
  font: 500 14px var(--mono); border-radius: var(--radius);
}
.skip:focus { top: 12px; }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; flex-wrap: wrap; }
.brand {
  font: 600 17px/1 var(--mono); color: var(--ink); text-decoration: none; letter-spacing: -.01em;
  display: inline-flex; align-items: center;
}
.brand:hover { color: var(--ink); }
.brand-prompt { color: var(--accent); }
.brand-caret {
  display: inline-block; width: .55em; height: 1.05em; margin-left: 3px;
  background: var(--accent); transform: translateY(1px);
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.site-nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font: 500 14px/1 var(--mono); }
.site-nav a {
  color: var(--muted); text-decoration: none; padding: 10px 10px; border-radius: var(--radius);
}
.site-nav a:hover { color: var(--ink); background: var(--accent-soft); }
.site-nav a[aria-current="page"] { color: var(--accent); }
.site-nav a[aria-current="page"]::before { content: "> "; }
.theme-toggle {
  display: grid; place-items: center; width: 40px; height: 40px; margin-left: 6px;
  border: 1px solid var(--rule); border-radius: 50%;
  background: transparent; color: var(--ink); cursor: pointer;
  transition: border-color .2s, background-color .2s;
}
.theme-toggle:hover { border-color: var(--accent); background: var(--accent-soft); }
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.theme-toggle .icon-moon { fill: currentColor; stroke: none; }
:root[data-theme="dark"] .icon-moon,
:root[data-theme="light"] .icon-sun { display: none; }

/* ---------- hero with flames ---------- */
.hero {
  position: relative;
  height: clamp(380px, 64vh, 640px);
  overflow: hidden;
  border-bottom: 1px solid var(--accent);
  cursor: crosshair;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.flame-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* smaller fire band above the footer (articles and about pages) */
.flame-band {
  position: relative;
  height: clamp(150px, 24vh, 230px);
  margin-top: clamp(40px, 6vw, 72px);
  overflow: hidden;
  cursor: crosshair;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.flame-band + .site-footer { margin-top: 0; border-top-color: var(--accent); }
.hero-inner { position: relative; z-index: 1; padding-top: clamp(40px, 9vh, 96px); pointer-events: none; }
.hero-title {
  margin: 0;
  font: 700 clamp(72px, 15vw, 196px)/.86 var(--mono);
  letter-spacing: -.065em;
  color: var(--ink);
  text-shadow: 0 0 28px var(--bg), 0 0 2px var(--bg);
}
.hero-tagline {
  margin: 18px 0 0; max-width: 34ch;
  font: 400 clamp(17px, 1.6vw, 20px)/1.45 var(--serif);
  color: var(--ink-2);
  text-shadow: 0 0 14px var(--bg), 0 0 4px var(--bg);
}

/* ---------- home ---------- */
.home-body { padding-block: clamp(36px, 6vw, 72px) 24px; }
.home-section + .home-section { margin-top: clamp(48px, 7vw, 88px); }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  padding-bottom: 14px; border-bottom: 1px solid var(--rule);
}
.section-head h2 { margin: 0; font: 600 22px/1.2 var(--mono); letter-spacing: -.02em; }
.section-head h2::before { content: "## "; color: var(--accent); }
.more { font: 500 14px var(--mono); text-decoration: none; white-space: nowrap; }
.more:hover { text-decoration: underline; }
.empty { color: var(--muted); font-style: italic; }

/* ---------- article list ---------- */
.post-list { list-style: none; margin: 0; padding: 0; }
.post-item {
  display: grid; grid-template-columns: 8.5em minmax(0, 1fr); gap: 4px 28px;
  padding: 26px 0; border-bottom: 1px solid var(--rule);
}
.post-date { font: 400 14px/1.9 var(--mono); color: var(--muted); white-space: nowrap; }
.post-title { margin: 0; font: 600 21px/1.3 var(--mono); letter-spacing: -.02em; text-wrap: balance; }
.post-title a { color: var(--ink); text-decoration: none; background: linear-gradient(var(--accent), var(--accent)) 0 100% / 0 1px no-repeat; transition: background-size .25s ease, color .2s; }
.post-title a:hover { color: var(--accent); background-size: 100% 1px; }
.post-excerpt { margin: 8px 0 0; color: var(--ink-2); max-width: var(--read); }
.post-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 12px 0 0; font: 400 13px/1.4 var(--mono); color: var(--muted); }
.tag { color: var(--accent); }

/* ---------- article ---------- */
.article { padding-block: clamp(36px, 6vw, 72px) 32px; }
.article-head, .prose, .article-nav { max-width: var(--read); margin-inline: auto; }
.article-head { margin-bottom: 40px; padding-bottom: 28px; border-bottom: 1px solid var(--rule); }
.back { display: inline-block; margin-bottom: 22px; font: 500 14px var(--mono); text-decoration: none; color: var(--muted); }
.back::before { content: "$ "; color: var(--accent); }
.back:hover { color: var(--accent); }
.article-title {
  margin: 0; font: 700 clamp(32px, 5vw, 50px)/1.08 var(--mono);
  letter-spacing: -.04em; text-wrap: balance;
}
.article-lede { margin: 16px 0 0; font-size: 20px; line-height: 1.5; color: var(--ink-2); }
.article-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 20px 0 0; font: 400 13px/1.4 var(--mono); color: var(--muted); }
.sev { padding: 2px 8px; border-radius: 4px; font-weight: 600; border: 1px solid currentColor; }
.sev-critical { color: #d92d20; }
.sev-high { color: #e8590c; }
.sev-medium { color: #b7791f; }
.sev-low { color: var(--accent); }

/* ---------- prose (markdown) ---------- */
.prose { font-size: 18px; line-height: 1.72; color: var(--ink); overflow-wrap: break-word; }
.prose > * + * { margin-top: 1.15em; }
.prose > :first-child { margin-top: 0; }
.prose p, .prose ul, .prose ol, .prose blockquote, .prose table, .prose pre { margin-bottom: 0; }
.prose h2, .prose h3, .prose h4 {
  position: relative; font-family: var(--mono); letter-spacing: -.02em; line-height: 1.25;
  margin: 2.1em 0 0; text-wrap: balance;
}
.prose h2 { font-size: 26px; font-weight: 600; }
.prose h3 { font-size: 20px; font-weight: 600; }
.prose h4 { font-size: 17px; font-weight: 600; color: var(--ink-2); }
.prose h2::before { content: "## "; color: var(--accent); }
.prose h3::before { content: "### "; color: var(--accent); opacity: .75; }
.prose .anchor { margin-left: .4em; color: var(--muted); text-decoration: none; opacity: 0; transition: opacity .15s; font-weight: 400; }
.prose h2:hover .anchor, .prose h3:hover .anchor, .prose .anchor:focus { opacity: 1; }
.prose strong { font-weight: 600; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li + li { margin-top: .4em; }
.prose ul li::marker { content: "•  "; color: var(--accent); }
.prose ol li::marker { color: var(--accent); font: 500 .85em var(--mono); }
.prose blockquote {
  margin-left: 0; margin-right: 0; padding: 4px 0 4px 22px;
  border-left: 2px solid var(--accent); color: var(--ink-2); font-style: italic;
}
.prose hr { border: 0; margin: 2.6em 0; text-align: center; height: auto; }
.prose hr::after { content: "* * *"; font: 500 15px var(--mono); color: var(--muted); letter-spacing: .6em; }
.prose img { display: block; margin-inline: auto; border-radius: var(--radius); border: 1px solid var(--rule); }
.prose figure { margin: 2em 0 0; }
.article-cover { display: block; max-width: var(--read); width: 100%; margin: 0 auto 40px; border-radius: var(--radius); border: 1px solid var(--rule); }
.prose .video { position: relative; aspect-ratio: 16 / 9; margin: 1.6em 0; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--rule); background: #000; }
.prose .video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.prose figcaption, .prose img + em { display: block; margin-top: 10px; text-align: center; font: 400 13px var(--mono); color: var(--muted); font-style: normal; }
.prose kbd {
  font: 500 .78em var(--mono); padding: 2px 6px; border-radius: 4px;
  border: 1px solid var(--rule); border-bottom-width: 2px; background: var(--surface);
}
.prose mark { background: var(--accent-soft); color: var(--accent-strong); padding: 0 3px; border-radius: 3px; }

/* inline code */
.prose :not(pre) > code {
  font: 500 .84em var(--mono); padding: .12em .38em; border-radius: 4px;
  background: var(--accent-soft); color: var(--accent-strong); overflow-wrap: anywhere;
}

/* code blocks */
.code-block { position: relative; }
.prose div.highlighter-rouge, .prose figure.highlight { margin-top: 1.5em; }
.prose pre {
  margin: 0; padding: 44px 20px 18px; overflow-x: auto;
  font: 400 14px/1.65 var(--mono); tab-size: 4;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
}
.prose pre code { font: inherit; background: none; padding: 0; color: var(--ink); }
.code-bar {
  position: absolute; inset: 0 0 auto 0; height: 34px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 0 8px 0 16px; border-bottom: 1px solid var(--rule);
  font: 400 12px/1 var(--mono); color: var(--muted);
  pointer-events: none;
}
.code-lang::before { content: "▍"; color: var(--accent); margin-right: 4px; }
.code-copy {
  pointer-events: auto; font: 500 12px/1 var(--mono); color: var(--muted);
  background: transparent; border: 0; border-radius: 4px; padding: 7px 9px; cursor: pointer;
}
.code-copy:hover { color: var(--accent); background: var(--accent-soft); }
.code-copy[data-state="done"] { color: var(--accent); }

/* tables */
.table-scroll { overflow-x: auto; margin-top: 1.5em; border: 1px solid var(--rule); border-radius: var(--radius); }
.prose table { width: 100%; border-collapse: collapse; font-size: 15px; line-height: 1.5; margin: 0; }
.prose th {
  text-align: left; font: 600 13px/1.4 var(--mono); color: var(--muted);
  background: var(--surface); border-bottom: 1px solid var(--rule); padding: 10px 14px; white-space: nowrap;
}
.prose td { padding: 10px 14px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.prose tr:last-child td { border-bottom: 0; }

/* rouge */
.highlight .c, .highlight .c1, .highlight .cm, .highlight .cs, .highlight .cp, .highlight .ch, .highlight .cd { color: var(--c-comment); font-style: italic; }
.highlight .k, .highlight .kd, .highlight .kn, .highlight .kp, .highlight .kr, .highlight .kt, .highlight .kc, .highlight .ow { color: var(--c-keyword); font-weight: 500; }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sb, .highlight .sc, .highlight .sd, .highlight .se, .highlight .sh, .highlight .si, .highlight .sx, .highlight .sr, .highlight .ss, .highlight .dl { color: var(--c-string); }
.highlight .m, .highlight .mi, .highlight .mf, .highlight .mh, .highlight .mo, .highlight .il, .highlight .mb { color: var(--c-number); }
.highlight .nf, .highlight .fm, .highlight .nc, .highlight .nn { color: var(--c-func); font-weight: 600; }
.highlight .na, .highlight .nt, .highlight .nb, .highlight .bp, .highlight .nv, .highlight .vi, .highlight .vg, .highlight .py { color: var(--c-attr); }
.highlight .o, .highlight .p { color: var(--ink-2); }
.highlight .gd { color: var(--c-del); background: color-mix(in srgb, var(--c-del) 10%, transparent); }
.highlight .gi { color: var(--c-ins); background: color-mix(in srgb, var(--c-ins) 10%, transparent); }
.highlight .gh, .highlight .gu { color: var(--accent); font-weight: 600; }
.highlight .err { color: var(--c-del); }
.highlight .gp { color: var(--accent); user-select: none; }

/* navigation between articles */
.article-nav {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px;
  margin-top: 64px; padding-top: 28px; border-top: 1px solid var(--rule);
}
.article-nav a { display: flex; flex-direction: column; gap: 6px; text-decoration: none; font: 600 16px/1.35 var(--mono); color: var(--ink); }
.article-nav a:hover { color: var(--accent); }
.article-nav .dim { font-weight: 400; font-size: 12px; }
.article-nav .next { text-align: right; grid-column: 2; }

/* archive */
.archive-year { margin: 48px 0 0; font: 600 15px var(--mono); color: var(--muted); }
.archive-year:first-of-type { margin-top: 0; }

/* ---------- footer ---------- */
.site-footer { margin-top: clamp(56px, 8vw, 96px); border-top: 1px solid var(--rule); }
.footer-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; flex-wrap: wrap; padding-block: 32px 40px; }
.footer-sig { margin: 0; font: 400 14px/1.7 var(--mono); }
.footer-sig strong { font-weight: 600; }
.footer-links { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 18px; font: 500 14px var(--mono); }
.footer-links a { color: var(--muted); text-decoration: none; display: inline-block; padding: 6px 0; }
.footer-links a:hover { color: var(--accent); }

/* ---------- 404 ---------- */
.notfound pre { font: 400 14px/1.4 var(--mono); color: var(--accent); background: none; border: 0; padding: 0; }

/* ---------- narrow screens ---------- */
@media (max-width: 680px) {
  body { font-size: 16px; }
  .header-row { flex-wrap: nowrap; min-height: 56px; }
  .brand { font-size: 16px; }
  .site-nav { gap: 0; flex-wrap: nowrap; font-size: 13px; }
  .site-nav a { padding: 12px 7px; }
  .site-nav a[aria-current="page"]::before { content: ""; }
  .theme-toggle { margin-left: 4px; }
  .post-item { grid-template-columns: minmax(0, 1fr); gap: 6px; padding: 22px 0; }
  .post-date { font-size: 13px; line-height: 1.4; }
  .post-title { font-size: 19px; }
  .prose { font-size: 17px; }
  .prose h2 { font-size: 22px; }
  .prose pre { font-size: 13px; padding-inline: 14px; }
  .article-nav { grid-template-columns: minmax(0, 1fr); }
  .article-nav .next { grid-column: 1; text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .brand-caret { opacity: 1; }
}
