:root {
    --bg-gradient: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.15);
    --glass-highlight: rgba(255, 255, 255, 0.1);
    --primary-color: #00d2ff;
    --primary-glow: rgba(0, 210, 255, 0.6);
    --secondary-color: #3a7bd5;
    --accent-color: #ff9a9e;
    --text-color: #e0e0e0;
    --text-muted: #a0a0a0;
    --success-color: #00ff88;
    --danger-color: #ff4d4d;
    
    --board-bg: rgba(0, 20, 40, 0.6);
    --cell-border: rgba(0, 210, 255, 0.15);
    --cell-hover: rgba(0, 210, 255, 0.3);
}

html {
    background-color: #0f2027; /* Match start of gradient */
    height: 100%;
    margin: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-gradient);
    background-attachment: fixed;
    color: var(--text-color);
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 100%; /* Changed from 100vh to 100% to work better with html height */
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    text-align: center;
    padding: 20px;
    box-sizing: border-box;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

h1, h2, h3, h4 { 
    color: white; 
    margin: 15px 0; 
    text-shadow: 0 0 10px rgba(0,0,0,0.5);
    font-weight: 300;
    letter-spacing: 1px;
}

h1 {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 3px;
    background: linear-gradient(to right, #00d2ff, #3a7bd5);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: none; /* Clip overrides shadow */
    filter: drop-shadow(0 0 10px rgba(0, 210, 255, 0.5));
}

/* Glassmorphism Utilities */
.screen, .card, .highscore-column, .status-bar, #game-over-container {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    border-radius: 16px;
    padding: 20px;
    box-sizing: border-box;
    margin-top: 20px;
}

.hidden { display: none !important; }

/* Inputs */
input {
    padding: 12px 15px;
    margin: 10px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    font-size: 16px;
    color: white;
    outline: none;
    transition: all 0.3s ease;
}

input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 10px var(--primary-glow);
}

input::placeholder {
    color: var(--text-muted);
}

/* Buttons */
button {
    padding: 12px 24px;
    background: linear-gradient(135deg, var(--secondary-color), var(--primary-color));
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    margin: 5px;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

button:hover { 
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--primary-glow);
    filter: brightness(1.1);
}

button:disabled { 
    background: #555; 
    color: #888;
    cursor: not-allowed; 
    box-shadow: none;
    transform: none;
}

button#reset-ships-btn {
    background: rgba(255, 77, 77, 0.2);
    border: 1px solid rgba(255, 77, 77, 0.5);
}
button#reset-ships-btn:hover {
    background: rgba(255, 77, 77, 0.5);
    box-shadow: 0 0 15px rgba(255, 77, 77, 0.4);
}

/* Lobby Styling */
.lobby-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
}

.card {
    max-width: 350px;
    transition: transform 0.3s ease;
}

.card:hover {
    transform: translateY(-5px);
    background: var(--glass-highlight);
}

.card h3 {
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 10px;
    margin-top: 0;
}

/* Online List & Highscores */
.online-list, .highscore-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 150px;
    overflow-y: auto;
    text-align: left;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.1); 
    border-radius: 4px;
}
::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2); 
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.4); 
}

.online-list li, .highscore-list li {
    padding: 8px 12px;
    border-bottom: 1px solid var(--glass-border);
    font-size: 0.95em;
    display: flex;
    justify-content: space-between;
}

.online-list li:last-child, .highscore-list li:last-child {
    border-bottom: none;
}

.hs-name { color: white; font-weight: 600; }
.hs-score { color: var(--primary-color); }

#highscores-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
    margin-top: 30px;
    width: 100%;
}

.highscore-column {
    flex: 1;
    min-width: 280px;
}

/* Game Board */
.game-board-wrapper {
    position: relative;
    width: 100%;
    max-width: 500px;
    aspect-ratio: 1 / 1;
    margin: 0 auto;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    overflow: hidden;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(10, 1fr);
    gap: 0; /* Continuous grid lines look better */
    background-color: var(--board-bg);
    width: 100%;
    height: 100%;
    position: relative;
    /* Create grid lines with gradients */
    background-image: 
        linear-gradient(var(--cell-border) 1px, transparent 1px),
        linear-gradient(90deg, var(--cell-border) 1px, transparent 1px);
    background-size: 10% 10%;
    background-position: -1px -1px; /* Align grid */
    border: 1px solid var(--cell-border);
}

.cell {
    background-color: transparent;
    cursor: crosshair;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    position: relative;
    transition: background-color 0.2s;
}

.cell:hover { 
    background-color: var(--cell-hover); 
    box-shadow: inset 0 0 10px var(--primary-color);
}

.cell.hit { 
    background-color: rgba(255, 77, 77, 0.2); 
    box-shadow: inset 0 0 15px rgba(255, 77, 77, 0.5);
}
.cell.miss { 
    background-color: rgba(255, 255, 255, 0.1); 
}
.cell.preview { 
    background-color: rgba(0, 255, 136, 0.3); 
    border: 1px solid var(--success-color);
}
.cell.invalid { 
    background-color: rgba(255, 77, 77, 0.3); 
    border: 1px solid var(--danger-color);
}

/* Ship SVGs */
.ships-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

.ship-element {
    position: absolute;
    transition: all 0.3s;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.8));
}

