:root {
    /* Responsive sizing based on viewport */
    --card-width: min(13vw, calc((100vh - 120px) / 8.5), 160px);
    --card-height: calc(var(--card-width) * 1.5);
    --card-overlap: calc(var(--card-height) * -0.42);
    --card-margin: calc(var(--card-width) * 0.05);
}

body {
    font-family: Arial, sans-serif;
    background-color: #2d1b2d;
    background-image: url('assets/cat_30.webp');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: white;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
}

#game-container {
    max-width: 1000px;
    width: 100%;
    padding: 10px;
    text-align: center;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2vh;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px 20px;
    border-radius: 10px;
}

.header-left {
    display: flex;
    gap: 15px;
    align-items: center;
}

.header-left h1 {
    margin: 0;
    font-size: clamp(1rem, 3vw, 1.2rem);
}

#score {
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    font-weight: bold;
    color: #ffeb3b;
}

#timer {
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    font-weight: bold;
    color: #ffffff;
}

#status {
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    font-weight: bold;
    color: #ff5252;
}

.header-right {
    display: flex;
    gap: 10px;
    align-items: center;
}

.icon-btn {
    font-size: clamp(1rem, 3vw, 1.2rem);
    padding: 5px 8px;
    background: none;
    border: 2px solid white;
    border-radius: 50%;
    color: white;
}

button {
    padding: 6px 12px;
    background-color: #ffffff;
    color: #2e7d32;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    font-size: clamp(0.8rem, 2.5vw, 0.9rem);
}

button:hover {
    background-color: #e0e0e0;
}

#pyramid-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 2vh;
    flex-grow: 1;
    justify-content: center;
}

.pyramid-row {
    display: flex;
    justify-content: center;
    margin-top: var(--card-overlap);
}
.pyramid-row:first-child {
    margin-top: 0;
}

.card {
    width: var(--card-width);
    height: var(--card-height);
    background-color: transparent;
    margin: 0 var(--card-margin);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    perspective: 1000px;
    transform-style: preserve-3d;
}

.card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform 0.6s;
    transform-style: preserve-3d;
}

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

.card.selected .card-inner {
    box-shadow: 0 0 12px 4px #ffeb3b;
    transform: rotateY(180deg) translateY(-5px);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 6px;
    box-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    overflow: hidden;
}

.card-front-face {
    transform: rotateY(180deg);
    background-color: white;
}

.card-back-face {
    background-color: transparent;
}

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

.card-back {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card.empty .card-inner {
    display: none;
}
.card.empty {
    border: none;
    box-shadow: none;
    cursor: default;
    background: transparent;
    pointer-events: none;
}

.red {
    color: #d32f2f;
}

.black {
    color: #212121;
}

#bottom-area {
    display: flex;
    justify-content: center;
}

.deck-area {
    display: flex;
    gap: 20px;
}

/* For the stock and waste which don't flip in 3d */
.simple-card {
    width: var(--card-width);
    height: var(--card-height);
    border-radius: 6px;
    box-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    overflow: hidden;
    cursor: pointer;
}
.simple-card.selected {
    box-shadow: 0 0 12px 4px #ffeb3b;
    transform: translateY(-5px);
}
.simple-card.empty {
    box-shadow: none;
    border: none;
    cursor: default;
    background: transparent;
}

.floating-emoji {
    position: fixed;
    font-size: 3rem;
    pointer-events: none;
    animation: floatRandom 3s ease-in forwards;
    z-index: 1000;
}

@keyframes floatRandom {
    0% {
        transform: translateY(0) scale(0.5) rotate(-20deg);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    100% {
        transform: translateY(-100vh) scale(1.5) rotate(20deg);
        opacity: 0;
    }
}

@keyframes slideAndTurn {
    0% {
        transform: translateX(calc(-1 * (var(--card-width) + 20px))) rotateY(-180deg) scale(1);
    }
    40% {
        transform: translateX(calc(-0.4 * (var(--card-width) + 20px))) rotateY(-180deg) scale(1.1);
    }
    100% {
        transform: translateX(0) rotateY(0) scale(1);
    }
}
.slide-turn-anim {
    animation: slideAndTurn 0.4s ease-out forwards;
}

@keyframes matchDisappear {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.8; }
    100% { transform: scale(0) rotate(15deg); opacity: 0; }
}

.match-anim {
    animation: matchDisappear 0.5s forwards ease-out;
    pointer-events: none;
    box-shadow: 0 0 15px 5px #ffeb3b !important;
    border-radius: 6px;
}

/* Game Over Popup */
#game-over-popup {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}
#game-over-popup.hidden {
    display: none;
}
.popup-content {
    background: #2d1b2d;
    padding: 30px;
    border-radius: 15px;
    border: 3px solid #ffeb3b;
    text-align: center;
    color: white;
    width: 600px;
    height: 400px;
    box-sizing: border-box;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
}
.popup-left {
    display: flex;
    flex-direction: column;
    align-items: center;
}
#popup-emoji {
    font-size: 5rem;
    margin: 15px 0;
}
#popup-score {
    font-size: 1.5rem;
    font-weight: bold;
    color: #ffeb3b;
}
#btn-share-popup {
    width: 175px;
    text-align: center;
}

/* Scoreboard */
#scoreboard {
    background: rgba(0, 0, 0, 0.6);
    padding: 15px;
    border-radius: 10px;
    width: 220px;
    height: 100%;
    box-sizing: border-box;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
#scoreboard h3 {
    margin-top: 0;
    margin-bottom: 10px;
    color: #ffeb3b;
    font-size: 1.2rem;
}
#score-list {
    list-style-position: inside;
    padding: 0;
    margin: 0;
    text-align: left;
    display: flex;
    flex-direction: column;
}
#score-list li {
    padding: 4px 5px;
    border-bottom: 1px solid rgba(255,255,255,0.2);
    font-size: 0.9rem;
}
#score-list li.highlight {
    background: rgba(255, 235, 59, 0.3);
    font-weight: bold;
    color: #ffeb3b;
}
