@layer global, component, utility;

@layer global {

  /* Fonts */
  :root {
    --fs-14: calc(14 / 16 * 1rem);
    --fs-16: calc(16 / 16 * 1rem);
    --fs-18: calc(18 / 16 * 1rem);
    --fs-24: calc(24 / 16 * 1rem);
    --fs-36: calc(36 / 16 * 1rem);
    --fs-42: calc(42 / 16 * 1rem);
    --fs-48: calc(48 / 16 * 1rem);
    --fs-72: calc(72 / 16 * 1rem);

    --font-size-menu: var(--fs-16);
    --font-size-h1: var(--fs-42);
    --font-size-h2: var(--fs-24);

    @media (width >= 37.5rem) {
      --font-size-h1: var(--fs-72);
      --font-size-h2: var(--fs-36);
    }
  }

  /* Colours */
  :root {
    --c-white: hsl(0, 0%, 100%);
    --c-gray-dark: hsl(233, 14%, 25%);
    --c-gray-mid: hsl(233, 8%, 45%);
    --c-gray-light: hsl(233, 10%, 94%);
    --c-gray-line: hsl(233, 10%, 86%);
    --c-purple: hsl(232, 58%, 55%);

    --color-main-bg: var(--c-white);
    --color-text-dark: var(--c-gray-dark);
    --color-text-muted: var(--c-gray-mid);
    --color-placeholder-bg: var(--c-gray-light);
    --color-line: var(--c-gray-line);
    --color-accent: var(--c-purple);
  }

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

  * {
    margin: 0;
  }

  html {
    scroll-behavior: smooth;
  }

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

  body {
    min-height: 100svh;
    display: flex;
    flex-direction: column;
    font-family: "Helvetica Neue", -apple-system, BlinkMacSystemFont, "Inter", Helvetica, Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--color-text-dark);
    background-color: var(--color-main-bg);
  }

  main {
    flex: 1;
  }

  h1,
  h2,
  h3 {
    line-height: 1.1;
  }

  h1 {
    font-size: var(--font-size-h1);
  }
  h2 {
    font-size: var(--font-size-h2);
  }

  a {
    text-decoration: none;
    color: inherit;
  }

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

  :focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 3px;
  }

  .wrapper {
    width: min(calc(100% - 48px), calc(1200 / 16 * 1rem));
    margin-inline: auto;
  }
}

