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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    color: #333;
}

.container {
    background: white;
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 1200px;
    width: 100%;
}

h1 {
    text-align: center;
    color: #667eea;
    margin-bottom: 30px;
    font-size: 2.5em;
}

h2 {
    text-align: center;
    color: #764ba2;
    margin-bottom: 20px;
}

h3 {
    text-align: center;
    color: #555;
    margin-bottom: 15px;
    font-size: 1.2em;
}

.screen {
    display: block;
}

.screen.hidden {
    display: none;
}

/* Лобби */
.lobby-options {
    text-align: center;
}

.btn {
    padding: 12px 30px;
    font-size: 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 600;
    margin: 10px;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #764ba2;
    color: white;
}

.btn-secondary:hover {
    background: #653a8a;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(118, 75, 162, 0.4);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#rematchStatus {
    color: #666;
    margin-bottom: 15px;
    min-height: 1.2em;
}

.btn-small {
    padding: 8px 20px;
    font-size: 14px;
}

.divider {
    margin: 20px 0;
    color: #999;
    font-weight: 500;
}

.join-section {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

#lobbyCodeInput {
    padding: 12px 20px;
    font-size: 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
    text-transform: uppercase;
    text-align: center;
    letter-spacing: 2px;
    width: 200px;
}

#lobbyCodeInput:focus {
    outline: none;
    border-color: #667eea;
}

.lobby-info {
    margin-top: 30px;
    text-align: center;
    padding: 20px;
    background: #f5f5f5;
    border-radius: 10px;
}

.lobby-info p {
    margin: 10px 0;
    font-size: 18px;
}

#lobbyCodeDisplay {
    font-size: 24px;
    color: #667eea;
    letter-spacing: 3px;
}

/* Расстановка кораблей */
.placement-info {
    text-align: center;
    margin-bottom: 20px;
    color: #666;
}

#placementStatus {
    font-weight: 600;
    color: #667eea;
    margin-top: 10px;
}

.ships-panel {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 20px 0;
    flex-wrap: wrap;
}

.ship-selector {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px;
    border: 2px solid #ddd;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    background: #f9f9f9;
}

.ship-selector:hover {
    border-color: #667eea;
    background: #f0f0ff;
    transform: scale(1.05);
}

.ship-selector.selected {
    border-color: #667eea;
    background: #e8eaff;
}

.ship-selector.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ship-preview {
    display: flex;
    gap: 2px;
    margin-bottom: 5px;
}

.ship-preview div {
    width: 25px;
    height: 25px;
    background: #667eea;
    border-radius: 3px;
}

.ship-preview.vertical {
    flex-direction: column;
}

.rotation-controls {
    text-align: center;
    margin: 20px 0;
}

/* Игровые поля */
.boards-container {
    display: flex;
    gap: 40px;
    justify-content: center;
    flex-wrap: wrap;
    margin: 30px 0;
}

.board-section {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.board {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 2px;
    background: #e0e0e0;
    padding: 5px;
    border-radius: 10px;
    border: 3px solid #667eea;
}

.cell {
    width: 35px;
    height: 35px;
    background: #87CEEB;
    border: 1px solid #5a9fc7;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    border-radius: 3px;
}

.cell:hover {
    background: #6bb6d6;
    transform: scale(1.1);
}

.cell.ship {
    background: #4a5568;
    border-color: #2d3748;
}

.cell.ship:hover {
    background: #5a6578;
}

.cell.hit {
    background: #f56565;
    border-color: #e53e3e;
}

.cell.miss {
    background: #e2e8f0;
    border-color: #cbd5e0;
}

.cell.miss::after {
    content: '•';
    color: #718096;
    font-size: 20px;
}

.cell.hit::after {
    content: '✕';
    color: white;
    font-size: 18px;
}

.cell.sunk {
    background: #c53030;
    border-color: #9b2c2c;
}

/* Поле противника: в уже обстрелянные клетки и в чужой ход стрелять нельзя */
#opponentBoard .cell.hit,
#opponentBoard .cell.miss,
#opponentBoard .cell.pending {
    cursor: default;
    pointer-events: none;
}

#opponentBoard.locked .cell {
    cursor: not-allowed;
    pointer-events: none;
}

#opponentBoard.locked .cell:not(.hit):not(.miss) {
    opacity: 0.6;
}

#opponentBoard .cell.pending {
    opacity: 0.6;
}

.cell.placement-preview {
    background: #48bb78;
    border-color: #38a169;
}

.cell.placement-invalid {
    background: #fc8181;
    border-color: #f56565;
}

/* Игровая информация */
.game-info {
    text-align: center;
    margin-bottom: 20px;
    padding: 15px;
    background: #f5f5f5;
    border-radius: 10px;
}

#gameStatus {
    font-size: 20px;
    font-weight: 600;
    color: #667eea;
    margin-bottom: 10px;
}

#gameStatus.my-turn {
    color: #48bb78;
}

#gameStatus.their-turn {
    color: #f56565;
}

#turnIndicator {
    color: #666;
    font-size: 16px;
}

#fleetCounter {
    color: #888;
    font-size: 14px;
    margin-top: 8px;
}

/* Экран победы */
#gameOverScreen {
    text-align: center;
}

#gameOverMessage {
    font-size: 2em;
    color: #667eea;
    margin-bottom: 30px;
}

/* Чат */
.chat-panel {
    max-width: 500px;
    margin: 20px auto 0;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    padding: 10px;
}

.chat-panel.hidden {
    display: none;
}

.chat-messages {
    height: 140px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}

.chat-message {
    max-width: 80%;
    padding: 6px 12px;
    border-radius: 12px;
    word-wrap: break-word;
}

.chat-message.mine {
    align-self: flex-end;
    background: #667eea;
    color: white;
}

.chat-message.theirs {
    align-self: flex-start;
    background: #f0f0f0;
}

.chat-form {
    display: flex;
    gap: 8px;
}

.chat-form input {
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
}

.chat-form input:focus {
    outline: none;
    border-color: #667eea;
}

.chat-form .btn {
    margin: 0;
}

/* Сообщения об ошибках */
.error-message {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #f56565;
    color: white;
    padding: 15px 25px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(245, 101, 101, 0.4);
    z-index: 1000;
    max-width: 300px;
}

.error-message.hidden {
    display: none;
}

/* Адаптивность */
@media (max-width: 768px) {
    .container {
        padding: 20px;
    }

    h1 {
        font-size: 2em;
    }

    .boards-container {
        flex-direction: column;
        gap: 20px;
    }

    .cell {
        width: 30px;
        height: 30px;
    }

    .ships-panel {
        gap: 10px;
    }
}

