/**
 * Atomic Ink Portfolio
 *
 * The design language is four-colour process printing: ink linework, paper
 * white, and cyan/magenta/yellow plates. Offset shadows are coloured rather
 * than black, so a card reads as a slightly misregistered print plate.
 *
 * Palette arrives as custom properties from plugin settings, so nothing here
 * needs recompiling when the colours change.
 */

:root {
	--aip-ink: #141414;
	--aip-paper: #ffffff;
	--aip-yellow: #ffe400;
	--aip-magenta: #ec1180;
	--aip-cyan: #12b0e8;
	--aip-muted: #666666;

	--aip-border: 4px;
	--aip-offset: 7px;
	--aip-gap: 22px;
	--aip-columns: 3;
}

/* ---------------------------------------------------------------------------
 * Page background
 *
 * Only applies when a colour is configured -- the class is not added otherwise,
 * so by default the theme keeps full control and nothing here fires. Covers
 * portfolio detail pages and any page holding the index shortcode.
 *
 * On body rather than the plugin's own wrapper, because that is what actually
 * reaches the viewport edges without needing to know how the theme nests its
 * containers. !important is deliberate and narrow: Divi sets `body { background
 * -color: #fff }` at a specificity this would otherwise lose to, and this rule
 * only exists at all when the user has explicitly asked for a colour.
 * ------------------------------------------------------------------------ */

body.aip-has-bg {
	/* Fallback is belt and braces. The class and the variable are emitted
	   together from the same render, so they cannot drift -- but an
	   unresolvable var() would silently drop the whole declaration, which is
	   exactly how the column count broke once already. */
	background-color: var(--aip-bg, transparent) !important;
}

/*
 * Themes that paint their own opaque wrapper would otherwise cover the body
 * colour. These are transparent by default in most themes, so clearing them
 * costs nothing and saves a support round-trip.
 */
body.aip-has-bg #page-container,
body.aip-has-bg #et-main-area,
body.aip-has-bg .aip-single {
	background-color: transparent;
}

/* ---------------------------------------------------------------------------
 * Index grid
 * ------------------------------------------------------------------------ */

/*
 * Explicit breakpoints rather than auto-fill, so the count is predictable at
 * every width instead of depending on how a theme's container happens to size.
 * One across on phones, two on tablets, the configured count on desktop.
 */
.aip-grid {
	display: grid;
	grid-template-columns: 1fr;
	gap: var(--aip-gap);
	margin: 0 0 3rem;
	padding: 0;
	list-style: none;
}

