/*
 * RahkarTheme — rahkar/stories rail (frontend).
 *
 * Ships only on pages containing the block. Colors, sizes and weights come from
 * theme.json tokens. Corner radius does NOT: see the note on .rh-stories__ring —
 * the circles are exempt from the site-wide radius preset on purpose.
 *
 * This rail normally sits ABOVE the hero slider, i.e. at the very top of the
 * page — so every dimension here is fixed and explicit. Nothing about it may
 * depend on an image having loaded, or the hero below it would be pushed down
 * after paint and take the LCP with it. Height is reserved by the ring box,
 * not by the <img>.
 */

.wp-block-rahkar-stories {
	--rh-st-size: 64px;          /* circle diameter */
	--rh-st-gap: 14px;
	--rh-st-ring: 2px;
	margin-block: 0;
}

.rh-stories__heading {
	margin: 0 0 10px;
	font-size: var(--wp--preset--font-size--md, 1.125rem);
	font-weight: var(--wp--custom--fw--strong);
	color: var(--wp--preset--color--contrast, #0f1115);
}

.rh-stories__rail {
	display: flex;
	gap: var(--rh-st-gap);
	margin: 0;
	padding: 4px 0 2px;
	list-style: none;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: none;
	/* Rail scrolls edge-to-edge on phones; the scroll container itself is the
	 * only thing allowed to overflow, never the page. */
	scroll-snap-type: x proximity;
}
.rh-stories__rail::-webkit-scrollbar {
	display: none;
}

.rh-stories__item {
	flex: 0 0 auto;
	scroll-snap-align: start;
}

.rh-stories__btn {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
	/* The theme has no global border-box; this box has width + padding. */
	box-sizing: border-box;
	width: calc(var(--rh-st-size) + 16px);
	padding: 0;
	border: 0;
	background: none;
	font: inherit;
	color: inherit;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
}

/*
 * A story circle is a CIRCLE — 50%, never the radius token.
 *
 * The theme lets the owner pick a site-wide corner preset, and the `sharp`
 * preset sets `--wp--custom--radius--pill: 0` on <body> (see
 * rahkar_radius_preset_css()). Reading the token here turned every story into
 * a square with a square ring. Unlike a card or a button, a story ring is not
 * a themeable corner: roundness is the whole visual language of the pattern,
 * so it is deliberately exempt from the preset. Same reasoning as an avatar.
 */
.rh-stories__ring {
	box-sizing: border-box;
	display: block;
	width: var(--rh-st-size);
	height: var(--rh-st-size);
	padding: var(--rh-st-ring);
	border-radius: 50%;
	/* The Instagram story gradient, identical to the avatar ring in
	 * blocks/testimonials/style.css — the theme already speaks this visual
	 * language, and two different "story rings" on one page looked wrong.
	 * Deliberately NOT the brand token: this gradient IS the affordance that
	 * says "tap me, it plays". */
	background: linear-gradient(45deg, #feda75, #fa7e1e, #d62976, #962fbf, #4f5bd5);
}
.rh-stories__btn.is-seen .rh-stories__ring {
	background: var(--wp--preset--color--border, #e2e4e9);
}

.rh-stories__cover {
	/* box-sizing MATTERS here: the theme has no global border-box, so without
	 * it the 2px white border is added OUTSIDE the 100% width and the photo
	 * overflows the ring's padding box — the gradient gets covered on one side
	 * and the ring reads as uneven/broken. That was the "ugly ring" bug. */
	box-sizing: border-box;
	display: block;   /* kills the inline baseline gap, so the ring stays even */
	width: 100%;
	height: 100%;
	border-radius: 50%;
	object-fit: cover;
	/* The white gap between ring and photo — the Instagram story affordance. */
	border: 2px solid var(--wp--preset--color--base, #fff);
	background: var(--wp--preset--color--surface, #f7f7f8);
}

.rh-stories__label {
	max-width: 100%;
	overflow: hidden;
	font-size: var(--wp--preset--font-size--xs, 0.75rem);
	font-weight: var(--wp--custom--fw--base);
	line-height: 1.6;
	color: var(--wp--preset--color--text-muted, #5b6271);
	text-align: center;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.rh-stories__btn:hover .rh-stories__label,
.rh-stories__btn:focus-visible .rh-stories__label {
	color: var(--wp--preset--color--text, #1a1d23);
}

/* ─── Block options (inc/stories.php → rahkar_stories_render_rail) ───────
   Size, shape, ring and title. Each is a class on .rh-stories that swaps a
   custom property or two, so the rail's reserved height is still fixed by
   the ring box — no option can make the hero below it jump. */
.rh-stories--sm { --rh-st-size: 56px; }
.rh-stories--lg { --rh-st-size: 80px; --rh-st-ring: 3px; }

/* گوشه‌گرد — for covers that are a product shot rather than a face. A
   proportional radius, not the site-wide token, for the same reason the
   circle ignores it (see .rh-stories__ring): the shape is the option here,
   and the «sharp» preset would quietly turn it into a plain square. */
.rh-stories--rounded .rh-stories__ring { border-radius: 24%; }
.rh-stories--rounded .rh-stories__cover { border-radius: 20%; }

/* رنگ اصلی سایت instead of the Instagram gradient. */
.rh-stories--brand .rh-stories__ring {
	background: var(--wp--preset--color--primary, #0a66c2);
}
.rh-stories--brand .rh-stories__btn.is-seen .rh-stories__ring {
	background: var(--wp--preset--color--border, #e2e4e9);
}

/* No visible title — still the button's accessible name. */
.rh-stories--no-title .rh-stories__label {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}
.rh-stories--no-title .rh-stories__btn {
	position: relative;
	width: var(--rh-st-size);
}

/* Editor-only empty state (never rendered on the front end). */
.rh-stories-empty {
	margin: 0;
	padding: 14px;
	font-size: var(--wp--preset--font-size--sm, 0.875rem);
	color: var(--wp--preset--color--text-muted, #5b6271);
	background: var(--wp--preset--color--surface, #f7f7f8);
	border-radius: var(--wp--custom--radius--md, 0.5rem);
}

/* Phones: let the rail bleed to the screen edges so the last circle is
 * visibly cut off — the standard affordance that says "scroll me". */
@media (max-width: 600px) {
	.wp-block-rahkar-stories {
		--rh-st-size: 60px;
		--rh-st-gap: 12px;
	}
	.rh-stories--sm { --rh-st-size: 52px; }
	.rh-stories--lg { --rh-st-size: 72px; }
	.rh-stories__rail {
		margin-inline: calc(-1 * var(--wp--preset--spacing--40, 1.5rem));
		padding-inline: var(--wp--preset--spacing--40, 1.5rem);
	}
}

@media (prefers-reduced-motion: no-preference) {
	.rh-stories__btn {
		transition: transform 120ms ease;
	}
	.rh-stories__btn:active {
		transform: scale(0.94);
	}
}
