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

body {
    font-family: 'Arial', sans-serif;
    background: #000000;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    position: relative;
    overflow: hidden;
}

.container {
    text-align: center;
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

h1 {
    color: white;
    font-size: clamp(1.5rem, 4vw, 3rem);
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.game-info {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 10px;
    font-size: clamp(0.8rem, 2vw, 1.2rem);
}

.current-player {
    background: rgba(255, 255, 255, 0.15);
    padding: clamp(10px, 2vw, 18px) clamp(20px, 3vw, 35px);
    border-radius: 15px;
    font-weight: bold;
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    backdrop-filter: blur(10px);
}

.player-red {
    color: #ff6b6b;
}

.player-yellow {
    color: #ffd93d;
}

.thinking-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

.thinking-spinner.hidden {
    display: none;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.button-group {
    display: flex;
    gap: 10px;
}

#two-player-btn,
.ai-btn {
    background: white;
    border: none;
    padding: clamp(6px, 1.5vw, 12px) clamp(10px, 2vw, 20px);
    font-size: clamp(0.7rem, 1.8vw, 0.95rem);
    font-weight: bold;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

#two-player-btn:hover,
.ai-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
}

#two-player-btn:active,
.ai-btn:active,
#undo-btn:active:not(:disabled) {
    transform: translateY(0);
}

#undo-btn {
    background: #ff6b6b;
    color: white;
    border: none;
    padding: clamp(6px, 1.5vw, 12px) clamp(10px, 2vw, 20px);
    font-size: clamp(0.7rem, 1.8vw, 0.95rem);
    font-weight: bold;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s, background 0.2s;
}

#undo-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
    background: #ff5252;
}

#undo-btn:disabled {
    background: #666;
    cursor: not-allowed;
    opacity: 0.5;
}

#undo-btn.hidden {
    display: none;
}

#explain-btn {
    background: #ffd93d;
    color: #000;
    border: none;
    padding: clamp(6px, 1.5vw, 12px) clamp(10px, 2vw, 20px);
    font-size: clamp(1rem, 2vw, 1.5rem);
    font-weight: bold;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s, background 0.2s;
}

#explain-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
    background: #ffed4e;
}

#explain-btn:active:not(:disabled) {
    transform: translateY(0);
}

#explain-btn:disabled {
    background: #666;
    cursor: not-allowed;
    opacity: 0.5;
}

#explain-btn.hidden {
    display: none;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: linear-gradient(145deg, #2c3e50, #34495e);
    padding: 30px;
    border-radius: 15px;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    border: 2px solid #3a8ae6;
}

.modal-content h3 {
    color: #ffd93d;
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 1.5rem;
}

.modal-content #explanation-text {
    color: white;
    line-height: 1.6;
    font-size: 1rem;
}

.modal-content #explanation-text p {
    margin: 10px 0;
}

.board-grid {
    display: grid;
    grid-template-columns: auto auto auto;
    grid-template-rows: auto auto auto;
    gap: 8px;
    justify-items: center;
    align-items: center;
    width: fit-content;
    margin: 0 auto;
}

.board {
    background: linear-gradient(145deg, #1e5da8, #2874d6);
    padding: 4px;
    border-radius: 8px;
    display: grid;
    gap: 8px;
    box-shadow:
        0 8px 20px rgba(0, 0, 0, 0.6),
        inset 0 2px 4px rgba(255, 255, 255, 0.1),
        inset 0 -2px 4px rgba(0, 0, 0, 0.2);
    border: 2px solid #3a8ae6;
    position: relative;
}

.main-board {
    grid-template-columns: repeat(7, min(4.2vh, 60px));
    grid-template-rows: repeat(6, min(4.2vh, 60px));
    z-index: 2;
}

.mirror-board {
    opacity: 0.4;
    pointer-events: none;
    box-shadow:
        0 3px 10px rgba(0, 0, 0, 0.4),
        inset 0 1px 2px rgba(255, 255, 255, 0.1),
        inset 0 -1px 2px rgba(0, 0, 0, 0.2);
    border: 1px solid #3a8ae6;
    overflow: hidden;
}

.mirror-board[data-position="top"],
.mirror-board[data-position="bottom"] {
    grid-template-columns: repeat(7, min(4.2vh, 60px));
    grid-template-rows: repeat(3, min(4.2vh, 60px));
}

.mirror-board[data-position="left"],
.mirror-board[data-position="right"] {
    grid-template-columns: repeat(3, min(4.2vh, 60px));
    grid-template-rows: repeat(6, min(4.2vh, 60px));
}

.mirror-board[data-position="top-left"],
.mirror-board[data-position="top-right"],
.mirror-board[data-position="bottom-left"],
.mirror-board[data-position="bottom-right"] {
    grid-template-columns: repeat(3, min(4.2vh, 60px));
    grid-template-rows: repeat(3, min(4.2vh, 60px));
}

.cell {
    width: min(4.2vh, 60px);
    height: min(4.2vh, 60px);
    background: radial-gradient(circle at 50% 50%, #0d3a6e, #061829);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: visible;
    box-shadow:
        inset 0 4px 8px rgba(0, 0, 0, 0.5),
        inset 0 -2px 4px rgba(255, 255, 255, 0.1);
}

.cell::before {
    content: '';
    position: absolute;
    top: 15%;
    left: 15%;
    width: 30%;
    height: 30%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.3), transparent);
    border-radius: 50%;
    opacity: 0.5;
}

