:root {
    /* Core Theme */
    --bg-primary: rgb(12, 12, 14);
    --bg-card: rgba(24, 24, 28, 0.8);
    --bg-card-hover: rgba(50, 50, 60, 0.9);
    --border-color: rgb(40, 40, 45);
    --text-primary: #f0f0f5;
    --text-secondary: rgba(255, 255, 255, 0.5);
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --danger: #ef4444;

    /* System Colors (R, G, B) */
    --color-nes: 200, 16, 16;
    --color-snes: 120, 80, 200;
    --color-n64: 18, 140, 48;
    --color-gamecube: 100, 60, 180;
    --color-gb: 144, 168, 64;
    --color-gbc: 120, 60, 180;
    --color-gba: 60, 60, 160;
    --color-nds: 180, 180, 190;
    --color-megadrive: 20, 60, 160;
    --color-dreamcast: 240, 120, 40;
    --color-ps1: 40, 80, 180;
    --color-ps2: 20, 40, 120;
    --color-ps3: 60, 60, 60;

    /* Sizing & Spacing */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: var(--radius-sm);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Typography */
h1, h2, h3, h4 { font-weight: 600; }
.logo-text { font-weight: 700; font-size: 2rem; background: linear-gradient(to right, var(--text-primary), var(--text-secondary)); -webkit-background-clip: text; color: transparent; }
.subtitle { color: var(--text-secondary); font-size: 0.875rem; }
.text-danger { color: var(--danger) !important; }
.monospace { font-family: 'JetBrains Mono', monospace; }

/* Utilities */
.hidden { display: none !important; }

/* Screens & Transitions */
.screen {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%; height: 100%;
    animation: fadeIn var(--transition-normal);
    display: flex;
    flex-direction: column;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Card Component (Premium Shadow) */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.6);
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}

/* Inputs & Forms */
.input-group { margin-bottom: var(--spacing-md); }
.input-group label { display: block; margin-bottom: var(--spacing-xs); font-size: 0.875rem; color: var(--text-secondary); }
.input {
    width: 100%;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-family: inherit;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2); }
.dropdown { @extend .input; appearance: none; background: rgba(0,0,0,0.2) url('data:image/svg+xml;utf8,<svg fill="white" viewBox="0 0 24 24" width="24" height="24"><path d="M7 10l5 5 5-5z"/></svg>') no-repeat right 8px center; padding-right: 32px; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    border: none;
    font-weight: 500; font-family: inherit; cursor: pointer;
    transition: all var(--transition-fast);
    position: relative; overflow: hidden;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-secondary { background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border-color); }
.btn-secondary:hover { background: rgba(255,255,255,0.08); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--text-primary); background: rgba(255,255,255,0.05); }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; background: transparent; border: none; color: var(--text-secondary); cursor: pointer; border-radius: var(--radius-sm); }
.btn-icon:hover { color: var(--text-primary); background: rgba(255,255,255,0.05); }

/* Login Screen */
#login-screen { position: relative; display: flex; justify-content: center; align-items: center; min-height: 100vh; padding: 16px; overflow: hidden; }
#login-screen.hidden { display: none !important; }
.login-card { position: relative; z-index: 2; width: 100%; max-width: 380px; text-align: center; padding: 26px 28px; backdrop-filter: blur(16px); }

/* Hero Logo Avatar Frame */
.logo-avatar-frame-large {
    position: relative;
    padding: 4px;
    background: linear-gradient(135deg, #a855f7, #6366f1, #ec4899);
    border-radius: 28px;
    box-shadow: 0 0 35px rgba(168, 85, 247, 0.6), inset 0 0 12px rgba(255, 255, 255, 0.25);
    transition: transform var(--transition-normal);
}
.logo-avatar-frame-large:hover {
    transform: scale(1.03);
}

.brand-avatar-large {
    width: 170px;
    height: 170px;
    border-radius: 24px;
    object-fit: cover;
    display: block;
}

/* CRT Background Scanlines */
.crt-bg-scanlines {
    position: absolute;
    inset: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.4) 50%);
    background-size: 100% 4px;
    pointer-events: none;
    z-index: 1;
    opacity: 0.7;
}

