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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #0a1628 0%, #1a2d4a 50%, #0d3b66 100%);
    min-height: 100vh;
    color: #fff;
}

.screen {
    display: none !important;
    min-height: 100vh;
    padding: 20px;
}

.screen.active {
    display: flex !important;
    justify-content: center;
    align-items: center;
}

body > .screen:not(.active) {
    visibility: hidden !important;
    pointer-events: none !important;
}

.container {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 40px;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.container.wide {
    max-width: 800px;
}

h1 {
    text-align: center;
    font-size: 2.5rem;
    margin-bottom: 30px;
    text-shadow: 0 0 20px rgba(0, 100, 200, 0.8);
    color: #4da6ff;
    letter-spacing: 4px;
}

h2 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: #fff;
}

h3 {
    font-size: 1.1rem;
    margin-bottom: 10px;
    color: #aaa;
}

h4 {
    font-size: 1rem;
    margin-bottom: 8px;
    color: #8bb8e8;
    text-align: center;
}

.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: #aaa;
}

input[type="text"],
input[type="password"] {
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    color: #fff;
    transition: all 0.3s ease;
}

input[type="text"]:focus,
input[type="password"]:focus {
    outline: none;
    border-color: #4da6ff;
    box-shadow: 0 0 10px rgba(77, 166, 255, 0.3);
}

input[type="text"]::placeholder,
input[type="password"]::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.btn {
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: bold;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn.primary {
    background: linear-gradient(135deg, #0066cc, #4da6ff);
    color: #fff;
    box-shadow: 0 4px 15px rgba(0, 100, 200, 0.4);
}

.btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 100, 200, 0.6);
}

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

.btn.danger {
    background: linear-gradient(135deg, #cc0000, #ff3333);
    color: #fff;
}

.btn.danger:hover {
    transform: translateY(-2px);
}

.btn:not(.primary):not(.danger) {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.btn:not(.primary):not(.danger):hover {
    background: rgba(255, 255, 255, 0.3);
}

.btn.small {
    padding: 6px 12px;
    font-size: 0.75rem;
}

.error {
    color: #ff4444;
    font-size: 0.9rem;
    margin-top: 10px;
    text-align: center;
}

/* Lobby Browser */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.player-info {
    color: #aaa;
    font-size: 0.9rem;
}

.player-info span {
    color: #4da6ff;
    font-weight: bold;
}

.lobby-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.lobby-actions input {
    flex: 1;
    min-width: 150px;
}

.lobby-list {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    padding: 15px;
    min-height: 200px;
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 20px;
}

.no-lobbies {
    color: #666;
    text-align: center;
    padding: 50px;
}

.lobby-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    margin-bottom: 10px;
    transition: all 0.3s ease;
}

.lobby-item:hover {
    background: rgba(255, 255, 255, 0.15);
}

.lobby-item:last-child {
    margin-bottom: 0;
}

.lobby-item-info h4 {
    color: #fff;
    margin-bottom: 5px;
    text-align: left;
}

.lobby-item-info span {
    color: #888;
    font-size: 0.85rem;
}

.lobby-item-info .in-game {
    color: #4da6ff;
}

/* Lobby Room */
.lobby-room-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

@media (max-width: 768px) {
    .lobby-room-container {
        grid-template-columns: 1fr;
    }
}

.lobby-info {
    display: flex;
    flex-direction: column;
}

.players-list {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    padding: 15px;
    flex: 1;
    min-height: 100px;
    margin-bottom: 20px;
}

.player-item {
    display: flex;
    align-items: center;
    padding: 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    margin-bottom: 8px;
}

.player-item:last-child {
    margin-bottom: 0;
}

.player-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    margin-right: 10px;
}

.bot-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.bot-buttons .btn {
    flex: 1;
    padding: 8px 16px;
    font-size: 0.9rem;
    background: rgba(100, 100, 255, 0.3);
    border: 1px solid rgba(100, 100, 255, 0.5);
}

.bot-buttons .btn:hover {
    background: rgba(100, 100, 255, 0.5);
}

.lobby-buttons {
    display: flex;
    gap: 10px;
}

.lobby-buttons .btn {
    flex: 1;
}

/* Chat */
.chat-container {
    display: flex;
    flex-direction: column;
}

.chat-messages {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    padding: 15px;
    flex: 1;
    min-height: 200px;
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 15px;
}

.chat-messages.small {
    min-height: 80px;
    max-height: 120px;
}

.chat-message {
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.chat-message:last-child {
    margin-bottom: 0;
}

.chat-message .name {
    font-weight: bold;
    color: #4da6ff;
}

.chat-message .text {
    color: #ddd;
}

.chat-message.system {
    color: #888;
    font-style: italic;
}

.chat-input-container {
    display: flex;
    gap: 10px;
}

.chat-input-container input {
    flex: 1;
}

/* Game Screen */
#game-screen.active {
    padding: 10px;
    align-items: flex-start;
}

