/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: #333;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
}

#app {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

/* Connection Status */
.connection-status {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: bold;
    text-transform: uppercase;
    z-index: 1000;
}

.connection-status.connecting {
    background: #ffa500;
    color: white;
}

.connection-status.connected {
    background: #4caf50;
    color: white;
}

.connection-status.disconnected {
    background: #f44336;
    color: white;
}

.connection-status.error {
    background: #ff5722;
    color: white;
}

/* Screen Management */
.screen {
    display: none;
    width: 100%;
}

.screen.active {
    display: block;
}

/* Common Container Styles */
.menu-container,
.lobby-container,
.game-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    text-align: center;
}

/* Menu Screen */
.menu-container h1 {
    color: #1e3c72;
    font-size: 2.5em;
    margin-bottom: 10px;
}

.menu-container p {
    color: #666;
    margin-bottom: 30px;
    font-size: 1.1em;
}

/* Rules Section */
.rules-section {
    margin: 20px 0;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

.rules-toggle {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border: 2px solid #dee2e6;
    border-radius: 8px;
    padding: 12px 16px;
    cursor: pointer;
    font-size: 1.1em;
    font-weight: 600;
    color: #495057;
    transition: all 0.3s ease;
    display: block;
    text-align: center;
    user-select: none;
}

.rules-toggle:hover {
    background: linear-gradient(135deg, #e9ecef, #dee2e6);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.rules-section[open] .rules-toggle {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom-color: transparent;
    background: linear-gradient(135deg, #2a5298, #1e3c72);
    color: white;
}

.rules-content {
    border: 2px solid #dee2e6;
    border-top: none;
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    background: white;
    padding: 20px;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.rules-grid {
    display: grid;
    gap: 12px;
    margin-bottom: 15px;
}

.rule-item {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px;
    align-items: start;
    padding: 8px 0;
    border-bottom: 1px solid #f8f9fa;
}

.rule-item:last-child {
    border-bottom: none;
}

.rule-item strong {
    color: #1e3c72;
    white-space: nowrap;
}

.rule-item span {
    color: #495057;
    line-height: 1.4;
}

.rules-footer {
    text-align: center;
    padding-top: 15px;
    border-top: 1px solid #e9ecef;
}

.rules-link {
    display: inline-block;
    background: linear-gradient(135deg, #28a745, #20c997);
    color: white;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.rules-link:hover {
    background: linear-gradient(135deg, #20c997, #28a745);
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(40, 167, 69, 0.3);
}

.menu-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-width: 300px;
    margin: 0 auto;
}

input[type="text"] {
    padding: 12px 15px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s ease;
}

input[type="text"]:focus {
    outline: none;
    border-color: #2a5298;
}

button {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

button:active {
    transform: translateY(0);
}

#joinRoom {
    background: #4caf50;
    color: white;
}

#joinRoom:hover {
    background: #45a049;
}

#createRoom {
    background: #2196f3;
    color: white;
}

#createRoom:hover {
    background: #1976d2;
}

/* Lobby Screen */
.lobby-container h2 {
    color: #1e3c72;
    margin-bottom: 20px;
}

.player-info {
    margin: 20px 0;
    font-size: 1.1em;
}

.lobby-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

#startGame {
    background: #4caf50;
    color: white;
}

#startGame:hover {
    background: #45a049;
}

#leaveRoom {
    background: #f44336;
    color: white;
}

#leaveRoom:hover {
    background: #da190b;
}

#shareRoom {
    background: #ff9800;
    color: white;
}

#shareRoom:hover {
    background: #f57c00;
}

/* Game Screen */
.game-header {
    margin-bottom: 20px;
}

.game-header h2 {
    color: #1e3c72;
    margin-bottom: 15px;
}

.room-info {
    text-align: center;
    font-size: 0.9em;
    color: #666;
    margin-top: 10px;
    font-weight: normal;
}

