/*
 * services: the Fan Deck (spec 6.4 and 8).
 *
 * Two layouts:
 * 1. Static (no JS, reduced motion, motion-off): the fanned poster beside the
 *    full list of services with their lines. No pin, no counter.
 * 2. Deck (html.motion-ready): a pinned 100svh stage with the WebGL canvas (or
 *    the poster crossfade when WebGL is unavailable) and the DOM beats over it.
 *    Desktop pins the whole section; compact screens pin .svc-frame and show
 *    the service names as chips after the pin.
 */

.services {
  --svc-cols: 5;
  --svc-col: calc((min(100%, var(--maxw)) - 2 * var(--gx) - (var(--cols) - 1) * var(--gutter)) / var(--cols));
  --svc-left: calc((100% - min(100%, var(--maxw))) / 2 + var(--gx));
  --svc-copy-w: calc(var(--svc-col) * var(--svc-cols) + var(--gutter) * (var(--svc-cols) - 1));
  --svc-top: 0px;
  position: relative;
  isolation: isolate;
}

/* ---------- shared pieces ---------- */

.svc-say {
  font-family: var(--f-display);
  font-weight: 900;
  font-stretch: 100%;
  /* Leading of 1 keeps descenders (the g in "Everything") off the next line's ascenders. */
  line-height: 1;
  letter-spacing: -0.045em;
  text-wrap: balance;
  font-size: var(--fs-h2);
}
.svc-poster { display: block; }
.svc-poster img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.svc-caption { display: none; }
.svc-stage canvas { display: none; }

.svc-d-sub { margin-top: .9em; color: var(--fg); }
.svc-calls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  margin-top: 20px;
}
.svc-call {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  color: var(--link);
  text-decoration: none;
}
.svc-call__icon { width: 18px; height: 18px; flex: none; transition: transform .2s var(--ease-soft); }
.svc-call__name {
  font-family: var(--f-display);
  font-weight: 700;
  font-stretch: 88%;
  font-size: 1.0625rem;
  line-height: 1;
}
.svc-call__num {
  font: 500 .875rem/1 var(--f-body);
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
  color: var(--fg-soft);
}
.svc-call:hover .svc-call__name { text-decoration: underline; text-underline-offset: .18em; }
.svc-call:hover .svc-call__icon { transform: translateX(3px) rotate(-8deg); }

