:root {
    --bg-color: #0f172a;
    --text-color: #f8fafc;
    --primary-color: #3b82f6;
    --water-color: #1e3a8a;
    --ship-color: #94a3b8;
    --hit-color: #ef4444;
    --miss-color: #38bdf8;
    --board-bg: #0b1120;
    --board-border: #1e293b;
    --highlight-color: rgba(74, 222, 128, 0.5);
    --invalid-color: rgba(248, 113, 113, 0.5);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: radial-gradient(circle at top, #1e293b 0%, #0f172a 100%);
}

.container {
    max-width: 1200px;
    width: 100%;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

header {
    text-align: center;
}

h1 {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 1rem;
    background: linear-gradient(to right, #38bdf8, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0px 0px 20px rgba(56, 189, 248, 0.2);
}

.status-box {
    background-color: rgba(30, 41, 59, 0.8);
    padding: 1rem 2rem;
    border-radius: 999px;
    display: inline-block;
    font-size: 1.2rem;
    font-weight: 600;
    border: 1px solid var(--board-border);
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

/* Setup Panel */
.setup-panel {
    background-color: rgba(30, 41, 59, 0.6);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    border: 1px solid var(--board-border);
}

.hidden {
    display: none !important;
}

.ship-fleet {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
}

.ship-item {
    background-color: var(--board-border);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.ship-item:hover {
    background-color: #334155;
}

.ship-item.selected {
    border-color: var(--primary-color);
    background-color: rgba(59, 130, 246, 0.2);
}

.ship-item.placed {
    opacity: 0.4;
    cursor: not-allowed;
    text-decoration: line-through;
}

.btn {
    background-color: #334155;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn:hover { background-color: #475569; }

.btn-primary {
    background-color: var(--primary-color);
    font-size: 1.1rem;
    padding: 0.75rem 2rem;
}

.btn-primary:hover:not(:disabled) {
    background-color: #2563eb;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
}

.btn:disabled {
    background-color: #1e293b;
    color: #64748b;
    cursor: not-allowed;
}

/* Game Area */
.game-area {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4rem;
}

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

h2 {
    font-size: 1.2rem;
    font-weight: 400;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: #cbd5e1;
}

.board {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(10, 1fr);
    gap: 2px;
    background-color: var(--board-border);
    padding: 2px;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    width: 350px;
    height: 350px;
}

.cell {
    background-color: var(--water-color);
    border-radius: 2px;
    transition: all 0.1s ease;
}

/* Hover effects for Setup Phase */
.setup-mode .cell.highlight-valid {
    background-color: var(--highlight-color);
    cursor: pointer;
}

.setup-mode .cell.highlight-invalid {
    background-color: var(--invalid-color);
    cursor: not-allowed;
}

/* Gameplay Enemy Board */
#enemy-board .cell.game-active:hover {
    background-color: #2563eb;
    transform: scale(1.05);
    z-index: 10;
    cursor: crosshair;
}

/* Ship styles */
.cell.ship { 
    background: linear-gradient(145deg, #64748b, #94a3b8);
    box-shadow: inset 0 0 5px rgba(0,0,0,0.5);
    border: none;
    z-index: 5;
}

/* Horizontal ships */
.cell.ship-h-start {
    border-top-left-radius: 50%;
    border-bottom-left-radius: 50%;
    background: linear-gradient(to right, #475569, #94a3b8);
}
.cell.ship-h-end {
    border-top-right-radius: 50%;
    border-bottom-right-radius: 50%;
    background: linear-gradient(to left, #475569, #94a3b8);
}

/* Vertical ships */
.cell.ship-v-start {
    border-top-left-radius: 50%;
    border-top-right-radius: 50%;
    background: linear-gradient(to bottom, #475569, #94a3b8);
}
.cell.ship-v-end {
    border-bottom-left-radius: 50%;
    border-bottom-right-radius: 50%;
    background: linear-gradient(to top, #475569, #94a3b8);
}

/* Middle segments */
.cell.ship-middle {
    /* No border radius, just connect */
}

/* Hit & Miss Animations */
@keyframes shake {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    10% { transform: translate(-1px, -2px) rotate(-1deg); }
    20% { transform: translate(-3px, 0px) rotate(1deg); }
    30% { transform: translate(3px, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    50% { transform: translate(-1px, 2px) rotate(-1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    70% { transform: translate(3px, 1px) rotate(-1deg); }
    80% { transform: translate(-1px, -1px) rotate(1deg); }
    90% { transform: translate(1px, 2px) rotate(0deg); }
    100% { transform: translate(1px, -2px) rotate(-1deg); }
}

body.shake {
    animation: shake 0.5s;
    animation-iteration-count: 1;
}

@keyframes explosion {
    0% { background-color: #fef08a; transform: scale(1); border-radius: 50%; box-shadow: 0 0 20px #fef08a; z-index: 10; }
    50% { background-color: #f97316; transform: scale(1.3); box-shadow: 0 0 30px #f97316; }
    100% { background-color: var(--hit-color); transform: scale(1); border-radius: 2px; box-shadow: none; z-index: 1; }
}

.cell.hit {
    animation: explosion 0.6s ease-out forwards;
    position: relative;
}

.cell.hit::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 50%; height: 50%;
    background-color: #991b1b;
    border-radius: 50%;
    box-shadow: 0 0 10px #ef4444;
}

@keyframes splash {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 1; }
    50% { transform: translate(-50%, -50%) scale(2); opacity: 0.8; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.cell.miss {
    background-color: var(--miss-color);
    position: relative;
    opacity: 0.7;
}

.cell.miss::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 30%; height: 30%;
    background-color: #e0f2fe;
    border-radius: 50%;
    animation: splash 0.5s ease-out forwards;
}

/* Chat Area */
.chat-container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    background-color: rgba(30, 41, 59, 0.6);
    border-radius: 12px;
    border: 1px solid var(--board-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-messages {
    height: 150px;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chat-message {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    max-width: 80%;
    word-wrap: break-word;
}

.chat-message.self {
    background-color: var(--primary-color);
    align-self: flex-end;
}

.chat-message.opponent {
    background-color: #334155;
    align-self: flex-start;
}

.chat-form {
    display: flex;
    padding: 1rem;
    background-color: #0f172a;
    border-top: 1px solid var(--board-border);
}

#chat-input {
    flex-grow: 1;
    background-color: #1e293b;
    border: 1px solid #334155;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 6px 0 0 6px;
    outline: none;
    font-family: 'Outfit', sans-serif;
}

#chat-input:focus {
    border-color: var(--primary-color);
}

.chat-form .btn {
    border-radius: 0 6px 6px 0;
}

@media (max-width: 800px) {
    .board { width: 300px; height: 300px; }
    .game-area { gap: 2rem; }
}
