/*
 * Apollo UI — card styles type-1 … type-6 + the full-viewport overlay.
 *
 * TOKENS
 * :root belongs to core.js. Nothing here declares a global design token.
 * Every custom property below is component-scoped (--aui-*), which is the
 * pattern the design system explicitly allows and the reason a new :root entry
 * is treated as a defect.
 *
 * ONE MARKUP, SIX LOOKS
 * .aui-card is identical for all six types. The differences are:
 *   --aui-ratio        set inline per type (2/3, 16/9, 1/1, auto)
 *   .aui-media-*       poster | landscape | square | circle | none
 *   .aui-layout-*      stack | row | bare
 * That is the whole point — a surface changes look without forking markup.
 */

/* ── card ─────────────────────────────────────────────────────────────── */

.aui-card {
	--aui-radius: var(--r, 14px);
	--aui-gap: 10px;
	position: relative;
	display: block;
	min-width: 0;
}

.aui-card .aui-link {
	display: block;
	color: inherit;
	text-decoration: none;
	border-radius: var(--aui-radius);
	outline-offset: 3px;
}

.aui-card .aui-media {
	position: relative;
	margin: 0;
	overflow: hidden;
	border-radius: var(--aui-radius);
	aspect-ratio: var(--aui-ratio, 2 / 3);
	background: rgba(var(--rgb-theme, 128, 128, 128), .12);
}

.aui-card .aui-img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform .45s var(--ease, cubic-bezier(.2, .7, .3, 1));
}

.aui-card .aui-img--empty {
	display: block;
	width: 100%;
	height: 100%;
	background: linear-gradient(135deg,
		rgba(var(--rgb-theme, 128, 128, 128), .18),
		rgba(var(--rgb-theme, 128, 128, 128), .06));
}

@media (hover: hover) {
	.aui-card .aui-link:hover .aui-img { transform: scale(1.04); }
}

.aui-card .aui-body { padding: var(--aui-gap) 2px 0; min-width: 0; }

.aui-card .aui-title {
	margin: 0;
	font-family: var(--ff-heading, inherit);
	font-weight: 800;
	font-size: 15px;
	line-height: 1.25;
	letter-spacing: -.01em;
	overflow: hidden;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
}

