/*
 * tutorial-figures.css: the shared presentation layer for `figure:` media.
 *
 * Pairs with /tutorial-figures.js, which turns the `figure:` directives in
 * markdown into captioned, zoomable <figure> elements. These rules used to live
 * inline in pages/tutorial.html, which meant only the tutorial viewer could show
 * a figure. They are a file now so every markdown viewer can link them: the
 * tutorial viewer (.tdoc-article) and the cookbook recipe viewer (.cb-article)
 * both do.
 *
 * Adding a third viewer is one more selector in the :is() lists below, not a
 * copy of this file.
 */

/* ── Figures ─────────────────────────────────────────────────
   Mounted by /tutorial-figures.js from the `figure:` directives in
   the markdown. Every frame declares its intrinsic aspect ratio, so
   the article reserves the exact box before the image arrives and
   nothing under it moves. */

:is(.tdoc-article, .cb-article) .tfig {
	margin: 2rem 0;
	padding: 0;
}

.tfig-body {
	position: relative;
	border-radius: 12px;
	overflow: hidden;
	border: 1px solid rgba(255, 255, 255, 0.09);
	background:
		linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.008));
	box-shadow: 0 12px 40px -18px rgba(0, 0, 0, 0.85);
}

.tfig-frame {
	position: relative;
	display: block;
	width: 100%;
	background-size: cover;
	background-position: center;
}

.tfig-frame-img.is-loading::after {
	content: '';
	position: absolute;
	inset: 0;
	backdrop-filter: blur(12px);
	background: rgba(8, 8, 8, 0.25);
}

:is(.tdoc-article, .cb-article) .tfig-img {
	display: block;
	width: 100%;
	height: auto;
	margin: 0;
	border: none;
	border-radius: 0;
	opacity: 0;
	transition: opacity 0.45s ease;
}

.tfig-frame.is-ready .tfig-img {
	opacity: 1;
}

.tfig-frame.is-broken .tfig-img {
	opacity: 1;
}

.tfig-frame-live {
	aspect-ratio: 4 / 3;
	background:
		radial-gradient(ellipse 70% 70% at 50% 45%, var(--tdoc-accent-soft, rgba(255, 255, 255, 0.1)) 0%, transparent 70%),
		#0b0b0c;
}

.tfig-frame-live model-viewer {
	width: 100%;
	height: 100%;
	--poster-color: transparent;
	background: transparent;
}

