@layer reset, base, components, responsive, motion;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { scroll-behavior: smooth; }
  body, h1, h2, h3, p, figure, dl, dd, ol, ul { margin: 0; }
  ol, ul { padding: 0; }
  img { display: block; max-width: 100%; }
  button, a { font: inherit; }
}

@layer base {
  :root {
    --paper: oklch(97% 0.008 240);
    --paper-deep: oklch(92% 0.018 244);
    --surface: oklch(99% 0.005 240);
    --ink: oklch(23% 0.045 250);
    --muted: oklch(47% 0.035 246);
    --rule: oklch(83% 0.025 244);
    --accent: oklch(53% 0.15 250);
    --accent-dark: oklch(42% 0.13 250);
    --accent-ink: oklch(98% 0.008 240);
    --display: "Avenir Next", Avenir, "Segoe UI", sans-serif;
    --body: "Avenir Next", Avenir, "Segoe UI", sans-serif;
    --mono: "IBM Plex Mono", "Cascadia Code", Consolas, monospace;
    --shell: min(100% - 2rem, 76rem);
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  }

  html { background: var(--paper); color-scheme: light; }
  body {
    min-width: 0;
    min-height: 100vh;
    padding-right: env(safe-area-inset-right);
    padding-left: env(safe-area-inset-left);
    background-color: var(--paper);
    background-image: linear-gradient(180deg, var(--paper-deep) 0, var(--paper) 32rem);
    color: var(--ink);
    font-family: var(--body);
    font-size: 1rem;
    line-height: 1.65;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
  }

  ::selection { background: var(--accent); color: var(--accent-ink); }
  a { color: inherit; text-decoration-thickness: 0.08em; text-underline-offset: 0.18em; }
  a:focus-visible { outline: 0.2rem solid var(--accent); outline-offset: 0.25rem; border-radius: 0.1rem; }
  h2, h3 { font-family: var(--display); font-weight: 750; line-height: 1.06; text-wrap: balance; }
  h2 { font-size: clamp(2.55rem, 7vw, 6.4rem); letter-spacing: -0.055em; }
  h3 { font-size: clamp(1.55rem, 3vw, 2.55rem); letter-spacing: -0.035em; }

  .section-shell { width: var(--shell); margin-inline: auto; }
  section { scroll-margin-top: 2rem; }
  .eyebrow {
    color: var(--accent-dark);
    font-family: var(--mono);
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    line-height: 1.4;
    text-transform: uppercase;
  }
  .skip-link {
    position: fixed;
    z-index: 100;
    top: 0.75rem;
    left: 0.75rem;
    translate: 0 -200%;
    padding: 0.7rem 1rem;
    background: var(--ink);
    color: var(--paper);
    font-weight: 700;
  }
  .skip-link:focus { translate: 0; }
}

