@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

:root {
    --cell-size: min(2.8vh, 3vw); 
    --bg-dark: #0a0f18;
    --panel-bg: rgba(16, 24, 32, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-main: #e2e8f0;
}

body {
    font-family: 'Jura', sans-serif;
    background: radial-gradient(circle at center, #1a2536 0%, var(--bg-dark) 100%);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
}

/* --- ZAMANLAYICI (TIMER) ANA TASARIMI --- */
.game-timer {
    position: fixed; 
    left: 20px;
    top: 20px;
    z-index: 100; 
    background: #000;
    color: #48dbfb;
    font-family: 'Russo One', sans-serif;
    font-size: 1.5em; 
    padding: 10px 20px;
    border: 2px solid #48dbfb;
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(72, 219, 251, 0.3);
    transition: all 0.3s ease;
}

@media (max-width: 1000px) {
    .game-timer {
        left: 10px; 
        top: 10px; 
        font-size: clamp(0.7rem, 4vw, 1.2rem); 
        padding: 8px 15px;
        border-width: 2px;
    }
}

#lobby-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100vh;
}
.glass-panel {
    background: var(--panel-bg);
    padding: 40px 50px;
    border-radius: 12px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    text-align: center;
    width: 100%;
    max-width: 400px;
}
.glass-panel h2 {
    font-family: 'Russo One', sans-serif;
    font-size: 2em;
    color: #48dbfb;
    margin-top: 0;
    margin-bottom: 30px;
    letter-spacing: 2px;
    text-shadow: 0 0 10px rgba(72, 219, 251, 0.3);
}

input, .modern-select {
    width: 100%;
    margin: 10px 0;
    padding: 15px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: white;
    font-family: 'Jura', sans-serif;
    font-size: 1.1em;
    box-sizing: border-box;
    transition: border-color 0.3s;
}
input:focus, .modern-select:focus {
    outline: none;
    border-color: #48dbfb;
}

.primary-btn {
    background: linear-gradient(135deg, #0984e3, #00cec9);
    color: white;
    font-family: 'Russo One', sans-serif;
    font-size: 1.2em;
    padding: 15px;
    width: 100%;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    margin-top: 20px;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(9, 132, 227, 0.4);
}
.primary-btn:disabled {
    background: #555;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}
.ready-btn {
    background: linear-gradient(135deg, #00b894, #00cec9);
    color: #ffffff;
    width: auto;
    padding: 12px 20px; 
    font-family: 'Press Start 2P', cursive !important; 
    font-size: 0.7rem; 
    text-transform: uppercase;
    border: 2px solid #55efc4;
    border-radius: 4px;
    box-shadow: 0 0 10px rgba(0, 184, 148, 0.4);
    white-space: nowrap; 
    cursor: pointer;
    transition: all 0.2s ease;
}

.ready-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(0, 184, 148, 0.8);
}
#lobbyMessage:empty { display: none; }
#lobbyMessage:not(:empty) { 
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(255, 71, 87, 0.15); 
    color: #ff4757; 
    font-weight: bold; 
    font-size: 1.1em;
    padding: 12px 20px;
    margin-top: 20px; 
    border: 1px solid rgba(255, 71, 87, 0.4);
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(255, 71, 87, 0.2);
    animation: fadeInError 0.3s ease-out forwards;
}
@keyframes fadeInError {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

#game-screen {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}
.game-header { margin-bottom: 10px; }
.game-header h2 { font-family: 'Russo One', sans-serif; color: #a4b0be; }
.highlight { color: #feca57; }

#fleet-container {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    padding: min(15px, 2vh);
    border-radius: 8px;
    margin-bottom: min(20px, 2vh);
    width: 100%;
    max-width: calc(10 * var(--cell-size) + 9px);
    box-sizing: border-box;
    backdrop-filter: blur(5px);
}
#placement-hint { color: #a4b0be; text-align: center; margin-bottom: 10px; font-size: clamp(0.6em, 1.5vw, 0.9em); }
#ship-dock {
    display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap;
    background: rgba(0,0,0,0.3); padding: 10px; border-radius: 6px; border: 1px dashed #7f8fa6;
}
.action-row { text-align: center; }

/* Genel Board Container */
#board-container { 
    width: 100%; 
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* --- 2 KİŞİLİK (2P) DÜZEN --- */
#board-container.layout-2p {
    flex-direction: column;
    gap: min(4vh, 20px); 
}
#board-container.layout-2p .pos-top { --cell-size: min(2.5vh, 4.5vw); }
#board-container.layout-2p .pos-me { --cell-size: min(3.5vh, 6.5vw); }

/* --- 3 KİŞİLİK (3P) DÜZEN (Mobil Odaklı Temel Yapı) --- */
#board-container.layout-3p {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: min(2vh, 15px) min(4vw, 20px);
}
#board-container.layout-3p .pos-left { justify-self: right; --cell-size: min(2.2vh, 4vw); }
#board-container.layout-3p .pos-right { justify-self: left; --cell-size: min(2.2vh, 4vw); }
#board-container.layout-3p .pos-me { grid-column: 1 / span 2; justify-self: center; --cell-size: min(3.2vh, 5.5vw); }

/* --- 4 KİŞİLİK (4P) DÜZEN (Mobil Odaklı Temel Yapı) --- */
#board-container.layout-4p {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto auto;
    gap: min(2vh, 10px) min(2vw, 10px);
}
#board-container.layout-4p .pos-left { justify-self: right; --cell-size: min(1.8vh, 2.6vw); }
#board-container.layout-4p .pos-top { justify-self: center; --cell-size: min(1.8vh, 2.6vw); }
#board-container.layout-4p .pos-right { justify-self: left; --cell-size: min(1.8vh, 2.6vw); }
#board-container.layout-4p .pos-me { grid-column: 1 / span 3; justify-self: center; --cell-size: min(3vh, 5.5vw); }

