/*
 * Układ wzorowany na narzędziach generatywnych: galeria wypełnia stronę,
 * a sterowanie siedzi w małym, odklejonym pasku przyklejonym do dołu ekranu.
 * Pasek jest "sticky", nie "fixed" — dzięki temu nie zasłania stopki strony,
 * gdy użytkownik doscrolluje do końca.
 *
 * Wszystko jest ograniczone do .pe-app i oparte na zmiennych CSS, żeby style
 * motywu nie rozjechały narzędzia i żeby dało się je dopasować bez ruszania kodu.
 */

.pe-app {
	--pe-surface: #f4f5f7;
	--pe-border: #e3e6ea;
	--pe-text: #1d2327;
	--pe-muted: #6b7280;
	--pe-danger: #b32d2e;

	/* Pasek sterowania — ciemny, żeby odcinał się od galerii i od strony. */
	--pe-bar-bg: #16181d;
	--pe-bar-text: #f3f4f6;
	--pe-bar-muted: #9ca3af;
	--pe-bar-line: rgba(255, 255, 255, 0.14);
	--pe-bar-hover: rgba(255, 255, 255, 0.08);

	--pe-accent: #ffffff;
	--pe-accent-text: #16181d;

	--pe-radius: 10px;
	--pe-bar-radius: 18px;

	box-sizing: border-box;
	max-width: 1240px;
	margin: 0 auto;
	color: var(--pe-text);
	font-size: 15px;
	line-height: 1.5;
}

.pe-app *,
.pe-app *::before,
.pe-app *::after {
	box-sizing: inherit;
}

/* Własne reguły display mają wyższą wagę niż domyślne [hidden] przeglądarki. */
.pe-app [hidden] {
	display: none !important;
}

.pe-app--locked {
	padding: 24px;
	text-align: center;
	background: var(--pe-surface);
	border: 1px solid var(--pe-border);
	border-radius: var(--pe-radius);
}

/* ------------------------------------------------------------------ */
/* Bramka na hasło                                                     */
/* ------------------------------------------------------------------ */

