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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #1a1a2e;
    color: #fff;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Login Screen */
#login {
    text-align: center;
}

#login h1 {
    font-size: clamp(2rem, 5vw, 3.5rem);
    margin-bottom: 2rem;
    color: #d96704;
}

#login input {
    width: clamp(250px, 60vw, 350px);
    padding: 1rem;
    margin-bottom: 1rem;
    background: #16213e;
    border: 2px solid #d96704;
    border-radius: 8px;
    color: #fff;
    font-size: 1rem;
}

#login input:focus {
    outline: none;
    border-color: #ff8c1a;
}

#login button {
    width: clamp(250px, 60vw, 350px);
    padding: 1rem;
    background: #d96704;
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

#login button:hover {
    background: #a84b02;
}

/* Game Screen */
#game {
    width: 100%;
    max-width: 100vw;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#game h1 {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    margin-bottom: 1.5rem;
    color: #d96704;
    text-align: center;
}

.game-container {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 1.5rem;
}

.reroll-btn {
    background: transparent;
    border: 2px solid #d96704;
    color: #d96704;
    font-size: 1.2rem;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.reroll-btn:hover {
    background: #d96704;
    color: #fff;
    transform: scale(1.1) rotate(-180deg);
}

/* Players List */
#players {
    background: rgba(22, 33, 62, 0.95);
    padding: 1.25rem;
    border-radius: 12px;
    border: 2px solid #d96704;
    width: 220px;
    backdrop-filter: blur(10px);
    flex-shrink: 0;
}

#players h3 {
    color: #ff8c1a;
    margin-bottom: 0.75rem;
    font-size: 1.1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid rgba(217, 103, 4, 0.3);
    padding-bottom: 0.5rem;
}

#players ul {
    list-style: none;
}

#players li {
    padding: 0.4rem 0;
    font-size: 0.95rem;
    color: rgba(255, 255, 255, 0.9);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#players li.self {
    color: #ff8c1a;
}

#players .player-name {
    flex: 1;
}

#players .wins {
    background: #d96704;
    color: white;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.85rem;
    min-width: 1.5rem;
    text-align: center;
}

/* Bingo Card */
#card {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5rem;
    width: min(calc(100vh - 10rem), 55vw, calc(100vw - 16rem));
    aspect-ratio: 1;
    margin: 0 auto;
}

.cell {
    background: #16213e;
    border: 2px solid #d96704;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 0.5rem;
    font-size: clamp(0.6rem, 1vw, 0.9rem);
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
    animation: cellAppear 0.25s ease-out forwards;
    opacity: 0;
}

.cell.mark-animation {
    animation: cellFlip 0.25s ease-in-out;
}

.cell:hover:not(.free) {
    border-color: #ff8c1a;
    box-shadow: 0 0 30px rgba(217, 103, 4, 1);
    transform: scale(1.05) !important;
}

.cell.marked {
    background: #d96704;
    border-color: #ff8c1a;
}

.cell.free {
    background: #a84b02;
    cursor: default;
    font-weight: 600;
}

/* Celebration */
#celebration {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s;
    overflow: hidden;
}

#celebration::before {
    content: '🎉';
    position: absolute;
    font-size: 3rem;
    animation: confetti 3s infinite;
    top: -10%;
    left: 20%;
}

#celebration::after {
    content: '✨';
    position: absolute;
    font-size: 2.5rem;
    animation: confetti 3s infinite 0.5s;
    top: -10%;
    right: 20%;
}

#celebration .content {
    background: #16213e;
    padding: 3rem;
    border-radius: 16px;
    border: 3px solid #d96704;
    text-align: center;
    animation: scaleIn 0.5s, pulse 2s ease-in-out infinite 1s;
    box-shadow: 0 0 40px rgba(217, 103, 4, 0.5);
    position: relative;
    z-index: 10;
}

#celebration h2 {
    font-size: 3rem;
    color: #ff8c1a;
    margin-bottom: 1rem;
    animation: rainbow 2s linear infinite;
}

#celebration p {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
}

#celebration button {
    padding: 1rem 2rem;
    background: #d96704;
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

#celebration button:hover {
    background: #a84b02;
}

.confetti-piece {
    position: absolute;
    top: -10%;
    animation: confetti-fall 4s linear infinite;
    pointer-events: none;
    z-index: 1;
}

/* Winner Display */
#winner {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

#winner .content {
    background: #16213e;
    padding: 2rem;
    border-radius: 16px;
    border: 3px solid #d96704;
    text-align: center;
    max-width: 95vw;
    max-height: 95vh;
    overflow: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#winner h2 {
    color: #ff8c1a;
    margin-bottom: 1.5rem;
    font-size: clamp(1.5rem, 4vw, 2rem);
}

#winner-card {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.3rem;
    width: min(70vw, 500px);
    aspect-ratio: 1;
    margin-bottom: 1.5rem;
}

#winner-card .cell {
    font-size: clamp(0.5rem, 0.8vw, 0.7rem);
    padding: 0.3rem;
}

#winner button {
    padding: 0.75rem 2rem;
    background: #d96704;
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

#winner button:hover {
    background: #a84b02;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes scaleIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

@keyframes confetti {
    0% {
        transform: translateY(-10vh) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translateY(110vh) rotate(720deg);
        opacity: 0.5;
    }
}

@keyframes rainbow {
    0% {
        color: #ff8c1a;
    }

    25% {
        color: #ffd700;
    }

    50% {
        color: #ff8c1a;
    }

    75% {
        color: #ffb84d;
    }

    100% {
        color: #ff8c1a;
    }
}

@keyframes confetti-fall {
    0% {
        transform: translateY(-10vh) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translateY(110vh) rotate(1080deg);
        opacity: 0;
    }
}

@keyframes reroll {
    0% {
        transform: rotateY(0deg) rotateX(0deg) scale(1);
        opacity: 1;
    }

    50% {
        transform: rotateY(180deg) rotateX(10deg) scale(1.05);
        opacity: 0.6;
    }

    100% {
        transform: rotateY(360deg) rotateX(0deg) scale(1);
        opacity: 1;
    }
}

@keyframes cellAppear {
    0% {
        opacity: 0;
        transform: scale(0.8) rotateY(-90deg);
    }

    100% {
        opacity: 1;
        transform: scale(1) rotateY(0deg);
    }
}

@keyframes cellFlip {
    0% {
        transform: rotateY(0deg) scale(1);
    }

    50% {
        transform: rotateY(90deg) scale(1.1);
    }

    100% {
        transform: rotateY(0deg) scale(1);
    }
}

/* Mobile */
@media (max-width: 768px) {
    #game {
        padding-right: 1rem;
    }

    #players {
        position: static;
        margin-bottom: 1rem;
        max-width: 100%;
    }

    #card {
        width: min(90vw, calc(100vh - 15rem));
    }

    .cell {
        font-size: 0.7rem;
    }
}