@font-face { font-family: 'JetBrains Mono'; src: url('/fonts/jetbrains-mono-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; src: url('/fonts/jetbrains-mono-latin-400-italic.woff2') format('woff2'); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; src: url('/fonts/jetbrains-mono-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-style: normal; font-display: swap; }

/* ---------- Tokens ---------- */
:root {
  --bg: #07090E;
  --surface: #0D1117;
  --surface-2: #121823;
  --line: #1E2533;
  --line-strong: #2A3346;
  --text: #E8EBF0;
  --muted: #8F98AB;            /* 6.9:1 on --bg */
  --accent: #6EE7A0;           /* phosphor green */
  --accent-hover: #B4F5CF;
  --accent-soft: rgba(110, 231, 160, 0.10);
  --star: #F5C451;             /* Procyon gold: cursor and live dot only */
  --err: #F87171;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --radius: 10px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur: 180ms;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 5rem; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--mono); font-size: 16px; line-height: 1.7;
  background-image: radial-gradient(ellipse 70% 40% at 50% -10%, rgba(110, 231, 160, 0.06), transparent 70%);
  background-repeat: no-repeat;
}
a { color: var(--accent); text-underline-offset: 3px; transition: color var(--dur) var(--ease); }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
main:focus { outline: none; }
.accent { color: var(--accent); }
.muted { color: var(--muted); }
h1, h2, h3 { text-wrap: balance; }

.skip-link {
  position: absolute; left: 16px; top: -100px; z-index: 100;
  background: var(--accent); color: var(--bg); padding: 10px 14px; border-radius: 6px; font-weight: 700; text-decoration: none;
}
.skip-link:focus { top: 16px; }

.site-header, main, .site-footer { max-width: 820px; margin: 0 auto; padding: 0 20px; }

/* ---------- Header ---------- */
.site-header { max-width: none; margin: 0; padding: 0; position: sticky; top: 0; z-index: 50; background: rgba(7, 9, 14, 0.82); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.header-inner { max-width: 820px; margin: 0 auto; padding: 16px 20px; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; }
.brand { display: inline-flex; align-items: center; gap: 12px; min-height: 44px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.25rem; letter-spacing: -0.03em; }
.brand:hover { color: var(--text); }
nav { display: flex; flex-wrap: wrap; gap: 4px; }
nav a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 10px; border-radius: 6px;
  color: var(--muted); text-decoration: none; transition: color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
nav a:hover { color: var(--accent); background: var(--surface); }
nav a[aria-current="page"] { color: var(--accent); }

/* ---------- Terminal window ---------- */
.term {
  margin: 56px 0 48px; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden;
  background: var(--surface);
  box-shadow: 0 0 0 1px rgba(110, 231, 160, 0.04), 0 30px 60px -30px rgba(0, 0, 0, 0.8), 0 0 80px -40px rgba(110, 231, 160, 0.25);
}
.term-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.dot { width: 11px; height: 11px; border-radius: 50%; background: var(--line-strong); }
.dot-live { background: var(--star); }
.dot-err { background: var(--err); }
.term-title { flex: 1; text-align: center; margin-right: 46px; font-size: 0.8rem; color: var(--muted); }
.term-body { position: relative; padding: 28px 28px 32px; }
.term-body::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 3px);
}
.term h1 { margin: 10px 0 14px; font-size: clamp(2.4rem, 9vw, 4.5rem); letter-spacing: -0.04em; line-height: 1; }
.glow { text-shadow: 0 0 24px rgba(110, 231, 160, 0.18); }
.prompt { margin: 0; color: var(--muted); }
.ps1 { color: var(--accent); }
.path { color: #7DD3FC; }
.out { margin: 0 0 6px; }
.out.err { color: var(--err); }
.cursor { display: inline-block; width: 0.6em; height: 1.1em; vertical-align: -0.2em; background: var(--star); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Post lists ---------- */
.section-title { font-size: 1rem; color: var(--muted); font-weight: 400; margin: 0 0 12px; }
.page-title { margin-top: 48px; }
.postlist { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.postlist li { border-bottom: 1px solid var(--line); }
.post-row {
  position: relative; display: grid; grid-template-columns: 7.5em minmax(0, 1fr); gap: 4px 16px;
  padding: 14px 12px 14px 24px; margin: 0 -12px; border-radius: 6px; text-decoration: none; color: var(--text);
  transition: background-color var(--dur) var(--ease);
}
.post-row::before { content: '>'; position: absolute; left: 6px; top: 14px; color: var(--accent); opacity: 0; transition: opacity var(--dur) var(--ease); }
.post-row:hover { background: var(--surface); color: var(--text); }
.post-row:hover::before, .post-row:focus-visible::before { opacity: 1; }
.post-row time { color: var(--muted); }
.post-title { color: var(--accent); font-weight: 700; }
.post-row:hover .post-title { color: var(--accent-hover); }
.post-summary { display: block; color: var(--muted); font-size: 0.9rem; }
.post-tags { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-top: 4px; font-size: 0.8rem; color: var(--muted); }
.post-tags a { color: var(--muted); text-decoration: none; }
.post-tags a:hover { color: var(--accent); }
.badge { display: inline-block; margin-left: 6px; padding: 0 6px; border: 1px solid var(--star); border-radius: 4px; color: var(--star); font-size: 0.7rem; font-weight: 400; vertical-align: 2px; }
.empty { padding: 16px 0; color: var(--muted); }
.more { margin: 16px 0 0; text-align: right; }

.taglist { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 10px; }
.taglist a { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 999px; text-decoration: none; transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease); }
.taglist a:hover { border-color: var(--accent); background: var(--accent-soft); }
.count { color: var(--muted); font-size: 0.8rem; }

/* ---------- Article ---------- */
.post-header { margin: 56px 0 32px; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.post-header h1 { font-size: clamp(1.8rem, 5vw, 2.5rem); letter-spacing: -0.03em; line-height: 1.2; margin: 6px 0 12px; }
.meta { margin: 0; color: var(--muted); font-size: 0.85rem; }
.prose { max-width: 72ch; }
.prose h2, .prose h3 { margin-top: 2em; line-height: 1.3; scroll-margin-top: 5rem; }
.prose h2::before { content: '## '; color: var(--accent); }
.prose h3::before { content: '### '; color: var(--accent); }
.prose img { max-width: 100%; height: auto; border-radius: 6px; border: 1px solid var(--line); }
.prose blockquote { margin: 1.5em 0; padding: 0.25em 1em; border-left: 3px solid var(--accent); color: var(--muted); background: var(--surface); border-radius: 0 6px 6px 0; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li::marker { color: var(--accent); }
code { font-family: var(--mono); background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 4px; font-size: 0.92em; }
pre { overflow-x: auto; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface) !important; font-size: 0.9rem; line-height: 1.6; }
pre code { background: none; padding: 0; }
table { border-collapse: collapse; display: block; overflow-x: auto; }
th, td { border: 1px solid var(--line); padding: 6px 12px; }
hr { border: 0; border-top: 1px dashed var(--line-strong); margin: 2em 0; }

/* ---------- Footer ---------- */
.site-footer { margin-top: 80px; padding-top: 24px; padding-bottom: 48px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.85rem; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; }
.site-footer p { margin: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  .term { margin: 32px 0; }
  .term-body { padding: 20px 16px 24px; }
  .term-title { margin-right: 0; text-align: right; }
  .post-row { grid-template-columns: 1fr; }
  .post-row time { font-size: 0.8rem; }
}

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

/* ---------- Vim-window code blocks ---------- */
.vimwin {
  margin: 1.8em 0; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden;
  background: var(--surface); box-shadow: 0 20px 40px -24px rgba(0, 0, 0, 0.8);
}
.vim-chrome { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.vim-dots { display: inline-flex; gap: 7px; }
.vim-dots i { width: 11px; height: 11px; border-radius: 50%; background: var(--line-strong); }
.vim-dots i.live { background: var(--accent); }
.vim-name { font-size: 0.8rem; color: var(--muted); }

.vim-code { overflow-x: auto; background: var(--surface); }
.vim-code .highlight, .vim-code .chroma { margin: 0; background: transparent; }
.vim-code .chroma { font-size: 0.88rem; line-height: 1.55; }
.vim-code table.lntable { border-spacing: 0; width: 100%; }
.vim-code table.lntable td.lntd { padding: 0; border: 0; vertical-align: top; }
.vim-code table.lntable td.lntd:first-child {
  width: 1%; white-space: nowrap; background: var(--bg);
  border-right: 1px solid var(--line); position: sticky; left: 0; z-index: 1;
}
.vim-code pre.chroma { margin: 0; padding: 14px 0; background: transparent; border: 0; border-radius: 0; }
.vim-code .lnt { color: #44506a; padding: 0 14px; }
.vim-code table.lntable td.lntd:last-child pre.chroma { padding-left: 16px; padding-right: 24px; }
.vim-code code { background: none; padding: 0; }

.vim-status {
  display: flex; align-items: center; font-size: 0.75rem; line-height: 1.6;
  background: var(--accent); color: #06281a;
}
.vim-status .vim-mode { font-weight: 700; padding: 2px 12px; background: #4fd389; letter-spacing: 0.05em; }
.vim-status .vim-status-name { padding: 2px 12px; }
.vim-status .vim-flex { flex: 1; }
.vim-status .vim-ft { padding: 2px 12px; opacity: 0.85; }
.vim-status .vim-loc { padding: 2px 12px; background: #4fd389; font-weight: 700; }

@media (max-width: 560px) {
  .vim-status .vim-status-name { display: none; }
  .vim-code .chroma { font-size: 0.8rem; }
}

/* ---------- Post layout with sticky TOC ---------- */
main.wide { max-width: 1140px; }
.post-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 56px; align-items: start; }
.post-layout.no-toc { grid-template-columns: minmax(0, 1fr); max-width: 820px; margin: 0 auto; }
.post-layout .post-header { margin-top: 0; }

.post-toc {
  position: sticky; top: 88px; align-self: start; max-height: calc(100vh - 112px);
  overflow-y: auto; font-family: var(--mono); font-size: 0.8rem; line-height: 1.5;
}
.toc-sig { padding: 2px 10px; white-space: nowrap; color: var(--muted); }
.toc-sig .kw { color: #ff7b72; }            /* keyword  */
.toc-sig .fn { color: #d2a8ff; text-decoration: none; }  /* fn name */
.toc-sig .fn:hover { text-decoration: underline; }
.toc-sig .pn { color: #8b949e; }            /* punctuation */
.toc-close { margin-top: 2px; }

.toc-body, .toc-sub { list-style: none; margin: 0; padding: 0; }
.toc-body > li > a, .toc-sub > li > a {
  display: grid; grid-template-columns: 2.1em 1fr; gap: 10px; align-items: baseline;
  padding: 3px 10px; color: var(--muted); text-decoration: none;
  border-left: 2px solid transparent;
  transition: color var(--dur) var(--ease), background-color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.toc-ln { color: #44506a; text-align: right; user-select: none; }
.toc-label { line-height: 1.35; }
.toc-sub > li > a { padding-left: 24px; }
.toc-sub .toc-label { opacity: 0.85; }
.post-toc a:hover { color: var(--text); background: var(--surface); }
.post-toc a.active { color: var(--accent); background: var(--accent-soft); border-left-color: var(--accent); }
.post-toc a.active .toc-ln { color: var(--accent); }

@media (max-width: 1023px) {
  main.wide { max-width: 820px; }
  .post-layout { grid-template-columns: 1fr; gap: 0; }
  .post-toc { display: none; }
}