.pe-gate {
	/* Wąska karta pośrodku — formularz na trzy pola nie ma powodu ciągnąć się
	   przez cały ekran, a skupiony wzrok szybciej trafia w to, co trzeba zrobić. */
	width: 100%;
	max-width: 300px;
	margin: 48px auto;
	padding: 24px 22px;
	text-align: center;
	background: #ffffff;
	border: 1px solid var(--pe-border);
	border-radius: 14px;
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.pe-gate__title {
	margin: 0 0 6px;
	font-size: 18px;
	line-height: 1.3;
}

.pe-gate__hint {
	margin: 0 0 16px;
	font-size: 13px;
	line-height: 1.45;
	color: var(--pe-muted);
}

.pe-gate__error {
	margin: 0 0 14px;
	padding: 9px 12px;
	font-size: 13px;
	color: var(--pe-danger);
	background: #fdf3f3;
	border: 1px solid #f3d4d4;
	border-radius: 8px;
}

/* Przy 300 px pole i przycisk obok siebie byłyby ciasne — układamy je
   jedno pod drugim, oba na pełną szerokość karty. */
.pe-gate__row {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

/* Selektor przeładowany celowo — motywy stylują pola przez
   input[type="password"], co przebiłoby samą klasę. */
.pe-app input.pe-gate__input {
	width: 100%;
	min-width: 0;
	padding: 11px 14px;
	font-size: 15px;
	font-family: inherit;
	text-align: center;
	color: #1d2327;
	-webkit-text-fill-color: #1d2327;
	background: #ffffff;
	border: 1px solid var(--pe-border);
	border-radius: 10px;
	box-shadow: none;
}

.pe-app input.pe-gate__input:focus {
	outline: none;
	border-color: var(--pe-bar-bg);
}

.pe-gate__submit {
	width: 100%;
	padding: 11px 22px;
	font-size: 15px;
	font-weight: 600;
	font-family: inherit;
	color: #ffffff;
	background: var(--pe-bar-bg);
	border: 0;
	border-radius: 10px;
	cursor: pointer;
}

.pe-gate__submit:hover {
	filter: brightness(1.25);
}

/* ------------------------------------------------------------------ */
/* Galeria                                                             */
/* ------------------------------------------------------------------ */

.pe-gallery {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
	align-items: start;
	gap: 10px;
	/* Miejsce pod pasek, żeby ostatni rząd nie chował się za nim. */
	padding-bottom: 130px;
}

.pe-empty {
	grid-column: 1 / -1;
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 200px;
	color: var(--pe-muted);
	background: var(--pe-surface);
	border: 1px dashed var(--pe-border);
	border-radius: var(--pe-radius);
}

.pe-tile {
	position: relative;
	overflow: hidden;
	background: var(--pe-surface);
	border-radius: var(--pe-radius);
	aspect-ratio: 3 / 4;
}

.pe-tile img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

/* Podpis i pobieranie pojawiają się dopiero na najechaniu — dzięki temu
   galeria to same zdjęcia, bez wizualnego hałasu. Na dotyku (brak hovera)
   overlay jest widoczny na stałe, inaczej byłby nieosiągalny. */
.pe-tile__overlay {
	position: absolute;
	inset: auto 0 0 0;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 10px;
	background: linear-gradient(to top, rgba(0, 0, 0, 0.78), rgba(0, 0, 0, 0));
	opacity: 0;
	transition: opacity 0.15s ease;
}

.pe-tile:hover .pe-tile__overlay,
.pe-tile:focus-within .pe-tile__overlay {
	opacity: 1;
}

@media (hover: none) {
	.pe-tile__overlay { opacity: 1; }
}

.pe-tile__info {
	font-size: 11px;
	line-height: 1.3;
	color: rgba(255, 255, 255, 0.85);
}

.pe-tile__download {
	flex: none;
	padding: 6px 12px;
	font-size: 12px;
	font-weight: 600;
	text-decoration: none;
	color: var(--pe-accent-text);
	background: var(--pe-accent);
	border-radius: 999px;
}

.pe-tile__download:hover,
.pe-tile__download:focus {
	color: var(--pe-accent-text);
	filter: brightness(0.9);
}

/* Ikony narzędziowe w rogu kafelka */
.pe-tile__tools {
	position: absolute;
	top: 8px;
	right: 8px;
	display: flex;
	gap: 6px;
	opacity: 0;
	transition: opacity 0.15s ease;
}

.pe-tile:hover .pe-tile__tools,
.pe-tile:focus-within .pe-tile__tools {
	opacity: 1;
}

@media (hover: none) {
	.pe-tile__tools { opacity: 1; }
}

.pe-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	padding: 0;
	color: #fff;
	background: rgba(0, 0, 0, 0.55);
	border: 0;
	border-radius: 50%;
	cursor: pointer;
	backdrop-filter: blur(4px);
}

.pe-icon:hover,
.pe-icon:focus-visible {
	background: rgba(0, 0, 0, 0.8);
}

.pe-icon svg {
	width: 16px;
	height: 16px;
}

/* Okno powiększenia.
 *
 * Uwaga: okno mieszka bezpośrednio w <body>, a nie wewnątrz .pe-app — reguła
 * ukrywająca elementy wewnątrz narzędzia go NIE obejmuje. Bez poniższego
 * [hidden] własne "display: flex" wygrywa z domyślnym ukryciem i okna nie
 * dało się zamknąć.
 */
.pe-viewer[hidden],
.pe-viewer [hidden] {
	display: none !important;
}

.pe-viewer {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(10, 11, 13, 0.94);
	/* Bez tego przeciąganie zdjęcia zaznacza je na niebiesko. */
	user-select: none;
	-webkit-user-select: none;
}

.pe-viewer__stage {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	cursor: grab;
	touch-action: none;
}

.pe-viewer__stage:active {
	cursor: grabbing;
}

.pe-viewer__image {
	max-width: none;
	transform-origin: center center;
	/* Przy dużym zbliżeniu chcemy widzieć realne piksele, nie wygładzanie. */
	image-rendering: -webkit-optimize-contrast;
	user-select: none;
	-webkit-user-drag: none;
}

.pe-viewer__bar {
	position: absolute;
	left: 50%;
	bottom: 20px;
	transform: translateX(-50%);
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 8px;
	background: rgba(28, 30, 35, 0.94);
	border-radius: 999px;
	box-shadow: 0 8px 26px rgba(0, 0, 0, 0.45);
}

.pe-viewer__btn {
	display: flex;
	align-items: center;
	justify-content: center;
	min-width: 34px;
	height: 34px;
	padding: 0 12px;
	font-size: 15px;
	font-family: inherit;
	font-weight: 600;
	line-height: 1;
	text-decoration: none;
	color: #f3f4f6;
	background: rgba(255, 255, 255, 0.1);
	border: 0;
	border-radius: 999px;
	cursor: pointer;
}

.pe-viewer__btn:hover,
.pe-viewer__btn:focus-visible {
	color: #f3f4f6;
	background: rgba(255, 255, 255, 0.22);
}

.pe-viewer__btn--text {
	font-size: 13px;
}

.pe-viewer__level {
	min-width: 56px;
	font-size: 13px;
	font-variant-numeric: tabular-nums;
	text-align: center;
	color: #9ca3af;
}

.pe-viewer__note {
	position: absolute;
	top: 20px;
	left: 50%;
	transform: translateX(-50%);
	padding: 8px 16px;
	font-size: 13px;
	color: #f3f4f6;
	background: rgba(28, 30, 35, 0.94);
	border-radius: 999px;
}

@media (max-width: 600px) {
	.pe-viewer__bar {
		flex-wrap: wrap;
		justify-content: center;
		max-width: calc(100vw - 24px);
		border-radius: 18px;
	}
}

/* Kafelek w trakcie pracy i kafelek błędu */
.pe-tile--state {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 6px;
	padding: 14px;
	text-align: center;
	font-size: 13px;
	color: var(--pe-muted);
	border: 1px solid var(--pe-border);
}

.pe-tile--busy {
	animation: pe-pulse 1.8s ease-in-out infinite;
}

.pe-tile--error {
	color: var(--pe-danger);
	background: #fdf3f3;
	border-color: #f3d4d4;
}

.pe-tile__message {
	display: -webkit-box;
	-webkit-line-clamp: 5;
	-webkit-box-orient: vertical;
	overflow: hidden;
	font-size: 12px;
	word-break: break-word;
}

@keyframes pe-pulse {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.5; }
}

