:root {
    --glass-bg: rgba(38, 24, 16, 0.45);
    --glass-bg-light: rgba(255, 255, 255, 0.06);
    --glass-border: rgba(255, 255, 255, 0.13);
    --glass-border-strong: rgba(255, 255, 255, 0.28);
    --glass-highlight: rgba(255, 255, 255, 0.1);
    --text-color: #ffffff;
    --text-soft: rgba(255, 255, 255, 0.72);
    --text-faint: rgba(255, 255, 255, 0.45);
    --primary-gradient: linear-gradient(135deg, #ff8a5c 0%, #ffc371 100%);
    --accent-amber: #ffb347;
    --blur-amount: 28px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
}

html {
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    width: 100%;
    background: #170c08;
    color: var(--text-color);
    overflow-x: hidden;
    overflow-y: auto;
    touch-action: manipulation;
    position: relative;
    -webkit-font-smoothing: antialiased;
}

body.overlay-open {
    overflow: hidden;
}

/* ---------- Fond animé : aurora + bokeh ---------- */

.bg-aurora {
    position: fixed;
    inset: 0;
    z-index: -2;
    overflow: hidden;
    background:
        radial-gradient(1200px 800px at 15% 5%, #2a1a0e 0%, transparent 60%),
        radial-gradient(1000px 900px at 100% 100%, #3a1030 0%, transparent 55%),
        linear-gradient(160deg, #14091a 0%, #2a1509 45%, #10102a 100%);
    background-size: 160% 160%;
    animation: bgShift 26s ease-in-out infinite, auroraHue 18s linear infinite;
}

@keyframes bgShift {
    0%   { background-position: 0% 0%; }
    25%  { background-position: 50% 35%; }
    50%  { background-position: 100% 65%; }
    75%  { background-position: 35% 90%; }
    100% { background-position: 0% 0%; }
}

@keyframes auroraHue {
    0%   { filter: hue-rotate(0deg); }
    50%  { filter: hue-rotate(28deg); }
    100% { filter: hue-rotate(0deg); }
}

.aurora-blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(70px) saturate(140%);
    mix-blend-mode: screen;
    opacity: 0.75;
    pointer-events: none;
    will-change: transform, translate;
    animation: auroraFloat 22s ease-in-out infinite alternate;
}

.aurora-blob-lg {
    animation-duration: 18s;
}

.aurora-blob-sm {
    opacity: 0.85;
}

@keyframes auroraFloat {
    0%   { transform: translate(0, 0) scale(1) rotate(0deg); }
    30%  { transform: translate(70px, -50px) scale(1.2) rotate(8deg); }
    60%  { transform: translate(-55px, 60px) scale(0.88) rotate(-8deg); }
    100% { transform: translate(40px, -25px) scale(1.1) rotate(4deg); }
}

.bg-bokeh {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.bokeh {
    position: absolute;
    border-radius: 50%;
    mix-blend-mode: screen;
    will-change: transform, translate;
    animation: bokehFloat 14s ease-in-out infinite alternate;
}

@keyframes bokehFloat {
    0%   { transform: translate(0, 0); }
    50%  { transform: translate(12px, -34px); }
    100% { transform: translate(-10px, 20px); }
}

.bg-warm {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(60% 45% at 50% 108%, rgba(255, 168, 74, 0.28) 0%, transparent 70%),
        radial-gradient(40% 30% at 12% 0%, rgba(255, 205, 90, 0.18) 0%, transparent 70%);
}

/* ---------- Barre de recherche ---------- */

.search-bar {
    position: fixed;
    top: max(14px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    width: min(560px, calc(100% - 32px));
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 4px;
    height: 48px;
    padding: 0 8px 0 16px;
    background: rgba(38, 24, 16, 0.55);
    backdrop-filter: blur(24px) saturate(160%);
    -webkit-backdrop-filter: blur(24px) saturate(160%);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4),
                inset 0 1px 0 rgba(255, 255, 255, 0.1);
    transition: box-shadow 0.3s ease, background 0.3s ease, border-color 0.3s ease;
}

.search-bar:focus-within {
    background: rgba(38, 24, 16, 0.8);
    border-color: var(--glass-border-strong);
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.05),
                0 8px 34px -6px rgba(255, 168, 74, 0.4);
}

.search-bar-icon {
    color: var(--text-faint);
    font-size: 20px;
    flex-shrink: 0;
    pointer-events: none;
}

.search-input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    outline: none;
    color: #ffffff;
    font-size: 0.95rem;
    font-weight: 400;
    height: 100%;
}

.search-input::placeholder {
    color: var(--text-faint);
    font-weight: 300;
}

.search-clear {
    display: none;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    font-size: 18px;
    color: var(--text-soft);
    background: rgba(255, 255, 255, 0.08);
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.25s ease;
    user-select: none;
}

.search-clear.visible {
    display: flex;
}

.search-clear:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

/* ---------- Résultats de recherche ---------- */

.search-results {
    position: absolute;
    top: calc(100% + 12px);
    left: 0;
    right: 0;
    max-height: min(70vh, 560px);
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding: 8px;
    background: rgba(38, 24, 16, 0.85);
    backdrop-filter: blur(32px) saturate(150%);
    -webkit-backdrop-filter: blur(32px) saturate(150%);
    border: 1px solid var(--glass-border);
    border-radius: 18px;
    box-shadow: 0 30px 70px rgba(0, 0, 0, 0.65),
                inset 0 1px 0 rgba(255, 255, 255, 0.1);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px) scale(0.98);
    transition: all 0.28s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1002;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

.search-results.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.search-results::-webkit-scrollbar {
    width: 5px;
}

.search-results::-webkit-scrollbar-track {
    background: transparent;
}

.search-results::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 6px;
}

.search-group-label {
    padding: 10px 14px 6px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.4px;
    color: var(--text-faint);
}

.search-item {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 10px 12px;
    border-radius: 13px;
    color: #ffffff;
    text-decoration: none;
    transition: background 0.22s ease, transform 0.22s ease;
    cursor: pointer;
}

.search-item:hover {
    background: rgba(255, 255, 255, 0.09);
    transform: translateX(4px);
}

.search-item-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
    overflow: hidden;
}