.aui-card .aui-meta {
	margin: 4px 0 0;
	font-family: var(--ff-mono, ui-monospace, monospace);
	font-size: 10px;
	letter-spacing: .12em;
	text-transform: uppercase;
	color: var(--muted, #8a8a8a);
}

.aui-card .aui-excerpt {
	margin: 8px 0 0;
	font-size: 13px;
	line-height: 1.5;
	color: var(--muted, #8a8a8a);
}

/* ── type-1 poster: title overlaid on the media ───────────────────────── */

.aui-type-1 .aui-media::after {
	content: "";
	position: absolute;
	inset: auto 0 0 0;
	height: 62%;
	background: linear-gradient(to top, rgba(0, 0, 0, .78), rgba(0, 0, 0, 0));
	pointer-events: none;
}

.aui-type-1 .aui-link { position: relative; }

.aui-type-1 .aui-body {
	position: absolute;
	inset: auto 0 0 0;
	padding: 12px 13px;
	color: #fff;
	z-index: 1;
}

.aui-type-1 .aui-meta { color: rgba(255, 255, 255, .82); }

/* ── type-2 wide ──────────────────────────────────────────────────────── */

.aui-type-2 .aui-title { font-size: 16px; }

/* ── type-3 row: media beside text ────────────────────────────────────── */

.aui-layout-row .aui-link {
	display: grid;
	grid-template-columns: 68px 1fr;
	gap: 12px;
	align-items: center;
}

.aui-layout-row .aui-media { width: 68px; }
.aui-layout-row .aui-body { padding: 0; }
.aui-layout-row .aui-title { font-size: 14px; -webkit-line-clamp: 2; }

/* ── type-4 avatar ────────────────────────────────────────────────────── */

.aui-media-circle .aui-media { border-radius: 50%; }
.aui-media-circle .aui-body { text-align: center; }
.aui-type-4 .aui-title { font-size: 14px; }

/* ── type-5 tile ──────────────────────────────────────────────────────── */

.aui-type-5 .aui-link { position: relative; }

.aui-type-5 .aui-media::after {
	content: "";
	position: absolute;
	inset: auto 0 0 0;
	height: 50%;
	background: linear-gradient(to top, rgba(0, 0, 0, .7), rgba(0, 0, 0, 0));
	pointer-events: none;
}

.aui-type-5 .aui-body {
	position: absolute;
	inset: auto 0 0 0;
	padding: 10px;
	color: #fff;
	z-index: 1;
}

.aui-type-5 .aui-title { font-size: 13px; -webkit-line-clamp: 2; }

/* ── type-6 text ──────────────────────────────────────────────────────── */

.aui-layout-bare .aui-link {
	display: block;
	padding: 14px 16px;
	border: 1px solid rgba(var(--rgb-diff, 0, 0, 0), .08);
	border-radius: var(--aui-radius);
	background: rgba(var(--rgb-theme, 255, 255, 255), .22);
}

.aui-layout-bare .aui-body { padding: 0; }

/* ── grid ─────────────────────────────────────────────────────────────── */

.aui-grid {
	display: grid;
	grid-template-columns: repeat(var(--aui-cols, 4), minmax(0, 1fr));
	gap: 18px;
}

@media (max-width: 1000px) { .aui-grid { grid-template-columns: repeat(min(var(--aui-cols, 4), 3), minmax(0, 1fr)); } }
@media (max-width: 720px)  { .aui-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; } }
@media (max-width: 420px)  { .aui-grid--type-3 { grid-template-columns: 1fr; } }

/* ── full-viewport overlay ────────────────────────────────────────────────
 *
 * This is apollo-ui's own overlay, used ONLY for surfaces with no delegate.
 * Events delegate to apollo-events' `.ev-lb`, which already implements this;
 * two overlays for one card is the duplication this plugin exists to end.
 *
 * `100dvh` matters: on mobile Safari `100vh` is the UNCOLLAPSED viewport, so a
 * "full viewport" panel is taller than the screen and the close button in the
 * top-right sits under the URL bar — unreachable, which is the one control the
 * user must always be able to hit.
 */

.aui-lb {
	position: fixed;
	inset: 0;
	z-index: 999999;
	display: none;
	background: rgba(0, 0, 0, .72);
	-webkit-backdrop-filter: blur(14px) saturate(150%);
	backdrop-filter: blur(14px) saturate(150%);
}

.aui-lb[data-open] { display: block; }

.aui-lb-panel {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100dvh;
	max-height: 100dvh;
	overflow: hidden auto;
	-webkit-overflow-scrolling: touch;
	background: var(--bg, #fff);
	color: var(--fg, inherit);
}

.aui-lb-x {
	position: fixed;
	top: max(12px, env(safe-area-inset-top));
	right: max(12px, env(safe-area-inset-right));
	z-index: 2;
	width: 44px;
	height: 44px;
	display: grid;
	place-items: center;
	border: 1px solid rgba(var(--rgb-theme, 255, 255, 255), .4);
	border-radius: 50%;
	background: rgba(var(--rgb-theme, 20, 20, 20), .55);
	-webkit-backdrop-filter: blur(10px);
	backdrop-filter: blur(10px);
	color: #fff;
	font-size: 20px;
	line-height: 1;
	cursor: pointer;
}

.aui-lb-x:hover { background: rgba(var(--rgb-theme, 20, 20, 20), .8); }
.aui-lb-x:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.aui-lb-body { min-height: 100%; }

.aui-lb-state {
	display: grid;
	place-items: center;
	min-height: 60dvh;
	font-family: var(--ff-mono, ui-monospace, monospace);
	font-size: 11px;
	letter-spacing: .14em;
	text-transform: uppercase;
	color: var(--muted, #8a8a8a);
}

/* Scroll lock owned by the overlay, not by the page. */
html.aui-lb-open, body.aui-lb-open { overflow: hidden !important; }

@media (prefers-reduced-motion: reduce) {
	.aui-card .aui-img { transition: none; }
}
