/*
 * Clearway Stories -- front-end styles.
 * Colors reference the live theme's colors_and_type.css custom properties
 * (--blue-light, --blue-royal, --blue-licorice, --yellow, --green, --orange,
 * --white-gainsboro, --gray, --white-smoke) with the design-token hex values
 * as CSS fallbacks, so styling still matches the spec even if a variable is
 * renamed or missing.
 */

.cw-stories-wrap {
	--cw-blue: var(--blue-light, #009ADE);
	--cw-blue-royal: var(--blue-royal, #0D4D92);
	--cw-ink: var(--blue-licorice, #2D3843);
	--cw-yellow: var(--yellow, #FFD100);
	--cw-green: var(--green, #028446);
	--cw-orange: var(--orange, #F37128);
	--cw-border: var(--white-gainsboro, #E7E6E6);
	--cw-gray: var(--gray, #A5A5A5);
	--cw-white-smoke: var(--white-smoke, #F9F9F9);
	--cw-page-bg: var(--bg-2, var(--white-smoke, #F9F9F9));

	/* Intentionally no max-width/padding/background/shadow/border-radius here:
	   this block is meant to drop into whatever section of the page it's
	   placed in and inherit that section's width and spacing, not carry its
	   own "card" framing. */
	font-family: var(--font-main, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif);
	color: var(--cw-ink);
	box-sizing: border-box;
}

.cw-stories-wrap *,
.cw-stories-wrap *::before,
.cw-stories-wrap *::after {
	box-sizing: border-box;
}

/* Category tabs */
.cw-tabs {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	margin: 24px 0 32px;
}

.cw-tab {
	appearance: none;
	cursor: pointer;
	border-radius: 999px;
	padding: 9px 20px;
	font-size: 14px;
	font-weight: 600;
	border: 1.5px solid var(--cw-border);
	background: transparent;
	color: var(--cw-ink);
	opacity: 0.7;
	transition: background-color 180ms ease, color 180ms ease, border-color 180ms ease;
}

.cw-tab:hover {
	opacity: 1;
}

.cw-tab.is-active {
	background: var(--cw-ink);
	border-color: var(--cw-ink);
	color: #fff;
	opacity: 1;
}

/* Category dot + label */
.cw-category-meta {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-bottom: 10px;
}

.cw-category-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	flex: none;
}

.cw-category-label {
	text-transform: uppercase;
	letter-spacing: 0.06em;
	font-size: 11px;
	font-weight: 700;
	color: var(--cw-gray);
}

/* Featured story */
.cw-story-featured {
	display: grid;
	grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
	gap: 0;
	border: 1px solid var(--cw-border);
	border-radius: 10px;
	overflow: hidden;
	cursor: pointer;
	margin-bottom: 32px;
}

.cw-featured-media {
	position: relative;
	height: 420px;
	background: var(--cw-white-smoke);
}

.cw-featured-media .cw-story-media,
.cw-featured-media img,
.cw-featured-media .cw-carousel,
.cw-featured-media .cw-video {
	height: 100%;
	width: 100%;
}

.cw-featured-body {
	padding: 32px;
	display: flex;
	flex-direction: column;
	justify-content: center;
}

.cw-featured-title {
	font-size: 1.75rem;
	font-weight: 700;
	line-height: 1.2;
	margin: 0 0 12px;
}

.cw-featured-excerpt {
	font-size: 15px;
	line-height: 1.6;
	color: var(--cw-ink);
	opacity: 0.85;
	margin: 0 0 20px;
}

/* Card grid */
.cw-story-grid {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 24px;
}

@media (max-width: 1100px) {
	.cw-story-grid { grid-template-columns: repeat(2, 1fr); }
	.cw-story-featured { grid-template-columns: 1fr; }
	.cw-featured-media { height: 280px; }
}

@media (max-width: 600px) {
	.cw-story-grid { grid-template-columns: 1fr; }
}

.cw-story-card {
	background: #fff;
	border: 1px solid var(--cw-border);
	border-radius: 8px;
	overflow: hidden;
	cursor: pointer;
	display: flex;
	flex-direction: column;
	transition: box-shadow 200ms ease;
}

.cw-story-card:hover {
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}

.cw-card-body {
	padding: 20px;
	display: flex;
	flex-direction: column;
	flex: 1;
}

.cw-card-title {
	font-size: 1.05rem;
	font-weight: 700;
	line-height: 1.3;
	margin: 0 0 8px;
}

.cw-card-excerpt {
	font-size: 13px;
	line-height: 1.55;
	color: var(--cw-ink);
	opacity: 0.8;
	margin: 0 0 16px;
	flex: 1;
}

/* Media blocks (shared: card / featured / detail) */
.cw-story-media {
	position: relative;
	background: var(--cw-white-smoke);
	overflow: hidden;
}

.cw-story-card .cw-story-media {
	aspect-ratio: 3 / 2;
}

.cw-story-image {
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center top;
	display: block;
}

/*
 * Card/featured/carousel photos are almost always people standing for a
 * group photo -- cropping from dead-center (the object-fit default) trims
 * off the top of the frame first, which cuts off heads. Anchoring the crop
 * to the top instead means any cropping trims from the bottom, keeping
 * faces in frame. Applies to cards, the featured block, and carousel
 * slides/video posters wherever they reuse those same classes.
 */
.cw-carousel-slide,
.cw-video-poster {
	object-position: center top;
}

/*
 * Per-story image display override (added in 1.10.0, extended in 1.10.1 to
 * also cover the full detail view -- see below): an editor can choose, per
 * story, how the featured/card image and carousel photos are cropped or fit
 * -- set via the "Image Display" field in the Story Media meta box (stored
 * as _cw_image_display post meta; class added by
 * CW_Stories_Render::render_media()). Cover (Top) needs no rule here -- it's
 * simply the existing default above. Deliberately does NOT touch
 * .cw-video-poster (video wasn't part of this feature's scope) -- video
 * posters keep the fixed behavior in the rule below regardless of a story's
 * Image Display setting. Applies uniformly in every context that reuses
 * .cw-story-image/.cw-carousel-slide, including inside .cw-detail-media
 * (the read-more modal, the [story] shortcode's inline detail, and a
 * story's own single-page template all share that markup) -- there is no
 * more "always show the whole photo" exception for those contexts as of
 * 1.10.1; if an editor wants the whole photo to always show (card AND full
 * view), they choose Fit for that story.
 */
.cw-image-display-cover-center .cw-story-image,
.cw-image-display-cover-center .cw-carousel-slide {
	object-position: center center;
}

.cw-image-display-contain .cw-story-image,
.cw-image-display-contain .cw-carousel-slide {
	object-fit: contain;
	object-position: center center;
}

/*
 * Modal / single-story detail view ([story] shortcode and the read-more
 * modal share this markup via .cw-detail-media): video cover images always
 * show in full here (object-fit: contain), regardless of a story's Image
 * Display setting -- video was never part of that feature's scope, in the
 * detail view or anywhere else. .cw-story-image and .cw-carousel-slide are
 * deliberately NOT listed here (as of 1.10.1) -- see the per-story override
 * comment above for why.
 */
.cw-detail-media .cw-video-poster {
	object-fit: contain;
	object-position: center center;
}

/* Carousel */
.cw-carousel {
	position: relative;
	width: 100%;
	height: 100%;
}

.cw-carousel-track {
	position: relative;
	width: 100%;
	height: 100%;
}

.cw-carousel-slide {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	opacity: 0;
	visibility: hidden;
	transition: opacity 200ms ease;
}

.cw-carousel-slide.is-active {
	opacity: 1;
	visibility: visible;
}

.cw-carousel-arrow {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	width: 32px;
	height: 32px;
	border-radius: 50%;
	border: none;
	background: rgba(255, 255, 255, 0.75);
	color: var(--cw-ink);
	cursor: pointer;
	font-size: 18px;
	line-height: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background-color 150ms ease;
}

.cw-carousel-arrow:hover {
	background: rgba(255, 255, 255, 0.95);
}

.cw-carousel-prev { left: 10px; }
.cw-carousel-next { right: 10px; }

.cw-carousel-dots {
	position: absolute;
	bottom: 12px;
	left: 0;
	right: 0;
	display: flex;
	justify-content: center;
	gap: 6px;
}

.cw-carousel-dot {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.5);
	cursor: pointer;
}

.cw-carousel-dot.is-active {
	background: #fff;
}

/* Video */
.cw-video {
	position: relative;
	width: 100%;
	height: 100%;
}

.cw-video-poster {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.cw-video-play {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: 56px;
	height: 56px;
	border-radius: 50%;
	background: var(--cw-blue);
	border: none;
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 150ms ease;
}

.cw-video-play:hover {
	transform: translate(-50%, -50%) scale(1.06);
}

.cw-video iframe,
.cw-video video {
	width: 100%;
	height: 100%;
	display: block;
	border: 0;
}

/* Share button + popover */
.cw-share {
	position: relative;
	margin-top: auto;
}

/* Iframe embed view (class-cw-stories-embed.php): Share is hidden here on
   purpose -- back when this was written, sharing from inside a third-party
   site's nested iframe would have built a link pointing at the bare embed
   document itself (a chromeless page meant only to sit inside an <iframe>,
   not something a visitor should land on directly), so it was suppressed
   entirely for this one context.

   As of 1.11.0 that's no longer strictly true (Share/Copy Link on an
   embedded card already builds its link from the story's real permalink,
   same as everywhere else -- see CW_Stories_Render::get_story_data()), so
   this is now an opt-in per embed via &share=1 on the embed URL
   (class-cw-stories-embed.php adds a cw-embed-share class to the wrapper
   when that parameter is present) rather than always-on, so any embed
   already placed on a partner site keeps its current look unless someone
   deliberately turns this on. */
.cw-embed:not(.cw-embed-share) .cw-share {
	display: none;
}

.cw-share-toggle {
	appearance: none;
	cursor: pointer;
	border-radius: 999px;
	padding: 8px 18px;
	font-size: 13px;
	font-weight: 600;
	border: 1.5px solid var(--cw-border);
	background: transparent;
	color: var(--cw-ink);
}

.cw-share-toggle:hover {
	border-color: var(--cw-ink);
}

.cw-share-popover {
	position: absolute;
	bottom: calc(100% + 8px);
	left: 0;
	z-index: 5;
	display: flex;
	align-items: center;
	gap: 8px;
	background: #fff;
	border: 1px solid var(--cw-border);
	border-radius: 999px;
	padding: 8px 10px;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
	white-space: nowrap;
}

.cw-share-popover[hidden] {
	display: none;
}

.cw-share-icon {
	width: 30px;
	height: 30px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #fff;
	flex: none;
}

.cw-share-featured .cw-share-icon,
.cw-share-modal .cw-share-icon {
	width: 32px;
	height: 32px;
}

.cw-share-modal .cw-share-icon {
	width: 38px;
	height: 38px;
}

.cw-share-facebook { background: var(--cw-blue-royal); }
.cw-share-x { background: var(--cw-ink); }
.cw-share-linkedin { background: var(--cw-blue-royal); }

.cw-copy-link {
	appearance: none;
	cursor: pointer;
	border-radius: 999px;
	padding: 6px 14px;
	font-size: 12px;
	font-weight: 600;
	border: 1.5px solid var(--cw-border);
	background: transparent;
	color: var(--cw-ink);
}

/* Modal */
.cw-modal-scrim {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.85);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 40px;
	z-index: 10000;
}

.cw-modal-scrim[hidden] {
	display: none;
}

.cw-modal-panel {
	position: relative;
	background: #fff;
	max-width: 840px;
	width: 100%;
	max-height: 88vh;
	overflow-y: auto;
	border-radius: 10px;
}

.cw-modal-close {
	position: absolute;
	top: 16px;
	right: 16px;
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: #fff;
	border: 1px solid var(--cw-border);
	font-size: 18px;
	line-height: 1;
	cursor: pointer;
	z-index: 2;
}

.cw-detail-media {
	aspect-ratio: 16 / 9;
	background: var(--cw-white-smoke);
	position: relative;
}

.cw-detail-media .cw-story-media {
	width: 100%;
	height: 100%;
}

.cw-detail-body {
	padding: 32px;
}

.cw-detail-title {
	font-size: 2rem;
	font-weight: 700;
	margin: 0 0 16px;
	line-height: 1.2;
}

.cw-detail-content {
	font-size: 15px;
	line-height: 1.7;
}

.cw-detail-divider {
	height: 1px;
	background: var(--cw-border);
	margin: 24px 0;
}

/* Single-story shortcode ([story id]) reuses the detail styles without modal chrome */
.cw-stories-single .cw-story-detail {
	border: 1px solid var(--cw-border);
	border-radius: 10px;
	overflow: hidden;
}

/* [story id="..." style="featured|card"] -- standalone, not part of a grid. */
.cw-stories-single.cw-stories-single-featured .cw-story-featured,
.cw-stories-single.cw-stories-single-card .cw-story-card {
	margin-bottom: 0;
}

.cw-stories-single.cw-stories-single-card .cw-story-card {
	max-width: 360px;
}

.cw-stories-error {
	color: #b32d2e;
	font-weight: 600;
}

/* Dedicated single-story page (real permalink, built in 1.8.0, see
   templates/single-cw-story.php). Unlike the shortcode contexts above,
   there's no host page section to inherit width/spacing from, so this
   gets its own sensible container -- same 840px max-width as the modal
   panel, for visual consistency with what a story already looks like
   there. */
.cw-stories-single-page {
	max-width: 840px;
	margin: 48px auto;
	padding: 0 20px;
}

.cw-stories-single-page .cw-story-detail {
	border: 1px solid var(--cw-border);
	border-radius: 10px;
	overflow: hidden;
}

/* "Back to..." link (only rendered here -- see get_return_link() in
   class-cw-stories-render.php -- not in the modal or [story] shortcode,
   which already live on the page a visitor should return to). */
.cw-stories-single-page .cw-back-link {
	display: inline-block;
	margin-bottom: 16px;
	font-size: 14px;
	font-weight: 600;
	color: var(--cw-blue-royal);
	text-decoration: none;
}

.cw-stories-single-page .cw-back-link:hover,
.cw-stories-single-page .cw-back-link:focus {
	text-decoration: underline;
}
