/* ---------- Tokens ----------
   Light theme: pencil on paper. Dark theme: clean lines on a drafting grid.
   The theme is set on <html data-theme> by the inline script in index.html. */
:root {
  color-scheme: light;
  --bg: #f3eee4;      /* sketchbook paper */
  --ink: #2e2d2a;     /* graphite */
  --muted: #7d786e;
  --line: rgba(46, 45, 42, 0.16);
  --glass: #4f93cf;   /* blue pencil: the creative side */
  --light: #cc7f12;   /* light passing through the lens */
  --accent: #cf4b3a;  /* small details, like the red ring on a real lens */
  --bg-rgb: 243, 238, 228;
  --leader: rgba(46, 45, 42, 0.5);

  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;

  --gutter: clamp(16px, 4vw, 56px);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111214;
  --ink: #ebe8e2;
  --muted: #8b8881;
  --line: rgba(235, 232, 226, 0.14);
  --glass: #8ecbf5;
  --light: #ffd074;
  --accent: #ef5d4a;
  --bg-rgb: 17, 18, 20;
  --leader: rgba(235, 232, 226, 0.4);
}

/* Paper grain over the whole page (light theme), generated by an SVG noise filter. */
:root:not([data-theme="dark"]) body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  opacity: 0.5;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.45  0 0 0 0 0.41  0 0 0 0 0.34  0 0 0 0.22 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { background: var(--bg); scroll-behavior: smooth; transition: background-color 0.4s; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 400; margin: 0 0 0.45em; letter-spacing: -0.015em; }
h1 { font-size: clamp(44px, 5.6vw, 84px); line-height: 1.02; }
h2 { font-size: clamp(34px, 3.8vw, 56px); line-height: 1.05; }
h3 { font-size: 1.4rem; line-height: 1.2; }
h1 em, h2 em { color: var(--muted); }
p { margin: 0 0 1em; }
a { color: inherit; }

.kicker {
  font: 500 12px var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 20px;
}
.kicker-glass { color: var(--glass); }

.btn {
  display: inline-block;
  padding: 13px 24px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font: 500 15px var(--sans);
  text-decoration: none;
  transition: background 0.2s, color 0.2s, transform 0.2s;
}
.btn:hover { transform: translateY(-2px); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--ink); }

/* ---------- Header ---------- */
.site-header {
  position: fixed;
  z-index: 20;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: max(18px, env(safe-area-inset-top)) var(--gutter) 18px;
  background: linear-gradient(var(--bg) 30%, transparent);
}
/* Logo: one file per theme, swapped with the theme. */
.logo { display: block; line-height: 0; }
.logo img { height: 42px; width: auto; }
:root:not([data-theme="dark"]) .logo .logo-dark,
:root[data-theme="dark"] .logo .logo-light { display: none; }
.nav { display: flex; align-items: center; gap: 28px; font: 500 12px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; }
.nav a { text-decoration: none; color: var(--muted); }
.nav a:hover { color: var(--ink); }
.nav .nav-cta { color: var(--ink); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; }
.nav .nav-cta:hover { border-color: var(--ink); }

/* Light / dark switch: a round icon button, set apart from the text links. */
.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: none;
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.3s;
}
.theme-toggle:hover { border-color: var(--ink); transform: rotate(-15deg); }
.theme-toggle svg { grid-area: 1 / 1; width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .i-moon { fill: currentColor; stroke: none; }
:root:not([data-theme="dark"]) .theme-toggle .i-sun,
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }

/* ---------- Story (pinned lens) ---------- */
.story { position: relative; }
.stage {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100lvh;
  overflow: hidden;
}
/* Faint drafting grid behind the drawing (dark theme). */
:root[data-theme="dark"] .stage {
  background-image: radial-gradient(rgba(235, 232, 226, 0.08) 1px, transparent 1px);
  background-size: 28px 28px;
  background-position: center;
}
#scene, #leaders, #labels { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#scene { opacity: 0; transition: opacity 1.2s ease; }
.ready #scene { opacity: 1; }
#leaders { overflow: visible; }
:root:not([data-theme="dark"]) #leaders { filter: url(#pencil); }
#leaders line { stroke: var(--leader); stroke-width: 1; }
#leaders circle { fill: var(--ink); }
#leaders .leader-glass { stroke: var(--glass); }
#leaders circle.leader-glass { fill: var(--glass); stroke: none; }

