/* ==========================================================================
   Album — kartki Instax przypięte do tablicy korkowej
   ========================================================================== */

:root {
    --ink:          #23282c;
    --ink-soft:     #5b6570;
    --paper:        #fdfbf5;
    --paper-edge:   #eae4d6;
    --cream:        #f4ecdd;
    --accent:       #b4552f;
    --accent-dark:  #93401f;

    /* napisy na korku — ciemny brąz czyta się lepiej niż biel */
    --cork-ink:      #43270e;
    --cork-ink-soft: rgba(67, 39, 14, .78);

    --hand: 'Caveat', 'Segoe Script', 'Bradley Hand', 'Comic Sans MS', cursive;
    --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

    /* Kartka wypełnia komórkę siatki, ale nie rośnie ponad tę wartość.
       215 px to mniej więcej 54 mm na typowym ekranie — czyli dokładnie
       tyle, ile ma w dłoni prawdziwa odbitka Instax mini. */
    --card-max: 215px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

/* Ustawiane z JS, gdy otwarte jest okno dodawania albo podgląd. */
body.no-scroll { overflow: hidden; }

/*
   Korek. Nie ma tu żadnego obrazka — ziarno robi kilka warstw kropek
   o różnych rozmiarach kafla (79/113/167/... px). Rozmiary są względnie
   pierwsze, więc wzór powtarza się dopiero po tysiącach pikseli i oko
   nie łapie kafelkowania.
*/
body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--sans);
    color: var(--cork-ink);

    background-color: #d3ad78;
    background-image:
        radial-gradient(circle at 17% 24%, rgba(122,  82, 38, .17) 0 1.6px, transparent 2.4px),
        radial-gradient(circle at 68% 11%, rgba(168, 126, 74, .20) 0 2.4px, transparent 3.2px),
        radial-gradient(circle at 41% 71%, rgba(101,  66, 28, .14) 0 1.8px, transparent 2.6px),
        radial-gradient(circle at 87% 58%, rgba(196, 155, 100, .22) 0 3px,  transparent 4px),
        radial-gradient(circle at 9%  86%, rgba(134,  92, 44, .15) 0 1.4px, transparent 2.2px),
        radial-gradient(circle at 76% 92%, rgba(112,  74, 32, .16) 0 2.6px, transparent 3.4px),
        radial-gradient(circle at 33% 44%, rgba(219, 182, 130, .20) 0 2.2px, transparent 3px),
        radial-gradient(circle at 55% 33%, rgba(150, 106, 56, .12) 0 1.2px, transparent 2px),
        linear-gradient(158deg, #dcb682 0%, #c9a26c 100%);
    background-size: 41px 41px, 67px 67px, 53px 53px, 89px 89px,
                     31px 31px, 73px 73px, 59px 59px, 23px 23px, 100% 100%;
}

/* Światło z góry i ściemnienie brzegów — bez tego korek jest płaski. */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(120% 75% at 50% -12%, rgba(255, 240, 210, .30), transparent 62%),
        radial-gradient(135% 120% at 50% 108%, rgba(58, 32, 8, .42), transparent 68%),
        linear-gradient(90deg, rgba(58, 32, 8, .22), transparent 12%, transparent 88%, rgba(58, 32, 8, .22));
}

/* Rama tablicy — zostaje w miejscu, kartki przewijają się pod nią. */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 200;
    pointer-events: none;
    border: clamp(10px, 1.4vw, 20px) solid #6b4423;
    border-image: linear-gradient(145deg, #8a5c30, #5d3a1c 35%, #7a4f28 62%, #4d2f16) 1;
    box-shadow:
        inset 0 0 0 1px rgba(0, 0, 0, .5),
        inset 0 0 34px rgba(45, 24, 6, .45);
}

.masthead,
.board { position: relative; z-index: 1; }

/* --- nagłówek ----------------------------------------------------------- */

.masthead {
    padding: clamp(2rem, 6vw, 4rem) 1.25rem 0.5rem;
    text-align: center;
    text-shadow: 0 1px 0 rgba(255, 244, 222, .35);
}

.masthead__title {
    margin: 0;
    font-family: var(--hand);
    font-weight: 600;
    font-size: clamp(2.75rem, 8vw, 4.75rem);
    line-height: 1;
    letter-spacing: .01em;
    color: var(--cork-ink);
}