/* --- MASAÜSTÜ ÖZEL DÜZEN (Ortalanmış Çapraz Görünüm) --- */
@media (min-width: 1001px) {
    #board-container.layout-3p {
        grid-template-columns: 1fr auto 1fr;
        grid-template-rows: auto;
        gap: 3vh 4vw;
    }
    #board-container.layout-3p .pos-left { grid-column: 1; grid-row: 1; justify-self: end; align-self: center; }
    #board-container.layout-3p .pos-me { grid-column: 2; grid-row: 1; justify-self: center; align-self: center; }
    #board-container.layout-3p .pos-right { grid-column: 3; grid-row: 1; justify-self: start; align-self: center; }

    #board-container.layout-4p {
        grid-template-columns: 1fr auto 1fr;
        grid-template-rows: auto auto;
        gap: 3vh 4vw;
    }
    #board-container.layout-4p .pos-top { grid-column: 2; grid-row: 1; justify-self: center; align-self: end; }
    #board-container.layout-4p .pos-left { grid-column: 1; grid-row: 2; justify-self: end; align-self: center; }
    #board-container.layout-4p .pos-me { grid-column: 2; grid-row: 2; justify-self: center; align-self: center; }
    #board-container.layout-4p .pos-right { grid-column: 3; grid-row: 2; justify-self: start; align-self: center; }
}

.board-title {
    font-family: 'Press Start 2P', cursive !important;
    font-size: clamp(0.35rem, 1.2vw, 0.7rem); 
    background: #000;
    color: rgb(var(--theme-color));
    border: 1px solid rgb(var(--theme-color));
    padding: min(8px, 1.5vh) min(15px, 3vw);
    border-radius: 4px;
    margin-bottom: min(8px, 1.5vh);
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 0 10px rgba(var(--theme-color), 0.3);
    text-align: center;
}

.board {
    display: grid;
    grid-template-columns: repeat(10, var(--cell-size));
    grid-template-rows: repeat(10, var(--cell-size));
    gap: 1px;
    background-color: #000000; 
    border: 2px solid rgb(var(--theme-color));
    box-shadow: 0 0 15px rgba(var(--theme-color), 0.5);
    position: relative;
}

.cell {
    background-color: #0a0f18; 
    background-image: linear-gradient(rgba(var(--theme-color), 0.15), rgba(var(--theme-color), 0.15));
    width: var(--cell-size);
    height: var(--cell-size);
    cursor: pointer;
    transition: all 0.2s;
}
.cell:hover {
    background-image: linear-gradient(rgba(var(--theme-color), 0.4), rgba(var(--theme-color), 0.4));
}

