/**
 * Amitry Project Grid - frontend styles
 *
 * Two top-level components:
 *   .apshow-grid : the optional grid container (parent block)
 *   .apshow-card : the single card (child block, shortcode, or widget)
 *
 * Inside .apshow-card:
 *   .apshow-card__icon       : icon (dashicon or image)
 *   .apshow-card__headline   : H2-H6 title
 *   .apshow-card__description: paragraph text
 *   .apshow-mockup           : browser-frame screenshot with hover-scroll
 *   .apshow-card__cta        : call-to-action button link
 *
 * The hover-scroll effect is pure CSS. The image is taller than the
 * viewport. On hover, transform: translateY pulls it up so the bottom
 * aligns with the viewport bottom. On mouse leave, the transition
 * runs in reverse. prefers-reduced-motion disables the animation.
 */

/* =========================================================
   EDITOR: make the grid layout work inside Gutenberg.

   In the editor the DOM is:
     .apshow-grid (also has .block-editor-block-list__block)
       > .block-editor-inner-blocks
         > .block-editor-block-list__layout   <- the 3 cards live here

   So the cards are NOT direct children of .apshow-grid the way they are
   on the frontend. If we leave .apshow-grid as display:grid, its single
   child (.block-editor-inner-blocks) occupies one grid column and the
   cards get squeezed into it.

   Fix: in the editor only, switch the OUTER .apshow-grid back to block
   layout, and mirror the grid + column count onto the INNER layout
   wrapper that actually holds the cards. We anchor on
   .block-editor-block-list__block, an editor-only class that never
   appears on the frontend, so the frontend rules are untouched.
   ========================================================= */

.apshow-grid.block-editor-block-list__block {
	display: block;
}

.apshow-grid.block-editor-block-list__block > .block-editor-inner-blocks > .block-editor-block-list__layout {
	display: grid;
	gap: 24px;
	grid-template-columns: repeat( 3, minmax(0, 1fr) );
}

/* Mirror each column-count class onto the inner editor layout. */
.apshow-grid--cols-1.block-editor-block-list__block > .block-editor-inner-blocks > .block-editor-block-list__layout { grid-template-columns: minmax(0, 1fr); }
.apshow-grid--cols-2.block-editor-block-list__block > .block-editor-inner-blocks > .block-editor-block-list__layout { grid-template-columns: repeat( 2, minmax(0, 1fr) ); }
.apshow-grid--cols-3.block-editor-block-list__block > .block-editor-inner-blocks > .block-editor-block-list__layout { grid-template-columns: repeat( 3, minmax(0, 1fr) ); }
.apshow-grid--cols-4.block-editor-block-list__block > .block-editor-inner-blocks > .block-editor-block-list__layout { grid-template-columns: repeat( 4, minmax(0, 1fr) ); }
.apshow-grid--cols-5.block-editor-block-list__block > .block-editor-inner-blocks > .block-editor-block-list__layout { grid-template-columns: repeat( 5, minmax(0, 1fr) ); }
.apshow-grid--cols-6.block-editor-block-list__block > .block-editor-inner-blocks > .block-editor-block-list__layout { grid-template-columns: repeat( 6, minmax(0, 1fr) ); }

@media (max-width: 781px) {
	.apshow-grid.block-editor-block-list__block > .block-editor-inner-blocks > .block-editor-block-list__layout {
		grid-template-columns: repeat( 2, minmax(0, 1fr) );
	}
}

@media (max-width: 480px) {
	.apshow-grid.block-editor-block-list__block > .block-editor-inner-blocks > .block-editor-block-list__layout {
		grid-template-columns: minmax(0, 1fr);
	}
}

/* Cards in the editor get a Gutenberg block wrapper; let them fill the
   grid track instead of centering at their max-width. */
.apshow-grid.block-editor-block-list__block .apshow-card {
	margin: 0;
	min-width: 0;
	max-width: none;
}

