/* Site styles.

   Every color, font, size, and space comes from css/tokens.css. Do not write
   a color, a font name, or a pixel value here; add or change a token instead.
   The only fixed numbers are screen-width breakpoints (variables can't be used
   there), photo shapes, and the 1px box that hides screen-reader text.

   Layers, from weakest to strongest:
     reset      undo browser defaults
     base       plain elements: body, headings, links, focus
     layout     page structure: container, sections
     components header, hero, frame, photos, filters, viewer, footer
     utilities  single-purpose helpers */

@layer reset, base, layout, components, utilities;

/* ============================== reset ============================== */

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

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

  body,
  h1,
  h2,
  h3,
  p,
  figure,
  ul {
    margin: 0;
  }

  ul[role="list"] {
    padding: 0;
    list-style: none;
  }

  img,
  picture {
    display: block;
    max-inline-size: 100%;
  }

  img {
    block-size: auto;
  }

  button {
    font: inherit;
    color: inherit;
    cursor: pointer;
  }
}

/* ============================== base ============================== */

@layer base {
  html {
    /* Keeps headings clear of the sticky header when jumping to a section. */
    scroll-padding-top: calc(var(--header-height) + var(--space-4));
    scroll-behavior: smooth;
  }

  body {
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-text);
    font-size: var(--text-base);
    line-height: var(--leading-body);
    -webkit-font-smoothing: antialiased;
    overflow-wrap: break-word;
  }

  h1,
  h2,
  h3 {
    font-family: var(--font-display);
    font-weight: var(--weight-display);
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-display);
    text-wrap: balance;
  }

  h1 {
    font-size: var(--text-4xl);
  }

  h2 {
    font-size: var(--text-2xl);
  }

  p {
    max-inline-size: var(--measure);
  }

  a {
    color: inherit;
    text-underline-offset: 0.2em;
  }

  /* One visible focus style for everything that can be focused. */
  :focus-visible {
    outline: var(--focus-width) solid var(--color-focus);
    outline-offset: var(--focus-offset);
  }

  ::selection {
    background: var(--color-accent);
    color: var(--color-brand);
  }

  @media (prefers-reduced-motion: reduce) {
    html {
      scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-delay: 0ms !important;
      transition-duration: 0.01ms !important;
    }
  }
}

/* ============================== layout ============================== */

@layer layout {
  .container {
    inline-size: 100%;
    max-inline-size: var(--content-max);
    margin-inline: auto;
    padding-inline: var(--gutter);
  }

  .section {
    padding-block: var(--space-section);
  }

  .section--tight {
    padding-block-end: 0;
  }

  .on-brand {
    background: var(--color-brand);
    color: var(--color-on-brand);
  }

  .flow > * + * {
    margin-block-start: var(--space-5);
  }

  .page-head {
    padding-block: var(--space-8) var(--space-6);
  }

  /* Words beside a photo. */
  .split {
    display: grid;
    gap: var(--space-7);
    align-items: center;
  }

  @media (min-width: 56em) {
    .split {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: var(--space-9);
    }
  }
}

/* ============================== components ============================== */