@layer components {
  .gallery-page { background-image: linear-gradient(180deg, var(--paper-deep) 0, var(--paper) 30rem); }

  .gallery-header { border-bottom: 1px solid var(--rule); background: color-mix(in oklch, var(--paper) 94%, transparent); }
  .gallery-nav { display: flex; min-height: 4.5rem; align-items: center; justify-content: space-between; gap: 1rem; }
  .gallery-nav a { min-height: 2.75rem; display: inline-flex; align-items: center; font-size: 0.82rem; font-weight: 750; text-decoration: none; }
  .gallery-nav__brand { font-family: var(--display); font-size: 1rem !important; }
  .gallery-nav__links { display: flex; gap: clamp(0.8rem, 3vw, 2rem); }

  .gallery-collection { padding-block: clamp(4.5rem, 10vw, 8rem); border-top: 1px solid var(--rule); background: var(--surface); }
  .gallery-collection__heading { display: grid; gap: 1rem; align-items: end; margin-bottom: clamp(2rem, 6vw, 4rem); }
  .gallery-collection h2 { margin-top: 0.5rem; font-size: clamp(2.5rem, 6vw, 5rem); }
  .gallery-status { color: var(--muted); font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.04em; }

  .gallery-grid { display: grid; gap: clamp(2rem, 5vw, 4rem) clamp(1rem, 2.5vw, 2rem); }
  .gallery-card { --gallery-media-height: clamp(17rem, 42vw, 28rem); min-width: 0; border-top: 1px solid var(--ink); }
  .gallery-card__media { display: grid; width: 100%; height: var(--gallery-media-height); place-items: center; padding: clamp(0.75rem, 2vw, 1.5rem); background: var(--paper); overflow: hidden; }
  .gallery-card__image { width: auto; height: auto; max-width: 100%; max-height: calc(var(--gallery-media-height) - clamp(1.5rem, 4vw, 3rem)); object-fit: contain; transition: transform 550ms var(--ease-out); }
  .gallery-card__body { display: flex; align-items: start; justify-content: space-between; gap: 1rem; padding-top: 1rem; }
  .gallery-card__meta { min-width: 0; }
  .gallery-card__meta h3 { overflow: hidden; font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.04em; text-overflow: ellipsis; white-space: nowrap; }
  .gallery-card__meta time { display: block; margin-top: 0.25rem; color: var(--muted); font-size: 0.72rem; }
  .gallery-card__actions { display: flex; flex: 0 0 auto; gap: 0.8rem; }
  .gallery-action { display: inline-flex; min-height: 2.75rem; align-items: center; font-size: 0.76rem; font-weight: 750; }
  .gallery-action--quiet { color: var(--muted); }

  .pagination { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem; margin-top: clamp(3.5rem, 8vw, 6rem); }
  .pagination__button { min-width: 2.75rem; min-height: 2.75rem; padding: 0.55rem 0.8rem; border: 1px solid var(--rule); border-radius: 0.35rem; background: var(--paper); color: var(--ink); cursor: pointer; font-size: 0.78rem; font-weight: 750; }
  .pagination__button[aria-current="page"] { border-color: var(--ink); background: var(--ink); color: var(--paper); }
  .pagination__button:focus-visible { outline: 0.2rem solid var(--accent); outline-offset: 0.18rem; }
  .pagination__button:disabled { opacity: 0.42; cursor: not-allowed; }
  .gallery-loading, .gallery-error { min-height: 16rem; display: grid; place-items: center; border-block: 1px solid var(--rule); color: var(--muted); text-align: center; }
  .gallery-error { color: oklch(42% 0.14 25); }

  /* Guarded by (hover: hover): iOS Safari latches :hover after a tap ("sticky
     hover"), so hover styles on tappable elements only apply where a real
     hover-capable pointer exists. */
  @media (hover: hover) {
    .gallery-card__media:hover .gallery-card__image { transform: scale(1.018); }
    .pagination__button:hover:not(:disabled) { border-color: var(--ink); background: var(--ink); color: var(--paper); }
  }

  @media (min-width: 42rem) {
    .gallery-collection__heading { grid-template-columns: 1fr auto; }
    .gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }

  @media (min-width: 70rem) {
    .gallery-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .gallery-card { --gallery-media-height: clamp(20rem, 27vw, 28rem); }
  }

  @media (max-width: 30rem) {
    .gallery-nav__links { gap: 0.55rem; }
    .gallery-nav__links a { padding-inline: 0.25rem; }
    .gallery-card__body { display: grid; }
    .gallery-card__actions { justify-content: space-between; }
    .pagination__button:first-child, .pagination__button:last-child { flex-basis: calc(50% - 0.25rem); }
  }

  @media (prefers-reduced-motion: reduce) {
    .gallery-card__image { transition: none; }
  }

  .site-footer { padding-bottom: env(safe-area-inset-bottom); border-top: 1px solid var(--rule); }
  .site-footer__inner { display: grid; gap: 0.35rem; padding-block: 2rem; color: var(--muted); font-size: 0.75rem; }
  .site-footer__inner a { width: fit-content; color: var(--ink); font-weight: 700; }
}

@layer responsive {
  @media (min-width: 40rem) {
    :root { --shell: min(100% - 3.5rem, 76rem); }
    .site-footer__inner { grid-template-columns: 1fr auto; gap: 2rem; }
  }

  @media (max-width: 23rem) {
    :root { --shell: min(100% - 1.25rem, 76rem); }
  }
}

@layer motion {
  @media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  }
}
