/*
 * CAACOTyping — XP desktop: mobile-style folders.
 *
 * Desktop folder icon = a frosted rounded tile holding a 2×2 preview of
 * the apps inside (iOS home-screen folder). Clicking it opens a blurred
 * sheet with the full app grid. The tile inherits the active theme via
 * the `.theme-*` class already on `.xp-desktop`, so the folder glass
 * re-tints when the user switches wallpaper.
 *
 * Layers: the sheet must sit above the wallpaper and the desktop icons
 * but below the taskbar chrome that owns its own stacking, so it uses a
 * z-index between `.xp-desktop__icons` (1) and the taskbar (2) — as a
 * child of `.xp-desktop` it inherits that stacking context.
 */

/* ---------- Desktop folder tile (preview) ---------- */
.xp-desktop__icon--folder .xp-desktop__icon-art {
    width: 60px;
    height: 60px;
}

.xp-folder__preview {
    position: relative;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 2px;
    width: 54px;
    height: 54px;
    padding: 4px;
    box-sizing: border-box;
    border-radius: 12px;
    background: linear-gradient(160deg, rgba(255,255,255,0.30), rgba(255,255,255,0.14));
    border: 1px solid rgba(255, 255, 255, 0.42);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.55),
        inset 0 -1px 2px rgba(0, 0, 0, 0.18),
        0 2px 5px rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(3px) saturate(130%);
    -webkit-backdrop-filter: blur(3px) saturate(130%);
    overflow: hidden;
}

.xp-folder__preview-app {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
    border-radius: 4px;
}

.xp-folder__preview-app svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* When the badge is showing it overlaps the 4th cell — the tile keeps
   its 2×2 shape so the silhouette stays identical folder to folder. */
/* Hidden by DEFAULT so a wrong "+N" can never flash before
   js/desktop-folders.js computes the real overflow (DOMContentLoaded can
   lag behind first paint). syncPreviews() unhides it when count > 4. */
.xp-folder__preview-more {
    position: absolute;
    right: 3px;
    bottom: 3px;
    min-width: 15px;
    height: 15px;
    padding: 0 3px;
    box-sizing: border-box;
    border-radius: 8px;
    background: rgba(18, 32, 62, 0.82);
    color: #fff;
    font-family: Tahoma, 'Microsoft Sans Serif', sans-serif;
    font-size: 9px;
    font-weight: 700;
    line-height: 15px;
    text-align: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    display: none;
}
.xp-folder__preview-more[hidden] { display: none; }
/* JS sets data-has-overflow once it knows the real count. */
.xp-folder__preview-more[data-has-overflow="1"] { display: block; }

/* A folder with ≤4 apps needs no badge. */
.xp-desktop__icon--folder[data-folder-count="3"] .xp-folder__preview-more,
.xp-desktop__icon--folder[data-folder-count="4"] .xp-folder__preview-more,
.xp-desktop__icon--folder[data-folder-count="1"] .xp-folder__preview-more,
.xp-desktop__icon--folder[data-folder-count="2"] .xp-folder__preview-more {
    display: none;
}

.xp-desktop__icon--folder:hover .xp-folder__preview {
    border-color: rgba(255, 255, 255, 0.75);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.7),
        inset 0 -1px 2px rgba(0, 0, 0, 0.16),
        0 4px 10px rgba(0, 0, 0, 0.38);
}

/* ---------- Folder overlay (open sheet) ---------- */
.xp-folder {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px 68px;   /* clear the taskbar */
    box-sizing: border-box;
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease;
}
.xp-folder[hidden] { display: none; }
.xp-folder.is-open {
    opacity: 1;
    pointer-events: auto;
}

/* Dim + desaturate the wallpaper behind the sheet, like a dimmed
   home screen. Radial wash keeps the wallpaper legible at the edges. */
.xp-folder::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, rgba(6, 16, 38, 0.52), rgba(3, 9, 24, 0.74));
    backdrop-filter: blur(6px) saturate(85%);
    -webkit-backdrop-filter: blur(6px) saturate(85%);
}

.xp-folder__sheet {
    position: relative;
    z-index: 1;
    width: min(560px, 100%);
    max-height: 100%;
    display: flex;
    flex-direction: column;
    border-radius: 20px;
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.11));
    border: 1px solid rgba(255, 255, 255, 0.38);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.5),
        0 18px 46px rgba(0, 0, 0, 0.52);
    backdrop-filter: blur(22px) saturate(160%);
    -webkit-backdrop-filter: blur(22px) saturate(160%);
    overflow: hidden;
    transform: translateY(10px) scale(0.975);
    opacity: 0;
    transition: transform 190ms cubic-bezier(0.22, 0.9, 0.3, 1), opacity 170ms ease;
}
.xp-folder.is-open .xp-folder__sheet {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.xp-folder__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 14px 10px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.18);
}

