/*
 * Trinity Slider
 *
 * Mobile-first. The base rules are the phone; desktop is the enhancement. The
 * slider this replaces was authored the other way round, which is why its small
 * screens ended up with a 42px gutter, a 650px fixed height and a set of
 * breakpoint rules that contradicted each other.
 *
 * Design targets are the previous slider's, measured from production:
 *   headline  85px desktop, line-height .9, uppercase, white
 *   body      20px desktop / 19px mobile
 *   CTA       #dfa425, hover #efb943, pill
 *   scrim     rgba(0,0,0,.4)
 *   timing    9000ms dwell, 750ms cross-fade
 *   container 1200px
 */

.tg-slider {
  --tg-fade: 750ms;
  --tg-scrim: rgba(0, 0, 0, .4);
  --tg-gold: #dfa425;
  --tg-gold-hover: #efb943;
  --tg-blue: #006db6;

  /*
   * Clearance for the Oxygen overlay header, which is position:absolute over
   * this section. The old slider did this with margin-top:140px on the first
   * headline -- a magic number attached to the wrong element, so it applied
   * whether or not a header was there. slider.js measures the real header and
   * overwrites this value; the fallbacks below are close enough that nothing
   * jumps before it runs.
   */
  --tg-header-h: 96px;

  position: relative;
  isolation: isolate;
  overflow: hidden;
}

/* Nav legibility when no slide is live -- see Trinity_Slider_Render::empty_markup(). */
.tg-slider--empty {
  min-height: var(--tg-header-h);
  background: var(--tg-blue);
}

.tg-slider__track {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tg-slide {
  grid-area: 1 / 1;              /* stack every slide in one cell */
  position: relative;
  display: grid;
  align-items: center;

  min-height: 100vh;             /* fallback for anything without svh */
  min-height: 100svh;            /* the stable height, so it never jumps as */
                                 /* browser chrome hides on scroll */

  opacity: 0;
  visibility: hidden;
  z-index: 0;
  transition: opacity var(--tg-fade) ease-in-out, visibility 0s linear var(--tg-fade);
}

/*
 * The outgoing slide holds at full opacity underneath while the incoming one
 * fades in on top of it.
 *
 * The obvious approach -- fade one out while fading the other in -- looks wrong.
 * Both sit near 0.5 opacity at the midpoint, so roughly a quarter of the page
 * background shows through and the whole hero visibly dips before recovering.
 * Unslider avoided this by only ever animating the incoming slide, which is why
 * the old slider reads as a clean cross-fade and a naive reimplementation does
 * not.
 *
 * slider.js strips this class once the fade has finished, by which point the
 * incoming slide is fully opaque and covering it.
 */
.tg-slide.is-leaving {
  opacity: 1;
  visibility: visible;
  z-index: 1;
  transition: none;
}

/*
 * Oxygen's component framework (component-framework/oxygen.css) ships this as
 * "Custom HTML tag support":
 *
 *     :is(li, div._important) { display: list-item; }
 *
 * :is() takes the specificity of its most specific argument, so that selector
 * weighs (0,1,1) -- class-level specificity applied to every <li> on the site.
 * A plain .tg-slide is (0,1,0) and loses, which made the slide compute to
 * display:list-item, silently ignore align-items, and render its content
 * hard against the top of the viewport instead of centred. Everything else in
 * the rule above applied normally, which is what made it confusing.
 *
 * Scoping to the parent gets (0,2,0) and wins on merit rather than !important.
 * Any future attempt to change an <li>'s display on this site needs the same
 * treatment.
 */
.tg-slider__track > .tg-slide { display: grid; }

/* Defined after .is-leaving so that if both were ever set, active wins. */
.tg-slide.is-active {
  opacity: 1;
  visibility: visible;
  z-index: 2;
  transition: opacity var(--tg-fade) ease-in-out, visibility 0s;
}

/*
 * A real <img> rather than a CSS background-image.
 *
 * This is the single biggest mobile win in the rebuild. background-image cannot
 * carry srcset, so the old slider served every phone the full desktop
 * -scaled.jpg. An <img> lets WordPress emit the whole srcset and lets the
 * browser pick, and lets the first slide take fetchpriority="high" so it can be
 * the LCP element it actually is.
 */
.tg-slide__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  z-index: -2;
}

.tg-slide__scrim {
  position: absolute;
  inset: 0;
  background: var(--tg-scrim);
  z-index: -1;
}

.tg-slide__inner {
  width: 100%;
  max-width: 1200px;
  margin-inline: auto;
  padding-block: calc(var(--tg-header-h) + 1.5rem) 3.5rem;
  padding-inline: 20px;
}

.tg-slide__content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  color: #fff;
}

.tg-slide__eyebrow {
  margin: 0 0 .75rem;
  font-family: 'Montserrat', sans-serif;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-size: clamp(.9rem, 2.4vw, 1.15rem);
  line-height: 1.2;
  color: #fff;
}

/*
 * Fluid rather than the old 2.3rem / 55px / 85px steps. Those jumped abruptly
 * at 480 and 768 and left awkward sizes either side of each boundary. The
 * endpoints still land where they did: ~36px on a small phone, 85px from
 * roughly 1300px up.
 */