/* Retro Arcade Login Card */
.retro-arcade-card {
    position: relative;
    border: 1px solid rgba(168, 85, 247, 0.35) !important;
    box-shadow: 0 0 40px rgba(99, 102, 241, 0.25), 0 0 80px rgba(168, 85, 247, 0.15), inset 0 0 20px rgba(99, 102, 241, 0.1);
    background: rgba(14, 14, 18, 0.88) !important;
    border-radius: 16px;
    overflow: hidden;
}

/* Corner Brackets */
.corner-bracket {
    position: absolute;
    width: 14px;
    height: 14px;
    border-color: #a855f7;
    border-style: solid;
    pointer-events: none;
}
.corner-bracket.top-left {
    top: 6px;
    left: 6px;
    border-width: 2px 0 0 2px;
}
.corner-bracket.bottom-right {
    bottom: 6px;
    right: 6px;
    border-width: 0 2px 2px 0;
}

/* Arcade Badge */
.arcade-badge {
    display: inline-block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: #e0e7ff;
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.4);
    padding: 3px 10px;
    border-radius: 12px;
    margin-bottom: 10px;
    text-shadow: 0 0 8px rgba(99, 102, 241, 0.8);
    animation: coinBlink 2.5s ease-in-out infinite;
}

@keyframes coinBlink {
    0%, 100% { opacity: 1; text-shadow: 0 0 8px rgba(99, 102, 241, 0.8); }
    50% { opacity: 0.55; text-shadow: 0 0 2px rgba(99, 102, 241, 0.3); }
}

/* Logo Avatar Frame */
.logo-avatar-frame {
    position: relative;
    padding: 3px;
    background: linear-gradient(135deg, #a855f7, #6366f1, #ec4899);
    border-radius: 16px;
    box-shadow: 0 0 20px rgba(168, 85, 247, 0.5);
    margin-bottom: 10px;
}

.logo-avatar-frame .brand-avatar {
    margin-bottom: 0 !important;
    display: block;
}

/* Retro Typography */
.retro-title {
    font-family: 'Orbitron', 'Bungee', sans-serif !important;
    font-size: 1.35rem !important;
    letter-spacing: 2px;
    background: linear-gradient(90deg, #ffffff, #c7d2fe, #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 12px rgba(168, 85, 247, 0.4);
}

.retro-subtitle {
    font-family: 'JetBrains Mono', monospace !important;
    font-size: 0.65rem !important;
    letter-spacing: 1.5px;
    color: rgba(255, 255, 255, 0.5) !important;
    text-transform: uppercase;
}

.retro-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px !important;
    letter-spacing: 1px;
    color: #a5b4fc !important;
    font-weight: 600;
}

.retro-input {
    background: rgba(0, 0, 0, 0.4) !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
}
.retro-input:focus {
    border-color: #a855f7 !important;
    box-shadow: 0 0 12px rgba(168, 85, 247, 0.35) !important;
}

/* Arcade Push Button */
.retro-arcade-btn {
    font-family: 'Orbitron', sans-serif !important;
    font-weight: 700 !important;
    font-size: 13px !important;
    letter-spacing: 1.5px;
    background: linear-gradient(135deg, #6366f1, #4f46e5, #7c3aed) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3) !important;
    transition: transform 100ms ease, box-shadow 100ms ease !important;
}
.retro-arcade-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(168, 85, 247, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.4) !important;
}
.retro-arcade-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4) !important;
}

/* Retro Ticker Bar */
.retro-ticker-bar {
    margin-top: 14px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.45);
    letter-spacing: 0.5px;
}
.login-card h1 { font-size: 1.5rem; margin-bottom: 2px; }
.login-card .subtitle { margin-bottom: 14px; font-size: 0.8rem; }

/* Ambient Background Glow */
.ambient-glow {
    position: absolute;
    width: 340px;
    height: 340px;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.25) 0%, rgba(168, 85, 247, 0.15) 50%, transparent 70%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    filter: blur(40px);
    pointer-events: none;
    z-index: 0;
    animation: ambientPulse 8s ease-in-out infinite alternate;
}

