/* ============================================================
   TGraphX – Design System
   Mobile-first · Fluid type · Glass + Bento · Cross-browser
   ============================================================ */

/* ---------- 1. Tokens ---------- */
:root {
  /* Palette */
  --bg:            #0D1B2A;
  --bg-2:          #0a1622;
  --bg-3:          #08111c;
  --structural:    #1B263B;
  --structural-2:  #243049;
  --accent:        #00B4D8;
  --accent-2:      #7ee5f7;
  --accent-soft:   rgba(0,180,216,0.12);
  --accent-glow:   rgba(0,180,216,0.35);
  --text:          #E0E1DD;
  --muted:         rgba(224,225,221,0.62);
  --dim:           rgba(224,225,221,0.40);
  --hairline:      rgba(224,225,221,0.10);
  --hairline-strong: rgba(224,225,221,0.18);
  --warn:          #f5a524;
  --ok:            #2ecc71;
  --beta:          #b08bff;

  /* Surfaces (glass) */
  --glass-bg:      rgba(20, 32, 48, 0.55);
  --glass-bg-soft: rgba(20, 32, 48, 0.30);
  --glass-border:  rgba(224,225,221,0.10);
  --glass-blur:    saturate(140%) blur(14px);

  /* Type */
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Fluid type scale (clamp(min, fluid, max)) */
  --fs-xs:    clamp(0.70rem, 0.65rem + 0.18vw, 0.78rem);
  --fs-sm:    clamp(0.80rem, 0.75rem + 0.22vw, 0.90rem);
  --fs-base:  clamp(0.92rem, 0.88rem + 0.26vw, 1.05rem);
  --fs-md:    clamp(1.00rem, 0.94rem + 0.32vw, 1.18rem);
  --fs-lg:    clamp(1.15rem, 1.05rem + 0.55vw, 1.40rem);
  --fs-xl:    clamp(1.35rem, 1.18rem + 0.95vw, 1.85rem);
  --fs-2xl:   clamp(1.70rem, 1.30rem + 1.90vw, 2.60rem);
  --fs-3xl:   clamp(2.20rem, 1.60rem + 3.20vw, 4.20rem);
  --fs-display: clamp(2.60rem, 1.70rem + 5.50vw, 6.00rem);

  /* Spacing (fluid) */
  --sp-1:  clamp(0.25rem, 0.20rem + 0.20vw, 0.40rem);
  --sp-2:  clamp(0.50rem, 0.42rem + 0.32vw, 0.75rem);
  --sp-3:  clamp(0.75rem, 0.62rem + 0.50vw, 1.10rem);
  --sp-4:  clamp(1.00rem, 0.80rem + 0.80vw, 1.60rem);
  --sp-5:  clamp(1.50rem, 1.10rem + 1.40vw, 2.40rem);
  --sp-6:  clamp(2.00rem, 1.40rem + 2.20vw, 3.60rem);
  --sp-7:  clamp(3.00rem, 2.00rem + 3.40vw, 5.50rem);
  --sp-8:  clamp(4.50rem, 3.00rem + 5.00vw, 8.00rem);

  /* Radii */
  --r-1: 6px;
  --r-2: 10px;
  --r-3: 16px;
  --r-pill: 999px;

  /* Container width — adaptive up to ultrawide */
  --container: min(1240px, 92vw);
  --container-wide: min(1640px, 94vw);

  /* Shadows */
  --shadow-1: 0 1px 0 rgba(255,255,255,0.04) inset, 0 8px 24px -12px rgba(0,0,0,0.55);
  --shadow-2: 0 1px 0 rgba(255,255,255,0.04) inset, 0 30px 60px -30px rgba(0,0,0,0.65);
  --shadow-glow: 0 0 0 1px var(--accent-glow), 0 16px 40px -12px rgba(0,180,216,0.25);

  /* Motion */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --t-fast: 140ms;
  --t-med: 240ms;
  --t-slow: 420ms;

  color-scheme: dark;
}

/* Ultrawide / 4K — let the design breathe but cap line lengths */
@media (min-width: 1800px) {
  :root { --container: min(1480px, 86vw); }
}
@media (min-width: 2400px) {
  :root { --container: 1640px; }
}

