/* Game Specific Styles for Battleships Online */

:root {
    --water: #a0c4ff;
    --water-dark: #1a5276;
    --ship: #555;
    --hit: #ff6b6b;
    --miss: #edf2f4;
    --hover: #bdbdbd;
    --valid: rgba(46, 204, 113, 0.7);
    --invalid: rgba(231, 76, 60, 0.7);
    --dragging: rgba(85, 85, 85, 0.5);
    --grid-bg: #333;
}

[data-theme="dark"],
[data-theme="christmas"],
[data-theme="winter"] {
    --water: #1a5276;
    --water-dark: #0d3b5c;
    --ship: #4a6fa5;
    --miss: #2d3748;
    --grid-bg: #0f1419;
}

[data-theme="christmas"] {
    --water: #0d3b5c;
    --ship: #165b33;
    --hit: #d42426;
    --valid: rgba(22, 91, 51, 0.8);
    --invalid: rgba(212, 36, 38, 0.8);
}

[data-theme="winter"] {
    --water: #0d3b5c;
    --water-dark: #003366;
    --ship: #a0e0ff;
    --grid-bg: #1a2a40;
    --hit: #ff4d4d;
    --valid: rgba(160, 224, 255, 0.7);
    --akzent: #00d2ff;
}

body {
    background: var(--body-bg-color) !important;
    background-image: var(--body-bg-image) !important;
    color: var(--text-color) !important;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 20px;
    min-height: 100vh;
    text-align: center;
}

h1 {
    color: var(--text-color);
    margin-bottom: 30px;
}

/* Layout */
.game-container {
    display: flex;
    justify-content: center;
    gap: 40px;
    flex-wrap: wrap;
    margin-top: 20px;
}

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

.board-wrapper h3 {
    margin-bottom: 10px;
    color: var(--text-color);
}

/* Grids */
.grid {
    display: grid;
    grid-template-columns: repeat(10, 30px);
    grid-template-rows: repeat(10, 30px);
    gap: 2px;
    background: var(--grid-bg);
    border: 4px solid var(--grid-bg);
    position: relative;
    border-radius: 8px;
    touch-action: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

@media (max-width: 768px) {
    .game-container {
        gap: 20px;
        flex-direction: column;
        align-items: center;
    }
}

.cell {
    width: 30px;
    height: 30px;
    background: var(--water);
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    position: relative;
}

/* States */
.cell.ship {
    background: var(--ship);
}

.cell.ship:hover {
    background: #666;
    cursor: grab;
}

[data-theme="dark"] .cell.ship:hover,
[data-theme="christmas"] .cell.ship:hover,
[data-theme="winter"] .cell.ship:hover {
    background: var(--akzent);
}

.cell.preview-valid {
    background: var(--valid) !important;
}

.cell.preview-invalid {
    background: var(--invalid) !important;
}

.cell.dragging {
    background: var(--dragging) !important;
}

.cell.hit {
    background: var(--hit) !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cell.hit::after {
    content: '×';
    color: white;
    font-size: 20px;
    font-weight: bold;
}

.cell.miss {
    background: var(--miss) !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cell.miss::after {
    content: '•';
    color: var(--water-dark);
    font-size: 20px;
}

.cell:hover {
    opacity: 0.8;
}

/* Enemy board specific */
#enemy-grid .cell {
    cursor: crosshair;
}

#enemy-grid.disabled {
    pointer-events: none;
    opacity: 0.6;
}

/* Status UI */
#status {
    font-size: 1.2rem;
    font-weight: bold;
    margin: 20px 0;
    padding: 15px 25px;
    background: var(--card-bg);
    color: var(--text-color);
    border-radius: 12px;
    display: inline-block;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: var(--card-border);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.setup-controls {
    margin: 20px;
}

.setup-controls p {
    margin: 10px 0;
    color: var(--text-grey);
}

#invite-section {
    margin-top: 30px;
    padding: 20px;
    background: var(--card-bg);
    border: var(--card-border);
    display: inline-block;
    border-radius: 12px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

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

#invite-section input {
    padding: 10px;
    width: 250px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-color);
    border: var(--card-border);
    border-radius: 8px;
}

