@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;700&display=swap');

:root {
    --paper: #efe9d8;
    --paper-light: #fbf8ee;
    --navy: #14253d;
    --sea: #dde5e3;
    --red: #c8321e;
    --cell: 36px;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0 auto;
    max-width: 860px;
    min-height: 100vh;
    padding: clamp(24px, 6vw, 56px) 20px 60px;
    background: var(--paper);
    color: var(--navy);
    font-family: 'IBM Plex Mono', 'Courier New', monospace;
    overscroll-behavior-y: contain;
}

h1 {
    margin: 0 0 24px;
    padding-bottom: 12px;
    border-bottom: 4px solid var(--navy);
    font-size: clamp(28px, 7vw, 46px);
    line-height: 1.05;
    letter-spacing: -0.03em;
    text-transform: uppercase;
}

#status {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: 0 0 32px;
    padding: 12px 16px;
    background: var(--paper-light);
    border-left: 8px solid var(--red);
    font-size: 18px;
    font-weight: 700;
}

.boards {
    display: flex;
    flex-wrap: wrap;
    gap: 40px;
}

.boards section {
    flex: 1 1 320px;
    max-width: 380px;
}

h2 {
    margin: 0 0 12px;
    font-size: 15px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.board {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    width: 100%;
    aspect-ratio: 1 / 1;
    position: relative;
    background: var(--sea);
    border: 3px solid var(--navy);
}

.cell {
    position: relative;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    border: 1px solid rgba(20, 37, 61, 0.28);
}

@media (hover: hover) {
    #enemyBoard .cell:hover {
        background: var(--paper-light);
        cursor: crosshair;
    }
}

.cell.ship {
    background: var(--navy);
}

.cell.hit {
    background: var(--red);
}

.cell.hit::after {
    content: '✕';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--paper-light);
    font-weight: 700;
    font-size: clamp(10px, 3vw, 18px);
}

.cell.miss::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24%;
    height: 24%;
    background: var(--navy);
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

.ship-piece {
    position: absolute;
    background: transparent no-repeat center / 100% 100%;
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.ship-piece.in-dock {
    position: relative;
    flex: none;
}

.ship-piece.dragging {
    z-index: 10;
    opacity: 0.5;
    cursor: grabbing;
}

.ghost {
    position: absolute;
    z-index: 11;
    border: 3px dashed var(--navy);
    background: rgba(20, 37, 61, 0.12);
    pointer-events: none;
}

.ghost.bad {
    border: 3px solid var(--red);
    background: rgba(200, 50, 30, 0.28);
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 18px;
}

.controls button {
    min-height: 44px;
    padding: 10px 16px;
    touch-action: manipulation;
    background: var(--paper-light);
    border: 2px solid var(--navy);
    border-radius: 0;
    box-shadow: 3px 3px 0 var(--navy);
    color: var(--navy);
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.controls button:hover {
    transform: translate(-1px, -1px);
    box-shadow: 4px 4px 0 var(--navy);
}

.controls button:active {
    transform: translate(3px, 3px);
    box-shadow: 0 0 0 var(--navy);
}

.dock {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 14px;
    margin-top: 20px;
    min-height: var(--cell);
}

.controls button:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
    box-shadow: 3px 3px 0 var(--navy);
}

body.playing #randomBtn,
body.playing #clearBtn,
body.playing #playBtn,
body.playing .dock {
    display: none;
}

@media (max-width: 640px) {
    body {
        padding: max(16px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 40px max(14px, env(safe-area-inset-left));
    }

    h1 {
        margin-bottom: 16px;
    }

    #status {
        margin-bottom: 20px;
        padding: 10px 12px;
        font-size: 16px;
    }

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

    .boards section {
        flex: none;
        width: 100%;
        max-width: 420px;
        margin: 0 auto;
    }

    body.playing .boards section:last-child {
        order: -1;
    }

    body.playing .boards section:first-child {
        max-width: 260px;
    }

    .boards section:first-child {
        display: flex;
        flex-direction: column;
    }

    .boards section:first-child .board {
        order: 1;
    }

    .boards section:first-child .dock {
        order: 2;
        margin-top: 14px;
    }

    .boards section:first-child .controls {
        order: 3;
    }

    .controls button {
        flex: 1 1 140px;
    }
}

.online {
    margin: -12px 0 28px;
}

.online .controls {
    margin-top: 0;
    align-items: stretch;
}

.online input {
    flex: 1 1 120px;
    min-width: 0;
    min-height: 44px;
    padding: 10px 12px;
    background: var(--paper-light);
    border: 2px solid var(--navy);
    border-radius: 0;
    color: var(--navy);
    font-family: inherit;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

.online input:disabled {
    opacity: 0.4;
}

.room-info {
    margin-top: 14px;
    padding: 12px 16px;
    background: var(--paper-light);
    border-left: 8px solid var(--navy);
}

.room-info p {
    margin: 0 0 8px;
}

.room-info b {
    font-size: 24px;
    letter-spacing: 0.2em;
}

.room-info[hidden] {
    display: none;
}

body.playing .online {
    display: none;
}

.ship-art {
    position: absolute;
    background: transparent no-repeat center / 100% 100%;
    pointer-events: none;
}

.cell.hit.sunk {
    background: transparent;
}

.cell.hit.sunk::after {
    text-shadow: 0 0 3px var(--red), 0 0 3px var(--red);
}

.ship-art.revealed {
    opacity: 0.5;
}

.app-link {
    margin: 22px 0 0;
}

.app-link[hidden] {
    display: none;
}

.app-link a {
    display: inline-block;
    padding: 8px 14px;
    background: var(--paper-light);
    border: 2px solid var(--navy);
    box-shadow: 3px 3px 0 var(--navy);
    color: var(--navy);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-decoration: none;
    text-transform: uppercase;
}

.app-link a:active {
    transform: translate(3px, 3px);
    box-shadow: 0 0 0 var(--navy);
}

body.playing .app-link {
    display: none;
}

#enemyBoard,
#playerBoard {
    transition: filter 0.3s ease, box-shadow 0.3s ease;
}

body.my-turn #enemyBoard {
    box-shadow: 0 0 0 4px var(--red);
}

body.their-turn #enemyBoard {
    filter: brightness(0.5) saturate(0.6);
    pointer-events: none;
}