/* ---------- 2. Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
/* Hard overflow lock — both html AND body must carry this to catch every edge case */
html {
  overflow-x: hidden;
  max-width: 100vw;
}
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
body {
  background:
    radial-gradient(60vw 40vw at 80% -10%, rgba(0,180,216,0.07), transparent 60%),
    radial-gradient(50vw 35vw at -10% 20%, rgba(0,180,216,0.05), transparent 60%),
    var(--bg);
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: hidden;
  /* Prevent any child from escaping and creating horizontal scroll */
  position: relative;
}
img, svg, canvas, video { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

::selection { background: var(--accent); color: var(--bg); }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* tensor grid faint overlay */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(var(--hairline) 1px, transparent 1px),
    linear-gradient(90deg, var(--hairline) 1px, transparent 1px);
  background-size: 64px 64px;
  -webkit-mask-image: radial-gradient(ellipse at center, black 30%, transparent 80%);
          mask-image: radial-gradient(ellipse at center, black 30%, transparent 80%);
  opacity: 0.30;
  pointer-events: none;
  z-index: 0;
}

.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.accent { color: var(--accent); }

/* ---------- 3. Layout primitives ---------- */
.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

/* Global canvas — fixed behind all pages.
   The JS draw engine handles horizontal text-safe-zone fading (xa function).
   CSS handles the vertical top-fade and the overall layer opacity. */
.global-canvas-wrap {
  /* Single source of truth: one fixed full-viewport canvas layer. */
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  z-index: 0;          /* behind .app (z-index:1) but above body background */
  pointer-events: none;
  overflow: hidden;

  /* Subtle top fade — just enough to soften the topnav edge.
     The JS ya() handles the real brightness ramp so we don't need
     to black-out a large portion of the canvas from CSS. */
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0,0,0,0.6)  6%,
    black            18%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0,0,0,0.6)  6%,
    black            18%
  );

  opacity: 0.88;
}

/* CSS safe-zone overlay — a vertical centre-column dark wash that
   runs the full height of the canvas. Supplements JS xa() and ensures
   the text column stays clean even before the first canvas frame. */
.global-canvas-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    to right,
    transparent               0%,
    transparent               12%,
    rgba(10, 18, 30, 0.68)   30%,
    rgba(10, 18, 30, 0.82)   50%,
    rgba(10, 18, 30, 0.68)   70%,
    transparent               88%,
    transparent              100%
  );
}

@media (prefers-reduced-motion: reduce) {
  .global-canvas-wrap { display: none; }
}

/* On mobile the text fills the full viewport width, so lower opacity
   and replace the centre-column gradient with a uniform dark wash. */
@media (max-width: 767px) {
  .global-canvas-wrap {
    opacity: 0.38;
  }
  .global-canvas-wrap::after {
    background: rgba(10, 18, 30, 0.60);
  }
}
.container {
  width: var(--container);
  margin-inline: auto;
  padding-inline: 0;
}
.container.wide { width: var(--container-wide); }

/* ---------- 4. Top nav ---------- */
.topnav {
  position: sticky;
  top: 0;
  z-index: 50;
  -webkit-backdrop-filter: var(--glass-blur);
          backdrop-filter: var(--glass-blur);
  background: rgba(13, 27, 42, 0.72);
  border-bottom: 1px solid var(--hairline);
  /* Safari fallback when backdrop-filter unsupported */
  @supports not (backdrop-filter: blur(8px)) {
    background: rgba(13, 27, 42, 0.94);
  }
}
.topnav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: clamp(56px, 6vh, 72px);
  gap: var(--sp-3);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
  transition: opacity var(--t-fast);
}
.brand:hover { opacity: 0.85; }
.brand-mark { width: 28px; height: 28px; flex-shrink: 0; }
.brand-name {
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.04em;
  font-size: 14px;
}
.brand-name .ver {
  color: var(--muted);
  font-weight: 400;
  margin-left: 8px;
  font-size: 11px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-links::-webkit-scrollbar { display: none; }
.nav-link {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--muted);
  padding: 7px 11px;
  border-radius: 4px;
  cursor: pointer;
  transition: color var(--t-fast), background var(--t-fast);
  white-space: nowrap;
  position: relative;
}
.nav-link:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.nav-link.active { color: var(--accent); }
.nav-link.active::after {
  content: "";
  position: absolute;
  left: 11px; right: 11px; bottom: 2px;
  height: 1px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

.nav-cta { display: flex; gap: 8px; align-items: center; }

/* Hamburger (mobile) */
.nav-toggle {
  display: none;
  width: 40px; height: 40px;
  border: 1px solid var(--hairline-strong);
  background: rgba(255,255,255,0.02);
  border-radius: 8px;
  cursor: pointer;
  align-items: center; justify-content: center;
  transition: all var(--t-fast);
}
.nav-toggle:hover { border-color: var(--accent); color: var(--accent); }
.nav-toggle svg { width: 18px; height: 18px; }

@media (max-width: 1080px) {
  .nav-links { display: none; }
  .nav-toggle { display: inline-flex; }
  .nav-cta .btn:not(.primary) { display: none; }
}

/* Mobile drawer */
.mobile-drawer {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(8, 17, 28, 0.86);
  -webkit-backdrop-filter: blur(18px);
          backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-med) var(--ease-out);
}
.mobile-drawer.open { opacity: 1; pointer-events: auto; }
.mobile-drawer .drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--sp-5);
}
.mobile-drawer nav {
  display: flex; flex-direction: column; gap: 4px;
  margin-top: var(--sp-3);
}
.mobile-drawer .nav-link {
  font-size: 18px; padding: 14px 16px;
  border-bottom: 1px solid var(--hairline);
  border-radius: 0;
}
.mobile-drawer .nav-link.active::after { display: none; }
.mobile-drawer .nav-link.active {
  border-left: 2px solid var(--accent);
  padding-left: 14px;
}