@keyframes ambientPulse {
    0% { transform: translate(-50%, -50%) scale(0.85); opacity: 0.6; }
    100% { transform: translate(-50%, -50%) scale(1.1); opacity: 0.95; }
}

/* Input Wrappers & Icons */
.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}
.input-icon {
    position: absolute;
    left: 12px;
    color: rgba(255, 255, 255, 0.4);
    pointer-events: none;
    transition: color 150ms ease;
}
.input-wrapper:focus-within .input-icon {
    color: #818cf8;
}
.input-with-icon {
    padding-left: 38px !important;
    padding-right: 38px !important;
}
.input-action-btn {
    position: absolute;
    right: 8px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: color 150ms ease, background 150ms ease;
}
.input-action-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

/* Quick Fill Button */
.quick-fill-btn {
    background: rgba(99, 102, 241, 0.1);
    border: 1px dashed rgba(99, 102, 241, 0.4);
    color: #a5b4fc;
    font-size: 11px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 200ms ease;
    font-family: inherit;
}
.quick-fill-btn:hover {
    background: rgba(99, 102, 241, 0.25);
    border-color: #6366f1;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.4);
}

.brand-avatar {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    object-fit: cover;
    margin-bottom: 8px;
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.4), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}
.brand-avatar:hover {
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(99, 102, 241, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.3);
}

/* Unified Top Navigation Bar */
.unified-top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: rgba(12, 12, 16, 0.88);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-logo-badge {
    position: relative;
    padding: 2px;
    background: linear-gradient(135deg, #a855f7, #6366f1);
    border-radius: 10px;
    box-shadow: 0 0 12px rgba(168, 85, 247, 0.4);
}

.nav-logo-img {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    object-fit: cover;
    display: block;
}

.nav-brand-title {
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    font-size: 16px;
    letter-spacing: 1.5px;
    background: linear-gradient(90deg, #ffffff, #c7d2fe, #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #e0e7ff;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 150ms ease;
    font-family: inherit;
}
.nav-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.25);
    color: #fff;
    transform: translateY(-1px);
}

.nav-btn-accent {
    background: rgba(99, 102, 241, 0.2);
    border-color: rgba(99, 102, 241, 0.5);
    color: #a5b4fc;
}
.nav-btn-accent:hover {
    background: rgba(99, 102, 241, 0.4);
    border-color: #6366f1;
    color: #fff;
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.4);
}

.nav-btn-danger {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}
.nav-btn-danger:hover {
    background: rgba(239, 68, 68, 0.25);
    border-color: #ef4444;
    color: #fff;
}

/* Hero Brand Banner */
.hero-brand-banner {
    position: relative;
    margin: 20px 24px 16px 24px;
    padding: 20px 24px;
    background: linear-gradient(135deg, rgba(20, 20, 28, 0.9), rgba(12, 12, 18, 0.95));
    border: 1px solid rgba(168, 85, 247, 0.25);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), inset 0 0 30px rgba(99, 102, 241, 0.08);
    overflow: hidden;
    text-align: center;
}

.banner-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 400px;
    height: 120px;
    background: radial-gradient(ellipse, rgba(168, 85, 247, 0.2) 0%, rgba(99, 102, 241, 0.1) 50%, transparent 70%);
    filter: blur(30px);
    pointer-events: none;
}