.masthead__subtitle {
    margin: .35rem 0 0;
    font-family: var(--hand);
    font-size: clamp(1.15rem, 3vw, 1.6rem);
    color: var(--cork-ink-soft);
}

.masthead__count {
    margin: 1.1rem 0 0;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .22em;
    text-transform: uppercase;
    color: rgba(67, 39, 14, .6);
}

/* --- blat ze zdjęciami -------------------------------------------------- */

/*
   Siatka, a nie swobodny przepływ — dzięki temu kartki leżą dokładnie
   w kolejności dodawania, od lewej do prawej. Rozrzut robią same kartki:
   obrót, przesunięcie w bok i to, że każda wisi trochę niżej lub wyżej.

   Liczba kolumn rośnie z szerokością okna: 2 na telefonie, do 5 na
   monitorze. Kartka nigdy nie przekracza --card-max, więc na szerokim
   ekranie kolumny rozjeżdżają się na boki i między odbitkami widać korek.
*/
.board {
    display: grid;
    grid-template-columns: 1fr;
    gap: clamp(18px, 2.4vw, 36px);
    align-items: start;
    justify-items: center;

    padding: clamp(2rem, 5vw, 3.5rem) clamp(1.25rem, 4vw, 4rem) 9rem;
    max-width: 1600px;
    margin: 0 auto;
}