@layer component {
  /* ---------- Header (all pages) ---------- */
  .site-header {
    position: sticky;
    top: 0;
    z-index: 60;
    padding-block: 1.25rem;
    background: var(--color-main-bg);

    .wrapper {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 1rem;
    }
  }

  .logo {
    display: inline-block;
  }

  .logo__img {
    height: 2.5rem;
    width: auto;
  }

  .menu__button {
    padding: 0.5rem 0;
    font: inherit;
    font-size: var(--fs-18);
    font-weight: 700;
    color: var(--color-text-dark);
    background: none;
    border: 0;
    cursor: pointer;

    &:hover {
      color: var(--color-accent);
    }
  }

  /* ---------- Full-screen menu ---------- */
  .menu-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    padding: 6rem 0 3rem;
    background: var(--color-main-bg);
    overflow-y: auto;

    &[hidden] {
      display: none;
    }
  }

  .menu-overlay__list {
    width: min(calc(100% - 48px), calc(1200 / 16 * 1rem));
    margin-inline: auto;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 0.5rem;
  }

  .menu-overlay__link {
    display: inline-block;
    font-size: clamp(2.75rem, 10vw, 6rem);
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.02em;

    &:hover {
      color: var(--color-accent);
    }

    &[aria-current="page"] {
      text-decoration: underline;
      text-decoration-thickness: 0.06em;
      text-underline-offset: 0.12em;
    }
  }

  body.menu-open {
    overflow: hidden;
  }

  /* ---------- Home page ---------- */
  .hero {
    padding-block: clamp(4rem, 12vw, 9rem) clamp(3rem, 8vw, 6rem);
  }

  .hero__title {
    max-width: 18ch;
    font-size: clamp(2.5rem, 7vw, 5.5rem);
    font-weight: 400;
    line-height: 1.05;
    letter-spacing: -0.025em;
  }

  .hero__text {
    max-width: 40ch;
    margin-top: 2rem;
    font-size: var(--fs-24);
    line-height: 1.35;
    color: var(--color-text-muted);
  }

  .text-link {
    display: inline-block;
    margin-top: 1.5rem;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 4px;

    &:hover {
      color: var(--color-accent);
    }
  }

  .feature {
    padding-block: clamp(3rem, 8vw, 6rem);
    border-top: 1px solid var(--color-line);
  }

  .feature__title {
    font-size: clamp(2rem, 5vw, 3.5rem);
    letter-spacing: -0.02em;
  }

  .feature__text {
    max-width: 40ch;
    margin-top: 1rem;
    font-size: var(--fs-18);
    color: var(--color-text-muted);
  }

  .feature__image {
    display: block;
    margin-top: 2.5rem;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background: var(--color-placeholder-bg);

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }

  /* ---------- Inner page layout ---------- */
  .page {
    padding-block: 3rem 5rem;

    h1 {
      margin-bottom: 1rem;
    }
  }

  .page__intro {
    max-width: 60ch;
    margin-bottom: 3rem;
    font-size: var(--fs-18);
    color: var(--color-text-muted);
  }

  .section + .section {
    margin-top: 5rem;
  }

  .section__title {
    margin-bottom: 1.5rem;
  }

  /* ---------- Engineering: videos ---------- */
  .video-grid {
    display: grid;
    gap: 3rem 2rem;

    @media (width >= 56rem) {
      grid-template-columns: 1fr 1fr;
    }
  }

  .video__frame {
    position: relative;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background: var(--color-placeholder-bg);
    border-radius: 0.5rem;

    iframe,
    video {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      border: 0;
    }
  }

  .video__placeholder {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--color-text-muted);
  }

  .video__title {
    margin-top: 1rem;
    font-size: var(--fs-24);
  }

  .video__caption {
    margin-top: 0.25rem;
    color: var(--color-text-muted);
  }

  /* ---------- Engineering: project gallery (3 x 3) ---------- */
  .project-grid {
    --project-ratio: 4 / 3;
    display: grid;
    gap: 2rem 0.75rem;
    padding: 0;
    list-style: none;

    @media (width >= 48rem) {
      grid-template-columns: repeat(3, 1fr);
    }

    img {
      width: 100%;
      aspect-ratio: var(--project-ratio);
      object-fit: cover;
      background: var(--color-placeholder-bg);
    }
  }

  .project__caption {
    margin-top: 0.75rem;
    font-size: var(--fs-16);
    color: var(--color-text-muted);
  }

  /* ---------- Photography ---------- */
  .section__title {
    font-size: clamp(2rem, 5vw, 3.5rem);
    letter-spacing: -0.02em;
  }

  /* Commercial: clients (logo + quote) */
  .clients {
    display: grid;
    gap: 3rem;
    margin-bottom: 3rem;

    @media (width >= 48rem) {
      grid-template-columns: 1fr 1fr;
      gap: 2rem;
    }
  }

  .client__logo {
    height: 3.5rem;
    width: auto;
    min-width: 8rem;
    margin-bottom: 1.5rem;
    object-fit: contain;
    object-position: left center;
  }

  .client__quote {
    max-width: 40ch;
    font-size: var(--fs-24);
    line-height: 1.35;

    p::before { content: "\201C"; }
    p::after { content: "\201D"; }
  }

  .client__quote footer {
    margin-top: 0.75rem;
    font-size: var(--fs-16);
    color: var(--color-text-muted);
  }

  .client__quote.page__quote {
    max-width: 55ch;
    margin-bottom: 4rem;
  }

  .client__quote footer a {
    font-weight: 700;
    color: var(--color-text-dark);
    text-decoration: underline;
    text-underline-offset: 3px;

    &:hover {
      color: var(--color-accent);
    }
  }

  /* Commercial: picture rows (3 pictures, then 2) */
  .photo-row {
    --row-ratio: 3 / 2;
    display: grid;
    gap: 0.75rem;
    margin: 0;
    padding: 2rem 0 0;
    list-style: none;
    border-top: 1px solid var(--color-line);

    @media (width >= 48rem) {
      &.photo-row--3 { grid-template-columns: repeat(3, 1fr); }
      &.photo-row--2 { grid-template-columns: repeat(2, 1fr); }
    }

    img {
      width: 100%;
      aspect-ratio: var(--row-ratio);
      object-fit: cover;
      background: var(--color-placeholder-bg);
    }
  }

  .photo-row--2 {
    margin-top: 2rem;
  }

  /* Portrait + Macro: photos keep their own shape (no cropping) */
  .gallery {
    columns: 2;
    column-gap: 0.75rem;
    padding: 0;
    list-style: none;

    @media (width >= 48rem) {
      columns: 3;
    }

    li {
      break-inside: avoid;
      margin-bottom: 0.75rem;
    }

    img {
      width: 100%;
      height: auto;
      min-height: 10rem;
      background: var(--color-placeholder-bg);
    }
  }

  /* ---------- About ---------- */
  .about {
    display: grid;
    gap: 2.5rem;

    @media (width >= 48rem) {
      grid-template-columns: 1fr 1.4fr;
      align-items: start;
    }
  }

  .about__portrait {
    aspect-ratio: 4 / 5;
    width: 100%;
    object-fit: cover;
    background: var(--color-placeholder-bg);
  }

  .about__text {
    max-width: 60ch;

    p + p {
      margin-top: 1rem;
    }

    a {
      text-decoration: underline;
      text-underline-offset: 3px;
    }
  }

  /* ---------- Footer ---------- */
  .site-footer {
    padding-block: 2rem;
    border-top: 1px solid var(--color-line);
    font-size: var(--fs-14);
    color: var(--color-text-muted);
  }
}

@layer utility {
  .visually-hidden {
    position: absolute;
    left: -10000px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;

    &.skip:focus {
      left: 0;
      width: auto;
      height: auto;
      background: #fff;
      padding: 10px;
      border: 1px solid;
      z-index: 20;
    }
  }
}
