@layer reset, theme, layout, components, motion;

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

  html {
    scroll-behavior: smooth;
    scrollbar-gutter: stable;
  }

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

  button {
    font: inherit;
    cursor: pointer;
  }

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

@layer theme {
  :root {
    --paper: #f5f2ea;
    --paper-2: #fffdf7;
    --ink: #322820;
    --ink-soft: #6a5b4f;
    --accent: #d16f4f;
    --leaf: #4f8a67;
    --sun: #f0bc63;
    --line: rgba(50, 40, 32, 0.14);
    --shadow: 0 12px 30px rgba(32, 17, 10, 0.16);
    --radius: 1rem;
  }

  @supports (color: oklch(62% 0.11 35)) {
    :root {
      --paper: oklch(96% 0.012 84);
      --paper-2: oklch(99% 0.008 90);
      --ink: oklch(30% 0.04 55);
      --ink-soft: oklch(47% 0.03 58);
      --accent: oklch(66% 0.14 40);
      --leaf: oklch(60% 0.1 160);
      --sun: oklch(81% 0.12 78);
      --line: color-mix(in oklch, var(--ink) 16%, transparent);
    }
  }

  body {
    min-height: 100dvh;
    color: var(--ink);
    background:
      radial-gradient(circle at 15% 10%, color-mix(in oklch, var(--sun) 35%, transparent) 0, transparent 45%),
      radial-gradient(circle at 85% 20%, color-mix(in oklch, var(--leaf) 25%, transparent) 0, transparent 40%),
      linear-gradient(180deg, var(--paper) 0%, var(--paper-2) 45%, #efe9dc 100%);
    font-family: "Manrope", "Segoe UI", sans-serif;
    line-height: 1.5;
  }

  h1, h2, h3 {
    font-family: "Fraunces", Georgia, serif;
    text-wrap: balance;
    letter-spacing: 0.01em;
  }
}

@layer layout {
  .hero {
    position: relative;
    display: grid;
    gap: 1rem;
    padding: 1rem;
    max-inline-size: 1100px;
    margin: 0 auto;
  }

  .hero__backdrop {
    position: absolute;
    inset: 0.25rem;
    border-radius: 1.4rem;
    border: 1px solid var(--line);
    background: linear-gradient(135deg, color-mix(in oklch, var(--paper) 92%, white), color-mix(in oklch, var(--sun) 12%, var(--paper)));
    z-index: -1;
    box-shadow: var(--shadow);
  }

  .hero__content {
    padding: 1.2rem;
  }

  .hero__figure {
    justify-self: center;
    inline-size: min(100%, 26rem);
    padding: 0.8rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: var(--shadow);
    transform: rotate(-1.2deg);
  }

  .hero__figure img {
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 0.5rem;
  }

  .timeline {
    max-inline-size: 1100px;
    margin: 1rem auto 3rem;
    padding: 0 1rem;
  }

  .timeline__header {
    margin-block-end: 1rem;
  }

  .gallery {
    display: grid;
    gap: 1rem;
    container-type: inline-size;
  }

  .timeline__actions {
    display: flex;
    justify-content: center;
    margin-block-start: 1.25rem;
  }

  @container (min-width: 36rem) {
    .gallery {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }

  @container (min-width: 56rem) {
    .gallery {
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }
  }

  @media (min-width: 54rem) {
    .hero {
      grid-template-columns: 1.15fr 0.85fr;
      align-items: center;
      padding-top: 1.4rem;
    }
  }
}

@layer components {
  .eyebrow {
    font-size: 0.82rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--ink-soft);
    margin-block-end: 0.35rem;
  }

  .hero h1 {
    font-size: clamp(1.75rem, 4vw, 2.7rem);
    line-height: 1.05;
    margin-block-end: 0.8rem;
  }

  .intro {
    color: var(--ink-soft);
    max-inline-size: 38ch;
    margin-block-end: 1rem;
  }

  .hero__actions {
    display: flex;
    gap: 0.65rem;
    flex-wrap: wrap;
  }

  .toggle,
  .load-more,
  .entry-dialog__close {
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: var(--ink);
    padding: 0.5rem 0.92rem;
    font-weight: 700;
    font-size: 0.92rem;
    transition: transform 170ms ease, border-color 170ms ease, box-shadow 170ms ease;
  }

  .toggle:hover,
  .load-more:hover,
  .entry-dialog__close:hover {
    transform: translateY(-1px);
    box-shadow: 0 7px 16px rgba(0, 0, 0, 0.08);
    border-color: color-mix(in oklch, var(--accent) 58%, var(--line));
  }

  .timeline h2 {
    font-size: clamp(1.25rem, 2.8vw, 1.7rem);
    margin-block-end: 0.3rem;
  }

  .timeline__header p {
    color: var(--ink-soft);
  }

  .polaroid {
    position: relative;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 0.5rem;
    padding: 0.6rem 0.6rem 1rem;
    box-shadow: 0 8px 18px rgba(24, 20, 11, 0.13);
    transform: rotate(var(--tilt, 0deg));
    transition: transform 220ms ease, box-shadow 220ms ease;
  }

  .polaroid:focus-within,
  .polaroid:hover {
    transform: rotate(0deg) translateY(-4px);
    box-shadow: 0 16px 26px rgba(24, 20, 11, 0.2);
  }

  .polaroid__open {
    position: absolute;
    inset: 0;
    border: 0;
    background: transparent;
    border-radius: inherit;
    z-index: 1;
  }

  .polaroid__image {
    inline-size: 100%;
    aspect-ratio: 4 / 5;
    object-fit: cover;
    border-radius: 0.2rem;
    border: 1px solid var(--line);
    background: linear-gradient(135deg, #f3eee4, #e8deca);
  }

  .polaroid__body {
    margin-block-start: 0.62rem;
    padding-inline: 0.3rem;
  }

  .polaroid__caption {
    font-family: "Patrick Hand", cursive;
    font-size: 1.2rem;
    line-height: 1.2;
    margin-block-end: 0.3rem;
  }

  .polaroid__meta {
    color: var(--ink-soft);
    font-size: 0.86rem;
  }

  .entry-overlay {
    position: fixed;
    inset: 0;
    background: rgba(37, 24, 18, 0.44);
    backdrop-filter: blur(2px);
    display: grid;
    place-items: center;
    padding: 1rem;
    z-index: 30;
  }

  .entry-detail {
    inline-size: min(92vw, 54rem);
    border: 1px solid var(--line);
    border-radius: 1rem;
    padding: 1rem;
    background: var(--paper-2);
    box-shadow: 0 34px 60px rgba(0, 0, 0, 0.25);
    display: grid;
    gap: 0.9rem;
    max-height: 92vh;
    overflow: auto;
  }

  .entry-dialog__close {
    margin-inline-start: auto;
    display: block;
    margin-block-end: 0.35rem;
  }

  .entry-detail img {
    border: 1px solid var(--line);
    border-radius: 0.55rem;
    max-block-size: min(60vh, 34rem);
    inline-size: 100%;
    object-fit: contain;
    background: #fff;
  }

  .entry-detail h3 {
    font-size: clamp(1.2rem, 2.7vw, 1.6rem);
    text-wrap: balance;
  }

  .entry-detail p {
    color: var(--ink-soft);
  }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      animation: none !important;
      transition: none !important;
      scroll-behavior: auto !important;
    }
  }
}

@layer motion {
  @media (prefers-reduced-motion: no-preference) {
    .polaroid {
      animation: lift-in 520ms ease both;
      animation-delay: calc(var(--index, 0) * 40ms);
    }

    @keyframes lift-in {
      from {
        opacity: 0;
        transform: translateY(18px) rotate(var(--tilt, 0deg));
      }
      to {
        opacity: 1;
        transform: translateY(0) rotate(var(--tilt, 0deg));
      }
    }
  }
}