@media (min-width: 420px)  { .board { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 640px)  { .board { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 860px)  { .board { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1080px) { .board { grid-template-columns: repeat(5, minmax(0, 1fr)); } }

.board__empty {
    grid-column: 1 / -1;   /* komunikat na całą szerokość siatki */
    margin: 4rem auto;
    max-width: 32rem;
    text-align: center;
    font-family: var(--hand);
    font-size: 1.6rem;
    line-height: 1.55;
    color: var(--cork-ink);
    text-shadow: 0 1px 0 rgba(255, 244, 222, .35);
}

.board__empty code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .8em;
    padding: .1em .45em;
    border-radius: .3em;
    background: rgba(74, 44, 16, .14);
}

/*
   Otulina kartki. Wypełnia komórkę siatki i jest kontenerem zapytań —
   wszystko wewnątrz kartki (ramka, podpis, pinezka) wymiarowane jest
   w cqw, czyli w procentach JEJ szerokości. Dzięki temu kartka wygląda
   identycznie i przy pięciu kolumnach, i przy jednej na telefonie.
*/
.pinned {
    container-type: inline-size;
    position: relative;
    width: 100%;
    max-width: var(--card-max);

    /* każda kartka wisi trochę niżej — bez tego rząd byłby idealnie równy */
    margin-top: var(--mt, 0px);
}

/* Podniesiona kartka musi wyjść nad sąsiadki, a container-type zamyka
   jej z-index we własnym kontekście — stąd to samo na otulinie. */
.pinned:hover,
.pinned:focus-within { z-index: 100; }

/* --- kartka Instax ------------------------------------------------------ */

/*
   Proporcje prawdziwego Instax mini (54 x 86 mm, kadr 46 x 62 mm):
   ramka po bokach i u góry to 4/54 szerokości = 7,41%, u dołu
   20/54 = 37,04% — stąd ten charakterystyczny szeroki pasek na podpis.
*/
.polaroid {
    position: relative;
    width: 100%;
    margin: 0;
    padding: 7.41cqw 7.41cqw 37.04cqw;

    background: linear-gradient(160deg, #ffffff 0%, var(--paper) 45%, #f6f1e6 100%);
    border-radius: 3px;

    z-index: var(--z, 1);
    transform: translateX(var(--dx, 0)) rotate(var(--rot, 0deg));

    /* Kartka wisi na pinezce, więc obraca się wokół niej, a nie wokół
       swojego środka — dół odchyla się wyraźnie, góra prawie wcale. */
    transform-origin: 50% 7%;

    box-shadow:
        0 1px 1px rgba(0, 0, 0, .18),
        0 8px 16px -8px rgba(0, 0, 0, .45),
        0 20px 32px -20px rgba(0, 0, 0, .55);

    transition: transform .28s cubic-bezier(.2, .8, .3, 1), box-shadow .28s ease;
}

/* Pinezka wbita w górną krawędź. */
.polaroid::before {
    content: '';
    position: absolute;
    top: 1.2cqw;
    left: 50%;
    z-index: 3;

    width: 8.5cqw;
    height: 8.5cqw;
    margin-left: -4.25cqw;
    border-radius: 50%;

    background:
        radial-gradient(circle at 36% 30%, rgba(255, 255, 255, .95) 0 14%, rgba(255, 255, 255, 0) 46%),
        radial-gradient(circle at 50% 120%, rgba(0, 0, 0, .45), rgba(0, 0, 0, 0) 60%),
        var(--pin, #d0342c);

    box-shadow:
        0 2px 3px rgba(0, 0, 0, .45),
        0 0 0 1px rgba(0, 0, 0, .18),
        inset 0 -1px 3px rgba(0, 0, 0, .35);
}

.polaroid:hover,
.polaroid:focus-within {
    z-index: 100;
    transform: translateX(var(--dx, 0)) rotate(calc(var(--rot, 0deg) * .25)) scale(1.06);
    box-shadow:
        0 2px 3px rgba(0, 0, 0, .2),
        0 18px 28px -10px rgba(0, 0, 0, .5),
        0 40px 60px -30px rgba(0, 0, 0, .6);
}

.polaroid__frame {
    position: relative;
    aspect-ratio: 46 / 62;      /* kadr Instax mini */
    overflow: hidden;
    background: #1c1c1e;
    box-shadow:
        inset 0 0 0 1px rgba(0, 0, 0, .35),
        0 1px 3px rgba(0, 0, 0, .25);
}

.polaroid__img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* leciutko cieplej i kontrastowiej — tak wychodzą zdjęcia z natychmiastowca */
    filter: saturate(1.06) contrast(1.04) sepia(.06);
}

/* Odblask na powierzchni odbitki. */
.polaroid__frame::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(115deg,
        rgba(255, 255, 255, .16) 0%,
        rgba(255, 255, 255, .04) 22%,
        transparent 45%);
}

.polaroid__caption {
    position: absolute;
    left: 8cqw;
    right: 8cqw;
    bottom: 7.5cqw;

    font-family: var(--hand);
    /* Dwie linie tego rozmiaru mieszczą się w dolnym pasku ramki
       (37,04% szerokości) z zapasem — inaczej podpis wchodziłby na zdjęcie.
       Dolna granica pilnuje czytelności na wąskim telefonie. */
    font-size: max(12px, 11.5cqw);
    line-height: 1.15;
    text-align: center;
    color: #2b3138;

    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    overflow-wrap: break-word;
}

/* Przezroczysty przycisk na całej kartce — klikalność bez psucia semantyki. */
.polaroid__hit {
    position: absolute;
    inset: 0;
    border: 0;
    padding: 0;
    background: none;
    cursor: pointer;
    border-radius: 3px;
}

.polaroid__hit:focus-visible {
    outline: 3px solid #ffd79a;
    outline-offset: 4px;
}

/* Świeżo wrzucone zdjęcie wjeżdża na blat. */
@keyframes drop-in {
    from { opacity: 0; transform: translateX(var(--dx, 0)) rotate(var(--rot, 0deg)) scale(1.18) translateY(-40px); }
    to   { opacity: 1; transform: translateX(var(--dx, 0)) rotate(var(--rot, 0deg)); }
}

.polaroid--new { animation: drop-in .55s cubic-bezier(.2, .9, .3, 1) both; }

/* --- przycisk "Dodaj zdjęcie" ------------------------------------------- */

.fab {
    position: fixed;
    right: clamp(1rem, 3vw, 2.25rem);
    bottom: clamp(1rem, 3vw, 2.25rem);
    z-index: 500;

    display: inline-flex;
    align-items: center;
    gap: .55rem;
    padding: .85rem 1.4rem .85rem 1.15rem;

    font-family: var(--sans);
    font-size: .95rem;
    font-weight: 600;
    color: var(--cream);

    background: linear-gradient(#c2603a, var(--accent-dark));
    border: 0;
    border-radius: 999px;
    cursor: pointer;

    box-shadow: 0 6px 18px -4px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255, 255, 255, .25);
    transition: transform .2s ease, box-shadow .2s ease;
}

.fab:hover { transform: translateY(-2px); box-shadow: 0 12px 26px -6px rgba(0, 0, 0, .65), inset 0 1px 0 rgba(255, 255, 255, .3); }
.fab:active { transform: translateY(0); }
.fab:focus-visible { outline: 3px solid #ffd79a; outline-offset: 3px; }

.fab__plus { font-size: 1.35em; line-height: 0; margin-top: -.1em; }

/* --- okno modalne ------------------------------------------------------- */

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.modal[hidden] { display: none; }

.modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(20, 12, 6, .68);
    backdrop-filter: blur(4px);
}

.modal__panel {
    position: relative;
    width: min(30rem, 100%);
    max-height: min(88vh, 46rem);
    overflow-y: auto;
    padding: 1.75rem;

    color: var(--ink);
    background: linear-gradient(155deg, #fffdf7, var(--paper) 60%, #f2ebdd);
    border-radius: 8px;
    box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .8);

    animation: modal-in .25s ease both;
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(14px) scale(.97); }
    to   { opacity: 1; transform: none; }
}

.modal__close {
    position: absolute;
    top: .5rem;
    right: .75rem;
    width: 2rem;
    height: 2rem;
    font-size: 1.6rem;
    line-height: 1;
    color: var(--ink-soft);
    background: none;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}

.modal__close:hover { background: rgba(0, 0, 0, .06); color: var(--ink); }

.modal__title {
    margin: 0 0 .35rem;
    font-family: var(--hand);
    font-weight: 600;
    font-size: 2.1rem;
    line-height: 1.1;
}

.modal__lead {
    margin: 0 0 1.1rem;
    font-size: .9rem;
    color: var(--ink-soft);
}

/* --- formularze --------------------------------------------------------- */

.form { display: block; }
.form[hidden] { display: none; }

.form__row {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-top: 1rem;
}

.form__error {
    margin: .8rem 0 0;
    min-height: 1.2em;
    font-size: .85rem;
    color: #a32d1c;
}

.form__error:empty { margin: 0; min-height: 0; }

.field {
    width: 100%;
    padding: .7rem .9rem;
    font: inherit;
    font-size: 1rem;
    color: var(--ink);
    background: rgba(255, 255, 255, .8);
    border: 1px solid var(--paper-edge);
    border-radius: 6px;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, .06);
}

