/* ==========================================================================
   N&N Dental: "Een kies van binnen" scroll explainer (treatment pages only).
   Markup: section.tlayers[data-tooth-layers], see js/tooth-layers.js.
   Uses the tokens from style.css; adds nothing to it.
   ========================================================================== */

.tlayers {
  --tl-bg: #F6F1E7;          /* = --ivory; read by the WebGL scene for fades */
  --tl-top: 4.6rem;          /* sticky offset below the compact header */
  --tl-stacked: 0;
  position: relative;
  padding-block: calc(var(--section) * 0.6) calc(var(--section) * 0.35);
  background: var(--ivory);
  border-bottom: var(--rule);
}

.tlayers__intro { max-width: 44rem; }
.tlayers__intro h2 { margin-bottom: 0.9rem; }
.tlayers__intro p:not(.kicker) { color: var(--muted); font-size: var(--fs-lede); line-height: 1.55; font-weight: 300; }
.tlayers__skip { margin-top: var(--s-3); }

.tlayers__track {
  display: grid;
  grid-template-columns: minmax(0, 11fr) minmax(0, 8fr);
  column-gap: clamp(2rem, 4.5vw, 5.5rem);
  margin-top: var(--s-4);
}

/* ---------- stage ---------- */
.tlayers__stage {
  position: sticky;
  top: var(--tl-top);
  height: calc(100vh - var(--tl-top));
  height: calc(100svh - var(--tl-top));
  min-height: 420px;
  max-height: 980px;
  isolation: isolate;
}
.tlayers__gl, .tlayers__still {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* the close-up states crop the roots: let the crop dissolve instead of cutting */
  -webkit-mask-image: linear-gradient(to bottom, #000 80%, transparent 99%);
  mask-image: linear-gradient(to bottom, #000 80%, transparent 99%);
}
.tlayers__still {
  object-fit: contain;
  object-position: center;
  opacity: 0;
  transition: opacity 600ms var(--ease);
  pointer-events: none;
  user-select: none;
}
.tlayers__still.is-on { opacity: 1; }
.tlayers__canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  display: block;
  opacity: 0;
  transition: opacity 900ms var(--ease);
}
.tlayers__stage.is-live .tlayers__canvas { opacity: 1; }
.tlayers__stage.is-live .tlayers__still { opacity: 0; transition-duration: 900ms; }

/* ---------- steps ---------- */
.tlayers__steps {
  list-style: none;
  margin: 0;
  padding: 6vh 0 22vh;
}
.tlayers__step {
  margin: 0;
  min-height: 88vh;
  min-height: 88svh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-block: var(--s-4);
  transition: opacity 600ms var(--ease);
}
/* Inactive steps recede by colour, not opacity: everything drops to --muted
   (#6A6357 on ivory = 5.3:1), so they stay readable (WCAG 1.4.3). */
.tlayers__step .kicker, .tlayers__step h3, .tlayers__step h3 em, .tlayers__step > p,
.tlayers__link-title, .tlayers__link-arrow {
  transition: color 600ms var(--ease);
}
.tlayers__step .kicker::before { transition: background-color 600ms var(--ease); }
.tlayers.is-ready .tlayers__step:not(.is-active):not(:focus-within) :is(.kicker, h3, h3 em, .tlayers__link-title, .tlayers__link-arrow),
.tlayers.is-ready .tlayers__step:not(.is-active):not(:focus-within) > p { color: var(--muted); }
.tlayers.is-ready .tlayers__step:not(.is-active):not(:focus-within) .kicker::before { background-color: var(--sand); }
.tlayers.is-ready .tlayers__step:not(.is-active):not(:focus-within) .tlayers__links { border-top-color: var(--sand); }
.tlayers.is-ready .tlayers__step .tlayers__links a:hover .tlayers__link-title { color: var(--brass); }

.tlayers__step .kicker { margin-bottom: 1.1rem; }
.tlayers__step h3 {
  font-size: clamp(1.75rem, 1.25rem + 1.7vw, 2.75rem);
  line-height: 1.08;
  margin-bottom: 1.1rem;
}
.tlayers__step > p { color: var(--text); max-width: 34rem; }

.tlayers__links {
  list-style: none;
  margin: var(--s-3) 0 0;
  padding: 0;
  border-top: 1px solid var(--ink);
  max-width: 34rem;
}
.tlayers__links > li { margin: 0; border-bottom: var(--rule); }
.tlayers__links a {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 1.5rem;
  column-gap: var(--s-2);
  row-gap: 0.15rem;
  align-items: baseline;
  padding: 0.95rem 0;
  color: var(--text);
  background-image: none;
  transition: padding .5s var(--ease-out), background-color .5s var(--ease);
}
.tlayers__link-title { font-family: var(--serif); font-size: clamp(1.2rem, 1.05rem + 0.5vw, 1.45rem); color: var(--ink); line-height: 1.2; }
.tlayers__link-desc { grid-column: 1 / 2; color: var(--muted); font-size: 0.95rem; line-height: 1.55; }
.tlayers__link-arrow { grid-row: 1; grid-column: 2; justify-self: end; color: var(--ink); transition: transform .5s var(--ease-out); }
.tlayers__links a:hover { padding-left: 0.75rem; background-color: var(--paper); }
.tlayers__links a:hover .tlayers__link-title { color: var(--brass); }
.tlayers__links a:hover .tlayers__link-arrow { transform: translateY(3px); }
.tlayers__links a:focus-visible { outline: 2px solid var(--brass); outline-offset: 3px; }

/* ---------- stacked (tablet / phone): stage on top, text scrolls beneath ---------- */
@media (max-width: 900px) {
  .tlayers { --tl-stacked: 1; --tl-top: 4.4rem; --tl-stage-h: max(250px, 46svh); }
  .tlayers__track { grid-template-columns: minmax(0, 1fr); margin-top: var(--s-3); }
  .tlayers__stage {
    z-index: 2;
    height: 46vh;
    height: var(--tl-stage-h);
    min-height: 250px;
    margin-inline: calc(var(--gutter) * -1);
    background: var(--tl-bg);
    box-shadow: 0 1px 0 var(--sand);
  }
  .tlayers__stage::after { /* soft hand-off where the text slides under */
    content: "";
    position: absolute;
    left: 0; right: 0; bottom: -2.5rem;
    height: 2.5rem;
    background: linear-gradient(var(--tl-bg), rgba(246, 241, 231, 0));
    pointer-events: none;
  }
  .tlayers__steps { padding: 2vh 0 16vh; position: relative; z-index: 1; }
  .tlayers__step { min-height: 62vh; min-height: 62svh; justify-content: flex-start; padding-top: 1.5rem; }
}
@media (max-width: 900px) and (max-height: 560px) {
  .tlayers { --tl-stage-h: 40svh; }
  .tlayers__stage { min-height: 0; }
}
/* Keep focused / targeted text clear of the sticky stage (WCAG 2.4.11).
   Effective offset = html scroll-padding-top (110px, style.css) + this margin,
   which together equal header (--tl-top) + stage + a 1.25rem gap.
   js/tooth-layers.js also corrects focus scrolling where an engine ignores this. */
@media (max-width: 900px) and (min-height: 501px) {
  .tlayers__step, .tlayers__links a {
    scroll-margin-top: calc(var(--tl-top) + var(--tl-stage-h) + 1.25rem - 110px);
    scroll-margin-bottom: 1rem;
  }
}
/* Short viewports / 400% zoom (WCAG 1.4.10): a sticky stage would eat most of the
   screen, so it becomes a small static picture above the text. */
@media (max-height: 500px) {
  .tlayers { --tl-stacked: 0; --tl-top: 0px; }
  .tlayers__track { grid-template-columns: minmax(0, 1fr); margin-top: var(--s-3); }
  .tlayers__stage {
    position: relative;
    top: auto;
    z-index: auto;
    height: min(62vh, 300px);
    min-height: 0;
    max-height: none;
    width: min(100%, 300px);
    margin-inline: auto;
    box-shadow: none;
  }
  .tlayers__stage::after { display: none; }
  .tlayers__steps { padding: 0 0 6vh; }
  .tlayers__step { min-height: 0; justify-content: flex-start; padding-block: var(--s-3); }
}

@media (prefers-reduced-motion: reduce) {
  /* style.css shortens every transition; a calm crossfade between stills stays. */
  .tlayers__still { transition-duration: 450ms !important; }
}

@media print {
  .tlayers__stage { display: none; }
  .tlayers.is-ready .tlayers__step { min-height: 0; }
}
