:root {
    --shell-primary: #2d1566;
    --shell-secondary: #3a1d80;
    --shell-highlight: #5533aa;
    --shell-dark: #1a0d3d;
    --bezel-dark: #0a0a12;
    --bezel-inner: #111118;
    --screen-off: #8b9b6e;
    --screen-bg: #0d1008;
    --btn-dark: #2a2a3e;
    --btn-pressed: #1a1a2e;
    --action-btn: #4a2d8c;
    --action-btn-pressed: #3a1d6c;
    --led-off: #1a3a1a;
    --led-on: #00ff44;
    --text-primary: #e0e0e0;
    --text-dim: #888;
    --accent: #9b6dff;
    --bg: #0e0a18;
    --bg-pattern: #120e20;
    --ctrl-bar-bg: #16112a;
    --debug-bg: #0d0a1a;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

body {
    font-family: 'IBM Plex Mono', monospace;
    background: var(--bg);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    background-image:
        radial-gradient(circle at 20% 50%, rgba(75, 40, 150, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 80% 50%, rgba(40, 30, 100, 0.06) 0%, transparent 50%),
        repeating-linear-gradient(0deg, transparent, transparent 30px, rgba(100, 60, 180, 0.02) 30px, rgba(100, 60, 180, 0.02) 31px),
        repeating-linear-gradient(90deg, transparent, transparent 30px, rgba(100, 60, 180, 0.02) 30px, rgba(100, 60, 180, 0.02) 31px);
}

#app-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}

/* ---- Header ---- */
#top-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: rgba(14, 10, 24, 0.9);
    border-bottom: 1px solid rgba(100, 60, 180, 0.15);
    backdrop-filter: blur(10px);
    z-index: 100;
}

.brand {
    font-family: 'Silkscreen', cursive;
    font-size: 18px;
    color: var(--accent);
    letter-spacing: 1px;
}

.top-controls {
    display: flex;
    gap: 8px;
}

.top-controls button {
    background: rgba(100, 60, 180, 0.15);
    border: 1px solid rgba(100, 60, 180, 0.3);
    color: var(--text-primary);
    padding: 6px 14px;
    border-radius: 6px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.top-controls button:hover {
    background: rgba(100, 60, 180, 0.3);
    border-color: var(--accent);
}

/* ---- Main ---- */
#main-area {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
    flex: 1;
    gap: 16px;
    width: 100%;
    max-width: 1400px;
}

/* ---- GBA Shell ---- */
#gba-shell {
    flex-shrink: 0;
}

.shoulder-buttons {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 30px;
    margin-bottom: -2px;
    position: relative;
    z-index: 2;
}

.shoulder-btn {
    background: linear-gradient(180deg, #3a2070 0%, #2a1555 100%);
    border: none;
    color: rgba(255,255,255,0.5);
    font-family: 'Silkscreen', cursive;
    font-size: 11px;
    padding: 6px 28px;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    transition: all 0.1s;
    box-shadow: 0 -2px 4px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.1);
}