.field:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(180, 85, 47, .18);
}

.btn {
    padding: .7rem 1.25rem;
    font: inherit;
    font-size: .92rem;
    font-weight: 600;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
    transition: filter .15s ease, transform .15s ease;
}

.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:not(:disabled):hover { filter: brightness(1.07); }
.btn:not(:disabled):active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid rgba(180, 85, 47, .45); outline-offset: 2px; }

.btn--primary {
    margin-top: 1rem;
    color: #fff;
    background: linear-gradient(var(--accent), var(--accent-dark));
    box-shadow: 0 2px 6px -1px rgba(0, 0, 0, .3);
}

.form__row .btn--primary { margin-top: 0; }

.btn--ghost {
    margin-left: auto;
    color: var(--ink-soft);
    background: transparent;
    box-shadow: inset 0 0 0 1px var(--paper-edge);
}

/* --- wybór plików ------------------------------------------------------- */

.dropzone {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: 1.75rem 1rem;
    text-align: center;

    border: 2px dashed #cfc4ad;
    border-radius: 8px;
    background: rgba(255, 255, 255, .5);
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
}

.dropzone:hover,
.dropzone:focus-within,
.dropzone.is-dragover {
    border-color: var(--accent);
    background: rgba(180, 85, 47, .07);
}

/* Pole pliku jest przezroczyste, więc bez tego nie widać, że ma fokus. */
.dropzone:focus-within {
    box-shadow: 0 0 0 3px rgba(180, 85, 47, .2);
}

.dropzone__input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.dropzone__icon { font-size: 1.7rem; }

.dropzone__text {
    font-size: .95rem;
    font-weight: 600;
    color: var(--ink);
}

.dropzone__text small {
    display: inline-block;
    margin-top: .15rem;
    font-weight: 400;
    color: var(--ink-soft);
}

.queue {
    list-style: none;
    margin: 1rem 0 0;
    padding: 0;
    display: grid;
    gap: .7rem;
}

.queue__item {
    display: grid;
    grid-template-columns: 3.5rem 1fr auto;
    align-items: center;
    gap: .75rem;
    padding: .55rem;
    background: rgba(255, 255, 255, .7);
    border: 1px solid var(--paper-edge);
    border-radius: 6px;
}

.queue__thumb {
    width: 3.5rem;
    height: 3.5rem;
    object-fit: cover;
    border-radius: 4px;
    background: #ddd;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
}