.cell.column-hover:not(.filled) {
    transform: scale(1.05);
}

.cell.column-hover.red-turn:not(.filled) {
    background: radial-gradient(circle at 50% 50%, #8b3030, #5a1a1a);
    box-shadow:
        inset 0 4px 8px rgba(0, 0, 0, 0.5),
        0 0 20px rgba(231, 76, 60, 0.6);
}

.cell.column-hover.yellow-turn:not(.filled) {
    background: radial-gradient(circle at 50% 50%, #9a7d2f, #6b5520);
    box-shadow:
        inset 0 4px 8px rgba(0, 0, 0, 0.5),
        0 0 20px rgba(243, 156, 18, 0.6);
}

.mirror-board .cell.column-hover.red-turn:not(.filled) {
    background: radial-gradient(circle at 50% 50%, #5a1f1f, #3a1010);
    box-shadow:
        inset 0 4px 8px rgba(0, 0, 0, 0.5),
        0 0 15px rgba(231, 76, 60, 0.3);
}

.mirror-board .cell.column-hover.yellow-turn:not(.filled) {
    background: radial-gradient(circle at 50% 50%, #6b5520, #4a3a15);
    box-shadow:
        inset 0 4px 8px rgba(0, 0, 0, 0.5),
        0 0 15px rgba(243, 156, 18, 0.3);
}

.cell.filled {
    cursor: default;
}

.cell.red {
    background: radial-gradient(circle at 35% 35%, #ff6b6b, #c0392b);
    box-shadow:
        inset 0 -4px 10px rgba(0, 0, 0, 0.4),
        inset 0 4px 10px rgba(255, 107, 107, 0.5),
        0 4px 15px rgba(231, 76, 60, 0.4);
}

.cell.red::before {
    background: radial-gradient(circle, rgba(255, 255, 255, 0.6), transparent);
}

.cell.yellow {
    background: radial-gradient(circle at 35% 35%, #ffd93d, #d68910);
    box-shadow:
        inset 0 -4px 10px rgba(0, 0, 0, 0.4),
        inset 0 4px 10px rgba(255, 217, 61, 0.5),
        0 4px 15px rgba(243, 156, 18, 0.4);
}

.cell.yellow::before {
    background: radial-gradient(circle, rgba(255, 255, 255, 0.7), transparent);
}

.cell.drop-animation {
    animation: dropIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes dropIn {
    0% {
        transform: translateY(-500px) scale(0.8);
        opacity: 0;
    }
    60% {
        transform: translateY(10px) scale(1.05);
    }
    80% {
        transform: translateY(-5px) scale(0.95);
    }
    100% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.cell.winning {
    animation: winningPulse 0.6s ease-in-out infinite;
    z-index: 10;
}

@keyframes winningPulse {
    0%, 100% {
        transform: scale(1);
        filter: brightness(1) drop-shadow(0 0 10px currentColor);
    }
    50% {
        transform: scale(1.15);
        filter: brightness(1.5) drop-shadow(0 0 25px currentColor);
    }
}

.confetti {
    position: fixed;
    width: 10px;
    height: 10px;
    top: -10px;
    z-index: 1000;
    pointer-events: none;
}

@keyframes confettiFall {
    to {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

.firework {
    position: fixed;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    z-index: 1000;
    pointer-events: none;
}

@keyframes fireworkExplode {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(var(--tx), var(--ty)) scale(0);
        opacity: 0;
    }
}

.message {
    margin-top: 10px;
    font-size: clamp(1rem, 3vw, 1.5rem);
    font-weight: bold;
    color: white;
    min-height: 30px;
    text-shadow:
        2px 2px 4px rgba(0, 0, 0, 0.5),
        0 0 20px currentColor;
}

@keyframes messageScale {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@media (max-width: 768px) {
    .board-grid {
        gap: 2px;
    }

    .board {
        padding: 2px;
        gap: 2px;
        border-width: 1px;
        border-radius: 5px;
    }

    .main-board {
        grid-template-columns: repeat(7, 5.5vw) !important;
        grid-template-rows: repeat(6, 5.5vw) !important;
    }

    .mirror-board[data-position="top"],
    .mirror-board[data-position="bottom"] {
        grid-template-columns: repeat(7, 5.5vw) !important;
        grid-template-rows: repeat(3, 5.5vw) !important;
    }

    .mirror-board[data-position="left"],
    .mirror-board[data-position="right"] {
        grid-template-columns: repeat(3, 5.5vw) !important;
        grid-template-rows: repeat(6, 5.5vw) !important;
    }

    .mirror-board[data-position="top-left"],
    .mirror-board[data-position="top-right"],
    .mirror-board[data-position="bottom-left"],
    .mirror-board[data-position="bottom-right"] {
        grid-template-columns: repeat(3, 5.5vw) !important;
        grid-template-rows: repeat(3, 5.5vw) !important;
    }

    .cell {
        width: 5.5vw;
        height: 5.5vw;
    }

    .game-info {
        flex-direction: column;
        gap: 10px;
    }
}