/* =========================================================
   GRID CONTAINER (frontend)

   Column count is expressed as a fixed class (.apshow-grid--cols-N)
   instead of an inline custom property. This keeps the block wrapper
   free of a dynamic style attribute, so the render template can output
   get_block_wrapper_attributes() through a recognised escaping function
   without any inline CSS to worry about.

   minmax(0, 1fr): the 0 minimum lets tracks share the row evenly so a
   column can never collapse to 0px or overflow. The count is fixed (no
   auto-fit), so the layout never flips column counts on its own; the
   breakpoints below only step it DOWN on narrow screens.
   ========================================================= */

.apshow-grid {
	display: grid;
	gap: 24px;
	grid-template-columns: repeat( 3, minmax(0, 1fr) );
}

.apshow-grid--cols-1 { grid-template-columns: minmax(0, 1fr); }
.apshow-grid--cols-2 { grid-template-columns: repeat( 2, minmax(0, 1fr) ); }
.apshow-grid--cols-3 { grid-template-columns: repeat( 3, minmax(0, 1fr) ); }
.apshow-grid--cols-4 { grid-template-columns: repeat( 4, minmax(0, 1fr) ); }
.apshow-grid--cols-5 { grid-template-columns: repeat( 5, minmax(0, 1fr) ); }
.apshow-grid--cols-6 { grid-template-columns: repeat( 6, minmax(0, 1fr) ); }

/*
 * Mobile / narrow caps. On a real phone several full-width cards are
 * unusable, so we step the count down regardless of the chosen class.
 */
@media (max-width: 781px) {
	.apshow-grid,
	.apshow-grid--cols-1,
	.apshow-grid--cols-2,
	.apshow-grid--cols-3,
	.apshow-grid--cols-4,
	.apshow-grid--cols-5,
	.apshow-grid--cols-6 {
		grid-template-columns: repeat( 2, minmax(0, 1fr) );
	}
}

@media (max-width: 480px) {
	.apshow-grid,
	.apshow-grid--cols-1,
	.apshow-grid--cols-2,
	.apshow-grid--cols-3,
	.apshow-grid--cols-4,
	.apshow-grid--cols-5,
	.apshow-grid--cols-6 {
		grid-template-columns: minmax(0, 1fr);
	}
}

/* =========================================================
   CARD
   ========================================================= */

.apshow-card {
	box-sizing: border-box;
	margin: 0 auto;
	padding: 24px;
	background: #ffffff;
	border-radius: 12px;
	box-shadow:
		0 1px 2px rgba(0, 0, 0, 0.06),
		0 8px 24px rgba(0, 0, 0, 0.08);
	display: flex;
	flex-direction: column;
	gap: 14px;
	color: inherit;
}

.apshow-card *,
.apshow-card *::before,
.apshow-card *::after {
	box-sizing: border-box;
}

.apshow-card--align-center {
	text-align: center;
}

.apshow-card--align-center .apshow-card__cta-wrap {
	justify-content: center;
}

/* ICON */
.apshow-card__icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 48px;
	height: 48px;
	border-radius: 12px;
	background: #f3f4f6;
	font-size: 24px;
	color: #4b5563;
	flex-shrink: 0;
}

.apshow-card__icon--dashicon::before {
	font-size: 24px;
	line-height: 1;
	width: 24px;
	height: 24px;
}

.apshow-card__icon--image img {
	display: block;
	width: 32px;
	height: 32px;
	object-fit: contain;
}

.apshow-card--align-center .apshow-card__icon {
	margin: 0 auto;
}

/* HEADLINE */
.apshow-card__headline {
	margin: 0;
	font-size: 20px;
	font-weight: 700;
	line-height: 1.3;
	color: #111827;
}

/* DESCRIPTION */
.apshow-card__description {
	margin: 0;
	font-size: 15px;
	line-height: 1.6;
	color: #4b5563;
}

.apshow-card__description a {
	color: inherit;
	text-decoration: underline;
}

.apshow-card__description strong {
	font-weight: 600;
}

/* CTA */
.apshow-card__cta-wrap {
	display: flex;
	margin-top: 4px;
}

.apshow-card__cta {
	display: inline-block;
	padding: 10px 20px;
	background: #111827;
	color: #ffffff;
	text-decoration: none;
	border-radius: 8px;
	font-size: 14px;
	font-weight: 600;
	line-height: 1.4;
	transition: background-color 0.15s ease, transform 0.15s ease;
}