.svc-item__title { font: inherit; }
.svc-btn {
  display: flex;
  align-items: baseline;
  gap: 14px;
  width: 100%;
  min-height: 48px;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- 1. static layout ---------- */

.services { padding-block: var(--section-y); }
.svc-frame, .svc-copy, .svc-beats { display: contents; }
.services {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  column-gap: var(--gutter);
  padding-inline: max(var(--gx), (100% - var(--maxw)) / 2 + var(--gx));
  align-items: start;
}
.svc-eyebrow { grid-column: 1 / -1; margin-bottom: 20px; justify-self: start; }
.svc-beat--a, .svc-beat--b { grid-column: 1 / -1; }
.svc-beat--b { margin-top: .12em; }
.svc-beat--d { grid-column: 1 / -1; margin-top: 32px; }
.svc-beat--d .svc-say { font-size: var(--fs-h3); line-height: 1.02; letter-spacing: -0.03em; }
.svc-stage { grid-column: 1 / -1; margin-top: 40px; order: 1; }
.svc-index { grid-column: 1 / -1; margin-top: 40px; order: 2; }

.svc-btn { cursor: default; }
html.motion-ready .svc-btn { cursor: pointer; }
.svc-list { border-top: 1px solid var(--rule); }
.svc-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  padding: 14px 0 18px;
  border-bottom: 1px solid var(--rule-c);
}
.svc-item:last-child { border-bottom-color: var(--rule); }
.svc-btn__num { color: var(--fg-soft); flex: none; min-width: 2.2em; }
.svc-btn__name {
  font-family: var(--f-display);
  font-weight: 800;
  font-stretch: 96%;
  font-size: clamp(1.25rem, 1rem + 1vw, 1.75rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
}
.svc-item__line {
  padding-left: calc(2.2 * var(--fs-label) + 14px);
  font-size: var(--fs-body);
  line-height: 1.5;
  max-width: 44ch;
  color: var(--fg-soft);
}

@media (min-width: 1024px) {
  .services { grid-template-rows: auto auto auto auto 1fr; }
  .svc-eyebrow, .svc-beat--a, .svc-beat--b, .svc-beat--d, .svc-index { grid-column: 1 / span 6; }
  .svc-stage {
    grid-column: 7 / -1;
    grid-row: 1 / span 5;
    margin-top: 0;
    position: sticky;
    top: calc(var(--header-h) + 24px);
    align-self: start;
  }
  html.is-scrolled .svc-stage { top: 80px; }
}

/* ---------- 2. deck layout (motion allowed) ---------- */

html.motion-ready .services {
  display: block;
  padding: 0;
  overflow: clip;
}
html.motion-ready .svc-beat { display: block; }
html.motion-ready .svc-caption { display: block; }
html.motion-ready .svc-stage { margin: 0; align-self: auto; }
html.motion-ready .svc-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0;
  transition: opacity .6s var(--ease-soft);
}
html.motion-ready .svc-stage canvas.is-live { opacity: 1; }
html.motion-ready .svc-poster {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity .5s var(--ease-soft);
}
html.motion-ready .svc-poster.is-shown { opacity: 1; }
html.motion-ready .svc-stage.is-live .svc-poster { opacity: 0; transition-duration: .6s; }

/* Beats share one slot; the timeline crossfades them. Only A shows before JS. */
html.motion-ready .svc-beats {
  display: grid;
  grid-template-areas: 'beat';
}
html.motion-ready .svc-beats > .svc-beat { grid-area: beat; margin: 0; }
html.motion-ready .svc-beat--b,
html.motion-ready .svc-beat--d > * { opacity: 0; }
html.motion-ready .svc-caption { opacity: 0; visibility: hidden; }