.banner-content {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.banner-logo-wrapper {
    position: relative;
    padding: 4px;
    background: linear-gradient(135deg, #a855f7, #6366f1, #ec4899);
    border-radius: 28px;
    box-shadow: 0 0 35px rgba(168, 85, 247, 0.55), inset 0 0 10px rgba(255, 255, 255, 0.25);
    margin-bottom: 16px;
    transition: transform var(--transition-normal);
}
.banner-logo-wrapper:hover {
    transform: scale(1.02);
}

.hero-banner-logo {
    width: 220px;
    height: 220px;
    max-width: 80vw;
    border-radius: 24px;
    object-fit: cover;
    display: block;
}

.hero-banner-title {
    font-family: 'Orbitron', 'Bungee', sans-serif;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 2px;
    background: linear-gradient(90deg, #ffffff, #c7d2fe, #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin: 0;
    text-shadow: 0 0 16px rgba(168, 85, 247, 0.4);
}

.hero-banner-subtitle {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 6px;
    letter-spacing: 0.5px;
}
#login-form { text-align: left; }

/* Headers */
.app-header { display: flex; justify-content: space-between; align-items: center; padding: var(--spacing-lg) var(--spacing-xl); border-bottom: 1px solid var(--border-color); }
.header-actions { display: flex; gap: var(--spacing-sm); }

/* Console Select Grid */
.console-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 30px;
    padding: 30px var(--spacing-xl);
    flex: 1; overflow-y: auto;
    justify-content: center;
}
.console-card {
    position: relative;
    height: 160px;
    border-radius: 16px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    cursor: pointer;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    padding: var(--spacing-md);
    transition: transform 150ms ease, box-shadow 150ms ease, border 150ms ease, background 150ms ease;
}

.console-card.nes { --sys-color: var(--color-nes); }
.console-card.snes { --sys-color: var(--color-snes); }
.console-card.n64 { --sys-color: var(--color-n64); }
.console-card.gamecube { --sys-color: var(--color-gamecube); }
.console-card.gb { --sys-color: var(--color-gb); }
.console-card.gbc { --sys-color: var(--color-gbc); }
.console-card.gba { --sys-color: var(--color-gba); }
.console-card.nds { --sys-color: var(--color-nds); }
.console-card.megadrive { --sys-color: var(--color-megadrive); }
.console-card.dreamcast { --sys-color: var(--color-dreamcast); }
.console-card.ps1 { --sys-color: var(--color-ps1); }
.console-card.ps2 { --sys-color: var(--color-ps2); }
.console-card.ps3 { --sys-color: var(--color-ps3); }

.console-card:hover {
    background: rgba(var(--sys-color), 0.2);
    border: 2px solid rgb(var(--sys-color));
    box-shadow: 0 0 0 6px rgba(var(--sys-color), 0.15);
}

.console-image {
    position: absolute;
    top: 10px; left: 10px; right: 10px; bottom: 10px;
    width: calc(100% - 20px);
    height: calc(100% - 20px);
    object-fit: fill;
    opacity: 0.78;
    transition: opacity 150ms ease, filter 150ms ease;
    border-radius: 6px;
}
.console-card:hover .console-image { opacity: 0.15; filter: grayscale(100%); }

.console-hover-container {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 150ms ease, transform 150ms ease;
    z-index: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    width: 100%;
}
.console-hover-logo {
    color: rgb(var(--sys-color));
    text-align: center;
    text-shadow: 0 4px 12px rgba(0,0,0,0.8);
    margin-bottom: 2px;
}
.console-hover-name {
    font-size: 14px;
    font-weight: 500;
    color: #e0e0e0;
    text-align: center;
    text-shadow: 0 2px 8px rgba(0,0,0,0.8);
    font-family: 'Inter', sans-serif;
}
.console-card:hover .console-hover-container { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }

/* Font Mappings */
.console-card.nes .console-hover-logo, .console-card.snes .console-hover-logo, .console-card.gb .console-hover-logo, .console-card.gbc .console-hover-logo, .console-card.gba .console-hover-logo, .console-card.nds .console-hover-logo {
    font-family: 'Press Start 2P', cursive; font-size: 28px;
}
.console-card.n64 .console-hover-logo, .console-card.gamecube .console-hover-logo {
    font-family: 'Bungee', cursive; font-size: 56px;
}
.console-card.megadrive .console-hover-logo, .console-card.dreamcast .console-hover-logo {
    font-family: 'Orbitron', sans-serif; font-size: 52px; font-style: italic; font-weight: 700;
}
.console-card.ps1 .console-hover-logo, .console-card.ps2 .console-hover-logo, .console-card.ps3 .console-hover-logo {
    font-family: 'Michroma', sans-serif; font-size: 48px;
}

/* Favorite Star Badge */
.fav-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    opacity: 0.5;
    transition: opacity 0.2s, transform 0.2s, background 0.2s;
    z-index: 5;
}

.fav-badge:hover, .fav-badge.active {
    opacity: 1;
    transform: scale(1.15);
    background: rgba(234, 179, 8, 0.25);
    border-color: #eab308;
}

.console-count-badge {
    position: absolute;
    top: 10px; left: 10px;
    min-width: 80px; height: 24px;
    background: rgba(0, 0, 0, 0.59);
    border-radius: 12px;
    font-size: 12px; color: #fff;
    display: flex; align-items: center; justify-content: center;
    z-index: 2;
}

.app-only-overlay {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7); border-radius: 16px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    z-index: 3; color: var(--text-secondary);
}
.console-card.not-playable { cursor: not-allowed; }
.console-card.not-playable:hover { transform: none; box-shadow: none; border-width: 1px; border-color: var(--border-color); background: rgba(0, 0, 0, 0.4); }