.tg-slide__headline {
  margin: 0 0 1.25rem;
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  text-transform: uppercase;
  font-size: clamp(2.25rem, 6.5vw, 85px);
  line-height: .9;
  color: #fff;
  text-wrap: balance;
}

.tg-slide__body {
  margin: 0 0 2rem;
  font-family: 'Montserrat', sans-serif;
  font-size: clamp(1.1875rem, 1.6vw, 1.25rem);
  line-height: 1.45;
  color: #fff;
  max-width: 60ch;
  text-wrap: pretty;
}

/*
 * .button-yellow already supplies colour, radius and uppercase site-wide. Only
 * the slider-specific overrides live here. The old slide forced width:15rem,
 * which on a 320px phone is a button wider than it needs to be and unable to
 * shrink -- min-width gets the same desktop look while still fitting.
 */
.tg-slide__cta {
  display: inline-block;
  min-width: 15rem;
  text-align: center;
  padding: .65rem 1.5rem;
  border-radius: 20px;
  background: var(--tg-gold);
  border: 1px solid var(--tg-gold);
  color: #fff;
  font-family: 'Montserrat', sans-serif;
  font-weight: 500;
  font-size: .9rem;
  text-transform: uppercase;
  text-decoration: none;
  transition: background-color 150ms ease, border-color 150ms ease;
}

.tg-slide__cta:hover,
.tg-slide__cta:focus-visible {
  background: var(--tg-gold-hover);
  border-color: var(--tg-gold-hover);
  color: #fff;
}

/* ---- controls ---------------------------------------------------------- */

.tg-slider__arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 3;

  display: grid;
  place-items: center;
  width: 44px;                   /* 44px is the minimum comfortable touch target */
  height: 44px;
  padding: 0;

  background: transparent;
  border: 0;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  transition: background-color 150ms ease;
}

.tg-slider__arrow:hover,
.tg-slider__arrow:focus-visible { background: rgba(255, 255, 255, .18); }

.tg-slider__arrow svg { width: 26px; height: 26px; }
.tg-slider__arrow--prev { left: 6px; }
.tg-slider__arrow--next { right: 6px; }

/*
 * Below 768px the headline is centred and can fill the full width, so the
 * arrows sat on top of it -- measured at 360px the left arrow overlapped the
 * text by 10px, and at 390px cleared it by only 5px. Phones get the dots (and
 * swipe, see slider.js) instead, which is the better affordance there anyway;
 * arrows are the desktop control. Each breakpoint now has exactly one.
 */
@media (max-width: 767px) {
  .tg-slider__arrow { display: none; }
}

/*
 * Dots are an addition. The original had arrows only: two 26px targets pinned
 * to the screen edges, which on a phone are both hard to hit and easy not to
 * notice, so most people never knew there was a second slide.
 */
.tg-slider__dots {
  position: absolute;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  z-index: 3;
  display: flex;
  gap: .5rem;
}

.tg-slider__dot {
  position: relative;
  width: 10px;
  height: 10px;
  padding: 0;
  border: 1px solid #fff;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  transition: background-color 150ms ease;
}

.tg-slider__dot.is-active { background: #fff; }

/* Keep the hit area finger-sized without making the dot itself big. */
.tg-slider__dot::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
}

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

.tg-slider :focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

/* ---- desktop ----------------------------------------------------------- */

@media (min-width: 768px) {
  .tg-slider { --tg-header-h: 120px; }

  /*
   * Keep the text clear of the arrows.
   *
   * The arrow track ends at 54px (left:10 + 44 wide). The inner is capped at
   * 1200px and centred, so above about 1264px viewport its auto margin already
   * pushes the text well clear and the design gutter of 42px is correct. Below
   * that the margin is zero, the text starts at exactly 42px, and the arrow
   * overlapped it by 12px all the way from 768px to ~1290px.
   *
   * So: use the design gutter, but never let the text start closer than 76px
   * to the viewport edge. The two expressions cross at ~1264px, so the padding
   * changes continuously and there is no jump at any width.
   */
  .tg-slide__inner {
    padding-inline: max(42px, calc(76px - max(0px, (100vw - 1200px) / 2)));
    padding-bottom: 5rem;
  }

  /* Left-aligned in a 75% column, as the current slider is above 767px. */
  .tg-slide__content {
    align-items: flex-start;
    text-align: left;
    width: 75%;
  }

  .tg-slider__arrow--prev { left: 10px; }
  .tg-slider__arrow--next { right: 10px; }

  /* Arrows are the desktop affordance; dots would be redundant clutter. */
  .tg-slider__dots { display: none; }
}

/* ---- reduced motion ---------------------------------------------------- */

/*
 * Honour the preference without removing the slider. Autoplay continues (the
 * brief keeps the 9s rotation) but the cross-fade becomes an instant swap,
 * which is the part that actually causes trouble for vestibular sensitivity.
 */
@media (prefers-reduced-motion: reduce) {
  .tg-slide,
  .tg-slide.is-active { transition-duration: 1ms; }

  .tg-slide__cta,
  .tg-slider__arrow,
  .tg-slider__dot { transition: none; }
}
