/* ===========================================================
   Galerie photo — style inspiré d'iOS (Photos / réglages)
   =========================================================== */

:root {
    --bg: #f2f2f7;
    --bg-elevated: #ffffff;
    --text: #1c1c1e;
    --text-secondary: #8e8e93;
    --separator: rgba(60, 60, 67, 0.16);
    --accent: #007aff;
    --danger: #ff3b30;
    --overlay-scrim: rgba(0, 0, 0, 0.35);
    --blur-bg: rgba(255, 255, 255, 0.72);
    --radius: 13px;
    --radius-lg: 20px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #000000;
        --bg-elevated: #1c1c1e;
        --text: #f2f2f7;
        --text-secondary: #98989d;
        --separator: rgba(84, 84, 88, 0.6);
        --blur-bg: rgba(28, 28, 30, 0.72);
        --overlay-scrim: rgba(0, 0, 0, 0.55);
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* ---------- Barre supérieure ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: calc(var(--safe-top) + 12px) 16px 12px;
    background: var(--blur-bg);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 0.5px solid var(--separator);
}

.topbar-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0;
    flex: 1;
}

.topbar-count {
    font-size: 13px;
    color: var(--text-secondary);
}

.topbar-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    color: var(--accent);
    text-decoration: none;
    transition: background 0.15s ease;
}
.topbar-logout:active { background: var(--separator); }

/* ---------- Galerie ---------- */

.gallery {
    padding: 4px 12px calc(var(--safe-bottom) + 24px);
    max-width: 1400px;
    margin: 0 auto;
}

.year-section { margin-top: 22px; }

.year-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0 4px 8px;
}

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 3px;
}

.photo-item {
    position: relative;
    margin: 0;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border-radius: 6px;
    background: var(--bg-elevated);
}

.video-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(28, 28, 30, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    color: #ffffff;
    pointer-events: none;
}
.video-badge svg { margin-left: 1px; } /* recentrage optique du triangle */

.photo-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    background: var(--separator);
}

.photo-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    gap: 6px;
    padding: 7px;
    background: linear-gradient(to top, var(--overlay-scrim) 0%, transparent 42%);
    opacity: 0;
    transition: opacity 0.18s ease;
}

/* Sur tactile : toujours visible mais discret (pas de hover) */
@media (hover: none) {
    .photo-overlay { opacity: 1; }
}

.photo-item:hover .photo-overlay,
.photo-item:focus-within .photo-overlay {
    opacity: 1;
}

.photo-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: rgba(28, 28, 30, 0.45);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    color: #ffffff;
    cursor: pointer;
    padding: 0;
    transition: transform 0.12s ease, background 0.12s ease;
}
.photo-btn:active {
    transform: scale(0.9);
    background: rgba(28, 28, 30, 0.65);
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    margin-top: 60px;
    font-size: 15px;
}
.empty-state code {
    background: var(--separator);
    padding: 2px 6px;
    border-radius: 6px;
}

/* ---------- Lightbox ---------- */

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
}
.lightbox.open {
    opacity: 1;
    pointer-events: auto;
}

.lightbox-image {
    max-width: 94vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 10px;
    opacity: 0;
    transform: scale(0.96);
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.lightbox-image.loaded {
    opacity: 1;
    transform: scale(1);
}

.lightbox-video {
    max-width: 94vw;
    max-height: 90vh;
    border-radius: 10px;
    opacity: 0;
    transform: scale(0.96);
    transition: opacity 0.2s ease, transform 0.2s ease;
    display: none;
    background: #000;
}
.lightbox-video.visible { display: block; }
.lightbox-video.loaded {
    opacity: 1;
    transform: scale(1);
}

.lightbox-spinner {
    position: absolute;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2.5px solid rgba(255, 255, 255, 0.25);
    border-top-color: #ffffff;
    animation: spin 0.8s linear infinite;
    display: none;
}
.lightbox-spinner.visible { display: block; }

@keyframes spin { to { transform: rotate(360deg); } }

.lightbox-close,
.lightbox-download {
    position: absolute;
    top: calc(var(--safe-top) + 16px);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(120, 120, 128, 0.32);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #ffffff;
    cursor: pointer;
}
.lightbox-close { right: 16px; }
.lightbox-download { right: 66px; }
.lightbox-close:active,
.lightbox-download:active { transform: scale(0.92); }

/* ---------- Connexion ---------- */

.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 340px;
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    padding: 32px 26px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
}

.login-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card h1 {
    font-size: 20px;
    font-weight: 700;
    margin: 0 0 6px;
}

.login-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0 0 22px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.login-input {
    width: 100%;
    padding: 13px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--separator);
    background: var(--bg);
    color: var(--text);
    font-size: 16px; /* évite le zoom auto iOS */
    outline: none;
}
.login-input:focus {
    border-color: var(--accent);
}

.login-button {
    padding: 13px 14px;
    border: none;
    border-radius: var(--radius);
    background: var(--accent);
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.12s ease;
}
.login-button:active { opacity: 0.75; }

.login-error {
    margin-top: 14px;
    color: var(--danger);
    font-size: 13px;
}

/* ---------- Responsive ---------- */

@media (min-width: 700px) {
    .photo-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 4px; }
    .gallery { padding: 8px 24px 40px; }
}

@media (min-width: 1100px) {
    .photo-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}