/* ROM Library */
.system-header { display: flex; align-items: center; gap: var(--spacing-md); padding: var(--spacing-md) var(--spacing-xl); border-bottom: 1px solid var(--border-color); background: rgba(0,0,0,0.2); }
.system-header h2 { flex: 1; }
.library-controls { display: flex; gap: var(--spacing-sm); }
.search-bar { position: relative; }
.search-bar svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-secondary); }
.search-bar input { padding-left: 36px; }

.library-content { padding: var(--spacing-xl); flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: var(--spacing-xl); }
.rom-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 20px; }
.game-card {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    aspect-ratio: 3/4;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}
.game-card:hover {
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.6);
}
.game-card .rom-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: rgba(0,0,0,0.4);
    display: flex; align-items: center; justify-content: center;
}
.game-card .rom-info-overlay {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    padding: var(--spacing-sm) var(--spacing-md);
    background: linear-gradient(to top, rgba(0,0,0,0.9), transparent);
    color: white;
}
.game-card .rom-title { font-weight: 600; font-size: 1rem; text-shadow: 0 2px 4px rgba(0,0,0,0.8); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Game Details Modal */
.game-details-card {
    width: 600px; max-width: 90vw;
    background: rgba(24, 24, 28, 0.85); backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.1);
    position: relative;
    text-align: left;
}
.game-details-card .close-btn { position: absolute; top: 16px; right: 16px; }
.details-content { display: flex; gap: var(--spacing-lg); margin-top: var(--spacing-md); }
@media (max-width: 600px) {
    .details-content { flex-direction: column; }
}
.details-poster { flex: 0 0 200px; }
.details-poster img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: var(--radius-md); box-shadow: 0 4px 12px rgba(0,0,0,0.5); }
.details-info { flex: 1; display: flex; flex-direction: column; }
.details-meta { font-size: 0.875rem; color: var(--text-secondary); margin-bottom: var(--spacing-md); }
.details-desc { font-size: 0.875rem; line-height: 1.5; color: #d0d0d5; margin-bottom: var(--spacing-md); }
.divider { border: 0; border-top: 1px solid var(--border-color); margin: var(--spacing-md) 0; }
.edit-metadata-section h3 { font-size: 1rem; margin-bottom: var(--spacing-sm); }

/* Game Player */
.player-container { position: relative; width: 100%; height: 100%; background: black; display: flex; justify-content: center; align-items: center; overflow: hidden; }
canvas#game-canvas {
    max-width: 100%; max-height: 100%;
    object-fit: contain;
    z-index: 1;
}
#game-canvas.pixelated { image-rendering: pixelated; }
#game-canvas.smooth { image-rendering: auto; }
.shader-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5;
}
.crt-overlay {
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.4) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.03));
    background-size: 100% 4px, 6px 100%;
    box-shadow: inset 0 0 80px rgba(0,0,0,0.6);
}
.crt-phosphor-overlay {
    background: linear-gradient(90deg, rgba(255,0,0,0.06), rgba(0,255,0,0.06), rgba(0,0,255,0.06));
    background-size: 3px 100%;
    box-shadow: inset 0 0 100px rgba(0,0,0,0.8);
}
.lcd-overlay {
    background: linear-gradient(90deg, rgba(0,0,0,0.15) 1px, transparent 1px), linear-gradient(0deg, rgba(0,0,0,0.15) 1px, transparent 1px);
    background-size: 4px 4px;
}
.vignette-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3;
    background: radial-gradient(circle, rgba(0,0,0,0) 60%, rgba(0,0,0,0.6) 100%);
}

