/* Battleship — dumbshit.app */

*, *::before, *::after { box-sizing: border-box; }

:root {
    --bg: #07101c;            /* deep navy black */
    --bg-2: #0e1a2c;
    --bg-3: #18253b;
    --border: #26385a;
    --text: #e8eef7;
    --text-dim: #9aabc4;
    --text-mute: #5d728f;
    --accent: #38bdf8;        /* sky cyan */
    --accent-hov: #7dd3fc;
    --hit: #ef4444;
    --miss: #cbd5e1;
    --sunk: #fbbf24;
    --ship: #475569;
    --ship-edge: #94a3b8;
    --danger: #ef4444;
    --water: rgba(56, 189, 248, 0.05);
}

html, body {
    margin: 0; padding: 0;
    background:
        radial-gradient(circle at 20% 0%, rgba(56, 189, 248, 0.06), transparent 50%),
        radial-gradient(circle at 80% 100%, rgba(56, 189, 248, 0.04), transparent 50%),
        var(--bg);
    color: var(--text);
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

/* ===== topbar ===== */
.topbar { padding: 24px 24px 8px; max-width: 1200px; margin: 0 auto; }
.back { color: var(--text-mute); text-decoration: none; font-family: ui-monospace, monospace; font-size: 12px; }
.back:hover { color: var(--text); }
.topbar h1 { margin: 12px 0 4px; font-size: clamp(28px, 4vw, 40px); font-weight: 800; letter-spacing: -0.02em; }
.topbar .sub { margin: 0; color: var(--text-dim); font-size: 15px; }

.app { max-width: 1200px; margin: 0 auto; padding: 16px 24px 60px; }

/* ===== shared form / lobby (same shape as TTT/Pong) ===== */
.card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px;
    max-width: 480px;
    margin: 16px auto;
}
.field { display: block; margin-bottom: 12px; }
.lbl {
    display: block;
    font-family: ui-monospace, monospace;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 10px;
    color: var(--text-mute);
    margin-bottom: 6px;
}
input[type=text] {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    padding: 11px 14px;
    width: 100%;
    transition: border-color 0.15s;
}
input[type=text]:focus { outline: none; border-color: var(--accent); }
.btn {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--bg-3);
    color: var(--text);
    font-family: inherit;
    font-weight: 600;
    font-size: 14px;
    padding: 11px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.12s;
}
.btn:hover:not(:disabled) { background: var(--border); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--bg); border-color: var(--accent); width: 100%; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hov); border-color: var(--accent-hov); }
.btn-ghost { appearance: none; background: transparent; color: var(--text-mute); border: 0; cursor: pointer; font-family: ui-monospace, monospace; font-size: 12px; padding: 6px 10px; border-radius: 6px; }
.btn-ghost:hover { color: var(--text); }
.hint { color: var(--text-mute); font-size: 12px; }

.tabs { display: flex; gap: 4px; background: var(--bg); border-radius: 8px; padding: 4px; margin-bottom: 12px; }
.tab { appearance: none; border: 0; background: transparent; color: var(--text-mute); font-family: inherit; font-size: 13px; font-weight: 600; padding: 7px 12px; border-radius: 6px; cursor: pointer; flex: 1; }
.tab:hover { color: var(--text); }
.tab.is-active { background: var(--bg-3); color: var(--text); }
.pane { padding-top: 4px; }
.chk { display: flex; align-items: flex-start; gap: 8px; color: var(--text-dim); font-size: 13px; margin-bottom: 10px; cursor: pointer; line-height: 1.4; }
.chk input { width: 16px; height: 16px; accent-color: var(--accent); margin-top: 2px; }

.lobby-head { display: flex; align-items: center; justify-content: space-between; font-family: ui-monospace, monospace; font-size: 11px; color: var(--text-mute); margin-bottom: 8px; }
.lobby-head .dot { display: inline-block; width: 6px; height: 6px; border-radius: 999px; background: var(--accent); margin-left: 4px; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }
.lobby-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; max-height: 240px; overflow-y: auto; }
.lobby-list .empty { color: var(--text-mute); font-style: italic; text-align: center; padding: 14px; font-size: 13px; }
.lobby-list .lobby-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 8px; padding: 8px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; font-family: ui-monospace, monospace; font-size: 12px; }
.lobby-list .lobby-row .when { color: var(--text-mute); font-size: 11px; }
.lobby-list .lobby-row .join { appearance: none; border: 0; background: var(--accent); color: var(--bg); padding: 5px 10px; border-radius: 6px; font-family: inherit; font-weight: 600; font-size: 11px; cursor: pointer; }
.lobby-list .lobby-row .join:hover { background: var(--accent-hov); }

