:root {
    --bg-deep: #041425;
    --bg-mid: #0b2f4d;
    --panel: rgba(4, 20, 37, 0.8);
    --panel-line: rgba(146, 213, 255, 0.2);
    --text: #e9f6ff;
    --muted: #b2d5ec;
    --accent: #19d3ff;
    --accent-alt: #ffd166;
    --danger: #ff5a6f;
    --ok: #2dd4a8;
    --cell: min(8vw, 44px);
    --shadow: 0 16px 42px rgba(1, 9, 20, 0.55);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: "Outfit", sans-serif;
    color: var(--text);
    background: radial-gradient(circle at 15% 15%, #0f4c75 0%, rgba(15, 76, 117, 0) 38%),
        radial-gradient(circle at 82% 18%, #1a5f7a 0%, rgba(26, 95, 122, 0) 35%),
        linear-gradient(160deg, #021322 0%, #06233b 48%, #010d18 100%);
    overflow-x: hidden;
}

.ocean-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    opacity: 0.28;
    background-image: repeating-linear-gradient(135deg,
            rgba(25, 211, 255, 0.2) 0,
            rgba(25, 211, 255, 0.2) 1px,
            transparent 1px,
            transparent 10px);
    pointer-events: none;
}

.app {
    position: relative;
    z-index: 1;
    width: min(1280px, 96vw);
    margin: 1.8rem auto;
    display: grid;
    gap: 1rem;
    grid-template-columns: minmax(290px, 370px) 1fr;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--panel-line);
    border-radius: 22px;
    box-shadow: var(--shadow);
}

.panel-controls {
    padding: 1rem;
    display: grid;
    gap: 0.9rem;
    align-content: start;
    max-height: calc(100vh - 120px);
    overflow: auto;
}

h1,
h2,
h3 {
    margin: 0;
    font-family: "Rajdhani", sans-serif;
    letter-spacing: 0.04em;
}

h1 {
    font-size: clamp(2rem, 4.8vw, 2.8rem);
}

h2 {
    font-size: 1.2rem;
}

.lead {
    margin: 0;
    color: var(--muted);
    line-height: 1.4;
}

.controls-grid {
    display: grid;
    gap: 0.7rem;
}

label {
    display: grid;
    gap: 0.3rem;
    font-size: 0.95rem;
}

select,
input,
button {
    font: inherit;
}

select,
input[type="text"],
input[type="password"] {
    width: 100%;
    border-radius: 10px;
    border: 1px solid rgba(178, 213, 236, 0.35);
    background: rgba(2, 19, 34, 0.7);
    color: var(--text);
    padding: 0.55rem 0.65rem;
}

select:focus,
input:focus,
button:focus-visible {
    outline: 2px solid rgba(25, 211, 255, 0.7);
    outline-offset: 1px;
}

.online-box {
    border: 1px solid rgba(25, 211, 255, 0.4);
    background: rgba(4, 45, 74, 0.45);
    border-radius: 12px;
    padding: 0.7rem;
    display: grid;
    gap: 0.5rem;
}

.online-actions {
    display: flex;
    gap: 0.5rem;
}

.online-status {
    margin: 0;
    color: #d2f0ff;
    font-size: 0.86rem;
}

.hidden {
    display: none;
}

.ship-palette {
    display: grid;
    gap: 0.45rem;
    margin-bottom: 0.35rem;
}

.ship-btn {
    text-align: left;
    border: 1px solid rgba(178, 213, 236, 0.35);
    border-radius: 10px;
    background: rgba(3, 26, 45, 0.8);
    color: var(--text);
    padding: 0.5rem 0.65rem;
    cursor: pointer;
    transition: transform 0.14s ease, border-color 0.14s ease;
}

.ship-btn-row {
    display: grid;
    grid-template-columns: 44px 1fr;
    align-items: center;
    gap: 0.6rem;
}

.ship-btn-copy {
    display: grid;
    gap: 0.08rem;
}

.ship-btn-name {
    font-weight: 600;
}

.ship-btn-status {
    font-size: 0.78rem;
    color: var(--muted);
}

.ship-preview {
    --unit: 6px;
    position: relative;
    width: calc(var(--w, 1) * var(--unit));
    height: calc(var(--h, 1) * var(--unit));
    min-width: 14px;
    border-radius: 5px;
    background: rgba(2, 19, 34, 0.5);
    border: 1px solid rgba(178, 213, 236, 0.3);
    justify-self: center;
}

.ship-preview-cell {
    position: absolute;
    width: var(--unit);
    height: var(--unit);
    left: calc(var(--x) * var(--unit));
    top: calc(var(--y) * var(--unit));
    border-radius: 2px;
    background: linear-gradient(145deg, #8ea7bb, #466176);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.ship-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(255, 209, 102, 0.85);
}

.ship-btn.active {
    border-color: rgba(25, 211, 255, 0.9);
    background: rgba(3, 53, 82, 0.85);
}

.ship-btn.placed {
    opacity: 0.55;
}

.placement-actions,
.controls-actions {
    display: grid;
    gap: 0.45rem;
}

.placement-actions {
    margin-top: 0.35rem;
    gap: 0.55rem;
}

.btn {
    border-radius: 10px;
    border: 1px solid rgba(178, 213, 236, 0.35);
    background: rgba(3, 26, 45, 0.85);
    color: var(--text);
    padding: 0.6rem 0.7rem;
    cursor: pointer;
    transition: transform 0.14s ease, filter 0.14s ease;
}

.btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.08);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    border: 0;
    color: #042237;
    font-weight: 700;
    background: linear-gradient(120deg, #19d3ff 0%, #ffd166 100%);
}

.btn-ghost {
    background: rgba(3, 26, 45, 0.45);
}

.toggle {
    display: flex;
    gap: 0.45rem;
    align-items: center;
    font-size: 0.92rem;
}

.stats-box {
    border-top: 1px dashed rgba(178, 213, 236, 0.3);
    padding-top: 0.65rem;
}

#statsList {
    margin: 0.4rem 0 0;
    padding-left: 1rem;
    color: var(--muted);
    display: grid;
    gap: 0.28rem;
}