.game-container {
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 10px 15px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
}

.game-status {
    display: flex;
    gap: 20px;
    align-items: center;
}

#game-phase {
    font-weight: bold;
    color: #4da6ff;
}

#turn-indicator {
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 0.9rem;
}

#turn-indicator.your-turn {
    background: #28a745;
    color: #fff;
}

#turn-indicator.opponent-turn {
    background: #dc3545;
    color: #fff;
}

.game-phase {
    margin-bottom: 20px;
}

.game-phase.hidden {
    display: none;
}

/* Placement Phase */
.placement-instructions {
    text-align: center;
    margin-bottom: 15px;
}

.placement-instructions h3 {
    color: #4da6ff;
    margin-bottom: 8px;
}

.placement-instructions p {
    color: #aaa;
    font-size: 0.9rem;
}

.placement-instructions kbd {
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: monospace;
}

.placement-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
}

.ships-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.ship-item {
    padding: 8px 12px;
    background: rgba(0, 100, 200, 0.3);
    border: 2px solid #4da6ff;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.85rem;
}

.ship-item:hover {
    background: rgba(0, 100, 200, 0.5);
}

.ship-item.selected {
    background: #4da6ff;
    color: #000;
}

.ship-item.placed {
    background: rgba(40, 167, 69, 0.3);
    border-color: #28a745;
    cursor: default;
}

/* Grid */
.grid-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 15px;
}

.game-grid {
    border: 2px solid #4da6ff;
    border-radius: 5px;
    cursor: default;
    touch-action: manipulation;
}

.game-grid.clickable {
    cursor: crosshair;
}

/* Battle Phase */
.battle-grids {
    display: flex;
    justify-content: center;
    gap: 30px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.fleet-status {
    margin-top: 10px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    font-size: 0.85rem;
}

.ship-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.ship-status:last-child {
    margin-bottom: 0;
}

.ship-status .ship-name {
    flex: 1;
}

.ship-status .ship-cells {
    display: flex;
    gap: 2px;
}

.ship-cell {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    background: #4da6ff;
}

.ship-cell.hit {
    background: #dc3545;
}

.ship-status.sunk .ship-name {
    text-decoration: line-through;
    color: #888;
}

.ship-status.sunk .ship-cell {
    background: #666;
}

.battle-log {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    padding: 10px 15px;
    max-height: 100px;
    overflow-y: auto;
    font-size: 0.85rem;
    margin-bottom: 15px;
}

.log-entry {
    margin-bottom: 4px;
    padding: 4px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.log-entry:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.log-entry.hit {
    color: #ff6b6b;
}

.log-entry.miss {
    color: #888;
}

.log-entry.sunk {
    color: #ff4444;
    font-weight: bold;
}

/* Game Chat */
.game-chat {
    margin-top: 15px;
}

.game-chat .chat-messages {
    min-height: 60px;
    max-height: 100px;
}

.game-chat input {
    font-size: 0.9rem;
    padding: 8px 12px;
}

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

.overlay.hidden {
    display: none !important;
}

.overlay-content {
    text-align: center;
    padding: 40px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 20px;
}

.overlay-content h2 {
    font-size: 2rem;
    margin-bottom: 20px;
    color: #4da6ff;
}

.overlay-content p {
    font-size: 1.2rem;
    margin-bottom: 10px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: #4da6ff;
    border-radius: 50%;
    margin: 20px auto 0;
    animation: spin 1s linear infinite;
}

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

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: rgba(77, 166, 255, 0.5);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(77, 166, 255, 0.7);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    h1 {
        font-size: 2rem;
    }

    .container {
        padding: 25px;
        margin: 10px;
    }

    .battle-grids {
        flex-direction: column;
        align-items: center;
    }

    .game-grid {
        max-width: calc(100vw - 40px);
        height: auto !important;
    }

    .placement-controls {
        flex-direction: column;
    }

    .ships-list {
        width: 100%;
    }

    .ship-item {
        flex: 1;
        text-align: center;
        min-width: 80px;
    }

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

    .game-status {
        flex-direction: column;
        gap: 8px;
    }
}

@media (max-width: 480px) {
    .screen {
        padding: 10px;
    }

    .container {
        padding: 20px;
    }

    .btn {
        padding: 10px 16px;
        font-size: 0.9rem;
    }

    .lobby-actions {
        flex-direction: column;
    }

    .lobby-buttons,
    .bot-buttons {
        flex-direction: column;
    }

    .fleet-status {
        font-size: 0.75rem;
    }

    .ship-cell {
        width: 10px;
        height: 10px;
    }
}

/* Touch-friendly hit areas */
@media (pointer: coarse) {
    .game-grid.clickable {
        cursor: pointer;
    }

    .btn {
        min-height: 44px;
    }

    .ship-item {
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}
