/* Modern Tactical Ocean Theme for 2-Player & 3-Player Mobile Battleship */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800&family=JetBrains+Mono:wght@500;700&display=swap');

:root {
    --bg-dark: #070d19;
    --bg-panel: rgba(17, 28, 51, 0.85);
    --bg-panel-solid: #111c33;
    --bg-grid: #0d172a;
    --border-color: rgba(0, 229, 255, 0.2);
    
    --primary-cyan: #00e5ff;
    --primary-green: #00ff9d;
    --hit-red: #ff3366;
    --miss-blue: #3b82f6;
    --ship-gray: #475569;
    --ship-placed: #0284c7;
    --ship-sunk: #dc2626;

    --player1-color: #00e5ff;
    --player2-color: #ff9900;
    --player3-color: #a855f7;

    --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
    --glass-border: 1px solid rgba(255, 255, 255, 0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(circle at 50% 0%, rgba(0, 229, 255, 0.12) 0%, transparent 60%),
        radial-gradient(circle at 100% 100%, rgba(168, 85, 247, 0.08) 0%, transparent 50%),
        linear-gradient(180deg, #050a14 0%, #0a1324 100%);
    color: #f8fafc;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Header & Controls */
header {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: var(--glass-border);
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    gap: 6px;
}

.brand-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 800;
    font-size: 1rem;
    letter-spacing: 0.5px;
    background: linear-gradient(135deg, #ffffff 0%, var(--primary-cyan) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    flex-wrap: wrap;
}

.brand-title .badge-3p {
    background: linear-gradient(135deg, #ff9900, #ff3366);
    -webkit-text-fill-color: #fff;
    font-size: 0.6rem;
    font-weight: 800;
    padding: 2px 5px;
    border-radius: 4px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.header-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.btn-icon {
    background: rgba(255, 255, 255, 0.08);
    border: var(--glass-border);
    color: #cbd5e1;
    padding: 5px 10px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-icon:active {
    transform: scale(0.94);
    background: rgba(255, 255, 255, 0.15);
}

/* Main Container */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
    padding: 10px;
    gap: 10px;
}

/* Player Status Bar */
.players-status-bar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    width: 100%;
}

.players-status-bar.mode-2p {
    grid-template-columns: repeat(2, 1fr);
}

.player-card {
    background: var(--bg-panel);
    border-radius: 10px;
    padding: 6px 4px;
    border: 1.5px solid transparent;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 3px;
}

.player-card.active {
    box-shadow: 0 0 12px rgba(0, 229, 255, 0.25);
    background: rgba(17, 28, 51, 0.95);
}

.player-card.p1.active { border-color: var(--player1-color); }
.player-card.p2.active { border-color: var(--player2-color); }
.player-card.p3.active { border-color: var(--player3-color); }

.player-card.eliminated {
    opacity: 0.45;
    filter: grayscale(0.8);
}

.player-card.eliminated::after {
    content: "ELIMINATED";
    position: absolute;
    inset: 0;
    background: rgba(220, 38, 38, 0.8);
    color: #fff;
    font-weight: 800;
    font-size: 0.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 0.5px;
}

.player-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.75rem;
    color: #fff;
    flex-shrink: 0;
}

.p1 .player-avatar { background: linear-gradient(135deg, #00b4d8, #00e5ff); }
.p2 .player-avatar { background: linear-gradient(135deg, #e67e22, #ff9900); }
.p3 .player-avatar { background: linear-gradient(135deg, #8e44ad, #a855f7); }

.player-name {
    font-size: 0.7rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.player-health {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.player-health-fill {
    height: 100%;
    width: 100%;
    border-radius: 4px;
    transition: width 0.4s ease;
}

.p1 .player-health-fill { background: var(--player1-color); }
.p2 .player-health-fill { background: var(--player2-color); }
.p3 .player-health-fill { background: var(--player3-color); }

.player-score {
    font-size: 0.6rem;
    font-family: var(--font-mono);
    color: #94a3b8;
    white-space: nowrap;
}

/* Setup Screen */
.screen {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.hidden {
    display: none !important;
}

.panel-card {
    background: var(--bg-panel);
    border-radius: 14px;
    border: var(--glass-border);
    padding: 14px;
    box-shadow: var(--glass-shadow);
    width: 100%;
}

.section-title {
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.config-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

/* Fully Mobile Responsive Player Input Row */
.player-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.03);
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    width: 100%;
}

.input-text {
    flex: 1 1 100px;
    min-width: 0;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    padding: 8px 10px;
    border-radius: 8px;
    font-family: var(--font-main);
    font-size: 0.85rem;
    outline: none;
}

.input-text:focus {
    border-color: var(--primary-cyan);
}

.select-type {
    flex: 0 0 auto;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    padding: 8px 6px;
    border-radius: 8px;
    font-size: 0.78rem;
    outline: none;
    max-width: 115px;
}

/* Primary Action Buttons */
.btn-primary {
    background: linear-gradient(135deg, #00b4d8 0%, #00e5ff 100%);
    color: #050e1d;
    font-family: var(--font-main);
    font-weight: 800;
    font-size: 0.95rem;
    padding: 12px 16px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 229, 255, 0.3);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.btn-primary:active {
    transform: scale(0.98);
    box-shadow: 0 2px 8px rgba(0, 229, 255, 0.2);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    border: var(--glass-border);
    color: #e2e8f0;
    font-family: var(--font-main);
    font-weight: 600;
    font-size: 0.82rem;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    white-space: nowrap;
}

.btn-secondary.active-mode {
    background: rgba(0, 229, 255, 0.2);
    border-color: var(--primary-cyan);
    color: #fff;
    box-shadow: 0 0 10px rgba(0, 229, 255, 0.3);
}

.btn-secondary:active {
    transform: scale(0.96);
    background: rgba(255, 255, 255, 0.14);
}

/* Orientation Toggle Switch */
.orientation-toggle-group {
    display: flex;
    background: rgba(0, 0, 0, 0.5);
    padding: 3px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    flex: 1 1 180px;
}

.btn-toggle {
    flex: 1;
    background: transparent;
    border: none;
    color: #94a3b8;
    padding: 8px 10px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.btn-toggle.active {
    background: linear-gradient(135deg, #00b4d8, #00e5ff);
    color: #050e1d;
    box-shadow: 0 0 10px rgba(0, 229, 255, 0.4);
}

/* Placement Screen */
.placement-header {
    text-align: center;
    margin-bottom: 6px;
}

.placement-instruction {
    font-size: 0.8rem;
    color: #94a3b8;
    margin-top: 4px;
}

.placement-controls {
    display: flex;
    gap: 6px;
    justify-content: center;
    align-items: center;
    margin-bottom: 10px;
    flex-wrap: wrap;
    width: 100%;
}

.ships-dock {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 6px 2px;
    margin-bottom: 8px;
    scrollbar-width: none;
    width: 100%;
}

.ships-dock::-webkit-scrollbar {
    display: none;
}

.ship-item {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: center;
    min-width: 75px;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.ship-item.selected {
    background: rgba(0, 229, 255, 0.2);
    border-color: var(--primary-cyan);
    box-shadow: 0 0 10px rgba(0, 229, 255, 0.3);
}

.ship-item.placed {
    opacity: 0.4;
    cursor: default;
    border-color: transparent;
}

.ship-name {
    font-size: 0.68rem;
    font-weight: 700;
    color: #e2e8f0;
}

/* Vector SVG Ship Graphics */
.ship-svg {
    width: 55px;
    height: 22px;
    filter: drop-shadow(0 0 4px rgba(0, 229, 255, 0.4));
    transition: transform 0.2s ease;
}

.ship-svg.vertical-preview {
    transform: rotate(90deg);
}

/* Grid Container */
.grid-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin: 0 auto;
    touch-action: manipulation;
}

.board-grid {
    display: grid;
    gap: 2px;
    background: rgba(0, 0, 0, 0.5);
    padding: 4px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.6);
    width: 100%;
    max-width: min(100%, 380px);
    aspect-ratio: 1 / 1;
    position: relative;
}

.board-cell {
    background: var(--bg-grid);
    border-radius: 4px;
    position: relative;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.board-cell:active {
    transform: scale(0.92);
}

/* Placed Ship Cells with SVG Vector Hull */
.board-cell.has-ship {
    background: #0f172a;
    box-shadow: inset 0 0 8px rgba(0, 229, 255, 0.3);
    border: 1px solid rgba(0, 229, 255, 0.3);
}

.board-cell.has-ship .ship-svg,
.board-cell.sunk .ship-svg {
    width: 80%;
    height: 80%;
    filter: drop-shadow(0 0 4px rgba(0, 229, 255, 0.6));
    z-index: 1;
}

.board-cell.preview-valid {
    background: rgba(0, 255, 157, 0.5) !important;
}

.board-cell.preview-invalid {
    background: rgba(255, 51, 102, 0.5) !important;
}

.board-cell.hit {
    background: rgba(255, 51, 102, 0.35);
}

.board-cell.hit::before {
    content: "X";
    font-family: var(--font-mono);
    font-weight: 800;
    font-size: 1rem;
    color: var(--hit-red);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 2;
}

.board-cell.miss {
    background: rgba(59, 130, 246, 0.15);
}

.board-cell.miss::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--miss-blue);
    box-shadow: 0 0 6px var(--miss-blue);
    animation: popIn 0.2s ease;
}

.board-cell.sunk {
    background: rgba(220, 38, 38, 0.5);
}

.board-cell.sunk::before {
    content: "X";
    font-family: var(--font-mono);
    font-weight: 900;
    font-size: 1.1rem;
    color: #ffffff;
    z-index: 2;
}

/* Combat Screen Setup & Tabs */
.combat-area {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.target-tabs {
    display: flex;
    gap: 6px;
    width: 100%;
}

.target-tab {
    flex: 1;
    padding: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    color: #94a3b8;
    font-weight: 700;
    font-size: 0.78rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.target-tab.active {
    background: rgba(0, 229, 255, 0.15);
    border-color: var(--primary-cyan);
    color: #fff;
    box-shadow: 0 0 10px rgba(0, 229, 255, 0.2);
}

.target-tab.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.tactical-status-banner {
    background: rgba(0, 0, 0, 0.4);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 0.8rem;
    text-align: center;
    font-weight: 600;
    color: var(--primary-cyan);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.tactical-status-banner.alert {
    color: var(--hit-red);
}

/* Battle Log */
.battle-log-card {
    background: rgba(0, 0, 0, 0.3);
    border: var(--glass-border);
    border-radius: 8px;
    padding: 6px 10px;
    max-height: 85px;
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    display: flex;
    flex-direction: column;
    gap: 3px;
    width: 100%;
}

.log-entry {
    color: #cbd5e1;
    display: flex;
    gap: 6px;
}

.log-entry .time {
    color: #64748b;
}

.log-entry.hit {
    color: var(--hit-red);
}

.log-entry.sunk {
    color: #ff9900;
    font-weight: 700;
}

/* Modal Overlay (Turn Privacy & GameOver) */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 10, 20, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: fadeIn 0.25s ease;
}

.modal-card {
    background: var(--bg-panel-solid);
    border: var(--glass-border);
    border-radius: 16px;
    padding: 20px 16px;
    max-width: 380px;
    width: 100%;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    gap: 14px;
    position: relative;
    overflow: hidden;
}

.modal-title {
    font-size: 1.3rem;
    font-weight: 800;
    color: #fff;
}

.modal-subtitle {
    font-size: 0.85rem;
    color: #94a3b8;
    line-height: 1.4;
}

.privacy-badge {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: #f87171;
    font-weight: 700;
    font-size: 0.7rem;
    padding: 3px 8px;
    border-radius: 16px;
    align-self: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Animations */
@keyframes popIn {
    0% { transform: scale(0); opacity: 0; }
    80% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(1); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* Responsive Tweak for Ultra-narrow screens (under 360px) */
@media (max-width: 360px) {
    body { font-size: 13px; }
    .brand-title { font-size: 0.9rem; }
    .player-name { font-size: 0.65rem; }
    .select-type { max-width: 90px; padding: 6px 4px; font-size: 0.72rem; }
    .board-grid { max-width: 300px; }
}
