/* ==========================================================================
   base.css — shared by every page
   Tokens, typography, header, footer, buttons, screenshot frame, sections.
   Page styles live in home.css / case-study.css; project-specific styles
   live next to each project (e.g. work/mailchimp/mailchimp.css).
   Two themes: dark (default) and light, set on <html data-theme> by an inline
   script in each page's <head> and switched with the header toggle (site.js).
   ========================================================================== */

:root {
  --bg: #0c0c0e;
  --bg-2: #111114;
  --surface: #16161a;
  --surface-2: #1d1d22;
  --ink: #f2f1ed;
  --ink-2: #d6d5d0;
  --muted: #a09fa6;
  --fg: 255, 255, 255;         /* rgb of the foreground, for translucent lines and fills: rgba(var(--fg), 0.08) */
  --bg-rgb: 12, 12, 14;        /* rgb of the page, for translucent bars */
  --line: rgba(var(--fg), 0.08);
  --line-strong: rgba(var(--fg), 0.18);
  /* the site itself is neutral; each case study sets its own project colour */
  --accent: #f2f1ed;
  --accent-ink: #0c0c0e;
  --accent-soft: rgba(var(--fg), 0.08);
  --hl: rgba(255, 221, 87, 0.3);    /* hand-drawn marker behind a heading or link you jumped to (site.js); case studies use their own colour */
  --todo: rgba(245, 196, 81, 0.16);
  --todo-ink: #f8d77f;
  --todo-line: rgba(245, 196, 81, 0.5);
  --shadow-shot: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 30px 60px -30px rgba(0, 0, 0, 0.8);
  --grain-opacity: 0.06;
  --grain-blend: screen;
  --grain-filter: none;

  --font: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;

  --fs-hero: clamp(2.4rem, 1.1rem + 3.5vw, 4.25rem);
  --fs-h1: clamp(2.3rem, 1.3rem + 3.8vw, 4.5rem);
  --fs-h2: clamp(1.7rem, 1.2rem + 1.9vw, 2.75rem);
  --fs-h3: clamp(1.15rem, 1rem + 0.5vw, 1.4rem);
  --fs-lead: clamp(1.1rem, 1rem + 0.4vw, 1.3rem);
  --fs-body: 1.0625rem;
  --fs-small: 0.92rem;
  --fs-label: 0.75rem;

  --gutter: clamp(16px, 4vw, 48px);
  --max: 1240px;
  --radius: 6px;               /* cards, panels and screenshot frames */
  --radius-lg: 8px;            /* large covers */
  --ease: cubic-bezier(0.2, 0.7, 0.1, 1);

  color-scheme: dark;
}

/* light theme: paper background, ink text; screens keep their own white */
:root[data-theme="light"] {
  --bg: #f6f6f3;
  --bg-2: #eeeeea;
  --surface: #ffffff;
  --surface-2: #f1f1ee;
  --ink: #141416;
  --ink-2: #393940;
  --muted: #66666e;
  --fg: 20, 20, 22;
  --bg-rgb: 246, 246, 243;
  --line: rgba(var(--fg), 0.1);
  --line-strong: rgba(var(--fg), 0.2);
  --accent: #141416;
  --accent-ink: #ffffff;
  --accent-soft: rgba(var(--fg), 0.06);
  --hl: rgba(255, 214, 10, 0.42);
  --todo: rgba(184, 132, 0, 0.12);
  --todo-ink: #7a5a00;
  --todo-line: rgba(140, 100, 0, 0.45);
  --shadow-shot: 0 18px 40px -26px rgba(20, 20, 30, 0.35);
  --grain-opacity: 0.05;
  --grain-blend: multiply;
  --grain-filter: invert(1);
  color-scheme: light;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
/* the page never scrolls sideways: pieces that reach to the window edge (the MailChimp backdrop, wide demos) are cut there.
   Without this, iPad Safari could widen the page to fit them, re-measure, and keep growing. clip keeps sticky elements working. */
html, body { overflow-x: hidden; }
@supports (overflow: clip) { html, body { overflow-x: clip; } }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs-body);
  font-weight: 400;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-numeric: tabular-nums;
}
/* the switch between themes eases instead of flashing (not on first paint) */
html.theme-anim body, html.theme-anim .site-header { transition: background-color 0.35s var(--ease), color 0.35s var(--ease); }
img { display: block; max-width: 100%; height: auto; }
svg { display: block; max-width: 100%; }
h1, h2, h3, h4 { margin: 0; font-weight: 500; line-height: 1.12; letter-spacing: -0.02em; text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }
ul, ol { margin: 0; padding: 0; }
strong, b { font-weight: 500; color: var(--ink); }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.22em; }
a:hover { color: var(--accent); }
::selection { background: var(--accent); color: var(--accent-ink); }

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

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: var(--gutter); top: -100px; z-index: 10;
  background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: 4px;
  font-size: var(--fs-label); font-weight: 500; text-decoration: none;
}
.skip:focus { top: 12px; color: var(--accent-ink); }