.xp-folder__title {
    margin: 0;
    color: #fff;
    font-family: Tahoma, 'Microsoft Sans Serif', sans-serif;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.65);
}

.xp-folder__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.34);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    cursor: pointer;
    transition: background-color 120ms ease, transform 120ms ease;
}
.xp-folder__close svg { width: 15px; height: 15px; display: block; }
.xp-folder__close:hover { background: rgba(255, 255, 255, 0.3); }
.xp-folder__close:active { transform: scale(0.92); }
.xp-folder__close:focus-visible {
    outline: 2px solid #ffd257;
    outline-offset: 2px;
}

.xp-folder__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 6px 4px;
    padding: 16px 14px 20px;
    overflow-y: auto;
    max-height: min(60vh, 460px);
    -webkit-overflow-scrolling: touch;
}

/* ---------- App inside the folder ---------- */
.xp-folder__app {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 9px 4px 10px;
    border: 1px dotted transparent;
    border-radius: 9px;
    background: transparent;
    color: #fff;
    font-family: inherit;
    text-align: center;
    cursor: pointer;
    transition: background-color 120ms ease, border-color 120ms ease, transform 120ms ease;
}
.xp-folder__app:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.45);
}
.xp-folder__app:active { transform: scale(0.95); }
.xp-folder__app:focus-visible {
    outline: 2px solid #ffd257;
    outline-offset: 1px;
}

.xp-folder__app-art {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    flex-shrink: 0;
}
.xp-folder__app-art svg {
    display: block;
    width: 46px;
    height: 46px;
    filter: drop-shadow(1px 1px 2px rgba(0, 0, 0, 0.55));
}

.xp-folder__app-label {
    display: block;
    width: 100%;
    font-size: 11.5px;
    line-height: 1.25;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
    overflow-wrap: break-word;
}

.xp-folder__app-hint {
    display: block;
    width: 100%;
    margin-top: 1px;
    font-size: 9.5px;
    line-height: 1.3;
    color: rgba(255, 255, 255, 0.78);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.xp-folder__empty {
    grid-column: 1 / -1;
    margin: 12px 6px;
    color: rgba(255, 255, 255, 0.86);
    font-family: Tahoma, 'Microsoft Sans Serif', sans-serif;
    font-size: 12px;
    line-height: 1.7;
    text-align: center;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

/* ---------- Theme adaptations ----------
   The sheet is neutral glass; these nudge the tint so each wallpaper
   reads correctly behind it. */

/* Win8 "simple" — flat, no blur-heavy chrome. */
.xp-desktop.theme-simple .xp-folder__preview {
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.22);
    border-color: rgba(255, 255, 255, 0.55);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}
.xp-desktop.theme-simple .xp-folder__sheet {
    border-radius: 6px;
    background: rgba(28, 46, 84, 0.86);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}
.xp-desktop.theme-simple .xp-folder::before { backdrop-filter: none; -webkit-backdrop-filter: none; }
.xp-desktop.theme-simple .xp-folder__app { border-radius: 3px; }

/* Harbour night — cooler, heavier glass so blue sky still reads. */
.xp-desktop.theme-harbour .xp-folder__sheet {
    background: linear-gradient(165deg, rgba(120, 190, 255, 0.20), rgba(20, 48, 92, 0.34));
    border-color: rgba(180, 220, 255, 0.4);
}

/* ---------- Small screens ---------- */
@media (max-width: 720px) {
    .xp-folder { padding: 24px 12px 56px; }
    .xp-folder__sheet { border-radius: 16px; }
    .xp-folder__grid { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); max-height: 62vh; }
    .xp-folder__app-art { width: 44px; height: 44px; }
    .xp-folder__app-art svg { width: 40px; height: 40px; }
    .xp-folder__app-label { font-size: 11px; }
}

@media (max-width: 900px) {
    .xp-desktop__icon--folder .xp-desktop__icon-art { width: 54px; height: 54px; }
    .xp-folder__preview { width: 50px; height: 50px; }
}

@media (prefers-reduced-motion: reduce) {
    .xp-folder,
    .xp-folder__sheet,
    .xp-folder__app { transition: none !important; }
}

