/* =====================================================================
   base.css: shared by every page
   Tokens, reset, links and micro-interactions, top bar, CTA, theme toggle,
   status dot, dithered thumbnails, cat mascot, footer, accessibility.
   ===================================================================== */

/* ---------- Tokens ---------- */
:root {
  --bg: #000;
  --fg: #fff;
  --fg-2: #bdbdbd;                 /* body copy, one step quieter than headings */
  --muted: #8f8f8f;
  --line: #262626;
  --accent: #b8a4ff;               /* lilac */
  --accent-text: #b8a4ff;
  --dither-back: #000;
  --dither-front: #b8a4ff;

  /* Type scale: s (meta) < body < l (sub-heads) < xl (titles, ledes) < xxl (callouts) */
  --fs: clamp(15px, 13.5px + .3vw, 18px);
  --fs-s: calc(var(--fs) * .82);
  --fs-l: clamp(18px, 16px + .45vw, 22px);
  --fs-xl: clamp(21px, 18px + .9vw, 28px);
  --fs-xxl: clamp(24px, 2.8vw, 36px);

  /* Layout: 20px gutter on phones → 48px on large screens, content capped at 1440px */
  --pad: clamp(20px, 2.5vw, 48px);
  --max: 1440px;
  --gutter: max(var(--pad), calc((100vw - var(--max)) / 2));

  --ease: cubic-bezier(.2, .8, .2, 1);
}
[data-theme="light"] {
  --bg: #fff;
  --fg: #000;
  --fg-2: #3a3a3a;
  --muted: #666;
  --line: #e5e5e5;
  --accent: #8f74f2;               /* non-text accents: focus ring, dot (3.5:1) */
  --accent-text: #5b3fd1;          /* text in accent colour (6.8:1) */
  --dither-back: hsl(0, 0%, 95%);
  --dither-front: #a690fb;
}

/* ---------- Reset ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: "Geist Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: var(--fs);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background .2s, color .2s;
}
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; height: auto; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--fg); color: var(--bg); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }

/* ---------- Links ----------
   site.js splits every text link into a label + a direction-aware arrow.
   The label gets a hairline underline that draws left → right and "decodes" on hover. */
.lbl {
  background: linear-gradient(currentColor, currentColor) 0 100% / 0 1px no-repeat;
  padding-bottom: 2px;
  transition: background-size .35s var(--ease);
}
a:hover .lbl, a:focus-visible .lbl { background-size: 100% 1px; }
.arr { display: inline-block; transition: transform .35s var(--ease); }
a:hover .arr-ne, a:focus-visible .arr-ne { transform: translate(2px, -2px); }
a:hover .arr-e, a:focus-visible .arr-e { transform: translateX(5px); }
a:hover .arr-w, a:focus-visible .arr-w { transform: translateX(-5px); }
a:hover .arr-s, a:focus-visible .arr-s { animation: nudge-down .8s var(--ease) infinite; }
@keyframes nudge-down { 0%, 100% { transform: none; } 50% { transform: translateY(3px); } }

/* Reveal on scroll (only when JS runs, so content is never hidden without it) */
.js .rv { opacity: 0; transform: translateY(10px); transition: opacity .6s var(--ease), transform .6s var(--ease); }
.js .rv.in { opacity: 1; transform: none; }