.wrap { width: 100%; max-width: var(--max); margin-inline: auto; padding-inline: var(--gutter); }

.label {
  font-size: var(--fs-label);
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  line-height: 1.5;
  color: var(--muted);
}
.label--accent { color: var(--accent); }
.muted { color: var(--muted); }

/* Draft placeholders — visible on purpose, remove before launch */
.todo {
  background: var(--todo); color: var(--todo-ink);
  border: 1px dashed var(--todo-line);
  border-radius: 4px; padding: 0.05em 0.4em;
  font-size: 0.82em; font-weight: 400; letter-spacing: 0; text-transform: none;
}

/* ---------- header ---------- */
.site-header { position: sticky; top: 0; z-index: 50; background: rgba(var(--bg-rgb), 0.82); backdrop-filter: saturate(140%) blur(12px); -webkit-backdrop-filter: saturate(140%) blur(12px); border-bottom: 1px solid var(--line); }
.site-header .wrap { display: flex; align-items: center; gap: 16px; min-height: 64px; }
.brand { display: inline-flex; align-items: center; margin-right: auto; text-decoration: none; font-weight: 500; font-size: 0.95rem; letter-spacing: 0.14em; text-transform: uppercase; white-space: nowrap; }
.brand:hover { color: var(--accent); }
.nav { position: relative; display: flex; gap: clamp(0px, 0.8vw, 12px); font-size: 0.92rem; }
.nav a { position: relative; z-index: 1; padding: 5px 10px; border-radius: 4px; text-decoration: none; color: var(--muted); font-weight: 400; transition: color 0.3s var(--ease); }
.nav__pill {
  position: absolute; left: 0; top: 0; z-index: 0; border-radius: 4px; background: rgba(var(--fg), 0.08);
  opacity: 0; pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.34, 1.26, 0.64, 1), width 0.3s cubic-bezier(0.34, 1.26, 0.64, 1), opacity 0.2s var(--ease);
}
.nav__pill.is-on { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .nav__pill { transition: opacity 0.2s; } }
.nav a:hover, .nav a[aria-current="page"] { color: var(--ink); }

/* header tools: the theme switch (always) and the menu button (phones) */
.header-tools { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 1px solid var(--line-strong); border-radius: 999px;
  background: transparent; color: var(--ink-2); cursor: pointer; transition: color 0.2s var(--ease), border-color 0.2s var(--ease), background-color 0.2s var(--ease);
}
.icon-btn:hover { color: var(--ink); border-color: var(--ink); }
.icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
/* sun in dark mode (switch to light), moon in light mode (switch to dark) */
/* theme switch (after 21st.dev's AnimatedThemeToggle): the sun shows in dark mode (switch to light), the moon in light.
   The outgoing icon shrinks while its lines un-draw; the incoming one grows and draws itself in. */
