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

html, body {
    height: 100%;
}

body {
    font-family: "Comic Sans MS", "Chalkboard SE", "Marker Felt", cursive, sans-serif;
    background: linear-gradient(160deg, #3b0a6b 0%, #7b2ff7 45%, #b362ff 75%, #ff9ff3 100%);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
}

/* Flying creatures behind everything */
#sky {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

.flyer {
    position: absolute;
    will-change: transform;
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.5));
}

main {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 16px;
}

/* Dancing rainbow title letters */
#title {
    font-size: clamp(1.6rem, 5vw, 3rem);
    margin-bottom: 12px;
    letter-spacing: 2px;
}

#title span {
    display: inline-block;
    animation: letter-dance 0.45s ease-in-out infinite alternate;
    text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
}

@keyframes letter-dance {
    from { transform: translateY(-6px) rotate(-8deg) scale(1); }
    to   { transform: translateY(6px) rotate(8deg) scale(1.15); }
}

#status {
    font-size: clamp(1.1rem, 3.5vw, 1.6rem);
    color: #fff;
    background: rgba(75, 0, 130, 0.55);
    border: 3px solid #e6b3ff;
    border-radius: 999px;
    padding: 8px 24px;
    display: inline-block;
    margin-bottom: 16px;
    animation: status-bounce 0.5s ease-in-out infinite alternate;
}

@keyframes status-bounce {
    from { transform: scale(1); }
    to   { transform: scale(1.06); }
}

#board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    width: min(72vw, 60vh, 420px);
    margin: 0 auto 18px;
}

.cell {
    aspect-ratio: 1;
    font-size: clamp(2.2rem, 9vw, 4.5rem);
    background: rgba(255, 255, 255, 0.22);
    border: 4px solid #d9a7ff;
    border-radius: 22px;
    cursor: pointer;
    transition: background 0.1s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
}

.cell:hover:not(.taken) {
    background: rgba(255, 255, 255, 0.45);
    transform: scale(1.08) rotate(-3deg);
}

.cell.taken {
    cursor: default;
}

/* Placed pieces zoom in fast, then keep dancing fast */
.cell .piece {
    display: inline-block;
    animation:
        pop-in 0.25s cubic-bezier(0.2, 2.5, 0.4, 1),
        piece-dance 0.35s ease-in-out 0.25s infinite alternate;
}

@keyframes pop-in {
    from { transform: scale(0) rotate(-720deg); }
    to   { transform: scale(1) rotate(0deg); }
}

@keyframes piece-dance {
    from { transform: translateY(-5px) rotate(-12deg) scale(1); }
    to   { transform: translateY(5px) rotate(12deg) scale(1.12); }
}

/* Winning cells flash rainbow */
.cell.winner {
    animation: rainbow-flash 0.4s linear infinite;
    border-color: #fff;
}

@keyframes rainbow-flash {
    0%   { background: #ff6b6b; }
    20%  { background: #ffa94d; }
    40%  { background: #ffe066; }
    60%  { background: #69db7c; }
    80%  { background: #74c0fc; }
    100% { background: #d0a9ff; }
}

#controls {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

#controls button {
    font-family: inherit;
    font-size: clamp(0.9rem, 2.8vw, 1.15rem);
    color: #4b0082;
    background: #ffe6ff;
    border: 3px solid #b362ff;
    border-radius: 999px;
    padding: 10px 20px;
    cursor: pointer;
    box-shadow: 0 4px 0 #8a2be2;
    transition: transform 0.1s, box-shadow 0.1s;
}

#controls button:hover {
    transform: translateY(-2px) scale(1.05);
}

#controls button:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 #8a2be2;
}

/* Confetti pieces */
.confetti {
    position: fixed;
    z-index: 2;
    pointer-events: none;
    will-change: transform;
    font-size: 1.6rem;
}
