/* Base reset and variables */
:root {
    --dark-bg: #1f2937;        /* Dark Gray Background */
    --card-bg: #374151;        /* Slightly Lighter Card/Panel BG */
    --text-color: #e5e7eb;     /* Light Gray Text */
    --accent-hit: #ef4444;     /* Red for Hits */
    --accent-miss: #3b82f6;     /* Blue for Misses (calm, conventional) */
    --accent-sunk: #b91c1c;     /* Dark red for sunk ships */
    --highlight-color: #fcd34d;/* Yellowish for selection/turn highlight */
    --border-color: #4b5563;   /* Medium Gray Border */
    --grid-size: 38px;
}

/* =================== General Layout =================== */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--dark-bg);
    color: var(--text-color);
    margin: 0;
    padding: 0 0 100px; /* bottom padding for the fixed footer banner */
    min-height: 100vh;
}

/* Fixed Status Banner */
#status-banner {
    position: sticky;
    top: 0;
    width: 100%;
    background-color: var(--card-bg);
    padding: 10px 20px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    z-index: 100;
    box-sizing: border-box;
}

#turn-info {
    font-weight: bold;
    font-size: 1.05em;
}

#last-action {
    font-size: 0.95em;
    opacity: 0.85;
    margin-top: 2px;
    min-height: 1.1em;
}

/* =================== Lobby =================== */
.lobby {
    max-width: 480px;
    margin: 60px auto;
    text-align: center;
    background-color: var(--card-bg);
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.lobby h1 {
    margin: 0 0 8px 0;
    font-size: 2em;
}

.lobby p {
    opacity: 0.8;
    margin: 0 0 24px 0;
}

.lobby-actions {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
}

.join-group {
    display: flex;
    gap: 8px;
}

#join-code {
    width: 140px;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background-color: var(--dark-bg);
    color: var(--text-color);
    font-size: 1.1em;
    letter-spacing: 3px;
    text-transform: uppercase;
    text-align: center;
}

#create-btn, #join-btn {
    padding: 12px 24px;
    background-color: #3b82f6;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    font-weight: bold;
}

#create-btn:hover, #join-btn:hover, #submit-placement:hover {
    background-color: #2563eb;
}

.room-code-display {
    margin-top: 24px;
    padding: 14px;
    background-color: var(--dark-bg);
    border-radius: 6px;
    font-size: 1.05em;
    font-weight: bold;
    letter-spacing: 1px;
}

/* =================== Game Layout =================== */
.game-container {
    padding: 20px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    max-width: 1100px;
    margin: 0 auto;
}

/* Mobile Tab Switcher (hidden on desktop) */
.mobile-tab-switcher {
    display: none;
    grid-column: 1 / -1;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.tab-btn {
    padding: 10px 20px;
    background-color: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
}

.tab-btn.active {
    background-color: var(--highlight-color);
    color: #000;
    font-weight: bold;
}

.leave-btn {
    margin-left: auto;
    background-color: #dc3545;
    color: white;
    border-color: #dc3545;
}

.grid-views {
    display: contents;
}

.game-grid {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.battleship-grid {
    display: grid;
    grid-template-columns: repeat(10, var(--grid-size));
    grid-auto-rows: var(--grid-size);
    border: 2px solid var(--border-color);
    padding: 5px;
    background-color: var(--card-bg);
}

.battleship-cell {
    width: var(--grid-size);
    height: var(--grid-size);
    box-sizing: border-box;
    border: 1px solid #2d3a4a;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7em;
    cursor: pointer;
    touch-action: manipulation;   /* spec: comfortable touch, no double-tap zoom */
    transition: background-color 0.15s, transform 0.08s;
    user-select: none;
}

.battleship-cell:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

/* State Styling */
.cell-hit { background-color: var(--accent-hit) !important; }
.cell-miss { background-color: var(--accent-miss) !important; opacity: 0.7; }
.cell-ship { background-color: #4f6378; }
.cell-sunk { background-color: var(--accent-sunk) !important; }
.cell-highlighted { background-color: rgba(252, 211, 77, 0.45) !important; cursor: crosshair; }
.cell-highlighted-invalid { background-color: rgba(239, 68, 68, 0.45) !important; cursor: not-allowed; }

/* =================== Placement Controls =================== */
.game-controls {
    grid-column: 1 / -1;
    background-color: var(--card-bg);
    padding: 16px 20px;
    border-radius: 8px;
    text-align: center;
}

.game-controls h3 { margin: 0 0 8px 0; }
.game-controls p { margin: 8px 0; opacity: 0.85; font-size: 0.95em; }

.placement-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin: 12px 0;
}

#random-btn, #rotate-btn, #clear-btn {
    padding: 10px 18px;
    background-color: #6b7280;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.95em;
}

#random-btn:hover, #rotate-btn:hover, #clear-btn:hover { background-color: #4b5563; }

#submit-placement {
    padding: 10px 22px;
    background-color: #22c55e;
    color: white;
    border: none;
    cursor: pointer;
    border-radius: 5px;
    font-size: 0.95em;
    font-weight: bold;
}

