/* lobby.css */

/* --- Entry Screen --- */
.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    /* Changed from center to allow natural scrolling down */
    transition: opacity 0.5s, transform 0.5s;
    overflow-y: auto;
    /* Enable vertical scrolling */
    overflow-x: hidden;
}

.screen.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.95);
}

.screen.active {
    opacity: 1;
    transform: scale(1);
}

.logo-container {
    text-align: center;
    margin-bottom: 2rem;
    animation: fadeInDown 1s ease-out;
}

.logo-text {
    font-family: var(--font-heading);
    font-size: 4rem;
    background: linear-gradient(180deg, #fff 0%, #aaa 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 30px rgba(255, 255, 255, 0.2);
    margin: 0;
}

.logo-subtitle {
    letter-spacing: 0.5rem;
    color: var(--primary);
    font-size: 1rem;
    margin-top: 0.5rem;
    text-transform: uppercase;
}

.login-card {
    width: 100%;
    max-width: 500px;
    padding: 3rem;
    border-radius: 20px;
    background: rgba(10, 10, 12, 0.6);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.input-group {
    margin-bottom: 2rem;
}

.input-group label,
.avatar-selection label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
}

.input-group input {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1rem;
    color: #fff;
    font-family: var(--font-heading);
    font-size: 1.5rem;
    text-align: center;
    border-radius: 8px;
    transition: all 0.3s;
}

.input-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.2);
    outline: none;
}

.avatar-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.avatar-option {
    aspect-ratio: 1;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
    opacity: 0.7;
}

.avatar-option:hover {
    opacity: 1;
    border-color: rgba(255, 255, 255, 0.3);
}

.avatar-option.selected {
    opacity: 1;
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.4);
    transform: scale(1.05);
}

.avatar-option img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* --- Lobby Screen --- */
#lobby-screen {
    justify-content: flex-start;
    padding: 2rem;
    min-height: 100%;
    /* Changed from height:100% to allow contents to expand */
    height: auto;
}

.lobby-header {
    width: 100%;
    max-width: 1400px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    border-radius: 12px;
    margin-bottom: 2rem;
}

.header-left {
    flex: 1;
    display: flex;
    align-items: center;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    font-size: 2rem;
    color: var(--primary);
}

.logo-text-header {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    color: #fff;
    margin: 0;
    letter-spacing: 2px;
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
    gap: 3rem;
}

.header-right {
    flex: 1;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    transition: opacity 0.2s;
}

.header-right:hover {
    opacity: 0.8;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.avatar-small {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    object-fit: cover;
    box-shadow: 0 0 10px rgba(0, 242, 255, 0.4);
}

.user-name {
    font-family: var(--font-heading);
    font-size: 1.2rem;
}

/* Stats Header */
.lobby-stats {
    display: flex;
    gap: 3rem;
    /* Reduced gap based on mockup */
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    letter-spacing: 2px;
    font-weight: 500;
}

.stat-value {
    font-family: var(--font-heading);
    font-size: 2.5rem;
    color: var(--primary);
    text-shadow: 0 0 15px rgba(0, 242, 255, 0.6);
    line-height: 1;
    margin-top: 4px;
}

.lobby-content {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    width: 100%;
    max-width: 1400px;
    padding-bottom: 2rem;
}

.lobby-section {
    background: rgba(10, 10, 12, 0.4);
    border-radius: 16px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.deck-section {
    flex-shrink: 0;
}



.section-title {
    font-size: 1.2rem;
    color: var(--text-muted);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.section-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
}

.section-header-row .section-title {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

/* Filter Styling */
.filter-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.filter-group {
    display: flex;
    background: transparent;
    padding: 0;
    gap: 0.5rem;
}

.filter-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    padding: 8px 24px;
    border-radius: 20px;
    /* Pill shape */
    cursor: pointer;
    font-family: var(--font-heading);
    font-size: 0.8rem;
    transition: all 0.2s;
}

.filter-btn:hover {
    color: #fff;
}

.filter-btn.active {
    background: var(--primary);
    color: #000;
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.4);
}

.filter-select {
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 8px 12px;
    border-radius: 8px;
    font-family: var(--font-heading);
    font-size: 0.8rem;
    cursor: pointer;
}

/* Deck Grid to Stack */
.deck-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

@media (max-width: 900px) {
    .deck-grid {
        grid-template-columns: 1fr;
    }

    .section-header-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .filter-controls {
        width: 100%;
        justify-content: space-between;
    }
}

.deck-card {
    width: 100%;
    height: 120px;
    /* Adjusted list view height */
    background: linear-gradient(90deg, #111 0%, #050505 100%);
    border: 1px solid rgba(0, 255, 204, 0.4);
    /* Glow matching */
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: row;
    align-items: center;
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
    padding: 0;
    box-shadow: 0 0 15px rgba(0, 255, 204, 0.1) inset, 0 0 10px rgba(0, 255, 204, 0.1);
}

.deck-card:hover {
    transform: translateX(5px);
    box-shadow: 0 0 20px rgba(0, 255, 136, 0.3);
    border-color: #fff;
}

.deck-card.selected {
    border: 2px solid #fff;
    box-shadow: 0 0 30px rgba(0, 255, 204, 0.5) inset, 0 0 20px rgba(0, 255, 204, 0.5);
}

.deck-card.disabled {
    opacity: 0.2;
    filter: grayscale(1) brightness(0.5);
    cursor: not-allowed;
}

.deck-card img {
    width: auto;
    height: 100%;
    /* Make image flush */
    aspect-ratio: 2.5/3;
    object-fit: cover;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0;
    /* Flush with edge */
    margin-right: 1.5rem;
}

.deck-card-content {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.4rem;
    flex: 1;
    background: transparent;
    text-align: left;
}

.deck-card-name {
    font-size: 1.4rem;
    font-weight: bold;
    color: #fff;
    line-height: 1.2;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 1);
}

.deck-card-subtitle {
    font-size: 1rem;
    color: #ccc;
    font-style: italic;
    line-height: 1.1;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 1);
    margin-bottom: 0.4rem;
}

