/* Stage (slider) and its slides (front end and editor) */
.sg-stage {
  --stage-h: clamp(520px, 75svh, 820px);
  position: relative;
  background: var(--wp--custom--dark, #0d1a33);

  &.is-h-m { --stage-h: clamp(440px, 60svh, 640px); }
  &.is-h-xl { --stage-h: max(520px, calc(100svh - 110px)); }
}

.is-layout-constrained > .sg-stage,
.is-layout-flow > .sg-stage {
  margin-block: 0;
}

.sg-stage__track {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior-x: contain;

  &::-webkit-scrollbar { display: none; }
}

.sg-slide {
  position: relative;
  isolation: isolate;
  flex: 0 0 100%;
  min-height: var(--stage-h);
  display: flex;
  align-items: flex-end;
  scroll-snap-align: start;
  color: #fff;
  overflow: hidden;
}

.is-pos-center .sg-slide { align-items: center; }

.sg-slide__bg {
  position: absolute;
  inset: 0;
  z-index: -2;

  & img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }
}

.sg-slide::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
}

.sg-slide.has-shade-dark::before {
  background: linear-gradient(0deg, rgba(6, 14, 20, .78) 0%, rgba(6, 14, 20, .35) 45%, rgba(6, 14, 20, .1) 75%);
}

.is-pos-center .sg-slide.has-shade-dark::before {
  background: linear-gradient(90deg, rgba(6, 14, 20, .72) 0%, rgba(6, 14, 20, .35) 50%, rgba(6, 14, 20, .05) 80%);
}

.sg-slide.has-shade-light {
  color: var(--wp--preset--color--ink);

  &::before { background: linear-gradient(0deg, rgba(255, 255, 255, .9) 0%, rgba(255, 255, 255, .55) 45%, rgba(255, 255, 255, 0) 75%); }
}

.sg-slide__in {
  width: 100%;
  min-width: 0; /* long words in the heading wrap instead of widening the slide */
  max-width: calc(var(--wp--style--global--wide-size, 1312px) + 2 * var(--wp--custom--gutter, 24px));
  margin: 0 auto;
  padding: 48px var(--wp--custom--gutter, 24px) 88px;
  display: flex;
  flex-direction: column;
  gap: 16px;

  & > * { margin: 0; max-width: 62ch; }
  & :is(h1, h2) { max-width: 22ch; color: inherit; hyphens: manual; } /* wrap at spaces, no hyphens */
  & h1 { font-size: var(--wp--preset--font-size--xl); line-height: 1.12; } /* the H1 of a page slide looks like the other slides (h2) */
  & .is-style-lead { color: inherit; }
  & .wp-block-buttons { margin-top: 12px; }
}

.sg-stage.has-controls .sg-slide__in { padding-bottom: 104px; }

.sg-slide:not(.has-shade-light) .wp-block-button.is-style-ghost .wp-block-button__link {
  border-color: #fff;
  color: #fff;
}

/* ---------- controls (created by view.js) ----------
   Arrows at the sides, vertically centred – white squares (no round buttons on the SULO sites).
   Dots and pause bottom right, so the text of the slide stays free. Touch screens: no arrows (swiping), dots stay. */
.sg-stage__arrow,
.sg-stage__toggle {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 6px 16px -8px rgba(21, 26, 25, .5);
  color: var(--wp--preset--color--ink);
  cursor: pointer;
  transition: background-color 200ms ease;

  &:hover { background: #fff; }
  &:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
}

.sg-stage__arrow {
  position: absolute;
  top: 50%;
  z-index: 3;
  margin-top: -22px;

  &::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 10px;
    height: 10px;
    border-top: 2px solid currentColor;
    border-right: 2px solid currentColor;
  }

  &.is-prev { left: 24px; }
  &.is-next { right: 24px; }
  &.is-prev::before { transform: translate(-30%, -50%) rotate(-135deg); }
  &.is-next::before { transform: translate(-70%, -50%) rotate(45deg); }
}

@media (hover: none) {
  .sg-stage__arrow { display: none; }
}

/* where the page column reaches the arrows (screens below ~1480 px), the text keeps clear of them */
@media (hover: hover) and (min-width: 1024px) and (max-width: 1480px) {
  .sg-stage.has-controls .sg-slide__in { padding-inline: 84px; }
  .sg-stage.has-controls.has-box .sg-slide__in { margin-left: 84px; }
}

