* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Ubuntu', 'Cantarell', 'Segoe UI', Roboto, sans-serif;
    background: #2c2c2c;
    color: #ececec;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.dashboard-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: calc(0.75rem + env(safe-area-inset-top, 0px)) calc(1.25rem + env(safe-area-inset-right, 0px)) 0.75rem calc(1.25rem + env(safe-area-inset-left, 0px));
    background: #242424;
    border-bottom: 1px solid #3d3d3d;
    flex-shrink: 0;
}

.dashboard-header h1 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 500;
    color: #fff;
    white-space: nowrap;
}

.dashboard-header .version {
    font-size: 0.65rem;
    opacity: 0.55;
    font-weight: 400;
}

.dashboard-search-wrap {
    flex: 1;
    max-width: 420px;
    margin: 0 auto;
}

.dashboard-search {
    width: 100%;
    padding: 0.55rem 1rem 0.55rem 2.4rem;
    border: none;
    border-radius: 6px;
    background: #3d3d3d url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23999' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.857 1.156a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E") no-repeat 0.75rem center;
    color: #ececec;
    font-size: 0.95rem;
    outline: none;
}

.dashboard-search:focus {
    background-color: #454545;
    box-shadow: 0 0 0 2px rgba(233, 84, 32, 0.45);
}

.dashboard-search::placeholder {
    color: #888;
}

.dashboard-profile-toggle {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    padding: 2px;
    border-radius: 999px;
    border: 1px solid #4a4a4a;
    background: #1f1f1f;
    gap: 0;
}

.dashboard-profile-btn {
    border: 0;
    background: transparent;
    color: #999;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    cursor: pointer;
    font-family: inherit;
}

.dashboard-profile-btn.is-active {
    background: #e95420;
    color: #fff;
}

.dashboard-profile-btn:focus-visible {
    outline: 2px solid rgba(233, 84, 32, 0.7);
    outline-offset: 1px;
}

@media (max-width: 720px) {
    .dashboard-header {
        flex-wrap: wrap;
    }

    .dashboard-search-wrap {
        order: 3;
        flex: 1 1 100%;
        max-width: none;
        margin: 0;
    }

    .dashboard-profile-toggle {
        margin-left: auto;
    }
}

.dashboard-main {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 2rem 1rem;
}

.app-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.5rem 0.75rem;
    max-width: 1100px;
    margin: 0 auto;
}

/* Desktop (fine pointer): use the full window width so long groups like Nexus
   stay on fewer rows when maximised / full screen. Touch / phone keep the
   narrower centred column. */
@media (min-width: 1200px) and (pointer: fine) {
    .app-grid {
        max-width: none;
        width: 100%;
    }

    html.dashboard-retro-covers .app-grid.retro-cover-grid {
        max-width: none;
        width: 100%;
    }
}

.app-group-heading {
    grid-column: 1 / -1;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #888;
    margin: 1rem 0 0.25rem;
    padding-left: 0.25rem;
}

.app-group-heading:first-child {
    margin-top: 0;
}

.app-group-heading.drag-over {
    color: #4dabf7;
    background: rgba(77, 171, 247, 0.08);
    border-radius: 4px;
}

.dashboard-drag-ghost {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 10000;
    pointer-events: none;
    opacity: 1;
    transform-origin: top left;
    filter: drop-shadow(0 10px 28px rgba(0, 0, 0, 0.5));
    cursor: grabbing;
    transition: none !important;
    will-change: transform;
}

.app-tile.app-tile-placeholder {
    opacity: 0.32;
    filter: grayscale(0.4) brightness(0.85);
    border: none;
    background: transparent;
    box-shadow: none;
    pointer-events: none;
    cursor: default;
}

body.dashboard-drag-active .app-tile {
    transition: transform 0.12s ease;
}

.app-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.45rem;
    padding: 0.65rem 0.35rem;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    cursor: grab;
    text-align: center;
    transition: background 0.15s, opacity 0.15s, transform 0.15s;
    touch-action: none;
    user-select: none;
}

.app-tile:active {
    cursor: grabbing;
}

.app-tile.drag-over {
    background: rgba(77, 171, 247, 0.15);
    box-shadow: inset 0 0 0 2px rgba(77, 171, 247, 0.55);
}

body.dashboard-drag-active {
    cursor: grabbing;
}

body.dashboard-drag-active .app-tile-icon,
body.dashboard-drag-active .app-tile-icon-fallback,
body.dashboard-drag-active .app-tile-name {
    pointer-events: none;
}

.app-tile:hover,
.app-tile:focus-visible {
    background: rgba(255, 255, 255, 0.08);
    outline: none;
}

.app-tile.selected {
    background: rgba(233, 84, 32, 0.18);
    box-shadow: inset 0 0 0 1px rgba(233, 84, 32, 0.5);
}

