:root {
    --bg-color: #0c0d14;
    /* Deep dark background */
    --sidebar-bg: #13141e;
    /* Slightly lighter for sidebar */
    --header-bg: rgba(12, 13, 20, 0.85);
    /* Transparent header */
    --card-bg: #1c1e26;
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --accent-color: #6c42ff;
    /* CrazyGames Purple */
    --accent-hover: #825eff;
    --border-color: #272832;
    --nav-item-hover: #252630;

    --font-family: 'Nunito', sans-serif;

    --sidebar-width: 240px;
    --sidebar-width-collapsed: 72px;
    --header-height: 72px;
    --border-radius: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow-x: hidden;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color);
}

::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.app-container {
    display: flex;
    min-height: 100vh;
}

/* --- SIDEBAR --- */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 100;
    transition: width 0.3s ease;
}

.sidebar.collapsed {
    width: var(--sidebar-width-collapsed);
}

.logo-area {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 16px;
    border-bottom: 1px solid transparent;
    /* Optional */
}

.logo-icon {
    font-size: 32px;
    color: var(--accent-color);
    margin-right: 12px;
    min-width: 32px;
}

.logo-text {
    font-weight: 900;
    font-size: 20px;
    white-space: nowrap;
    opacity: 1;
    transition: opacity 0.2s;
}

.sidebar.collapsed .logo-text {
    opacity: 0;
    pointer-events: none;
    display: none;
}

.nav-toggle-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    margin-left: auto;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar.collapsed .nav-toggle-btn {
    display: none;
    /* Usually hide toggle inside collapsed state or move it */
}

/* Adjust toggle button for the clone - maybe keep it simple for now */

.nav-links {
    flex: 1;
    overflow-y: auto;
    padding: 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    text-decoration: none;
    color: var(--text-secondary);
    border-radius: 8px;
    font-weight: 700;
    transition: background-color 0.2s, color 0.2s;
    white-space: nowrap;
    overflow: hidden;
}

.nav-item:hover,
.nav-item.active {
    background-color: var(--nav-item-hover);
    color: var(--text-primary);
}

.nav-item.active {
    color: var(--accent-color);
}

.nav-item .material-symbols-rounded {
    font-size: 24px;
    min-width: 24px;
    margin-right: 14px;
}

.nav-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 8px 0;
}

/* --- MAIN CONTENT --- */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* Prevent overflow issues */
    transition: margin-left 0.3s ease;
}

.sidebar.collapsed+.main-content {
    margin-left: var(--sidebar-width-collapsed);
}

/* --- TOP HEADER --- */
.top-header {
    height: var(--header-height);
    background-color: var(--header-bg);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 50;
    border-bottom: 1px solid var(--border-color);
}

.search-bar {
    background-color: var(--card-bg);
    /* darker input */
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    width: 400px;
    max-width: 100%;
}

.search-bar input {
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    margin-left: 10px;
    width: 100%;
    font-family: inherit;
    font-weight: 600;
}

.search-icon {
    color: var(--text-secondary);
}

.header-actions {
    display: flex;
    gap: 12px;
}

