* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

:root {
    --primary-color: #6C63FF;
    --secondary-color: #4CAF50;
    --background-dark: #1a1a2e;
    --background-light: rgba(255, 255, 255, 0.1);
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.back-button {
    position: fixed;
    top: 2rem;
    left: 2rem;
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
    font-size: 1.1rem;
    box-shadow: var(--shadow);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    z-index: 100;
    backdrop-filter: blur(5px);
}

.back-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
    background: rgba(255, 255, 255, 0.15);
}

.back-button:active {
    transform: translateY(1px);
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
}

@media (max-width: 600px) {
    .back-button {
        top: 1rem;
        left: 1rem;
        padding: 0.6rem 1.2rem;
        font-size: 1rem;
    }
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

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

@keyframes float {
    0% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
    100% { transform: translateY(0px); }
}

body {
    min-height: 100vh;
    background: linear-gradient(-45deg, #1a1a2e, #16213e, #1b2436, #0f3460);
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    overflow-x: hidden;
}

/* Star effect */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background-image: radial-gradient(white 1px, transparent 1px);
    background-size: 50px 50px;
    animation: twinkle 4s infinite;
    z-index: 0;
}

.mode-selection {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 2rem;
    margin: 2rem;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: var(--shadow);
    max-width: 600px;
    width: 90%;
    animation: float 6s ease-in-out infinite;
}

h1 {
    font-size: 3rem;
    margin-bottom: 2rem;
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 400px;
    margin: 0 auto;
}

.mode-btn {
    padding: 1.5rem;
    border: none;
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.mode-btn:hover {
    transform: translateY(-5px) scale(1.02);
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.mode-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
    animation: float 3s ease-in-out infinite;
}

.mode-text {
    font-size: 1.4rem;
    font-weight: bold;
    color: var(--text-primary);
}

.mode-desc {
    font-size: 1rem;
    color: var(--text-secondary);
}

.container {
    position: relative;
    z-index: 1;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    padding: 2rem;
    border-radius: 20px;
    box-shadow: var(--shadow);
    max-width: 600px;
    width: 90%;
    margin: 2rem auto;
}

.game-info {
    text-align: center;
    margin-bottom: 1.5rem;
}

.player-turn {
    font-size: 1.4rem;
    color: var(--text-primary);
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.status {
    font-size: 1.2rem;
    color: var(--secondary-color);
    margin: 1rem 0;
    min-height: 1.5em;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin: 2rem auto;
    max-width: 400px;
}

.cell {
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.cell:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.2);
}

.cell.x {
    color: var(--primary-color);
    text-shadow: 0 0 10px rgba(108, 99, 255, 0.5);
}

.cell.o {
    color: var(--secondary-color);
    text-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
}

.score-board {
    display: flex;
    justify-content: space-around;
    margin: 2rem 0;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    backdrop-filter: blur(5px);
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
}

.score-item span:first-child {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

.score-item span:last-child {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
}

.button-container {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 2rem;
}

button {
    padding: 1rem 2rem;
    border: none;
    border-radius: 10px;
    background: var(--primary-color);
    color: white;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
}

.ad-container {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    padding: 1rem;
    text-align: center;
    z-index: 100;
}

.ad-banner {
    max-width: 728px;
    min-height: 90px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Make ads responsive */
@media (max-width: 728px) {
    .ad-banner {
        max-width: 320px;
        min-height: 50px;
    }
}

.adsbygoogle {
    display: block;
    width: 100%;
    height: 100%;
}

.ad-text {
    color: var(--text-secondary);
    font-size: 1.2rem;
}

/* Responsive Design */
@media (max-width: 600px) {
    h1 {
        font-size: 2.5rem;
    }

    .mode-btn {
        padding: 1.2rem;
    }

    .mode-icon {
        font-size: 2.5rem;
    }

    .mode-text {
        font-size: 1.2rem;
    }

    .container {
        padding: 1.5rem;
    }

    .game-board {
        gap: 10px;
    }

    .cell {
        font-size: 2.5rem;
    }

    .button-container {
        flex-direction: column;
    }

    button {
        width: 100%;
    }

    .ad-banner {
        height: 60px;
    }
}

/* Animations for game elements */
@keyframes popIn {
    0% { transform: scale(0); opacity: 0; }
    70% { transform: scale(1.1); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

.cell.x, .cell.o {
    animation: popIn 0.3s ease-out forwards;
}

/* Win animation */
@keyframes win {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.status:not(:empty) {
    animation: win 0.5s ease-in-out;
}

.level-info {
    margin-top: 1rem;
    text-align: center;
}

.level-display {
    font-size: 1.2rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(108, 99, 255, 0.3);
}

.progress-bar {
    width: 100%;
    max-width: 300px;
    height: 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    margin: 0 auto;
    overflow: hidden;
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
}

.progress {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    border-radius: 5px;
    transition: width 0.5s ease;
}

.level-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
    padding: 1.5rem 3rem;
    border-radius: 15px;
    font-size: 1.5rem;
    font-weight: bold;
    color: white;
    text-align: center;
    opacity: 0;
    z-index: 1000;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

.level-message.show {
    animation: levelMessage 2s ease-in-out forwards;
}

.level-message.fail {
    background: linear-gradient(45deg, #ff4757, #ff6b81);
}

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

/* Add these styles for online multiplayer */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    padding: 2rem;
    border-radius: 20px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: var(--shadow);
}

.modal-content h2 {
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    font-size: 1.8rem;
}

.online-options {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.online-options button {
    flex: 1;
    padding: 1rem;
    font-size: 1rem;
}

.game-id-container {
    display: flex;
    gap: 0.5rem;
    margin: 1rem 0;
}

.game-id-container input {
    flex: 1;
    padding: 0.8rem;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    font-size: 1rem;
    text-align: center;
}

#copyGameId {
    padding: 0.8rem 1.2rem;
    white-space: nowrap;
}

#joinGameForm {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin: 1rem 0;
}

#joinGameForm input {
    padding: 0.8rem;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    font-size: 1rem;
    text-align: center;
}

.waiting-message {
    color: var(--text-secondary);
    margin: 1rem 0;
    font-style: italic;
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.5rem;
    padding: 0.5rem;
    transition: color 0.3s ease;
}

.close-btn:hover {
    color: var(--text-primary);
}

/* Online game status styles */
.online-status {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    margin-top: 1rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.online-status.connected {
    background: rgba(76, 175, 80, 0.2);
    color: #4CAF50;
}

.online-status.disconnected {
    background: rgba(244, 67, 54, 0.2);
    color: #f44336;
}

/* Animation for waiting message */
@keyframes pulse {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}

.waiting-message {
    animation: pulse 1.5s infinite ease-in-out;
}

/* Copy button animation */
@keyframes copySuccess {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.copy-success {
    animation: copySuccess 0.3s ease-out;
    background: var(--secondary-color) !important;
}

/* Enhanced Responsive Design */
@media (max-width: 768px) {
    .mode-selection {
        margin: 1rem;
        padding: 1.5rem;
        margin-top: 4rem;
    }

    h1 {
        font-size: 2rem;
        margin-bottom: 1.5rem;
    }

    .mode-btn {
        padding: 1rem;
    }

    .mode-icon {
        font-size: 2rem;
    }

    .mode-text {
        font-size: 1.1rem;
    }

    .mode-desc {
        font-size: 0.9rem;
    }

    .container {
        padding: 1rem;
        margin: 1rem;
        margin-top: 4rem;
    }

    .game-board {
        gap: 8px;
        margin: 1rem auto;
    }

    .cell {
        font-size: 2rem;
        border-radius: 10px;
    }

    .button-container {
        flex-direction: column;
        gap: 0.8rem;
    }

    button {
        width: 100%;
        padding: 0.8rem 1.5rem;
        font-size: 0.9rem;
    }

    .score-board {
        flex-direction: row;
        padding: 0.8rem;
        margin: 1rem 0;
    }

    .score-item {
        padding: 0.8rem;
    }

    .score-item span:first-child {
        font-size: 0.9rem;
    }

    .score-item span:last-child {
        font-size: 1.6rem;
    }

    .player-turn {
        font-size: 1.2rem;
    }

    .status {
        font-size: 1rem;
    }

    .level-display {
        font-size: 1rem;
    }

    .progress-bar {
        height: 8px;
    }

    /* Modal Responsiveness */
    .modal-content {
        padding: 1.5rem;
        width: 95%;
        max-width: 350px;
    }

    .modal-content h2 {
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }

    .online-options {
        flex-direction: column;
        gap: 0.8rem;
    }

    .game-id-container {
        flex-direction: column;
        gap: 0.5rem;
    }

    .game-id-container input,
    #joinGameForm input {
        padding: 0.6rem;
        font-size: 0.9rem;
    }

    #copyGameId {
        width: 100%;
        padding: 0.6rem;
    }

    .waiting-message {
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .mode-selection {
        margin: 0.5rem;
        padding: 1rem;
        margin-top: 3.5rem;
    }

    h1 {
        font-size: 1.8rem;
    }

    .cell {
        font-size: 1.8rem;
    }

    .score-item span:last-child {
        font-size: 1.4rem;
    }

    .back-button {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
}

/* Portrait Mode Optimization */
@media screen and (max-height: 600px) and (orientation: landscape) {
    .mode-selection {
        margin: 0.5rem;
        padding: 1rem;
        margin-top: 3.5rem;
    }

    .mode-buttons {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    .mode-btn {
        width: calc(50% - 1rem);
        min-width: 200px;
    }

    .game-board {
        max-width: 300px;
    }

    .cell {
        font-size: 1.8rem;
    }

    .score-board {
        max-width: 300px;
        margin: 1rem auto;
    }
}

/* High-DPI Screens */
@media screen and (-webkit-min-device-pixel-ratio: 2), 
       screen and (min-resolution: 192dpi) {
    .cell {
        border-width: 1px;
    }

    .mode-btn {
        border-width: 1px;
    }
}

/* Touch Device Optimization */
@media (hover: none) {
    .mode-btn:hover {
        transform: none;
        background: rgba(255, 255, 255, 0.1);
    }

    .cell:hover {
        transform: none;
        background: rgba(255, 255, 255, 0.05);
    }

    button:hover {
        transform: none;
    }

    .back-button:hover {
        transform: none;
    }
}

/* Active States for Touch Devices */
.mode-btn:active,
.cell:active,
button:active,
.back-button:active {
    transform: scale(0.95);
    transition: transform 0.1s;
}
