:root {
  --bg: #0a0e12;
  --surface: #10161d;
  --surface-2: #141c25;
  --border: #1c2530;
  --grid: rgba(91, 228, 155, 0.045);
  --text: #d6dee6;
  --text-dim: #76828e;
  --text-faint: #4d5762;
  --accent: #5be49b;
  --accent-2: #58c7f3;
  --accent-dim: #1f5f40;
  --accent-glow: rgba(91, 228, 155, 0.07);
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --serif: 'Newsreader', Georgia, 'Times New Roman', serif;
  --max: min(1000px, 94vw);
}

/* per-category hues, assigned by build.py */
.hue-0 { --c: #5be49b; --c-soft: rgba(91,228,155,0.10); --c-border: rgba(91,228,155,0.45); }
.hue-1 { --c: #58c7f3; --c-soft: rgba(88,199,243,0.10); --c-border: rgba(88,199,243,0.45); }
.hue-2 { --c: #f5b759; --c-soft: rgba(245,183,89,0.10); --c-border: rgba(245,183,89,0.45); }
.hue-3 { --c: #b18cff; --c-soft: rgba(177,140,255,0.10); --c-border: rgba(177,140,255,0.45); }
.hue-4 { --c: #ff8d7e; --c-soft: rgba(255,141,126,0.10); --c-border: rgba(255,141,126,0.45); }

* { box-sizing: border-box; }

html { color-scheme: dark; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- Animated background (CSS only) ---------- */
html::before {
  content: "";
  position: fixed;
  inset: -42px;
  z-index: -3;
  pointer-events: none;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 42px 42px;
  -webkit-mask-image: radial-gradient(ellipse 120% 90% at 50% -10%, black 30%, transparent 75%);
  mask-image: radial-gradient(ellipse 120% 90% at 50% -10%, black 30%, transparent 75%);
  animation: grid-pan 70s linear infinite;
}
@keyframes grid-pan {
  to { transform: translate(42px, 42px); }
}

html::after {
  content: "";
  position: fixed;
  left: 0; right: 0;
  top: -10%;
  height: 140px;
  z-index: -2;
  pointer-events: none;
  background: linear-gradient(180deg, transparent, rgba(91, 228, 155, 0.035), transparent);
  animation: scan 14s linear infinite;
}
@keyframes scan {
  from { top: -12%; }
  to { top: 112%; }
}

body::before, body::after {
  content: "";
  position: fixed;
  z-index: -2;
  pointer-events: none;
  border-radius: 50%;
  filter: blur(70px);
}
body::before {
  width: 55vmax; height: 55vmax;
  top: -22vmax; right: -18vmax;
  background: radial-gradient(circle, rgba(91, 228, 155, 0.10), transparent 62%);
  animation: drift-a 26s ease-in-out infinite alternate;
}
body::after {
  width: 48vmax; height: 48vmax;
  bottom: -24vmax; left: -16vmax;
  background: radial-gradient(circle, rgba(88, 199, 243, 0.08), transparent 62%);
  animation: drift-b 32s ease-in-out infinite alternate;
}
@keyframes drift-a {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(-8vmax, 7vmax) scale(1.15); }
}
@keyframes drift-b {
  from { transform: translate(0, 0) scale(1.1); }
  to   { transform: translate(9vmax, -6vmax) scale(0.95); }
}

::selection { background: var(--accent-dim); color: #eafff3; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

h1, h2, h3 { text-wrap: balance; }

.wrap { max-width: var(--max); margin: 0 auto; padding: 0 28px; }

/* ---------- Header ---------- */
header.site {
  border-bottom: 1px solid var(--border);
  padding: 20px 0;
  background: rgba(10, 14, 18, 0.78);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}
header.site .wrap { display: flex; justify-content: space-between; align-items: center; gap: 16px; }

.site-title {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.site-title:hover { text-decoration: none; color: var(--accent); }
.site-title .dot { color: var(--accent); }

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.site-nav { display: flex; gap: 22px; font-family: var(--mono); font-size: 13px; }
.site-nav a { color: var(--text-dim); }
.site-nav a:hover { color: var(--accent); text-decoration: none; }
.site-nav a.active { color: var(--text); }
.site-nav a.active::before { content: "> "; color: var(--accent); }

/* ---------- Hero ---------- */
.hero { padding: 72px 0 48px; border-bottom: 1px solid var(--border); }

.prompt-line {
  font-family: var(--mono);
  font-size: 13.5px;
  color: var(--text-dim);
  margin-bottom: 26px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5ch;
}
.prompt-line .user { color: var(--accent); }
.prompt-line .path { color: var(--text-dim); }
.prompt-line .cmd { color: var(--text); }
.cursor {
  display: inline-block;
  width: 8px; height: 17px;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.hero h1 {
  font-size: clamp(34px, 5.5vw, 50px);
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -0.015em;
  margin: 0 0 18px;
  max-width: 18ch;
}
.hero h1 em {
  font-style: italic;
  background: linear-gradient(92deg, var(--accent) 20%, var(--accent-2) 85%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero p.lede {
  color: var(--text-dim);
  font-size: 19px;
  max-width: 54ch;
  margin: 0 0 36px;
}

.hero-actions { display: flex; gap: 14px; align-items: center; font-family: var(--mono); font-size: 13px; margin-bottom: 52px; flex-wrap: wrap; }
.hero-actions a.button {
  border: 1px solid var(--accent-dim);
  background: var(--accent-glow);
  color: var(--accent);
  padding: 10px 18px;
  border-radius: 5px;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}
.hero-actions a.button:hover { border-color: var(--accent); background: rgba(91, 228, 155, 0.13); text-decoration: none; transform: translateY(-1px); }
.hero-actions a.text-link { color: var(--text-dim); padding: 10px 4px; }
.hero-actions a.text-link:hover { color: var(--accent); text-decoration: none; }
.hero-actions a.text-link::after { content: " ->"; }

/* System readout stats */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(16, 22, 29, 0.75);
  backdrop-filter: blur(4px);
  overflow: hidden;
}
.stats > div {
  padding: 18px 20px;
  border-left: 1px solid var(--border);
  position: relative;
}
.stats > div::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--c, var(--accent));
  opacity: 0.65;
}
.stats > div:first-child { border-left: none; }
.stat-num {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 700;
  color: var(--c, var(--text));
  line-height: 1.1;
}
.stat-num .unit { font-size: 14px; color: var(--text-dim); font-weight: 400; }
.stat-label {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin-top: 7px;
}

/* ---------- Topics ---------- */
.topics { padding: 40px 0; border-bottom: 1px solid var(--border); }
.kicker {
  font-family: var(--mono);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-faint);
  margin: 0 0 18px;
  font-weight: 500;
}
.kicker::before { content: "// "; color: var(--accent-dim); }

.topic-list { display: flex; flex-wrap: wrap; gap: 9px; list-style: none; padding: 0; margin: 0; }
.topic-list a {
  font-family: var(--mono);
  font-size: 12.5px;
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 7px 14px 7px 11px;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.topic-list a::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--c, var(--accent));
}
.topic-list a:hover {
  border-color: var(--c-border, var(--accent-dim));
  color: var(--c, var(--accent));
  background: var(--c-soft, var(--accent-glow));
  text-decoration: none;
}
.topic-list .count { color: var(--text-faint); }

/* ---------- Post list ---------- */
main { padding: 0 0 88px; }
.section-head { margin: 56px 0 12px; }

.post-list { list-style: none; margin: 0; padding: 0; }
.post-list li {
  border-bottom: 1px solid var(--border);
  padding: 30px 0 30px 20px;
  margin-left: -20px;
  border-left: 2px solid transparent;
  transition: border-left-color 0.15s ease, background 0.15s ease;
}
.post-list li:hover {
  border-left-color: var(--c, var(--accent));
  background: linear-gradient(90deg, var(--c-soft, var(--accent-glow)), transparent 45%);
}

.post-meta {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-faint);
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
  letter-spacing: 0.04em;
}

.tag {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  padding: 3px 9px;
  border: 1px solid var(--c-border, var(--accent-dim));
  color: var(--c, var(--accent));
  background: var(--c-soft, transparent);
  border-radius: 4px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.post-list h2 {
  margin: 0 0 8px;
  font-size: 27px;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.post-list h2 a { color: var(--text); }
.post-list h2 a:hover { color: var(--c, var(--accent)); text-decoration: none; }

.post-excerpt { color: var(--text-dim); font-size: 16.5px; margin: 0; line-height: 1.65; }

/* ---------- Single post ---------- */
article.post { padding-top: 56px; }

article.post h1 {
  font-size: clamp(30px, 4.5vw, 40px);
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: -0.015em;
  margin: 14px 0 16px;
}

article.post > .post-meta { margin-bottom: 44px; }

article.post h2 {
  font-family: var(--mono);
  font-size: 19px;
  font-weight: 700;
  margin: 2.4em 0 0.7em;
  color: var(--text);
}
article.post h2::before { content: "## "; color: var(--accent-dim); font-weight: 400; }
article.post h3 {
  font-family: var(--mono);
  font-size: 15.5px;
  font-weight: 700;
  margin: 2em 0 0.6em;
  color: var(--text);
}
article.post h3::before { content: "### "; color: var(--accent-dim); font-weight: 400; }

article.post p, article.post ul, article.post ol { font-size: 19px; }
article.post li { margin-bottom: 0.35em; }
article.post ul li::marker { color: var(--accent-dim); }

article.post code {
  font-family: var(--mono);
  font-size: 0.82em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.12em 0.45em;
  border-radius: 4px;
  color: #a8e6c3;
}

article.post .codeblock {
  margin: 1.6em 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
article.post .codeblock .lang-bar {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  padding: 7px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
article.post .codeblock .lang-bar::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent-dim);
}
article.post .codeblock pre {
  margin: 0;
  padding: 16px 18px;
  overflow-x: auto;
}
article.post .codeblock code {
  background: none; border: none; padding: 0;
  font-size: 13.5px; line-height: 1.65;
  color: var(--text);
}

article.post blockquote {
  border-left: 2px solid var(--accent-dim);
  margin: 1.6em 0;
  padding: 0.2em 0 0.2em 20px;
  color: var(--text-dim);
  font-style: italic;
}

article.post img {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
}

article.post .callout {
  display: flex;
  gap: 12px;
  border: 1px solid var(--accent-dim);
  background: var(--accent-glow);
  border-radius: 8px;
  padding: 15px 18px;
  font-size: 15px;
  font-family: var(--mono);
  line-height: 1.6;
  margin: 1.6em 0;
}
article.post .callout::before {
  content: "!";
  flex-shrink: 0;
  width: 20px; height: 20px;
  border: 1px solid var(--accent);
  border-radius: 50%;
  color: var(--accent);
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

.back-link {
  display: inline-block;
  margin-top: 60px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-dim);
}
.back-link:hover { color: var(--accent); text-decoration: none; }

/* ---------- Footer ---------- */
footer.site {
  border-top: 1px solid var(--border);
  padding: 36px 0;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-faint);
}
footer.site .prompt { color: var(--accent-dim); margin-right: 1ch; }

/* ---------- Motion and small screens ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  html::before, html::after, body::before, body::after,
  .cursor, .status-dot { animation: none; }
  html::after { display: none; }
  * { transition: none !important; }
}

@media (max-width: 640px) {
  body { font-size: 17.5px; }
  .hero { padding: 48px 0 36px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stats > div:nth-child(3) { border-left: none; }
  .stats > div:nth-child(n+3) { border-top: 1px solid var(--border); }
  .post-list li { padding-left: 14px; margin-left: -14px; }
  .post-list h2 { font-size: 23px; }
  article.post p, article.post ul, article.post ol { font-size: 17.5px; }
}

/* ---------- Data rain (markup generated by build.py) ---------- */
.bg-rain {
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  overflow: hidden;
}
.bg-rain span {
  position: absolute;
  top: -45%;
  font-family: var(--mono);
  line-height: 1.7;
  white-space: pre;
  color: var(--accent);
  text-shadow: 0 0 8px rgba(91, 228, 155, 0.35);
  animation: rain-fall linear infinite;
  will-change: transform;
}
.bg-rain span.rain-alt {
  color: var(--accent-2);
  text-shadow: 0 0 8px rgba(88, 199, 243, 0.35);
}
@keyframes rain-fall {
  to { transform: translateY(250vh); }
}

/* ---------- Animated 5-hue rule under the hero ---------- */
.hero { border-bottom: none; position: relative; }
.hero::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 1px;
  background: linear-gradient(90deg,
    #5be49b, #58c7f3, #b18cff, #f5b759, #ff8d7e, #5be49b);
  background-size: 250% 100%;
  opacity: 0.55;
  animation: hue-shift 16s linear infinite;
}
@keyframes hue-shift {
  to { background-position: 250% 0; }
}

/* ---------- More colour at rest on the index ---------- */
.topic-list a {
  color: var(--c, var(--text-dim));
  border-color: color-mix(in srgb, var(--c, var(--accent)) 30%, var(--border));
  background: color-mix(in srgb, var(--c, var(--accent)) 5%, transparent);
}
.topic-list a:hover {
  border-color: var(--c-border, var(--accent-dim));
  background: var(--c-soft, var(--accent-glow));
}
.topic-list .count { color: color-mix(in srgb, var(--c, var(--accent)) 55%, var(--text-faint)); }

.post-meta .mid { color: var(--c, var(--accent-dim)); }

.badge-new {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #0a0e12;
  background: var(--accent);
  padding: 2px 7px;
  border-radius: 3px;
  animation: badge-pulse 2.2s ease-in-out infinite;
}
@keyframes badge-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(91, 228, 155, 0.45); }
  55% { box-shadow: 0 0 0 6px rgba(91, 228, 155, 0); }
}

/* ---------- Motion & small-screen overrides for new layers ---------- */
@media (prefers-reduced-motion: reduce) {
  .bg-rain { display: none; }
  .hero::after, .badge-new { animation: none; }
}
@media (max-width: 640px) {
  .bg-rain span:nth-child(even) { display: none; }
}

/* ---------- Light theme ---------- */
:root {
  --header-bg: rgba(10, 14, 18, 0.78);
  --panel-bg: rgba(16, 22, 29, 0.75);
  --code-text: #a8e6c3;
  --sel-bg: var(--accent-dim);
  --sel-fg: #eafff3;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f8f7;
  --surface: #ffffff;
  --surface-2: #edf2ef;
  --border: #dce4df;
  --grid: rgba(15, 122, 71, 0.07);
  --text: #1d2730;
  --text-dim: #57636e;
  --text-faint: #8b959e;
  --accent: #0f7a47;
  --accent-2: #0b6aa8;
  --accent-dim: #8fcbaa;
  --accent-glow: rgba(15, 122, 71, 0.07);
  --header-bg: rgba(246, 248, 247, 0.82);
  --panel-bg: rgba(255, 255, 255, 0.75);
  --code-text: #0b5e38;
  --sel-bg: #bfe6d0;
  --sel-fg: #06291a;
}

html[data-theme="light"] .hue-0 { --c: #0f7a47; --c-soft: rgba(15,122,71,0.08);  --c-border: rgba(15,122,71,0.45); }
html[data-theme="light"] .hue-1 { --c: #0b6aa8; --c-soft: rgba(11,106,168,0.08); --c-border: rgba(11,106,168,0.45); }
html[data-theme="light"] .hue-2 { --c: #9c6605; --c-soft: rgba(156,102,5,0.08);  --c-border: rgba(156,102,5,0.45); }
html[data-theme="light"] .hue-3 { --c: #6d4fc4; --c-soft: rgba(109,79,196,0.08); --c-border: rgba(109,79,196,0.45); }
html[data-theme="light"] .hue-4 { --c: #c2503f; --c-soft: rgba(194,80,63,0.08);  --c-border: rgba(194,80,63,0.45); }

html[data-theme="light"] .hero h1 em {
  background: linear-gradient(92deg, #0f7a47 20%, #0b6aa8 85%);
  -webkit-background-clip: text;
  background-clip: text;
}
html[data-theme="light"] .hero::after {
  background: linear-gradient(90deg,
    #0f7a47, #0b6aa8, #6d4fc4, #9c6605, #c2503f, #0f7a47);
  background-size: 250% 100%;
}
html[data-theme="light"] .bg-rain span { text-shadow: none; }
html[data-theme="light"] body::before {
  background: radial-gradient(circle, rgba(15, 122, 71, 0.07), transparent 62%);
}
html[data-theme="light"] body::after {
  background: radial-gradient(circle, rgba(11, 106, 168, 0.06), transparent 62%);
}

::selection { background: var(--sel-bg); color: var(--sel-fg); }
header.site { background: var(--header-bg); }
.stats { background: var(--panel-bg); }
article.post code { color: var(--code-text); }
.badge-new { color: var(--bg); }

/* ---------- Theme toggle button ---------- */
.theme-btn {
  font-family: var(--mono);
  font-size: 12px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--text-dim);
  padding: 5px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.theme-btn:hover { border-color: var(--accent-dim); color: var(--accent); }
.theme-btn .sw {
  width: 9px; height: 9px;
  border-radius: 50%;
  border: 1px solid currentColor;
  background: linear-gradient(90deg, currentColor 50%, transparent 50%);
}