/* ---------- 5. Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  padding: 10px 16px;
  border-radius: var(--r-1);
  border: 1px solid var(--hairline-strong);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: all var(--t-fast) var(--ease-out);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}
.btn::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120px 80px at var(--mx, 50%) var(--my, 50%), rgba(0,180,216,0.18), transparent 60%);
  opacity: 0;
  transition: opacity var(--t-med);
  pointer-events: none;
}
.btn:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.btn:hover::before { opacity: 1; }
.btn:active { transform: translateY(0); }
.btn.primary {
  background: var(--accent);
  color: #06212d;
  border-color: var(--accent);
  font-weight: 600;
  box-shadow: 0 6px 20px -8px var(--accent-glow);
}
.btn.primary:hover {
  background: var(--accent-2);
  color: #06212d;
  box-shadow: 0 0 0 4px var(--accent-soft), 0 10px 30px -8px var(--accent-glow);
}
.btn.ghost {
  border-color: var(--hairline);
  color: var(--muted);
}
.btn.ghost:hover {
  color: var(--text);
  border-color: var(--hairline-strong);
}
.btn .arrow { transition: transform var(--t-fast); }
.btn:hover .arrow { transform: translateX(3px); }

/* ---------- 6. Chips & badges ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 5px 9px;
  border-radius: var(--r-pill);
  border: 1px solid var(--hairline-strong);
  background: rgba(255,255,255,0.02);
  color: var(--muted);
  letter-spacing: 0.02em;
  transition: border-color var(--t-fast), color var(--t-fast);
}
.chip:hover { border-color: var(--hairline-strong); color: var(--text); }
.chip .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}
.chip.ok .dot { background: var(--ok); box-shadow: 0 0 6px rgba(46,204,113,0.5);}
.chip.beta .dot { background: var(--beta); box-shadow: 0 0 6px rgba(176,139,255,0.5);}
.chip.warn .dot { background: var(--warn); box-shadow: 0 0 6px rgba(245,165,36,0.5);}

.badge {
  display: inline-flex;
  align-items: stretch;
  font-family: var(--font-mono);
  font-size: 11px;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--hairline-strong);
  line-height: 1;
  transition: transform var(--t-fast), border-color var(--t-fast);
}
.badge:hover { transform: translateY(-1px); border-color: var(--accent); }
.badge .k { background: #0a1421; color: var(--muted); padding: 6px 9px; }
.badge .v { background: var(--structural); color: var(--text); padding: 6px 9px; border-left: 1px solid var(--hairline); }
.badge.accent .v { color: var(--accent); }

/* ---------- 7. Hero ---------- */
.hero {
  position: relative;
  padding: var(--sp-8) 0 var(--sp-6);
  overflow: hidden;
}
.hero-inner {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-5);
  align-items: center;
}
@media (min-width: 960px) {
  .hero-inner { grid-template-columns: 1.15fr 1fr; gap: var(--sp-6); }
}
.eyebrow {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--accent);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: var(--sp-3);
}
.eyebrow::before {
  content: "";
  width: 24px; height: 1px;
  background: var(--accent);
  display: inline-block;
}
h1.display {
  font-family: var(--font-sans);
  font-size: var(--fs-display);
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 0.96;
  margin: 0 0 var(--sp-3);
  text-wrap: balance;
}
h1.display .stroke {
  -webkit-text-stroke: 1px var(--text);
  color: transparent;
}
.subtitle {
  font-size: var(--fs-md);
  color: var(--text);
  max-width: 60ch;
  font-weight: 400;
  letter-spacing: -0.01em;
  margin-bottom: var(--sp-2);
}
.lede {
  color: var(--muted);
  max-width: 64ch;
  font-size: var(--fs-base);
  margin-bottom: var(--sp-4);
}
.hero-cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: var(--sp-4);
}
.hero-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ---------- 8. Sections ---------- */
section.section {
  padding: var(--sp-7) 0;
  position: relative;
}
section.section.tight { padding: var(--sp-6) 0; }
.section-head {
  margin-bottom: var(--sp-5);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
}
.section-head .left { max-width: 760px; }
.section-tag {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--accent);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-bottom: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.section-tag::before {
  content: "";
  width: 18px; height: 1px; background: var(--accent);
}
h2.section-title {
  font-size: var(--fs-2xl);
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.08;
  margin: 0;
  text-wrap: balance;
}
.section-sub {
  color: var(--muted);
  margin-top: 12px;
  font-size: var(--fs-base);
  max-width: 68ch;
  text-wrap: pretty;
}

