:root {
    --clr-primary: #2d5a27;
    --clr-accent: #d4af37;
    --clr-bg: #1a1a1a;
    --clr-glass: rgba(255, 255, 255, 0.1);
    --clr-glass-border: rgba(255, 255, 255, 0.2);
    --clr-text: #ffffff;
    --font-main: 'Outfit', sans-serif;
    --transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

body {
    font-family: var(--font-main);
    background: radial-gradient(circle at center, #2c3e50 0%, #000000 100%);
    color: var(--clr-text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
}

#app {
    width: 100%;
    max-width: 1200px;
    min-height: 100vh;
    padding: 1rem;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    /* Optimization to avoid large top margin */
}

.screen {
    position: relative;
    /* Changed from absolute to allow natural flow if needed */
    margin: 0 auto;
    width: 100%;
    max-width: 800px;
    opacity: 0;
    visibility: hidden;
    display: none;
    /* Changed to none when not active */
    transition: var(--transition);
}

.screen.active {
    opacity: 1;
    visibility: visible;
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 10;
    animation: fadeIn 0.5s forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.glass-panel {
    background: var(--clr-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--clr-glass-border);
    border-radius: 30px;
    padding: 3rem;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

h1 {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 1rem;
    color: var(--clr-accent);
}

p {
    margin-bottom: 2rem;
    opacity: 0.8;
}

.main-logo {
    height: 120px;
    margin-bottom: 2rem;
    filter: drop-shadow(0 0 20px rgba(212, 175, 55, 0.3));
}

/* Player Selector */
.player-selector {
    margin: 2rem 0;
}

.button-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    margin-top: 1rem;
}

.count-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--clr-glass-border);
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 700;
    font-size: 1.1rem;
    transition: var(--transition);
    display: flex;
    justify-content: center;
    align-items: center;
}

.count-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.count-btn.selected {
    background: var(--clr-accent);
    color: #000;
    border-color: var(--clr-accent);
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.4);
}

.player-names {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
    max-height: 250px;
    overflow-y: auto;
    padding: 1rem;
}

.player-input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--clr-glass-border);
    border-radius: 10px;
    padding: 0.75rem;
    color: white;
    width: 100%;
}

/* Buttons */
.btn-primary {
    background: var(--clr-accent);
    color: #000;
    border: none;
    padding: 1rem 3rem;
    border-radius: 50px;
    font-weight: 800;
    font-size: 1.1rem;
    cursor: pointer;
    transition: var(--transition);
    text-transform: uppercase;
    touch-action: manipulation;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-5px) scale(1.05);
    box-shadow: 0 10px 20px rgba(212, 175, 55, 0.4);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--clr-accent);
    color: var(--clr-accent);
    padding: 0.8rem 2rem;
    border-radius: 50px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

/* Game Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3rem;
    width: 100%;
    position: relative;
}

.current-turn .name {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--clr-accent);
    display: block;
}

.btn-quit {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--transition);
    backdrop-filter: blur(5px);
}

.btn-quit:hover {
    background: #e74c3c;
    border-color: #e74c3c;
    transform: scale(1.1);
}

/* Card Area */
.card-area {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4rem;
    margin-bottom: 3rem;
}

.deck-container {
    position: relative;
    width: 250px;
    height: 350px;
}

.deck-stacks {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: 1;
}

.card-back-stack {
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #2d5a27 0%, #1e3c1a 100%);
    border-radius: 15px;
    border: 3px solid var(--clr-accent);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    z-index: 1;
}

.draw-pile {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 5;
}

.card-face {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #2d5a27 0%, #1e3c1a 100%);
    border-radius: 15px;
    border: 4px solid var(--clr-accent);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--transition);
    overflow: hidden;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}

.card-face img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.card-back-content {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    background: radial-gradient(circle at center, rgba(212, 175, 55, 0.1) 0%, transparent 70%);
}

.card-back-content img {
    width: 65%;
    height: auto;
    opacity: 0.9;
    filter: drop-shadow(0 0 10px rgba(0, 0, 0, 0.5));
}

.clickable {
    cursor: pointer;
}

.clickable:hover {
    transform: translateY(-10px) rotate(-2deg);
}

/* Active Card */
.active-card-container {
    width: 320px;
    /* Reduced fixed size */
    height: 460px;
    perspective: 1500px;
}

.active-card {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.active-card.flipped {
    transform: rotateY(180deg);
}

.card-side {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 20px;
    border: 4px solid var(--clr-accent);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
    background: #1a1a1a;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.card-side img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Ensures the full image is visible without being truncated */
}

.card-side.front {
    transform: rotateY(180deg);
}

.card-side.back {
    background: var(--clr-primary);
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.score-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--clr-glass-border);
}

.score-controls {
    display: flex;
    gap: 0.5rem;
}