@media (prefers-reduced-motion: reduce) {
	.pe-tile--busy { animation: none; }
}

/* ------------------------------------------------------------------ */
/* Pasek sterowania                                                    */
/* ------------------------------------------------------------------ */

.pe-bar {
	position: sticky;
	bottom: 18px;
	z-index: 20;
	margin: 0 auto;
	max-width: 940px;
}

.pe-bar__inner {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 10px;
	color: var(--pe-bar-text);
	background: var(--pe-bar-bg);
	border-radius: var(--pe-bar-radius);
	box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
}

.pe-bar__inner.is-over {
	outline: 2px dashed rgba(255, 255, 255, 0.5);
	outline-offset: -5px;
}

/* --- miniatura wybranego zdjęcia + przycisk dodawania --- */

.pe-slot {
	position: relative;
	flex: none;
	width: 52px;
	height: 52px;
	border-radius: 12px;
	overflow: hidden;
}

.pe-slot img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.pe-slot__clear {
	position: absolute;
	top: 3px;
	right: 3px;
	width: 18px;
	height: 18px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 13px;
	line-height: 1;
	color: #fff;
	background: rgba(0, 0, 0, 0.62);
	border: 0;
	border-radius: 50%;
	cursor: pointer;
	padding: 0;
}

.pe-add {
	flex: none;
	width: 52px;
	height: 52px;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--pe-bar-muted);
	background: var(--pe-bar-hover);
	border: 1px solid var(--pe-bar-line);
	border-radius: 12px;
	cursor: pointer;
	transition: background-color 0.15s, color 0.15s;
}