.panel-game {
    padding: 0.9rem;
    display: grid;
    gap: 0.8rem;
    align-content: start;
}

.game-head {
    display: grid;
    gap: 0.25rem;
}

.phase-label,
.turn-label,
.result-label {
    margin: 0;
}

.phase-label {
    color: #9ad9ff;
}

.result-label {
    min-height: 1.4em;
    color: #ffe29a;
}

.boards-wrap {
    display: grid;
    gap: 0.8rem;
    grid-template-columns: repeat(2, minmax(250px, 1fr));
}

.board-card {
    border: 1px solid rgba(146, 213, 255, 0.2);
    border-radius: 16px;
    background: rgba(1, 15, 27, 0.55);
    padding: 0.6rem;
    display: grid;
    gap: 0.45rem;
}

.board-card-target {
    box-shadow: inset 0 0 0 1px rgba(255, 209, 102, 0.25);
}

.board {
    --gap: 3px;
    display: grid;
    width: min(100%, calc(var(--cell) * 10 + var(--gap) * 9));
    aspect-ratio: 1 / 1;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    grid-template-rows: repeat(10, minmax(0, 1fr));
    gap: var(--gap);
    justify-content: center;
    align-content: center;
    margin-inline: auto;
}

.cell {
    border: 1px solid rgba(151, 202, 238, 0.2);
    border-radius: 6px;
    background: linear-gradient(135deg, #0c2e48 0%, #071220 100%);
    position: relative;
    cursor: pointer;
    overflow: hidden;
    width: 100%;
    height: 100%;
    padding: 0;
    min-width: 0;
    line-height: 0;
}

.cell::after {
    content: "";
    display: none;
}

.cell.ship {
    background: linear-gradient(145deg, #628198, #30495c);
}

.cell.ship-hovered {
    box-shadow: inset 0 0 0 2px rgba(25, 211, 255, 0.9), 0 0 14px rgba(25, 211, 255, 0.45);
    filter: brightness(1.14);
}

.cell.preview-valid {
    box-shadow: inset 0 0 0 2px rgba(45, 212, 168, 0.9);
}

.cell.preview-invalid {
    box-shadow: inset 0 0 0 2px rgba(255, 90, 111, 0.9);
}

.cell.miss {
    background: linear-gradient(170deg, #125c87, #0a3657);
}

.cell.miss::before {
    content: "";
    position: absolute;
    width: 42%;
    aspect-ratio: 1;
    border-radius: 999px;
    border: 2px solid rgba(191, 234, 255, 0.75);
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    animation: splash 450ms ease-out;
}

.cell.hit {
    background: radial-gradient(circle at 45% 45%, #ffd166 0%, #ff8f4a 35%, #a11d33 100%);
}

.cell.hit::before {
    content: "";
    position: absolute;
    inset: 16%;
    background: radial-gradient(circle, rgba(255, 244, 165, 0.95) 0%, rgba(255, 102, 0, 0.1) 75%);
    animation: blast 360ms ease-out;
}

.cell.sunk {
    background: linear-gradient(170deg, #0f172a, #2a3445);
}

.cell.sunk::after {
    animation: none;
    background: rgba(9, 15, 23, 0.7);
}

.cell.revealed-ship {
    box-shadow: inset 0 0 0 2px rgba(255, 209, 102, 0.68);
}

.app-footer {
    grid-column: 1 / -1;
    justify-self: center;
    margin-top: 0.1rem;
    font-size: 0.78rem;
    color: rgba(201, 228, 247, 0.7);
    display: inline-flex;
    gap: 0.4rem;
    align-items: center;
    border: 1px solid rgba(146, 213, 255, 0.2);
    border-radius: 999px;
    padding: 0.2rem 0.65rem;
    background: rgba(2, 17, 30, 0.36);
}

.app-footer a {
    color: rgba(233, 246, 255, 0.9);
    text-decoration: underline;
    text-decoration-color: rgba(255, 209, 102, 0.6);
    text-underline-offset: 2px;
}

@keyframes splash {
    from {
        transform: scale(0.4);
        opacity: 1;
    }

    to {
        transform: scale(1.2);
        opacity: 0;
    }
}

@keyframes blast {
    from {
        transform: scale(0.6);
        opacity: 1;
    }

    to {
        transform: scale(1.35);
        opacity: 0;
    }
}

@media (max-width: 1080px) {
    .app {
        grid-template-columns: 1fr;
    }

    .panel-controls {
        max-height: none;
    }

    .boards-wrap {
        grid-template-columns: 1fr;
    }

    .board-card-target {
        order: -1;
        border-color: rgba(255, 209, 102, 0.42);
    }
}

@media (max-width: 560px) {
    :root {
        --cell: min(8.8vw, 37px);
    }

    .app {
        width: min(99vw, 99vw);
        margin: 0.5rem auto;
    }

    .panel,
    .board-card {
        border-radius: 14px;
    }

    .panel-game {
        padding: 0.55rem;
    }

    .panel-controls {
        padding: 0.7rem;
    }

    .online-actions {
        flex-direction: column;
    }
}

@media (prefers-reduced-motion: reduce) {

    .ocean-bg,
    .cell::after,
    .cell::before,
    .btn,
    .ship-btn {
        animation: none !important;
        transition: none !important;
    }
}
