/* ============================================
   Layout
   ============================================ */

@layer layout {
  /* --- Container --- */
  .container {
    width: 100%;
    max-width: var(--max-width);
    margin-inline: auto;
    padding: 0 var(--gutter);
  }

.container--narrow {
  max-width: var(--content-width);
}

.container--wide {
  max-width: var(--wide-width);
}

/* --- Page wrapper --- */
.page {
  display: flex;
  flex-direction: column;
  min-block-size: 100vh;
  min-block-size: 100dvh;
}

.page__main {
  flex: 1;
}

/* --- Header --- */
.header {
  position: sticky;
  inset-block-start: 0;
  z-index: 100;
  background: rgba(250, 250, 248, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border-light);
}

.header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  block-size: 3.75rem;
  gap: var(--space-6);
  container-type: inline-size;
  container-name: header-shell;
}

.header__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  color: var(--color-text);
  flex-shrink: 0;
}

.header__logo-img {
  block-size: 44px;
  width: auto;
  display: block;
  flex-shrink: 0;
}

.header__title {
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: var(--text-sm);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-snug);
  max-width: 420px;
  color: var(--color-text);
}

/* --- Navigation --- */
.nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

  .nav__link {
    font-family: var(--font-ui);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--color-text-secondary);
    text-decoration: none;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    transition: color var(--duration-fast) var(--ease-default),
                background var(--duration-fast) var(--ease-default);
    white-space: nowrap;

    &:hover {
      color: var(--color-text);
      background: var(--color-surface-alt);
    }

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

    &.nav__link--active {
      color: var(--color-accent);
      background: var(--color-accent-light);
    }
  }

  .header__inner:has(.nav.nav--open) .nav-toggle {
    background: var(--color-accent-light);
    color: var(--color-accent);
    border-color: transparent;
  }

  /* --- Mobile menu toggle --- */
  .nav-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--space-2);
    color: var(--color-text);
    border-radius: var(--radius-sm);

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

    svg {
      width: 24px;
      height: 24px;
    }
  }

  /* --- Footer --- */
  .footer {
    border-block-start: 1px solid var(--color-border);
    padding: var(--space-12) 0 var(--space-8);
    margin-block-start: var(--space-20);
    background: var(--color-surface);
    container-type: inline-size;
    container-name: footer-shell;
  }

  .footer__inner {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-8);
  }

  .footer__info {
    max-width: 480px;
  }

  .footer__title {
    font-family: var(--font-ui);
    font-size: var(--text-base);
    font-weight: 600;
    margin-bottom: var(--space-2);
  }

  .footer__text {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    line-height: var(--leading-normal);
  }

  .footer__nav {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }

  .footer__nav-title {
    font-family: var(--font-ui);
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: var(--tracking-caps);
    color: var(--color-text-muted);
    margin-bottom: var(--space-1);
  }

  .footer__link {
    font-family: var(--font-ui);
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    text-decoration: none;
    transition: color var(--duration-fast) var(--ease-default);

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

  .footer__bottom {
    margin-block-start: var(--space-8);
    padding-block-start: var(--space-6);
    border-block-start: 1px solid var(--color-border-light);
    font-family: var(--font-ui);
    font-size: var(--text-xs);
    color: var(--color-text-muted);
  }

  /* --- Section spacing --- */
  .section {
    padding: var(--space-16) 0;
  }

  .section--flush-top {
    padding-block-start: 0;
  }

  .section--hero {
    padding: var(--space-20) 0 var(--space-12);
  }

  @container header-shell (max-width: 52rem) {
    .header__inner {
      block-size: 3.25rem;
    }

    .header__title {
      max-inline-size: 10rem;
      font-size: var(--text-xs);
    }

    .nav {
      position: fixed;
      inset-block-start: 3.25rem;
      inset-inline: 0;
      background: var(--color-surface);
      border-bottom: 1px solid var(--color-border);
      flex-direction: column;
      padding: var(--space-4) var(--gutter);
      gap: var(--space-1);
      transform: translateY(-100%);
      opacity: 0;
      pointer-events: none;
      transition: transform var(--duration-normal) var(--ease-default),
                  opacity var(--duration-normal) var(--ease-default);
      box-shadow: var(--shadow-lg);
    }

    .nav--open {
      transform: translateY(0);
      opacity: 1;
      pointer-events: auto;
    }

    .nav__link {
      inline-size: 100%;
      padding: var(--space-3) var(--space-4);
      font-size: var(--text-base);
    }

    .nav-toggle {
      display: block;
    }
  }

  @container footer-shell (max-width: 42rem) {
    .footer__inner {
      flex-direction: column;
      gap: var(--space-6);
    }
  }

  /* ============================================
     Responsive
     ============================================ */

  @media (max-width: 768px) {
    .header__inner {
      block-size: 3.25rem;
    }

    .header__title {
      max-inline-size: 160px;
      font-size: var(--text-xs);
    }

    .nav {
      position: fixed;
      inset-block-start: 3.25rem;
      inset-inline: 0;
      background: var(--color-surface);
      border-bottom: 1px solid var(--color-border);
      flex-direction: column;
      padding: var(--space-4) var(--gutter);
      gap: var(--space-1);
      transform: translateY(-100%);
      opacity: 0;
      pointer-events: none;
      transition: transform var(--duration-normal) var(--ease-default),
                  opacity var(--duration-normal) var(--ease-default);
      box-shadow: var(--shadow-lg);
    }

    .nav--open {
      transform: translateY(0);
      opacity: 1;
      pointer-events: auto;
    }

    .nav__link {
      width: 100%;
      padding: var(--space-3) var(--space-4);
      font-size: var(--text-base);
    }

    .nav-toggle {
      display: block;
    }

    .footer__inner {
      flex-direction: column;
      gap: var(--space-6);
    }

    .section--hero {
      padding: var(--space-12) 0 var(--space-8);
    }

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