/* ---------- 9. Terminal ---------- */
.terminal {
  border: 1px solid var(--hairline-strong);
  background: linear-gradient(180deg, #0c1a29 0%, #0a1622 100%);
  border-radius: var(--r-2);
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 13px;
  box-shadow: var(--shadow-2);
  transition: transform var(--t-med) var(--ease-out), box-shadow var(--t-med);
}
.terminal:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-2), 0 24px 48px -24px rgba(0,180,216,0.25);
}
.terminal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--hairline);
  background: rgba(255,255,255,0.02);
}
.terminal-dots { display: flex; gap: 6px; }
.terminal-dots span {
  width: 11px; height: 11px; border-radius: 50%;
  background: rgba(255,255,255,0.12);
}
.terminal-dots span:nth-child(1) { background: #ff5f57; opacity: 0.55; }
.terminal-dots span:nth-child(2) { background: #febc2e; opacity: 0.55; }
.terminal-dots span:nth-child(3) { background: #28c840; opacity: 0.55; }
.terminal-title { font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }
.terminal-body {
  padding: 14px 16px;
  white-space: pre;
  overflow-x: auto;
}
.terminal-line { display: block; color: var(--text); }
.terminal-line .prompt { color: var(--accent); user-select: none; margin-right: 8px; }
.terminal-line .cmd { color: var(--text); }
.terminal-line .out { color: var(--muted); }
.terminal-line .ok { color: var(--ok); }
.terminal-line .warn { color: var(--warn); }
.terminal-line .dim { color: var(--dim); }
.cursor {
  display: inline-block;
  width: 8px; height: 14px;
  background: var(--accent);
  vertical-align: middle;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- 10. Code blocks ---------- */
.code {
  border: 1px solid var(--hairline-strong);
  background: #0a1421;
  border-radius: var(--r-2);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--hairline);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--muted);
}
.code-head .left { display: flex; align-items: center; gap: 10px; }
.copy-btn {
  font-family: var(--font-mono);
  font-size: 11px;
  background: transparent;
  border: 1px solid var(--hairline);
  color: var(--muted);
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--t-fast);
}
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }
.code-body {
  padding: 16px 18px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  overflow-x: auto;
  white-space: pre;
}
.tok-kw { color: #ff7eb6; }
.tok-fn { color: #6ee7ff; }
.tok-str { color: #a5e3a0; }
.tok-num { color: #ffd479; }
.tok-cmt { color: var(--dim); font-style: italic; }
.tok-mod { color: #b08bff; }
.tok-op  { color: var(--muted); }
.tok-arg { color: var(--text); }

/* ---------- 11. Bento grid ---------- */
.grid { display: grid; gap: var(--sp-3); }
.grid.cols-2 { grid-template-columns: 1fr; }
.grid.cols-3 { grid-template-columns: 1fr; }
.grid.cols-4 { grid-template-columns: 1fr; }

@media (min-width: 600px) {
  .grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 960px) {
  .grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
  .grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 1800px) {
  .grid { gap: var(--sp-4); }
}

/* ---------- 12. Cards ---------- */
.card {
  border: 1px solid var(--hairline);
  background: var(--glass-bg-soft);
  -webkit-backdrop-filter: blur(8px);
          backdrop-filter: blur(8px);
  border-radius: var(--r-2);
  padding: var(--sp-4);
  position: relative;
  transition: border-color var(--t-med), transform var(--t-med), box-shadow var(--t-med);
  overflow: hidden;
}
.card::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, transparent 50%, var(--accent-glow) 100%);
  -webkit-mask: linear-gradient(#000, #000) content-box, linear-gradient(#000, #000);
          mask: linear-gradient(#000, #000) content-box, linear-gradient(#000, #000);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  opacity: 0;
  transition: opacity var(--t-med);
  pointer-events: none;
}
.card:hover { transform: translateY(-2px); border-color: var(--hairline-strong); }
.card:hover::after { opacity: 1; }
.card .card-tag {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--accent);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 12px;
}
.card h3 {
  margin: 0 0 8px;
  font-size: var(--fs-md);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.card p {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
  text-wrap: pretty;
}
.card .card-icon {
  width: 28px; height: 28px;
  margin-bottom: 14px;
  color: var(--accent);
}

/* Feature card with hover glow */
.feature-card {
  border: 1px solid var(--hairline);
  background: linear-gradient(180deg, rgba(27,38,59,0.55) 0%, rgba(27,38,59,0.20) 100%);
  -webkit-backdrop-filter: blur(8px);
          backdrop-filter: blur(8px);
  border-radius: var(--r-2);
  padding: var(--sp-4);
  position: relative;
  overflow: hidden;
  transition: transform var(--t-med) var(--ease-out), border-color var(--t-med);
}
.feature-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0;
  transition: opacity var(--t-med);
}
.feature-card:hover { transform: translateY(-3px); border-color: var(--hairline-strong); }
.feature-card:hover::before { opacity: 0.7; }
.feature-card svg { color: var(--accent); transition: transform var(--t-med) var(--ease-out); }
.feature-card:hover svg { transform: scale(1.06) rotate(-2deg); }

/* Metric card */
.metric {
  border: 1px solid var(--hairline);
  border-radius: var(--r-2);
  padding: var(--sp-3);
  background: var(--glass-bg-soft);
  -webkit-backdrop-filter: blur(8px);
          backdrop-filter: blur(8px);
  transition: border-color var(--t-fast), transform var(--t-fast);
}
.metric:hover { border-color: var(--accent); transform: translateY(-1px); }
.metric .label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.metric .value {
  font-family: var(--font-mono);
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.metric .value .unit { color: var(--muted); font-size: 14px; font-weight: 400; margin-left: 4px; }
.metric .sub { font-size: 12px; color: var(--dim); margin-top: 4px; }

/* Author row — locked horizontal, Arash left, Mark right, never stacks */
.footer-authors {
  display: flex;
  flex-direction: row;        /* explicit — never column */
  flex-wrap: nowrap;          /* never wraps */
  align-items: center;
  gap: 6px;
  margin-top: 16px;
  overflow: hidden;           /* clip if truly tiny (e.g. 240px watch screen) */
}
.footer-author-name {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--dim);
  white-space: nowrap;
  flex-shrink: 0;
  text-decoration: none;
  transition: color var(--t-fast);
}
.footer-author-name:hover { color: var(--accent); }
.footer-author-sep {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--dim);
  opacity: 0.4;
  flex-shrink: 0;
}

/* Footer credit line (Image Lab attribution) */
.footer-credit {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--dim);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--hairline);
  margin-bottom: var(--sp-2);
}
.footer-credit a {
  color: var(--muted);
  border-bottom: 1px solid rgba(224,225,221,0.18);
  transition: color var(--t-fast), border-color var(--t-fast);
}
.footer-credit a:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- 13. Footer ---------- */
footer.footer {
  border-top: 1px solid var(--hairline);
  margin-top: var(--sp-7);
  padding: var(--sp-6) 0 var(--sp-4);
  background: rgba(8,16,28,0.55);
  -webkit-backdrop-filter: blur(8px);
          backdrop-filter: blur(8px);
}
.footer-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}
@media (min-width: 600px) {
  .footer-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 960px) {
  .footer-grid { grid-template-columns: 1.4fr 1fr 1fr 1fr; }
}
.footer-col h4 {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 0 0 14px;
  font-weight: 500;
}
.footer-col a {
  display: block;
  font-size: 13.5px;
  color: var(--text);
  margin-bottom: 8px;
  cursor: pointer;
  transition: color var(--t-fast), transform var(--t-fast);
}
.footer-col a:hover { color: var(--accent); transform: translateX(2px); }
.footer-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--hairline);
  padding-top: var(--sp-3);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--dim);
  flex-wrap: wrap;
  gap: 12px;
}

