/* ct_Gallery front end */
.ctg { position: relative; margin: 0 0 1.5em; box-sizing: border-box; }
.ctg *, .ctg *::before, .ctg *::after { box-sizing: inherit; }
.ctg--bg-light { background: #f4f4f2; padding: var(--ctg-gap); }
.ctg--bg-dark  { background: #111; padding: var(--ctg-gap); color: #ddd; }
.ctg-item { margin: 0; padding: 0; min-width: 0; }
.ctg-frame { position: relative; line-height: 0; }
.ctg-cap, .ctg-ocap { font-family: var(--ctg-ff, inherit); font-weight: var(--ctg-fw, normal); }
.ctg-cap { font-size: var(--ctg-fs, .85em); }

/* Overlay: caption and download button anchored to top / middle / bottom rows */
.ctg-over {
	position: absolute; inset: 0; z-index: 2; pointer-events: none;
	display: grid; grid-template-rows: auto 1fr auto; grid-template-columns: minmax(0, 1fr); line-height: 1.3;
}
.ctg-row { display: flex; align-items: center; gap: 8px; padding: var(--ctg-oy) var(--ctg-ox); min-width: 0; }
.ctg-row--top { grid-row: 1; align-items: flex-start; }
.ctg-row--middle { grid-row: 2; align-self: center; }
.ctg-row--bottom { grid-row: 3; align-items: flex-end; }
.ctg-slot { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.ctg-slot.has-cap { flex: 0 1 auto; min-width: 0; }
.ctg-slot--left { margin-right: auto; }
.ctg-slot--center { margin-left: auto; margin-right: auto; text-align: center; }
.ctg-slot--right { margin-left: auto; text-align: right; }
.ctg-slot--center + .ctg-slot--right { margin-left: 0; }
.ctg-ocap { color: #fff; font-size: var(--ctg-fs, .85em); text-shadow: 0 1px 2px rgba(0,0,0,.6); overflow-wrap: break-word; min-width: 0; }
.ctg-row--bottom.has-cap { background: linear-gradient(to top, rgba(0,0,0,.6), rgba(0,0,0,0)); padding-top: calc(var(--ctg-oy) + 1.5em); }
.ctg-row--top.has-cap { background: linear-gradient(to bottom, rgba(0,0,0,.6), rgba(0,0,0,0)); padding-bottom: calc(var(--ctg-oy) + 1.5em); }
.ctg-row--middle .ctg-ocap { background: rgba(0,0,0,.5); padding: .3em .6em; border-radius: 3px; }

/* Download button */
.ctg-dl {
	pointer-events: auto; flex: 0 0 auto;
	display: inline-flex; align-items: center; gap: .35em;
	height: 2rem; padding: 0 .55rem; border-radius: 3px;
	background: rgba(255,255,255,.92); color: #1a5fb4; font: 600 13px/1 system-ui, -apple-system, "Segoe UI", sans-serif;
	box-shadow: 0 1px 3px rgba(0,0,0,.3); text-decoration: none;
	opacity: var(--ctg-dlo, .6); transition: opacity .15s;
}
.ctg-dl:hover, .ctg-dl:focus-visible, .ctg-item:hover .ctg-dl { opacity: 1; }
.ctg-dl svg { width: 18px; height: 18px; }
.ctg-dl:not(.has-label) { width: 1.6rem; height: 2.1rem; padding: 0; justify-content: center; }
.ctg-dl:not(.has-label) svg { width: 16px; height: 16px; }
.ctg:focus { outline: none; }
.ctg:focus-visible { outline: 2px solid #1a5fb4; outline-offset: 2px; }
.ctg-link { display: block; cursor: zoom-in; line-height: 0; }
.ctg-img { display: block; max-width: 100%; height: auto; }
.ctg-cap { margin: .35em 0 0; font-size: .85em; line-height: 1.35; opacity: .8; overflow-wrap: anywhere; }
.ctg-missing { padding: .5em .75em; border: 1px dashed #c00; color: #c00; font-size: .9em; }

/* Grid: up to N columns, fewer on narrow screens */
.ctg--grid .ctg-track {
	display: grid;
	gap: var(--ctg-gap);
	grid-template-columns: repeat(auto-fill, minmax(max(150px, calc((100% - (var(--ctg-cols) - 1) * var(--ctg-gap)) / var(--ctg-cols))), 1fr));
	align-items: start;
}
.ctg--grid .ctg-img { width: 100%; }
.ctg--crop-square.ctg--grid .ctg-img { aspect-ratio: 1 / 1; object-fit: cover; }

/* Single column */
.ctg--column .ctg-track { display: flex; flex-direction: column; gap: var(--ctg-gap); }
.ctg--column .ctg-img { width: 100%; }

/* Horizontal (carousel) */
.ctg--horizontal .ctg-track {
	display: flex; gap: var(--ctg-gap);
	overflow-x: auto; overscroll-behavior-x: contain;
	scroll-snap-type: x mandatory; scrollbar-width: thin;
}
.ctg--horizontal .ctg-item { flex: 0 0 auto; scroll-snap-align: center; }
.ctg--horizontal .ctg-track.is-dragging { scroll-snap-type: none; cursor: grabbing; user-select: none; }
.ctg--horizontal .ctg-track.is-dragging .ctg-link { cursor: grabbing; }
/* The height setting is a maximum. The real height also respects the gallery's own width (cqw) and the
   screen height (svh), so a landscape image fits across a phone instead of being cut off. */
.ctg--horizontal { container-type: inline-size; --ctg-hv: min(var(--ctg-h), 70svh, 66cqw); }
.ctg--stage { --ctg-hv: min(var(--ctg-h), 80svh, 75cqw); }
.ctg--horizontal.is-full { --ctg-hv: var(--ctg-h); }
.ctg--horizontal .ctg-img { height: var(--ctg-hv, var(--ctg-h)); width: auto; max-width: none; }
.ctg-hcap { text-align: center; margin-top: .5em; min-height: 1.35em; padding: 0 3rem; }
/* Over-the-image captions: in the carousel, only the current image shows one. */
.ctg--horizontal .ctg-item:not(.is-current) .ctg-ocap { visibility: hidden; }
.ctg-scroll {
	position: absolute; top: 50%; transform: translateY(-50%);
	width: 2.5rem; height: 2.5rem; border: 0; border-radius: 50%;
	background: rgba(0,0,0,.45); color: #fff; font-size: 1.6rem; line-height: 1;
	cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0 0 .15em;
}
.ctg-scroll:hover, .ctg-scroll:focus-visible { background: rgba(0,0,0,.7); }
.ctg-scroll--prev { left: .5rem; }
.ctg-scroll--next { right: .5rem; }
.ctg-scroll { z-index: 3; }

/* Playing, one image at a time (carousel switches to this view while it plays) */
.ctg--horizontal.is-single .ctg-track { display: block; overflow: hidden; height: auto; position: relative; scroll-snap-type: none; touch-action: pan-y; }
.ctg--horizontal.is-single .ctg-item { display: none; }
.ctg--horizontal.is-single .ctg-item.is-current { display: flex; flex-direction: column; align-items: center; }
.ctg--fade.is-single .ctg-item.is-current { animation: ctg-fade .6s ease; }
@keyframes ctg-fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .ctg--fade.is-single .ctg-item.is-current { animation: none; } }
.ctg-controls { display: flex; align-items: center; justify-content: center; gap: .75rem; padding-top: .4rem; font-size: .85em; line-height: 1; }
.ctg-play { display: inline-flex; align-items: center; gap: .4em; border: 1px solid currentColor; border-radius: 3px; background: none; color: inherit; font: inherit; font-size: .9em; padding: .35em .7em; cursor: pointer; opacity: .75; }
.ctg-play__i { font-size: .75em; letter-spacing: -.1em; }
.ctg-play:hover, .ctg-play:focus-visible { opacity: 1; }
.ctg-count { opacity: .7; }

/* Lightbox */
.ctg-lb {
	position: fixed; inset: 0; z-index: 100000;
	background: #0b0b0b; color: #eee;
	display: none; flex-direction: column;
	font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.ctg-lb.is-open { display: flex; }
.ctg-lb--top .ctg-lb__bar { order: -1; padding: .9rem 0 .6rem; }
.ctg-lb--top .ctg-lb__stage { padding: 0 4rem 2rem; }
.ctg-lb__stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 3rem 4rem 0; touch-action: pan-y; }
.ctg-lb__img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.ctg-lb__bar {
	display: flex; align-items: center; gap: 1rem; padding: .6rem 0 .9rem; min-height: 3.25rem;
	/* Width set by script to the widest image in the gallery, so the bar lines up with the pictures and doesn't jump. */
	align-self: center; width: var(--ctg-bar, calc(100% - 2rem)); max-width: calc(100% - 2rem);
}
.ctg-lb__cap { flex: 1; overflow-wrap: anywhere; }
.ctg-lb__count { opacity: .65; white-space: nowrap; }
.ctg-lb button, .ctg-lb a.ctg-lb__dl {
	background: none; border: 0; color: inherit; cursor: pointer; font: inherit;
}
.ctg-lb__close { position: absolute; top: .5rem; right: .75rem; font-size: 2rem !important; line-height: 1; padding: .25rem .5rem; }
.ctg-lb__nav { position: absolute; top: 50%; transform: translateY(-50%); font-size: 2.75rem !important; padding: 1rem .75rem; opacity: .75; }
.ctg-lb__nav:hover, .ctg-lb__nav:focus-visible, .ctg-lb__close:hover { opacity: 1; }
.ctg-lb__prev { left: .25rem; }
.ctg-lb__next { right: .25rem; }
.ctg-lb a.ctg-lb__dl { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid rgba(255,255,255,.4); border-radius: 4px; padding: .35rem .75rem; text-decoration: none; white-space: nowrap; }
.ctg-lb a.ctg-lb__dl:hover { border-color: #fff; }
.ctg-lb [hidden] { display: none !important; }
@media (max-width: 700px) {
	.ctg-lb__stage, .ctg-lb--top .ctg-lb__stage { padding: 3rem .5rem .5rem; }
	.ctg-lb--top .ctg-lb__stage { padding-top: .5rem; }
	.ctg-lb__nav { display: none; }
	/* Caption on its own line; buttons on the next. Download becomes icon-only. */
	.ctg-lb__bar { flex-wrap: wrap; gap: .5rem .75rem; max-width: calc(100% - 1rem); }
	.ctg-lb__cap { flex: 1 1 100%; }
	/* Bar on top: leave the first row to the close button. */
	.ctg-lb--top .ctg-lb__bar { padding-top: 4.25rem; }
	.ctg-lb a.ctg-lb__dl span { display: none; }
	.ctg-lb .ctg-tools { margin-left: auto; }
	.ctg-lb__thumbs { padding: 0 .5rem .75rem; }
}
html.ctg-lb-open { overflow: hidden; }

/* ---------- Stage: one large image, thumbnail bar, toolbar ---------- */
.ctg--stage .ctg-stage { position: relative; }
.ctg--stage.is-single .ctg-track { min-height: var(--ctg-hv, var(--ctg-h)); display: flex; align-items: center; justify-content: center; }
.ctg--stage .ctg-item.is-current { width: 100%; }
.ctg--stage .ctg-img { height: var(--ctg-hv, var(--ctg-h)); width: auto; max-width: 100%; object-fit: contain; }
.ctg-tools { position: absolute; top: .5rem; right: .5rem; z-index: 4; display: flex; gap: 2px; background: rgba(0,0,0,.45); border-radius: 4px; padding: 2px; }
.ctg-tool { width: 2.25rem; height: 2.1rem; border: 0; border-radius: 3px; background: none; color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; opacity: .85; }
.ctg-tool:hover, .ctg-tool:focus-visible { opacity: 1; background: rgba(255,255,255,.15); }
a.ctg-tool { text-decoration: none; }
.ctg-tool[hidden] { display: none; }
.ctg-tool svg { width: 20px; height: 20px; }
.ctg-tool[aria-pressed="true"] { background: rgba(255,255,255,.22); opacity: 1; }
.ctg-i--exit { display: none; }
.is-full .ctg-i--full { display: none; }
.is-full .ctg-i--exit { display: inline; }

.ctg-thumbs { display: none; gap: 6px; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; padding: 6px 0 2px; }
.has-thumbs > .ctg-thumbs { display: flex; }
.ctg-thumb { flex: 0 0 auto; margin: 2px; padding: 0 !important; border: 0 !important; background: none !important; color: inherit; cursor: pointer; line-height: 0; opacity: .6; border-radius: 2px; box-shadow: none; min-height: 0; }
.ctg-thumb img { height: min(var(--ctg-th, 84px), 17cqw); width: auto; display: block; }
.ctg--thumbs-small { --ctg-th: 48px; }
.ctg-thumb:hover, .ctg-thumb:focus-visible { opacity: 1; }
.ctg-thumb.is-current { opacity: 1; box-shadow: 0 0 0 2px currentColor; }

/* Fullscreen gallery */
.ctg--stage:fullscreen { background: #000; color: #ddd; padding: 1rem; display: flex; flex-direction: column; justify-content: center; overflow: auto; }
.ctg--stage:fullscreen .ctg-thumbs { justify-content: safe center; }

/* Lightbox toolbar and thumbnail bar */
.ctg-lb .ctg-tools { position: static; background: none; padding: 0; }
.ctg-lb__thumbs { display: none; gap: 6px; overflow-x: auto; padding: 0 1rem .9rem; justify-content: safe center; scrollbar-width: thin; }
.ctg-lb.has-thumbs .ctg-lb__thumbs { display: flex; }
.ctg-lb .ctg-thumb { color: #fff; }
.ctg-lb .ctg-thumb img { height: min(var(--ctg-th, 72px), 15vw); }
.ctg-lb.ctg--thumbs-small { --ctg-th: 44px; }
