/* ---- blog post shared stylesheet ---- */

:root {
  --bg:        #14161c;
  --surface:   #1b1e26;
  --surface-2: #21252f;
  --ink:       #e6e9ef;
  --muted:     #8b93a7;
  --faint:     #5b6275;
  --line:      #2a2e3a;
  --accent:    #ffb454; /* string / keyword amber */
  --blue:      #6cb6ff; /* function / link */
  --purple:    #c490f5; /* keyword */
  --green:     #82d99a; /* string */
  --red:       #ff7b72; /* error */

  --display: "Space Grotesk", system-ui, sans-serif;
  --body:    "Newsreader", Georgia, serif;
  --mono:    "JetBrains Mono", ui-monospace, monospace;

  --gutter: 64px;
  --maxw: 720px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 19px;
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
  /* faint grid like graph/blueprint paper */
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 28px 28px;
  background-position: -1px -1px;
}
/* dim the grid so it's atmosphere, not noise */
body::before {
  content: "";
  position: fixed; inset: 0;
  background: radial-gradient(120% 90% at 50% -10%, transparent 30%, var(--bg) 78%);
  pointer-events: none; z-index: 0;
}

/* ---- reading progress ---- */
#progress {
  position: fixed; top: 0; left: 0; height: 2px; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--blue));
  z-index: 50; transition: width .08s linear;
}

/* ---- top nav ---- */
header.site {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px clamp(20px, 5vw, 56px);
  backdrop-filter: blur(10px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; text-decoration: none; }
.brand .mark {
  font-family: var(--mono); font-weight: 600; color: var(--accent);
  font-size: 18px; letter-spacing: -.5px;
}
.brand .name {
  font-family: var(--display); font-weight: 600; color: var(--ink);
  font-size: 18px; letter-spacing: -.3px;
}
.brand .name b { color: var(--blue); font-weight: 600; }
nav.site { display: flex; gap: 26px; align-items: center; }
nav.site a {
  font-family: var(--mono); font-size: 13px; color: var(--muted);
  text-decoration: none; letter-spacing: .2px; transition: color .15s;
}
nav.site a:hover, nav.site a:focus-visible { color: var(--accent); }
nav.site .sep { color: var(--faint); }
nav.site a.current { color: var(--accent); }
@media (max-width: 640px) { nav.site a:not(.cta) { display: none; } }
nav.site .cta {
  color: var(--bg); background: var(--accent); padding: 7px 14px;
  border-radius: 6px; font-weight: 500;
}
nav.site .cta:hover { color: var(--bg); background: var(--ink); }

/* ---- layout shell ---- */
.shell {
  position: relative; z-index: 1;
  max-width: calc(var(--maxw) + var(--gutter) + 260px);
  margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px);
  display: grid;
  grid-template-columns: var(--gutter) minmax(0, var(--maxw)) 1fr;
  gap: 0;
}
@media (max-width: 980px) { .shell { grid-template-columns: var(--gutter) minmax(0,1fr); } .toc { display: none; } }
@media (max-width: 560px) { :root { --gutter: 34px; } body { font-size: 18px; } }

/* ---- line-number gutter (signature) ---- */
.gutter {
  grid-column: 1;
  border-right: 1px solid var(--line);
  font-family: var(--mono); font-size: 12px; color: var(--faint);
  text-align: right; padding-right: 14px; user-select: none;
  position: relative;
}
.gutter .ln {
  display: block; line-height: 28px; height: 28px;
}

article { grid-column: 2; padding: 0 clamp(16px, 4vw, 44px) 80px; min-width: 0; text-align: justify; }

/* ---- hero comment-block header ---- */
.hero { padding: 52px 0 30px; }
.filepath {
  font-family: var(--mono); font-size: 12.5px; color: var(--muted);
  display: flex; align-items: center; gap: 8px; margin-bottom: 22px;
  flex-wrap: wrap;
}
.filepath .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); }
.filepath .path { color: var(--blue); }
.filepath .branch { color: var(--faint); }

.commentblock {
  font-family: var(--mono); font-size: 13px; line-height: 2;
  color: var(--muted); border-left: 2px solid var(--line);
  padding-left: 18px; margin-bottom: 30px;
}
.commentblock .c { color: var(--faint); }
.commentblock .k { color: var(--purple); }
.commentblock .s { color: var(--green); }
.commentblock .deco { color: var(--accent); }

.hero h1 {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(34px, 6vw, 56px); line-height: 1.04;
  letter-spacing: -1.5px; margin: 0 0 18px; color: var(--ink);
  text-align: left;
}
.hero h1 .hl {
  background: linear-gradient(transparent 64%, color-mix(in srgb, var(--accent) 28%, transparent) 0);
}
.hero .standfirst {
  font-size: 21px; color: var(--muted); margin: 0; max-width: 60ch;
  font-style: italic;
}
.meta {
  display: flex; gap: 18px; flex-wrap: wrap; align-items: center;
  margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--line);
  font-family: var(--mono); font-size: 12.5px; color: var(--muted);
}
.meta .av {
  width: 30px; height: 30px; border-radius: 7px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: grid; place-items: center; color: var(--bg); font-weight: 600; font-size: 13px;
}
.meta b { color: var(--ink); font-weight: 500; }
.meta .tag { color: var(--blue); }