.share-row { display: flex; gap: 6px; margin: 12px 0; }
.share-row input { flex: 1; font-family: ui-monospace, monospace; font-size: 12px; color: var(--text-dim); }
.share-row .btn { padding: 11px 14px; }
.waiting-status { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-family: ui-monospace, monospace; font-size: 12px; margin: 12px 0; }
.waiting-status .pulse { width: 8px; height: 8px; border-radius: 999px; background: var(--accent); animation: pulse 1.6s ease-in-out infinite; }
.join-error { margin-top: 10px; padding: 10px 12px; background: rgba(239,68,68,0.08); border: 1px solid var(--danger); border-radius: 8px; color: #fecaca; font-size: 13px; }
.join-sub { color: var(--text-dim); margin-top: 0; }

/* ===== SETUP phase ============================================= */
.setup-shell {
    display: grid;
    grid-template-columns: 1fr 260px 260px;
    gap: 16px;
    align-items: start;
}
.setup-main { background: var(--bg-2); border: 1px solid var(--border); border-radius: 14px; padding: 18px; }
.setup-side { background: var(--bg-2); border: 1px solid var(--border); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.setup-chat { /* chat panel uses chat.css; just dock it on the right */ }
.phase-title { margin: 0 0 14px; font-size: 16px; font-family: ui-monospace, monospace; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }
.phase-status { margin-top: 12px; color: var(--text-mute); font-family: ui-monospace, monospace; font-size: 11px; text-align: center; min-height: 14px; }
.phase-status.is-ready  { color: var(--accent); }
.phase-status.is-error  { color: #fecaca; }

.palette { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.ship-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: grab;
    user-select: none;
    touch-action: none;
    transition: border-color 0.12s, opacity 0.12s;
}
.ship-item.placed { opacity: 0.4; cursor: default; }
.ship-item.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.25); }
.ship-item .ship-glyph {
    display: inline-block;
    height: 14px;
    background: linear-gradient(180deg, var(--ship-edge), var(--ship));
    border-radius: 6px;
    flex-shrink: 0;
}
.ship-item .ship-name { flex: 1; font-size: 13px; font-weight: 600; }
.ship-item .ship-size { font-family: ui-monospace, monospace; font-size: 11px; color: var(--text-mute); }

.setup-actions { display: flex; gap: 6px; }
.setup-actions .btn { flex: 1; }

/* ===== BATTLE phase ============================================ */
.battle-banner {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 18px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.banner-turn {
    font-family: ui-monospace, monospace;
    font-size: 14px;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.banner-turn.theirs { color: var(--text-mute); }
.banner-turn.over   { color: var(--sunk); }
.banner-meta {
    font-family: ui-monospace, monospace;
    font-size: 11px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.battle-shell {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 16px;
    align-items: start;
}
.battle-grids {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
}
.grid-block { display: flex; flex-direction: column; gap: 8px; }
.grid-label {
    font-family: ui-monospace, monospace;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 10px;
    color: var(--text-mute);
}
.fleet-status { background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; grid-column: 1 / -1; }
.fleet-list { list-style: none; padding: 0; margin: 6px 0 0; display: flex; flex-wrap: wrap; gap: 8px; font-family: ui-monospace, monospace; font-size: 12px; }
.fleet-list li {
    padding: 4px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    display: inline-flex; align-items: center; gap: 6px;
}
.fleet-list li.sunk { color: var(--text-mute); text-decoration: line-through; opacity: 0.6; }
.battle-chat { /* same chat panel mount */ }

/* ===== board (10×10) common ===== */
.board {
    position: relative;
    --cell: 32px;
    display: grid;
    grid-template-columns: 18px repeat(10, var(--cell));
    grid-template-rows: 18px repeat(10, var(--cell));
    gap: 1px;
    aspect-ratio: 11 / 11;
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
    background: var(--bg);
    padding: 4px;
    border-radius: 10px;
    user-select: none;
    touch-action: manipulation;
}
.setup-board { max-width: 460px; touch-action: none; }   /* drag-to-place would otherwise scroll the page on mobile */
.board .axis {
    color: var(--text-mute);
    font-family: ui-monospace, monospace;
    font-size: 10px;
    display: grid;
    place-items: center;
    line-height: 1;
}
.board .cell {
    background: var(--water);
    border-radius: 3px;
    position: relative;
    transition: background 0.1s;
    cursor: default;
}
.board.clickable .cell:not(.shot) { cursor: crosshair; }
.board.clickable .cell:not(.shot):hover { background: rgba(56, 189, 248, 0.15); }

.board .cell.ship  {
    background: linear-gradient(180deg, var(--ship-edge), var(--ship));
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}
/* round outer corners of ships when neighbors don't have ships */
.board .cell.ship.ship-edge-l  { border-top-left-radius: 8px;     border-bottom-left-radius: 8px; }
.board .cell.ship.ship-edge-r  { border-top-right-radius: 8px;    border-bottom-right-radius: 8px; }
.board .cell.ship.ship-edge-t  { border-top-left-radius: 8px;     border-top-right-radius: 8px; }
.board .cell.ship.ship-edge-b  { border-bottom-left-radius: 8px;  border-bottom-right-radius: 8px; }
.board .cell.shot::after {
    content: '';
    position: absolute;
    inset: 30%;
    border-radius: 999px;
    background: var(--miss);
    box-shadow: 0 0 6px rgba(203,213,225,0.4);
}
.board .cell.shot.hit::after { background: var(--hit); box-shadow: 0 0 10px rgba(239,68,68,0.6); animation: splash 0.3s ease-out; }
.board .cell.shot.miss::after { background: var(--miss); }
.board .cell.shot.sunk { background: rgba(251, 191, 36, 0.12); }
.board .cell.shot.sunk::after { background: var(--sunk); box-shadow: 0 0 10px rgba(251, 191, 36, 0.6); }
.board .cell.pending::after { background: var(--text-mute); opacity: 0.5; }

@keyframes splash {
    0%   { transform: scale(0.4); opacity: 0; }
    60%  { transform: scale(1.4); opacity: 1; }
    100% { transform: scale(1);   opacity: 1; }
}

/* drag preview overlay (during ship placement) */
.board .cell.preview-ok  { background: rgba(56, 189, 248, 0.35); }
.board .cell.preview-bad { background: rgba(239, 68, 68, 0.3); }

/* ===== overlays ===== */
.overlay {
    position: fixed; inset: 0;
    background: rgba(7, 16, 28, 0.84);
    backdrop-filter: blur(6px);
    display: grid;
    place-items: center;
    z-index: 100;
    padding: 20px;
    overflow-y: auto;
}
.overlay-card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 22px;
    text-align: center;
    max-width: 560px;
    width: 100%;
}
.overlay-eyebrow { font-family: ui-monospace, monospace; font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-mute); margin-bottom: 6px; }
.overlay-card h2 { margin: 0 0 8px; font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.overlay-stats { color: var(--text-dim); margin: 0 0 16px; font-family: ui-monospace, monospace; font-size: 13px; }
.cheat-banner {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid var(--danger);
    color: #fecaca;
    border-radius: 8px;
    padding: 10px;
    font-family: ui-monospace, monospace;
    font-size: 12px;
    margin-bottom: 12px;
    letter-spacing: 0.04em;
}
.end-grids {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin: 14px 0 16px;
}
.end-grids .grid-block { font-size: 11px; }
.end-grids .board { max-width: 240px; --cell: 18px; }
.overlay-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.overlay-actions .btn { width: 100%; }

/* ===== responsive ===== */
@media (max-width: 900px) {
    .setup-shell { grid-template-columns: 1fr; }
    .setup-chat, .battle-chat { height: 200px; }
    .battle-shell { grid-template-columns: 1fr; }
    .battle-grids { grid-template-columns: 1fr; }
    .end-grids { grid-template-columns: 1fr; }
    .board { --cell: 28px; }
}
@media (max-width: 480px) {
    .board { --cell: 24px; }
    .setup-board { --cell: 26px; }
}

/* ===== foot ===== */
.foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 24px;
    max-width: 1200px;
    margin: 0 auto;
    color: var(--text-mute);
    font-family: ui-monospace, monospace;
    font-size: 11px;
    letter-spacing: 0.04em;
}
.bmc-link { display: inline-flex; align-items: center; gap: 6px; color: var(--text-mute); text-decoration: none; transition: color 0.15s; }
.bmc-link:hover { color: #FFDD00; }