/* ---------- 14. Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-2);
  overflow: hidden;
  min-width: 520px;
}
.table th, .table td {
  text-align: left;
  padding: 14px 16px;
  border-bottom: 1px solid var(--hairline);
  vertical-align: top;
}
.table th {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(27,38,59,0.45);
  font-weight: 500;
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:hover { background: rgba(0,180,216,0.04); }
.table .row-label { font-weight: 600; color: var(--text); }
.table .yes { color: var(--accent); }
.table .partial { color: var(--warn); }
.table .no { color: var(--dim); }

/* ---------- 15. Notebook card ---------- */
.nb-card {
  border: 1px solid var(--hairline);
  border-radius: var(--r-2);
  background: var(--glass-bg-soft);
  -webkit-backdrop-filter: blur(8px);
          backdrop-filter: blur(8px);
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color var(--t-med), transform var(--t-med);
}
.nb-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.nb-card .nb-num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 0.1em;
}
.nb-card h3 {
  margin: 0;
  font-size: var(--fs-md);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.nb-card .nb-meta {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 4px;
}
.nb-card .nb-actions {
  margin-top: auto;
  padding-top: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- 16. Docs layout ---------- */
.docs-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-3);
  padding: var(--sp-5) 0;
}
@media (min-width: 880px) {
  .docs-layout { grid-template-columns: 240px 1fr; gap: var(--sp-6); }
}
.docs-side {
  border-bottom: 1px solid var(--hairline);
  padding-bottom: 16px;
  position: static;
  max-height: none;
  overflow-y: auto;
}
@media (min-width: 880px) {
  .docs-side {
    border-right: 1px solid var(--hairline);
    border-bottom: none;
    padding-right: 24px;
    padding-bottom: 0;
    position: sticky;
    top: 88px;
    align-self: start;
    max-height: calc(100vh - 110px);
  }
}
.docs-side h5 {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 20px 0 8px;
}
.docs-side h5:first-child { margin-top: 0; }
.docs-side a {
  display: block;
  font-size: 13.5px;
  color: var(--muted);
  padding: 6px 0 6px 12px;
  margin-left: -12px;
  cursor: pointer;
  border-left: 1px solid transparent;
  transition: color var(--t-fast), border-color var(--t-fast);
}
.docs-side a:hover { color: var(--text); }
.docs-side a.active { color: var(--accent); border-left-color: var(--accent); }
.docs-body { max-width: 76ch; }
.docs-body h1 {
  font-size: var(--fs-2xl);
  letter-spacing: -0.025em;
  margin: 0 0 8px;
}
.docs-body h2 {
  font-size: var(--fs-xl);
  letter-spacing: -0.015em;
  margin: var(--sp-5) 0 12px;
  padding-top: 12px;
  border-top: 1px solid var(--hairline);
}
.docs-body h3 { font-size: var(--fs-md); margin: var(--sp-4) 0 8px; }
.docs-body p, .docs-body ul { color: var(--text); font-size: var(--fs-base); }
.docs-body p { margin: 0 0 14px; color: var(--muted); }
.docs-body ul { padding-left: 22px; color: var(--muted); }
.docs-body li { margin: 4px 0; }
.docs-body code:not(pre code) {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: rgba(0,180,216,0.08);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 3px;
}

