:root {
    --menu-bar-height: 28px;
    --dock-height: 70px;
    --window-radius: 10px;
    --accent: #007aff;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text",
        system-ui, sans-serif;
    color: #fff;
}

body {
    /*background: radial-gradient(circle at top, #4c6fff, #0b0c1f 60%);*/
    background-image: url("../images/background/fond.png");
    overflow: hidden;
    background-position: center;
    /* Center the image */
    background-repeat: no-repeat;
    /* Do not repeat the image */
    background-size: cover;
    /* Resize the background image to cover the entire container */
}

.desktop {
    position: relative;
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Barre de menu en haut */
.menu-bar {
    height: var(--menu-bar-height);
    background: rgba(15, 15, 20, 0.75);
    backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    font-size: 12px;
    -webkit-user-select: none;
    user-select: none;
}

.menu-left,
.menu-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.menu-apple {
    font-size: 16px;
}

/* Zone centrale du bureau (où se trouvent les icônes et fenêtres) */
.desktop-main {
    position: relative;
    flex: 1;
    overflow: hidden;
    padding: 16px;
    padding-right: min(460px, 48vw);
}

.widgets-panel {
    position: absolute;
    top: 18px;
    right: 20px;
    width: min(420px, calc(100vw - 40px));
    display: flex;
    flex-direction: column;
    gap: 18px;
    z-index: 40;
}

.widgets-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.desktop-widget {
    position: relative;
    overflow: hidden;
    border-radius: 24px;
    padding: 18px;
    background: rgba(25, 28, 38, 0.42);
    backdrop-filter: blur(24px) saturate(1.3) brightness(0.85);
    -webkit-backdrop-filter: blur(24px) saturate(1.3) brightness(0.85);
    box-shadow: 0 18px 34px rgba(17, 24, 39, 0.32);
    border: 1px solid rgba(255, 255, 255, 0.14);
}

.widget-label {
    display: inline-block;
    margin-bottom: 14px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.78);
}

.desktop-widget-text {
    min-height: 170px;
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0.18)),
        rgba(20, 22, 32, 0.35);
}

.widget-text-content {
    min-height: 96px;
    outline: none;
}

.widget-text-content h2,
.widget-text-content p {
    margin: 0;
}

.widget-text-content h2 {
    font-size: 28px;
    line-height: 1.05;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.widget-text-content p {
    margin-top: 10px;
    font-size: 16px;
    line-height: 1.35;
    color: rgba(255, 255, 255, 0.92);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.desktop-widget-image {
    min-height: 260px;
    padding: 12px;
    display: flex;
    flex-direction: column;
}

.desktop-widget-image .widget-label {
    margin: 6px 8px 12px;
}

.desktop-widget-image img {
    width: 100%;
    height: 100%;
    min-height: 150px;
    flex: 1;
    object-fit: cover;
    border-radius: 18px;
    display: block;
}

/* === Widget Carrousel (style Apple Photos) === */
.desktop-widget-carousel {
    position: relative;
    overflow: hidden;
    padding: 0;
    min-height: 260px;
}

.desktop-widget-carousel .carousel-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0;
    margin: 0;
    min-height: 0;
    flex: none;
    opacity: 0;
    transition: opacity 1.2s ease-in-out;
    pointer-events: none;
    user-select: none;
}

.desktop-widget-carousel .carousel-img.active {
    opacity: 1;
    animation: widget-carousel-kenburns 7s ease-in-out forwards;
}

@keyframes widget-carousel-kenburns {
    from { transform: scale(1); }
    to   { transform: scale(1.06); }
}

/* Dock en bas */
.dock {
    position: relative;
    height: calc(var(--dock-height) + 12px);
    padding: 0 0 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    -webkit-user-select: none;
    user-select: none;
}

.dock::before {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
    width: min(560px, calc(100vw - 36px));
    height: 74px;
    border-radius: 26px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.18)),
        linear-gradient(180deg, rgba(198, 205, 218, 0.28), rgba(112, 122, 139, 0.18));
    border: 1px solid rgba(255, 255, 255, 0.35);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.55),
        inset 0 -14px 24px rgba(110, 118, 139, 0.18);
    backdrop-filter: blur(24px) saturate(140%);
    -webkit-backdrop-filter: blur(24px) saturate(140%);
    pointer-events: none;
}