/* ---- prose ---- */
article p { margin: 0 0 1.35em; }
article h2 {
  font-family: var(--display); font-weight: 600; letter-spacing: -.6px;
  font-size: 28px; line-height: 1.2; margin: 2.2em 0 .7em; scroll-margin-top: 80px;
  display: flex; align-items: baseline; gap: 12px;
  text-align: left;
}
article h2 .num {
  font-family: var(--mono); font-size: 13px; color: var(--accent);
  font-weight: 500; flex: none;
}
article h3 {
  font-family: var(--display); font-weight: 600; font-size: 20px;
  margin: 1.8em 0 .5em; letter-spacing: -.3px;
}
article a { color: var(--blue); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--blue) 40%, transparent); }
article a:hover { border-bottom-color: var(--blue); }
article strong { color: var(--ink); font-weight: 500; }

/* inline code with token color */
code.inline {
  font-family: var(--mono); font-size: .82em; color: var(--accent);
  background: var(--surface); padding: 2px 7px; border-radius: 5px;
  border: 1px solid var(--line);
}

/* ---- code block with window chrome ---- */
.code {
  margin: 1.8em 0; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); overflow: hidden;
}
.code .bar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.code .lights { display: flex; gap: 6px; }
.code .lights i { width: 11px; height: 11px; border-radius: 50%; display: block; }
.code .lights i:nth-child(1){ background:#ff5f57; }
.code .lights i:nth-child(2){ background:#febc2e; }
.code .lights i:nth-child(3){ background:#28c840; }
.code .fname { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-left: 6px; }
.code .copy {
  margin-left: auto; font-family: var(--mono); font-size: 11px;
  color: var(--muted); background: transparent; border: 1px solid var(--line);
  border-radius: 6px; padding: 4px 10px; cursor: pointer; transition: all .15s;
}
.code .copy:hover { color: var(--ink); border-color: var(--faint); }
.code .copy.done { color: var(--green); border-color: var(--green); }
.code pre {
  margin: 0; padding: 16px 18px; overflow-x: auto;
  font-family: var(--mono); font-size: 13.5px; line-height: 1.7;
  color: #c9d1e3; tab-size: 2;
}
.tok-k { color: var(--purple); }
.tok-f { color: var(--blue); }
.tok-s { color: var(--green); }
.tok-n { color: var(--accent); }
.tok-c { color: var(--faint); font-style: italic; }
.tok-t { color: #7ee0d8; }

/* ---- comment aside callout ---- */
.callout {
  margin: 1.8em 0; padding: 16px 18px; border-radius: 10px;
  background: color-mix(in srgb, var(--blue) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--blue) 25%, var(--line));
  font-family: var(--mono); font-size: 14px; line-height: 1.65; color: var(--ink);
}
.callout .label {
  color: var(--blue); font-weight: 600; font-size: 11px;
  letter-spacing: 1px; text-transform: uppercase; display: block; margin-bottom: 6px;
}
.callout.warn {
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 30%, var(--line));
}
.callout.warn .label { color: var(--accent); }

blockquote {
  margin: 1.8em 0; padding: 6px 0 6px 22px; border-left: 3px solid var(--accent);
  font-style: italic; color: var(--muted); font-size: 20px;
}

/* ---- figures ---- */
figure {
  margin: 2em 0; text-align: center;
}
figure img {
  max-width: 100%; height: auto; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
}
figcaption {
  font-family: var(--mono); font-size: 12px; color: var(--faint);
  margin-top: 10px; letter-spacing: .3px;
}
figcaption .c { color: var(--faint); }

/* ---- table of contents (right rail) ---- */
.toc {
  grid-column: 3; align-self: start; position: sticky; top: 90px;
  padding-left: 36px; padding-top: 56px;
}
.toc .h {
  font-family: var(--mono); font-size: 11px; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--faint); margin-bottom: 14px;
}
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0; }
.toc a {
  display: block; font-family: var(--mono); font-size: 12.5px;
  color: var(--muted); text-decoration: none; padding: 5px 0 5px 14px;
  border-left: 2px solid var(--line); transition: all .15s; line-height: 1.4;
}
.toc a:hover { color: var(--ink); }
.toc a.active { color: var(--accent); border-left-color: var(--accent); }

/* ---- footer ---- */
footer.site {
  position: relative; z-index: 1; border-top: 1px solid var(--line);
  margin-top: 40px; padding: 40px clamp(20px, 5vw, 56px);
  display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap;
  font-family: var(--mono); font-size: 12.5px; color: var(--muted);
}
footer.site a { color: var(--blue); text-decoration: none; }
footer.site .signoff { color: var(--faint); }

/* ---- load reveal ---- */
.reveal { opacity: 0; transform: translateY(12px); animation: rise .7s cubic-bezier(.2,.7,.2,1) forwards; }
.reveal:nth-child(2){ animation-delay:.06s } .reveal:nth-child(3){ animation-delay:.12s }
@keyframes rise { to { opacity: 1; transform: none; } }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; border-radius: 3px; }