@layer components {
  .skip-link {
    position: absolute;
    inset-block-start: var(--space-3);
    inset-inline-start: var(--space-3);
    z-index: 100;
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg);
    color: var(--color-text);
    transform: translateY(-300%);
  }

  .skip-link:focus {
    transform: none;
  }

  /* ---------- Small text ---------- */

  .lead {
    font-size: var(--text-lg);
  }

  /* ---------- Buttons ---------- */

  .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-block-size: var(--target-min);
    padding: var(--space-3) var(--space-6);
    border: var(--border-width-strong) solid var(--color-text);
    background: var(--color-text);
    color: var(--color-bg);
    font-weight: var(--weight-medium);
    line-height: var(--leading-snug);
    text-decoration: none;
    transition:
      background-color var(--duration-fast) var(--ease-out),
      color var(--duration-fast) var(--ease-out);
  }

  .button:hover {
    background: transparent;
    color: var(--color-text);
  }

  .on-brand .button {
    border-color: var(--color-on-brand);
    background: var(--color-on-brand);
    color: var(--color-brand);
  }

  .on-brand .button:hover {
    background: transparent;
    color: var(--color-on-brand);
  }

  /* ---------- Header and navigation ---------- */

  .site-header {
    position: sticky;
    inset-block-start: 0;
    z-index: 50;
  }

  .site-header__inner {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    column-gap: var(--space-5);
    min-block-size: var(--header-height);
  }

  .logo__mark {
    inline-size: var(--logo-width);
  }

  .site-footer .logo__mark {
    inline-size: var(--logo-width-footer);
  }

  .nav-toggle {
    min-block-size: var(--target-min);
    padding: var(--space-2) var(--space-4);
    border: var(--border-width) solid currentColor;
    background: transparent;
    font-weight: var(--weight-medium);
  }

  /* On phones the links open in a small panel under the Menu button. Without
     JavaScript, css/no-js.css shows the links and hides the button. */
  .site-nav {
    display: none;
    position: absolute;
    inset-block-start: 100%;
    inset-inline-end: var(--gutter);
    inline-size: min(var(--menu-width), calc(100% - 2 * var(--gutter)));
    padding: var(--space-2) var(--space-5);
    border: var(--border-width) solid var(--color-on-brand-muted);
    background: var(--color-brand);
  }

  .site-header.is-open .site-nav {
    display: block;
  }

  .site-nav a {
    display: flex;
    align-items: center;
    min-block-size: var(--target-min);
    font-weight: var(--weight-medium);
    text-decoration: none;
  }

  .site-nav a:hover,
  .site-nav a[aria-current="page"] {
    text-decoration: underline;
    text-decoration-color: var(--color-accent);
    text-decoration-thickness: var(--border-width-strong);
    text-underline-offset: 0.4em;
  }

  @media (min-width: 48em) {
    .site-header .logo__mark {
      inline-size: var(--logo-width-wide);
    }

    .nav-toggle {
      display: none;
    }

    .site-nav {
      display: block;
      position: static;
      inline-size: auto;
      padding: 0;
      border: 0;
    }

    .site-nav ul {
      display: flex;
      gap: var(--space-6);
    }
  }

  /* ---------- The frame (signature) ----------
     A beam on two posts, like the frame around "Endeavors" in the logo. It
     frames the About photo. On the home page, the logo itself is built. */

  .frame {
    position: relative;
    padding: calc(var(--frame-size) + var(--frame-gap));
    padding-block-end: 0;
  }

  .frame__beam,
  .frame__post {
    position: absolute;
    inset-block-start: 0;
    background: currentColor;
  }

  .frame__beam {
    inset-inline: 0;
    block-size: var(--frame-size);
  }

  .frame__post {
    inset-block-end: 0;
    inset-inline-start: 0;
    inline-size: var(--frame-size);
  }

  .frame__post--end {
    inset-inline: auto 0;
  }

  /* ---------- Home: the top ----------
     The logo is in three parts, stacked exactly on top of each other, so it
     can build itself: the frame rises, ENDEAVORS wipes in, BUILT drops into
     place. It stays still for visitors who ask for less motion. */

  .hero {
    position: relative;
    display: grid;
    place-items: center;
    overflow: hidden;
    min-block-size: max(var(--photo-min), calc(100svh - var(--header-height)));
    padding: var(--space-6) var(--gutter);
  }

  .hero picture {
    position: absolute;
    inset: 0;
  }

  .hero__photo {
    inline-size: 100%;
    block-size: 100%;
    object-fit: cover;
    filter: brightness(var(--hero-light));
  }

  .hero__words {
    position: relative;
    display: grid;
    justify-items: center;
    gap: var(--space-5);
    text-align: center;
  }

  .big-logo {
    display: grid;
    inline-size: var(--hero-logo);
  }

  .big-logo img {
    grid-area: 1 / 1;
    inline-size: 100%;
  }

  @media (prefers-reduced-motion: no-preference) {
    .hero__photo {
      animation: settle calc(4 * var(--duration-build)) var(--ease-out) both;
    }

    .big-logo__frame {
      animation: rise calc(1.5 * var(--duration-build)) var(--ease-out) both;
    }

    .big-logo__endeavors {
      animation: wipe var(--duration-build) var(--ease-out) calc(1.2 * var(--duration-build)) both;
    }

    .big-logo__built {
      animation: drop var(--duration-build) var(--ease-out) calc(1.8 * var(--duration-build)) both;
    }
  }

  @keyframes settle {
    from {
      transform: scale(1.14);
    }
  }

  @keyframes rise {
    from {
      clip-path: inset(100% 0 0);
    }

    to {
      clip-path: inset(0);
    }
  }

  @keyframes wipe {
    from {
      clip-path: inset(0 100% 0 0);
    }

    to {
      clip-path: inset(0);
    }
  }

  @keyframes drop {
    from {
      opacity: 0;
      transform: translateY(-30%);
    }
  }

  /* The small header logo waits until the big one has scrolled away. The
     script adds this class, so without JavaScript the small logo shows. */
  .site-header .logo {
    transition: opacity var(--duration-fast) var(--ease-out);
  }

  .site-header.is-over-hero .logo {
    visibility: hidden;
    opacity: 0;
  }

  /* ---------- Home: projects ----------
     Normal scrolling. Each name slides into view on black and leads into its
     photo. The photo opens to full width and moves a little slower than the
     page (parallax). Browsers that can't do this, and visitors who ask for
     less motion, see the same page without the movement.

     The photo is taller than its window, which hides the extra. The window
     must use "overflow: clip". With "hidden", the browser would follow the
     window instead of the page, and the photo would not move. */

  .project__name {
    padding: var(--space-section) var(--gutter);
    font-size: var(--text-project);
    line-height: 1;
    text-align: center;
    text-transform: uppercase;
  }

  .project__photo {
    --depth: var(--parallax);
    overflow: clip;
    block-size: min(calc(100svh - var(--header-height)), 90vw);
    min-block-size: var(--photo-min);
  }

  .project__photo picture {
    block-size: 100%;
  }

  .project__photo img {
    inline-size: 100%;
    block-size: calc(100% * var(--depth));
    object-fit: cover;
    /* Centered when there is no movement. */
    transform: translateY(calc((1 - var(--depth)) / var(--depth) * 50%));
  }

  .project--tall .project__photo {
    --depth: var(--parallax-tall);
    block-size: 133vw;
  }

  .project--tall img {
    object-position: 70% 50%;
  }

  /* On wide screens, a tall photo sits beside its name, so it stays large
     without being cropped down to a strip. */
  @media (min-width: 60em) {
    .project--tall {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      align-items: center;
    }

    .project--tall .project__photo {
      block-size: max(var(--photo-min), calc(100svh - var(--header-height)));
    }
  }

  @supports (animation-timeline: view()) {
    @media (prefers-reduced-motion: no-preference) {
      .project__name span {
        display: block;
        animation: wipe linear both;
        animation-timeline: view();
        animation-range: cover 5% cover 30%;
      }

      .project__photo {
        animation: open linear both;
        animation-timeline: view();
        animation-range: entry 0% entry 85%;
        view-timeline: --photo block;
      }

      .project__photo img {
        animation: parallax linear both;
        animation-timeline: --photo;
      }
    }
  }

  @keyframes open {
    from {
      clip-path: inset(0 14%);
    }

    to {
      clip-path: inset(0);
    }
  }

  @keyframes parallax {
    from {
      transform: translateY(calc((1 - var(--depth)) / var(--depth) * 100%));
    }

    to {
      transform: none;
    }
  }

  /* ---------- Home: closing section ----------
     "Built Right" inside the logo's frame. */

  .closing {
    padding: var(--space-section) var(--gutter);
    background: var(--color-bg);
    text-align: center;
  }

  .closing__inner {
    display: grid;
    justify-items: center;
    gap: var(--space-6);
  }

  .closing__statement {
    max-inline-size: 20ch;
    font-size: var(--text-4xl);
    text-transform: uppercase;
  }

  .closing .frame {
    padding: calc(var(--frame-size) + var(--space-5)) calc(var(--frame-size) + var(--space-6)) 0;
  }

  .closing__slogan {
    font-family: var(--font-display);
    font-size: var(--text-3xl);
    font-weight: var(--weight-display);
    line-height: var(--leading-tight);
    text-transform: uppercase;
    white-space: nowrap;
  }

  /* The beam slides across as the section scrolls into view. */
  @supports (animation-timeline: view()) {
    @media (prefers-reduced-motion: no-preference) {
      .closing .frame__beam {
        animation: wipe linear both;
        animation-timeline: view();
        animation-range: cover 5% cover 22%;
      }
    }
  }

  /* ---------- Photos ----------
     On the Work and About pages, every photo is one of two shapes: wide (3:2)
     or tall (3:4). */

  .photo {
    display: block;
    overflow: hidden;
    background: var(--color-surface);
  }

  .photo img {
    inline-size: 100%;
    aspect-ratio: 3 / 2;
    object-fit: cover;
    transition: transform var(--duration-slow) var(--ease-out);
  }

  .is-tall .photo img,
  .photo.is-tall img {
    aspect-ratio: 3 / 4;
  }

  @media (hover: hover) and (prefers-reduced-motion: no-preference) {
    .photo:hover img {
      transform: scale(1.02);
    }
  }

  .caption {
    margin-block-start: var(--space-2);
    font-size: var(--text-sm);
  }

  /* ---------- Work page ---------- */

  /* The filters need JavaScript. Without it, every photo is shown. */
  .filters {
    display: none;
  }

  .js .filters {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-block-end: var(--space-4);
  }

  .filter {
    min-block-size: var(--target-min);
    padding: var(--space-2) var(--space-4);
    border: var(--border-width) solid var(--color-muted);
    background: transparent;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
  }

  .filter:hover {
    border-color: var(--color-text);
  }

  .filter[aria-pressed="true"] {
    border-color: var(--color-text);
    background: var(--color-text);
    color: var(--color-bg);
  }

  .count {
    min-block-size: 1lh;
    margin-block-end: var(--space-5);
    font-size: var(--text-sm);
    color: var(--color-muted);
  }

  .gallery {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-5) var(--photo-gap);
  }

  .gallery > li {
    flex: 2 1 calc(1.5 * var(--gallery-row));
    min-inline-size: 0;
    max-inline-size: 100%;
  }

  .gallery > .is-tall {
    flex: 1 1 calc(0.75 * var(--gallery-row));
  }

  .gallery > [hidden] {
    display: none;
  }

  /* Fills the end of the last row so its photos don't stretch. Not needed
     on phones, where each wide photo fills its row. */
  @media (min-width: 48em) {
    .gallery::after {
      content: "";
      flex: 10 1 0;
    }
  }

  /* ---------- Photo viewer ---------- */

  .viewer {
    inline-size: 100%;
    block-size: 100%;
    max-inline-size: none;
    max-block-size: none;
    margin: 0;
    padding: var(--space-4);
    border: 0;
  }

  .viewer[open] {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: var(--space-3);
  }

  .viewer::backdrop {
    background: var(--color-brand);
  }

  .viewer__image {
    inline-size: 100%;
    block-size: 100%;
    object-fit: contain;
  }

  .viewer__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
  }

  .viewer__caption {
    font-size: var(--text-sm);
    text-align: center;
  }

  .viewer__button {
    min-block-size: var(--target-min);
    padding: var(--space-2) var(--space-4);
    border: var(--border-width) solid currentColor;
    background: transparent;
    font-weight: var(--weight-medium);
  }

  .viewer__close {
    margin-inline-start: auto;
  }

  /* ---------- Closing band and footer ---------- */

  .site-footer {
    padding-block: var(--space-8) var(--space-6);
    font-size: var(--text-sm);
  }

  .site-footer__top,
  .site-footer__base {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-5);
  }

  .site-footer__base {
    margin-block-start: var(--space-7);
    color: var(--color-on-brand-muted);
  }

  .site-footer ul {
    display: flex;
    gap: var(--space-5);
  }

  .site-footer li a {
    display: inline-flex;
    align-items: center;
    min-block-size: var(--target-min);
  }
}

/* ============================== utilities ============================== */

@layer utilities {
  .visually-hidden {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}