.shoulder-btn:active, .shoulder-btn.pressed {
    background: linear-gradient(180deg, #2a1555 0%, #1a0d3d 100%);
    transform: translateY(2px);
    box-shadow: 0 -1px 2px rgba(0,0,0,0.3);
}

.cartridge-slot {
    background: linear-gradient(180deg, #1a0d3d 0%, #2d1566 100%);
    padding: 4px 20px;
    border-radius: 4px 4px 0 0;
    cursor: pointer;
    transition: all 0.3s;
    border: 1px solid rgba(100,60,180,0.2);
    border-bottom: none;
    position: relative;
}

.cartridge-slot:hover {
    background: linear-gradient(180deg, #2a1860 0%, #3a2080 100%);
    box-shadow: 0 0 15px rgba(100, 60, 180, 0.3);
}

.cartridge-label {
    font-family: 'Silkscreen', cursive;
    font-size: 9px;
    color: rgba(255,255,255,0.4);
    text-align: center;
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.shell-body {
    background: linear-gradient(145deg, #3a1d80 0%, #2d1566 30%, #251260 70%, #1a0d3d 100%);
    border-radius: 20px;
    padding: 20px 24px 16px;
    box-shadow:
        0 8px 32px rgba(0,0,0,0.5),
        0 2px 8px rgba(0,0,0,0.3),
        inset 0 1px 0 rgba(255,255,255,0.08),
        inset 0 -1px 0 rgba(0,0,0,0.3);
    position: relative;
}

/* ---- Screen ---- */
.screen-housing {
    margin-bottom: 16px;
}

.screen-text {
    font-family: 'Silkscreen', cursive;
    font-size: 10px;
    color: rgba(255,255,255,0.25);
    text-align: center;
    letter-spacing: 4px;
    margin-bottom: 6px;
    text-transform: uppercase;
}

.screen-bezel {
    background: var(--bezel-dark);
    border-radius: 10px;
    padding: 12px 16px 14px;
    box-shadow:
        inset 0 2px 8px rgba(0,0,0,0.8),
        inset 0 0 20px rgba(0,0,0,0.4),
        0 1px 0 rgba(255,255,255,0.05);
    position: relative;
}

.power-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 6px;
}

.power-indicator span {
    font-family: 'Silkscreen', cursive;
    font-size: 7px;
    color: rgba(255,255,255,0.2);
    text-transform: uppercase;
}

.power-led {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--led-off);
    transition: all 0.5s;
}

.power-led.on {
    background: var(--led-on);
    box-shadow: 0 0 6px var(--led-on), 0 0 12px rgba(0,255,68,0.3);
}

#gba-screen {
    display: block;
    width: 720px;
    height: 480px;
    background: var(--screen-bg);
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    border-radius: 2px;
}

/* ---- Controls area ---- */
.controls-area {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    margin-bottom: 10px;
}

/* D-Pad */
.dpad-container {
    position: relative;
    width: 120px;
    height: 120px;
}

.dpad {
    position: relative;
    width: 120px;
    height: 120px;
}

.dpad-btn {
    position: absolute;
    background: linear-gradient(180deg, #3a3a5c 0%, #2a2a42 100%);
    border: none;
    cursor: pointer;
    transition: all 0.08s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.08);
}

.dpad-btn:active, .dpad-btn.pressed {
    background: linear-gradient(180deg, #2a2a42 0%, #1e1e32 100%);
    box-shadow: 0 1px 2px rgba(0,0,0,0.4), inset 0 1px 2px rgba(0,0,0,0.3);
    transform: scale(0.96);
}

.dpad-up {
    width: 36px;
    height: 42px;
    left: 42px;
    top: 0;
    border-radius: 6px 6px 0 0;
}

.dpad-down {
    width: 36px;
    height: 42px;
    left: 42px;
    bottom: 0;
    border-radius: 0 0 6px 6px;
}

.dpad-left {
    width: 42px;
    height: 36px;
    left: 0;
    top: 42px;
    border-radius: 6px 0 0 6px;
}

.dpad-right {
    width: 42px;
    height: 36px;
    right: 0;
    top: 42px;
    border-radius: 0 6px 6px 0;
}

.dpad-center {
    position: absolute;
    width: 36px;
    height: 36px;
    left: 42px;
    top: 42px;
    background: #2e2e48;
    box-shadow: inset 0 0 4px rgba(0,0,0,0.3);
}

/* Action buttons */
.action-buttons {
    position: relative;
    width: 120px;
    height: 100px;
}

.action-btn {
    position: absolute;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    font-family: 'Silkscreen', cursive;
    font-size: 14px;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    transition: all 0.08s;
    box-shadow: 0 3px 6px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.1);
}

.btn-a {
    background: linear-gradient(145deg, var(--action-btn) 0%, #3a1d6c 100%);
    right: 0;
    top: 0;
}

.btn-b {
    background: linear-gradient(145deg, var(--action-btn) 0%, #3a1d6c 100%);
    left: 0;
    bottom: 0;
}

.action-btn:active, .action-btn.pressed {
    background: linear-gradient(145deg, var(--action-btn-pressed) 0%, #2a1050 100%);
    box-shadow: 0 1px 3px rgba(0,0,0,0.5), inset 0 1px 3px rgba(0,0,0,0.3);
    transform: scale(0.94);
}

/* Start/Select */
.start-select-area {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin-bottom: 8px;
}

.system-btn {
    background: linear-gradient(180deg, #4a4a68 0%, #3a3a55 100%);
    border: none;
    color: rgba(255,255,255,0.4);
    font-family: 'Silkscreen', cursive;
    font-size: 8px;
    padding: 5px 18px;
    border-radius: 10px;
    cursor: pointer;
    letter-spacing: 1px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.05);
    transition: all 0.08s;
}

.system-btn:active, .system-btn.pressed {
    background: linear-gradient(180deg, #3a3a55 0%, #2a2a3e 100%);
    box-shadow: 0 1px 2px rgba(0,0,0,0.3), inset 0 1px 2px rgba(0,0,0,0.3);
    transform: scale(0.96);
}

/* Speaker grille */
.speaker-grille {
    position: absolute;
    right: 30px;
    bottom: 20px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    transform: rotate(-30deg);
}

.speaker-hole {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: rgba(0,0,0,0.3);
    box-shadow: inset 0 1px 1px rgba(0,0,0,0.5);
}

/* ---- Control Bar ---- */
#control-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--ctrl-bar-bg);
    border-radius: 12px;
    margin-top: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    flex-wrap: wrap;
    justify-content: center;
}

.ctrl-btn {
    background: rgba(100, 60, 180, 0.15);
    border: 1px solid rgba(100, 60, 180, 0.25);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'IBM Plex Mono', monospace;
}

.ctrl-btn:hover {
    background: rgba(100, 60, 180, 0.3);
    border-color: var(--accent);
}

.ctrl-select {
    background: rgba(100, 60, 180, 0.15);
    border: 1px solid rgba(100, 60, 180, 0.25);
    color: var(--text-primary);
    padding: 6px 8px;
    border-radius: 6px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 13px;
    cursor: pointer;
}

.ctrl-select option {
    background: var(--bg);
}

.volume-ctrl {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
}

.volume-ctrl input[type="range"] {
    width: 80px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* ---- Debug Panel ---- */
#debug-panel {
    width: 360px;
    background: var(--debug-bg);
    border: 1px solid rgba(100, 60, 180, 0.2);
    border-radius: 12px;
    overflow: hidden;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    flex-shrink: 0;
}

#debug-panel.hidden {
    display: none;
}

.debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: rgba(100, 60, 180, 0.1);
    border-bottom: 1px solid rgba(100, 60, 180, 0.15);
    font-family: 'Silkscreen', cursive;
    font-size: 13px;
    color: var(--accent);
}

.debug-header button {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 16px;
}

.debug-content {
    padding: 10px;
}

.debug-section {
    margin-bottom: 12px;
}

.debug-section h3 {
    font-family: 'Silkscreen', cursive;
    font-size: 10px;
    color: var(--accent);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.debug-mono {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    line-height: 1.6;
    color: #aaa;
    white-space: pre;
    overflow-x: auto;
    background: rgba(0,0,0,0.2);
    padding: 6px 8px;
    border-radius: 6px;
    max-height: 160px;
    overflow-y: auto;
}

.debug-input {
    width: 100%;
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(100,60,180,0.2);
    color: var(--text-primary);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 4px;
    margin-bottom: 6px;
}

.debug-controls {
    display: flex;
    gap: 8px;
    padding-top: 8px;
}

/* ---- Shortcuts Overlay ---- */
#shortcuts-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#shortcuts-overlay.hidden {
    display: none;
}

.shortcuts-box {
    background: var(--debug-bg);
    border: 1px solid rgba(100,60,180,0.3);
    border-radius: 16px;
    padding: 24px 32px;
    max-width: 400px;
    width: 90%;
}

.shortcuts-box h2 {
    font-family: 'Silkscreen', cursive;
    font-size: 16px;
    color: var(--accent);
    margin-bottom: 16px;
    text-align: center;
}

.shortcut-grid {
    display: grid;
    gap: 8px;
    margin-bottom: 16px;
}

.shortcut-grid div {
    font-size: 13px;
    color: var(--text-dim);
}

kbd {
    background: rgba(100,60,180,0.2);
    border: 1px solid rgba(100,60,180,0.3);
    border-radius: 4px;
    padding: 2px 8px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    color: var(--accent);
    margin-right: 8px;
}

.shortcuts-box button {
    display: block;
    margin: 0 auto;
    background: var(--action-btn);
    border: none;
    color: white;
    padding: 8px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Silkscreen', cursive;
}

/* ---- Footer ---- */
#app-footer {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    padding: 12px 20px;
    font-size: 11px;
    color: var(--text-dim);
    border-top: 1px solid rgba(100,60,180,0.1);
}

#app-footer a {
    color: var(--accent);
    text-decoration: none;
    opacity: 0.7;
    transition: opacity 0.2s;
}

#app-footer a:hover {
    opacity: 1;
}

