/* nim444.com V2 — design system + home page.
 *
 * Hand-authored, no build step. The whole point of V2 is fewer moving parts,
 * and one page of bespoke layout is clearer as plain CSS than as utility
 * classes. Add a Tailwind build when the page count justifies it, not before.
 *
 * Palette: near-black graphite, greyscale, and exactly one hue — the brand
 * blue #149CEB from the NK wordmark. The brand never uses a second colour.
 */

/* ---------------------------------------------------------------- fonts -- */
@font-face {
  font-family: "Space Grotesk";
  src: url("/fonts/space-grotesk-400.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Space Grotesk";
  src: url("/fonts/space-grotesk-500.woff2") format("woff2");
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Space Grotesk";
  src: url("/fonts/space-grotesk-700.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/fonts/jetbrains-mono-400.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/fonts/jetbrains-mono-500.woff2") format("woff2");
  font-weight: 500; font-style: normal; font-display: swap;
}

/* --------------------------------------------------------------- tokens -- */
:root {
  --ink:        #07080a;   /* base — cold graphite, not pure black */
  --ink-raised: #0d0f13;   /* panels */
  --line:       #1a1e24;   /* hairlines */
  --line-lit:   #262c35;   /* hairlines on hover */
  --text:       #f2f4f7;
  --dim:        #8a93a1;   /* cool grey, keyed to the blue */
  --faint:      #565e6b;
  --blue:       #149ceb;   /* the one accent */
  --blue-soft:  rgba(20, 156, 235, 0.13);

  --display: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --gutter: clamp(1.25rem, 5vw, 5rem);
  --measure: 68rem;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---------------------------------------------------------------- reset -- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  position: relative;
  margin: 0;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background: var(--ink);
  color: var(--text);
  font-family: var(--display);
  font-weight: 400;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 3px;
  border-radius: 2px;
}

/* A single, very wide, very soft blue wash behind the fold. It is the only
   gradient on the page — it gives the black some depth without reading as
   the usual "glow orb" hero treatment. */
body::before {
  content: "";
  position: fixed;
  inset: -30vh -10vw auto;
  height: 80vh;
  background: radial-gradient(60% 55% at 22% 40%, var(--blue-soft), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.shell {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* ------------------------------------------------------------------ nav --
 * A floating "liquid glass" pill, in the spirit of macOS: translucent, blurred,
 * with a specular rim — and a real refraction at the curved edges, driven by
 * the feDisplacementMap in the inline SVG (see views.rs). Blur alone reads as
 * frosted plastic; bending what is behind it is what reads as glass.
 */
.glass-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.masthead {
  position: sticky;
  top: 0;
  z-index: 50;
  padding-block: 0.85rem;
  padding-inline: var(--gutter);
}

.nav-glass {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 0.6rem 0.85rem 0.6rem 1.15rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: rgba(13, 15, 19, 0.55);
  /* Frosted first — every modern browser gets this much. */
  backdrop-filter: blur(14px) saturate(1.7);
  -webkit-backdrop-filter: blur(14px) saturate(1.7);
  box-shadow:
    inset 0 0 2px 1px rgba(255, 255, 255, 0.11),   /* crisp specular rim */
    inset 0 1px 10px 3px rgba(255, 255, 255, 0.05), /* soft inner bloom */
    0 8px 28px -10px rgba(0, 0, 0, 0.7);            /* lift off the page */
  transition: background 0.3s var(--ease), border-color 0.3s var(--ease);
}

/* Chromium supports url() inside backdrop-filter — layer the refraction on
   top. Anything else keeps the plain blur above and looks right regardless. */
@supports (backdrop-filter: url(#nk-liquid-glass)) {
  .nav-glass {
    backdrop-filter: url(#nk-liquid-glass) blur(11px) saturate(1.7);
  }
}

/* Respect the OS setting rather than forcing translucency on people who have
   asked for less of it. */
@media (prefers-reduced-transparency: reduce) {
  .nav-glass {
    background: var(--ink-raised);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

.mark {
  display: inline-flex;
  align-items: center;
  flex: none;
  border-radius: 8px;
}
/* The NK gif is the logotype; intrinsic size is 112×57, shown at 28px tall. */
.mark img {
  display: block;
  height: 28px;
  width: auto;
  transition: opacity 0.18s var(--ease);
}
.mark:hover img { opacity: 0.82; }

.nav {
  display: flex;
  align-items: center;
  gap: clamp(1rem, 3vw, 2.25rem);
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.nav a {
  color: var(--dim);
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: color 0.18s var(--ease), background 0.18s var(--ease),
              border-color 0.18s var(--ease);
}
/* Each link becomes its own small pane of the same glass on hover. */
.nav a:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.08);
}
.nav a:active { background: rgba(255, 255, 255, 0.04); }

/* Hamburger — phone only; the desktop rule below hides it. Bare bars, no
   frame. The 38px box stays for the touch target even though nothing paints. */
.nav-toggle {
  display: none;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.nav-toggle:active .nav-toggle-bars { opacity: 0.6; }

.nav-toggle-bars {
  display: grid;
  gap: 4px;
  width: 19px;
  transition: opacity 0.15s var(--ease);
}
.nav-toggle-bars span {
  display: block;
  height: 1.5px;
  border-radius: 2px;
  background: currentColor;
  transition: transform 0.26s var(--ease), opacity 0.18s var(--ease);
}
/* Open state: top and bottom bars cross, middle fades. */
.nav-open .nav-toggle-bars span:nth-child(1) { transform: translateY(5.5px) rotate(45deg); }
.nav-open .nav-toggle-bars span:nth-child(2) { opacity: 0; }
.nav-open .nav-toggle-bars span:nth-child(3) { transform: translateY(-5.5px) rotate(-45deg); }

/* ----------------------------------------------------------------- hero -- */
.hero {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  padding-block: clamp(3rem, 12vh, 8rem);
}

/* Video background.
 *
 * Anchored to the top of the page, not to .hero — it has to pass *behind* the
 * nav. Sitting inside .hero started it at the masthead's lower edge and left a
 * hard horizontal seam across the top of the page.
 *
 * One vertical gradient only. Two stacked gradients (vertical + horizontal)
 * multiplied into a muddy grey wash and flattened the footage. */
.hero-video {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: min(100svh, 60rem);
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.hero-video video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  /* The footage is a bright grey mesh; knocking brightness down keeps it as
     texture instead of a grey wash over the graphite palette. */
  filter: brightness(0.55) contrast(1.05);
  opacity: 0.5;
}
/* Clear at the top so the nav has something to refract, easing to solid ink
   before the next section so there is no visible edge where it ends. */
.hero-video::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    rgba(7, 8, 10, 0.15) 0%,
    rgba(7, 8, 10, 0.34) 30%,
    rgba(7, 8, 10, 0.62) 62%,
    rgba(7, 8, 10, 0.92) 86%,
    var(--ink) 100%
  );
}

.eyebrow {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--blue);
  margin: 0 0 clamp(1.25rem, 3vw, 2rem);
}

.headline {
  font-size: clamp(2.75rem, 9.5vw, 7rem);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.035em;
  margin: 0;
  max-width: 15ch;
  text-wrap: balance;
}
.headline .muted { color: #798394; }  /* lighter than --faint: must hold over the video */
.headline .stop { color: var(--blue); }

.lede {
  margin: clamp(1.5rem, 4vw, 2.25rem) 0 0;
  max-width: 46ch;
  font-size: clamp(1rem, 1.6vw, 1.15rem);
  color: var(--dim);
  text-wrap: pretty;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: clamp(2rem, 5vw, 3rem);
}

/* Buttons: .btn holds every shared property so the variants only ever set
   colour. Keeps specificity flat and stops the two rules cancelling out. */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.72rem 1.25rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.18s var(--ease), border-color 0.18s var(--ease),
              color 0.18s var(--ease), transform 0.18s var(--ease);
}
.btn:hover { transform: translateY(-1px); }
.btn svg { transition: transform 0.18s var(--ease); }
.btn:hover svg { transform: translateX(3px); }

.btn-primary { background: var(--blue); border-color: var(--blue); color: #04121c; }
.btn-primary:hover { background: #2aa9f0; border-color: #2aa9f0; }

.btn-ghost { color: var(--dim); }
.btn-ghost:hover { color: var(--text); border-color: var(--line-lit); }

/* ------------------------------------------------- signature: the machine --
 * The page reports on the process serving it. This is the one bold element:
 * real numbers from this binary, on this machine, refreshed live. It is the
 * argument for the whole V2 rebuild, stated as data rather than as a claim.
 */
.machine {
  border-top: 1px solid var(--line);
  padding-block: clamp(1.25rem, 3vw, 1.75rem);
}
.machine .shell {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.75rem clamp(1.25rem, 4vw, 3rem);
}

.machine-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
  white-space: nowrap;
}

.pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 0 0 0 var(--blue-soft);
  animation: pulse 2.4s var(--ease) infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(20, 156, 235, 0.5); }
  70%  { box-shadow: 0 0 0 7px rgba(20, 156, 235, 0); }
  100% { box-shadow: 0 0 0 0 rgba(20, 156, 235, 0); }
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem clamp(1.25rem, 4vw, 2.75rem);
  margin: 0;
  font-family: var(--mono);
  font-size: 0.78rem;
}
.stats div { display: flex; align-items: baseline; gap: 0.5rem; }
.stats dt { color: var(--faint); }
.stats dd {
  margin: 0;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------- content pages -- */
.page { flex: 1; padding-block: clamp(2rem, 6vw, 4.5rem) clamp(3rem, 8vw, 6rem); }

.page-head { margin-bottom: clamp(2rem, 5vw, 3.25rem); }
.page-title {
  font-size: clamp(2rem, 5.5vw, 3.5rem);
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: -0.03em;
  margin: 0;
  max-width: 22ch;
  text-wrap: balance;
}
.page-sub {
  margin: 0.9rem 0 0;
  max-width: 54ch;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 0.8rem;
}
.page-sub a { color: var(--blue); }
.page-head .eyebrow { margin-bottom: 0.9rem; }
.page-head .eyebrow a { color: inherit; }
.page-head .eyebrow a:hover { color: var(--text); }

/* Section strips on the home page */
.strip { padding-block: clamp(2.5rem, 6vw, 4rem); border-top: 1px solid var(--line); }
.strip-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; margin-bottom: clamp(1.25rem, 3vw, 2rem);
}
.strip-head h2, .strip-h {
  margin: 0;
  font-size: clamp(1.1rem, 2vw, 1.4rem);
  font-weight: 500;
  letter-spacing: -0.015em;
}
.strip-h { margin: clamp(2rem, 5vw, 3rem) 0 1.25rem; }
.more {
  font-family: var(--mono); font-size: 0.75rem; color: var(--dim);
  white-space: nowrap; transition: color 0.18s var(--ease);
}
.more:hover { color: var(--blue); }

/* Cards */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
  gap: clamp(1rem, 2.5vw, 1.5rem);
}
.grid-tight { grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); }

.card {
  display: flex; flex-direction: column;
  background: var(--ink-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.18s var(--ease), transform 0.18s var(--ease);
}
.card:hover { border-color: var(--line-lit); transform: translateY(-2px); }
.card-link { display: flex; flex-direction: column; flex: 1; }
.card-cover { aspect-ratio: 16 / 9; overflow: hidden; background: #000; }
.card-cover img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  transition: transform 0.4s var(--ease);
}
.card:hover .card-cover img { transform: scale(1.03); }
.card-body { padding: 1.1rem 1.15rem; display: flex; flex-direction: column; gap: 0.45rem; flex: 1; }
.card-date { margin: 0; font-family: var(--mono); font-size: 0.7rem; color: var(--faint); }
.card-title {
  margin: 0; font-size: 1.02rem; font-weight: 500; line-height: 1.25;
  letter-spacing: -0.012em; display: flex; align-items: center; gap: 0.4rem;
}
.card:hover .card-title { color: var(--blue); }
.card-out { flex: none; opacity: 0.5; }
.card-summary {
  margin: 0; font-size: 0.86rem; color: var(--dim); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-repo .card-body { gap: 0.5rem; }

/* Tags */
.tags { display: flex; flex-wrap: wrap; gap: 0.35rem; list-style: none; margin: 0; padding: 0 1.15rem 1.1rem; }
.tags a {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--line); border-radius: 4px;
  font-family: var(--mono); font-size: 0.68rem; color: var(--faint);
  transition: color 0.18s var(--ease), border-color 0.18s var(--ease);
}
.tags a:hover { color: var(--blue); border-color: var(--blue); }
.tag-n { color: var(--line-lit); }
.tags-index { padding: 0 0 clamp(2rem, 4vw, 2.75rem); gap: 0.4rem; }
.page-head .tags { padding: 1.1rem 0 0; }

/* Search */
.search { display: flex; gap: 0.6rem; margin-bottom: clamp(1.5rem, 4vw, 2.5rem); flex-wrap: wrap; }
.search input {
  flex: 1 1 18rem;
  padding: 0.72rem 1rem;
  background: var(--ink-raised);
  border: 1px solid var(--line); border-radius: 6px;
  color: var(--text); font-family: var(--mono); font-size: 0.85rem;
}
.search input::placeholder { color: var(--faint); }
.search input:focus { border-color: var(--blue); outline: none; }
.result-count { margin-bottom: 0; }
.empty { color: var(--faint); font-family: var(--mono); font-size: 0.85rem; }

/* ---------------------------------------------------------------- prose -- */
.prose-wrap { max-width: 46rem; }
.cover {
  width: 100%; border-radius: 10px; border: 1px solid var(--line);
  margin-block: clamp(1.5rem, 4vw, 2.5rem); display: block;
}
.prose { font-size: 1.02rem; line-height: 1.72; color: #d9dee6; }
.prose > * + * { margin-top: 1.15em; }
.prose h1, .prose h2, .prose h3 {
  color: var(--text); font-weight: 700; letter-spacing: -0.02em;
  line-height: 1.2; margin-top: 2.2em; margin-bottom: 0.6em;
}
.prose h1 { font-size: 1.7rem; }
.prose h2 { font-size: 1.4rem; }
.prose h3 { font-size: 1.15rem; }
.prose a { color: var(--blue); text-decoration: underline; text-underline-offset: 2px; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li + li { margin-top: 0.35em; }
.prose img { max-width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--line); display: block; }
.prose blockquote {
  border-left: 2px solid var(--blue); padding-left: 1rem; margin-left: 0; color: var(--dim);
}
.prose table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.prose th, .prose td { border: 1px solid var(--line); padding: 0.5rem 0.7rem; text-align: left; }
.prose th { background: var(--ink-raised); font-weight: 500; }
.prose code {
  font-family: var(--mono); font-size: 0.86em;
  background: var(--ink-raised); border: 1px solid var(--line);
  padding: 0.12em 0.35em; border-radius: 4px;
}
.prose pre {
  background: var(--ink-raised); border: 1px solid var(--line); border-radius: 8px;
  padding: 1rem 1.1rem; overflow-x: auto; font-size: 0.84rem; line-height: 1.6;
}
.prose pre code { background: none; border: 0; padding: 0; font-size: inherit; }
.prose video { width: 100%; border-radius: 8px; border: 1px solid var(--line); }

/* Mermaid renders into this; keep it quiet until the diagram exists. */
.prose pre.mermaid { text-align: center; color: transparent; }
.prose pre.mermaid[data-processed] { color: inherit; }

.back { margin-top: clamp(2.5rem, 6vw, 4rem); font-family: var(--mono); font-size: 0.8rem; }
.back a { color: var(--dim); }
.back a:hover { color: var(--blue); }

/* --------------------------------------------------------------- footer -- */
.footer {
  border-top: 1px solid var(--line);
  padding-block: clamp(1.25rem, 3vw, 1.75rem);
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--faint);
}
.footer .shell {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
}
.footer a { color: var(--dim); transition: color 0.18s var(--ease); }
.footer a:hover { color: var(--text); }
.footer nav { display: flex; gap: 1.25rem; }

/* --------------------------------------------------------------- motion -- */
/* One load sequence, staggered. Nothing else animates on entry. */
.rise {
  opacity: 0;
  transform: translateY(14px);
  animation: rise 0.7s var(--ease) forwards;
}
.rise:nth-child(1) { animation-delay: 0.05s; }
.rise:nth-child(2) { animation-delay: 0.13s; }
.rise:nth-child(3) { animation-delay: 0.21s; }
.rise:nth-child(4) { animation-delay: 0.29s; }
@keyframes rise {
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .rise { opacity: 1; transform: none; animation: none; }
  .nav, .nav-toggle-bars span { transition: none; }
  /* Hide the footage; the poster frame stays as a still backdrop. */
  .hero-video video { display: none; }
  .hero-video {
    background: url("/video/hero-poster.jpg") center / cover no-repeat;
    opacity: 0.3;
  }
  .pulse { animation: none; }
  .btn, .btn svg, .nav a, .footer a { transition: none; }
  .btn:hover { transform: none; }
}

/* --------------------------------------------------------------- mobile -- */
@media (max-width: 40rem) {
  /* The pill keeps just the logotype and a hamburger; the links move into a
     glass panel that drops from under it. */
  .masthead { padding-inline: 0.75rem; }
  .nav-glass { gap: 0.6rem; padding: 0.45rem 0.5rem 0.45rem 0.8rem; }
  .nav-toggle { display: grid; }

  .nav {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    left: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0.15rem;
    padding: 0.5rem;
    font-size: 0.78rem;
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.09);
    /* Deliberately near-opaque, not blurred glass. The panel hangs outside
       .nav-glass, whose own backdrop-filter makes it a backdrop root — a
       nested backdrop-filter has nothing to sample out there and renders
       clear, letting page text collide with the links. An opaque surface is
       also simply the legible choice for a menu over arbitrary content. */
    background: #0b0d11;
    box-shadow:
      inset 0 0 2px 1px rgba(255, 255, 255, 0.08),
      0 16px 34px -12px rgba(0, 0, 0, 0.85);
    /* Closed: collapsed and inert, so it is not tabbable while hidden. */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(0.985);
    transform-origin: top center;
    transition: opacity 0.2s var(--ease), transform 0.24s var(--ease),
                visibility 0s linear 0.24s;
  }
  .nav a {
    padding: 0.7rem 0.85rem;
    border-radius: 12px;
    white-space: nowrap;
  }

  .nav-open .nav {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition: opacity 0.2s var(--ease), transform 0.24s var(--ease),
                visibility 0s;
  }
  .headline { max-width: 100%; }
  .actions .btn { flex: 1 1 auto; justify-content: center; }
  .footer .shell { flex-direction: column; align-items: flex-start; }
}