.deck-card-meta {
    display: flex;
    align-items: center;
    margin-top: 0;
}

.battle-details {
    font-size: 0.9rem;
    color: #ccc;
    font-family: var(--font-body);
}

.p-name {
    color: #fff;
    font-weight: bold;
}

.vs {
    color: var(--primary);
    font-weight: bold;
    font-size: 0.8rem;
    margin: 0 0.25rem;
}

.room-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Player Lists */
.player-list,
.cpu-list {
    list-style: none;
    display: flex;
    flex-direction: column;
}

/* --- Mobile Fixes --- */
@media (max-width: 768px) {

    /* Keep header horizontal but compact, wrap if necessary */
    .lobby-header {
        flex-direction: row;
        flex-wrap: wrap;
        /* allow wrapping on super narrow screens like Pixel 7 */
        gap: 0.5rem;
        padding: 0.5rem;
        justify-content: flex-start;
        /* prevent stretching */
    }

    .header-center.lobby-stats {
        gap: 1rem;
        order: 3;
        /* push stats to new line if wrapped */
        flex-basis: 100%;
        justify-content: center;
        margin-top: 0.5rem;
    }

    .brand {
        gap: 0.25rem;
    }

    .logo-icon {
        font-size: 1.5rem;
    }

    .logo-text-header {
        font-size: 1.2rem;
    }

    .header-right {
        justify-content: flex-end;
        gap: 0.5rem;
        flex: 1;
        /* let user profile take remaining width */
    }

    /* User Profile truncations for narrow viewports */
    .user-name {
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 120px;
    }

    .avatar-small {
        width: 36px;
        height: 36px;
    }

    /* Deck Cards: switch to stacked on very small screens to fit text and buttons */
    .deck-card {
        flex-direction: column;
        align-items: stretch;
        height: auto;
    }

    .deck-card img {
        width: 100%;
        height: 120px;
        aspect-ratio: auto;
        border-right: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        margin-right: 0;
    }

    .deck-card-content {
        padding: 0.75rem;
    }

    .deck-action-container {
        border-left: none !important;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        padding: 0.75rem !important;
        justify-content: flex-end;
        background: rgba(255, 255, 255, 0.02);
    }

    /* Keep content compact */
    .lobby-content {
        padding-bottom: 40px;
        /* Space for footer */
        gap: 1rem;
    }

    .lobby-section {
        padding: 1rem;
    }

    /* Allow the room list to be scrolled down naturally */
    .rooms-list-container {
        overflow-y: visible;
    }

    .room-item {
        flex-direction: column;
        align-items: flex-start;
        padding: 1rem;
        gap: 1rem;
    }

    .room-action {
        margin-left: 0;
        width: 100%;
        justify-content: flex-start;
    }

    /* Adjust font sizes and buttons so they don't break */
    .btn-primary.large {
        padding: 1rem;
        font-size: 1rem;
    }

    .stat-label {
        font-size: 0.6rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .room-name {
        font-size: 1.1rem;
    }

    /* Keep deck cards horizontal and sleek like desktop (remove height override) */
}

.player-item,
.cpu-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
}

/* Room List */
.room-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.rooms-list-container {
    padding-right: 0.5rem;
    overflow: visible;
    /* Let it overflow naturally down the page */
}

.room-item {
    background: rgba(10, 10, 12, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1.5rem 2rem;
    margin-bottom: 1rem;
    border-radius: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 110px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

.room-item:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.6);
}

.room-info {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    z-index: 1;
}