.dock-icon {
    position: relative;
    z-index: 1;
    width: 58px;
    height: 58px;
    margin-top: -8px;
    border-radius: 18px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(214, 222, 235, 0.64));
    border: 1px solid rgba(255, 255, 255, 0.58);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        0 10px 18px rgba(12, 20, 31, 0.22),
        inset 0 1px 0 rgba(255, 255, 255, 0.75),
        inset 0 -10px 18px rgba(116, 127, 146, 0.16);
    transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
    cursor: pointer;
}

.dock-icon::after {
    content: "";
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 7px;
    height: 8px;
    border-radius: 999px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0));
    opacity: 0.9;
    pointer-events: none;
}

.dock-icon img {
    width: 36px;
    height: 36px;
    pointer-events: none;
    filter: drop-shadow(0 4px 7px rgba(15, 23, 42, 0.18));
}

.dock-icon:hover {
    transform: translateY(-12px) scale(1.18);
    box-shadow:
        0 18px 28px rgba(12, 20, 31, 0.28),
        inset 0 1px 0 rgba(255, 255, 255, 0.85),
        inset 0 -12px 22px rgba(116, 127, 146, 0.2);
    filter: saturate(1.08);
}

.dock-icon:active {
    transform: translateY(-6px) scale(1.08);
}

/* Icônes du bureau */
.desktop-icon {
    position: absolute;
    width: 80px;
    text-align: center;
    font-size: 12px;
    color: #fff;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    padding: 4px;
    border-radius: 8px;
    transition: background 0.15s ease, transform 0.15s ease;
}

.desktop-icon:hover {
    background: rgba(255, 255, 255, 0.12);
    transform: scale(1.10);
}

.desktop-icon img {
    max-width: 48px;
    max-height: 60px;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    margin: 0 auto 4px;
    border-radius: 12px;
    pointer-events: none;
}

.desktop-icon span {
    display: block;
    word-wrap: break-word;
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
    padding: 1px 6px;
    border-radius: 4px;
    transition: background-color 0.15s ease;
}

.desktop-icon:hover span {
    background: rgba(0, 122, 255, 0.9);
}

.icons-name {
    text-shadow: rgba(0, 0, 0) 1px 1px 2px;
}

/* Fenêtres d'applications */
.app-window {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: min(900px, 92vw);
    height: calc(100% - 25px);
    min-width: 320px;
    min-height: 220px;
    max-height: calc(100% - 20px);
    background: #f5f5f7;
    color: #111;
    border-radius: var(--window-radius);
    box-shadow:
        0 10px 24px rgba(0, 0, 0, 0.12),
        0 2px 8px rgba(0, 0, 0, 0.06);
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.app-window.visible {
    display: flex;
}

.window-titlebar {
    height: 28px;
    display: flex;
    align-items: center;
    padding: 10px 10px;
    background: linear-gradient(to bottom, #e5e5ea, #c7c7cc);
    border-bottom: 1px solid #b0b0b5;
    -webkit-user-select: none;
    user-select: none;
    cursor: move;
}


.window-buttons {
    display: flex;
    gap: 6px;
    margin-right: 10px;
    cursor: pointer;
}

.window-btn {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.15);
}

.window-btn.close {
    background: #ff5f57;
}

.window-btn.minimize {
    background: #febc2e;
}

.window-btn.maximize {
    background: #28c840;
}

.window-title {
    font-size: 12px;
    font-weight: 500;
}

.window-content {
    flex: 1;
    padding: 14px 16px 18px;
    overflow: auto;
}

.window-resize-handle {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 18px;
    height: 18px;
    cursor: nwse-resize;
    z-index: 3;
}

.window-resize-handle::before {
    content: "";
    position: absolute;
    right: 4px;
    bottom: 4px;
    width: 10px;
    height: 10px;
    border-right: 2px solid rgba(17, 17, 17, 0.35);
    border-bottom: 2px solid rgba(17, 17, 17, 0.35);
    border-radius: 0 0 3px 0;
}

.window-content h2 {
    margin-top: 0;
    font-size: 18px;
}

.window-content img {
    max-width: 100%;
    border-radius: 8px;
    margin-top: 10px;
    display: block;
    cursor: zoom-in;
}

.window-content video {
    max-width: 100%;
    border-radius: 8px;
    margin-top: 10px;
    display: block;
}

.window-section {
    margin-bottom: 12px;
}

/* === Galerie Photos === */
.app-window-gallery {
    width: min(1100px, 95vw);
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: 140px;
    grid-auto-flow: dense;
    gap: 8px;
    margin-top: 8px;
}

.gallery-item {
    overflow: hidden;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.2);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    margin: 0;
    border-radius: 0;
}

