:root {
    --bg-color: #121212;
    --surface-color: #1e1e1e;
    --primary-color: #7c4dff;
    --primary-hover: #651fff;
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --accent-color: #00e676;
    --error-color: #ff5252;
    --glass-bg: rgba(30, 30, 30, 0.8);
    --border-radius: 12px;
    --spacing-md: 16px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: auto;
    /* Allow scrolling if content overflows */
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    padding: var(--spacing-md);
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
    padding: 0 var(--spacing-md);
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(45deg, var(--primary-color), var(--accent-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.status-bar {
    display: flex;
    gap: var(--spacing-md);
    font-size: 0.9rem;
}

.status {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--text-secondary);
}

.status.connected::before {
    background-color: var(--accent-color);
}

.status.disconnected::before {
    background-color: var(--error-color);
}

main {
    display: grid;
    grid-template-columns: 1fr 300px;
    grid-template-rows: 1fr;
    /* Ensure row fills available space */
    gap: var(--spacing-md);
    flex: 1;
    min-height: 0;
    /* Fix for grid overflow */
}

.game-container {
    background-color: #000;
    border-radius: var(--border-radius);
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    width: 100%;
    height: 100%;
    /* Fill the grid cell */
}

#emulator-wrapper {
    width: 100%;
    height: 100%;
    position: relative;
    /* overflow: hidden; Removed to allow scrolling if needed */
}

canvas,
video {
    display: block;
    width: 100% !important;
    height: 100% !important;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

#placeholder-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--surface-color);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    z-index: 10;
}

.content h2 {
    margin-bottom: 8px;
}

.content p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.file-upload-btn {
    background-color: var(--primary-color);
    color: white;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s;
    display: inline-block;
}

.file-upload-btn:hover {
    background-color: var(--primary-hover);
}

input[type="file"] {
    display: none;
}

.controls-panel {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.panel-section {
    background: var(--surface-color);
    padding: var(--spacing-md);
    border-radius: var(--border-radius);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

h3 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tabs {
    display: flex;
    margin-bottom: 12px;
    background: rgba(0, 0, 0, 0.2);
    padding: 4px;
    border-radius: 6px;
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 6px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.9rem;
}

.tab-btn.active {
    background: var(--primary-color);
    color: white;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.id-display {
    display: flex;
    gap: 8px;
    margin: 8px 0;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}

input[type="text"] {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    padding: 8px;
    border-radius: 4px;
    width: 100%;
    font-family: monospace;
}

button {
    background: var(--primary-color);
    border: none;
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
}

button:hover {
    background: var(--primary-hover);
}

.hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 8px;
}

.controls-list {
    list-style: none;
    font-size: 0.85rem;
}

.controls-list li {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.controls-list li:last-child {
    border-bottom: none;
}

.controls-list span:first-child {
    color: var(--text-secondary);
}

/* Game Bar */
#game-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
    backdrop-filter: blur(5px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    transition: opacity 0.3s ease-in-out;
}

#game-bar.hidden {
    display: none;
}

#game-bar.fade-out {
    opacity: 0;
    pointer-events: none;
}

.game-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.controls-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

.common-controls {
    display: flex;
    align-items: center;
}

/* Volume Control in Sidebar */
.volume-section .volume-control-panel {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.2);
    padding: 10px;
    border-radius: 8px;
}

.volume-section .volume-icon {
    font-size: 1.2rem;
}

#volume-slider {
    flex: 1;
    height: 12px;
    /* Taller track for easier touch */
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    outline: none;
    touch-action: none;
    /* Prevent scrolling while dragging */
}

#volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    /* Larger thumb */
    height: 24px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    transition: transform 0.1s, background 0.2s;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

#volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    background: var(--primary-hover);
}

#game-bar button {
    display: inline-block;
}

#current-rom-name {
    font-weight: 600;
    color: #e0e0e0;
}

#change-rom-btn {
    background: #4a4a4a;
    color: white;
    border: 1px solid #666;
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

#change-rom-btn:hover {
    background: #666;
}

#site-logo {
    width: 180px;
    height: 180px;
    object-fit: cover;
    margin: 0 auto var(--spacing-md) auto;
    display: block;
    border-radius: 50%;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    body {
        height: auto;
        overflow-y: auto;
    }

    #app {
        height: auto;
        padding: 10px;
    }

    header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
        margin-bottom: 10px;
    }

    main {
        grid-template-columns: 1fr;
        display: flex;
        flex-direction: column;
        gap: 20px;
    }

    .game-container {
        aspect-ratio: 4/3;
        width: 100%;
        height: auto;
    }

    .controls-panel {
        order: 2;
    }

    #game-bar {
        padding: 8px 10px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .game-controls {
        width: 100%;
        justify-content: space-between;
    }

    #current-rom-name {
        font-size: 0.9rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }

    /* Hide static controls info on mobile to save space */
    .settings-section,
    .volume-section {
        display: none;
    }

    /* Make logo much smaller on mobile and position top right */
    #site-logo {
        width: 40px;
        height: 40px;
        position: absolute;
        top: 15px;
        right: 15px;
        margin: 0;
        z-index: 100;
    }
}

/* Fullscreen specific styles */
:fullscreen #emulator-wrapper {
    background: black;
    display: flex;
    align-items: center;
    justify-content: center;
}

:fullscreen canvas,
:fullscreen video {
    max-height: 100vh;
    max-width: 100vw;
}