/* ---------- 17. Forms ---------- */
.form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 560px;
}
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.form-field input,
.form-field select,
.form-field textarea {
  font-family: var(--font-sans);
  font-size: 14.5px;
  color: var(--text);
  background: rgba(10, 22, 34, 0.6);
  border: 1px solid var(--hairline-strong);
  border-radius: 6px;
  padding: 12px 14px;
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
  -webkit-appearance: none;
          appearance: none;
}
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: rgba(10, 22, 34, 0.85);
}
.form-field textarea { resize: vertical; min-height: 120px; }
.honeypot { position: absolute; left: -9999px; opacity: 0; pointer-events: none; }

/* ---------- 18. Notice / banner ---------- */
.notice {
  border: 1px solid var(--hairline-strong);
  border-left: 2px solid var(--accent);
  background: rgba(0,180,216,0.04);
  padding: 16px 18px;
  border-radius: 6px;
  font-size: var(--fs-sm);
  color: var(--muted);
}
.notice strong { color: var(--text); font-weight: 600; }
.notice.warn {
  border-left-color: var(--warn);
  background: rgba(245,165,36,0.04);
}

/* Inline link */
.link-inline {
  color: var(--accent);
  border-bottom: 1px solid rgba(0,180,216,0.3);
  transition: border-color var(--t-fast);
}
.link-inline:hover { border-color: var(--accent); }

