/* Add your global styles here */

/* Tulloch Castle timeline: entries fade until they reach the middle of the viewport */
@keyframes timeline-focus {
  0%, 100% { opacity: 0.2; }
  30%, 70% { opacity: 1; }
}

@keyframes timeline-dot {
  0%, 100% { background-color: var(--primary); }
  30%, 70% { background-color: var(--white); }
}

/* Anchor jumps stop below the sticky header; DWC keeps --dwc-scroll-margin at the header's live height */
html {
  scroll-padding-block-start: calc(var(--dwc-scroll-margin, var(--header-height)) + var(--space-s));
}

/* Filter chips: one copy per option, so the animation replays every time the choice changes */
@keyframes filter-in-1 {
  from { opacity: 0; translate: 0 0.5rem; }
}

@keyframes filter-in-2 {
  from { opacity: 0; translate: 0 0.5rem; }
}

@keyframes filter-in-3 {
  from { opacity: 0; translate: 0 0.5rem; }
}

@keyframes filter-in-4 {
  from { opacity: 0; translate: 0 0.5rem; }
}

@keyframes filter-in-5 {
  from { opacity: 0; translate: 0 0.5rem; }
}

@keyframes filter-in-6 {
  from { opacity: 0; translate: 0 0.5rem; }
}

@keyframes filter-in-7 {
  from { opacity: 0; translate: 0 0.5rem; }
}

@keyframes filter-in-8 {
  from { opacity: 0; translate: 0 0.5rem; }
}

@keyframes filter-in-9 {
  from { opacity: 0; translate: 0 0.5rem; }
}

@keyframes filter-in-10 {
  from { opacity: 0; translate: 0 0.5rem; }
}

@keyframes filter-in-11 {
  from { opacity: 0; translate: 0 0.5rem; }
}

@keyframes filter-in-12 {
  from { opacity: 0; translate: 0 0.5rem; }
}

/* Small soft shadow for standalone photographs (not images inside cards, galleries or logos) */
:root {
  --image-shadow-s: 0 0.125rem 0.375rem color-mix(in oklch, var(--black) 10%, transparent), 0 0.5rem 1.25rem color-mix(in oklch, var(--black) 8%, transparent);
}


/* Links: ACSS --link-transition names no property, so every property animates (Lighthouse flags line-height). Limit it to paint-only properties */
:root {
  --link-transition: color var(--transition), background-color var(--transition), border-color var(--transition), text-decoration-color var(--transition), box-shadow var(--transition), opacity var(--transition), transform var(--transition);
}

/* DWC header: once scrolling starts, DWC adds a top margin the height of the fixed header. It only checks the desktop overlay setting, so with the mobile overlay header on (where the first section already clears the header) the whole page dropped by the header's height each time the scroll state switched */
html.dwc-mobile body:is(.scroll-up, .scroll-down):has([data-sticky-header="true"][data-overlay-header-mobile="true"]) {
  margin-block-start: 0;
}

/* Scroll motion: section content fades in from transparent and rises as it comes onto the screen, cards in a row arrive left to right, and the Home hero tartan drifts slower than the page.
   Runs on the scroll timeline (no JavaScript). Where scroll-driven animation is unsupported or reduced motion is set, everything stays still and visible.
   Left alone on purpose: heroes, gallery walls, sticky rails, the Tulloch timeline (it has its own scroll motion) and filter results (they have their own filter animation) */
@keyframes content-fade-up {
  from {
    opacity: 0;
    translate: 0 var(--content-fade-distance);
  }
}

@keyframes hero-tartan-parallax {
  to {
    background-position: 50% 50%, 50% calc(50% + var(--hero-parallax-shift));
  }
}

:root {
  --content-fade-distance: 4rem;
  /* Ranges are measured from when the top of the content reaches the bottom of the screen */
  --content-fade-length: 30vh;
  /* Extra delay per card for each place across a row of cards */
  --content-fade-step: 12vh;
  /* The tartan moves down 40% of the scroll, so it travels at about 60% of the page's speed */
  --hero-parallax-shift: 40vh;
}