.pe-add:hover,
.pe-add:focus-visible {
	color: var(--pe-bar-text);
	background: rgba(255, 255, 255, 0.16);
}

.pe-add svg {
	width: 20px;
	height: 20px;
}

/* --- pigułki z ustawieniami --- */

.pe-pills {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	min-width: 0;
	flex: 1 1 auto;
}

.pe-pill {
	position: relative;
	display: inline-flex;
	align-items: center;
}

.pe-pill select {
	appearance: none;
	-webkit-appearance: none;
	padding: 8px 30px 8px 14px;
	max-width: 190px;
	font-size: 13px;
	font-family: inherit;
	color: var(--pe-bar-text);
	background: transparent;
	border: 1px solid var(--pe-bar-line);
	border-radius: 999px;
	cursor: pointer;
	text-overflow: ellipsis;
}

.pe-pill select:hover {
	background: var(--pe-bar-hover);
}

.pe-pill select option {
	color: #1d2327;
	background: #fff;
}

.pe-pill::after {
	content: "";
	position: absolute;
	right: 12px;
	width: 6px;
	height: 6px;
	border-right: 1.5px solid var(--pe-bar-muted);
	border-bottom: 1.5px solid var(--pe-bar-muted);
	transform: translateY(-2px) rotate(45deg);
	pointer-events: none;
}

/* Pole na dodatkowe wskazówki.
 *
 * Selektor jest celowo "przeładowany" (.pe-app input.pe-prompt), bo motywy
 * WordPressa stylują pola przez input[type="text"], co ma wyższą wagę niż
 * sama klasa. Bez tego motyw narzucał białe tło, a tekst zostawał jasny —
 * czyli biały na białym.
 *
 * Kolory podajemy wprost, oba naraz: gdyby motyw mimo wszystko wymusił swoje
 * tło, ciemny tekst pozostanie czytelny.
 */
.pe-app input.pe-prompt {
	flex: 1 1 200px;
	min-width: 120px;
	padding: 9px 16px;
	font-size: 13px;
	font-family: inherit;
	color: #1d2327;
	-webkit-text-fill-color: #1d2327; /* Chrome potrafi nadpisać kolor przy autouzupełnianiu. */
	background: #ffffff;
	border: 1px solid transparent;
	border-radius: 999px;
	box-shadow: none;
}

.pe-app input.pe-prompt:focus {
	outline: none;
	border-color: rgba(255, 255, 255, 0.5);
}

.pe-app input.pe-prompt::placeholder {
	color: #8a8f98;
	opacity: 1; /* Firefox domyślnie przygasza tekst zastępczy. */
}

.pe-generate {
	flex: none;
	margin-left: auto;
	padding: 11px 24px;
	font-size: 14px;
	font-weight: 700;
	font-family: inherit;
	color: var(--pe-accent-text);
	background: var(--pe-accent);
	border: 0;
	border-radius: 999px;
	cursor: pointer;
}

.pe-generate:hover:not(:disabled) {
	filter: brightness(0.9);
}

.pe-generate:disabled {
	opacity: 0.5;
	cursor: default;
}

.pe-status {
	margin: 8px auto 0;
	padding: 0 6px;
	font-size: 12px;
	text-align: center;
	color: var(--pe-muted);
}

.pe-status--error {
	color: var(--pe-danger);
	font-weight: 600;
}

/* Na wąskim ekranie pigułki idą do drugiego rzędu, a przycisk na całą szerokość. */
@media (max-width: 720px) {
	.pe-bar__inner {
		flex-wrap: wrap;
	}

	.pe-pills {
		order: 3;
		width: 100%;
	}

	.pe-generate {
		flex: 1 1 auto;
	}

	.pe-gallery {
		grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
		padding-bottom: 190px;
	}
}