.apshow-card__cta:hover,
.apshow-card__cta:focus-visible {
	background: #1f2937;
	color: #ffffff;
	transform: translateY(-1px);
}

.apshow-card__cta:focus-visible {
	outline: 2px solid #2563eb;
	outline-offset: 2px;
}

/* =========================================================
   MOCKUP (browser frame + hover-scroll screenshot)
   ========================================================= */

.apshow-mockup {
	margin: 0;
	padding: 0;
	border-radius: 8px;
	overflow: hidden;
	background: #ffffff;
	box-shadow:
		0 1px 2px rgba(0, 0, 0, 0.06),
		0 4px 12px rgba(0, 0, 0, 0.06);

	--apshow-ratio: 16 / 10;
	--apshow-speed: 8s;
}

.apshow-mockup__bar {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 8px 12px;
	background: linear-gradient(180deg, #f5f6f8 0%, #eceef1 100%);
	border-bottom: 1px solid rgba(0, 0, 0, 0.08);
	font-size: 11px;
	line-height: 1.2;
	color: #5b6470;
}

.apshow-mockup__dots {
	display: inline-flex;
	gap: 5px;
	flex-shrink: 0;
}

.apshow-mockup__dot {
	display: inline-block;
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: #cfd2d6;
}

.apshow-mockup__dot--red { background: #ff5f57; }
.apshow-mockup__dot--yellow { background: #febc2e; }
.apshow-mockup__dot--green { background: #28c840; }

.apshow-mockup__url {
	flex: 1 1 auto;
	min-width: 0;
	padding: 3px 8px;
	background: #ffffff;
	border: 1px solid rgba(0, 0, 0, 0.08);
	border-radius: 5px;
	font-size: 11px;
	color: #5b6470;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.apshow-mockup__viewport {
	position: relative;
	width: 100%;
	aspect-ratio: var(--apshow-ratio);
	overflow: hidden;
	background: #f3f4f6;
}

/*
 * The image is positioned absolutely and anchored to the top. A tall
 * screenshot overflows the bottom of the viewport (which is clipped).
 *
 * The scroll distance (how far up the image must travel so its bottom
 * meets the viewport bottom) depends on the image's real pixel height
 * versus the viewport height. CSS alone cannot read the image's
 * intrinsic height, so a tiny bit of JavaScript measures it and sets
 * the per-card custom property --apshow-shift (a negative pixel value).
 *
 * Until JS runs (or if JS is disabled) the fallback shift keeps the
 * image at rest, so there is never a broken state - just no animation.
 *
 * Crucially this uses only plain length units, so the parent grid does
 * not recalculate its column count on hover (the bug that
 * container-query units + auto-fit caused).
 */
.apshow-mockup__image {
	position: absolute;
	top: 0;
	left: 0;
	display: block;
	width: 100%;
	height: auto;
	max-width: none;
	transform: translateY(0);
	transition: transform var(--apshow-speed) linear;
}

.apshow-mockup--mode-hover-return .apshow-mockup__viewport:hover .apshow-mockup__image,
.apshow-mockup--mode-hover-return .apshow-mockup__viewport:focus-within .apshow-mockup__image,
.apshow-mockup--mode-hover-return.is-apshow-playing .apshow-mockup__image {
	transform: translateY(var(--apshow-shift, 0px));
}

.apshow-mockup__link {
	display: block;
	color: inherit;
	text-decoration: none;
}

.apshow-mockup__link:focus-visible {
	outline: 2px solid #2563eb;
	outline-offset: 2px;
}

/* =========================================================
   ACCESSIBILITY
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
	.apshow-mockup__image,
	.apshow-card__cta {
		transition: none;
	}
	.apshow-mockup--mode-hover-return .apshow-mockup__viewport:hover .apshow-mockup__image,
	.apshow-mockup--mode-hover-return .apshow-mockup__viewport:focus-within .apshow-mockup__image,
	.apshow-mockup--mode-hover-return.is-apshow-playing .apshow-mockup__image {
		transform: translateY(0);
	}
}