.theme-toggle .i-theme { width: 19px; height: 19px; stroke-width: 1.9; overflow: visible; }
.i-theme path {
  transform-box: fill-box; transform-origin: center; stroke-dasharray: 1; stroke-dashoffset: 0;
  transition: transform 0.7s var(--ease), stroke-dashoffset 0.45s var(--ease) 0.25s;
}
.i-theme .i-theme__moon, :root[data-theme="light"] .i-theme .i-theme__sun {
  transform: scale(0); stroke-dashoffset: 1; transition: transform 0.7s var(--ease), stroke-dashoffset 0.3s var(--ease);
}
:root[data-theme="light"] .i-theme .i-theme__moon {
  transform: none; stroke-dashoffset: 0; transition: transform 0.7s var(--ease), stroke-dashoffset 0.45s var(--ease) 0.25s;
}
.nav-toggle { display: none; }
.nav-toggle span { position: relative; display: block; width: 16px; height: 10px; }
.nav-toggle span::before, .nav-toggle span::after { content: ""; position: absolute; left: 0; right: 0; height: 1.6px; border-radius: 2px; background: currentColor; transition: transform 0.3s var(--ease), top 0.3s var(--ease); }
.nav-toggle span::before { top: 0; } .nav-toggle span::after { top: 8px; }
.site-header.is-open .nav-toggle span::before { top: 4px; transform: rotate(45deg); }
.site-header.is-open .nav-toggle span::after { top: 4px; transform: rotate(-45deg); }

/* phones and small tablets: the nav folds into a menu that drops below the header */
@media (max-width: 699px) {
  .brand { font-size: 0.85rem; letter-spacing: 0.1em; }
  .nav-toggle { display: grid; }
  .nav {
    position: absolute; top: 100%; left: 0; right: 0; display: grid; gap: 0; padding: 6px var(--gutter) 18px;
    background: rgba(var(--bg-rgb), 0.97); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--line);
    font-size: 1.15rem; visibility: hidden; opacity: 0; transform: translateY(-6px);
    transition: opacity 0.25s var(--ease), transform 0.25s var(--ease), visibility 0s linear 0.25s;
  }
  .site-header.is-open .nav { visibility: visible; opacity: 1; transform: none; transition: opacity 0.25s var(--ease), transform 0.25s var(--ease), visibility 0s; }
  .nav a { padding: 14px 0; border-bottom: 1px solid var(--line); color: var(--ink-2); }
  .nav a:last-child { border-bottom: 0; }
  .nav__pill { display: none; }
  /* without scripts the menu button does nothing, so the links stay visible in a row */
  html:not(.has-js) .nav { position: static; display: flex; visibility: visible; opacity: 1; transform: none; padding: 0; background: none; border: 0; font-size: 0.9rem; }
  html:not(.has-js) .nav a { padding: 5px 6px; border: 0; }
  html:not(.has-js) .nav-toggle { display: none; }
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 13px 22px; border-radius: 999px;
  font-size: 0.95rem; font-weight: 500; text-decoration: none;
  border: 1px solid var(--line-strong);
  transition: background-color 0.2s var(--ease), color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.btn--solid { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn--solid:hover { background: color-mix(in srgb, var(--accent) 86%, var(--bg)); color: var(--accent-ink); }
.btn--ghost:hover { border-color: var(--ink); color: var(--ink); }
.btn .arrow { transition: transform 0.2s var(--ease); }
.btn:hover .arrow { transform: translateX(3px); }


/* screenshot frame: product screens stay white in both themes */
.shot {
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: #fff; border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-shot);
}
.shot img { width: 100%; }
.shot--plain { background: var(--surface); }

/* images still loading shimmer softly; one that failed twice says so (site.js) */
.img-wait { background-image: linear-gradient(100deg, rgba(120, 124, 132, 0.07) 30%, rgba(120, 124, 132, 0.2) 50%, rgba(120, 124, 132, 0.07) 70%); background-size: 240% 100%; animation: img-wait 1.4s linear infinite; }
.img-wait img { opacity: 0; }
@keyframes img-wait { from { background-position: 130% 0; } to { background-position: -130% 0; } }
.img-failed { position: relative; min-height: 120px; }
.img-failed::after {
  content: "This screen didn't load. Refresh the page to try again."; position: absolute; inset: 0; display: grid; place-items: center; padding: 16px;
  background: #f4f5f8; color: #5d5e63; font-size: 0.88rem; text-align: center;
}
@media (prefers-reduced-motion: reduce) { .img-wait { animation: none; } }


/* ---------- sections ---------- */
.section { padding-block: clamp(72px, 10vw, 140px); }
.section--alt { background: var(--bg-2); border-block: 1px solid var(--line); }
.section-head { display: grid; gap: 16px; margin-bottom: clamp(36px, 5vw, 64px); }
@media (min-width: 900px) { .section-head { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); align-items: end; } }
.section-head h2 { font-size: var(--fs-h2); }
.section-head p { color: var(--muted); max-width: 36em; }
.kicker { display: block; margin-bottom: 14px; color: var(--accent); }