#submit-placement:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    background-color: #6b7280;
}

#placement-feedback {
    font-style: italic;
}

/* =================== Mobile Responsiveness (< 768px) =================== */
@media (max-width: 768px) {
    :root { --grid-size: 35px; }   /* spec: at least 35x35px */

    .game-container {
        grid-template-columns: 1fr;
        padding: 10px;
        gap: 20px;
    }

    .mobile-tab-switcher {
        display: flex;             /* show on mobile */
    }

    .hidden-panel { display: none !important; }
    .active-panel { display: flex !important; }

    /* Bigger touch targets for placement buttons on mobile */
    .placement-actions {
        flex-wrap: wrap;
        gap: 8px;
    }

    .placement-actions button {
        flex: 1 1 auto;
        min-width: 0;
        padding: 12px 12px;
        font-size: 0.95em;
    }

    /* Show orientation hint on the fleet title */
    #fleet-view .grid-title {
        cursor: pointer;
        user-select: none;
    }
}

.hidden-area { display: none !important; }

.grid-title {
    margin: 0 0 10px 0;
    text-align: center;
    font-size: 1.2rem;
}

/* Fleet grid title is tappable to toggle orientation during placement */
#fleet-view .grid-title {
    cursor: pointer;
    user-select: none;
    transition: color 0.15s;
}
#fleet-view .grid-title:hover {
    color: var(--highlight-color);
}

/* =================== Ad & CMP Styles =================== */

/* Ad block detection test unit — ad blockers hide this by default. */
.ad-test-unit {
    height: 1px;
    width: 1px;
    position: absolute;
    left: -9999px;
    top: -9999px;
}

/* Shared overlay visibility */
.hidden-overlay { display: none !important; }

/* CMP GDPR Consent Banner (fixed bottom bar) */
.cmp-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card-bg);
    z-index: 1000;
    padding: 20px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
    border-top: 1px solid var(--border-color);
}

.cmp-banner-content {
    max-width: 700px;
    margin: 0 auto;
    text-align: center;
}

.cmp-banner-content p {
    margin: 0 0 16px 0;
    font-size: 0.95em;
    line-height: 1.5;
}

.cmp-banner-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

#cmp-accept-all {
    padding: 10px 24px;
    background: #22c55e;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.95em;
}

#cmp-accept-all:hover {
    background: #16a34a;
}

#cmp-reject-all {
    padding: 10px 24px;
    background: #6b7280;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95em;
}

#cmp-reject-all:hover {
    background: #4b5563;
}

/* =================== AdInPlay Styles =================== */

/* AdInPlay Footer Banner */
#ad-banner-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    z-index: 50;
    background: var(--dark-bg);
    padding: 4px 0;
    border-top: 1px solid var(--border-color);
}

#ad-banner-728x90 {
    min-height: 90px;
    margin: 0 auto;
}

/* AdInPlay Interstitial Overlay */
#ad-interstitial-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
}

#ad-interstitial-overlay .interstitial-content {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 12px;
    text-align: center;
    min-width: 300px;
    max-width: 500px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

#ad-interstitial-overlay .interstitial-content p {
    margin: 0 0 16px 0;
    opacity: 0.8;
}

#ad-interstitial-slot {
    min-height: 250px;
    background: var(--dark-bg);
    border-radius: 8px;
    margin-bottom: 16px;
}

#close-ad-btn {
    padding: 10px 24px;
    background: var(--highlight-color);
    color: #000;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    font-size: 1em;
}

#close-ad-btn:hover {
    background: #fbbf24;
}

/* =================== Reconnection Overlay =================== */
.reconnect-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.reconnect-content {
    text-align: center;
    color: var(--text-color);
}

.reconnect-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--highlight-color);
    border-radius: 50%;
    animation: reconnect-spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes reconnect-spin {
    to { transform: rotate(360deg); }
}

.reconnect-content p {
    font-size: 1.1em;
    opacity: 0.9;
}

/* =================== Game Over Modal =================== */
.game-over-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 800;
    display: flex;
    align-items: center;
    justify-content: center;
}

.game-over-content {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 16px;
    text-align: center;
    min-width: 320px;
    max-width: 420px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    animation: modal-in 0.3s ease-out;
}

@keyframes modal-in {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

#game-over-title {
    font-size: 2em;
    margin: 0 0 8px 0;
}

#game-over-title.victory { color: #22c55e; }
#game-over-title.defeat { color: #ef4444; }

.game-over-reason {
    opacity: 0.7;
    margin: 0 0 24px 0;
    font-size: 0.95em;
}

.game-over-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.stat-item {
    background: var(--dark-bg);
    padding: 12px;
    border-radius: 8px;
}

.stat-value {
    display: block;
    font-size: 1.5em;
    font-weight: bold;
}

.stat-label {
    display: block;
    font-size: 0.8em;
    opacity: 0.6;
    margin-top: 4px;
}

.play-again-btn {
    padding: 12px 32px;
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1em;
    font-weight: bold;
    transition: background 0.15s;
}

.play-again-btn:hover {
    background: #2563eb;
}