@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    /* Home: section > layout > block > item */
    :is(.about, .home-chief, .what-we-do, .happening, .explore) > * > * > :not(.happening__grid),
    .what-we-do__text,
    .happening__grid > *,
    /* Inner pages: section > container > block. Tall blocks fade item by item instead (below) */
    main > .etch-section-style > * > :not(.filter, .timeline, .interior__columns, .history, .genealogy, .clan-global, .tartans-layout, .membership-apply, .inaug, .inaug-more, .benefit-cards),
    .filter > .filter__bar,
    .interior__columns > :not(.interior__column, .chattan-moment),
    .interior__column > *,
    .history > :not(.history__chapter),
    .history__chapter > *,
    .genealogy > *,
    .clan-global > *,
    .tartans-layout > * > *,
    .membership-apply > *,
    .inaug__story > *,
    .inaug-more > *,
    .benefit-cards > * {
      animation: content-fade-up ease-out both;
      animation-timeline: view();
      /* --fade-slot is a card's place across its row (0 for the first), set below for each card grid at each breakpoint */
      --fade-delay: calc(var(--fade-slot, 0) * var(--content-fade-step));
      animation-range: cover var(--fade-delay) cover calc(var(--fade-delay) + var(--content-fade-length));
    }

    /* Cards in a row come in one after another, left to right. Stacked cards need no slot: scrolling already brings them in one at a time */
    .explore__tiles > :nth-child(2n) {
      --fade-slot: 1;
    }

    @media (width >= 30rem) {
      :is(.what-we-do__cards, .benefit-cards) > :nth-child(2n) {
        --fade-slot: 1;
      }

      .happening__grid > :nth-child(3n + 2) {
        --fade-slot: 1;
      }

      .happening__grid > :nth-child(3n) {
        --fade-slot: 2;
      }
    }

    /* Clan Global facts are placed by name, not in list order: the right-hand column follows the left */
    @media (width >= 48rem) {
      .clan-global > :is(.clan-fact--line, .clan-fact--day, .clan-fact--chief, .clan-fact--salute) {
        --fade-slot: 1;
      }
    }

    @media (width >= 61.9375rem) {
      :is(.what-we-do__cards, .explore__tiles, .benefit-cards) > :nth-child(4n + 1) {
        --fade-slot: 0;
      }

      :is(.what-we-do__cards, .explore__tiles, .benefit-cards) > :nth-child(4n + 2) {
        --fade-slot: 1;
      }

      :is(.what-we-do__cards, .explore__tiles, .benefit-cards) > :nth-child(4n + 3) {
        --fade-slot: 2;
      }

      :is(.what-we-do__cards, .explore__tiles, .benefit-cards) > :nth-child(4n) {
        --fade-slot: 3;
      }

      /* Clan Global facts sit in named areas, so each fact gets its slot by name, left to right */
      .clan-global > :is(.clan-fact--crest, .clan-fact--plant, .clan-fact--badge) {
        --fade-slot: 0;
      }

      .clan-global > :is(.clan-fact--line, .clan-fact--chief, .clan-fact--salute) {
        --fade-slot: 1;
      }

      .clan-global > :is(.clan-fact--motto, .clan-fact--gaelic) {
        --fade-slot: 2;
      }

      .clan-global > .clan-fact--day {
        --fade-slot: 3;
      }

      /* Side-by-side layouts: the right-hand column follows the left */
      :is(.membership-apply, .interior__columns) > :nth-child(2),
      :is(.tartans-layout, .interior__columns) > :nth-child(2) > * {
        --fade-slot: 1;
      }
    }

    /* The tartan repeats, so moving it never shows an edge. The overlay layer stays put */
    .hero {
      animation: hero-tartan-parallax linear both;
      animation-timeline: scroll(root);
      animation-range: 0 100vh;
    }
  }
}

/* Short pages reveal on a timer as the page paints, so content already on the first screen does not wait for a scroll that barely exists.
   Contact, Events, Clan Chattan, Clans & Septs, Genealogy Resources and The Clan Global. Items follow one another down the page, and cards side by side still go left to right */
:root {
  --content-reveal-duration: 0.9s;
  --content-reveal-step: 0.1s;
  --content-reveal-slot-step: 0.15s;
}

@media (prefers-reduced-motion: no-preference) {
  main:has(.contact__columns, .interior__columns, .events__split, .event-list, .genealogy, .clan-global) {
    & :nth-child(2) {
      --fade-order: 1;
    }

    & :nth-child(3) {
      --fade-order: 2;
    }

    & :nth-child(4) {
      --fade-order: 3;
    }

    & :nth-child(n + 5) {
      --fade-order: 4;
    }

    & :is(
      main > .etch-section-style > * > :not(.filter, .timeline, .interior__columns, .history, .genealogy, .clan-global, .tartans-layout, .membership-apply, .inaug, .inaug-more, .benefit-cards),
      .interior__columns > :not(.interior__column, .chattan-moment),
      .interior__column > *,
      .genealogy > *,
      .clan-global > *
    ) {
      animation: content-fade-up var(--content-reveal-duration) ease-out both;
      animation-timeline: auto;
      animation-range: normal;
      animation-delay: calc(var(--fade-order, 0) * var(--content-reveal-step) + var(--fade-slot, 0) * var(--content-reveal-slot-step));
    }
  }
}