/* CRT Screen Curvature Presets */
canvas#game-canvas.crt-curved-trinitron {
    transform: perspective(1000px) rotateX(1deg) scale(1.02);
    border-radius: 20px;
    box-shadow: 0 0 40px rgba(99, 102, 241, 0.3), inset 0 0 40px rgba(0,0,0,0.8);
}

canvas#game-canvas.crt-arcade-barrel {
    transform: perspective(600px) rotateX(2deg) scale(1.04);
    border-radius: 36px;
    box-shadow: 0 0 60px rgba(236, 72, 153, 0.4), inset 0 0 60px rgba(0,0,0,0.9);
}

canvas#game-canvas.crt-vga-sharp {
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.15);
}

/* Retro Bezel Frames */
.player-container {
    transition: padding 0.3s ease, border-radius 0.3s ease, box-shadow 0.3s ease, background 0.3s ease;
}

.player-container.bezel-crt-tv {
    padding: 32px 48px;
    background: linear-gradient(135deg, #3d2817 0%, #1f140a 100%);
    border: 12px solid #5a3c22;
    border-radius: 40px;
    box-shadow: 0 0 50px rgba(255, 165, 0, 0.25), inset 0 0 30px rgba(0, 0, 0, 0.9);
}

.player-container.bezel-gameboy {
    padding: 24px 36px 48px 36px;
    background: linear-gradient(180deg, #8b8b9e 0%, #6e6e80 100%);
    border: 10px solid #525263;
    border-radius: 24px 24px 60px 24px;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.7), inset 0 4px 10px rgba(255, 255, 255, 0.2);
}

.player-container.bezel-arcade {
    padding: 40px;
    background: #0d0d12;
    border: 8px solid #6366f1;
    border-radius: 20px;
    box-shadow: 0 0 60px rgba(99, 102, 241, 0.5), inset 0 0 40px rgba(236, 72, 153, 0.3);
}

.modal-backdrop { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); display: flex; justify-content: center; align-items: center; z-index: 100; }
.modal { width: 300px; text-align: center; }
.modal h2 { margin-bottom: var(--spacing-lg); }
.menu-actions { display: flex; flex-direction: column; gap: var(--spacing-sm); }

/* Touch Controls */
#touch-controls-container {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
    font-family: sans-serif;
}

.touch-btn, .touch-dpad-btn {
    position: absolute;
    pointer-events: auto;
    background: rgba(255,255,255,0.12);
    border: 1.5px solid rgba(255,255,255,0.25);
    border-radius: 50%;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    user-select: none;
    touch-action: none;
    transition: transform 0.1s, background 0.1s, box-shadow 0.1s;
    font-weight: 600;
}

.touch-btn:active, .touch-btn.active, .touch-dpad-btn:active, .touch-dpad-btn.active {
    background: rgba(99, 102, 241, 0.4);
    border-color: #6366f1;
    transform: scale(0.92);
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.6);
}

/* Layout */
#virtual-dpad {
    position: absolute;
    bottom: 40px;
    left: 40px;
    width: 160px;
    height: 160px;
}
.dpad-up { top: 0; left: 50px; width: 60px; height: 60px; }
.dpad-down { bottom: 0; left: 50px; width: 60px; height: 60px; }
.dpad-left { left: 0; top: 50px; width: 60px; height: 60px; }
.dpad-right { right: 0; top: 50px; width: 60px; height: 60px; }

