* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    touch-action: manipulation;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    margin: 0;
}

.container {
    text-align: center;
}

.gamepad {
    background: linear-gradient(135deg, #34495e 0%, #2c3e50 50%, #1a252f 100%);
    border-radius: clamp(40px, 6vw, 80px) clamp(40px, 6vw, 80px) clamp(50px, 8vw, 100px) clamp(50px, 8vw, 100px);
    padding: clamp(40px, 5vw, 80px) clamp(50px, 6vw, 100px);
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.4),
        inset 0 -3px 15px rgba(0, 0, 0, 0.3),
        inset 0 3px 15px rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: clamp(60px, 10vw, 160px);
    width: 90vw;
    max-width: 1200px;
    margin: 0 auto;
    position: relative;
}

.gamepad::before {
    content: '';
    position: absolute;
    top: 50%;
    left: -2%;
    right: -2%;
    height: 60%;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 50%;
    transform: translateY(-50%);
    z-index: -1;
    filter: blur(10px);
}

.gamepad::after {
    content: '';
    position: absolute;
    top: clamp(15px, 2vw, 30px);
    left: 50%;
    transform: translateX(-50%);
    width: clamp(60px, 8vw, 120px);
    height: clamp(4px, 0.5vw, 8px);
    background: rgba(255, 255, 255, 0.1);
    border-radius: clamp(2px, 0.25vw, 4px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Gamepad transparency when Bluetooth controller is connected */
.gamepad.controller-connected {
    background: linear-gradient(135deg, rgba(52, 73, 94, 0.1) 0%, rgba(44, 62, 80, 0.1) 50%, rgba(26, 37, 47, 0.1) 100%);
    transition: background 0.5s ease;
}

.gamepad.controller-connected::before {
    opacity: 0.1;
}

.gamepad.controller-connected::after {
    opacity: 0.1;
}

.gamepad.controller-connected .dpad-btn:not(.active-pressed),
.gamepad.controller-connected .play-btn:not(.active-pressed) {
    opacity: 0.1;
    transition: opacity 0.5s ease;
}

.gamepad.controller-connected .dpad-center {
    opacity: 0.1;
    transition: opacity 0.5s ease;
}

.gamepad.controller-connected .dpad::before,
.gamepad.controller-connected .play-button-container::before {
    opacity: 0.05;
}

/* Button highlight effect when pressed via Bluetooth controller */
.dpad-btn.active-pressed {
    background: linear-gradient(145deg, #3498db, #2980b9) !important;
    color: white !important;
    transform: scale(1.05) !important;
    box-shadow:
        0 0 40px rgba(52, 152, 219, 1),
        0 0 80px rgba(52, 152, 219, 0.6),
        inset 0 0 20px rgba(255, 255, 255, 0.3) !important;
    opacity: 1 !important;
    transition: all 0.05s ease !important;
    border: 3px solid rgba(255, 255, 255, 0.8) !important;
    z-index: 10;
}

.play-btn.active-pressed {
    background: linear-gradient(145deg, #ff3838, #ff1744) !important;
    box-shadow:
        0 0 50px rgba(255, 23, 68, 1),
        0 0 100px rgba(255, 23, 68, 0.6),
        inset 0 0 30px rgba(255, 255, 255, 0.3) !important;
    transform: scale(1.1) !important;
    opacity: 1 !important;
    transition: all 0.05s ease !important;
    border: 4px solid rgba(255, 255, 255, 0.9) !important;
    z-index: 10;
}

/* D-Pad Styles */
.dpad {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.dpad::before {
    content: '';
    position: absolute;
    width: 120%;
    height: 120%;
    background:
        radial-gradient(circle at 30% 30%, rgba(0, 0, 0, 0.1) 2px, transparent 2px),
        radial-gradient(circle at 70% 30%, rgba(0, 0, 0, 0.1) 2px, transparent 2px),
        radial-gradient(circle at 30% 70%, rgba(0, 0, 0, 0.1) 2px, transparent 2px),
        radial-gradient(circle at 70% 70%, rgba(0, 0, 0, 0.1) 2px, transparent 2px);
    background-size: clamp(12px, 1.5vw, 20px) clamp(12px, 1.5vw, 20px);
    border-radius: 50%;
    z-index: -1;
    opacity: 0.5;
}

.dpad-middle {
    display: flex;
    align-items: center;
}

.dpad-btn {
    width: clamp(80px, 10vw, 160px);
    height: clamp(80px, 10vw, 160px);
    background: #34495e;
    border: none;
    cursor: pointer;
    color: #95a5a6;
    transition: all 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
}

.dpad-btn:hover {
    background: #4a5f7f;
    color: #ecf0f1;
}

.dpad-btn:active {
    background: #5dade2;
    color: white;
    transform: scale(0.95);
}

.dpad-up {
    border-radius: clamp(15px, 2vw, 30px) clamp(15px, 2vw, 30px) 0 0;
}

.dpad-down {
    border-radius: 0 0 clamp(15px, 2vw, 30px) clamp(15px, 2vw, 30px);
}

.dpad-left {
    border-radius: clamp(15px, 2vw, 30px) 0 0 clamp(15px, 2vw, 30px);
}

.dpad-right {
    border-radius: 0 clamp(15px, 2vw, 30px) clamp(15px, 2vw, 30px) 0;
}

.dpad-center {
    width: clamp(60px, 7vw, 120px);
    height: clamp(60px, 7vw, 120px);
    background: #1a252f;
    border-radius: clamp(8px, 1vw, 15px);
}

.dpad-btn svg {
    width: clamp(40px, 5vw, 80px);
    height: clamp(40px, 5vw, 80px);
}

/* Play Button Styles */
.play-button-container {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.play-button-container::before {
    content: '';
    position: absolute;
    width: 140%;
    height: 140%;
    background:
        radial-gradient(circle at 30% 30%, rgba(0, 0, 0, 0.1) 2px, transparent 2px),
        radial-gradient(circle at 70% 30%, rgba(0, 0, 0, 0.1) 2px, transparent 2px),
        radial-gradient(circle at 30% 70%, rgba(0, 0, 0, 0.1) 2px, transparent 2px),
        radial-gradient(circle at 70% 70%, rgba(0, 0, 0, 0.1) 2px, transparent 2px);
    background-size: clamp(12px, 1.5vw, 20px) clamp(12px, 1.5vw, 20px);
    border-radius: 50%;
    z-index: -1;
    opacity: 0.5;
}

.play-btn {
    width: clamp(100px, 12vw, 200px);
    height: clamp(100px, 12vw, 200px);
    border-radius: 50%;
    background: linear-gradient(145deg, #e74c3c, #c0392b);
    border: none;
    cursor: pointer;
    color: white;
    box-shadow: 0 8px 20px rgba(231, 76, 60, 0.4);
    transition: all 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
}

.play-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 25px rgba(231, 76, 60, 0.5);
}

.play-btn:active {
    transform: scale(0.95);
    box-shadow: 0 5px 15px rgba(231, 76, 60, 0.4);
}

.play-btn svg {
    width: clamp(40px, 5vw, 80px);
    height: clamp(40px, 5vw, 80px);
    margin-left: clamp(3px, 0.5vw, 6px);
}

/* Mobile-specific styles for full background coverage */
@media (pointer: coarse) {
    html, body {
        width: 100%;
        height: 100%;
        position: fixed;
        overflow: hidden;
    }

    body {
        padding: 10px;
    }

    .gamepad {
        width: 85vw;
    }
}

/* Mobile landscape - make gamepad fit better accounting for browser chrome */
@media (orientation: landscape) and (pointer: coarse) {
    body {
        padding: 5px;
        /* Use svh (small viewport height) which accounts for browser UI */
        min-height: 100svh;
    }

    .gamepad {
        width: 75vw;
        max-height: 90svh;
    }
}

/* Rotate gamepad 90 degrees in portrait mode on mobile devices only */
@media (orientation: portrait) and (pointer: coarse) {
    body {
        padding: 0;
    }

    .container {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%) rotate(90deg);
    }

    .gamepad {
        /* Use svh (small viewport height) as width since rotated - accounts for browser UI */
        width: 75svh;
        max-width: none;
    }
}