@media (min-width: 600px) {
	.aip-grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

@media (min-width: 900px) {
	/*
	 * The fallback matters. An unresolvable var() is invalid at computed-value
	 * time, which drops the whole declaration back to `none` -- a single column,
	 * silently overriding the rules above. Never write var(--aip-columns) here
	 * without one.
	 */
	.aip-grid {
		grid-template-columns: repeat(var(--aip-columns, 3), minmax(0, 1fr));
	}
}

.aip-card {
	position: relative;
	background: var(--aip-paper);
	border: var(--aip-border) solid var(--aip-ink);
	border-radius: 0;
	transition: transform 0.16s ease, box-shadow 0.16s ease;
}

/* Plate colour drives the offset shadow. */
.aip-plate-cyan { box-shadow: var(--aip-offset) var(--aip-offset) 0 var(--aip-cyan); }
.aip-plate-magenta { box-shadow: var(--aip-offset) var(--aip-offset) 0 var(--aip-magenta); }
.aip-plate-yellow { box-shadow: var(--aip-offset) var(--aip-offset) 0 var(--aip-yellow); }

.aip-tilt-a { transform: rotate(-0.7deg); }
.aip-tilt-b { transform: rotate(0.5deg); }

.aip-card:hover,
.aip-card:focus-within {
	transform: translate(-2px, -2px) rotate(0deg);
	box-shadow: calc(var(--aip-offset) + 3px) calc(var(--aip-offset) + 3px) 0 currentColor;
}

.aip-plate-cyan:hover, .aip-plate-cyan:focus-within { color: var(--aip-cyan); }
.aip-plate-magenta:hover, .aip-plate-magenta:focus-within { color: var(--aip-magenta); }
.aip-plate-yellow:hover, .aip-plate-yellow:focus-within { color: var(--aip-yellow); }

.aip-card__link {
	display: block;
	text-decoration: none;
	color: inherit;
}

.aip-card__link:focus-visible {
	outline: 3px solid var(--aip-magenta);
	outline-offset: 3px;
}

.aip-card__frame {
	position: relative;
	overflow: hidden;
	border-bottom: var(--aip-border) solid var(--aip-ink);
	background: var(--aip-ink);
}

.aip-card__img {
	display: block;
	width: 100%;
	height: auto;
	aspect-ratio: 4 / 3;
	object-fit: cover;
	object-position: center 6%;
}

.aip-card__empty {
	aspect-ratio: 4 / 3;
	background: var(--aip-ink);
}

/* Halftone screen. Pure CSS dot grid, no image asset. */
.aip-halftone {
	position: absolute;
	inset: 0;
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.2s ease;
	background-image: radial-gradient(circle, rgba(20, 20, 20, 0.55) 1.1px, transparent 1.3px);
	background-size: 6px 6px;
}

.aip-card:hover .aip-halftone,
.aip-card:focus-within .aip-halftone {
	opacity: 1;
}

/* The caption box hangs off the left edge, breaking the panel frame. */
.aip-caption {
	position: absolute;
	top: 14px;
	left: calc(var(--aip-border) * -1 - 6px);
	display: inline-block;
	padding: 3px 14px 1px;
	background: var(--aip-yellow);
	border: 3px solid var(--aip-ink);
	font-family: Bangers, Impact, "Arial Black", sans-serif;
	font-size: 1.35rem;
	letter-spacing: 0.6px;
	line-height: 1.25;
	color: var(--aip-ink);
	transform: rotate(-1.4deg);
}

.aip-card__meta {
	display: block;
	padding: 10px 14px;
	font-family: Archivo, system-ui, sans-serif;
	font-size: 0.75rem;
	font-weight: 700;
	letter-spacing: 0.4px;
	text-transform: uppercase;
	color: var(--aip-muted);
}

/* ---------------------------------------------------------------------------
 * Portfolio detail page
 *
 * Deliberately quieter than the index. Thin borders, no rotation, no halftone.
 * Once someone is looking at the art, the frame should get out of the way.
 * ------------------------------------------------------------------------ */

.aip-single {
	max-width: 1240px;
	margin: 0 auto;
	padding: 2.5rem 1.25rem 4rem;
}

.aip-single__head,
.aip-index__head {
	margin-bottom: 2.5rem;
}

/*
 * Index and gallery headings share one rule rather than two matching ones, so
 * they cannot drift apart later.
 */
.aip-single__title,
.aip-index__title {
	display: inline-block;
	margin: 0;
	padding: 6px 18px 2px;
	background: var(--aip-yellow);
	border: 3px solid var(--aip-ink);
	font-family: Bangers, Impact, "Arial Black", sans-serif;
	font-size: clamp(1.8rem, 5vw, 3rem);
	font-weight: 400;
	letter-spacing: 1px;
	line-height: 1.15;
	color: var(--aip-ink);
	transform: rotate(-1deg);
}

.aip-single__intro {
	max-width: 62ch;
	margin: 1.5rem 0 0;
	font-family: Archivo, system-ui, sans-serif;
	font-size: 1rem;
	line-height: 1.65;
	color: var(--aip-ink);
}

/* ---------------------------------------------------------------------------
 * Back to index
 *
 * Reuses the caption-box treatment from the cards -- yellow fill, ink border,
 * coloured offset shadow -- so it reads as part of the print-plate system
 * rather than a generic button. Ink on yellow measures 14.5:1, the strongest
 * pairing in the palette.
 * ------------------------------------------------------------------------ */

.aip-back-row {
	/* Its own row, hard left, regardless of what the theme does with text
	   alignment on the surrounding container. */
	display: block;
	margin: 0 0 var(--aip-gap);
	text-align: left;
}

.aip-back {
	display: inline-flex;
	align-items: baseline;
	gap: 9px;
	padding: 7px 16px 5px;
	background: var(--aip-yellow);
	border: 3px solid var(--aip-ink);
	border-radius: 0;
	box-shadow: 4px 4px 0 var(--aip-magenta);
	font-family: Archivo, system-ui, sans-serif;
	font-size: 0.82rem;
	font-weight: 700;
	line-height: 1.3;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	text-decoration: none;
	color: var(--aip-ink);
	transition: transform 0.16s ease, box-shadow 0.16s ease;
}

/* Beat theme link colours without an !important arms race. */
.aip-back:link,
.aip-back:visited {
	color: var(--aip-ink);
	text-decoration: none;
}

.aip-back__arrow {
	font-size: 1.15rem;
	line-height: 1;
	transition: transform 0.16s ease;
}

/*
 * Same gesture as the cards: pull toward the viewer and let the plate shadow
 * open up behind it. The arrow slides left, so the direction is legible before
 * anyone reads the label.
 */
.aip-back:hover,
.aip-back:focus-visible {
	transform: translate(-2px, -2px);
	box-shadow: 7px 7px 0 var(--aip-magenta);
	color: var(--aip-ink);
}

.aip-back:hover .aip-back__arrow,
.aip-back:focus-visible .aip-back__arrow {
	transform: translateX(-3px);
}

.aip-back:focus-visible {
	outline: 3px solid var(--aip-cyan);
	outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
	.aip-back,
	.aip-back__arrow {
		transition: none;
	}

	.aip-back:hover,
	.aip-back:focus-visible {
		transform: none;
	}

	.aip-back:hover .aip-back__arrow,
	.aip-back:focus-visible .aip-back__arrow {
		transform: none;
	}
}

.aip-crumbs {
	margin: 0 0 1.25rem;
	font-family: Archivo, system-ui, sans-serif;
	font-size: 0.8rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.5px;
}

.aip-crumbs ol {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

.aip-crumbs li + li::before {
	content: "/";
	margin-right: 0.5rem;
	color: var(--aip-muted);
}

.aip-crumbs a {
	color: var(--aip-muted);
	text-decoration: none;
}

.aip-crumbs a:hover {
	color: var(--aip-ink);
}

/* ---------------------------------------------------------------------------
 * Gallery
 * ------------------------------------------------------------------------ */

.aip-gallery {
	display: grid;
	gap: 18px;
	grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

/*
 * Masonry without JavaScript. Rows are 8px tall and each figure spans a
 * number of them computed server-side from the Drive-reported aspect ratio,
 * so nothing reflows after paint.
 */
.aip-gallery--masonry {
	grid-auto-rows: 8px;
	align-items: start;
}

.aip-gallery--masonry .aip-figure {
	grid-row: span var(--aip-span, 40);
}

.aip-gallery--uniform .aip-figure img {
	aspect-ratio: 1 / 1;
	object-fit: cover;
}

.aip-figure {
	margin: 0;
	border: 2px solid var(--aip-ink);
	background: var(--aip-paper);
}

.aip-figure__btn {
	display: block;
	width: 100%;
	padding: 0;
	border: 0;
	background: none;
	cursor: zoom-in;
	line-height: 0;
}

.aip-figure__btn:focus-visible {
	outline: 3px solid var(--aip-magenta);
	outline-offset: 2px;
}

.aip-figure img {
	display: block;
	width: 100%;
	height: auto;
}

.aip-figure__cap {
	padding: 8px 10px;
	border-top: 2px solid var(--aip-ink);
	font-family: Archivo, system-ui, sans-serif;
	font-size: 0.78rem;
	line-height: 1.45;
	color: var(--aip-muted);
}

/* ---------------------------------------------------------------------------
 * Lightbox
 * ------------------------------------------------------------------------ */

.aip-lightbox {
	position: fixed;
	inset: 0;
	z-index: 99999;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 3vmin;
	background: rgba(20, 20, 20, 0.94);
}

.aip-lightbox[hidden] {
	display: none;
}

.aip-lightbox__panel {
	position: relative;
	max-width: 100%;
	max-height: 100%;
	border: 4px solid var(--aip-paper);
	background: var(--aip-ink);
	line-height: 0;
}

.aip-lightbox__img {
	display: block;
	max-width: 100%;
	max-height: 86vh;
	width: auto;
	height: auto;
}

/*
 * Busy state. Only ever seen under lazy derivative mode, where the first
 * request for a full size builds it on the server. A plate-coloured bar
 * running the top edge, in keeping with the misregistration idea.
 */
.aip-lightbox__panel.is-loading::after {
	content: "";
	position: absolute;
	top: 0;
	left: 0;
	height: 4px;
	width: 40%;
	background: var(--aip-magenta);
	animation: aip-plate-sweep 1.1s linear infinite;
}

.aip-lightbox__panel.is-loading .aip-lightbox__img {
	opacity: 0.35;
}

@keyframes aip-plate-sweep {
	from { transform: translateX(-100%); }
	to   { transform: translateX(250%); }
}

@media (prefers-reduced-motion: reduce) {
	.aip-lightbox__panel.is-loading::after {
		animation: none;
		width: 100%;
	}
}

.aip-lightbox__cap {
	position: absolute;
	bottom: 14px;
	left: -6px;
	max-width: 70%;
	padding: 4px 14px 2px;
	background: var(--aip-yellow);
	border: 3px solid var(--aip-ink);
	font-family: Archivo, system-ui, sans-serif;
	font-size: 0.85rem;
	font-weight: 700;
	line-height: 1.4;
	color: var(--aip-ink);
	transform: rotate(-1deg);
}

.aip-lightbox__btn {
	position: absolute;
	width: 52px;
	height: 52px;
	padding: 0;
	background: var(--aip-paper);
	border: 3px solid var(--aip-ink);
	font-family: Bangers, Impact, sans-serif;
	font-size: 1.5rem;
	line-height: 1;
	color: var(--aip-ink);
	cursor: pointer;
	transition: transform 0.12s ease;
}

.aip-lightbox__btn:hover {
	transform: scale(1.08);
}

.aip-lightbox__btn:focus-visible {
	outline: 3px solid var(--aip-yellow);
	outline-offset: 2px;
}

.aip-lightbox__close { top: 2vmin; right: 2vmin; }
.aip-lightbox__prev { top: 50%; left: 2vmin; transform: translateY(-50%); }
.aip-lightbox__next { top: 50%; right: 2vmin; transform: translateY(-50%); }

.aip-lightbox__prev:hover,
.aip-lightbox__next:hover {
	transform: translateY(-50%) scale(1.08);
}

.aip-lightbox__count {
	position: absolute;
	top: 2vmin;
	left: 2vmin;
	padding: 4px 12px 2px;
	background: var(--aip-magenta);
	border: 3px solid var(--aip-paper);
	font-family: Archivo, system-ui, sans-serif;
	font-size: 0.78rem;
	font-weight: 700;
	color: var(--aip-paper);
}


/* ---------------------------------------------------------------------------
 * Empty and notice states
 * ------------------------------------------------------------------------ */

.aip-empty {
	padding: 3rem 1.5rem;
	border: 4px dashed var(--aip-ink);
	text-align: center;
	font-family: Archivo, system-ui, sans-serif;
	color: var(--aip-muted);
}

.aip-empty__title {
	margin: 0 0 0.5rem;
	font-family: Bangers, Impact, sans-serif;
	font-size: 1.6rem;
	letter-spacing: 0.8px;
	color: var(--aip-ink);
}

.aip-notice {
	padding: 12px 16px;
	background: var(--aip-yellow);
	border: 3px solid var(--aip-ink);
	font-family: Archivo, system-ui, sans-serif;
	font-size: 0.85rem;
	font-weight: 700;
	color: var(--aip-ink);
}

/* ---------------------------------------------------------------------------
 * Quality floor
 * ------------------------------------------------------------------------ */

@media (max-width: 600px) {
	:root {
		--aip-offset: 5px;
		--aip-border: 3px;
		--aip-gap: 16px;
	}

	.aip-caption {
		font-size: 1.1rem;
	}

	.aip-lightbox__prev,
	.aip-lightbox__next {
		display: none; /* Swipe handles this on touch. */
	}
}

@media (prefers-reduced-motion: reduce) {
	.aip-card,
	.aip-halftone,
	.aip-lightbox__btn {
		transition: none;
	}

	.aip-tilt-a,
	.aip-tilt-b {
		transform: none;
	}

	.aip-card:hover,
	.aip-card:focus-within {
		transform: none;
	}
}

@media print {
	.aip-card {
		box-shadow: none;
		break-inside: avoid;
	}
}