/* ---------- Theme toggle ---------- */
.toggle {
  background: none; border: 0; color: inherit; cursor: pointer;
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-grid; place-items: center;
}
.toggle:hover { background: color-mix(in srgb, var(--fg) 10%, transparent); }
.toggle svg { transition: transform .6s var(--ease); }
.toggle:hover svg { transform: rotate(45deg); }
.toggle.spin svg { animation: spin-in .6s var(--ease); }
@keyframes spin-in { from { transform: rotate(-120deg) scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
.toggle .sun { display: block; } .toggle .moon { display: none; }
[data-theme="light"] .toggle .sun { display: none; }
[data-theme="light"] .toggle .moon { display: block; }

/* ---------- Top bar (sticky on case studies, slides in after the hero on the homepage) ---------- */
.bar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 6px var(--gutter);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.bar nav { display: flex; align-items: center; gap: 20px; }

/* ---------- CTA: inverted fill that wipes across in pixel "steps" ---------- */
.cta {
  position: relative; isolation: isolate; overflow: hidden; display: inline-block;
  padding: 10px 16px; border: 1px solid var(--fg); background: var(--fg); color: var(--bg);
  transition: color 0s .12s;
}
.cta::before {
  content: ""; position: absolute; inset: 0; z-index: -1; background: var(--bg);
  transform: translateX(-101%); transition: transform .32s steps(8);
}
.cta:hover, .cta:focus-visible { color: var(--fg); }
.cta:hover::before, .cta:focus-visible::before { transform: none; }
.cta:active { transform: translateY(1px); }
.cta .lbl { background: none; }

/* ---------- "Live" status dot ---------- */
.dot { position: relative; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; transform: translateY(-1px); }
.dot::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%; background: var(--accent);
  animation: ping 2.4s var(--ease) infinite;
}
@keyframes ping { 0% { transform: scale(1); opacity: .7; } 70%, 100% { transform: scale(2.8); opacity: 0; } }
@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

/* ---------- Dithered thumbnail + viewfinder hover (project cards, "next project") ---------- */
.thumb { aspect-ratio: 4 / 3; background: var(--dither-back); position: relative; overflow: hidden; }
.thumb canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.thumb .label { position: absolute; left: 12px; bottom: 10px; font-size: 13px; background: var(--bg); padding: 2px 6px; }
.thumb::after {
  content: ""; position: absolute; inset: 10px; pointer-events: none;
  --c: var(--fg); --l: 16px;
  background:
    linear-gradient(var(--c), var(--c)) top left / var(--l) 1px, linear-gradient(var(--c), var(--c)) top left / 1px var(--l),
    linear-gradient(var(--c), var(--c)) top right / var(--l) 1px, linear-gradient(var(--c), var(--c)) top right / 1px var(--l),
    linear-gradient(var(--c), var(--c)) bottom left / var(--l) 1px, linear-gradient(var(--c), var(--c)) bottom left / 1px var(--l),
    linear-gradient(var(--c), var(--c)) bottom right / var(--l) 1px, linear-gradient(var(--c), var(--c)) bottom right / 1px var(--l);
  background-repeat: no-repeat;
  opacity: 0; transform: scale(1.06);
  transition: opacity .3s var(--ease), transform .4s var(--ease);
}
a:hover .thumb::after, a:focus-visible .thumb::after { opacity: 1; transform: none; }

/* ---------- Footer ---------- */
footer {
  padding: 24px var(--gutter);
  display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: space-between;
  font-size: var(--fs-s); border-top: 1px solid var(--line);
}

/* ---------- Cat mascot: body in text colour, eyes in background colour ---------- */
.cat { position: fixed; left: 0; bottom: 0; z-index: 40; pointer-events: none; will-change: transform; }
.cat canvas { display: block; image-rendering: pixelated; }
.cat .bubble {
  position: absolute; left: 50%; bottom: 100%; transform: translate(-50%, -4px);
  font-size: 12px; padding: 2px 6px; white-space: nowrap;
  background: var(--fg); color: var(--bg);
  opacity: 0; transition: opacity .2s;
}
.cat .bubble.on { opacity: 1; }

/* ---------- Responsive ----------
   > 1440       content capped at --max and centred (--gutter)
   901 – 1440   laptop / tablet landscape
   601 – 900    tablet portrait
   ≤ 600        phone */
@media (max-width: 900px) { .hide-sm { display: none; } }

/* Touch screens: tap targets ≥ 44px */
@media (pointer: coarse) {
  .bar nav a { padding-block: 12px; display: inline-block; }
}

/* Reduced motion: keep every state change, drop the movement */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; transition-delay: 0s !important; }
  .js .rv { opacity: 1; transform: none; }
}