/* --- YENİ KIRMIZI ÇİZGİ ROMAN TARZI GEMİLER --- */
.ship {
    box-sizing: border-box;
    background-color: transparent; 
    position: relative;
    overflow: visible;
    z-index: 10;
    transition: transform 0.1s;
    cursor: grab;
}

/* Pixel Art Gemi Şablonları */
.ship::after {
    content: '';
    position: absolute;
    /* Kareleri neredeyse tamamen kaplaması için çok küçük bir boşluk bırakıyoruz */
    top: 2%; bottom: 2%; 
    left: 2%; right: 2%;
    /* Resmi kutunun tamamına yay (boşluk kalmasın) */
    background-size: 100% 100%;
    background-position: center;
    background-repeat: no-repeat;
    pointer-events: none;
    filter: drop-shadow(0 4px 4px rgba(0,0,0,0.5));
}

.ship.vertical::after {
    top: 2%; bottom: 2%; 
    left: 2%; right: 2%;
}

/* YATAY GEMİLER */
.ship[data-id="0"].horizontal::after { background-image: url('images/ship_5.png'); }
.ship[data-id="1"].horizontal::after { background-image: url('images/ship_4.png'); }
.ship[data-id="2"].horizontal::after { background-image: url('images/ship_3a.png'); }
.ship[data-id="3"].horizontal::after { background-image: url('images/ship_3b.png'); }
.ship[data-id="4"].horizontal::after { background-image: url('images/ship_2.png'); }

