/* Bingo board layout */
#bingoCard {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 10px;
    padding: 10px;
    width: 100%;
    max-width: calc(min(100vh - 52px, 100vh - 350px));
    max-height: calc(min(100vh - 52px, 100vh - 350px));
    height: calc(min(100vh - 52px, 100vh - 350px));
    margin: 0 auto;
    aspect-ratio: 1;
}

/* Ensure no wrapping or overflow */
#bingoCard > * {
    grid-column: auto !important;
    grid-row: auto !important;
}

/* Bingo cell styling */
.bingo-cell {
    position: relative;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(255, 0, 0, 0.1);
    border: 2px solid #ddd;
    border-radius: var(--border-radius);
    overflow: hidden;
    padding: 0;
    transition: all 0.3s ease;
    cursor: pointer;
    background: white;
    width: 100%;
    height: 100%;

    /* Background image settings */
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
    background-blend-mode: overlay;
}

.bingo-cell span {
    position: relative;
    z-index: 1;
    padding: var(--spacing-sm);
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: var(--border-radius);
    font-weight: 500;
    font-size: clamp(0.7rem, 2vmin, 1rem);
    text-align: center;
    max-width: 90%;
    word-break: break-word;
}

.bingo-cell img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.3;
    transition: opacity 0.3s ease;
}

/* Bingo states */
.bingo-cell.selected {
    border-color: var(--accent-color);
    transform: scale(0.98);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
}

.bingo-cell.bingo-row {
    background-color: rgba(76, 175, 80, 0.3) !important;
    border-color: var(--success-color);
}

.bingo-cell.bingo-column {
    background-color: rgba(33, 150, 243, 0.3) !important;
    border-color: #2196F3;
}

.bingo-cell.bingo-diagonal {
    background-color: rgba(156, 39, 176, 0.3) !important;
    border-color: #9C27B0;
}

.bingo-cell.bingo-multiple {
    background-color: rgba(255, 193, 7, 0.3) !important;
    border-color: #FFC107;
    animation: pulse 2s infinite;
}

.bingo-cell.super-bingo {
    background-color: rgba(255, 215, 0, 0.4) !important;
    border-color: gold;
    animation: superPulse 1.5s infinite;
}

/* Star icon in FREE space */
.star-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    height: 80%;
    color: var(--accent-color);
    opacity: 0.3;
    z-index: 0;
}

/* Celebration elements */
#confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
}

.confetti {
    position: fixed;
    width: 10px;
    height: 10px;
    pointer-events: none;
    z-index: 1000;
    animation: shoot-out 2s forwards cubic-bezier(0.05, 0.9, 0.25, 1);
}

@keyframes shoot-out {
    0% {
        transform: translate(-50%, -50%) scale(0.1) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translate(var(--final-x), var(--final-y)) scale(1) rotate(var(--rotation));
        opacity: 0;
    }
}

.celebration-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem;
    font-weight: bold;
    color: var(--accent-color);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    animation: celebrate 1s ease-in-out infinite;
    z-index: 1001;
}

/* Animations */
@keyframes fall {
    0% {
        transform: translateY(-10vh) rotate(var(--rotation));
        opacity: 1;
    }
    70% {
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(calc(var(--rotation) + 360deg));
        opacity: 0;
    }
}

@keyframes celebrate {
    0%, 100% {
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        transform: translate(-50%, -50%) scale(1.1);
    }
}

@keyframes pulse {
    0% { transform: scale(0.98); }
    50% { transform: scale(1); }
    100% { transform: scale(0.98); }
}

@keyframes superPulse {
    0% {
        transform: scale(0.98);
        box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.4);
    }
    70% {
        transform: scale(1);
        box-shadow: 0 0 0 10px rgba(255, 215, 0, 0);
    }
    100% {
        transform: scale(0.98);
        box-shadow: 0 0 0 0 rgba(255, 215, 0, 0);
    }
}

/* Update FREE space specific styles */
.bingo-cell.free-space {
    background-color: white;
}

.bingo-cell.free-space span {
    font-weight: bold;
    color: var(--primary-dark);
    z-index: 1;
    background-color: transparent;
}

.bingo-cell.free-space.selected {
    background-color: var(--primary-dark);
}

.bingo-cell.free-space.selected span {
    color: white;
}

.bingo-cell.free-space.selected .star-icon {
    color: white;
    opacity: 0.2;
}

.free-space .cell-text {
    font-size: 1.5rem;
    line-height: 1.2;
    text-align: center;
}

.free-space .cell-text:first-line {
    font-size: 2rem; /* Bigger star */
}

.free-space .cell-content {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    width: 100%;
    perspective: 1000px; /* Adds depth perception */
}