/* ============================================================
   RETRO XP — classic (Luna) theme only
   ============================================================
   The base design is iOS-style frosted glass, which reads as macOS on a
   desktop that is otherwise unmistakably Windows XP. Under the
   `classic` theme we swap the folder chrome for the XP equivalents,
   keeping the same DOM and ids so js/desktop-folders.js needs no change:

     • tile      rounded frosted square -> flat yellow manila folder
     • sheet     big blurred glass pill  -> Luna blue Explorer window
                                           with a gradient title bar
     • close     round glass disc        -> flat square red ✕ button
     • app hover dotted glass tile      -> XP selection blue

   Scoped to .theme-classic so `simple` (Win8) and `harbour` keep the
   modern glass treatment.
   ============================================================ */

/* ---------- Retro tile: manila folder (compact) ---------- */
.xp-desktop.theme-classic .xp-desktop__icon--folder .xp-desktop__icon-art {
    width: 50px;
    height: 44px;
}

/* A real folder silhouette instead of a 2x2 glass grid. The app glyphs
   remain visible — they ride on the "papers" that stick out of the top
   of the folder, which is what makes the tile readable as "what's in
   here". A hidden preview (an earlier revision hid it) defeats the tile. */
.xp-desktop.theme-classic .xp-folder__preview {
    position: relative;
    width: 50px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 1px;
    overflow: visible;
    border-radius: 0;
    background: none;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

/* Folder tab: small raised block on the top-left edge. */
.xp-desktop.theme-classic .xp-folder__preview::before {
    content: '';
    position: absolute;
    left: 0;
    top: -7px;
    width: 22px;
    height: 8px;
    border: 1px solid #b5761a;
    border-bottom: none;
    border-radius: 3px 4px 0 0;
    background: linear-gradient(180deg, #ffe9a8, #fdc84c);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
    z-index: 2;
}

/* The manila body. Drawn as ::after so it can COVER the lower half of
   the glyphs, leaving just their tops peeking out like sheets of paper. */
.xp-desktop.theme-classic .xp-folder__preview::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 32px;
    border: 1px solid #b5761a;
    border-radius: 2px 2px 3px 3px;
    background: linear-gradient(170deg, #ffe08a 0%, #fdc84c 42%, #e8a521 100%);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.65),
        inset 0 -2px 3px rgba(120, 74, 8, 0.30),
        0 1px 2px rgba(0, 0, 0, 0.45);
    background-image:
        linear-gradient(180deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0) 55%),
        linear-gradient(170deg, #ffe08a 0%, #fdc84c 42%, #e8a521 100%);
    z-index: 1;
}

/* Glyphs sit BEHIND the folder face (z-index 0) so only their tops show.
   All four fit in a single strip across the "papers" — showing 2 of 4
   reads as broken rather than as a preview. 11px is small, but that is
   the honest trade at a 50px tile: a legible 2 looks like an oversight,
   whereas a complete row reads as "here is what is inside". */
.xp-desktop.theme-classic .xp-folder__preview-app {
    position: relative;
    z-index: 0;
    width: 11px;
    height: 11px;
    flex: 0 0 auto;
    display: block;
    margin-top: 1px;
}
.xp-desktop.theme-classic .xp-folder__preview-app svg {
    display: block;
    width: 11px;
    height: 11px;
    filter: drop-shadow(0 1px 1px rgba(90, 56, 6, 0.35));
}

/* Five or more would spill past the 50px face; the badge covers it. */
.xp-desktop.theme-classic .xp-folder__preview-app:nth-child(n+5) {
    display: none !important;
}

/* The "+N" badge keeps its place in the corner. */
.xp-desktop.theme-classic .xp-folder__preview-more {
    z-index: 3;
}

/* Hover lifts the whole tile — the folder body is a ::after now, so the
   highlight goes on the art box rather than the old background. */
.xp-desktop.theme-classic .xp-desktop__icon--folder:hover .xp-folder__preview {
    filter: brightness(1.06);
}
.xp-desktop.theme-classic .xp-desktop__icon--folder:hover .xp-folder__preview::after {
    background-image:
        linear-gradient(180deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0) 55%),
        linear-gradient(170deg, #ffe9a4 0%, #ffd45e 42%, #eeb02c 100%);
    border-color: #8a5a10;
}

/* ---------- Retro sheet: Luna blue Explorer window ---------- */
.xp-desktop.theme-classic .xp-folder::before {
    background: rgba(9, 22, 56, 0.55);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.xp-desktop.theme-classic .xp-folder__sheet {
    width: min(520px, 100%);
    border-radius: 7px 7px 4px 4px;
    border: 1px solid #0b3d91;
    border-top: none;
    background: #ece9d8;              /* Luna client area */
    box-shadow:
        0 10px 34px rgba(0, 0, 0, 0.62),
        inset 0 0 0 1px rgba(255, 255, 255, 0.55);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    transform: translateY(8px) scale(0.985);
}

/* Title bar — the Luna gradient. */
.xp-desktop.theme-classic .xp-folder__head {
    padding: 0;
    border-bottom: 1px solid #0b3d91;
    background: linear-gradient(180deg,
        #3a8ee6 0%, #1660d8 6%, #1f74e0 10%,
        #1a63d2 42%, #1558c4 88%, #1248a8 94%, #1a5fc4 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.xp-desktop.theme-classic .xp-folder__title {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 7px 10px;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.55);
}

/* Faux folder glyph in the title bar. */
.xp-desktop.theme-classic .xp-folder__title::before {
    content: '';
    width: 16px;
    height: 14px;
    flex: 0 0 auto;
    border: 1px solid #7a4c08;
    border-radius: 1px 2px 2px 2px;
    background: linear-gradient(170deg, #ffe08a, #f0a51c);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.xp-desktop.theme-classic .xp-folder__close {
    width: 24px;
    height: 21px;
    margin: 6px 7px 0 0;
    border-radius: 3px;
    border: 1px solid #0d3f8f;
    background: linear-gradient(180deg, #f0a878 0%, #dd7440 8%, #cf5c2c 45%, #b9441c 92%, #d4763f 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
    color: #fff;
}
.xp-desktop.theme-classic .xp-folder__close svg {
    width: 11px;
    height: 11px;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.5));
}
.xp-desktop.theme-classic .xp-folder__close:hover {
    background: linear-gradient(180deg, #ffb98e 0%, #e8834f 8%, #dc6a38 45%, #c44e22 92%, #dd7f48 100%);
}

/* ---------- Retro app tiles ---------- */
.xp-desktop.theme-classic .xp-folder__grid {
    padding: 12px 12px 16px;
    gap: 4px;
}

.xp-desktop.theme-classic .xp-folder__app {
    gap: 4px;
    padding: 7px 3px 8px;
    border: 1px solid transparent;
    border-radius: 2px;
    color: #1b1b1b;
}

/* Hover = XP selection blue with a dotted focus rect. */
.xp-desktop.theme-classic .xp-folder__app:hover {
    background: #316ac5;
    border: 1px dotted #ffd257;
    color: #fff;
}
.xp-desktop.theme-classic .xp-folder__app:hover .xp-folder__app-hint {
    color: rgba(255, 255, 255, 0.92);
    text-shadow: none;
}
.xp-desktop.theme-classic .xp-folder__app:active {
    background: #2a5cb0;
    transform: none;
}
.xp-desktop.theme-classic .xp-folder__app:focus-visible {
    outline: 1px dotted #ffd257;
    outline-offset: -3px;
}

.xp-desktop.theme-classic .xp-folder__app-art svg {
    filter: drop-shadow(1px 1px 1px rgba(0, 0, 0, 0.28));
}

.xp-desktop.theme-classic .xp-folder__app-label {
    color: #1b1b1b;
    text-shadow: none;
    font-size: 11px;
}
.xp-desktop.theme-classic .xp-folder__app:hover .xp-folder__app-label {
    color: #fff;
}

.xp-desktop.theme-classic .xp-folder__app-hint {
    color: #5a5a5a;
    text-shadow: none;
}

.xp-desktop.theme-classic .xp-folder__empty {
    color: #3a3a3a;
    text-shadow: none;
}

/* Retro scrollbar inside the sheet. */
.xp-desktop.theme-classic .xp-folder__grid::-webkit-scrollbar { width: 15px; }
.xp-desktop.theme-classic .xp-folder__grid::-webkit-scrollbar-track {
    background: #f2f0e6;
    border-left: 1px solid #d8d4c4;
}
.xp-desktop.theme-classic .xp-folder__grid::-webkit-scrollbar-thumb {
    border: 1px solid #7f9db9;
    border-radius: 0;
    background: linear-gradient(90deg, #cddcff, #9db8e8 60%, #7c9dd6);
}
.xp-desktop.theme-classic .xp-folder__grid::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(90deg, #e2ecff, #b6cbf0 60%, #93b0e2);
}

@media (max-width: 720px) {
    .xp-desktop.theme-classic .xp-folder__sheet { border-radius: 6px 6px 3px 3px; }
    .xp-desktop.theme-classic .xp-folder__grid {
        grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
    }
}