/* Make ships look cool on dark bg */
.ship-element svg {
    filter: brightness(1.5) contrast(1.1) saturate(0.8);
}
/* Give friendly ships a blueish tint */
#my-ships-container .ship-element svg, #setup-ships-container .ship-element svg, #enemy-ships-container .ship-element svg {
    filter: brightness(1.3) sepia(1) hue-rotate(180deg) saturate(3);
}

.ship-element.sunk {
    filter: brightness(0.8) drop-shadow(0 0 5px var(--danger-color));
    opacity: 0.9;
}

/* Effects */
@keyframes explode {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 1; box-shadow: 0 0 0 var(--danger-color); }
    50% { opacity: 1; box-shadow: 0 0 20px var(--danger-color); }
    100% { transform: translate(-50%, -50%) scale(2); opacity: 0; }
}

.fx-hit {
    position: absolute;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, #fff, var(--danger-color));
    border-radius: 50%;
    pointer-events: none;
    z-index: 20;
    animation: explode 0.5s ease-out forwards;
}

.fx-miss {
    position: absolute;
    width: 60%;
    height: 60%;
    border: 2px solid white;
    border-radius: 50%;
    pointer-events: none;
    z-index: 20;
    opacity: 0.5;
    animation: ripple 0.6s ease-out forwards;
}

@keyframes ripple {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 1; border-width: 4px; }
    100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; border-width: 0; }
}

/* Floating Text */
.floating-text {
    position: absolute;
    pointer-events: none;
    font-weight: 800;
    font-size: 1rem;
    text-transform: uppercase;
    z-index: 100;
    animation: floatUp 1.2s ease-out forwards;
    width: 100%;
    text-align: center;
    text-shadow: 0 0 5px black;
}

.text-hit { color: #ff4d4d; text-shadow: 0 0 10px #ff4d4d; }
.text-miss { color: #aaa; }

@keyframes floatUp {
    0% { transform: translateY(0) scale(0.8); opacity: 0; }
    20% { transform: translateY(-5px) scale(1.2); opacity: 1; }
    100% { transform: translateY(-20px) scale(1); opacity: 0; }
}

/* Status Bar */
.status-bar {
    background: rgba(0, 0, 0, 0.4);
    color: white;
    font-size: 1.1em;
    border-left: 5px solid var(--primary-color);
}

/* Turn Indication */
.board-active { 
    border: 2px solid var(--success-color);
    box-shadow: 0 0 25px rgba(0, 255, 136, 0.4);
}

.board-waiting { 
    border: 2px solid var(--glass-border);
    opacity: 0.8;
}

/* Legend */
.legend-container {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 10px;
    margin-top: 15px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.legend-item span {
    color: white;
    font-size: 0.8em;
    margin-top: 5px;
}

.legend-ship-icon {
    filter: brightness(1.5) drop-shadow(0 2px 2px rgba(0,0,0,0.5));
}
.legend-item.sunk .legend-ship-icon {
    filter: brightness(0.5) sepia(1) hue-rotate(180deg) saturate(2);
}
.legend-item.sunk::after {
    color: var(--danger-color);
    text-shadow: 0 0 5px black;
}

/* Popup */
.turn-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 20, 40, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid var(--primary-color);
    box-shadow: 0 0 50px rgba(0, 210, 255, 0.5);
    color: white;
    padding: 20px 40px;
    border-radius: 50px;
    font-size: 2em;
    font-weight: 900;
    z-index: 9999;
    pointer-events: none;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 2px;
    white-space: normal;
    max-width: 90%;
    box-sizing: border-box;
}

.turn-popup.p-green { 
    border-color: var(--success-color); 
    color: var(--success-color);
    box-shadow: 0 0 50px rgba(0, 255, 136, 0.4);
}
.turn-popup.p-orange { 
    border-color: var(--danger-color); 
    color: var(--danger-color);
    box-shadow: 0 0 50px rgba(255, 77, 77, 0.4);
}

/* Layout Response */
.boards-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
    width: 100%;
}

.board-column {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

@media (min-width: 900px) {
    .boards-container {
        flex-direction: row;
        justify-content: center;
        align-items: flex-start;
        gap: 50px;
    }
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0; 
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s;
}

.modal-content {
    width: 90%;
    max-width: 500px;
    padding: 30px;
    text-align: left;
    max-height: 90vh;
    overflow-y: auto;
}

.rules-options {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin: 20px 0;
}

.rule-option {
    display: flex;
    align-items: flex-start;
    position: relative;
    padding-left: 40px;
    cursor: pointer;
    user-select: none;
}

.rule-option input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

/* Custom Checkbox Box */
.rule-option .rule-text::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 24px;
    width: 24px;
    background-color: rgba(255,255,255,0.1);
    border: 2px solid var(--primary-color);
    border-radius: 6px;
    transition: all 0.2s;
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
}

.rule-option input:checked ~ .rule-text::before {
    background-color: var(--primary-color);
    box-shadow: 0 0 15px var(--primary-glow);
}

.rule-option input:checked ~ .rule-text::after {
    content: '';
    position: absolute;
    left: 9px;
    top: 4px;
    width: 6px;
    height: 12px;
    border: solid white;
    border-width: 0 3px 3px 0;
    transform: rotate(45deg);
}

.rule-text {
    display: flex;
    flex-direction: column;
}

.rule-text span {
    font-size: 1.1em;
    font-weight: 600;
    color: white;
    margin-bottom: 4px;
}

.rule-text small {
    color: var(--text-muted);
    font-size: 0.9em;
    line-height: 1.4;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
    margin-top: 20px;
}