/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--line); padding-block: 28px 40px; color: var(--muted); font-size: 0.85rem; }
.site-footer .wrap { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }


/* ---------- motion ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
@media print {
  .site-header, .toc { display: none; }
  body { background: #fff; color: #000; }
}

/* ---------- grain texture ---------- */
body::after {
  content: ""; position: fixed; inset: 0; z-index: 60; pointer-events: none;
  opacity: var(--grain-opacity); mix-blend-mode: var(--grain-blend); filter: var(--grain-filter);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1.4 -0.2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
}
@media print { body::after { display: none; } }

/* ---------- back to top ---------- */
.to-top {
  position: fixed; right: clamp(16px, 3vw, 32px); bottom: clamp(16px, 3vw, 32px); z-index: 40;
  height: 44px; padding: 0 18px 0 14px; border-radius: 999px; display: inline-flex; align-items: center; gap: 8px;
  background: rgba(var(--bg-rgb), 0.88); color: var(--ink); border: 1px solid var(--line-strong);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font: inherit; font-size: 0.88rem; font-weight: 400; cursor: pointer; white-space: nowrap;
  opacity: 0; transform: translateY(12px); pointer-events: none;
  transition: opacity 0.25s var(--ease), transform 0.12s linear, border-color 0.2s var(--ease), color 0.2s var(--ease);
}
.to-top.is-visible { opacity: 1; transform: translateY(calc(-1 * var(--lift, 0px))); pointer-events: auto; }
.to-top:hover { border-color: var(--accent); color: var(--accent); }

main:focus { outline: none; }

/* arrival highlight (site.js): a transparent copy of the text behind the original carries a marker stroke per line,
   draws in left to right, then fades away. Colours come from --hl (each case study sets its own). */
.hl-host { position: relative; isolation: isolate; }
.hl-ghost { position: absolute; inset: 0; z-index: -1; pointer-events: none; color: transparent; transition: opacity 0.8s ease-out; }
.hl-ghost.is-fading { opacity: 0; }
.hl-ghost__t {
  background-repeat: no-repeat; background-position: left center; background-size: 0% 100%;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
  padding: 0 0.16em; margin: 0 -0.16em;
  transition: background-size 0.42s cubic-bezier(0.3, 0.7, 0.2, 1);
}
.hl-ghost__t.is-drawn { background-size: 100% 100%; }
/* a small coloured label would vanish into a marker of the same colour, so it reads in ink while marked */
.label { transition: color 0.4s var(--ease); }
.label.hl-host { color: var(--ink) !important; } /* outranks each project's label colour, only while marked */
.to-top__icon { font-size: 1rem; line-height: 1; }
