/* =========================================================================
   Margin Studio
   Concept: marginalia — the margin is an active part of the page, not
   empty space. Folios, labels and annotations live out in the rail;
   the centrepiece is a stack of ruled sheets tilted in 3D space.
   ========================================================================= */

/* ---------- 1. Fonts (self-hosted, latin subset) ---------- */

@font-face {
  font-family: "Fraunces";
  src: url("/fonts/fraunces-var-latin.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
    U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212,
    U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("/fonts/ibm-plex-mono-400-latin.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("/fonts/ibm-plex-mono-500-latin.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

/* ---------- 2. Tokens ---------- */

:root {
  /* Print stock, ink, and one accent: the proofreader's red pencil. */
  --paper: #f5f1e8;
  --paper-raised: #fffdf7;
  --paper-sunk: #ece7da;
  --ink: #17150f;
  --ink-soft: #5c584c;
  --rule: #d8d2c4;
  /* Measured 5.47:1 on --paper. The brighter #c1440e came out at 4.54:1 —
     a technical AA pass with no headroom, which is not good enough for
     13px mono annotations. */
  --annot: #ad3b0b;

  /* Sheet lighting: a highlight edge and a defined border, so the stack
     reads as physical paper rather than flat rectangles. */
  --sheet-hi: #ffffff;
  --sheet-edge: #cdc6b5;

  --shadow-lift: 0 2px 4px rgb(23 21 15 / 0.04), 0 12px 28px rgb(23 21 15 / 0.07),
    0 40px 80px rgb(23 21 15 / 0.06);
  --grain-blend: multiply;
  --grain-opacity: 0.055;

  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;

  /* Fluid scale.
     The display size is bounded by viewport HEIGHT as well as width, via
     min(): on a short laptop screen a purely vw-based size pushes the last
     line below the fold. */
  --f-display: clamp(3.4rem, min(9.5vw, 14vh), 8rem);
  --f-h2: clamp(2rem, 5.2vw, 3.75rem);
  --f-h3: clamp(1.35rem, 2.4vw, 1.75rem);
  --f-lede: clamp(1.125rem, 1.15rem + 0.5vw, 1.4rem);
  --f-body: clamp(1rem, 0.96rem + 0.2vw, 1.0625rem);
  --f-mono: clamp(0.6875rem, 0.66rem + 0.15vw, 0.8125rem);

  /* Layout */
  --shell: 78rem;
  --rail: 9.5rem;
  --gutter: clamp(1.5rem, 3.5vw, 3rem);
  --pad: clamp(1.25rem, 4vw, 3.25rem);
  --section-gap: clamp(5rem, 12vh, 10rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141310;
    --paper-raised: #1e1c17;
    --paper-sunk: #100f0c;
    --ink: #ece7db;
    --ink-soft: #9c968a;
    --rule: #312e26;
    --annot: #e4702c;

    /* Dark mode needs far more separation than light: paper-on-paper at
       these luminances is otherwise invisible. */
    --sheet-hi: #353027;
    --sheet-edge: #4a443a;

    --shadow-lift: 0 2px 4px rgb(0 0 0 / 0.3), 0 12px 28px rgb(0 0 0 / 0.45),
      0 40px 80px rgb(0 0 0 / 0.4);
    --grain-blend: overlay;
    --grain-opacity: 0.09;
  }
}

/* Registered so the parallax values interpolate as numbers, not strings.
   Unsupported browsers still read them as plain custom properties. */
@property --mx {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}
@property --my {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

/* ---------- 3. Base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  /* Column flex so the footer sits at the bottom of short pages (the
     privacy policy) instead of floating halfway up. */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: var(--f-body);
  font-variation-settings: "opsz" 14, "wght" 400, "SOFT" 0, "WONK" 0;
  line-height: 1.65;
  /* `clip` rather than `hidden`: hidden would make body a scroll container
     and silently break `position: sticky` on the margin rail. */
  overflow-x: hidden;
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
}

/* Paper grain. Decorative, never interactive. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: var(--grain-opacity);
  mix-blend-mode: var(--grain-blend);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

a {
  color: inherit;
}

p {
  margin: 0 0 1.1em;
}

::selection {
  background: var(--annot);
  color: var(--paper-raised);
}

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

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: 0.75rem 1.25rem;
  background: var(--annot);
  color: #fff;
  font-family: var(--font-mono);
  font-size: var(--f-mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  z-index: 10000;
}
.skip:focus {
  left: 0.5rem;
  top: 0.5rem;
}

/* ---------- 4. Layout primitives ---------- */

.shell {
  max-width: var(--shell);
  margin-inline: auto;
  padding-inline: var(--pad);
}

/* Two-track grid: the margin rail, then the text column. */
.tracks {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  gap: var(--gutter);
  align-items: start;
}

.rail {
  position: sticky;
  top: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--ink);
}

.folio {
  font-family: var(--font-mono);
  font-size: var(--f-mono);
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--annot);
}

.label {
  font-family: var(--font-mono);
  font-size: var(--f-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* An annotation: red, mono, set as if pencilled into the margin. */
.note {
  font-family: var(--font-mono);
  font-size: var(--f-mono);
  line-height: 1.6;
  color: var(--annot);
  border-left: 1px solid var(--annot);
  padding-left: 0.75rem;
  margin-top: 0.5rem;
}

/* ---------- 5. Header ---------- */

.site-head {
  position: relative;
  z-index: 5;
  padding-block: clamp(1.5rem, 3vh, 2.5rem);
}

.site-head .shell {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  font-family: var(--font-display);
  font-variation-settings: "opsz" 48, "wght" 600, "SOFT" 20, "WONK" 1;
  font-size: 1.3rem;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.brand em {
  font-style: normal;
  color: var(--annot);
}

.site-nav {
  display: flex;
  gap: 1.5rem;
  font-family: var(--font-mono);
  font-size: var(--f-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.site-nav a {
  color: var(--ink-soft);
  text-decoration: none;
  padding-bottom: 2px;
  border-bottom: 1px solid transparent;
  transition: color 0.25s ease, border-color 0.25s ease;
}
.site-nav a:hover {
  color: var(--annot);
  border-bottom-color: var(--annot);
}

/* ---------- 6. Hero ---------- */

.hero {
  position: relative;
  padding-block: clamp(2rem, 6vh, 5rem) var(--section-gap);
}

/* The sheet stage anchors to the content column, not the viewport,
   so it bleeds off the shell edge by a controlled amount. */
.hero .shell {
  position: relative;
}

.hero-grid {
  position: relative;
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  gap: var(--gutter);
  align-items: start;
}

.hero-body {
  position: relative;
  z-index: 2;
}

.display {
  margin: 0;
  font-size: var(--f-display);
  /* opsz 144 is the display cut: high contrast, fine hairlines.
     WONK 1 turns on the quirky alternate letterforms. */
  font-variation-settings: "opsz" 144, "wght" 480, "SOFT" 0, "WONK" 1;
  line-height: 0.86;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

/* Two nested elements on purpose: `.line` owns the parallax transform,
   `.line-in` owns the reveal transform. One element cannot hold both,
   since the second `transform` would simply overwrite the first.

   Deliberately 2D. Putting the headline in a `preserve-3d` context with
   translateZ forces the browser to rasterize the text into a composited
   texture and then scale it, which softens the edges — unacceptable when
   the type is the design. Staggered translateX reads as depth anyway, and
   the genuine 3D lives in the sheet stage where it costs nothing. */
.display .line {
  display: block;
}

.display .line-in {
  display: block;
}

/* Each line drifts a different distance — the nearer it "is", the more it
   moves. Same cue the sheet stack uses, without the 3D cost. */
.display .line:nth-child(1) {
  transform: translateX(calc(var(--mx) * 4px));
}
.display .line:nth-child(2) {
  margin-left: 0.14em;
  transform: translateX(calc(var(--mx) * 10px));
}
.display .line:nth-child(3) {
  margin-left: 0.04em;
  transform: translateX(calc(var(--mx) * 17px));
}

/* "apps." gets the accent — the one word that names what they make. */
.display .accent {
  color: var(--annot);
}

.lede {
  max-width: 34ch;
  margin-top: clamp(1.75rem, 4vh, 2.75rem);
  font-size: var(--f-lede);
  font-variation-settings: "opsz" 24, "wght" 380, "SOFT" 30, "WONK" 0;
  color: var(--ink-soft);
  line-height: 1.5;
}

/* ---------- 7. The 3D sheet stack ---------- */

.stage {
  position: absolute;
  z-index: 1;
  right: calc(var(--pad) * -0.25);
  top: 50%;
  width: min(30rem, 42vw);
  aspect-ratio: 5 / 6;
  translate: 0 -50%;
  perspective: 1400px;
  perspective-origin: 60% 45%;
  pointer-events: none;
}

.sheets {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  /* Base tilt, then the live pointer parallax on top. */
  transform: rotateX(calc(8deg + var(--my) * -7deg))
    rotateY(calc(-22deg + var(--mx) * 11deg)) rotateZ(-3deg);
}

.sheet {
  position: absolute;
  inset: 0;
  /* A raking light across each sheet — the cheapest way to make a flat
     rectangle read as a physical surface tilted in space. */
  background: linear-gradient(
    152deg,
    var(--sheet-hi) 0%,
    var(--paper-raised) 42%,
    var(--paper-sunk) 100%
  );
  border: 1px solid var(--sheet-edge);
  box-shadow: var(--shadow-lift);
  overflow: hidden;
  backface-visibility: hidden;
}

/* The red margin rule — the detail the whole concept hangs on. */
.sheet::before {
  content: "";
  position: absolute;
  inset-block: 0;
  left: 17%;
  width: 1px;
  background: var(--annot);
  opacity: 0.45;
}

/* Ghost text: ruled lines standing in for body copy. */
.sheet::after {
  content: "";
  position: absolute;
  inset: 13% 9% 16% 23%;
  background: repeating-linear-gradient(
    to bottom,
    var(--rule) 0 1px,
    transparent 1px 15px
  );
  opacity: 0.85;
}

.sheet:nth-child(1) {
  transform: translateZ(-90px) translate(-9%, 7%) rotate(-5deg);
  opacity: 0.5;
}
.sheet:nth-child(2) {
  transform: translateZ(-45px) translate(-4.5%, 3.5%) rotate(-2.5deg);
  opacity: 0.72;
}
.sheet:nth-child(3) {
  transform: translateZ(0);
}
.sheet:nth-child(4) {
  transform: translateZ(45px) translate(4.5%, -3.5%) rotate(2deg);
}
/* The front sheet carries a struck-through line and a margin tick,
   like a page someone has actually marked up. */
.sheet:nth-child(5) {
  transform: translateZ(92px) translate(9.5%, -7.5%) rotate(4.5deg);
}
.sheet:nth-child(5)::after {
  inset: 18% 14% 22% 26%;
  background: repeating-linear-gradient(
    to bottom,
    var(--ink) 0 2px,
    transparent 2px 17px
  );
  opacity: 0.16;
}

.sheet-mark {
  position: absolute;
  left: 7%;
  top: 27%;
  width: 7%;
  height: 1.5px;
  background: var(--annot);
  transform: rotate(-14deg);
  opacity: 0.9;
}
.sheet-mark::after {
  content: "";
  position: absolute;
  left: 0;
  top: 260%;
  width: 62%;
  height: 1.5px;
  background: var(--annot);
  transform: rotate(6deg);
}

/* ---------- 8. Sections ---------- */

.section {
  padding-block: var(--section-gap);
  border-top: 1px solid var(--rule);
}

.section-title {
  margin: 0 0 clamp(1.5rem, 3vh, 2.25rem);
  font-size: var(--f-h2);
  font-variation-settings: "opsz" 96, "wght" 450, "SOFT" 0, "WONK" 1;
  line-height: 0.95;
  letter-spacing: -0.025em;
}

.section-body {
  max-width: 62ch;
}

.section-body > p:last-child {
  margin-bottom: 0;
}

/* ---------- 9. Work / Under Control ---------- */

.work-head {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.status {
  font-family: var(--font-mono);
  font-size: var(--f-mono);
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--annot);
  border: 1px solid var(--annot);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  white-space: nowrap;
}

.features {
  list-style: none;
  margin: clamp(2rem, 4vh, 3rem) 0 0;
  padding: 0;
  display: grid;
  gap: 1px;
  background: var(--rule);
  border-block: 1px solid var(--rule);
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
}

.features li {
  background: var(--paper);
  padding: clamp(1.25rem, 2.5vw, 1.75rem) clamp(1rem, 2vw, 1.5rem);
}

.features h3 {
  margin: 0 0 0.5rem;
  font-size: var(--f-h3);
  font-variation-settings: "opsz" 36, "wght" 500, "SOFT" 20, "WONK" 1;
  line-height: 1.15;
  letter-spacing: -0.015em;
}

.features p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
  line-height: 1.6;
}

.features .idx {
  display: block;
  margin-bottom: 0.9rem;
  font-family: var(--font-mono);
  font-size: var(--f-mono);
  font-weight: 500;
  letter-spacing: 0.1em;
  color: var(--annot);
}

/* Underlined link that draws itself on hover. */
.link {
  display: inline-block;
  margin-top: 2rem;
  font-family: var(--font-mono);
  font-size: var(--f-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--ink);
  padding-bottom: 3px;
  background-image: linear-gradient(var(--annot), var(--annot));
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 100% 1px;
  transition: background-size 0.3s ease, color 0.3s ease;
}
.link:hover {
  color: var(--annot);
  background-size: 100% 2px;
}
.link::after {
  content: " \2192";
}

/* ---------- 10. Studio note ---------- */

.studio-body p {
  font-size: var(--f-lede);
  font-variation-settings: "opsz" 24, "wght" 380, "SOFT" 30, "WONK" 0;
  line-height: 1.55;
  max-width: 46ch;
}

.studio-body p + p {
  color: var(--ink-soft);
}

/* ---------- 11. Footer ---------- */

main {
  flex: 1 0 auto;
}

.site-foot {
  flex-shrink: 0;
  border-top: 1px solid var(--ink);
  padding-block: clamp(2rem, 5vh, 3.5rem) clamp(2rem, 4vh, 3rem);
}

.foot-grid {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1.5rem 2rem;
  flex-wrap: wrap;
  font-family: var(--font-mono);
  font-size: var(--f-mono);
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

.foot-links {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.foot-links a {
  color: var(--ink-soft);
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 2px;
  transition: color 0.25s ease, border-color 0.25s ease;
}
.foot-links a:hover {
  color: var(--annot);
  border-bottom-color: var(--annot);
}

/* ---------- 12. Reveal choreography ---------- */

/* Only hide things when scripting is available to bring them back.
   Without JS (or without support for this query) content renders
   immediately — the animation is an enhancement, never a gate. */
@media (scripting: enabled) {
  [data-reveal] {
    opacity: 0;
    transform: translateY(1.5rem);
    transition: opacity 0.85s cubic-bezier(0.22, 1, 0.36, 1),
      transform 0.85s cubic-bezier(0.22, 1, 0.36, 1);
  }
  [data-reveal].is-in {
    opacity: 1;
    transform: none;
  }
  [data-reveal-delay="1"] { transition-delay: 0.09s; }
  [data-reveal-delay="2"] { transition-delay: 0.18s; }
  [data-reveal-delay="3"] { transition-delay: 0.27s; }
  [data-reveal-delay="4"] { transition-delay: 0.36s; }
  [data-reveal-delay="5"] { transition-delay: 0.45s; }
}

/* The sheet stack assembles itself once, on load. */
@keyframes sheet-settle {
  from {
    opacity: 0;
    transform: translateZ(0) translate(0, 14%) rotate(0deg);
  }
}

.sheet {
  animation: sheet-settle 1.1s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}
.sheet:nth-child(1) { animation-delay: 0.05s; }
.sheet:nth-child(2) { animation-delay: 0.14s; }
.sheet:nth-child(3) { animation-delay: 0.23s; }
.sheet:nth-child(4) { animation-delay: 0.32s; }
.sheet:nth-child(5) { animation-delay: 0.41s; }

/* Progressive enhancement: where scroll-linked animation is supported,
   the stack drifts gently as the hero leaves the viewport. */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .sheets {
      animation: stack-drift linear both;
      animation-timeline: view();
      animation-range: entry 40% exit 90%;
    }
    @keyframes stack-drift {
      to {
        translate: 0 -5%;
        rotate: 1.5deg;
      }
    }
  }
}

/* ---------- 13. Responsive ---------- */

@media (max-width: 62rem) {
  :root {
    --rail: 6.5rem;
  }
  .stage {
    width: min(24rem, 46vw);
    opacity: 0.55;
    right: calc(var(--pad) * -0.6);
  }
  .display {
    letter-spacing: -0.03em;
  }
}

@media (max-width: 46rem) {
  :root {
    --rail: 0px;
    --gutter: 0px;
  }
  .tracks,
  .hero-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  /* The rail reflows inline, above its section: folio and label share one
     line, the annotation drops to its own full-width line beneath. Without
     the wrap the label breaks across two lines and squeezes the note into
     a ~200px column. */
  .rail {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.75rem;
    margin-bottom: 1.75rem;
    padding-top: 0.6rem;
  }
  .note {
    flex-basis: 100%;
    border-left: 2px solid var(--annot);
    padding-left: 0.75rem;
    margin-top: 0.35rem;
    max-width: 38ch;
  }
  /* Behind the type, dimmed — depth without crowding the headline. */
  .stage {
    width: min(20rem, 76vw);
    right: -16%;
    top: 68%;
    opacity: 0.42;
  }
  .lede {
    max-width: none;
  }
}

/* ---------- 14. Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  /* Freeze the stack at its resting tilt, ignoring the pointer. */
  .sheets {
    transform: rotateX(8deg) rotateY(-22deg) rotateZ(-3deg);
  }
  .display .line {
    transform: none !important;
  }
  [data-reveal] {
    opacity: 1 !important;
    transform: none !important;
  }
}

/* ---------- 15. Document pages (privacy policy, etc.) ----------
   Shares the tokens and type, but stays a plain readable document:
   no 3D, no motion, generous measure. */

.doc {
  max-width: 44rem;
  margin-inline: auto;
  padding-block: clamp(2rem, 5vh, 4rem) clamp(4rem, 8vh, 6rem);
}

.doc h1 {
  margin: 0 0 1.5rem;
  font-size: clamp(2rem, 5vw, 3rem);
  font-variation-settings: "opsz" 72, "wght" 460, "SOFT" 0, "WONK" 1;
  line-height: 1.05;
  letter-spacing: -0.025em;
}

.doc h2 {
  margin: 2.5rem 0 0.75rem;
  font-size: var(--f-h3);
  font-variation-settings: "opsz" 36, "wght" 520, "SOFT" 20, "WONK" 0;
  line-height: 1.2;
}

.doc p,
.doc li {
  font-variation-settings: "opsz" 16, "wght" 400, "SOFT" 20, "WONK" 0;
  line-height: 1.7;
}

.doc a {
  color: var(--annot);
  text-underline-offset: 3px;
}

.doc .updated {
  font-family: var(--font-mono);
  font-size: var(--f-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 2rem;
}

.notice {
  border-left: 3px solid var(--annot);
  background: var(--paper-raised);
  padding: 1rem 1.25rem;
  margin: 2rem 0;
}
.notice strong {
  font-variation-settings: "opsz" 16, "wght" 600, "SOFT" 0, "WONK" 0;
  color: var(--annot);
}