.tfig-frame-live model-viewer:focus-visible {
	outline: 2px solid var(--tdoc-accent, #fff);
	outline-offset: -2px;
}

/* Fallback card: shown when a page figure has no capture yet. It is a
   real link to the real page, never a broken image. */
.tfig-frame-card {
	aspect-ratio: 16 / 7;
}

.tfig-card {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	justify-content: center;
	gap: 0.4rem;
	padding: clamp(1rem, 4vw, 2rem);
	text-decoration: none;
	background:
		radial-gradient(ellipse 60% 100% at 0% 50%, var(--tdoc-accent-soft, rgba(255, 255, 255, 0.1)) 0%, transparent 70%);
	transition: background 0.2s ease;
}

.tfig-card:hover {
	background:
		radial-gradient(ellipse 80% 120% at 0% 50%, var(--tdoc-accent-soft, rgba(255, 255, 255, 0.16)) 0%, transparent 70%);
}

.tfig-card:focus-visible {
	outline: 2px solid var(--tdoc-accent, #fff);
	outline-offset: -3px;
}

.tfig-card-eyebrow {
	font-family: var(--font-display);
	font-size: 0.64rem;
	font-weight: 700;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--tdoc-accent, rgba(255, 255, 255, 0.6));
}

.tfig-card-path {
	font-family: 'JetBrains Mono', monospace;
	font-size: clamp(1rem, 3vw, 1.35rem);
	color: rgba(255, 255, 255, 0.92);
}

.tfig-card-cta {
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
	font-family: 'Inter', sans-serif;
	font-size: 0.82rem;
	color: rgba(255, 255, 255, 0.55);
}

/* Zoom affordance */
.tfig-body.is-zoomable .tfig-img {
	cursor: zoom-in;
}

.tfig-zoom {
	position: absolute;
	top: 0.6rem;
	right: 0.6rem;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	border-radius: 8px;
	border: 1px solid rgba(255, 255, 255, 0.14);
	background: rgba(10, 10, 10, 0.66);
	backdrop-filter: blur(8px);
	color: rgba(255, 255, 255, 0.78);
	cursor: zoom-in;
	opacity: 0;
	transform: translateY(-4px);
	transition:
		opacity 0.18s ease,
		transform 0.18s ease,
		color 0.18s ease;
}

.tfig-body:hover .tfig-zoom,
.tfig-zoom:focus-visible {
	opacity: 1;
	transform: translateY(0);
}

.tfig-zoom:hover {
	color: #fff;
	border-color: var(--tdoc-accent, #fff);
}

.tfig-zoom:focus-visible {
	outline: 2px solid var(--tdoc-accent, #fff);
	outline-offset: 2px;
}

@media (hover: none) {
	.tfig-zoom {
		opacity: 1;
		transform: none;
	}
}

:is(.tdoc-article, .cb-article) .tfig-caption {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 0.5rem;
	margin: 0.7rem 0 0;
	font-family: 'Inter', sans-serif;
	font-size: 0.82rem;
	line-height: 1.55;
	color: rgba(255, 255, 255, 0.52);
}

.tfig-num {
	font-family: var(--font-display);
	font-size: 0.64rem;
	font-weight: 700;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: var(--tdoc-accent, rgba(255, 255, 255, 0.7));
	white-space: nowrap;
}

.tfig-text {
	flex: 1 1 14rem;
	min-width: 0;
}

.tfig-badge {
	display: inline-flex;
	align-items: center;
	gap: 0.3rem;
	padding: 0.16rem 0.5rem;
	border-radius: 999px;
	border: 1px solid rgba(255, 255, 255, 0.1);
	font-size: 0.68rem;
	color: rgba(255, 255, 255, 0.42);
	white-space: nowrap;
}

.tfig-badge svg {
	flex-shrink: 0;
}

/* ── Lightbox ──────────────────────────────────────────────── */

/* The viewers that host figures unlock scrolling with their own `overflow: auto
   !important` on <html> and <body>, so the modal lock has to answer in kind or
   the page scrolls away underneath an open lightbox. */
html.tfig-lb-open,
html.tfig-lb-open body {
	overflow: hidden !important;
}

.tfig-lightbox {
	position: fixed;
	inset: 0;
	z-index: 900;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: clamp(1rem, 4vw, 3rem);
	background: rgba(4, 4, 5, 0.9);
	backdrop-filter: blur(10px);
	animation: tfig-fade 0.18s ease;
}

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

@keyframes tfig-fade {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}

.tfig-lb-inner {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.9rem;
	max-width: min(1200px, 100%);
	max-height: 100%;
}

.tfig-lb-img {
	max-width: 100%;
	max-height: calc(100vh - 9rem);
	width: auto;
	height: auto;
	border-radius: 10px;
	border: 1px solid rgba(255, 255, 255, 0.12);
	box-shadow: 0 30px 90px -30px rgba(0, 0, 0, 0.9);
}

.tfig-lb-bar {
	display: flex;
	align-items: baseline;
	gap: 0.9rem;
	flex-wrap: wrap;
	justify-content: center;
	font-family: 'Inter', sans-serif;
	font-size: 0.85rem;
	color: rgba(255, 255, 255, 0.72);
	text-align: center;
}

.tfig-lb-count {
	font-family: 'JetBrains Mono', monospace;
	font-size: 0.72rem;
	color: rgba(255, 255, 255, 0.4);
}

.tfig-lb-close,
.tfig-lb-nav {
	position: absolute;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: 10px;
	border: 1px solid rgba(255, 255, 255, 0.14);
	background: rgba(16, 16, 18, 0.8);
	color: rgba(255, 255, 255, 0.8);
	cursor: pointer;
	transition:
		color 0.15s ease,
		border-color 0.15s ease;
}

.tfig-lb-close {
	top: clamp(0.75rem, 3vw, 1.5rem);
	right: clamp(0.75rem, 3vw, 1.5rem);
	width: 40px;
	height: 40px;
}

.tfig-lb-nav {
	top: 50%;
	transform: translateY(-50%);
	width: 44px;
	height: 44px;
	font-size: 1.1rem;
	line-height: 1;
}

.tfig-lb-nav.prev {
	left: clamp(0.5rem, 2vw, 1.5rem);
}
.tfig-lb-nav.next {
	right: clamp(0.5rem, 2vw, 1.5rem);
}

.tfig-lb-close:hover,
.tfig-lb-nav:hover {
	color: #fff;
	border-color: rgba(255, 255, 255, 0.5);
}

.tfig-lb-close:focus-visible,
.tfig-lb-nav:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
}

@media (max-width: 540px) {
	.tfig-lb-nav {
		top: auto;
		bottom: clamp(0.5rem, 3vw, 1.5rem);
		transform: none;
	}
	:is(.tdoc-article, .cb-article) .tfig-caption {
		font-size: 0.78rem;
	}
}

/* Light theme: the frames sit on paper, so the borders and captions
   invert rather than staying ghost-white on white. */
html[data-theme='light'] .tfig-body {
	border-color: rgba(0, 0, 0, 0.1);
	background: linear-gradient(180deg, rgba(0, 0, 0, 0.02), rgba(0, 0, 0, 0.005));
	box-shadow: 0 10px 30px -20px rgba(0, 0, 0, 0.35);
}
html[data-theme='light'] .tfig-frame-live {
	background:
		radial-gradient(ellipse 70% 70% at 50% 45%, var(--tdoc-accent-soft, rgba(0, 0, 0, 0.06)) 0%, transparent 70%),
		#f4f4f5;
}
html[data-theme='light'] :is(.tdoc-article, .cb-article) .tfig-caption {
	color: rgba(0, 0, 0, 0.58);
}
html[data-theme='light'] .tfig-badge {
	border-color: rgba(0, 0, 0, 0.12);
	color: rgba(0, 0, 0, 0.45);
}
html[data-theme='light'] .tfig-card-path {
	color: rgba(0, 0, 0, 0.86);
}
html[data-theme='light'] .tfig-card-cta {
	color: rgba(0, 0, 0, 0.5);
}
html[data-theme='light'] .tfig-zoom {
	background: rgba(255, 255, 255, 0.8);
	border-color: rgba(0, 0, 0, 0.12);
	color: rgba(0, 0, 0, 0.7);
}

@media (prefers-reduced-motion: reduce) {
	.tfig-zoom,
	:is(.tdoc-article, .cb-article) .tfig-img,
	.tfig-card {
		transition: none;
	}
	.tfig-lightbox {
		animation: none;
	}
}