.svc-counter {
  display: flex;
  align-items: baseline;
  gap: .18em;
  font-family: var(--f-display);
  font-weight: 800;
  font-stretch: 75%;
  font-size: var(--fs-counter);
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.svc-of { color: var(--fg-soft); font-size: .5em; letter-spacing: 0; }
.svc-flip { --flip-bg: var(--bg); }
.svc-name { margin-top: 14px; text-wrap: balance; }
.svc-line { margin-top: 12px; color: var(--fg-soft); }

/* List: in the deck the lines stay available to screen readers only. */
html.motion-ready .svc-item__line {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ----- desktop deck ----- */
@media (min-width: 1024px) {
  html.motion-ready .services {
    height: 100svh;
    min-height: 600px;
    --svc-top: 57px;
  }
  html.motion-ready .svc-frame { display: block; position: absolute; inset: 0; }
  html.motion-ready .svc-stage { position: absolute; inset: 0; }
  html.motion-ready .svc-poster {
    inset: calc(var(--svc-top) + 2svh) var(--gx) 2svh calc(var(--svc-left) + var(--svc-copy-w) + var(--gutter));
  }
  html.motion-ready .svc-copy {
    display: block;
    position: absolute;
    z-index: 2;
    left: var(--svc-left);
    top: calc(var(--svc-top) + clamp(20px, 4.5svh, 48px));
    width: var(--svc-copy-w);
  }
  html.motion-ready .svc-eyebrow { display: block; margin-bottom: clamp(14px, 2.4svh, 24px); }
  html.motion-ready .svc-say {
    font-size: min(var(--fs-h2), 6.6svh, (min(100vw, var(--maxw)) - 2 * var(--gx) - 11 * var(--gutter)) / 12 * var(--svc-cols) / 7);
  }
  html.motion-ready .svc-beat--d .svc-say { line-height: 1; letter-spacing: -0.045em; }
  html.motion-ready .svc-d-sub { font-size: var(--fs-body-l); }
  html.motion-ready .svc-name { font-size: min(var(--fs-h3), 5.6svh); }

  html.motion-ready .svc-index {
    position: absolute;
    z-index: 2;
    left: var(--svc-left);
    bottom: clamp(16px, 4svh, 40px);
    width: var(--svc-copy-w);
    margin: 0;
  }
  html.motion-ready .svc-list {
    border-top: 1px solid var(--rule);
    padding-top: 6px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-auto-flow: column;
    grid-template-rows: repeat(4, auto);
    column-gap: var(--gutter);
  }
  html.motion-ready .svc-item {
    display: block;
    padding: 0;
    border: 0;
  }
  html.motion-ready .svc-btn {
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 4px 0;
    font: 500 .95rem/1.2 var(--f-body);
    color: var(--ink-soft);
    transition: color .25s var(--ease-soft);
  }
  html.motion-ready .svc-btn__num { display: none; }
  html.motion-ready .svc-btn__name { font: inherit; letter-spacing: 0; }
  html.motion-ready .svc-btn::before {
    content: '';
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ink);
    transform: scale(0);
    transition: transform .25s var(--ease-soft);
  }
  html.motion-ready .svc-item.is-active .svc-btn { color: var(--ink); }
  html.motion-ready .svc-item.is-active .svc-btn::before { transform: scale(1); }
  html.motion-ready .svc-btn:hover { color: var(--ink); }
}
@media (min-width: 1280px) {
  html.motion-ready .services { --svc-cols: 4; }
}
@media (min-width: 1280px) and (min-height: 860px) {
  html.motion-ready .svc-list { grid-template-columns: 1fr; grid-template-rows: none; grid-auto-flow: row; }
}

/* ----- compact deck (phones and tablets) ----- */
@media (max-width: 1023px) {
  html.motion-ready .services { padding-bottom: calc(var(--section-y) * .5); }
  html.motion-ready .svc-frame {
    display: grid;
    grid-template-columns: var(--gx) minmax(0, 1fr) var(--gx);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    height: calc(100svh - var(--dock-h));
    min-height: 520px;
    padding-top: calc(var(--svc-top) + 14px);
    padding-bottom: 12px;
    background: var(--bg);
  }
  html.motion-ready .svc-copy { display: contents; }
  html.motion-ready .svc-eyebrow { grid-column: 2; grid-row: 1; margin-bottom: 12px; }
  html.motion-ready .svc-beats { display: contents; }
  html.motion-ready .svc-beats > .svc-beat--a,
  html.motion-ready .svc-beats > .svc-beat--b,
  html.motion-ready .svc-d {
    grid-column: 2;
    grid-row: 2;
    align-self: start;
    min-height: calc(24svh - 60px);
  }
  html.motion-ready .svc-beats > .svc-beat--d { display: contents; }
  html.motion-ready .svc-d-rest { grid-column: 2; grid-row: 4; align-self: start; }
  html.motion-ready .svc-say {
    font-size: var(--fs-h3);
    line-height: 1.02;
    letter-spacing: -0.035em;
  }
  html.motion-ready .svc-d-sub { font-size: var(--fs-body); margin-top: 8px; }
  html.motion-ready .svc-calls { margin-top: 6px; gap: 0 22px; }
  html.motion-ready .svc-stage {
    grid-column: 1 / -1;
    grid-row: 3;
    position: relative;
    min-height: 0;
  }
  html.motion-ready .svc-poster { inset: 0 var(--gx); }
  html.motion-ready .svc-beats > .svc-caption {
    grid-area: auto;
    grid-column: 2;
    grid-row: 4;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: 14px;
    align-items: center;
    align-content: start;
    min-height: 7.25rem;
  }
  html.motion-ready .svc-of { display: none; }
  html.motion-ready .svc-name { margin-top: 0; font-size: clamp(1.35rem, 1rem + 2.2vw, 2.25rem); }
  html.motion-ready .svc-line { grid-column: 2; margin-top: 6px; font-size: 1rem; line-height: 1.45; }


  html.motion-ready .svc-index { padding: 28px var(--gx) 0; margin: 0; }
  html.motion-ready .svc-list { display: flex; flex-wrap: wrap; gap: 0 8px; border: 0; }
  html.motion-ready .svc-item { display: block; padding: 0; border: 0; }
  html.motion-ready .svc-btn {
    display: inline-flex;
    align-items: center;
    width: auto;
    min-height: 48px;
    gap: 0;
  }
  html.motion-ready .svc-btn__num { display: none; }
  html.motion-ready .svc-btn__name {
    display: inline-flex;
    align-items: center;
    height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid currentColor;
    font-family: var(--f-display);
    font-weight: 700;
    font-stretch: 75%;
    font-size: var(--fs-label);
    line-height: 1;
    letter-spacing: .06em;
    text-transform: uppercase;
    white-space: nowrap;
    color: var(--ink-soft);
    transition: background-color .2s var(--ease-soft), color .2s var(--ease-soft);
  }
  html.motion-ready .svc-item.is-active .svc-btn__name { background: var(--ink); border-color: var(--ink); color: var(--paper); }
}
@media (min-width: 768px) and (max-width: 1023px) {
  html.motion-ready .services { --svc-top: 57px; }
}
/*
 * Landscape phones: the stacked layout needs about 520px of height, so short
 * landscape screens put the copy in a left column (eyebrow and beat at the top,
 * caption or calls at the bottom) and give the canvas the full height on the
 * right. deck.js frames the scene for this wide canvas (the `wide` plan).
 */
@media (max-width: 1023px) and (orientation: landscape) and (max-height: 560px) {
  html.motion-ready .svc-frame {
    grid-template-columns:
      max(var(--gx), env(safe-area-inset-left, 0px)) minmax(0, 37fr) var(--gutter) minmax(0, 63fr) env(safe-area-inset-right, 0px);
    grid-template-rows: auto auto minmax(0, 1fr);
    min-height: 0;
    padding-top: calc(var(--svc-top) + 12px);
    padding-bottom: 12px;
  }
  html.motion-ready .svc-eyebrow { margin-bottom: 10px; }
  html.motion-ready .svc-beats > .svc-beat--a,
  html.motion-ready .svc-beats > .svc-beat--b,
  html.motion-ready .svc-d { min-height: 0; }
  html.motion-ready .svc-say {
    font-size: clamp(1.3rem, 8svh, 2.25rem);
    line-height: 1;
  }
  /* The stage runs to the frame's bottom edge, so the cover's handle leaves the screen cleanly. */
  html.motion-ready .svc-stage { grid-column: 4; grid-row: 1 / -1; margin-bottom: -12px; }
  html.motion-ready .svc-poster { inset: 0; }
  html.motion-ready .svc-beats > .svc-caption {
    grid-row: 3;
    align-self: end;
    align-items: start;
    min-height: 0;
  }
  html.motion-ready .svc-d-rest { grid-row: 3; align-self: end; }
  html.motion-ready .svc-counter { font-size: clamp(2rem, 10svh, 2.75rem); }
  html.motion-ready .svc-name { font-size: clamp(1.1rem, 5.6svh, 1.5rem); }
  html.motion-ready .svc-line { font-size: .9375rem; line-height: 1.4; }
  html.motion-ready .svc-d-sub { margin-top: 0; }
  html.motion-ready .svc-calls { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 767px) {
  /* The call dock already shows both numbers; names alone keep the two links on one line. */
  html.motion-ready .svc-call__num { display: none; }
}

/* WebGL unavailable: posters only, the pin and beats still run. */
.services.is-posters .svc-stage canvas { display: none; }