.app-tile-icon {
    width: 64px;
    height: 64px;
    border-radius: 14px;
    object-fit: cover;
    display: block;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.app-tile-icon-fallback {
    width: 64px;
    height: 64px;
    border-radius: 14px;
    background: linear-gradient(145deg, #4dabf7, #228be6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.app-tile-name {
    font-size: 0.78rem;
    line-height: 1.25;
    color: #ddd;
    max-width: 100%;
    word-wrap: break-word;
}

.app-tile.hidden {
    display: none;
}

.app-group-heading.hidden {
    display: none;
}

.no-results {
    grid-column: 1 / -1;
    text-align: center;
    color: #888;
    padding: 3rem 1rem;
    font-size: 0.95rem;
    display: none;
}

.no-results.visible {
    display: block;
}

.dashboard-footer {
    flex-shrink: 0;
    background: #242424;
    border-top: 1px solid #3d3d3d;
    padding: 0.85rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    min-height: 72px;
}

.dashboard-footer-info {
    flex: 1;
    min-width: 0;
}

.dashboard-footer-info h2 {
    margin: 0 0 0.2rem;
    font-size: 0.95rem;
    font-weight: 500;
    color: #fff;
}

.dashboard-footer-info p {
    margin: 0;
    font-size: 0.82rem;
    line-height: 1.4;
    color: #aaa;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.dashboard-footer-actions {
    flex-shrink: 0;
}

.btn-run {
    padding: 0.45rem 1.25rem;
    border: none;
    border-radius: 6px;
    background: #e95420;
    color: #fff;
    font-size: 0.9rem;
    cursor: pointer;
    font-weight: 500;
}

.btn-run:hover:not(:disabled) {
    background: #ff6a33;
}

.btn-run:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

@media (max-width: 768px), (pointer: coarse) {
    .dashboard-footer {
        padding-bottom: calc(0.85rem + env(safe-area-inset-bottom, 0px));
    }
}

/* Touch-primary dashboard: open on pointerup (iOS often skips click with touch-action:none). */
html.dashboard-touch-primary .app-tile {
    cursor: pointer;
    touch-action: manipulation;
}

html.dashboard-touch-primary .app-tile:active {
    cursor: pointer;
}

html.dashboard-touch-primary .app-tile-icon,
html.dashboard-touch-primary .app-tile-icon-fallback,
html.dashboard-touch-primary .app-tile-name {
    pointer-events: none;
}

/* Retro Games: LaunchBox / EmulationStation style cover explorer */
html.dashboard-retro-covers .app-grid.retro-cover-grid {
    grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
    gap: 1.15rem 1.1rem;
    max-width: 1180px;
}

html.dashboard-retro-covers .app-group-heading {
    margin: 1.35rem 0 0.55rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid #3a3a3a;
    letter-spacing: 0.12em;
    color: #9a9a9a;
}

html.dashboard-retro-covers .retro-cover-tile {
    align-items: stretch;
    gap: 0.5rem;
    padding: 0;
    text-align: left;
    cursor: pointer;
}

html.dashboard-retro-covers .retro-cover-tile.selected {
    background: transparent;
}

html.dashboard-retro-covers .retro-cover-sleeve {
    position: relative;
    aspect-ratio: auto;
    min-height: 150px;
    border-radius: 0;
    overflow: visible;
    background: transparent;
    box-shadow: none;
    transition: transform 0.16s ease;
    display: flex;
    align-items: stretch;
    justify-content: center;
    color: #888;
    font-size: 2rem;
    padding: 0;
    box-sizing: border-box;
}

html.dashboard-retro-covers .retro-cover-tile:hover .retro-cover-sleeve,
html.dashboard-retro-covers .retro-cover-tile:focus-visible .retro-cover-sleeve,
html.dashboard-retro-covers .retro-cover-tile.selected .retro-cover-sleeve {
    transform: translateY(-5px) scale(1.02);
}

html.dashboard-retro-covers .retro-cover-tile:hover .media-shell,
html.dashboard-retro-covers .retro-cover-tile:focus-visible .media-shell,
html.dashboard-retro-covers .retro-cover-tile.selected .media-shell {
    box-shadow: 0 18px 34px rgba(0, 0, 0, 0.55), 0 0 0 2px rgba(233, 84, 32, 0.55);
}

html.dashboard-retro-covers .media-shell {
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    transition: box-shadow 0.16s ease;
}

html.dashboard-retro-covers .media-label {
    position: relative;
    overflow: hidden;
    background: #0d0d0d;
    display: flex;
    align-items: center;
    justify-content: center;
}

html.dashboard-retro-covers .retro-cover-art {
    width: 100%;
    height: auto;
    max-width: 100%;
    max-height: none;
    object-fit: contain;
    object-position: center center;
    display: block;
    pointer-events: none;
    border-radius: 0;
}

/* —— Cartridge (N64 / GBA / SNES / Genesis) —— */
html.dashboard-retro-covers .media-cartridge .media-shell {
    background: linear-gradient(180deg, #6a6e74 0%, #4a4e54 18%, #3a3e44 100%);
    border-radius: 10px 10px 6px 6px;
    padding: 10px 10px 0;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.28),
        inset 0 -2px 0 rgba(0, 0, 0, 0.35),
        0 12px 22px rgba(0, 0, 0, 0.4);
    border: 1px solid #2a2c30;
}
html.dashboard-retro-covers .media-cartridge .media-shell::before {
    content: '';
    position: absolute;
    left: 4px;
    right: 4px;
    top: 4px;
    height: 5px;
    border-radius: 3px;
    background: repeating-linear-gradient(
        90deg,
        rgba(0, 0, 0, 0.22) 0 3px,
        rgba(255, 255, 255, 0.08) 3px 6px
    );
    pointer-events: none;
}
html.dashboard-retro-covers .media-cartridge .media-label {
    margin-top: 4px;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.45);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
    background: #111;
}
html.dashboard-retro-covers .media-cartridge .media-cart-connector {
    height: 14px;
    margin: 8px 18px 0;
    border-radius: 0 0 4px 4px;
    background: linear-gradient(180deg, #1a1a1a, #0a0a0a);
    box-shadow: inset 0 2px 3px rgba(255, 255, 255, 0.08);
    position: relative;
}
html.dashboard-retro-covers .media-cartridge .media-cart-connector::before,
html.dashboard-retro-covers .media-cartridge .media-cart-connector::after {
    content: '';
    position: absolute;
    top: 3px;
    bottom: 3px;
    width: 28%;
    background: repeating-linear-gradient(
        90deg,
        #c9a227 0 2px,
        #1a1a1a 2px 4px
    );
    opacity: 0.85;
}
html.dashboard-retro-covers .media-cartridge .media-cart-connector::before { left: 10%; }
html.dashboard-retro-covers .media-cartridge .media-cart-connector::after { right: 10%; }

/* —— Cassette (ZX Spectrum) —— */
html.dashboard-retro-covers .media-cassette .media-shell {
    background: linear-gradient(160deg, #2b2b2b, #151515 55%, #0e0e0e);
    border-radius: 8px;
    padding: 9px 9px 8px;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.16),
        0 12px 22px rgba(0, 0, 0, 0.45);
    border: 1px solid #333;
}
html.dashboard-retro-covers .media-cassette .media-label {
    border-radius: 3px;
    border: 1px solid #000;
    background: #f4f0e6;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}
html.dashboard-retro-covers .media-cassette .media-cassette-window {
    margin-top: 8px;
    height: 34px;
    border-radius: 3px;
    background: linear-gradient(180deg, #1c2430, #0b1018);
    border: 1px solid #000;
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0 12px;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
html.dashboard-retro-covers .media-cassette .media-reel {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background:
        radial-gradient(circle at center, #222 0 28%, transparent 29%),
        repeating-conic-gradient(from 0deg, #666 0deg 18deg, #333 18deg 36deg);
    box-shadow: inset 0 0 0 2px #111, 0 0 0 1px #555;
}

/* —— Disc / jewel case (PlayStation) —— */
html.dashboard-retro-covers .media-disc .media-shell {
    background: linear-gradient(145deg, rgba(220, 230, 240, 0.18), rgba(40, 50, 60, 0.55));
    border-radius: 6px;
    padding: 7px;
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.28),
        0 12px 24px rgba(0, 0, 0, 0.42);
    border: 1px solid rgba(180, 200, 220, 0.25);
}
html.dashboard-retro-covers .media-disc .media-label {
    border-radius: 2px;
    background: #111;
    overflow: hidden;
}
html.dashboard-retro-covers .media-disc .media-disc-hub {
    pointer-events: none;
    position: absolute;
    width: 28%;
    aspect-ratio: 1;
    left: 50%;
    top: 58%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background:
        radial-gradient(circle at center, rgba(20, 20, 20, 0.92) 0 18%, transparent 19%),
        radial-gradient(circle at center, transparent 0 34%, rgba(255, 255, 255, 0.12) 35% 36%, transparent 37%),
        conic-gradient(from 0deg, rgba(180, 210, 230, 0.08), rgba(255, 255, 255, 0.2), rgba(180, 210, 230, 0.08));
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15);
    opacity: 0.55;
    mix-blend-mode: screen;
}

html.dashboard-retro-covers .retro-cover-sleeve.is-missing .media-label {
    min-height: 140px;
    font-size: 2.2rem;
    color: #777;
}

html.dashboard-retro-covers .retro-cover-art {
    width: 100%;
    height: auto;
    max-width: 100%;
    max-height: none;
    object-fit: contain;
    object-position: center center;
    display: block;
    pointer-events: none;
    border-radius: 0;
}

html.dashboard-retro-covers .retro-cover-name {
    font-size: 0.78rem;
    line-height: 1.25;
    color: #ddd;
    min-height: 2.4em;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

html.dashboard-retro-covers .retro-cover-meta {
    font-size: 0.68rem;
    color: #777;
    margin-top: -0.15rem;
}

html.dashboard-touch-primary .retro-cover-sleeve,
html.dashboard-touch-primary .retro-cover-name,
html.dashboard-touch-primary .retro-cover-meta {
    pointer-events: none;
}