.label {
  position: absolute;
  left: 0; top: 0;
  white-space: nowrap;
  will-change: transform, opacity;
  opacity: 0;
  /* Soft halo so labels stay legible over the drawing. */
  text-shadow: 0 0 6px var(--bg), 0 0 12px var(--bg), 0 0 2px var(--bg);
}
.label b { display: block; font: 500 11px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.label span { display: block; font: 400 17px var(--serif); color: var(--ink); margin-top: 1px; }
.label-glass span { color: var(--glass); }
.label.right { text-align: right; }

.scrim {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(to right, var(--bg) 0%, rgba(var(--bg-rgb), 0.8) 26%, transparent 46%);
}

.legend {
  position: absolute;
  right: var(--gutter);
  bottom: 28px;
  display: flex;
  gap: 22px;
  font: 500 11px var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.legend span::before {
  content: "";
  display: inline-block;
  width: 18px;
  height: 0;
  border-top: 1.5px solid var(--ink);
  vertical-align: middle;
  margin-right: 8px;
}
.legend .legend-glass::before { border-color: var(--glass); }

.chapters {
  position: relative;
  z-index: 2;
  margin-top: -100vh;
  margin-top: -100lvh;
  pointer-events: none;
}
.chapter {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: min(500px, 40vw);
  padding: 0 0 0 var(--gutter);
  opacity: 0.12;
  transform: translateY(24px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}
.chapter.is-active { opacity: 1; transform: none; }
.chapter > * { pointer-events: auto; }
.chapter p:not(.kicker) { color: var(--muted); font-size: 17px; }
.chapter .lede { color: var(--ink); font-size: 19px; }
.chapter-hero { max-width: min(620px, 46vw); }
.actions { margin-top: 12px; display: flex; gap: 12px; flex-wrap: wrap; }

.hint {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  margin-top: 20px;
  align-self: flex-start;
  font: 500 12px var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
  transition: opacity 0.4s;
}
.hint-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  transition: background 0.2s, color 0.2s;
}
.hint-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; animation: nudge 1.8s ease-in-out infinite; }
.hint:hover .hint-icon { background: var(--ink); color: var(--bg); }
@keyframes nudge {
  0%, 100% { transform: translateY(-3px); }
  50% { transform: translateY(4px); }
}

.no-webgl .stage { display: none; }
.no-webgl .chapters { margin-top: 0; }
.no-webgl .chapter { opacity: 1; transform: none; min-height: 70vh; max-width: 640px; }

/* ---------- Regular sections ---------- */
.section { position: relative; z-index: 4; background: var(--bg); padding: 120px 0; border-top: 1px solid var(--line); }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 var(--gutter); }
.section h2 { max-width: 760px; margin-bottom: 56px; }

.tag { font: 500 11px var(--mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--glass); margin-bottom: 12px; }
.tag-mech { color: var(--muted); }

.case {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 64px;
  align-items: start;
  padding-bottom: 64px;
  margin-bottom: 64px;
  border-bottom: 1px solid var(--line);
}
.case h3 { font-size: clamp(26px, 2.6vw, 36px); }
.case-text p:not(.tag) { color: var(--muted); }

.spec { margin: 0; border: 1px solid var(--line); font: 400 13px var(--mono); }
.spec div { display: flex; justify-content: space-between; gap: 16px; padding: 13px 18px; border-bottom: 1px solid var(--line); }
.spec div:last-child { border-bottom: 0; }
.spec dt { color: var(--ink); }
.spec dd { margin: 0; color: var(--ink); }
.spec dd.g { color: var(--glass); }
.spec .spec-head { text-transform: uppercase; letter-spacing: 0.08em; font-size: 11px; }
.spec .spec-head dt, .spec .spec-head dd { color: var(--muted); }
.spec .spec-total { border-top: 1px solid var(--ink); }
.spec .spec-total dd { font: 400 28px/1 var(--serif); color: var(--light); }
.spec .spec-total dt { align-self: center; }

