/* =========================================================================
   SERVORAPRISE ARCADE SYSTEM
   -------------------------------------------------------------------------
   PURPOSE: Complete Arcade feature (launcher, modal, games, HUD, mobile).
   OWNS: Everything related to the Arcade
   DOES NOT OWN: Navigation, global buttons, service cards
   ========================================================================= */

/* =========================================================
   25. SERVORAPRISE ARCADE SYSTEM
   Independent subsystem. All rules retained exactly.
   ========================================================= */

/* 25.1 Arcade floating launcher */
#sp-arcade-fab {
    position: fixed;
    right: 20px;
    bottom: 100px;
    z-index: 2147483000;
    width: 62px;
    height: 62px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #fff;
    background:
        linear-gradient(
            135deg,
            #ff8800,
            #ff3399 55%,
            #9900ff
        );
    box-shadow:
        0 10px 32px rgba(0, 0, 0, 0.38),
        0 0 28px rgba(255, 136, 0, 0.28);
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

#sp-arcade-fab:hover {
    transform: translateY(-3px) scale(1.05);
}

#sp-arcade-fab:active {
    transform: scale(0.94);
}

.sp-arcade-fab-icon {
    font-size: 26px;
    line-height: 1;
}

.sp-arcade-fab-label {
    position: absolute;
    right: 0;
    bottom: -17px;
    font-family: Arial, sans-serif;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 1.5px;
    opacity: 0.75;
}

/* 25.2 Arcade backdrop */
#sp-arcade-backdrop {
    position: fixed;
    inset: 0;
    z-index: 2147483001;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

#sp-arcade-backdrop[hidden] {
    display: none !important;
    /* Protected JS state */
}

/* 25.3 Arcade modal */
#sp-arcade-modal {
    position: fixed;
    inset: 2.5vh 2.5vw;
    z-index: 2147483002;
    max-width: 1280px;
    max-height: 95vh;
    margin: auto;
    overflow: auto;
    border-radius: 26px;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.6);
}

#sp-arcade-modal[hidden] {
    display: none !important;
}

/* 25.4 Arcade root + CSS variables */
#sp-arcade {
    --sp-orange: #ff8800;
    --sp-yellow: #ffcc33;
    --sp-pink: #ff3399;
    --sp-purple: #9900ff;
    --sp-blue: #0077ff;
    --sp-green: #00c977;
    --sp-bg: #07070a;
    --sp-panel: #111116;
    --sp-line: rgba(255, 255, 255, 0.12);
    --sp-text: #ffffff;
    --sp-muted: #a9a9b4;

    width: 100%;
    min-height: 620px;
    color: var(--sp-text);
    background:
        radial-gradient(
            circle at 15% 10%,
            rgba(255, 136, 0, 0.13),
            transparent 28%
        ),
        radial-gradient(
            circle at 85% 20%,
            rgba(153, 0, 255, 0.12),
            transparent 28%
        ),
        linear-gradient(
            135deg,
            #050507,
            #0d0d13 55%,
            #050507
        );
    border: 1px solid var(--sp-line);
    border-radius: 26px;
    overflow: hidden;
    font-family: Arial, Helvetica, sans-serif;
    position: relative;
    isolation: isolate;
}

#sp-arcade *,
#sp-arcade *::before,
#sp-arcade *::after {
    box-sizing: border-box;
}

/* 25.5 Arcade shell / header */
.sp-arcade-shell {
    max-width: 1200px;
    margin: auto;
    padding: 24px;
}

.sp-arcade-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--sp-line);
}

.sp-arcade-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sp-arcade-logo {
    width: 48px;
    height: 48px;
    border-radius: 15px;
    display: grid;
    place-items: center;
    font-size: 31px;
    font-weight: 900;
    font-style: italic;
    background:
        linear-gradient(
            135deg,
            var(--sp-orange),
            var(--sp-yellow) 45%,
            var(--sp-pink) 72%,
            var(--sp-purple)
        );
    color: #080808;
    box-shadow: 0 0 28px rgba(255, 136, 0, 0.25);
}

.sp-arcade-brand h1 {
    margin: 0;
    font-size: clamp(20px, 3vw, 30px);
}

.sp-arcade-brand p {
    margin: 3px 0 0;
    color: var(--sp-muted);
    font-size: 12px;
}

.sp-arcade-close {
    border: 1px solid var(--sp-line);
    background: #15151b;
    color: #fff;
    border-radius: 12px;
    padding: 10px 14px;
    cursor: pointer;
}

/* 25.6 Arcade home */
.sp-arcade-screen {
    padding-top: 24px;
}

.sp-arcade-screen[hidden] {
    display: none !important;
}

.sp-arcade-hero {
    text-align: center;
    padding: 28px 10px 20px;
}