/* small KV list */
.kv {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px 24px;
  font-family: var(--font-mono);
  font-size: 12.5px;
}
@media (min-width: 540px) {
  .kv { grid-template-columns: 200px 1fr; }
}
.kv .k { color: var(--muted); }
.kv .v { color: var(--text); }

/* Page transitions */
.page-enter { animation: pageIn var(--t-slow) var(--ease-out); }
@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Changelog timeline */
.cl-entry {
  border-left: 1px solid var(--hairline);
  padding: 0 0 var(--sp-5) 24px;
  position: relative;
}
.cl-entry::before {
  content: "";
  position: absolute;
  left: -5px; top: 6px;
  width: 9px; height: 9px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 0 3px var(--bg), 0 0 12px var(--accent-glow);
}
.cl-entry h3 {
  font-family: var(--font-mono);
  font-size: 14px;
  margin: 0 0 4px;
  color: var(--accent);
}
.cl-entry .date { font-family: var(--font-mono); font-size: 11px; color: var(--dim); }
.cl-entry ul { color: var(--muted); font-size: var(--fs-sm); padding-left: 20px; margin: 10px 0 0; }

/* utility */
.divider { height: 1px; background: var(--hairline); margin: 0; border: none; }

/* scrollbar (WebKit) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
  background: var(--structural);
  border-radius: 5px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--structural-2); }
/* Firefox */
* { scrollbar-color: var(--structural) var(--bg); scrollbar-width: thin; }

/* Reveal-on-scroll utility (used by JS) */
.reveal {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 600ms var(--ease-out), transform 600ms var(--ease-out);
  will-change: opacity, transform;
}
.reveal.in { opacity: 1; transform: translateY(0); }

/* High-DPI hairlines stay crisp on retina via 0.5px */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .hairline-precise { border-width: 0.5px; }
}

/* ============================================================
   MOBILE-FIRST LAYER  (< 768px)
   All rules here are ADDITIONS to the base styles — no desktop
   layout is changed. The bottom nav is the centrepiece.
   ============================================================ */

/* Main content area — flush, fills space, padded bottom for bottom nav */
.app-main {
  flex: 1;
  position: relative;
  z-index: 1;
  /* prevent any direct child from overflowing horizontally */
  overflow-x: hidden;
  max-width: 100vw;
}

/* ── Bottom Navigation Bar ────────────────────────────────── */
.bottom-nav {
  /* Hidden on desktop — revealed only on mobile */
  display: none;
}