.search-item-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.search-item-info {
    flex: 1;
    min-width: 0;
}

.search-item-name {
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-item-desc {
    font-size: 0.72rem;
    color: var(--text-faint);
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-item-badge {
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 4px 10px;
    border-radius: 20px;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.09);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text-soft);
}

.search-item-badge.badge-game {
    color: #ffb347;
    border-color: rgba(255, 179, 71, 0.4);
    background: rgba(255, 179, 71, 0.12);
}

.search-item-badge.badge-app {
    color: #ffd08a;
    border-color: rgba(255, 208, 138, 0.35);
    background: rgba(255, 208, 138, 0.1);
}

.search-empty {
    padding: 26px 16px;
    text-align: center;
    color: var(--text-faint);
    font-size: 0.85rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.search-empty .material-symbols-outlined {
    font-size: 30px;
    opacity: 0.6;
}

/* ---------- Bouton soutien ---------- */

.support-btn {
    position: fixed;
    top: max(14px, env(safe-area-inset-top));
    right: max(16px, env(safe-area-inset-right));
    z-index: 999;
    text-decoration: none;
    color: #ffffff;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--glass-border);
    padding: 10px 18px;
    border-radius: 30px;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.support-btn:hover {
    transform: translateY(-2px);
    background: rgba(0, 0, 0, 0.6);
    border-color: var(--glass-border-strong);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

/* ---------- Accueil ---------- */

.home-view {
    position: relative;
    z-index: 10;
    max-width: 1100px;
    width: 92%;
    margin: 0 auto;
    padding: calc(110px + env(safe-area-inset-top)) 0 48px;
    min-height: 100vh;
    min-height: 100dvh;
}

.home-header {
    text-align: center;
    margin-bottom: 2.2rem;
}

.home-title {
    font-size: clamp(2.4rem, 6vw, 4rem);
    font-weight: 900;
    line-height: 1.1;
    background: linear-gradient(135deg, #ffffff 0%, #ffd08a 60%, #ff8a5c 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    text-shadow: none;
    filter: drop-shadow(0 4px 24px rgba(255, 168, 74, 0.35));
}

.home-subtitle {
    margin-top: 0.4rem;
    color: var(--text-soft);
    font-size: clamp(0.95rem, 2.5vw, 1.2rem);
    font-weight: 300;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
    gap: 1.7rem 1rem;
    justify-items: center;
}

.category-folder {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.7rem;
    padding: 0.4rem 0.2rem;
    border-radius: 22px;
    color: #fff;
    font-family: inherit;
    width: 100%;
    max-width: 130px;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    animation: fadeIn 0.6s ease backwards;
    -webkit-tap-highlight-color: transparent;
}

.category-folder:hover {
    transform: translateY(-6px);
}

.category-folder:active {
    transform: scale(0.94);
}

.folder-tile {
    width: 104px;
    height: 104px;
    border-radius: 26px;
    background: rgba(255, 255, 255, 0.09);
    backdrop-filter: blur(18px) saturate(160%);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
    border: 1px solid var(--glass-border);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18),
                0 12px 28px -12px rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    transition: box-shadow 0.3s ease;
}

.category-folder:hover .folder-tile {
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22),
                0 18px 40px -14px rgba(0, 0, 0, 0.7),
                0 0 30px -8px rgba(255, 168, 74, 0.45);
}

.folder-tile-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mini-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    width: 84px;
    height: 84px;
    align-content: center;
}

.mini-tile {
    width: 25px;
    height: 25px;
    border-radius: 7px;
    background: linear-gradient(135deg, var(--tile-from, #ff8a5c), var(--tile-to, #ffc371));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    color: #fff;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
    overflow: hidden;
}

.mini-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mini-tile.tile-game {
    font-size: 0.6rem;
}

.mini-tile-empty {
    font-size: 0.9rem;
    background: rgba(255, 255, 255, 0.1);
}

.folder-name {
    font-size: 0.78rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.92);
    max-width: 100%;
    text-align: center;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
    overflow-wrap: anywhere;
    line-height: 1.25;
}

/* ---------- Overlay dossier (animation iOS) ---------- */

.folder-overlay {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(24, 12, 6, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    padding: 24px;
}

.folder-overlay.open {
    opacity: 1;
    visibility: visible;
}

.folder-sheet {
    width: min(680px, 100%);
    max-height: min(78vh, 640px);
    max-height: min(78dvh, 640px);
    overflow: hidden;
    background: rgba(38, 24, 16, 0.78);
    backdrop-filter: blur(40px) saturate(170%);
    -webkit-backdrop-filter: blur(40px) saturate(170%);
    border: 1px solid var(--glass-border-strong);
    border-radius: 32px;
    box-shadow: 0 40px 120px rgba(0, 0, 0, 0.7),
                inset 0 1px 0 rgba(255, 255, 255, 0.15);
    display: flex;
    flex-direction: column;
    transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
    will-change: transform;
}

.folder-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 22px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.folder-header-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    overflow: hidden;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.folder-header-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.folder-header-emoji {
    font-size: 1.8rem;
}

.folder-header-info {
    flex: 1;
    min-width: 0;
}

.folder-header-name {
    font-size: 1.2rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.folder-header-count {
    font-size: 0.78rem;
    color: var(--text-faint);
    margin-top: 2px;
}

.folder-close-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 600;
    flex-shrink: 0;
    transition: all 0.25s ease;
    -webkit-tap-highlight-color: transparent;
}

.folder-close-btn:hover {
    background: rgba(255, 255, 255, 0.16);
    transform: rotate(90deg);
}

.folder-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 1.1rem 0.5rem;
    justify-items: center;
    align-content: start;
    padding: 24px 16px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 179, 71, 0.5) transparent;
}

.folder-grid::-webkit-scrollbar {
    width: 5px;
}

.folder-grid::-webkit-scrollbar-thumb {
    background: rgba(255, 179, 71, 0.5);
    border-radius: 6px;
}

.folder-app {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: #fff;
    width: 100%;
    max-width: 98px;
    padding: 0.4rem 0.2rem;
    border-radius: 16px;
    animation: appIn 0.4s cubic-bezier(0.22, 1, 0.36, 1) backwards;
    transition: transform 0.25s ease, background 0.25s ease;
    -webkit-tap-highlight-color: transparent;
}

.folder-app:hover {
    background: rgba(255, 255, 255, 0.07);
    transform: translateY(-4px);
}

.folder-app:active {
    transform: scale(0.94);
}

.folder-app-tile {
    width: 62px;
    height: 62px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--tile-from, #ff8a5c), var(--tile-to, #ffc371));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 700;
    color: #fff;
    overflow: hidden;
    box-shadow: 0 10px 22px -10px rgba(0, 0, 0, 0.6),
                inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.folder-app-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.folder-app-tile.tile-game {
    font-size: 1.6rem;
}

.folder-app-name {
    font-size: 0.72rem;
    font-weight: 500;
    text-align: center;
    line-height: 1.2;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    max-width: 100%;
}

@keyframes appIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

/* ---------- États vide / chargement ---------- */

.glass-loader {
    grid-column: 1 / -1;
    border: 1px dashed var(--glass-border);
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.03);
}

.home-loading,
.home-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 3rem 2rem;
    color: var(--text-soft);
    font-size: 1.05rem;
    width: 100%;
}