/* Turn Indicator */
.turn-indicator {
    background: linear-gradient(135deg, #4caf50, #45a049);
    color: white;
    padding: 15px 20px;
    border-radius: 12px;
    text-align: center;
    margin: 15px 0;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
    border: 3px solid #388e3c;
    animation: turnPulse 2s infinite;
}

.turn-indicator.opponent-turn {
    background: linear-gradient(135deg, #ff5722, #e64a19);
    border-color: #d84315;
    box-shadow: 0 4px 15px rgba(255, 87, 34, 0.3);
    animation: none;
}

.turn-indicator.waiting {
    background: linear-gradient(135deg, #9e9e9e, #757575);
    border-color: #616161;
    box-shadow: 0 4px 15px rgba(158, 158, 158, 0.3);
    animation: none;
}

.turn-indicator.game-won {
    background: linear-gradient(135deg, #4caf50, #2e7d32);
    border-color: #1b5e20;
    box-shadow: 0 4px 20px rgba(76, 175, 80, 0.5);
    animation: victoryPulse 1.5s infinite;
}

.turn-indicator.game-lost {
    background: linear-gradient(135deg, #f44336, #c62828);
    border-color: #b71c1c;
    box-shadow: 0 4px 15px rgba(244, 67, 54, 0.4);
    animation: none;
}

.turn-indicator.game-draw {
    background: linear-gradient(135deg, #ff9800, #ef6c00);
    border-color: #e65100;
    box-shadow: 0 4px 15px rgba(255, 152, 0, 0.4);
    animation: none;
}

@keyframes victoryPulse {
    0%, 100% { 
        transform: scale(1);
        box-shadow: 0 4px 20px rgba(76, 175, 80, 0.5);
    }
    50% { 
        transform: scale(1.03);
        box-shadow: 0 6px 25px rgba(76, 175, 80, 0.7);
    }
}

.turn-message {
    font-size: 1.4em;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
}

.turn-subtext {
    font-size: 0.9em;
    opacity: 0.9;
    font-weight: normal;
}

@keyframes turnPulse {
    0%, 100% { 
        transform: scale(1);
        box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
    }
    50% { 
        transform: scale(1.02);
        box-shadow: 0 6px 20px rgba(76, 175, 80, 0.5);
    }
}


/* Board Styles */
.board-container {
    display: flex;
    justify-content: center;
    margin: 20px auto;
    padding: 0 10px;
    max-width: 100%;
    overflow: visible;
}

.board {
    border: 3px solid #1e3c72;
    border-radius: 15px;
    background: #fafafa;
    cursor: pointer;
    width: 100%;
    height: auto;
    max-width: 400px;
    max-height: 400px;
}

.board.your-turn {
    border-color: #4caf50;
    box-shadow: 0 0 20px rgba(76, 175, 80, 0.3);
}

.board-lines {
    pointer-events: none;
}

.cell {
    fill: #e8e8e8;
    stroke: #333;
    stroke-width: 2;
    cursor: pointer;
    transition: all 0.2s ease;
}

.cell:hover {
    fill: #d0d0d0;
}

.cell.player1 {
    fill: #2196f3;
    stroke: #1976d2;
}

.cell.player2 {
    fill: #f44336;
    stroke: #d32f2f;
}

.cell.selected {
    fill: #ffc107;
    stroke: #f57c00;
    stroke-width: 4;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.cell.center {
    fill: #f0f0f0;
}

.cell.center.player1 {
    fill: #2196f3;
}

.cell.center.player2 {
    fill: #f44336;
}

/* Game Actions */
.game-actions {
    margin-top: 20px;
    display: flex;
    gap: 15px;
    justify-content: center;
}

#restartGame {
    background: #4caf50;
    color: white;
}

#restartGame:hover {
    background: #45a049;
}

#endGame {
    background: #ff9800;
    color: white;
}

#endGame:hover {
    background: #f57c00;
}

/* Notifications */
.notifications {
    position: fixed;
    top: 70px;
    right: 20px;
    z-index: 1000;
    max-width: 300px;
}

.notification {
    padding: 12px 16px;
    margin-bottom: 10px;
    border-radius: 8px;
    color: white;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.notification.success {
    background: #4caf50;
}

.notification.error {
    background: #f44336;
}

.notification.warning {
    background: #ff9800;
}

.notification.info {
    background: #2196f3;
}

/* Responsive Design */
@media (max-width: 600px) {
    #app {
        padding: 8px;
    }
    
    .menu-container,
    .lobby-container,
    .game-container {
        padding: 12px;
    }
    
    .menu-container h1 {
        font-size: 2em;
    }
    
    .board-container {
        margin: 15px auto;
        padding: 0 8px;
        width: 100%;
        box-sizing: border-box;
    }
    
    .board {
        width: calc(100vw - 40px);
        height: calc(100vw - 40px);
        max-width: 320px;
        max-height: 320px;
        min-width: 280px;
        min-height: 280px;
        border-width: 2px;
    }
    
    .turn-indicator {
        padding: 12px 15px;
        margin: 10px 0;
    }
    
    .turn-message {
        font-size: 1.2em;
    }
    
    .turn-subtext {
        font-size: 0.8em;
    }
    
    .rules-section {
        margin: 15px 0;
        max-width: 100%;
    }
    
    .rules-toggle {
        font-size: 1em;
        padding: 10px 12px;
    }
    
    .rules-content {
        padding: 15px;
    }
    
    .rule-item {
        grid-template-columns: 1fr;
        gap: 4px;
        padding: 6px 0;
    }
    
    .rule-item strong {
        white-space: normal;
    }
    
    .lobby-actions,
    .game-actions {
        flex-direction: column;
        align-items: center;
    }
    
    .notifications {
        right: 10px;
        left: 10px;
        max-width: none;
    }
    
    .connection-status {
        top: 10px;
        right: 10px;
    }
}

/* Extra small mobile devices */
@media (max-width: 360px) {
    #app {
        padding: 4px;
    }
    
    .menu-container,
    .lobby-container,
    .game-container {
        padding: 8px;
    }
    
    .board-container {
        margin: 10px auto;
        padding: 0 4px;
    }
    
    .board {
        width: calc(100vw - 24px);
        height: calc(100vw - 24px);
        max-width: 300px;
        max-height: 300px;
        min-width: 240px;
        min-height: 240px;
        border-width: 1px;
    }
    
    .game-header h2 {
        font-size: 1.2em;
    }
    
    .turn-indicator {
        padding: 8px 10px;
        margin: 8px 0;
    }
    
    .turn-message {
        font-size: 1em;
    }
    
    .turn-subtext {
        font-size: 0.75em;
    }
}

/* Loading states */
.loading {
    opacity: 0.7;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #ddd;
    border-top: 2px solid #2196f3;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}