.queue__body { min-width: 0; }

.queue__name {
    display: block;
    font-size: .72rem;
    color: var(--ink-soft);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.queue__caption {
    width: 100%;
    margin-top: .25rem;
    padding: .4rem .55rem;
    font: inherit;
    font-size: .88rem;
    border: 1px solid var(--paper-edge);
    border-radius: 4px;
    background: #fff;
}

.queue__caption:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(180, 85, 47, .18);
}

.queue__remove {
    width: 1.75rem;
    height: 1.75rem;
    font-size: 1.2rem;
    line-height: 1;
    color: var(--ink-soft);
    background: none;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}

.queue__remove:hover { background: rgba(0, 0, 0, .07); color: #a32d1c; }

.progress {
    height: 6px;
    margin-top: 1rem;
    overflow: hidden;
    background: rgba(0, 0, 0, .1);
    border-radius: 999px;
}

.progress__bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--accent), #d9803f);
    border-radius: inherit;
    transition: width .2s ease;
}

/* --- ekran logowania (album całkiem prywatny) --------------------------- */

.gate {
    position: relative;
    z-index: 1;
    max-width: 24rem;
    margin: 0 auto;
    padding: clamp(4rem, 18vh, 9rem) 1.5rem;
    text-align: center;
}

.gate__title {
    margin: 0 0 .35rem;
    font-family: var(--hand);
    font-weight: 600;
    font-size: clamp(2.5rem, 9vw, 3.75rem);
    line-height: 1.05;
    color: var(--cork-ink);
    text-shadow: 0 1px 0 rgba(255, 244, 222, .35);
}

.gate__lead {
    margin: 0 0 2rem;
    font-size: .95rem;
    color: var(--cork-ink-soft);
}

.gate .field { background: rgba(255, 255, 255, .95); }
.gate .form__error { color: #8c2415; }

/* --- podgląd pełnoekranowy ---------------------------------------------- */

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: grid;
    place-items: center;
    padding: clamp(1rem, 4vw, 3rem);
    background: rgba(12, 8, 5, .93);
    backdrop-filter: blur(6px);
    animation: fade-in .2s ease both;
}

.lightbox[hidden] { display: none; }

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

.lightbox__figure {
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    max-width: 100%;
    max-height: 100%;
}

.lightbox__img {
    max-width: 100%;
    max-height: 76vh;
    padding: clamp(8px, 1.4vw, 16px);
    background: var(--paper);
    border-radius: 2px;
    box-shadow: 0 30px 70px -25px rgba(0, 0, 0, .9);
}

.lightbox__caption {
    font-family: var(--hand);
    font-size: clamp(1.4rem, 3.5vw, 2.1rem);
    text-align: center;
    color: #fdf4e3;
    max-width: 40ch;
}

.lightbox__close,
.lightbox__nav {
    position: absolute;
    color: rgba(253, 244, 227, .75);
    background: rgba(255, 255, 255, .08);
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

.lightbox__close:hover,
.lightbox__nav:hover { background: rgba(255, 255, 255, .18); color: #fff; }

.lightbox__close {
    top: 1rem;
    right: 1rem;
    width: 2.75rem;
    height: 2.75rem;
    font-size: 1.9rem;
    line-height: 1;
}

.lightbox__nav {
    top: 50%;
    transform: translateY(-50%);
    width: 3rem;
    height: 3rem;
    font-size: 2rem;
    line-height: 1;
}

.lightbox__nav--prev { left: clamp(.5rem, 2vw, 1.5rem); }
.lightbox__nav--next { right: clamp(.5rem, 2vw, 1.5rem); }

/* --- małe ekrany -------------------------------------------------------- */

@media (max-width: 640px) {
    .pinned { margin-top: calc(var(--mt, 0px) * .5); }
    .board { padding-bottom: 7rem; }

    .fab { padding: .75rem 1.15rem; font-size: .88rem; }

    .lightbox__nav { width: 2.5rem; height: 2.5rem; font-size: 1.6rem; }
    .lightbox__img { max-height: 66vh; }
}

/* Dotyk nie ma "hover" — bez tego kartki potrafią zostać powiększone. */
@media (hover: none) {
    .polaroid:hover {
        transform: translateX(var(--dx, 0)) rotate(var(--rot, 0deg));
        z-index: var(--z, 1);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