/* ---- Drag & Drop ---- */
.drag-over .cartridge-slot {
    background: linear-gradient(180deg, #3a2080 0%, #4a30a0 100%) !important;
    box-shadow: 0 0 25px rgba(155, 109, 255, 0.5) !important;
}

.drag-over .cartridge-label {
    color: rgba(255,255,255,0.8) !important;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(100,60,180,0.3);
    border-radius: 3px;
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
    #main-area {
        flex-direction: column;
        align-items: center;
        padding: 10px;
    }

    #gba-screen {
        width: 100%;
        max-width: 480px;
        height: auto;
        aspect-ratio: 240/160;
    }

    .shell-body {
        padding: 14px 16px 12px;
    }

    .controls-area {
        padding: 0 10px;
    }

    .dpad-container, .dpad {
        width: 100px;
        height: 100px;
    }

    .dpad-up { width: 30px; height: 36px; left: 35px; }
    .dpad-down { width: 30px; height: 36px; left: 35px; }
    .dpad-left { width: 36px; height: 30px; top: 35px; }
    .dpad-right { width: 36px; height: 30px; top: 35px; }
    .dpad-center { width: 30px; height: 30px; left: 35px; top: 35px; }

    .action-buttons { width: 100px; height: 86px; }
    .action-btn { width: 42px; height: 42px; }

    #debug-panel {
        width: 100%;
        max-height: 400px;
    }

    #control-bar {
        width: 100%;
    }

    .shoulder-buttons {
        padding: 0 16px;
    }
}

@media (max-width: 500px) {
    #gba-screen {
        max-width: 360px;
    }

    .screen-bezel {
        padding: 8px 10px 10px;
    }

    .shell-body {
        border-radius: 14px;
        padding: 10px 12px 10px;
    }
}