:root {
    --bg: #0b1a2f;
    --bg-2: #122a47;
    --panel: #16314f;
    --panel-2: #1c3a5e;
    --water: #1e4d7b;
    --water-2: #234e72;
    --accent: #4aa3ff;
    --accent-2: #2b7fd6;
    --hit: #ff5a5a;
    --killed: #d63030;
    --miss: #3a5a7a;
    --ship: #8aa6c2;
    --ship-2: #6d8aa8;
    --text: #e8f0fa;
    --muted: #8ea3bd;
    --good: #4ade80;
    --warn: #fbbf24;
    --radius: 12px;
}

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

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    overscroll-behavior: none;
}

#app {
    max-width: 560px;
    margin: 0 auto;
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

.view {
    display: none;
    flex-direction: column;
    flex: 1;
    padding: 16px;
    gap: 14px;
}
.view.active { display: flex; }

/* ---------- Hero / menu ---------- */
.hero { text-align: center; padding: 18px 0 6px; }
.hero h1 { margin: 0; font-size: 28px; letter-spacing: .5px; }
.subtitle { color: var(--muted); margin: 4px 0 0; font-size: 13px; }

.menu-actions { display: flex; flex-direction: column; gap: 10px; }
.join-form { display: flex; gap: 8px; }
.join-form input {
    flex: 1;
    background: var(--panel);
    border: 1px solid var(--panel-2);
    color: var(--text);
    border-radius: var(--radius);
    padding: 12px 14px;
    font-size: 16px;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-align: center;
}
.join-form input:focus { outline: none; border-color: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--panel-2);
    border-radius: var(--radius);
    padding: 13px 16px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform .05s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent-2); border-color: var(--accent); }
.btn-secondary { background: var(--panel-2); }
.btn-small { padding: 8px 12px; font-size: 14px; }
.btn:disabled { opacity: .45; cursor: default; }

.btn-icon {
    background: transparent;
    color: var(--text);
    border: none;
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
}

/* ---------- Stats ---------- */
.stats-panel {
    background: var(--panel);
    border: 1px solid var(--panel-2);
    border-radius: var(--radius);
    padding: 12px 14px;
}
.stats-panel h3 { margin: 0 0 8px; font-size: 14px; color: var(--muted); }
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    text-align: center;
}
.stat-cell .v { font-size: 20px; font-weight: 700; }
.stat-cell .l { font-size: 11px; color: var(--muted); }
.leaderboard { margin: 0; padding-left: 22px; }
.leaderboard li { padding: 3px 0; font-size: 14px; }
.leaderboard li.me { color: var(--accent); font-weight: 700; }

.hint { color: var(--muted); font-size: 12px; text-align: center; margin: 4px 0; }

/* ---------- Topbar ---------- */
.topbar {
    display: flex;
    align-items: center;
    gap: 8px;
}
.topbar h2 { margin: 0; font-size: 18px; flex: 1; }
.turn-timer {
    background: var(--panel);
    border: 1px solid var(--panel-2);
    border-radius: 8px;
    padding: 4px 10px;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    min-width: 44px;
    text-align: center;
}
.turn-timer.warn { color: var(--warn); border-color: var(--warn); }
.turn-timer.danger { color: var(--hit); border-color: var(--hit); }

/* ---------- Lobby ---------- */
.lobby-card {
    background: var(--panel);
    border: 1px solid var(--panel-2);
    border-radius: var(--radius);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.lobby-label { color: var(--muted); font-size: 12px; margin: 8px 0 2px; }
.room-id-row { display: flex; align-items: center; gap: 10px; }
.room-id {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: 4px;
    color: var(--accent);
    flex: 1;
}
.lobby-status { font-size: 15px; }
.lobby-players { display: flex; gap: 8px; margin-top: 8px; }
.player-chip {
    background: var(--panel-2);
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 13px;
}
.player-chip.muted { opacity: .5; }

/* ---------- Boards ---------- */
.board-section { display: flex; flex-direction: column; gap: 6px; }
.board-label {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
    text-align: center;
}
.board {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 2px;
    background: var(--bg-2);
    padding: 4px;
    border-radius: var(--radius);
    aspect-ratio: 1 / 1;
    width: 100%;
    user-select: none;
}
.cell {
    background: var(--water);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: default;
    transition: background .12s;
}
.cell.miss { background: var(--miss); }
.cell.ship { background: var(--ship); }
.cell.hit { background: var(--hit); }
.cell.killed { background: var(--killed); }
.cell.preview { background: var(--accent); opacity: .5; }
.cell.preview-bad { background: var(--hit); opacity: .5; }

.enemy-board .cell { cursor: pointer; }
.enemy-board .cell:active { transform: scale(.92); }
.enemy-board.disabled .cell { cursor: default; }

/* ---------- Placement ---------- */
.placement-board-wrap { display: flex; justify-content: center; }
.ship-pool {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}
.ship-badge {
    background: var(--panel);
    border: 1px solid var(--panel-2);
    border-radius: 8px;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    min-width: 56px;
}
.ship-badge.selected { border-color: var(--accent); background: var(--panel-2); }
.ship-badge.empty { opacity: .3; cursor: default; }
.ship-badge .seg { display: flex; gap: 2px; }
.ship-badge .seg i {
    width: 10px; height: 10px; background: var(--ship); border-radius: 2px; display: block;
}
.ship-badge.empty .seg i { background: var(--panel-2); }
.ship-badge .cnt { font-size: 11px; color: var(--muted); }
.placement-actions { display: flex; gap: 8px; }
.placement-actions .btn { flex: 1; }

/* ---------- Turn indicator ---------- */
.turn-indicator {
    text-align: center;
    font-weight: 700;
    font-size: 15px;
    padding: 8px;
    border-radius: var(--radius);
    background: var(--panel);
}
.turn-indicator.you { background: var(--accent-2); }
.turn-indicator.wait { color: var(--muted); }

/* ---------- Emoji ---------- */
.emoji-bar { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.emoji-btn {
    background: var(--panel);
    border: 1px solid var(--panel-2);
    border-radius: 50%;
    width: 42px; height: 42px;
    font-size: 20px;
    cursor: pointer;
}
.emoji-btn:active { transform: scale(.9); }
.emoji-pop {
    position: fixed;
    left: 50%;
    top: 40%;
    transform: translate(-50%, -50%) scale(.5);
    font-size: 64px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s, transform .6s;
    z-index: 50;
}
.emoji-pop.show { opacity: 1; transform: translate(-50%, -80%) scale(1); }

/* ---------- Overlay ---------- */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(5, 12, 22, .8);
    align-items: center;
    justify-content: center;
    z-index: 40;
}
.overlay.show { display: flex; }
.overlay-card {
    background: var(--panel);
    border: 1px solid var(--panel-2);
    border-radius: 16px;
    padding: 28px 24px;
    text-align: center;
    max-width: 320px;
    width: calc(100% - 32px);
}
.overlay-card h2 { margin: 0 0 8px; font-size: 24px; }
.overlay-card p { color: var(--muted); margin: 0 0 18px; }
.overlay-actions { display: flex; flex-direction: column; gap: 8px; }

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--panel-2);
    color: var(--text);
    padding: 10px 18px;
    border-radius: 20px;
    font-size: 14px;
    opacity: 0;
    transition: opacity .25s, transform .25s;
    pointer-events: none;
    z-index: 60;
    max-width: 90%;
    text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