.sp-arcade-hero h2 {
    margin: 0;
    font-size: clamp(32px, 7vw, 62px);
    line-height: 0.95;
    background:
        linear-gradient(
            90deg,
            var(--sp-orange),
            var(--sp-yellow),
            var(--sp-pink),
            var(--sp-purple)
        );
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.sp-arcade-hero p {
    max-width: 650px;
    margin: 14px auto;
    color: var(--sp-muted);
    line-height: 1.6;
}

/* 25.7 Game cards */
.sp-arcade-games {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}

.sp-arcade-card {
    text-align: left;
    background:
        linear-gradient(
            145deg,
            #131319,
            #0d0d11
        );
    color: #fff;
    border: 1px solid var(--sp-line);
    border-radius: 20px;
    padding: 20px;
    cursor: pointer;
    transition:
        transform 0.18s ease,
        border-color 0.18s ease,
        box-shadow 0.18s ease;
}

.sp-arcade-card:hover {
    transform: translateY(-4px);
    border-color: rgba(255, 136, 0, 0.65);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.35);
}

.sp-arcade-icon {
    font-size: 38px;
}

.sp-arcade-card h3 {
    margin: 10px 0 6px;
}

.sp-arcade-card p {
    color: var(--sp-muted);
    font-size: 13px;
    line-height: 1.5;
    margin: 0 0 8px;
}

.sp-card-best {
    font-size: 12px;
    color: #a9a9b4;
    margin: 6px 0 10px;
}

.sp-card-best strong {
    color: #ffcc33;
}

/* Later override using CSS variables */
.sp-card-best {
    font-size: 12px;
    color: var(--sp-muted);
    margin: 0 0 12px;
    font-family: Arial, sans-serif;
}

.sp-card-best strong {
    color: var(--sp-yellow);
    font-weight: 700;
}

.sp-arcade-play {
    display: inline-block;
    padding: 8px 12px;
    border-radius: 9px;
    background:
        linear-gradient(
            90deg,
            var(--sp-orange),
            var(--sp-pink)
        );
    font-weight: 700;
    font-size: 12px;
}

/* 25.8 Score */
.sp-arcade-total {
    margin-top: 18px;
    padding: 16px 18px;
    border: 1px solid var(--sp-line);
    border-radius: 16px;
    background: #0d0d12;
    display: flex;
    justify-content: space-between;
}

/* 25.9 Game header */
.sp-game-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.sp-game-title {
    margin: 0;
    font-size: clamp(22px, 5vw, 34px);
}

.sp-game-actions {
    display: flex;
    gap: 8px;
}

.sp-btn {
    border: 1px solid var(--sp-line);
    background: #15151b;
    color: #fff;
    border-radius: 10px;
    padding: 9px 12px;
    cursor: pointer;
}

.sp-btn-primary {
    background:
        linear-gradient(
            90deg,
            var(--sp-orange),
            var(--sp-pink)
        );
    border-color: transparent;
    font-weight: 700;
}

/* 25.10 HUD */
.sp-hud {
    display: flex;
    justify-content: space-around;
    gap: 8px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.55);
    border-bottom: 1px solid var(--sp-line);
}

.sp-hud div {
    text-align: center;
    min-width: 70px;
}

.sp-hud small {
    display: block;
    color: var(--sp-muted);
    font-size: 10px;
    text-transform: uppercase;
}

.sp-hud strong {
    font-size: 18px;
}

/* 25.11 Game boards */
.sp-game-board {
    position: relative;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    overflow: hidden;
    border: 1px solid var(--sp-line);
    border-radius: 20px;
    background: #080b12;
}

.sp-canvas {
    display: block;
    width: 100%;
    height: auto;
    touch-action: none;
}

.sp-game-help {
    text-align: center;
    color: var(--sp-muted);
    font-size: 12px;
    margin: 10px 0 0;
}

/* 25.12 Target game */
.sp-target-area {
    height: min(62vw, 560px);
    min-height: 360px;
    position: relative;
    background:
        radial-gradient(
            circle at 50% 50%,
            rgba(0, 119, 255, 0.12),
            transparent 42%
        ),
        linear-gradient(
            135deg,
            #080a11,
            #0b0d16
        );
    overflow: hidden;
    cursor: crosshair;
    touch-action: manipulation;
}

.sp-target {
    position: absolute;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: 5px solid #fff;
    background:
        radial-gradient(
            circle,
            #fff 0 12%,
            var(--sp-pink) 13% 38%,
            var(--sp-orange) 39% 65%,
            transparent 66%
        );
    transform: translate(-50%, -50%);
    cursor: pointer;
    box-shadow: 0 0 22px rgba(255, 51, 153, 0.65);
}

/* 25.13 Memory game */
.sp-memory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    max-width: 560px;
    margin: 0 auto;
}

.sp-memory-card {
    aspect-ratio: 1;
    background: #13131a;
    border: 1px solid var(--sp-line);
    border-radius: 15px;
    cursor: pointer;
    perspective: 700px;
}