/* Dragging overlay */
.drag-ship {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.8;
    display: none;
}

.drag-ship .block {
    width: 30px;
    height: 30px;
    background: var(--ship);
    border: 1px solid var(--grid-bg);
}

.drag-ship.horizontal {
    display: flex;
    flex-direction: row;
}

.drag-ship.vertical {
    display: flex;
    flex-direction: column;
}

/* Join Dialog */
.join-dialog {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 20px;
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: var(--card-border);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    max-width: 450px;
    margin: 50px auto;
}

.join-dialog h2 {
    margin-top: 0;
    margin-bottom: 25px;
    color: var(--text-color);
}

.join-dialog input {
    width: 100%;
    margin: 15px 0;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-color);
    border: var(--card-border);
    border-radius: 10px;
    text-align: center;
}

.or-divider {
    margin: 25px 0;
    color: var(--text-grey);
    font-weight: bold;
}

.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, .3);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s ease-in-out infinite;
    margin-left: 10px;
    vertical-align: middle;
}

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

/* "VERSENKT" Popup */
.sunk-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    font-size: 4rem;
    font-weight: 900;
    color: #ff0000;
    text-shadow:
        0 0 10px rgba(255, 0, 0, 0.8),
        0 0 20px rgba(255, 0, 0, 0.6),
        0 0 40px rgba(255, 0, 0, 0.4),
        3px 3px 0 #8b0000;
    letter-spacing: 0.15em;
    z-index: 9999;
    pointer-events: none;
    opacity: 0;
    font-family: 'Impact', 'Arial Black', sans-serif;
}

.sunk-popup.show {
    animation: sunkPopup 1.5s ease-out forwards;
}

@keyframes sunkPopup {
    0% {
        transform: translate(-50%, -50%) scale(0) rotate(-10deg);
        opacity: 0;
    }

    15% {
        transform: translate(-50%, -50%) scale(1.3) rotate(5deg);
        opacity: 1;
    }

    25% {
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
        opacity: 1;
    }

    75% {
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -50%) scale(0.8) rotate(-5deg);
        opacity: 0;
    }
}

@media (max-width: 768px) {
    .sunk-popup {
        font-size: 2.5rem;
    }
}

/* Rotation Error Popup */
.rotation-error {
    position: fixed;
    top: 20%;
    left: 50%;
    transform: translateX(-50%) scale(0);
    font-size: 1.5rem;
    font-weight: 700;
    color: #ff6b6b;
    background: rgba(0, 0, 0, 0.85);
    padding: 15px 30px;
    border-radius: 12px;
    border: 2px solid #ff6b6b;
    z-index: 9999;
    pointer-events: none;
    opacity: 0;
    box-shadow: 0 0 20px rgba(255, 107, 107, 0.4);
}

.rotation-error.show {
    animation: rotationError 1.2s ease-out forwards;
}

@keyframes rotationError {
    0% {
        transform: translateX(-50%) scale(0);
        opacity: 0;
    }

    15% {
        transform: translateX(-50%) scale(1.1);
        opacity: 1;
    }

    25% {
        transform: translateX(-50%) scale(1);
        opacity: 1;
    }

    75% {
        transform: translateX(-50%) scale(1);
        opacity: 1;
    }

    100% {
        transform: translateX(-50%) scale(0.9);
        opacity: 0;
    }
}

/* Water-marked cells (auto-marked around sunken ships) */
.cell.water-marked {
    background: var(--water-dark) !important;
    position: relative;
}

.cell.water-marked::after {
    content: '·';
    color: rgba(255, 255, 255, 0.3);
    font-size: 16px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Better miss visibility on enemy grid */
#enemy-grid .cell.miss {
    background: var(--miss) !important;
    position: relative;
}

#enemy-grid .cell.miss::after {
    content: '○';
    color: rgba(255, 255, 255, 0.6);
    font-size: 14px;
    font-weight: bold;
}