.home-empty span {
    font-size: 3rem;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 3px solid rgba(255, 255, 255, 0.16);
    border-top-color: #ffb347;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ---------- Version ---------- */

.versionning {
    position: fixed;
    bottom: max(6px, env(safe-area-inset-bottom));
    left: 10px;
    z-index: 999;
    font-size: 0.65rem;
    color: var(--text-faint);
    letter-spacing: 0.5px;
    font-weight: 400;
    pointer-events: none;
    user-select: none;
}

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

@media (max-width: 700px) {
    .search-bar {
        top: max(10px, env(safe-area-inset-top));
        width: calc(100% - 20px);
        height: 46px;
    }

    .support-btn {
        display: none;
    }

    .search-results {
        position: fixed;
        top: calc(max(10px, env(safe-area-inset-top)) + 54px);
        left: 10px;
        right: 10px;
        max-height: calc(100vh - 90px);
        max-height: calc(100dvh - 90px);
    }

    .home-view {
        width: 94%;
        padding-top: calc(96px + env(safe-area-inset-top));
    }

    .home-header {
        margin-bottom: 1.6rem;
    }

    .category-grid {
        grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
        gap: 1.4rem 0.6rem;
    }

    .folder-tile {
        width: 92px;
        height: 92px;
        border-radius: 24px;
    }

    .mini-grid {
        width: 74px;
        height: 74px;
        gap: 4px;
    }

    .mini-tile {
        width: 22px;
        height: 22px;
        border-radius: 6px;
        font-size: 0.55rem;
    }

    .folder-name {
        font-size: 0.72rem;
    }

    .folder-overlay {
        padding: 12px;
        align-items: flex-end;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .folder-sheet {
        width: 100%;
        max-height: min(86vh, 640px);
        max-height: min(86dvh, 640px);
        border-radius: 28px;
    }

    .folder-header {
        padding: 16px 18px;
    }

    .folder-header-icon {
        width: 48px;
        height: 48px;
        border-radius: 14px;
    }

    .folder-header-name {
        font-size: 1.05rem;
    }

    .folder-grid {
        grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
        gap: 1rem 0.4rem;
        padding: 18px 12px;
    }

    .folder-app-tile {
        width: 56px;
        height: 56px;
        border-radius: 16px;
        font-size: 1.2rem;
    }

    .folder-app-tile.tile-game {
        font-size: 1.4rem;
    }

    .folder-app-name {
        font-size: 0.68rem;
    }
}

@media (max-width: 360px) {
    .category-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .folder-tile {
        width: 84px;
        height: 84px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .bg-aurora,
    .aurora-blob,
    .bokeh {
        animation: none;
    }
}