.icon-btn {
    background: var(--nav-item-hover);
    border: none;
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-btn {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 8px 24px;
    border-radius: 20px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s;
}

.login-btn:hover {
    background-color: var(--accent-hover);
}

/* --- CONTENT BODY --- */
.content-body {
    padding: 32px;
    flex: 1;
}

.page-title {
    font-size: 32px;
    margin-bottom: 12px;
}

.page-description {
    color: var(--text-secondary);
    margin-bottom: 32px;
    max-width: 800px;
    line-height: 1.5;
}

/* --- GAME GRID --- */
.game-grid {
    display: grid;
    /* Responsive columns: Auto-fill with min width of about 180px-200px */
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    padding-bottom: 40px;
}

.game-card {
    background-color: transparent;
    border-radius: var(--border-radius);
    overflow: hidden;
    position: relative;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
}

.game-card:hover {
    transform: translateY(-4px);
    z-index: 2;
}

.card-thumbnail {
    width: 100%;
    aspect-ratio: 16 / 9;
    /* Standard game thumbnail ratio */
    background-color: #2a2c36;
    position: relative;
    overflow: hidden;
    border-radius: 12px;
}

/* Gradient placeholders for game images */
.thumb-gradient {
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, #FF6B6B, #3B82F6);
    display: flex;
    align-items: center;
    justify-content: center;
}

.thumb-gradient span {
    font-size: 32px;
    color: rgba(255, 255, 255, 0.7);
}

.card-title {
    margin-top: 8px;
    font-weight: 700;
    font-size: 15px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Hover overlay effect */
.hover-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.game-card:hover .hover-overlay {
    opacity: 1;
}

.play-icon {
    font-size: 48px;
    color: white;
    background: var(--accent-color);
    border-radius: 50%;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.card-video-preview {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    /* Let clicks pass through */
}

/* --- GAME BADGES --- */
.card-badges {
    position: absolute;
    top: 8px;
    left: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 10;
    pointer-events: none;
}

.game-badge {
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    color: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 4px;
    width: fit-content;
}

.badge-new {
    background: linear-gradient(135deg, #00C6FF, #0072FF);
}

.badge-trending {
    background: linear-gradient(135deg, #FF512F, #DD2476);
}

.game-badge span {
    font-size: 14px;
}

/* Show video on hover if valid */
.game-card:hover .card-video-preview {
    opacity: 1;
}

.main-footer {
    padding: 32px;
    text-align: center;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 250px;
        /* Slightly wider for better touch */
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 1100;
        /* Higher than header */
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: none;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    }

    /* Sidebar Overlay for Mobile */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(4px);
        z-index: 1050;
        /* Below sidebar, above content */
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
    }

    .sidebar-overlay.active {
        opacity: 1;
        pointer-events: all;
    }

    .main-content {
        margin-left: 0 !important;
        /* Force no margin */
        width: 100%;
    }

    .sidebar.collapsed+.main-content {
        margin-left: 0;
    }

    .sidebar.collapsed+.main-content {
        margin-left: 0;
    }

    .search-bar {
        display: none;
    }

    .mobile-menu-btn {
        display: flex !important;
        background: none;
        border: none;
        color: var(--text-primary);
        padding: 8px;
        cursor: pointer;
    }
}

/* --- AUTH MODAL --- */
.auth-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.auth-modal-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.auth-modal-content {
    background-color: #1c1e26;
    width: 100%;
    max-width: 400px;
    border-radius: 16px;
    padding: 32px;
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.auth-modal-overlay.open .auth-modal-content {
    transform: translateY(0);
}

.close-modal-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.close-modal-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.auth-tabs {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 24px;
}

.auth-tab {
    flex: 1;
    background: none;
    border: none;
    padding: 12px;
    color: var(--text-secondary);
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    position: relative;
    transition: color 0.2s;
}

.auth-tab.active {
    color: var(--accent-color);
}

.auth-tab.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 2px;
    background-color: var(--accent-color);
}

.auth-form {
    display: none;
    flex-direction: column;
    gap: 16px;
    animation: fadeIn 0.3s ease;
}

.auth-form.active {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.auth-form h2 {
    text-align: center;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 600;
}

.form-group input {
    background-color: #0f1012;
    border: 1px solid var(--border-color);
    padding: 12px;
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: var(--accent-color);
}

.submit-btn {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    margin-top: 8px;
    transition: background 0.2s;
}

.submit-btn:hover {
    background-color: var(--accent-hover);
}

.input-error-msg {
    color: #ff6b6b;
    font-size: 13px;
    margin-top: 4px;
    min-height: 18px;
    /* reserve space */
    display: none;
}

.input-error-msg.visible {
    display: block;
}

.form-footer {
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 8px;
}

.form-footer a {
    color: var(--accent-color);
    text-decoration: none;
}


/* --- MOBILE MENU BUTTON --- */
.mobile-menu-btn {
    display: none;
    /* Hidden by default on desktop */
}

/* --- USER PROFILE DROPDOWN --- */
.user-menu-container {
    position: relative;
    display: inline-block;
}

.profile-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 24px;
    transition: all 0.2s;
    color: var(--text-primary);
    font-family: inherit;
    font-weight: 600;
    border: 1px solid transparent;
}

.profile-toggle:hover,
.profile-toggle.active {
    background-color: var(--nav-item-hover);
    border-color: rgba(255, 255, 255, 0.1);
}

.profile-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-color), #4e54c8);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
    overflow: hidden;
    font-size: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Dropdown Menu */
.dropdown-menu {
    position: absolute;
    top: calc(100% + 12px);
    right: 0;
    width: 260px;
    background-color: rgba(28, 30, 38, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    padding: 8px;
    display: none;
    flex-direction: column;
    z-index: 1000;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    transform-origin: top right;
}

.dropdown-menu.show {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}

.menu-header {
    padding: 16px 16px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 6px;
}

.menu-user-name {
    font-weight: 700;
    color: var(--text-primary);
    display: block;
    font-size: 16px;
    margin-bottom: 2px;
}

.menu-user-role {
    font-size: 13px;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 8px;
    border-radius: 4px;
    display: inline-block;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    text-decoration: none;
    color: var(--text-secondary);
    border-radius: 10px;
    font-weight: 600;
    font-size: 15px;
    transition: all 0.2s;
    cursor: pointer;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
}

.menu-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    transform: translateX(2px);
}

.menu-item .material-symbols-rounded {
    font-size: 22px;
    opacity: 0.8;
}

.menu-item.logout {
    color: #ff4757;
    margin-top: 6px;
    border-top: 1px solid transparent;
}

.menu-item.logout:hover {
    background-color: rgba(255, 71, 87, 0.1);
    color: #ff6b6b;
}

/* Mobile Bottom Sheet Styles */
@media (max-width: 768px) {
    .dropdown-menu {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        border-radius: 24px 24px 0 0;
        border: none;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        transform: translateY(100%);
        padding: 24px 16px 32px;
        background-color: #1c1e26;
        /* Solid bg better for mobile performance */
        box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
    }

    .dropdown-menu.show {
        transform: translateY(0);
    }

    /* Handle indicator for bottom sheet */
    .dropdown-menu::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background-color: rgba(255, 255, 255, 0.2);
        border-radius: 2px;
        margin: -10px auto 20px;
    }

    .menu-item {
        padding: 16px;
        /* Larger touch targets */
        font-size: 16px;
    }
}