.sp-memory-inner {
    width: 100%;
    height: 100%;
    transition: transform 0.3s;
    transform-style: preserve-3d;
}

.sp-memory-card.flipped .sp-memory-inner,
.sp-memory-card.matched .sp-memory-inner {
    transform: rotateY(180deg);
}

.sp-memory-face {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    border-radius: 15px;
    backface-visibility: hidden;
    font-size: 32px;
}

.sp-memory-back {
    background:
        linear-gradient(
            135deg,
            #15151c,
            #09090d
        );
}

.sp-memory-front {
    background:
        linear-gradient(
            135deg,
            #20100a,
            #1a0a1c
        );
    transform: rotateY(180deg);
}

.sp-memory-card.matched {
    border-color: var(--sp-green);
}

/* 25.14 Snake game */
.sp-snake-wrap {
    max-width: 620px;
    margin: auto;
}

.sp-snake-board {
    width: 100%;
    background: #070b0c;
    border: 1px solid var(--sp-line);
    border-radius: 16px;
    touch-action: none;
}

.sp-dpad {
    display: grid;
    grid-template-columns: repeat(3, 58px);
    gap: 6px;
    justify-content: center;
    margin: 14px auto 0;
}

.sp-dpad button {
    width: 58px;
    height: 46px;
    border-radius: 10px;
    border: 1px solid var(--sp-line);
    background: #15151b;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
}

.sp-dpad .empty {
    visibility: hidden;
}

/* 25.15 Merge game */
.sp-merge-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 7px;
    max-width: 420px;
    margin: 15px auto;
    background: #15151b;
    padding: 7px;
    border-radius: 12px;
}

.sp-merge-cell {
    aspect-ratio: 1;
    border-radius: 8px;
    display: grid;
    place-items: center;
    font-weight: 900;
    font-size: clamp(18px, 5vw, 28px);
    background: #26262d;
}

.sp-merge-cell[data-v="2"] { background: #8c551f; }
.sp-merge-cell[data-v="4"] { background: #9a6b21; }
.sp-merge-cell[data-v="8"] { background: #c34e1b; }
.sp-merge-cell[data-v="16"] { background: #d83d20; }
.sp-merge-cell[data-v="32"] { background: #d9255b; }
.sp-merge-cell[data-v="64"] { background: #9c25c9; }
.sp-merge-cell[data-v="128"] { background: #5e31d9; }
.sp-merge-cell[data-v="256"] { background: #315fd9; }
.sp-merge-cell[data-v="512"] { background: #1888d0; }
.sp-merge-cell[data-v="1024"] { background: #159d91; }
.sp-merge-cell[data-v="2048"] { background: #00b86b; }

/* 25.16 Results */
.sp-result {
    max-width: 520px;
    margin: 20px auto;
    padding: 26px;
    text-align: center;
    border: 1px solid var(--sp-line);
    border-radius: 20px;
    background: #101015;
}

.sp-result h3 {
    margin: 0 0 8px;
    font-size: 28px;
}

.sp-result-score {
    font-size: 46px;
    font-weight: 900;
    margin: 8px 0;
    background:
        linear-gradient(
            90deg,
            var(--sp-orange),
            var(--sp-pink)
        );
    -webkit-background-clip: text;
    color: transparent;
}

.sp-arcade-muted {
    color: var(--sp-muted);
}

/* 25.17 Arcade mobile */
@media (max-width: 600px) {
    #sp-arcade-fab {
        right: 14px;
        bottom: 90px;
        width: 56px;
        height: 56px;
    }

    #sp-arcade-modal {
        inset: 0;
        max-height: 100vh;
        border-radius: 0;
    }

    #sp-arcade {
        min-height: 100vh;
        border-radius: 0;
    }

    .sp-arcade-shell {
        padding: 15px;
    }

    .sp-arcade-games {
        grid-template-columns: 1fr 1fr;
    }

    .sp-arcade-card {
        padding: 15px;
    }

    .sp-memory-grid {
        gap: 7px;
    }

    .sp-target-area {
        min-height: 330px;
    }
}

@media (max-width: 420px) {
    .sp-arcade-games {
        grid-template-columns: 1fr;
    }

    .sp-arcade-card {
        padding: 17px;
    }
}

/* 25.18 Arcade touch controls */
.sp-canvas,
.sp-snake-board {
    display: block;
    width: 100%;
    max-width: 900px;
    height: auto;
    margin: 0 auto;
    touch-action: none;
    /* Required to prevent browser scroll/zoom interference during gameplay */
    user-select: none;
    -webkit-user-select: none;
}

.sp-game-board {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}


/* =========================================================
   26. ANIMATION SYSTEM
   ========================================================= */

.fade-slide {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s ease, transform 0.3s ease;
}

.fade-slide.visible {
    opacity: 1;
    transform: translateY(0);
    /* JS-controlled visibility class */
}