/* DİKEY GEMİLER */
.ship[data-id="0"].vertical::after { background-image: url('images/ship_5_v.png'); }
.ship[data-id="1"].vertical::after { background-image: url('images/ship_4_v.png'); }
.ship[data-id="2"].vertical::after { background-image: url('images/ship_3a_v.png'); }
.ship[data-id="3"].vertical::after { background-image: url('images/ship_3b_v.png'); }
.ship[data-id="4"].vertical::after { background-image: url('images/ship_2_v.png'); }
.ship:active { cursor: grabbing; transform: scale(0.95); box-shadow: 0 2px 5px rgba(0,0,0,0.5); }
.cell.drag-over { background-color: rgba(46, 213, 115, 0.6) !important; box-shadow: inset 0 0 10px #2ed573 !important; }
.cell.drag-invalid { background-color: rgba(255, 71, 87, 0.6) !important; box-shadow: inset 0 0 10px #ff4757 !important; }
.ship.touch-selected { border-color: #f1c40f !important; box-shadow: 0 0 15px #f1c40f !important; }

/* --- Karavana ve Otomatik Miss (İnce, Parlayan ✕) --- */
.cell.miss {
    background-color: transparent !important; 
    background-image: none !important; 
    position: relative; 
    cursor: default;
    z-index: 20;
}
.cell.miss::after {
    content: "✕"; 
    font-family: sans-serif;
    font-size: 1.2rem;
    color: rgba(255, 255, 255, 0.4);
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}

/* --- İsabet (Parlayan Kırmızı Merkez) --- */
.cell.hit {
    background-color: rgba(255, 71, 87, 0.2) !important;
    background-image: none !important;
    box-shadow: inset 0 0 10px rgba(255, 71, 87, 0.8) !important;
    position: relative; 
    cursor: default;
    z-index: 20;
}
.cell.hit::after {
    content: ""; 
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 35%; height: 35%;
    background-color: #ff4757;
    border-radius: 50%;
    box-shadow: 0 0 10px #ff4757, 0 0 20px #ff4757;
}

/* --- Batan Gemi (SVG Kurukafa, Asla Kaymaz) --- */
.cell.sunk {
    background-color: #050505 !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ff4757'%3E%3Cpath d='M12,2C8.13,2 5,5.13 5,9C5,11.38 6.19,13.47 8,14.74V17A1,1 0 0,0 9,18H10V20A1,1 0 0,0 11,21H13A1,1 0 0,0 14,20V18H15A1,1 0 0,0 16,17V14.74C17.81,13.47 19,11.38 19,9C19,5.13 15.87,2 12,2M8.5,8A1.5,1.5 0 0,1 10,9.5A1.5,1.5 0 0,1 8.5,11A1.5,1.5 0 0,1 7,9.5A1.5,1.5 0 0,1 8.5,8M15.5,8A1.5,1.5 0 0,1 17,9.5A1.5,1.5 0 0,1 15.5,11A1.5,1.5 0 0,1 14,9.5A1.5,1.5 0 0,1 15.5,8M12,13.5A1.5,1.5 0 0,1 10.5,12A1.5,1.5 0 0,1 12,10.5A1.5,1.5 0 0,1 13.5,12A1.5,1.5 0 0,1 12,13.5Z' /%3E%3C/svg%3E") !important;
    background-size: 65% !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
    border: 1px solid #ff4757 !important;
    box-shadow: inset 0 0 15px rgba(255, 71, 87, 0.4) !important;
    position: relative;
    cursor: default;
    z-index: 20;
}
.cell.sunk::after { 
    content: none !important; 
}

/* Oyun Sonu Modal */
#gameOverModal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(10, 15, 24, 0.9);
    display: flex; justify-content: center; align-items: center;
    z-index: 1000; backdrop-filter: blur(8px);
}
.modal-content {
    background: var(--panel-bg);
    padding: 50px; border-radius: 12px; text-align: center; min-width: 400px;
    border: 2px solid transparent;
}
.modal-content.victory { border-color: #00b894; box-shadow: 0 0 50px rgba(0, 184, 148, 0.3); }
.modal-content.defeat { border-color: #d63031; box-shadow: 0 0 50px rgba(214, 48, 49, 0.3); }
#gameOverTitle { font-family: 'Russo One', sans-serif; font-size: 3.5em; margin: 0 0 15px 0; letter-spacing: 4px; }
#gameOverMessage { font-size: 1.3em; margin-bottom: 35px; color: #dfe6e9; }

#board-container.layout-2p .pos-me { 
    /* no translation */
}

/* --- Kural Bildirimi Animasyonu --- */
.toast {
    position: fixed; 
    top: 20px; 
    right: 20px; 
    background: linear-gradient(135deg, #e84118, #c23616); 
    color: white; 
    padding: 15px 25px;
    border-radius: 8px; 
    font-family: 'Jura', sans-serif; 
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5); 
    z-index: 9999;
    opacity: 0; 
    transform: translateX(150%); 
    transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    pointer-events: none; 
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.game-timer.danger {
    color: #ff4757;
    border-color: #ff4757;
    box-shadow: 0 0 20px rgba(255, 71, 87, 0.6);
    animation: shakeTimer 0.5s infinite alternate;
}

@keyframes shakeTimer {
    0% { transform: scale(1); }
    100% { transform: scale(1.05); }
}

#ruleToast2 { 
    top: 90px; 
    background: linear-gradient(135deg, #f39c12, #d35400); 
}

#board-container.layout-2p .pos-top {
    /* no translation */
}

/* --- Oyun Sonu Açığa Çıkan Rakiplerin Gemileri --- */
.cell.revealed-ship {
    background-color: rgba(45, 52, 54, 0.6) !important;
    border: 1px dashed #f1c40f !important;
    position: relative;
    cursor: default;
}
.cell.revealed-ship::after {
    content: "👀"; 
    font-size: 14px;
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    opacity: 0.6;
}

/* --- Üstten Bildirim (Top Notification) --- */
.top-notification {
    position: fixed;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #d63031, #c0392b);
    color: white;
    padding: 15px 30px;
    border-radius: 8px;
    font-family: 'Jura', sans-serif;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    z-index: 10000;
    transition: top 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: center;
}

.top-notification.show {
    top: 20px;
}

/* --- MOBİL CİHAZ YAN ÇEVİRME ENGELİ --- */
#orientation-warning {
    display: none;
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: #050505; color: #48dbfb; z-index: 999999;
    flex-direction: column; justify-content: center; align-items: center;
    text-align: center; font-family: 'Press Start 2P', cursive; font-size: 1rem; line-height: 1.5;
}
@media (max-height: 500px) and (orientation: landscape) {
    #orientation-warning { display: flex !important; }
    #lobby-screen, #game-screen { display: none !important; }
}