@layer components {
  .hero-media.hero-gallery {
    --gallery-ease: cubic-bezier(.2, 1, .3, 1);
    position: relative;
    background: var(--surface, #f2ebe3);
    isolation: isolate;
  }

  .hero-gallery .gallery-cards {
    position: absolute;
    inset: 8px;
    display: flex;
    gap: 8px;
    min-width: 0;
    min-height: 0;
  }

  .hero-gallery .gallery-card {
    position: relative;
    display: block;
    flex: 1 1 0%;
    min-width: 48px;
    min-height: 0;
    padding: 0;
    overflow: hidden;
    border: 0;
    border-radius: 10px;
    background: #8a7766;
    color: #fffdfa;
    font: inherit;
    text-align: center;
    cursor: pointer;
    touch-action: manipulation;
    isolation: isolate;
    transition: flex-grow 700ms var(--gallery-ease);
  }

  .hero-gallery .gallery-card.is-active { flex-grow: 4.5; }

  .hero-gallery .gallery-image {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: cover;
    object-position: center;
    filter: grayscale(.28) brightness(.72);
    transform: scale(1.045);
    pointer-events: none;
    transition: transform 900ms var(--gallery-ease), filter 700ms var(--gallery-ease);
  }

  .hero-gallery .gallery-card.is-active .gallery-image {
    filter: grayscale(0) brightness(.96);
    transform: scale(1);
  }

  .hero-gallery .gallery-card--article { background: #ff6500; }

  .hero-gallery .gallery-card--article.is-active .gallery-image {
    object-fit: contain;
    object-position: center 42%;
    filter: none;
  }

  .hero-gallery .gallery-shade {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: #30282180;
    pointer-events: none;
    transition: opacity 700ms var(--gallery-ease);
  }

  .hero-gallery .gallery-card.is-active .gallery-shade { opacity: .16; }

  .hero-gallery .gallery-vertical {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fffdfa;
    font-size: 14px;
    font-weight: 550;
    letter-spacing: .12em;
    line-height: 1.6;
    white-space: nowrap;
    writing-mode: vertical-rl;
    text-orientation: upright;
    text-shadow: 0 2px 12px #211b1559;
    pointer-events: none;
    transition: opacity 180ms ease;
  }

  .hero-gallery .gallery-card.is-active .gallery-vertical { opacity: 0; }

  .hero-gallery .gallery-content {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px;
    background: linear-gradient(180deg, #302821b3, #30282114 34%, #3028210d 56%, #211b15d9);
    color: #fffdfa;
    opacity: 0;
    pointer-events: none;
    transition: opacity 220ms ease;
  }

  .hero-gallery .gallery-card.is-active .gallery-content {
    opacity: 1;
    transition-delay: 160ms;
  }

  .hero-gallery .gallery-index {
    font-family: Arial, sans-serif;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: .15em;
    line-height: 1.6;
    white-space: nowrap;
  }

  .hero-gallery .gallery-bottom {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr) 24px;
    align-items: center;
    gap: 12px;
    width: 100%;
    margin-top: auto;
    transform: translateY(6px);
    transition: transform 600ms var(--gallery-ease);
  }

  .hero-gallery .gallery-card.is-active .gallery-bottom { transform: translateY(0); }

  .hero-gallery .gallery-title {
    grid-column: 2;
    display: block;
    min-width: 0;
    font-size: clamp(18px, 2vw, 28px);
    font-weight: 550;
    letter-spacing: .035em;
    line-height: 1.5;
    text-wrap: balance;
  }

  .hero-gallery .gallery-arrow {
    grid-column: 3;
    justify-self: end;
    width: 20px;
    height: 20px;
    color: #fffdfa;
  }

  .hero-gallery .gallery-card:focus-visible {
    outline: 3px solid var(--accent, #a84630);
    outline-offset: -3px;
  }

  .hero-gallery .gallery-card:focus-visible::after {
    content: "";
    position: absolute;
    inset: 5px;
    z-index: 4;
    border: 1px solid #fffdfa;
    border-radius: 6px;
    pointer-events: none;
  }

  .hero-gallery .gallery-status {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    border: 0;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  @media (hover: hover) and (pointer: fine) {
    .hero-gallery .gallery-card:not(.is-active):hover .gallery-image { transform: scale(1.02); }
  }
}

@layer responsive {
  @media (max-width: 800px) {
    .hero-gallery .gallery-content { padding: 20px; }
    .hero-gallery .gallery-bottom { grid-template-columns: 20px minmax(0, 1fr) 20px; gap: 8px; }
    .hero-gallery .gallery-title { font-size: 20px; }
    .hero-gallery .gallery-vertical { font-size: 13px; }
  }

  @media (max-width: 640px) {
    .hero-media.hero-gallery { aspect-ratio: auto; height: clamp(280px, 85vw, 360px); }
    .hero-gallery .gallery-cards { inset: 5px; flex-direction: row; gap: 4px; }
    .hero-gallery .gallery-card { flex: 0 0 28px; min-width: 28px; min-height: 0; border-radius: 7px; }
    .hero-gallery .gallery-card.is-active { flex-grow: 1; }
    .hero-gallery .gallery-vertical { font-size: 12px; letter-spacing: .1em; writing-mode: vertical-rl; text-orientation: upright; }
    .hero-gallery .gallery-content { padding: 12px; }
    .hero-gallery .gallery-bottom { grid-template-columns: minmax(0, 1fr); justify-items: center; gap: 6px; }
    .hero-gallery .gallery-title { grid-column: 1; font-size: clamp(14px, 4vw, 18px); letter-spacing: .025em; }
    .hero-gallery .gallery-index { font-size: 10px; }
    .hero-gallery .gallery-arrow { grid-column: 1; justify-self: center; width: 16px; height: 16px; }
  }

  @media (prefers-reduced-motion: reduce) {
    .hero-gallery .gallery-card,
    .hero-gallery .gallery-image,
    .hero-gallery .gallery-shade,
    .hero-gallery .gallery-vertical,
    .hero-gallery .gallery-content,
    .hero-gallery .gallery-bottom { transition: none; }
    .hero-gallery .gallery-image,
    .hero-gallery .gallery-bottom { transform: none; }
  }
}