.gallery-item.landscape {
    grid-column: span 2;
    grid-row: span 1;
}

.gallery-item.portrait {
    grid-column: span 1;
    grid-row: span 2;
}

@media (max-width: 600px) {
    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        grid-auto-rows: 110px;
    }
    .gallery-item.landscape { grid-column: span 2; }
    .gallery-item.portrait { grid-column: span 1; grid-row: span 2; }
}

/* Responsive : ajuster un peu les tailles sur petits écrans */
@media (max-width: 600px) {
    .desktop-main {
        padding-right: 16px;
        overflow: auto;
    }

    .widgets-panel {
        display: none;
    }

    .desktop-icon {
        width: 72px;
        font-size: 11px;
    }

    .desktop-icon img {
        max-width: 42px;
        max-height: 54px;
        width: auto;
        height: auto;
    }

    .dock-icon {
        width: 48px;
        height: 48px;
        border-radius: 15px;
    }

    .dock-icon img {
        width: 30px;
        height: 30px;
    }
}

/* === Lightbox / image overlay === */
.image-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.88);
    backdrop-filter: blur(14px) saturate(1.1);
    -webkit-backdrop-filter: blur(14px) saturate(1.1);
    cursor: zoom-out;
    opacity: 0;
    transition: opacity 0.18s ease;
}

.image-overlay.visible {
    display: flex;
    opacity: 1;
}

.image-overlay img {
    max-width: 92vw;
    max-height: 92vh;
    object-fit: contain;
    border-radius: 6px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
    cursor: default;
    user-select: none;
}

.image-overlay-close,
.image-overlay-nav {
    position: absolute;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.15s;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}

.image-overlay-close:hover,
.image-overlay-nav:hover {
    background: rgba(255, 255, 255, 0.22);
    transform: scale(1.08);
}

.image-overlay-close:active,
.image-overlay-nav:active {
    transform: scale(0.96);
}

.image-overlay-close { top: 20px; right: 20px; }
.image-overlay-prev  { left: 20px;  top: 50%; transform: translateY(-50%); }
.image-overlay-next  { right: 20px; top: 50%; transform: translateY(-50%); }

.image-overlay-prev:hover { transform: translateY(-50%) scale(1.08); }
.image-overlay-next:hover { transform: translateY(-50%) scale(1.08); }
.image-overlay-prev:active { transform: translateY(-50%) scale(0.96); }
.image-overlay-next:active { transform: translateY(-50%) scale(0.96); }

@media (max-width: 600px) {
    .image-overlay-close,
    .image-overlay-nav {
        width: 38px;
        height: 38px;
        font-size: 22px;
    }
    .image-overlay-close { top: 12px; right: 12px; }
    .image-overlay-prev  { left: 8px; }
    .image-overlay-next  { right: 8px; }
}

/* La barre d'état iOS n'existe que pour le mode mobile : masquée sur desktop */
.ios-statusbar { display: none; }

/* ============================================================
   MODE iPhone — actif uniquement sur écrans ≤ 768px.
   Tout est additif : la version desktop (> 768px) n'est pas
   affectée par ce bloc. Le JS bascule le DOM en parallèle
   (cf. js/script.js, bloc `if (IS_MOBILE)`).
   ============================================================ */
