/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #1a1a24;
    --bg-hover: #252532;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #27272a;
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

.app {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-radius: 16px;
    margin-bottom: 24px;
    border: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 28px;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.5px;
}

/* System Dropdown */
.system-dropdown {
    position: relative;
}

.dropdown-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 200px;
    justify-content: space-between;
}

.dropdown-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 12px;
    min-width: 320px;
    max-height: 500px;
    overflow-y: auto;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 100;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.dropdown-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

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

.dropdown-section:last-child {
    margin-bottom: 0;
}

.dropdown-label {
    display: block;
    padding: 8px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: left;
}

.dropdown-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.dropdown-item.active {
    background: var(--accent);
    color: white;
}

.system-icon {
    font-size: 1.2rem;
    width: 24px;
    text-align: center;
}

/* Main Layout */
.main {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 24px;
    flex: 1;
}

/* Screen Section */
.screen-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.screen-container {
    position: relative;
    background: var(--bg-secondary);
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--border);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 500px;
    flex: 1;
}

#gameCanvas {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    max-width: 100%;
    max-height: 70vh;
    display: block;
}

.screen-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--bg-secondary);
    z-index: 10;
}

.screen-overlay.hidden {
    display: none;
}

.upload-area {
    text-align: center;
    padding: 48px;
    border: 2px dashed var(--border);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 400px;
}

.upload-area:hover {
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.05);
}

.upload-area.dragover {
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.1);
}

.upload-icon {
    width: 48px;
    height: 48px;
    color: var(--accent);
    margin-bottom: 16px;
}

.upload-text {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.upload-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Screen Controls */
.screen-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.ctrl-btn {
    width: 44px;
    height: 44px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.ctrl-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.ctrl-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.ctrl-btn svg {
    width: 20px;
    height: 20px;
}

.scale-control {
    margin-left: auto;
}

.scale-control select {
    padding: 10px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
}

.scale-control select:focus {
    outline: none;
    border-color: var(--accent);
}

/* Sidebar */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.card {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--border);
}

.card h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 16px;
}

/* Controls List */
.controls-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.control-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--bg-card);
    border-radius: 10px;
}

.control-keys {
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 0.85rem;
    background: var(--bg-secondary);
    padding: 6px 12px;
    border-radius: 6px;
    color: var(--accent);
    border: 1px solid var(--border);
}

.control-action {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Info Rows */
.info-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.info-value {
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
}

/* Systems Grid */
.systems-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.systems-category {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.category-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.system-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: left;
}

.system-chip:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--text-primary);
}

.system-chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.chip-status {
    font-size: 0.9rem;
}

.chip-name {
    font-weight: 500;
}

/* Tips */
.tips ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tips li {
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding-left: 20px;
    position: relative;
}

.tips li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--accent);
}

.tips kbd {
    background: var(--bg-card);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--accent);
    border: 1px solid var(--border);
}

/* Mobile Controls */
.mobile-controls {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20px;
    background: linear-gradient(to top, rgba(10, 10, 15, 0.95), transparent);
    z-index: 100;
}

.touch-dpad {
    position: absolute;
    left: 20px;
    bottom: 20px;
    width: 140px;
    height: 140px;
}

.touch-btn {
    position: absolute;
    width: 45px;
    height: 45px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: white;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    transition: all 0.1s ease;
}

.touch-btn:active,
.touch-btn.active {
    background: var(--accent);
    transform: scale(0.95);
}

.dpad-up { top: 0; left: 47.5px; }
.dpad-down { bottom: 0; left: 47.5px; }
.dpad-left { top: 47.5px; left: 0; }
.dpad-right { top: 47.5px; right: 0; }

.touch-actions {
    position: absolute;
    right: 20px;
    bottom: 30px;
    display: flex;
    gap: 20px;
}

.action-a {
    width: 60px;
    height: 60px;
    background: rgba(99, 102, 241, 0.3);
    border-color: rgba(99, 102, 241, 0.5);
}

.action-b {
    width: 60px;
    height: 60px;
    background: rgba(239, 68, 68, 0.3);
    border-color: rgba(239, 68, 68, 0.5);
    margin-top: 20px;
}

.touch-system {
    position: absolute;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%);
    display: flex;
    gap: 16px;
}

.sys-btn {
    position: static;
    width: auto;
    padding: 12px 24px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    padding: 16px 24px;
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 0.95rem;
    animation: slideIn 0.3s ease;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s ease;
}

.toast.success {
    border-color: var(--success);
    background: rgba(34, 197, 94, 0.1);
}

.toast.error {
    border-color: var(--error);
    background: rgba(239, 68, 68, 0.1);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Responsive */
@media (max-width: 1200px) {
    .main {
        grid-template-columns: 1fr;
    }
    
    .sidebar {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .card {
        flex: 1;
        min-width: 280px;
    }
    
    .tips {
        display: none;
    }
}

@media (max-width: 768px) {
    .app {
        padding: 12px;
    }
    
    .header {
        flex-direction: column;
        gap: 16px;
        padding: 16px;
    }
    
    .logo h1 {
        font-size: 1.25rem;
    }
    
    .dropdown-btn {
        width: 100%;
        min-width: auto;
    }
    
    .dropdown-menu {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 70vh;
        border-radius: 20px 20px 0 0;
        transform: translateY(100%);
    }
    
    .dropdown-menu.show {
        transform: translateY(0);
    }
    
    .screen-container {
        min-height: 300px;
    }
    
    .upload-area {
        min-width: auto;
        width: 100%;
        padding: 32px 24px;
    }
    
    .sidebar {
        display: none;
    }
    
    .mobile-controls {
        display: block;
    }
    
    .screen-controls {
        justify-content: center;
    }
    
    .scale-control {
        display: none;
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Focus States */
button:focus-visible,
select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Selection */
::selection {
    background: var(--accent);
    color: white;
}