.star-background {
    position: absolute;
    width: 90%;
    height: 90%;
    z-index: 1;
    transition: all 0.3s ease;
    transform: rotateY(10deg) rotateX(10deg); /* Slight rotation for 3D effect */
    pointer-events: none; /* Ensures clicks pass through */
}

.free-text {
    position: relative;
    z-index: 2;
    font-size: 1.2em;
    font-weight: bold;
    text-align: center;
    line-height: 1.2;
    color: var(--text-primary);
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2); /* Enhanced shadow for depth */
    pointer-events: none; /* Ensures clicks pass through */
}

.free-space.marked .star-background {
    opacity: 1;
    transform: rotateY(0deg) rotateX(0deg) scale(1.05); /* Animation when marked */
}

/* Add hover effect */
.free-space:hover .star-background {
    transform: rotateY(15deg) rotateX(15deg) scale(1.02);
}

.free-space .cell-content * {
    pointer-events: none; /* Prevents SVG and text from capturing clicks */
}

.bingo-cell.marked {
    background-color: rgba(255, 215, 0, 0.2);
    border-color: #FFD700;
}

.bingo-cell.marked .cell-content {
    transform: scale(0.95); /* Slight shrink effect */
}

.bingo-cell.winner {
    background-color: rgba(76, 175, 80, 0.3);
    border-color: #4CAF50;
    animation: winPulse 1s forwards;
}

/* Winner celebration animation */
@keyframes winPulse {
    0% {
        transform: scale(1);
        background-color: rgba(76, 175, 80, 0.1);
    }
    50% {
        transform: scale(1.05);
        background-color: rgba(76, 175, 80, 0.3);
    }
    100% {
        transform: scale(1);
        background-color: rgba(76, 175, 80, 0.2);
    }
}

.cell-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 5px;
    text-align: center;
    position: relative; /* For absolute positioning of images */
}

.cell-content img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover; /* This will fill the space while maintaining aspect ratio */
    opacity: 0.3; /* Make the image more subtle */
    z-index: 1;
}

.cell-text {
    position: relative;
    z-index: 2;
    font-size: 1.2em;
    line-height: 1.2;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 90%;
    padding: 5px;
    background-color: rgba(255, 255, 255, 0.8); /* Semi-transparent background for better readability */
    border-radius: 4px;
    text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.5);
    font-weight: bold;
}

/* Responsive font sizes */
@media (min-width: 768px) {
    .cell-text {
        font-size: 1.4em;
    }
}

/* Make sure FREE space still works correctly */
.free-space .cell-content {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    width: 100%;
}

.free-space .cell-content * {
    pointer-events: none;
}

.star-background {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    height: 80%;
    z-index: 1;
}

.free-text {
    position: relative;
    z-index: 2;
    font-size: 1.4em;
    font-weight: bold;
}

/* Add hover effect */
.bingo-cell:hover {
    transform: scale(1.02);
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* Active click state */
.bingo-cell:active {
    transform: scale(0.98);
}

.bingo-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    font-size: 4rem;
    font-weight: bold;
    color: #FFD700;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
}

.bingo-message.show {
    animation: bingoAppear 1.5s ease-out forwards;
}

@keyframes bingoAppear {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0;
    }
}

/* Make text more readable on colored backgrounds */
.cell-text {
    color: #333;
    font-weight: 500;
    text-shadow: 1px 1px 1px rgba(255,255,255,0.5);
}

.cell-content img {
    max-width: 80%;
    max-height: 60%;
    object-fit: contain;
    margin-bottom: 5px;
}

.bingo-cell {
    aspect-ratio: 1;
    width: 100%;
    height: 100%;
    border: 2px solid #ddd;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    background-color: rgba(255, 0, 0, 0.1);
    overflow: hidden; /* Ensure images don't spill out */
}

.cell-content {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(255, 255, 255, 0.7); /* This creates the overlay effect */
}

/* Regular cell background images */
.background-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.3;
    z-index: 1;
}

.cell-text {
    position: relative;
    z-index: 2;
    font-size: 1.2em;
    line-height: 1.2;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 90%;
    background-color: rgba(255, 255, 255, 0.8);
    padding: 5px 10px;
    border-radius: 4px;
    font-weight: bold;
    text-align: center;
}

/* FREE space specific styles */
.free-space .cell-content {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: transparent;
}

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

.free-text {
    position: relative;
    z-index: 2;
    font-size: 1.4em;
    font-weight: bold;
    text-align: center;
    line-height: 1.2;
    background-color: rgba(255, 255, 255, 0.8);
    padding: 5px 10px;
    border-radius: 4px;
}

/* Responsive text size */
@media (min-width: 768px) {
    .cell-text {
        font-size: 1.4em;
    }
}