@media (max-width: 768px) {

    .desktop {
        height: 100dvh; /* fallback 100vh hérité de la règle de base */
    }

    /* --- Barre d'état iOS (heure / signal-wifi-batterie) --- */
    .menu-bar { display: none; }

    .ios-statusbar {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: calc(env(safe-area-inset-top, 0px) + 40px);
        padding: env(safe-area-inset-top, 0px) 22px 0;
        align-items: center;
        justify-content: space-between;
        z-index: 10000;
        font-size: 15px;
        font-weight: 600;
        color: #fff;
        text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
        background: linear-gradient(to bottom, rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.12) 55%, transparent);
        pointer-events: none;
    }
    .ios-statusbar-time { letter-spacing: 0.02em; }
    .ios-statusbar-right {
        display: flex;
        align-items: center;
        gap: 6px;
        filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
    }
    .ios-signal { display: flex; align-items: flex-end; gap: 2px; height: 12px; }
    .ios-signal span { width: 3px; background: #fff; border-radius: 1px; }
    .ios-signal span:nth-child(1) { height: 4px; }
    .ios-signal span:nth-child(2) { height: 7px; }
    .ios-signal span:nth-child(3) { height: 10px; }
    .ios-signal span:nth-child(4) { height: 12px; }
    .ios-wifi { display: flex; align-items: center; color: #fff; }
    .ios-battery { display: flex; align-items: center; gap: 1px; }
    .ios-battery-body {
        width: 24px;
        height: 12px;
        border: 1.5px solid rgba(255, 255, 255, 0.9);
        border-radius: 3px;
        padding: 1.5px;
        display: flex;
    }
    .ios-battery-level { flex: 0 0 78%; background: #fff; border-radius: 1px; }
    .ios-battery-cap {
        width: 2px;
        height: 4px;
        background: rgba(255, 255, 255, 0.9);
        border-radius: 0 1px 1px 0;
    }

    /* --- Écran d'accueil paginé --- */
    .desktop-main {
        position: relative;
        padding: 0;
        overflow: hidden;
    }
    .widgets-panel { display: none; } /* le JS sort les widgets utiles ; le panneau reste masqué */

    .ios-home {
        position: relative;
        width: 100%;
        height: 100%;
    }
    .ios-home-pages {
        display: flex;
        width: 100%;
        height: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .ios-home-pages::-webkit-scrollbar { display: none; }
    .ios-home-page {
        flex: 0 0 100%;
        width: 100%;
        height: 100%;
        scroll-snap-align: start;
        box-sizing: border-box;
        padding: calc(env(safe-area-inset-top, 0px) + 56px) 18px 40px;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        grid-auto-rows: min-content;
        gap: 24px 6px;
        align-content: start;
        overflow-y: auto;
        overflow-x: hidden;
    }

    /* --- Icônes en grille (override du positionnement absolu desktop) --- */
    .desktop-icon {
        position: static;
        width: auto;
        margin: 0;
        padding: 0;
        font-size: 11px;
        color: #fff;
        display: flex;
        flex-direction: column;
        align-items: center;
        border-radius: 0;
    }
    .desktop-icon:hover { background: none; transform: none; }
    .desktop-icon:hover span { background: transparent; }
    .desktop-icon img {
        max-width: 58px;
        max-height: 58px;
        width: auto;
        height: auto;
        object-fit: contain;
        margin: 0 auto 6px;
        border-radius: 14px;
    }
    .desktop-icon span {
        padding: 0 4px;
        line-height: 1.2;
        max-height: 2.4em;
        overflow: hidden;
    }

    /* --- Widgets iOS dans la grille (page 1) --- */
    .desktop-widget.ios-widget {
        grid-column: 1 / -1;
        border-radius: 22px;
        margin: 0;
    }
    .ios-widget-notes {
        padding: 16px 18px;
        min-height: 0;
    }
    .ios-widget-notes .widget-label { margin-bottom: 8px; }
    .ios-widget-notes .widget-text-content { min-height: 0; }
    .ios-widget-notes .widget-text-content h2 { font-size: 19px; }
    .ios-widget-notes .widget-text-content p { font-size: 14px; margin-top: 6px; }
    .desktop-widget-carousel.ios-widget {
        height: 160px;
        min-height: 0;
        padding: 0;
    }

    /* --- Dots de pagination --- */
    .ios-page-dots {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 6px;
        display: flex;
        justify-content: center;
        gap: 7px;
        z-index: 50;
    }
    .ios-dot {
        width: 7px;
        height: 7px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.35);
        transition: background 0.2s;
        cursor: pointer;
    }
    .ios-dot.active { background: rgba(255, 255, 255, 0.95); }

    /* --- Dock iOS (réutilise .dock / .dock-icon, juste retaillé + safe-area) --- */
    .dock {
        padding: 0 0 env(safe-area-inset-bottom, 6px);
        height: calc(var(--dock-height) + env(safe-area-inset-bottom, 6px));
        z-index: 60;
    }
    .dock::before {
        width: min(420px, calc(100vw - 24px));
        height: 64px;
        bottom: calc(env(safe-area-inset-bottom, 6px) + 4px);
    }
    .dock-icon {
        width: 50px;
        height: 50px;
        border-radius: 14px;
        margin-top: -6px;
    }
    .dock-icon img { width: 32px; height: 32px; }
    .dock-icon:hover { transform: none; box-shadow:
        0 2px 6px rgba(12, 20, 31, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.7),
        inset 0 -10px 18px rgba(116, 127, 146, 0.16); filter: none; }
    .dock-icon:active { transform: scale(0.92); }

    /* --- Apps en plein écran --- */
    .app-window {
        position: fixed;
        inset: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        min-width: 0;
        min-height: 0;
        max-height: none;
        transform: none;
        border-radius: 0;
        z-index: 9000;
        box-shadow: none;
        transition:
            transform 0.34s cubic-bezier(0.32, 0.72, 0, 1),
            opacity 0.22s ease,
            border-radius 0.34s ease;
    }
    .app-window.ios-opening,
    .app-window.ios-closing {
        transform: scale(0.12);
        opacity: 0;
        border-radius: 28px;
    }

    /* Barre de titre → barre de navigation iOS.
       Le padding-top inclut 40px pour passer SOUS la .ios-statusbar (fixed en haut),
       en plus de env(safe-area-inset-top) pour les iPhones notch en PWA. */
    .window-titlebar {
        height: auto;
        min-height: calc(env(safe-area-inset-top, 0px) + 88px);
        padding: calc(env(safe-area-inset-top, 0px) + 46px) 8px 8px;
        background: rgba(248, 248, 250, 0.94);
        -webkit-backdrop-filter: saturate(1.6) blur(20px);
        backdrop-filter: saturate(1.6) blur(20px);
        border-bottom: 1px solid rgba(0, 0, 0, 0.08);
        cursor: default;
        position: relative;
        justify-content: center;
    }
    .window-titlebar .window-buttons { display: none; }
    .window-title { font-size: 16px; font-weight: 600; color: #111; }
    .ios-app-back {
        position: absolute;
        left: 4px;
        bottom: 4px;
        height: 40px;
        min-width: 48px;
        padding: 0 8px 0 2px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: none;
        border: none;
        color: var(--accent);
        font-size: 30px;
        line-height: 1;
        font-family: inherit;
        cursor: pointer;
    }
    .ios-app-back:active { opacity: 0.45; }

    .window-content {
        padding: 16px 16px calc(32px + env(safe-area-inset-bottom, 0px));
    }
    .window-resize-handle { display: none; }

    /* Home indicator (sert aussi de bouton fermer) */
    .ios-home-indicator {
        position: absolute;
        bottom: calc(7px + env(safe-area-inset-bottom, 0px));
        left: 50%;
        transform: translateX(-50%);
        width: 134px;
        height: 5px;
        border-radius: 3px;
        background: rgba(0, 0, 0, 0.32);
        z-index: 9001;
        cursor: pointer;
    }
    .ios-home-indicator:active { background: rgba(0, 0, 0, 0.5); }

    /* Galerie en plein écran : 2 colonnes */
    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        grid-auto-rows: 130px;
    }
    .gallery-item.landscape { grid-column: span 2; grid-row: span 1; }
    .gallery-item.portrait  { grid-column: span 1; grid-row: span 2; }

    /* La fenêtre galerie a sa propre largeur sur desktop ; en mobile c'est plein écran */
    .app-window-gallery { width: 100%; }
}
