/* ===== BASE STYLES ===== */
:root {
    --primary-color: #1a73e8;
    --primary-dark: #1557b0;
    --secondary-color: #6c5ce7;
    --success-color: #00b894;
    --danger-color: #e74c3c;
    --warning-color: #f39c12;
    --attack-color: #ff6b6b;
    --defend-color: #4ecdc4;
    --system-color: #a29bfe;
    --dark-bg: #0f0f23;
    --card-bg: rgba(255, 255, 255, 0.95);
    --text-dark: #2d3436;
    --text-light: #636e72;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    text-align: center;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    margin: 0;
    padding: 20px;
    min-height: 100vh;
    color: #fff;
}

/* ===== HERO CONTAINER ===== */
.hero-container {
    max-width: 600px;
    margin: 0 auto;
}

.game-title {
    font-size: 3rem;
    background: linear-gradient(45deg, #00d2ff, #3a7bd5);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 30px rgba(0, 210, 255, 0.3);
    margin-bottom: 0.5rem;
}

.tagline {
    color: #a29bfe;
    font-size: 1.2rem;
    margin-bottom: 2rem;
}

/* ===== CARDS ===== */
.card {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 2rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    color: var(--text-dark);
}

.rules-card {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    padding: 1.5rem;
    text-align: left;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.rules-card h3 {
    text-align: center;
    color: #ffeaa7;
    margin-bottom: 1rem;
}

.rules-card h4 {
    color: #81ecec;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.rules-section {
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.rules-section:last-child {
    border-bottom: none;
}

.rules-card ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.rules-card li {
    padding: 0.3rem 0;
    padding-left: 0.5rem;
    font-size: 0.9rem;
}

/* ===== BUTTONS ===== */
.btn {
    padding: 12px 24px;
    font-size: 16px;
    cursor: pointer;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    box-shadow: 0 4px 15px rgba(26, 115, 232, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(26, 115, 232, 0.6);
}

.btn-secondary {
    background: linear-gradient(135deg, #636e72, #2d3436);
    color: white;
}

.btn-secondary:hover {
    transform: translateY(-2px);
}

.btn-large {
    padding: 15px 40px;
    font-size: 18px;
}

.btn-small {
    padding: 8px 16px;
    font-size: 12px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

button {
    padding: 12px 24px;
    margin-top: 10px;
    font-size: 16px;
    cursor: pointer;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    transition: all 0.3s ease;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(26, 115, 232, 0.4);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== INPUTS ===== */
.input-field {
    width: 80%;
    max-width: 300px;
    padding: 12px 16px;
    font-size: 16px;
    border: 2px solid #ddd;
    border-radius: 10px;
    margin: 10px 0;
    transition: border-color 0.3s ease;
}

.input-field:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* ===== ROOM CODE ===== */
.room-code-display {
    background: linear-gradient(135deg, #667eea, #764ba2);
    padding: 15px 25px;
    border-radius: 15px;
    display: inline-flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 1rem;
}

.room-code {
    font-size: 2rem;
    font-weight: bold;
    letter-spacing: 5px;
    color: #fff;
    font-family: 'Courier New', monospace;
}

.player-count {
    color: var(--success-color);
    font-weight: 600;
}

/* ===== BUTTON GROUPS ===== */
.button-group {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

.join-room-group {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.divider {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-light);
    width: 100%;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #ddd;
}

/* ===== INFO TEXT ===== */
.info-text {
    padding: 10px;
    border-radius: 8px;
    margin-top: 10px;
}

.info-text.error {
    background: #ffe0e0;
    color: var(--danger-color);
}

.info-text.success {
    background: #d4edda;
    color: var(--success-color);
}

/* ===== HIDDEN ===== */
.hidden {
    display: none !important;
}

/* ===== CIPHER BOXES ===== */
.cipher-box {
    width: 45px;
    height: 45px;
    text-align: center;
    font-size: 22px;
    margin: 5px;
    border: 2px solid #ddd;
    border-radius: 10px;
    text-transform: lowercase;
    transition: all 0.3s ease;
}

.cipher-box:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(26, 115, 232, 0.3);
}

.cipher-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 15px 0;
}

/* ===== CHAT CONTAINER ===== */
#chat-container {
    max-width: 400px;
    min-width: 350px;
    border-radius: 15px;
    padding: 15px;
    background: linear-gradient(135deg, #2d3436, #000000);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
}

#chat-container h2 {
    color: #ffeaa7;
    margin-bottom: 10px;
}

#messages {
    height: 400px;
    overflow-y: auto;
    border-radius: 10px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.message {
    padding: 10px 15px;
    margin: 8px 0;
    border-radius: 10px;
    text-align: left;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Message Types */
.message.attack {
    background: linear-gradient(135deg, rgba(255, 107, 107, 0.3), rgba(238, 90, 36, 0.2));
    border-left: 4px solid var(--attack-color);
}

.message.defend {
    background: linear-gradient(135deg, rgba(78, 205, 196, 0.3), rgba(0, 184, 148, 0.2));
    border-left: 4px solid var(--defend-color);
}

.message.system {
    background: linear-gradient(135deg, rgba(162, 155, 254, 0.3), rgba(108, 92, 231, 0.2));
    border-left: 4px solid var(--system-color);
    text-align: center;
}

.message.player0 {
    background: linear-gradient(135deg, rgba(255, 234, 167, 0.3), rgba(253, 203, 110, 0.2));
    border-left: 4px solid #ffeaa7;
}

.message.player1 {
    background: linear-gradient(135deg, rgba(129, 236, 236, 0.3), rgba(0, 206, 201, 0.2));
    border-left: 4px solid #81ecec;
}

.username {
    font-weight: bold;
    display: block;
    margin-bottom: 3px;
}

.username.attack {
    color: var(--attack-color);
}

.username.defend {
    color: var(--defend-color);
}

.username.system {
    color: var(--system-color);
}

.username.player0 {
    color: #ffeaa7;
}

.username.player1 {
    color: #81ecec;
}

.text {
    color: #dfe6e9;
}

/* ===== TIMER ===== */
.timer-display {
    position: fixed;
    top: 20px;
    right: 20px;
    background: linear-gradient(135deg, #2d3436, #000);
    padding: 15px 25px;
    border-radius: 15px;
    font-size: 1.5rem;
    font-weight: bold;
    color: #00ff88;
    font-family: 'Courier New', monospace;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(0, 255, 136, 0.3);
    z-index: 1000;
}

.timer-display.warning {
    color: #f39c12;
    border-color: rgba(243, 156, 18, 0.5);
    animation: pulse 1s infinite;
}

.timer-display.danger {
    color: #e74c3c;
    border-color: rgba(231, 76, 60, 0.5);
    animation: pulse 0.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ===== PLAY AREA ===== */
.render-area {
    margin: 25px auto;
    max-width: 1200px;
}

.play-area {
    display: flex;
    justify-content: center;
    gap: 30px;
    flex-wrap: wrap;
}

.play-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.play-title h2 {
    color: #ffeaa7;
}

#score {
    background: linear-gradient(135deg, #00b894, #00cec9);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 1.3rem;
}

#cipher {
    color: #a29bfe;
    font-size: 1rem;
}

/* ===== GRID ===== */
.grid {
    display: grid;
    gap: 5px;
    grid-template-columns: repeat(6, 60px);
    grid-template-rows: repeat(6, 60px);
    justify-content: center;
    margin: 15px auto;
    background: rgba(0, 0, 0, 0.3);
    padding: 10px;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
}

.cell {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #2d3436, #1e272e);
    border: 2px solid #4a4a4a;
    border-radius: 8px;
    box-sizing: border-box;
    text-align: center;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    color: #dfe6e9;
}

.cell:hover {
    transform: scale(1.05);
    border-color: #74b9ff;
}

/* Cell States */
.cell.water {
    background: linear-gradient(135deg, #0984e3, #74b9ff);
}

.cell.ship {
    background: linear-gradient(135deg, #00b894, #55efc4);
    box-shadow: 0 0 15px rgba(0, 184, 148, 0.5);
}

.cell.attacked {
    background: linear-gradient(135deg, #d63031, #e17055);
    box-shadow: 0 0 15px rgba(214, 48, 49, 0.5);
}

.cell.defended {
    background: linear-gradient(135deg, #0984e3, #74b9ff);
    box-shadow: 0 0 15px rgba(9, 132, 227, 0.5);
}

.cell.attacking {
    background: linear-gradient(135deg, #e17055, #fdcb6e);
    animation: attackPulse 1s infinite;
}

@keyframes attackPulse {
    0%, 100% { box-shadow: 0 0 10px rgba(225, 112, 85, 0.5); }
    50% { box-shadow: 0 0 25px rgba(225, 112, 85, 0.8); }
}

.cell.defending {
    background: linear-gradient(135deg, #00cec9, #81ecec);
    animation: defendPulse 1s infinite;
}

@keyframes defendPulse {
    0%, 100% { box-shadow: 0 0 10px rgba(0, 206, 201, 0.5); }
    50% { box-shadow: 0 0 25px rgba(0, 206, 201, 0.8); }
}

.cell.selected {
    background: linear-gradient(135deg, #a29bfe, #6c5ce7);
    box-shadow: 0 0 20px rgba(108, 92, 231, 0.7);
    transform: scale(1.1);
}

/* ===== SCORE DISPLAY ===== */
.score-panel {
    background: linear-gradient(135deg, #2d3436, #000);
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-around;
    align-items: center;
}

.score-item {
    text-align: center;
}

.score-label {
    color: #636e72;
    font-size: 0.9rem;
    text-transform: uppercase;
}

.score-value {
    font-size: 2rem;
    font-weight: bold;
}

.score-value.your-score {
    color: #00ff88;
}

.score-value.enemy-score {
    color: #ff6b6b;
}

/* ===== END GAME SCREENS ===== */
.end-game-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.end-game-card {
    background: rgba(255, 255, 255, 0.95);
    padding: 40px 60px;
    border-radius: 25px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    color: var(--text-dark);
}

.win-title {
    font-size: 4rem;
    color: #00b894;
    margin-bottom: 0.5rem;
}

.lose-title {
    font-size: 4rem;
    color: #e74c3c;
    margin-bottom: 0.5rem;
}

.draw-title {
    font-size: 4rem;
    color: #f39c12;
    margin-bottom: 0.5rem;
}

.end-message {
    font-size: 1.5rem;
    color: var(--text-light);
    margin-bottom: 2rem;
}

.final-score {
    font-size: 2rem;
    margin: 1rem 0;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .game-title {
        font-size: 2rem;
    }
    
    .grid {
        grid-template-columns: repeat(6, 45px);
        grid-template-rows: repeat(6, 45px);
    }
    
    .cell {
        width: 45px;
        height: 45px;
        font-size: 0.9rem;
    }
    
    .timer-display {
        position: relative;
        top: 0;
        right: 0;
        margin-bottom: 15px;
    }
    
    .play-area {
        flex-direction: column;
        align-items: center;
    }
    
    #chat-container {
        min-width: 100%;
    }
}

/* ===== TABLE (Legacy Support) ===== */
table {
    width: 80%;
    margin: 0 auto;
    border-collapse: collapse;
}

th, td {
    border: 1px solid #ddd;
    padding: 10px;
}

th {
    background-color: #f4f4f4;
}

h1 {
    color: #ffeaa7;
    text-shadow: 0 0 20px rgba(255, 234, 167, 0.3);
}

h3 {
    color: #dfe6e9;
}