/* Case study photos: one wide image, two smaller ones beside it. */
.case-gallery {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  align-items: start;
}
.case-gallery > :first-child { grid-row: span 2; }
.case-gallery > :not(:first-child) { aspect-ratio: auto; height: 100%; }

.projects { display: grid; grid-template-columns: repeat(3, 1fr); gap: 56px 32px; }
.project p:not(.tag):not(.meta) { color: var(--muted); font-size: 15px; margin: 0 0 14px; }
.project .ph, .project .shot { margin-bottom: 20px; }
.tag-both { color: var(--ink); }

/* What I did on a project: small outlined chips. */
.did { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.did li { padding: 3px 10px; border: 1px solid var(--line); border-radius: 999px; font: 400 12px var(--mono); color: var(--muted); }
.meta { margin: 0; font: 400 12px var(--mono); color: var(--muted); }

/* Real photos: fill their frame, cropped to the given ratio. */
.shot { display: block; width: 100%; aspect-ratio: var(--ratio, 4 / 3); object-fit: cover; }

/* Placeholders for photos still to find: dashed frame with crop marks and a note on what goes here. */
.ph {
  --m: 14px;
  position: relative;
  aspect-ratio: var(--ratio, 4 / 3);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 20px;
  text-align: center;
  border: 1px dashed var(--muted);
  background:
    linear-gradient(var(--glass), var(--glass)) top -1px left -1px / var(--m) 1.5px,
    linear-gradient(var(--glass), var(--glass)) top -1px left -1px / 1.5px var(--m),
    linear-gradient(var(--glass), var(--glass)) bottom -1px right -1px / var(--m) 1.5px,
    linear-gradient(var(--glass), var(--glass)) bottom -1px right -1px / 1.5px var(--m),
    rgba(var(--bg-rgb), 0.5);
  background-repeat: no-repeat;
}
.ph-label { font: 400 15px/1.4 var(--serif); color: var(--ink); max-width: 30ch; }
.ph-spec { font: 400 11px var(--mono); letter-spacing: 0.04em; color: var(--muted); }
.ph-main .ph-label { font-size: 19px; }

.steps { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 32px; counter-reset: step; }
.steps li { counter-increment: step; padding-top: 22px; border-top: 1px solid var(--ink); }
.steps li::before {
  content: counter(step, decimal-leading-zero);
  display: block;
  font: 500 12px var(--mono);
  color: var(--glass);
  margin-bottom: 14px;
}
.steps p { color: var(--muted); font-size: 15px; }

.about { display: grid; grid-template-columns: 1fr 1.4fr; gap: 80px; align-items: center; }
.about h2 { margin-bottom: 28px; }
.about p:not(.kicker) { color: var(--muted); font-size: 18px; }
/* Portrait framed with photographer's crop marks. */
.portrait {
  position: relative;
  aspect-ratio: 4 / 5;
  max-width: 400px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  font: 500 11px var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  --m: 18px;
  background:
    linear-gradient(var(--glass), var(--glass)) top -1px left -1px / var(--m) 1.5px,
    linear-gradient(var(--glass), var(--glass)) top -1px left -1px / 1.5px var(--m),
    linear-gradient(var(--glass), var(--glass)) bottom -1px right -1px / var(--m) 1.5px,
    linear-gradient(var(--glass), var(--glass)) bottom -1px right -1px / 1.5px var(--m);
  background-repeat: no-repeat;
}
.portrait img { position: absolute; inset: 12px; width: calc(100% - 24px); height: calc(100% - 24px); object-fit: cover; }

.contact { text-align: center; padding: 140px 0; }
.contact h2 { margin: 0 auto 20px; }
.contact > .wrap > p:not(.kicker) { color: var(--muted); font-size: 19px; max-width: 560px; margin: 0 auto 48px; }

/* ---------- Contact form ---------- */
.contact-form { max-width: 640px; margin: 0 auto; text-align: left; }
.contact-form .fields { display: grid; gap: 22px; }
.contact-form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }

.topics { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.topics legend,
.field > span {
  display: block;
  margin-bottom: 10px;
  font: 500 11px var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.field em { font-style: normal; opacity: 0.7; text-transform: none; letter-spacing: 0; }
/* Topic choices as pills; the radio itself is visually hidden but still focusable. */
.topics label { position: relative; cursor: pointer; }
.topics input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.topics label {
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 15px;
  color: var(--muted);
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.topics label:hover { border-color: var(--ink); color: var(--ink); }
.topics label:has(input:checked) { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.topics label:has(input:focus-visible) { outline: 2px solid var(--glass); outline-offset: 2px; }

.field input,
.field textarea {
  width: 100%;
  padding: 12px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: 400 17px var(--sans);
  transition: border-color 0.2s;
}
.field textarea { resize: vertical; min-height: 120px; line-height: 1.5; }
.field input:focus,
.field textarea:focus { outline: none; border-bottom-color: var(--glass); }
.field textarea::placeholder { color: var(--muted); opacity: 0.7; }

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.form-foot { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; margin-top: 8px; }
.form-foot .btn { cursor: pointer; }
.form-foot .btn:disabled { opacity: 0.5; cursor: wait; transform: none; }
.privacy { margin: 0; font-size: 14px; color: var(--muted); }

.form-status { margin: 20px 0 0; font-size: 16px; color: var(--muted); }
.form-status:empty { display: none; }
.form-status.error { color: var(--accent); }
/* After sending, the form makes way for the thank-you note. */
.contact-form.sent .fields { display: none; }
.contact-form.sent .form-status { margin: 0; text-align: center; font: 400 clamp(22px, 2.4vw, 30px)/1.3 var(--serif); color: var(--ink); }

.site-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding: 28px var(--gutter) max(28px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  font: 400 12px var(--mono);
  color: var(--muted);
}
.site-footer .logo img { height: 30px; }

/* ---------- Stacked layout: portrait phones and tablets ----------
   Keep this query in sync with stackedMQ in main.js. */
@media (max-aspect-ratio: 11/10), (max-width: 760px) {
  .nav a:not(.nav-cta) { display: none; }
  .nav { gap: 10px; }
  .site-header .logo img { height: 34px; }
  .scrim { background: linear-gradient(to bottom, transparent 46%, rgba(var(--bg-rgb), 0.88) 62%, var(--bg) 78%); }
  .legend { display: none; }
  .chapter,
  .chapter-hero {
    max-width: 620px;
    min-height: 100vh;
    min-height: 100svh;
    justify-content: flex-end;
    padding: 0 var(--gutter) calc(8vh + env(safe-area-inset-bottom));
  }
  .chapter-hero { padding-bottom: calc(14vh + env(safe-area-inset-bottom)); }
  h1 { font-size: clamp(38px, 10vw, 64px); }
  h2 { font-size: clamp(30px, 8vw, 48px); }
  .chapter p:not(.kicker) { font-size: 15px; }
  .chapter .lede { font-size: 16px; }
  .label b { display: none; }
  .label span { font-size: 13px; }
  .hint { margin-top: 8px; }
  .hint-icon { width: 40px; height: 40px; }
}

@media (max-width: 900px) {
  .section { padding: 88px 0; }
  .case, .about { grid-template-columns: 1fr; gap: 40px; }
  .projects { grid-template-columns: repeat(2, 1fr); gap: 48px 24px; }
  .case-gallery { grid-template-columns: 1fr; }
  .case-gallery > :first-child { grid-row: auto; }
  .case-gallery > :not(:first-child) { aspect-ratio: var(--ratio); height: auto; }
  .steps { grid-template-columns: repeat(2, 1fr); }
  .portrait { max-width: 300px; }
}
@media (max-width: 560px) {
  .steps { grid-template-columns: 1fr; }
  .contact-form .row { grid-template-columns: 1fr; }
  .projects { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .chapter { transition: none; transform: none; }
  .hint-icon svg { animation: none; }
}