@media (max-width: 767px) {
  /* ── Scroll direction lock ───────────────────────────────── */
  html, body { touch-action: pan-y; }

  /* overflow-x lock lives ONLY on html/body — applying it to any
     non-body ancestor of position:fixed children (like .app) can
     cause iOS Safari to blank the canvas or clip fixed elements.   */
  html, body { overflow-x: hidden; max-width: 100vw; }

  /* ── Push content above the bottom tab bar ───────────────── */
  .app-main { padding-bottom: 72px; }

  /* ── Top nav — slim on mobile ────────────────────────────── */
  .nav-toggle { display: none !important; }   /* bottom nav replaces hamburger */
  .topnav-inner { height: 52px; }
  .brand-name .ver { display: none; }
  .nav-cta { gap: 6px; }
  .nav-cta .btn { padding: 8px 12px; font-size: 11.5px; }

  /* ── Bottom nav bar ──────────────────────────────────────── */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 60;
    height: 64px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(10, 18, 30, 0.92);
    -webkit-backdrop-filter: saturate(150%) blur(20px);
            backdrop-filter: saturate(150%) blur(20px);
    border-top: 1px solid var(--hairline-strong);
    align-items: stretch;
    pointer-events: auto;
  }

  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 44px;
    padding: 6px 4px;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    text-decoration: none;
    font-family: var(--font-mono);
    transition: color var(--t-fast), background var(--t-fast);
    -webkit-tap-highlight-color: transparent;
    position: relative;
  }
  .bottom-nav-item.active { color: var(--accent); }
  .bottom-nav-item.active::before {
    content: "";
    position: absolute;
    top: 0; left: 20%; right: 20%;
    height: 2px;
    background: var(--accent);
    border-radius: 0 0 2px 2px;
    box-shadow: 0 0 8px var(--accent-glow);
  }
  .bottom-nav-item:active { background: rgba(0, 180, 216, 0.06); }

  .bottom-nav-icon {
    width: 24px; height: 24px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
  }
  .bottom-nav-icon svg {
    width: 22px; height: 22px;
    transition: transform var(--t-fast) var(--ease-out);
  }
  .bottom-nav-item.active .bottom-nav-icon svg {
    transform: translateY(-1px) scale(1.08);
  }
  .bottom-nav-label {
    font-size: 9.5px;
    letter-spacing: 0.04em;
    line-height: 1;
    text-transform: uppercase;
    white-space: nowrap;
  }

  /* ── Container gutters ───────────────────────────────────── */
  .container { width: 100%; padding-inline: 16px; }

  /* ── Grids → single column ───────────────────────────────── */
  .grid.cols-2,
  .grid.cols-3,
  .grid.cols-4 { grid-template-columns: 1fr; }

  /* Keep two-column author cards on cite page */
  div[style*="repeat(2, 1fr)"] { grid-template-columns: repeat(2, 1fr) !important; }

  /* ── Hero — compact ──────────────────────────────────────── */
  .hero { padding: 40px 0 24px; }

  /* ── CRITICAL: allow both hero grid cells to shrink below    ──
     their content's intrinsic width. Without min-width:0, a CSS
     grid cell containing white-space:pre text (terminal/code)
     expands to the longest line width (~540px), blowing the    ──
     layout on any screen narrower than that content.           */
  .hero-inner > div {
    min-width: 0;
    /* belt-and-suspenders: clip anything that still overflows  */
    overflow-x: hidden;
  }

  /* Display heading — smaller fluid scale for narrow screens */
  h1.display {
    font-size: clamp(1.8rem, 10vw, 3rem);
    line-height: 1.08;
    letter-spacing: -0.03em;
    max-width: 100%;
  }

  /* Eyebrow — long uppercase string must not overflow.
     Hide the decorative ::before line and let text truncate.  */
  .eyebrow {
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    letter-spacing: 0.10em;
    font-size: var(--fs-xs);
  }
  .eyebrow::before { display: none; }

  /* Subtitle and lede — override ch-based max-width */
  .subtitle,
  .lede {
    max-width: 100%;
  }

  /* Hero text column — merged: padding + stacking context for canvas overlay */
  .hero-inner > div:first-child {
    position: relative;
    z-index: 2;
  }

  /* CSS canvas-safe-zone vignette behind the text column */
  .hero-inner > div:first-child::before {
    content: "";
    position: absolute;
    inset: -32px -24px;
    border-radius: 12px;
    background: radial-gradient(
      ellipse 90% 100% at 50% 50%,
      rgba(10, 18, 30, 0.82) 0%,
      rgba(10, 18, 30, 0.55) 55%,
      transparent 100%
    );
    pointer-events: none;
    z-index: -1;
  }

  /* CTA buttons — left-aligned so overflow goes right, not both sides */
  .hero-cta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
  }
  .hero-cta-row .btn {
    flex-shrink: 1;
    min-width: 0;
    white-space: nowrap;
  }

  /* Badges — left-aligned, wrap freely */
  .hero-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-start;
    max-width: 100%;
  }
  .hero-chips .badge,
  .hero-chips > * {
    flex-shrink: 1;
    min-width: 0;
  }

  /* ── Terminal / code blocks ──────────────────────────────── */
  /* Outer box: constrained to cell width, clips visual overflow */
  .terminal,
  .code {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
  }
  /* Inner body: scrolls horizontally so pre content stays readable */
  .terminal-body,
  .code-body {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Don't set max-width here — let the scrollable area be full content width */
  }

  /* ── Docs sidebar → top bar ──────────────────────────────── */
  .docs-side {
    border-right: none;
    border-bottom: 1px solid var(--hairline);
    padding-bottom: 12px;
  }

  /* ── Tables — horizontal scroll ─────────────────────────── */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* ── Canvas: pointer-event passthrough ──────────────────── */
  .global-canvas-wrap {
    pointer-events: none !important;
    touch-action: none;
  }

  /* ── Author line: always one row, never wraps ────────────── */
  .footer-authors {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
    gap: 4px;
  }
  .footer-author-name,
  .footer-author-sep {
    font-size: 10px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* ── Footer grid ─────────────────────────────────────────── */
  .footer-grid { grid-template-columns: repeat(2, 1fr); gap: var(--sp-3); }
  footer.footer { padding: var(--sp-4) 0 var(--sp-3); margin-top: var(--sp-5); }
}

/* Small phones (≤ 390px) — extra squeeze */
@media (max-width: 390px) {
  .footer-authors { gap: 3px; }
  .footer-author-name, .footer-author-sep { font-size: 9px; }
  .bottom-nav-label { font-size: 8.5px; }
  .hero h1.display { letter-spacing: -0.05em; }
}
