* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #1a1a1a;
    --card-w: 140px;
    --card-h: 190px;
    --card-padding: 8px;
    --card-bottom: 24px;
}

body {
    min-height: 100vh;
    background-color: var(--bg);
    color: #fff;
    font-family: "Noto Serif TC", "Microsoft JhengHei", serif;
}

/* ── Header ──────────────────────────────────── */
.gallery-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    padding: 16px 16px 12px;
    background: linear-gradient(to bottom, #1a1a1a 60%, transparent);
}

.gallery-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    color: #f0ebe3;
    font-size: 18px;
    text-decoration: none;
    flex-shrink: 0;
    transition: background 0.2s;
}

.gallery-back:active {
    background: rgba(255,255,255,0.2);
}

.gallery-header-text {
    flex: 1;
    text-align: center;
    margin-right: 40px; /* 平衡左側返回鍵的寬度 */
}

.gallery-header h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: #f0ebe3;
}

.gallery-header p {
    margin-top: 2px;
    font-size: 12px;
    color: #9e9689;
    letter-spacing: 0.1em;
}

/* ── Grid ────────────────────────────────────── */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--card-w), 1fr));
    gap: 16px;
    padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
    overflow-y: auto;
}

/* ── Polaroid Card ───────────────────────────── */
.polaroid-card {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4.2;
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.35);
    cursor: pointer;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
                box-shadow 0.25s ease;
    animation: cardFadeIn 0.4s ease both;
}

.polaroid-card:hover {
    transform: translateY(-4px) rotate(-1deg);
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.polaroid-card:active {
    transform: scale(0.97);
}

@keyframes cardFadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* 照片區域（佔上方大部分） */
.polaroid-card .card-photo {
    position: absolute;
    top: var(--card-padding);
    left: var(--card-padding);
    right: var(--card-padding);
    bottom: var(--card-bottom);
    background-color: #222;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    /* 向內陰影，模擬拍立得相片凹陷感 */
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.45),
                inset 0 -2px 6px rgba(0,0,0,0.25);
}

/* ── Empty State ─────────────────────────────── */
.gallery-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: #9e9689;
}

.gallery-empty p {
    font-size: 16px;
    font-weight: 600;
}

.gallery-empty small {
    font-size: 12px;
    opacity: 0.6;
}

/* ── Lightbox ────────────────────────────────── */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.92);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.lightbox.active {
    opacity: 1;
    pointer-events: auto;
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 101;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: rgba(255,255,255,0.12);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    transition: background 0.2s;
}

.lightbox-close:hover {
    background: rgba(255,255,255,0.25);
}

/* Lightbox 拍立得大卡 */
.lightbox-photo {
    width: min(85vw, 380px);
    aspect-ratio: 3 / 4.2;
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.6);
    position: relative;
    transform: scale(0.85);
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.lightbox.active .lightbox-photo {
    transform: scale(1);
}

.lightbox-photo .card-photo {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    bottom: 36px;
    background-color: #222;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.45),
                inset 0 -2px 6px rgba(0,0,0,0.25);
}

/* ── Mobile RWD ──────────────────────────────── */
@media (max-width: 600px) {
    :root {
        --card-w: 110px;
        --card-padding: 6px;
        --card-bottom: 18px;
    }

    .gallery-grid {
        gap: 10px;
        padding: 6px 10px calc(16px + env(safe-area-inset-bottom));
    }

    .gallery-header {
        padding: 14px 14px 10px;
    }

    .lightbox-photo {
        width: min(90vw, 340px);
    }

    .lightbox-photo .card-photo {
        top: 8px;
        left: 8px;
        right: 8px;
        bottom: 28px;
    }
}