.score-controls button {
    background: var(--clr-glass);
    border: 1px solid var(--clr-accent);
    color: var(--clr-accent);
    width: 30px;
    height: 30px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
}

.score-controls button:hover {
    background: var(--clr-accent);
    color: #000;
}

.close-modal {
    margin-top: 2rem;
    margin-bottom: 0.5rem;
}

.modal-content {
    max-width: 500px;
    width: 90%;
}

#scoreboard-list {
    margin-bottom: 1.5rem;
    max-height: 60vh;
    overflow-y: auto;
}

.winner-banner {
    font-size: 4rem;
    font-weight: 900;
    color: var(--clr-accent);
    text-shadow: 0 0 30px rgba(212, 175, 55, 0.5);
    margin: 2rem 0;
}

.text-center {
    text-align: center;
}

/* Animations */
@keyframes drawCard {
    from {
        transform: translate(0, 0) rotate(0);
        opacity: 0;
    }

    to {
        transform: translate(0, 0) rotate(0);
        opacity: 1;
    }
}

.game-controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

/* Mobile Adjustments */
@media (max-width: 968px) {
    #app {
        padding: 0;
        height: 100vh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    #setup-screen {
        justify-content: center;
        padding: 1rem;
    }

    #game-screen {
        justify-content: flex-start;
    }

    .glass-panel {
        padding: 1.5rem;
        border-radius: 20px;
    }

    h1 {
        font-size: 2rem;
    }

    .main-logo {
        height: 80px;
        margin-bottom: 1.5rem;
    }

    .card-area {
        flex: 1;
        display: grid;
        grid-template-areas: "card";
        place-items: center;
        width: 100%;
        margin: 0;
        position: relative;
    }

    /* Hide deck when card is active on small screens to save space */
    #deck.has-active-card {
        display: none;
    }

    .deck-container {
        width: 140px;
        height: 200px;
    }

    .active-card-container {
        width: 90vw;
        max-width: 350px;
        height: auto;
        aspect-ratio: 250 / 350;
    }



    .game-header {
        margin-bottom: 1.5rem;
        flex-direction: row;
        font-size: 0.9rem;
    }

    .current-turn .name {
        font-size: 1.1rem;
    }

    .btn-primary {
        padding: 0.8rem 2rem;
        font-size: 1rem;
    }

    .winner-banner {
        font-size: 2.5rem;
    }

    .player-names {
        grid-template-columns: 1fr 1fr;
        max-height: 200px;
        padding: 0.5rem;
    }
}

@media (max-width: 480px) {
    #app {
        padding: 0;
        height: 100vh;
        overflow: hidden;
    }

    .screen.active {
        height: 100vh;
        position: relative;
        display: flex;
        flex-direction: column;
    }

    .game-header {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        padding: 10px 15px;
        z-index: 100;
        background: linear-gradient(to bottom, rgba(0, 0, 0, 0.8) 0%, transparent 100%);
        margin-bottom: 0 !important;
        pointer-events: none;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .game-header>* {
        pointer-events: auto;
    }

    .player-names {
        grid-template-columns: 1fr;
    }

    .count-btn {
        width: 40px;
        height: 40px;
        font-size: 0.9rem;
    }

    .screen .card-area {
        flex: 1;
        margin: 0;
        padding: 0;
        display: grid;
        grid-template-areas: "card";
        place-items: center;
        width: 100vw;
        height: 100vh;
    }

    .deck-container,
    .active-card-container {
        grid-area: card;
        width: 95vw;
        max-width: none;
        height: auto;
        aspect-ratio: 250 / 350;
        margin: auto;
        max-height: 85vh;
        z-index: 10;
        position: relative;
    }

    .deck-container {
        z-index: 20;
        /* Ensure deck is above empty active container */
    }

    .active-card-container:empty {
        display: none;
    }

    .active-card-container .active-card {
        border-radius: 15px;
        box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    }

    /* Keep deck hidden but same size when active card is there */
    #deck.has-active-card {
        display: none;
    }

    .deck-container {
        /* Ensure the deck looks like a card even when alone */
        display: flex;
        justify-content: center;
        align-items: center;
    }


    #game-screen .game-controls {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        padding: 15px;
        z-index: 100;
        background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, transparent 100%);
        margin: 0 !important;
        gap: 8px;
    }

    .modal .game-controls {
        position: relative;
        margin-top: 2rem;
        margin-bottom: 1rem;
        background: none;
        padding: 0;
    }

    .btn-primary,
    .btn-outline {
        padding: 0.8rem;
        font-size: 0.95rem;
    }
}

/* Landscape orientation on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .screen {
        top: 0;
        transform: none;
        position: relative;
        left: 0;
        margin-top: 2rem;
    }

    .card-area {
        flex-direction: row;
        gap: 2rem;
    }

    .main-logo {
        height: 50px;
    }
}