.sg-stage__nav {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 28px;
  z-index: 3;
  max-width: calc(var(--wp--style--global--wide-size, 1312px) + 2 * var(--wp--custom--gutter, 24px));
  margin: 0 auto;
  padding: 0 var(--wp--custom--gutter, 24px);
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 14px;
  color: #fff;
  pointer-events: none; /* the empty part of the row does not cover the text or buttons of the slide */

  & > * { pointer-events: auto; }
}

.sg-stage__dots {
  display: flex;
  gap: 8px;
}

.sg-stage__dot {
  width: 28px;
  height: 24px; /* touch target; the visible bar is the line in the middle */
  padding: 0;
  border: 0;
  background: linear-gradient(currentColor, currentColor) center / 100% 3px no-repeat;
  color: inherit; /* white of the controls – buttons would otherwise use the black text colour of the browser */
  opacity: .55;
  cursor: pointer;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .45));
  transition: opacity 200ms ease, width 260ms var(--wp--custom--ease-out);

  &[aria-current="true"] { opacity: 1; width: 44px; }
  &:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
}

/* pause / play (only when the slides change by themselves) */
.sg-stage__toggle {
  position: relative;

  /* pause: two bars */
  &::before,
  &::after {
    content: "";
    position: absolute;
    top: 50%;
    width: 3px;
    height: 12px;
    background: currentColor;
    transform: translateY(-50%);
  }
  &::before { left: calc(50% - 5px); }
  &::after { left: calc(50% + 2px); }

  /* play: triangle */
  &.is-paused::before {
    left: calc(50% - 3px);
    width: 0;
    height: 0;
    background: none;
    border-style: solid;
    border-width: 7px 0 7px 11px;
    border-color: transparent transparent transparent currentColor;
  }
  &.is-paused::after { display: none; }
}

/* ---------- option "Text box": the text of each slide in a box (white, teal or dark) that sits on the lower edge
   of the image, aligned with the page column – off-grid over the photo instead of text on a shade ---------- */
.sg-stage.has-box {
  & .sg-slide::before { background: none; } /* the box gives the contrast */

  & .sg-slide__in {
    width: min(600px, calc(100% - 2 * var(--wp--custom--gutter, 24px)));
    max-width: none;
    margin: 0 0 0 max(var(--wp--custom--gutter, 24px), calc((100% - var(--wp--style--global--wide-size, 1312px)) / 2));
    padding: 40px 44px 44px;
    gap: 14px;
    background: #fff;
    color: var(--wp--preset--color--ink);

    & > * { max-width: none; }
  }

  &.has-controls .sg-slide__in { padding-bottom: 44px; }
  &.is-pos-center .sg-slide__in { margin-block: auto; }

  &.is-box-teal .sg-slide__in { background: var(--wp--preset--color--teal); color: #fff; }
  &.is-box-dark .sg-slide__in { background: var(--wp--preset--color--ink); color: #fff; }

  /* buttons in the box: white box = normal buttons; teal / dark box = white main button, white outline */
  &.is-box-white .wp-block-button.is-style-ghost .wp-block-button__link {
    border-color: var(--wp--preset--color--teal);
    color: var(--wp--preset--color--teal);
  }
  &:is(.is-box-teal, .is-box-dark) .wp-block-button:not(.is-style-ghost, .is-style-link) .wp-block-button__link {
    border-color: #fff;
    background: #fff;
    color: var(--wp--preset--color--teal);
  }
}

/* phones and tablets: the box sits BELOW the image (the image stays whole), the dots move to the top of the stage */
@media (max-width: 1023px) {
  .sg-stage.has-box {
    & .sg-slide { flex-direction: column; align-items: stretch; min-height: 0; }
    & .sg-slide__bg { position: relative; inset: auto; height: clamp(220px, 48svh, 460px); flex: none; }
    & .sg-slide__in { width: 100%; margin: 0; flex: 1; padding: 28px var(--wp--custom--gutter, 24px) 32px; }
    &.has-controls .sg-slide__in { padding-bottom: 32px; }
    & .sg-stage__nav { top: 20px; bottom: auto; }
  }
}
/* editor: slides one below the other */
.sg-stage.is-editing .sg-stage__track {
  display: block;
  overflow: visible;

  & > .sg-slide { margin-bottom: 4px; min-height: min(var(--stage-h), 520px); }
}