#virtual-face-buttons {
    position: absolute;
    bottom: 40px;
    right: 40px;
    width: 160px;
    height: 160px;
}
.btn-y { top: 0; left: 50px; width: 60px; height: 60px; }
.btn-a { bottom: 0; left: 50px; width: 60px; height: 60px; }
.btn-x { left: 0; top: 50px; width: 60px; height: 60px; }
.btn-b { right: 0; top: 50px; width: 60px; height: 60px; }

#virtual-shoulders {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    height: 60px;
}
.btn-l2 { left: 0; top: 0; width: 80px; height: 40px; border-radius: 20px; }
.btn-l1 { left: 90px; top: 0; width: 80px; height: 40px; border-radius: 20px; }
.btn-r2 { right: 0; top: 0; width: 80px; height: 40px; border-radius: 20px; }
.btn-r1 { right: 90px; top: 0; width: 80px; height: 40px; border-radius: 20px; }

#virtual-center-btns {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
}
.btn-select, .btn-start {
    position: relative;
    width: 80px;
    height: 36px;
    border-radius: 18px;
    font-size: 12px;
}

@media (max-width: 768px) {
    #virtual-dpad, #virtual-face-buttons {
        transform: scale(0.85);
        transform-origin: bottom center;
        bottom: 20px;
    }
    #virtual-dpad { left: 10px; }
    #virtual-face-buttons { right: 10px; }
    .btn-select, .btn-start { transform: scale(0.9); }
}

/* Admin Drawer */
.drawer-backdrop { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000; transition: opacity var(--transition-normal); }
.drawer {
    position: fixed; top: 0; right: 0; width: 400px; max-width: 100vw; height: 100%; background: var(--bg-primary); border-left: 1px solid var(--border-color);
    z-index: 1001; display: flex; flex-direction: column; transform: translateX(0); transition: transform var(--transition-normal);
}
.drawer.hidden { transform: translateX(100%); display: flex !important; }
.drawer-backdrop.hidden { opacity: 0; pointer-events: none; display: block !important; }
.drawer-header { display: flex; justify-content: space-between; align-items: center; padding: var(--spacing-md) var(--spacing-xl); border-bottom: 1px solid var(--border-color); }
.drawer-content { padding: var(--spacing-xl); overflow-y: auto; flex: 1; }
.admin-section { margin-bottom: var(--spacing-xl); }
.admin-section h3 { margin-bottom: var(--spacing-sm); color: var(--text-secondary); font-size: 0.875rem; text-transform: uppercase; letter-spacing: 0.05em; }
.upload-zone { border: 2px dashed var(--border-color); border-radius: var(--radius-md); padding: var(--spacing-xl); text-align: center; color: var(--text-secondary); cursor: pointer; transition: border-color var(--transition-fast); }
.upload-zone:hover { border-color: var(--accent); color: var(--text-primary); }

/* Toasts */
#toast-container { position: fixed; bottom: var(--spacing-lg); right: var(--spacing-lg); z-index: 9999; display: flex; flex-direction: column; gap: var(--spacing-sm); }
.toast {
    background: var(--bg-card); backdrop-filter: blur(10px); border: 1px solid var(--border-color); padding: 12px 16px; border-radius: var(--radius-md);
    box-shadow: 0 4px 12px rgba(0,0,0,0.5); display: flex; align-items: center; gap: 8px; animation: slideUp 0.3s ease forwards;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Loaders */
#loading-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(10, 10, 15, 0.8); z-index: 9999; display: flex; justify-content: center; align-items: center; }
.spinner { width: 40px; height: 40px; border: 3px solid rgba(255,255,255,0.1); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 768px) {
    .console-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); padding: var(--spacing-md); }
    .console-card { height: 120px; }
    .app-header { padding: var(--spacing-md); }
    .library-controls { flex-direction: column; }
    .drawer { width: 100%; }
}

/* Achievements */
.achievement-banner {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(15, 15, 20, 0.85);
    backdrop-filter: blur(8px);
    border: 2px solid;
    border-image: linear-gradient(45deg, #ffd700, #ff8c00) 1;
    border-radius: var(--radius-md);
    padding: 12px 20px;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.3);
    z-index: 200;
    color: white;
}
.achievement-banner.slide-down { animation: slideDown 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; }
.achievement-banner.slide-up { animation: slideUpOut 0.5s ease forwards; }

