/*
 * Services — Block: ds-services
 *
 * Written mobile-first on purpose. The base layer is a plain vertical list of
 * photo cards that needs no JS and cannot collapse: every frame gets its size
 * from `aspect-ratio`, and every photo is absolutely stretched inside it.
 *
 * The pinned scroll deck is an enhancement layered on top, gated behind BOTH
 * a wide viewport AND the `is-deck` class that ds-services.js only adds once
 * it has successfully taken over. If the script never runs, the list stays.
 *
 * @package Dreamy_Signal
 */

.ds-services {
	--sv-fg: var(--ds-text, #fff);
	--sv-muted: color-mix(in srgb, var(--sv-fg) 58%, transparent);
	--sv-accent: #ff4a1a;
	--sv-shade: #07070b;

	--sv-pad-x: clamp(0.8rem, 3.2vw, 2.4rem);
	--sv-pad-y: clamp(0.85rem, 2.2vw, 1.4rem);
	--sv-gap: clamp(0.7rem, 2.4vw, 1.15rem);
	--sv-radius: clamp(0.95rem, 3vw, 1.55rem);

	/* Space reserved for the fixed header / floating dock. */
	--sv-head: 3.6rem;
	--sv-dock: 5.4rem;

	/* Card aspect on the mobile list. */
	--sv-ratio: 16 / 10;

	background: transparent;
	box-sizing: border-box;
	color: var(--sv-fg);
	isolation: isolate;
	position: relative;
	width: 100%;
}

.ds-services *,
.ds-services *::before,
.ds-services *::after {
	box-sizing: border-box;
}

.ds-services[lang="en"] {
	font-family: var(--ds-font-en);
}

.ds-services[lang="fa"],
.ds-services[lang="ar"] {
	font-family: var(--ds-font-fa), var(--ds-font-en);
}

/* ------------------------------------------------------------------ *
 * Shell
 * ------------------------------------------------------------------ */

.ds-services__pin {
	display: flex;
	flex-direction: column;
	gap: var(--sv-gap);
	padding:
		calc(var(--sv-pad-y) + env(safe-area-inset-top, 0px))
		max(var(--sv-pad-x), env(safe-area-inset-right, 0px))
		calc(var(--sv-dock) + env(safe-area-inset-bottom, 0px))
		max(var(--sv-pad-x), env(safe-area-inset-left, 0px));
	position: relative;
	width: 100%;
}

html.ds-has-header .ds-services__pin {
	padding-block-start: calc(var(--sv-pad-y) + var(--sv-head) + env(safe-area-inset-top, 0px));
}

/* ------------------------------------------------------------------ *
 * Intro header
 * ------------------------------------------------------------------ */

.ds-services__head {
	display: flex;
	flex-direction: column;
	flex: 0 0 auto;
	gap: clamp(0.6rem, 2.4vw, 0.95rem);
	margin-inline: auto;
	max-width: min(96rem, 100%);
	width: 100%;
	z-index: 2;
}

.ds-services__intro {
	display: grid;
	gap: 0.3rem;
	min-width: 0;
}

.ds-services__kicker {
	align-items: center;
	color: var(--sv-muted);
	display: inline-flex;
	font-family: var(--ds-font-mono);
	font-size: clamp(0.5rem, 1.9vw, 0.58rem);
	gap: 0.4rem;
	letter-spacing: 0.22em;
	margin: 0;
	text-transform: uppercase;
}

.ds-services[dir="rtl"] .ds-services__kicker {
	font-family: var(--ds-font-fa);
	letter-spacing: 0.06em;
	text-transform: none;
}

.ds-services__kicker-dot {
	background: var(--sv-accent);
	border-radius: 50%;
	box-shadow: 0 0 0 4px color-mix(in srgb, var(--sv-accent) 18%, transparent);
	flex: 0 0 auto;
	height: 6px;
	width: 6px;
}

.ds-services__headline {
	display: flex;
	flex-direction: column;
	font-size: clamp(1.3rem, 6.4vw, 2.55rem);
	font-weight: 800;
	gap: 0.02em;
	letter-spacing: -0.045em;
	line-height: 1;
	margin: 0;
	text-wrap: balance;
}

.ds-services[dir="rtl"] .ds-services__headline {
	letter-spacing: -0.015em;
	line-height: 1.2;
}

.ds-services[lang="en"] .ds-services__headline {
	font-family: var(--ds-font-en);
}

.ds-services__line--soft {
	color: var(--sv-muted);
}

.ds-services__lead {
	color: var(--sv-muted);
	font-size: clamp(0.8rem, 2.9vw, 0.95rem);
	line-height: 1.6;
	margin: 0;
	max-width: 48ch;
	text-wrap: pretty;
}

.ds-services[dir="rtl"] .ds-services__lead {
	line-height: 1.8;
	max-width: 52ch;
}

/* ------------------------------------------------------------------ *
 * CTA
 * ------------------------------------------------------------------ */

.ds-services__cta {
	align-items: center;
	align-self: flex-start;
	background: var(--sv-fg);
	border: 1px solid var(--sv-fg);
	border-radius: 999px;
	color: #000;
	display: inline-flex;
	flex: 0 0 auto;
	font-size: clamp(0.78rem, 2.8vw, 0.82rem);
	font-weight: 700;
	gap: 0.55rem;
	justify-content: center;
	min-height: 2.6rem;
	padding-inline: 1.2rem;
	text-decoration: none;
	transition: transform 320ms var(--ds-transition-ease, ease);
	white-space: nowrap;
	-webkit-tap-highlight-color: transparent;
}

.ds-services[lang="en"] .ds-services__cta {
	letter-spacing: -0.02em;
}

.ds-services__cta:focus-visible {
	outline: 2px solid var(--sv-accent);
	outline-offset: 3px;
}

.ds-services__cta-arrow {
	display: block;
	flex: 0 0 auto;
	height: 10px;
	overflow: visible;
	position: relative;
	transition: width 280ms var(--ds-transition-ease, ease);
	width: 14px;
}

.ds-services__cta-arrow::before {
	background: currentColor;
	content: "";
	height: 1.5px;
	inset-block-start: calc(50% - 0.75px);
	inset-inline: 0 1px;
	position: absolute;
}

.ds-services__cta-arrow::after {
	border-block-start: 1.5px solid currentColor;
	border-inline-end: 1.5px solid currentColor;
	content: "";
	height: 6px;
	inset-block-start: calc(50% - 3px);
	inset-inline-end: 0;
	position: absolute;
	transform: rotate(45deg);
	width: 6px;
}

.ds-services[dir="rtl"] .ds-services__cta-arrow,
[dir="rtl"] .ds-services .ds-services__cta-arrow {
	transform: scaleX(-1);
}

/* ------------------------------------------------------------------ *
 * Stage + deck — base (mobile) layer is a simple list
 * ------------------------------------------------------------------ */

.ds-services__stage {
	flex: 1 1 auto;
	margin-inline: auto;
	max-width: min(96rem, 100%);
	min-width: 0;
	position: relative;
	width: 100%;
}

.ds-services__deck {
	display: grid;
	gap: var(--sv-gap);
	position: relative;
	width: 100%;
}

.ds-services__card {
	min-width: 0;
	position: relative;
	width: 100%;
}

.ds-services__frame {
	aspect-ratio: var(--sv-ratio);
	background-color: var(--sv-shade);
	border-radius: var(--sv-radius);
	box-shadow:
		0 18px 44px rgba(0, 0, 0, 0.36),
		0 0 0 1px rgba(255, 255, 255, 0.07);
	container-type: inline-size;
	isolation: isolate;
	min-height: 10.5rem;
	overflow: hidden;
	position: relative;
	width: 100%;
}

/*
 * The media wrapper and the photo are both absolutely stretched. This is the
 * part that keeps photos on screen: the frame owns the box, the photo only
 * ever fills it, so a slow or oversized upload can never resize the layout.
 */
.ds-services__media {
	background-color: var(--sv-shade);
	inset: 0;
	overflow: hidden;
	position: absolute;
}

.ds-services__photo {
	display: block;
	height: 100%;
	inset: 0;
	max-width: none;
	object-fit: cover;
	object-position: center;
	pointer-events: none;
	position: absolute;
	width: 100%;
}

.ds-services__veil {
	background:
		linear-gradient(
			180deg,
			rgba(0, 0, 0, 0.05) 0%,
			rgba(0, 0, 0, 0.18) 46%,
			rgba(0, 0, 0, 0.62) 100%
		);
	inset: 0;
	pointer-events: none;
	position: absolute;
}

/* ------------------------------------------------------------------ *
 * Card copy — sized against the card, not the viewport
 * ------------------------------------------------------------------ */

.ds-services__copy {
	display: flex;
	flex-direction: column;
	gap: 0.22rem;
	inset-block-end: clamp(0.8rem, 4cqi, 1.8rem);
	inset-inline: clamp(0.85rem, 4cqi, 2rem);
	pointer-events: none;
	position: absolute;
	z-index: 1;
}

.ds-services__index {
	color: rgba(255, 255, 255, 0.72);
	font-family: var(--ds-font-mono);
	font-size: clamp(0.56rem, 2cqi, 0.62rem);
	letter-spacing: 0.22em;
}

.ds-services__title {
	color: #fff;
	font-size: clamp(1.15rem, 7cqi, 3.1rem);
	font-weight: 800;
	letter-spacing: -0.038em;
	line-height: 1.06;
	margin: 0;
	text-shadow: 0 10px 34px rgba(0, 0, 0, 0.38);
	text-wrap: balance;
}

.ds-services[dir="rtl"] .ds-services__title {
	letter-spacing: -0.015em;
	line-height: 1.2;
}

.ds-services[lang="en"] .ds-services__title {
	font-weight: 900;
}

.ds-services__body {
	color: rgba(255, 255, 255, 0.84);
	display: -webkit-box;
	font-size: clamp(0.78rem, 2.6cqi, 1.02rem);
	line-height: 1.6;
	margin: 0;
	max-width: 44ch;
	overflow: hidden;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
	line-clamp: 3;
}

.ds-services[dir="rtl"] .ds-services__body {
	line-height: 1.8;
	max-width: 48ch;
}

/* Narrow cards: drop the body copy rather than let it crush the title. */
@container (max-width: 20rem) {
	.ds-services__body {
		display: none;
	}
}

/* ------------------------------------------------------------------ *
 * Progress rail — only meaningful while the deck is driving
 * ------------------------------------------------------------------ */

.ds-services__rail {
	display: none;
}

/* ------------------------------------------------------------------ *
 * Deck mode — pinned, scroll-driven stack. Phones get this too.
 *
 * Everything here hangs off `.is-deck`, which ONLY ds-services.js applies,
 * and only immediately before its first paint. There is deliberately no media
 * query around this block: a gate duplicated in CSS and JS can drift apart,
 * and a viewport where CSS parks the cards but JS never moves them would show
 * one card and three blanks. The class is the single source of truth.
 * ------------------------------------------------------------------ */

.ds-services.is-deck {
	--sv-pad-y: clamp(0.5rem, 1.4vh, 1.05rem);
	--sv-gap: clamp(0.4rem, 1.2vh, 0.8rem);
	/* Room above the deck for the receded cards to peek into.
	   ds-services.js reads this padding back to derive its peek step. */
	--sv-room: clamp(18px, 3.4vh, 54px);

	/*
	 * The section must stay free to grow: ScrollTrigger injects a pin-spacer
	 * around the pin whose height is the whole scroll range. Pinning the
	 * section itself to one viewport would let later sections overlap it.
	 */
	min-height: var(--sv-vh, 100dvh);
}

/*
 * `--sv-vh` is a locked pixel height written by the script. On phones the
 * dynamic viewport shrinks and grows as the URL bar slides, and feeding that
 * into a pinned height makes the whole stage twitch on every scroll.
 */
.ds-services.is-deck .ds-services__pin {
	height: var(--sv-vh, 100dvh);
	overflow: hidden;
}

.ds-services.is-deck .ds-services__stage {
	flex: 1 1 auto;
	min-height: 0;
	overflow: hidden;
	padding-block-start: var(--sv-room);
}

.ds-services.is-deck .ds-services__deck {
	display: block;
	gap: 0;
	height: 100%;
}

.ds-services.is-deck .ds-services__card {
	height: 100%;
	inset: 0;
	position: absolute;
	transform: translate3d(0, 104%, 0);
	transform-origin: 50% 0%;
	visibility: hidden;
}

/*
 * `will-change` is scoped to the cards actually on stage. Promoting all of
 * them would pin four full-screen photo layers in memory at once, which is
 * what pushes low-end phones into dropped frames.
 */
.ds-services.is-deck .ds-services__card.is-shown {
	visibility: visible;
	will-change: transform;
}

/*
 * Safety net for the frame between `is-deck` landing and the script's first
 * paint: show card one at rest so the stage is never empty. JS overrides this
 * with an inline transform on its first pass.
 */
.ds-services.is-deck .ds-services__card:first-child {
	transform: translate3d(0, 0, 0);
	visibility: visible;
}

/* Later cards slide over earlier ones, so DOM order is paint order. */
.ds-services.is-deck .ds-services__card:nth-child(1) { z-index: 1; }
.ds-services.is-deck .ds-services__card:nth-child(2) { z-index: 2; }
.ds-services.is-deck .ds-services__card:nth-child(3) { z-index: 3; }
.ds-services.is-deck .ds-services__card:nth-child(4) { z-index: 4; }
.ds-services.is-deck .ds-services__card:nth-child(5) { z-index: 5; }
.ds-services.is-deck .ds-services__card:nth-child(6) { z-index: 6; }

.ds-services.is-deck .ds-services__frame {
	aspect-ratio: auto;
	height: 100%;
	min-height: 0;
}

.ds-services.is-deck .ds-services__copy {
	opacity: 0;
	transform: translateY(12px);
	transition: opacity 240ms ease-out, transform 240ms ease-out;
}

.ds-services.is-deck .ds-services__card.is-live .ds-services__copy,
.ds-services.is-deck .ds-services__card.is-next .ds-services__copy {
	opacity: 1;
	transform: none;
}

/* Receded cards only show a sliver, so hide their copy entirely. */
.ds-services.is-deck .ds-services__card.is-past .ds-services__copy {
	opacity: 0;
	transition-duration: 160ms;
}

/* ---------------- Rail — the deck's progress readout ---------------- */

.ds-services.is-deck .ds-services__rail {
	align-items: center;
	display: flex;
	flex: 0 0 auto;
	gap: clamp(0.5rem, 2.4vw, 0.75rem);
	list-style: none;
	margin: 0;
	margin-inline: auto;
	max-width: min(96rem, 100%);
	padding: 0;
	width: 100%;
}

.ds-services__rail-step {
	color: color-mix(in srgb, var(--sv-fg) 34%, transparent);
	flex: 1 1 0;
	font-family: var(--ds-font-mono);
	font-size: clamp(0.5rem, 2vw, 0.58rem);
	letter-spacing: 0.18em;
	padding-block-start: 0.4rem;
	position: relative;
	transition: color 260ms ease;
}

.ds-services__rail-step::before {
	background: color-mix(in srgb, var(--sv-fg) 16%, transparent);
	content: "";
	height: 1px;
	inset-block-start: 0;
	inset-inline: 0;
	position: absolute;
	transition: background-color 260ms ease;
}

.ds-services__rail-step.is-on {
	color: var(--sv-fg);
}

.ds-services__rail-step.is-on::before {
	background: var(--sv-accent);
}

/* ---------------- Deck proportions per viewport ---------------- */

/*
 * Phones in deck mode: the header has to give ground so the card keeps a
 * usable share of the screen. The lead drops to two lines rather than
 * disappearing, since it is the only body copy above the fold.
 */
@media (max-width: 759px) {
	.ds-services.is-deck .ds-services__lead {
		display: -webkit-box;
		overflow: hidden;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		line-clamp: 2;
	}

	.ds-services.is-deck .ds-services__cta {
		min-height: 2.4rem;
	}
}

/* Tight phones: the lead is a luxury the card needs more than the reader. */
@media (max-width: 759px) and (max-height: 700px) {
	.ds-services.is-deck .ds-services__lead {
		display: none;
	}
}

/* Tablets and up: header becomes a row, CTA sits beside the intro. */
@media (min-width: 760px) {
	.ds-services.is-deck .ds-services__head {
		align-items: flex-end;
		flex-direction: row;
		gap: 0.75rem 1.6rem;
		justify-content: space-between;
	}

	.ds-services.is-deck .ds-services__intro {
		max-width: min(40rem, 100%);
	}

	.ds-services.is-deck .ds-services__cta {
		align-self: auto;
	}

	.ds-services__rail-step {
		flex: 0 0 auto;
		min-width: 3.5rem;
	}
}

/* ------------------------------------------------------------------ *
 * Hover affordances — pointer devices only
 * ------------------------------------------------------------------ */

@media (hover: hover) and (pointer: fine) {
	.ds-services__cta:hover {
		transform: translateY(-2px);
	}

	.ds-services__cta:hover .ds-services__cta-arrow {
		width: 1.5rem;
	}

	.ds-services__photo {
		transition: transform 900ms cubic-bezier(0.16, 1, 0.3, 1);
	}

	.ds-services__card:hover .ds-services__photo {
		transform: scale(1.045);
	}
}

/* ------------------------------------------------------------------ *
 * Viewport tuning for the list layer
 *
 * Only `--sv-ratio` and the spacing tokens change across breakpoints — the
 * layout itself never does. Type and card padding come from clamp() and
 * container units, so the steps below are corrections, not rebuilds.
 * ------------------------------------------------------------------ */

/* Small phones: nearly square cards so the photo still reads as a scene. */
@media (max-width: 400px) {
	.ds-services {
		--sv-ratio: 4 / 3;
	}

	.ds-services__lead {
		display: -webkit-box;
		overflow: hidden;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 3;
		line-clamp: 3;
	}

	/* A full-width tap target beats a floating pill at this size. */
	.ds-services__cta {
		align-self: stretch;
	}
}

/* Large phones / small tablets. */
@media (min-width: 560px) {
	.ds-services {
		--sv-ratio: 16 / 9;
	}
}

/*
 * Tablets and up: cap the card width. Left unbounded, a 1024px-wide 16/9 card
 * grows taller than the viewport and the list stops scanning as a list.
 */
@media (min-width: 760px) {
	.ds-services {
		--sv-ratio: 2 / 1;
	}

	.ds-services__stage {
		max-width: min(64rem, 100%);
	}

	.ds-services__head {
		align-items: flex-end;
		flex-direction: row;
		gap: 0.75rem 1.6rem;
		justify-content: space-between;
		max-width: min(64rem, 100%);
	}

	.ds-services__intro {
		max-width: min(40rem, 100%);
	}

	.ds-services__cta {
		align-self: auto;
	}
}

/* Desktop without the deck (no JS, reduced motion, or a short viewport). */
@media (min-width: 981px) {
	.ds-services {
		--sv-ratio: 21 / 9;
	}

	.ds-services__stage,
	.ds-services__head {
		max-width: min(96rem, 100%);
	}
}

/*
 * Short landscape — phones held sideways, and the short-wide laptops the deck
 * gate turns away. Flatten the cards so a whole one fits between the header
 * and the dock, and drop the copy that has nowhere to go.
 */
@media (orientation: landscape) and (max-height: 640px) {
	.ds-services {
		--sv-ratio: 3 / 1;
		--sv-dock: 4.4rem;
		--sv-head: 3rem;
		--sv-pad-y: 0.5rem;
	}

	.ds-services__frame {
		min-height: 7.5rem;
	}

	.ds-services__lead {
		display: none;
	}
}

/* Ultra-wide: stop the stage from stretching past a readable measure. */
@media (min-width: 1800px) {
	.ds-services {
		--sv-ratio: 24 / 9;
	}
}

/*
 * Coarse pointers get no hover state, so the photo's resting scale is all
 * they will ever see — keep it at 1 to avoid a soft-looking crop.
 */
@media (pointer: coarse) {
	.ds-services__photo {
		transform: none;
	}
}

/* ------------------------------------------------------------------ *
 * Reduced motion — the list layer is already the calm version, so all
 * this needs to do is make sure no enhancement transitions remain.
 * ------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
	.ds-services__cta,
	.ds-services__cta-arrow,
	.ds-services__photo,
	.ds-services__copy,
	.ds-services__rail-step,
	.ds-services__rail-step::before {
		transition: none;
	}

	.ds-services__card:hover .ds-services__photo {
		transform: none;
	}
}
