/* ---------------------------------------------------------------- */
/* Layers keep cascade order explicit without a preprocessor.       */
/* ---------------------------------------------------------------- */
@layer reset, tokens, base, layout, components, utilities;

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

  body {
    margin: 0;
  }

  img, svg {
    display: block;
    max-width: 100%;
  }
}

@layer tokens {
  :root {
    /* From the Figma hero (node 133:3663) */
    --bg: #FFF7E3;
    --fg: #000000;
    --muted: #6B6558;
    --rule: rgba(0, 0, 0, 0.12);

    --serif: 'PP Kyoto', Georgia, 'Times New Roman', serif;
    --mono: 'PP Right Serif Mono', ui-monospace, 'SF Mono', monospace;

    /* Container is wide; prose is separately constrained so long lines
       never run the full width. */
    --container: 1180px;
    --measure: 62ch;
    --gutter: clamp(1.25rem, 4vw, 3.5rem);

    --step--1: clamp(0.8rem, 0.76rem + 0.2vw, 0.9rem);
    --step-0: clamp(0.95rem, 0.9rem + 0.25vw, 1.08rem);
    --step-1: clamp(1.1rem, 1rem + 0.5vw, 1.4rem);
    --step-2: clamp(1.5rem, 1.2rem + 1.4vw, 2.4rem);
    --step-3: clamp(2.75rem, 1.6rem + 5.6vw, 7rem);

    /* Hero type + gaps, locked to Figma 1512×982 (node 133:3663).
       Preferred vw terms hit 72 / 16 / 22px and 20 / 47px at 1512. */
    --hero-title: clamp(3.25rem, 4.76vw, 5.5rem);
    --hero-sub: clamp(0.875rem, 1.058vw, 1.125rem);
    --hero-name: clamp(1.125rem, 1.455vw, 1.625rem);
    --hero-gap-sub: clamp(1rem, 1.32vw, 1.5rem);
    --hero-gap-name: clamp(2.25rem, 3.11vw, 3.5rem);

    --dot-size: 12px;
    --duration-fast: 200ms;
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
  }

  @font-face {
    font-family: 'PP Kyoto';
    src: url('../fonts/PPKyoto-Medium.woff2') format('woff2');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
  }

  @font-face {
    font-family: 'PP Kyoto';
    src: url('../fonts/PPKyoto-Extrabold.woff2') format('woff2');
    font-weight: 800;
    font-style: normal;
    font-display: swap;
  }

  @font-face {
    font-family: 'PP Right Serif Mono';
    src: url('../fonts/PPRightSerifMono-Regular.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
  }
}

@layer base {
  html {
    color-scheme: light;
  }

  body {
    background: var(--bg);
    color: var(--fg);
    font-family: var(--mono);
    font-size: var(--step-0);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
  }

  h1, h2 {
    font-family: var(--serif);
    font-weight: 500;
    margin: 0;
    text-wrap: balance;
  }

  p {
    text-wrap: pretty;
  }

  a {
    color: var(--fg);
    text-underline-offset: 0.2em;
  }

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

@layer layout {
  section {
    padding-block: clamp(3.5rem, 9vw, 8rem);
    border-bottom: 1px solid var(--rule);
  }

  /* Hero is a full-bleed title page; other sections stay in the measure. */
  section:not(.hero) {
    width: min(var(--container), 100%);
    margin-inline: auto;
    padding-inline: var(--gutter);
  }

  section:last-of-type {
    border-bottom: none;
  }

  .prose {
    max-width: var(--measure);
  }
}

@layer components {
  .skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--fg);
    color: var(--bg);
    padding: 0.75rem 1rem;
    z-index: 100;

    &:focus {
      left: var(--gutter);
      top: var(--gutter);
    }
  }

  /* -- Hero --
     Publication title page: three centred lines, Figma 133:3663.
     Desktop-first; clamp() tracks viewport width around the 1512 artboard. */
  .hero {
    min-height: 100svh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding-block: 0;
    padding-inline: var(--gutter);
    border-bottom: none;

    h1 {
      font-size: var(--hero-title);
      line-height: 1;
      white-space: nowrap;
    }

    .sub {
      font-size: var(--hero-sub);
      line-height: 1.125;
      margin: var(--hero-gap-sub) 0 0;
    }

    .name {
      font-family: var(--serif);
      font-weight: 800;
      font-size: var(--hero-name);
      line-height: 1;
      margin: var(--hero-gap-name) 0 0;
    }
  }

  /* JS hides the literal period once the floating dot takes over.
     Without JS the character simply stays put. */
  .hero-dot-anchor[data-dot-active='true'] {
    visibility: hidden;
  }

  /* -- Floating dot: hero -> scroll indicator -> cursor companion -- */
  .dot {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--dot-size);
    height: var(--dot-size);
    border-radius: 50%;
    background: var(--fg);
    pointer-events: none;
    opacity: 0;
    z-index: 50;
    transform: translate3d(-999px, -999px, 0);
    /* Transform is owned by the spring in dot.js — only opacity may
       transition here. The dot keeps one size at all times; hover is
       expressed by where it goes, not by how big it gets. */
    transition: opacity 240ms var(--ease);
  }

  /* -- Work / accordions -- */
  .work h2 {
    font-size: var(--step-2);
    margin-bottom: clamp(1.5rem, 3vw, 2.5rem);
  }

  .project {
    border-top: 1px solid var(--rule);

    &:last-of-type {
      border-bottom: 1px solid var(--rule);
    }

    summary {
      display: flex;
      align-items: baseline;
      gap: clamp(1rem, 4vw, 3rem);
      padding-block: clamp(1rem, 2vw, 1.5rem);
      cursor: pointer;
      list-style: none;

      &::-webkit-details-marker {
        display: none;
      }

      &::after {
        content: '+';
        color: var(--muted);
        margin-left: clamp(1rem, 3vw, 2.5rem);
        transition: rotate var(--duration-fast) var(--ease);
      }
    }

    &[open] summary::after {
      rotate: 45deg;
    }

    /* Native nesting has no Sass-style name concatenation — `&__name`
       is invalid and would drop the whole block. BEM elements are
       written out in full. */

    /* Progressive enhancement: animates where ::details-content is
       supported, snaps open where it isn't. */
    &::details-content {
      opacity: 0;
      block-size: 0;
      overflow: clip;
      transition: block-size 400ms var(--ease),
                  opacity 400ms var(--ease),
                  content-visibility 400ms var(--ease) allow-discrete;
    }

    &[open]::details-content {
      opacity: 1;
      block-size: auto;
    }
  }

  .project__name {
    font-size: var(--step-1);
  }

  .project__metric {
    color: var(--muted);
    font-size: var(--step--1);
    margin-left: auto;
    text-align: right;
  }

  .project__body {
    max-width: var(--measure);
    padding-bottom: clamp(1.25rem, 2.5vw, 2rem);

    p {
      margin: 0 0 0.75rem;
    }
  }

  .project__stack {
    color: var(--muted);
    font-size: var(--step--1);
  }

  /* -- Stack -- */
  .stack {
    display: grid;
    gap: clamp(2rem, 4vw, 3rem);
  }

  .stack__group {
    h2 {
      font-family: var(--mono);
      font-size: var(--step--1);
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: var(--muted);
      margin-bottom: 0.75rem;
    }

    p {
      max-width: 70ch;
      margin: 0;
    }
  }

  /* -- Contact -- */
  .contact {
    h2 {
      font-family: var(--mono);
      font-size: var(--step--1);
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: var(--muted);
      margin-bottom: 1rem;
    }

    p {
      margin: 0 0 0.5rem;
    }

    .tagline {
      color: var(--muted);
      margin-top: clamp(2rem, 4vw, 3rem);
    }
  }
}

@layer utilities {
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      animation-duration: 0.001ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.001ms !important;
    }
  }
}