.room-name {
    font-weight: 900;
    color: #fff;
    font-size: 1.4rem;
    letter-spacing: 2px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
    text-transform: uppercase;
}

.room-details {
    font-size: 1rem;
    color: #bbb;
    font-family: var(--font-body);
    font-weight: 500;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.room-action {
    margin-left: 2rem;
    display: flex;
    gap: 12px;
    align-items: center;
    z-index: 1;
}

.btn-join {
    background: #00f2ff;
    color: #000;
    border: none;
    padding: 0.8rem 2rem;
    font-weight: 900;
    cursor: pointer;
    border-radius: 8px;
    font-family: var(--font-heading);
    transition: all 0.3s;
    letter-spacing: 1px;
    font-size: 0.9rem;
}

.btn-join:hover {
    box-shadow: 0 0 25px rgba(0, 242, 255, 0.8);
    transform: scale(1.05);
}

.btn-terminate {
    transition: all 0.2s;
}

.btn-terminate:hover {
    background: #ff0000 !important;
    transform: scale(1.1);
}

.player-item.current-user {
    border: 1px solid rgba(0, 242, 255, 0.3);
}

.player-avatar-small,
.cpu-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-left: auto;
}

.status-dot.online {
    background: #00ff88;
    box-shadow: 0 0 5px #00ff88;
}

.status-dot.busy {
    background: #ffaa00;
}

.cpu-info {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.cpu-name {
    font-weight: bold;
    font-size: 0.9rem;
}

.cpu-diff {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.btn-xs {
    padding: 0.25rem 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: transparent;
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.7rem;
}

.btn-xs:hover {
    background: #fff;
    color: #000;
}

.lobby-footer {
    width: 100%;
    max-width: 1400px;
    display: flex;
    justify-content: flex-end;
    margin-top: 2rem;
}

.btn-primary.large {
    padding: 1.25rem 3rem;
    font-size: 1.2rem;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: #111;
    border: 2px solid var(--primary);
    padding: 2rem;
    border-radius: 12px;
    width: 100%;
    max-width: 500px;
    box-shadow: 0 0 50px rgba(0, 255, 255, 0.2);
}

.modal-content h2 {
    font-family: var(--font-heading);
    color: #fff;
    margin-bottom: 2rem;
    text-align: center;
}

.form-group {
    margin-bottom: 2rem;
}

.form-group label {
    display: block;
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2rem;
}

.btn-secondary {
    background: transparent;
    border: 1px solid #666;
    color: #bbb;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-heading);
    transition: all 0.2s;
}

.btn-secondary:hover {
    border-color: #fff;
    color: #fff;
}

.glitch-input {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #444;
    color: #fff;
    padding: 0.5rem;
    width: 100%;
    font-family: var(--font-body);
}

/* AUTH SCREEN REWORK */
.auth-container {
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.auth-tabs {
    display: flex;
    gap: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.5rem;
}

.auth-tab {
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    padding: 0.5rem 1rem;
    transition: all 0.2s;
}

.auth-tab.active {
    color: var(--primary);
    text-shadow: 0 0 10px var(--primary);
    border-bottom: 2px solid var(--primary);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    animation: fadeIn 0.3s ease-out;
}

.auth-form.hidden {
    display: none;
}

.full-width {
    width: 100%;
}

.guest-option {
    text-align: center;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 1rem;
}

.btn-icon {
    font-weight: bold;
    margin-right: 0.5rem;
    color: #fff;
}

/* Opponent Selection Grid */
.opponent-grid {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: 10px;
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 20px;
    padding-right: 5px;
}

.opponent-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 10px;
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 8px;
}

.opponent-card:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary);
}

.opponent-card.selected {
    background: rgba(0, 242, 255, 0.1);
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(0, 242, 255, 0.2);
}

.opponent-avatar {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    margin-right: 15px;
    object-fit: cover;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.opponent-info {
    display: flex;
    flex-direction: column;
}

.opponent-name {
    font-weight: bold;
    font-size: 0.9em;
    color: var(--text-main);
}

.opponent-difficulty {
    font-size: 0.75em;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* --- Create Modal 2-Step Styles --- */
.create-page.hidden {
    display: none;
}

.rules-group button {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: var(--font-heading);
    font-size: 0.8rem;
    letter-spacing: 1px;
    border-radius: 4px;
    text-transform: uppercase;
    font-weight: bold;
}

.rules-group button:hover {
    background: rgba(0, 242, 255, 0.1);
    border-color: var(--primary) !important;
}

.rules-group button.active {
    background: var(--primary) !important;
    color: #000 !important;
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.4);
}

.deck-info-display {
    border-radius: 8px;
    animation: slideInRight 0.4s ease-out;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.glitch-input {
    width: 100%;
}

#btn-back-create {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}