.ach-icon img { border-radius: 50%; border: 2px solid #ffd700; }
.ach-title { font-weight: 700; color: #ffd700; font-size: 1.1rem; }
.ach-desc { font-size: 0.875rem; color: #e0e0e0; }
.ach-points { font-weight: bold; color: #fff; background: rgba(255, 215, 0, 0.3); padding: 4px 8px; border-radius: 12px; margin-left: auto; }

@keyframes slideDown { from { top: -100px; opacity: 0; } to { top: 20px; opacity: 1; } }
@keyframes slideUpOut { from { top: 20px; opacity: 1; } to { top: -100px; opacity: 0; } }

.ach-list-item { display: flex; gap: 12px; padding: 12px; border-bottom: 1px solid var(--border-color); opacity: 0.5; }
.ach-list-item.unlocked { opacity: 1; border-left: 3px solid #ffd700; background: rgba(255, 215, 0, 0.05); }
.ach-list-item:last-child { border-bottom: none; }

/* Cheat Items */
.cheat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    padding: 12px;
    border-radius: var(--radius-md);
    gap: 8px;
}
.cheat-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.cheat-desc {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}
.cheat-code-badge {
    align-self: flex-start;
    font-size: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    background: rgba(99, 102, 241, 0.2);
    color: #a5b4fc;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid rgba(99, 102, 241, 0.3);
}
.cheat-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}
.cheat-toggle {
    appearance: none;
    width: 36px;
    height: 20px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    position: relative;
    cursor: pointer;
    outline: none;
    transition: background 0.2s;
}
.cheat-toggle:checked {
    background: var(--accent);
}
.cheat-toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}
.cheat-toggle:checked::after {
    transform: translateX(16px);
}
.btn-delete-cheat {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.btn-delete-cheat:hover {
    color: var(--danger);
}

/* Audio Controls */
.volume-slider {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    outline: none;
    transition: background 0.15s ease-in-out;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
    transition: transform 0.15s ease, background 0.15s ease;
}

.volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    background: var(--accent-hover);
}

/* --- Visual Controller Remapper --- */
#visual-remapper-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 15px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    position: relative;
    overflow: hidden;
}

.remapper-layout {
    display: contents;
}

.rebind-node {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.rebind-node:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(99, 102, 241, 0.5);
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.3);
    transform: translateY(-2px);
}

.rebind-node .node-label {
    font-size: 14px;
    font-weight: 600;
    color: #e0e0e0;
}

.rebind-node .key-badge {
    background: rgba(99, 102, 241, 0.2);
    border: 1px solid rgba(99, 102, 241, 0.4);
    color: #a5b4fc;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

@keyframes rebindPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.7);
        border-color: rgba(99, 102, 241, 1);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(99, 102, 241, 0);
        border-color: rgba(99, 102, 241, 0.5);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0);
        border-color: rgba(99, 102, 241, 1);
    }
}

.rebind-node.listening {
    animation: rebindPulse 1.5s infinite;
    background: rgba(99, 102, 241, 0.15);
}

.listening-prompt {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #4f46e5;
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
    animation: fadeInUp 0.3s ease-out forwards;
    white-space: nowrap;
    pointer-events: none;
    z-index: 10;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translate(-50%, 10px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* Save Slots Manager */
#slots-grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    flex: 1;
    overflow-y: auto;
}
.slot-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: transform var(--transition-fast), border-color var(--transition-fast);
}
.slot-card.active {
    border-color: var(--accent);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
}
.slot-thumbnail-container {
    width: 100%;
    aspect-ratio: 4/3;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
.slot-thumbnail {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.slot-thumbnail.empty {
    color: var(--text-secondary);
    font-size: 0.875rem;
}
.slot-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.slot-index {
    font-weight: 600;
    font-size: 0.875rem;
}
.slot-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
}
.slot-actions {
    display: flex;
    gap: 4px;
    margin-top: auto;
}
.slot-actions .btn {
    padding: 4px 0;
    flex: 1;
    font-size: 0.75rem;
}
