/* ==================== RESET & VARIABLES ==================== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    /* touch-action manipulation sur tout : élimine le délai 300ms */
    touch-action: manipulation;
}

/* Pas de sélection de texte sur les éléments interactifs */
button, .ship-item, .cell, .menu-btn, .btn {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

:root {
    --ocean-dark:   #001f3f;
    --ocean-blue:   #0074D9;
    --ocean-light:  #7FDBFF;
    --ship-gray:    #2c3e50;
    --fire-red:     #FF4136;
    --water-splash: #39CCCC;
    --hit-orange:   #FF851B;
    --gold:         #FFD700;
    --white:        #ffffff;
    /* Taille cellule adaptative selon écran */
    --cell-size: clamp(28px, 8vw, 52px);
}



/* ==================== THÈMES ==================== */
body.theme-sunset {
    --ocean-dark:  #2c1a00;
    --ocean-blue:  #ff6b35;
    --ocean-light: #ffaa5a;
}
body.theme-night {
    --ocean-dark:  #0a0a1a;
    --ocean-blue:  #1a1a3e;
    --ocean-light: #6060b0;
}
body.theme-arctic {
    --ocean-dark:  #1a3a4a;
    --ocean-blue:  #5a9aaa;
    --ocean-light: #aaddee;
}

/* ==================== BODY ==================== */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(180deg, var(--ocean-dark) 0%, var(--ocean-blue) 100%);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    color: white;
    /* scroll doux iOS */
    -webkit-overflow-scrolling: touch;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle at 20% 50%, rgba(127, 219, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(0, 116, 217, 0.1) 0%, transparent 50%);
    animation: waves 15s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes waves {
    0%, 100% { opacity: 0.3; transform: scale(1); }
    50%       { opacity: 0.6; transform: scale(1.1); }
}

/* ==================== HEADER ==================== */
.header {
    background: linear-gradient(135deg, rgba(0,31,63,.95), rgba(0,116,217,.95));
    backdrop-filter: blur(10px);
    padding: 14px 20px;
    box-shadow: 0 4px 20px rgba(0,0,0,.3);
    display: none;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    flex-wrap: wrap;
    gap: 10px;
}
.header.active { display: flex; }

.logo { display: flex; align-items: center; gap: 12px; }
.logo-icon { font-size: 2rem; animation: float 3s ease-in-out infinite; }

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-8px); }
}

.logo-text { display: flex; flex-direction: column; }
.logo-title    { font-size: 1.5rem; font-weight: bold; color: var(--gold); text-shadow: 0 0 10px rgba(255,215,0,.5); }
.logo-subtitle { font-size: .85rem; color: var(--ocean-light); letter-spacing: 2px; }

.header-stats { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stat-badge {
    background: rgba(0,0,0,.3);
    padding: 8px 14px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 6px;
    color: white;
    font-weight: bold;
    border: 1.5px solid rgba(255,255,255,.2);
    font-size: .95rem;
}
.stat-icon { font-size: 1.1rem; }

/* ==================== MENU PRINCIPAL ==================== */
.main-menu {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, var(--ocean-dark) 0%, var(--ocean-blue) 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity .4s, visibility .4s;
    padding: 20px;
}
.main-menu.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.menu-container { text-align: center; animation: slideUp .7s ease-out; }

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

.menu-title {
    font-size: clamp(2.2rem, 8vw, 4.5rem);
    color: var(--gold);
    text-shadow: 0 0 20px rgba(255,215,0,.5), 0 0 40px rgba(255,215,0,.3);
    margin-bottom: 8px;
    font-weight: bold;
}
.menu-subtitle {
    font-size: clamp(.9rem, 3vw, 1.3rem);
    color: var(--ocean-light);
    margin-bottom: 36px;
    letter-spacing: 3px;
}

.menu-ships {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 36px;
    font-size: clamp(1.8rem, 5vw, 3rem);
}

.menu-ship { animation: floatShip 3s ease-in-out infinite; }
.menu-ship:nth-child(1) { animation-delay: 0s; }
.menu-ship:nth-child(2) { animation-delay: .3s; }
.menu-ship:nth-child(3) { animation-delay: .6s; }
.menu-ship:nth-child(4) { animation-delay: .9s; }

@keyframes floatShip {
    0%, 100% { transform: translateY(0) rotate(-4deg); }
    50%       { transform: translateY(-12px) rotate(4deg); }
}

.menu-buttons { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 380px; }

.menu-btn {
    padding: 18px 36px;
    font-size: clamp(.95rem, 3vw, 1.2rem);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    /* press effect */
    transition: transform .08s ease, box-shadow .08s ease;
    min-height: 56px;        /* cible tactile minimum */
    position: relative;
    overflow: hidden;
}
.menu-btn.primary  { background: linear-gradient(135deg, var(--gold), #e07800); color: var(--ocean-dark); box-shadow: 0 8px 25px rgba(255,215,0,.4); }
.menu-btn.secondary{ background: linear-gradient(135deg, var(--ocean-blue), var(--ocean-light)); color: white; box-shadow: 0 8px 25px rgba(0,116,217,.35); }
.menu-btn:active   { transform: scale(.94); box-shadow: none; }

/* ==================== GAME CONTAINER ==================== */
.game-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px 16px;
    position: relative;
    z-index: 10;
}

/* ==================== PHASE DE PLACEMENT ==================== */
.placement-phase { display: none; }
.placement-phase.active { display: block; }

.placement-header { text-align: center; margin-bottom: 20px; }
.placement-title {
    font-size: clamp(1.3rem, 4vw, 2rem);
    color: var(--gold);
    text-shadow: 0 0 10px rgba(255,215,0,.5);
    margin-bottom: 8px;
}
.placement-info { color: var(--ocean-light); font-size: clamp(.9rem, 2.5vw, 1.1rem); }

/* ==================== FLOTTE ==================== */
.fleet-container {
    background: rgba(0,31,63,.8);
    border-radius: 18px;
    padding: 18px;
    margin-bottom: 20px;
    border: 2px solid rgba(127,219,255,.25);
}
.fleet-title { color: var(--gold); font-size: 1.1rem; margin-bottom: 14px; text-align: center; }

.ships-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
}

.ship-item {
    background: rgba(0,116,217,.3);
    border: 2px solid var(--ocean-light);
    border-radius: 12px;
    padding: 12px 10px;
    cursor: pointer;
    transition: transform .08s ease, box-shadow .1s ease;
    text-align: center;
    min-height: 90px;         /* grande cible tactile */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}
.ship-item:active:not(.placed) { transform: scale(.94); }
.ship-item.selected {
    background: rgba(255,215,0,.3);
    border-color: var(--gold);
    box-shadow: 0 0 16px rgba(255,215,0,.5);
}
.ship-item.placed {
    opacity: .45;
    cursor: not-allowed;
    background: rgba(0,0,0,.3);
    border-color: rgba(255,255,255,.15);
}
.ship-name { color: white; font-weight: bold; font-size: .95rem; }
.ship-icon { font-size: 1.8rem; }
.ship-size { color: var(--ocean-light); font-size: .8rem; }

/* ==================== GRILLE ==================== */
.game-board {
    background: rgba(0,31,63,.8);
    border-radius: 18px;
    padding: 18px;
    border: 2px solid rgba(127,219,255,.25);
    margin-bottom: 16px;
}
.board-label { color: var(--gold); font-size: 1.3rem; text-align: center; margin-bottom: 14px; font-weight: bold; }

.grid-wrapper {
    display: flex;
    justify-content: center;
    overflow-x: auto;            /* scroll horizontal si très petit écran */
}

.grid {
    display: inline-grid;
    grid-template-columns: 22px repeat(10, var(--cell-size));
    grid-template-rows:    22px repeat(10, var(--cell-size));
    gap: 2px;
    background: rgba(0,0,0,.3);
    padding: 3px;
    border-radius: 10px;
    touch-action: none;          /* CRITIQUE : empêche le scroll pendant qu'on joue */
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: var(--ocean-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(.55rem, 1.5vw, .75rem);
    color: var(--ocean-light);
    font-weight: bold;
    border: 1px solid rgba(127,219,255,.18);
    cursor: pointer;
    transition: transform .1s ease, background .1s ease;
    position: relative;
    border-radius: 2px;
    will-change: transform;
}
.cell.label {
    background: rgba(0,31,63,.9);
    cursor: default;
    border: none;
    font-size: clamp(.5rem, 1.4vw, .7rem);
}
/* Feedback tactile sur les cases eau */
.cell.water:active {
    transform: scale(1.1);
    background: var(--ocean-light);
}
/* Hover desktop uniquement (media query) */
@media (hover: hover) {
    .cell.water:hover {
        background: var(--ocean-light);
        transform: scale(1.05);
        box-shadow: 0 0 12px rgba(127,219,255,.6);
    }
}

.cell.ship { background: linear-gradient(135deg, var(--ship-gray), #34495e); border: 2px solid #95a5a6; }
.cell.ship-preview { background: rgba(255,215,0,.5); border: 2px dashed var(--gold); }
.cell.ship-invalid { background: rgba(255,65,54,.5); border: 2px dashed var(--fire-red); }

.cell.hit {
    background: radial-gradient(circle, var(--fire-red), var(--hit-orange));
    animation: explosion .4s ease-out;
}
.cell.hit::after {
    content: '💥';
    position: absolute;
    font-size: clamp(.9rem, 2.5vw, 1.4rem);
    animation: explode .6s ease-out forwards;
}

@keyframes explosion {
    0%   { transform: scale(0); }
    55%  { transform: scale(1.25); }
    100% { transform: scale(1); }
}
@keyframes explode {
    0%   { opacity: 0; transform: scale(0) rotate(0deg); }
    50%  { opacity: 1; transform: scale(1.3) rotate(180deg); }
    100% { opacity: .6; transform: scale(.8) rotate(360deg); }
}

.cell.miss { background: var(--water-splash); }
.cell.miss::after {
    content: '💧';
    position: absolute;
    font-size: clamp(.7rem, 2vw, 1.1rem);
    animation: splash .5s ease-out forwards;
}
@keyframes splash {
    0%   { opacity: 0; transform: translateY(-12px); }
    50%  { opacity: 1; transform: translateY(0); }
    100% { opacity: .7; transform: translateY(0); }
}

.cell.sunk { background: linear-gradient(135deg, #111, var(--ship-gray)); opacity: .55; }

/* ==================== PHASE DE COMBAT ==================== */
.battle-phase { display: none; }
.battle-phase.active {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr));
    gap: 20px;
}

/* ==================== CONTRÔLES ==================== */
.controls {
    text-align: center;
    margin-top: 16px;
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.btn {
    padding: 13px 24px;
    font-size: clamp(.85rem, 2.5vw, 1rem);
    border: none;
    border-radius: 28px;
    cursor: pointer;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    min-height: 48px;            /* cible tactile minimum */
    /* press 3D */
    box-shadow: 0 4px 0 rgba(0,0,0,.35);
    transition: transform .08s ease, box-shadow .08s ease;
}
.btn-primary   { background: linear-gradient(135deg, var(--gold), #e07800); color: var(--ocean-dark); }
.btn-secondary { background: linear-gradient(135deg, var(--ocean-blue), #00aaff); color: white; }
.btn-danger    { background: linear-gradient(135deg, var(--fire-red), var(--hit-orange)); color: white; }

.btn:active:not(:disabled) {
    transform: translateY(3px);
    box-shadow: 0 1px 0 rgba(0,0,0,.35);
}
@media (hover: hover) {
    .btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 0 rgba(0,0,0,.35); }
}
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

/* ==================== INDICATEUR DE TOUR ==================== */
.turn-indicator {
    background: rgba(0,31,63,.96);
    border: 2px solid var(--gold);
    border-radius: 16px;
    padding: 12px 20px;
    text-align: center;
    margin: 12px 16px;
    display: none;
    position: relative;
    z-index: 50;
}
.turn-indicator.active { display: block; }

.turn-text   { color: var(--ocean-light); font-size: .85rem; letter-spacing: 1px; text-transform: uppercase; }
.turn-player { color: var(--gold); font-size: 1.3rem; font-weight: bold; margin-top: 3px; }

/* ==================== TOAST (remplace alert) ==================== */
.toast {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(-16px);
    background: rgba(0,31,63,.97);
    border: 2px solid var(--gold);
    color: white;
    padding: 12px 24px;
    border-radius: 28px;
    font-size: 1rem;
    font-weight: bold;
    z-index: 3000;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
    white-space: nowrap;
    max-width: 90vw;
    text-align: center;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ==================== MODALS ==================== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 20px;
    /* Scroll si contenu dépasse l'écran */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
/* Paramètres : aligner en haut sur petit écran pour pouvoir scroller */
#settingsModal { align-items: flex-start; padding-top: 30px; padding-bottom: 30px; }

.modal.show { display: flex; }

@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn {
    0%   { transform: scale(.5); opacity: 0; }
    60%  { transform: scale(1.04); }
    100% { transform: scale(1); opacity: 1; }
}

.modal-content {
    background: linear-gradient(135deg, var(--ocean-dark), #004070);
    padding: clamp(24px, 5vw, 44px);
    border-radius: 24px;
    text-align: center;
    max-width: 500px;
    width: 100%;
    border: 2.5px solid var(--gold);
    animation: scaleIn .4s ease-out;
}

.modal-content.modal-rules {
    max-width: 680px;
    text-align: left;
    max-height: 82vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Modal settings : flex pour que le footer reste en bas */
.modal-content.modal-settings {
    display: flex;
    flex-direction: column;
    max-width: 460px;
}
.settings-scroll {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
}
/* Modal compact pour confirm + transition */
.modal-content.modal-sm { max-width: 340px; }

.modal-icon    { font-size: clamp(3rem, 10vw, 4.5rem); margin-bottom: 14px; }
.modal-title   { font-size: clamp(1.5rem, 5vw, 2.2rem); color: var(--gold); margin-bottom: 12px; font-weight: bold; }
.modal-message { font-size: clamp(.95rem, 2.5vw, 1.1rem); color: var(--ocean-light); margin-bottom: 0; line-height: 1.6; }

.modal-footer {
    text-align: center;
    margin-top: 24px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.rules-content { color: white; line-height: 1.8; margin: 16px 0; }
.rules-content h3 { color: var(--gold); margin-top: 18px; font-size: 1.05rem; }
.rules-content ul, .rules-content ol { padding-left: 20px; }
.rules-content li { margin-bottom: 6px; }

/* ==================== PARAMÈTRES ==================== */
.settings-content { color: white; margin: 16px 0; }
.setting-item { margin-bottom: 18px; }
.setting-label {
    display: block;
    margin-bottom: 8px;
    color: var(--ocean-light);
    font-size: 1rem;
    cursor: pointer;
}
.setting-label input[type="checkbox"] {
    margin-right: 10px;
    width: 20px;
    height: 20px;
    vertical-align: middle;
    cursor: pointer;
    accent-color: var(--gold);
}
.setting-label select, select {
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    border: 2px solid var(--ocean-light);
    background: rgba(0,31,63,.8);
    color: white;
    font-size: 1rem;
    margin-top: 6px;
    cursor: pointer;
    /* Taille minimum pour tactile */
    min-height: 44px;
}

/* ==================== WIDGET SOUTIEN ==================== */
.support-widget {
    position: fixed;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 500;           /* En dessous des boutons de jeu */
    max-width: 220px;
    font-family: 'Segoe UI', sans-serif;
    color: #e5e7eb;
}

.support-card {
    background: radial-gradient(circle at top left, rgba(0,116,217,.95), rgba(0,31,63,.98));
    border-radius: 1rem;
    padding: .75rem .85rem;
    border: 1px solid rgba(127,219,255,.4);
    box-shadow: 0 12px 30px rgba(0,31,63,.9);
    font-size: .78rem;
    line-height: 1.4;
    position: relative;
}
.support-card-title { font-weight: 600; font-size: .8rem; margin-bottom: .25rem; color: var(--gold); }
.support-card-text  { color: #cbd5f5; margin-bottom: .5rem; }
.support-card-text span { color: var(--ocean-light); }

.support-card-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .35rem .8rem;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--gold), #e07800);
    color: var(--ocean-dark);
    font-weight: 600;
    font-size: .75rem;
    text-decoration: none;
    white-space: nowrap;
    transition: transform .12s ease;
}
.support-card-button:active { transform: scale(.95); }

.support-card-close {
    position: absolute;
    top: -.5rem;
    right: -.5rem;
    width: 28px;              /* cible 28×28 minimum */
    height: 28px;
    border-radius: 50%;
    background: rgba(0,31,63,.95);
    border: 1.5px solid rgba(127,219,255,.7);
    color: #e5e7eb;
    font-size: .9rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    /* Réinitialiser les styles hérités de .btn */
    min-height: unset;
    box-shadow: none;
    padding: 0;
    text-transform: none;
    letter-spacing: 0;
}
.support-card-close:active { transform: scale(.9); }

/* ==================== COPYRIGHT ==================== */
.copyright {
    position: fixed;
    bottom: 8px;
    left: 12px;
    font-family: 'Segoe UI', sans-serif;
    font-size: 10px;
    color: rgba(255,255,255,.25);
    z-index: 9999;
    pointer-events: none;
    letter-spacing: 1px;
}

/* ==================== DÉSACTIVATION ANIMATIONS ==================== */
body.no-animations *,
body.no-animations *::before,
body.no-animations *::after {
    animation: none !important;
    transition: none !important;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 640px) {
    :root { --cell-size: clamp(26px, 8.5vw, 36px); }

    .header { padding: 10px 12px; }
    .game-container { padding: 10px; }
    .logo-title { font-size: 1.2rem; }

    .ships-list { grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 8px; }

    .support-widget { right: .4rem; max-width: 180px; }
    .turn-indicator { margin: 8px 10px; }

    /* Boutons controls en deux colonnes sur très petit écran */
    .controls { gap: 8px; }
    .btn { padding: 11px 16px; font-size: .8rem; }
}

@media (max-width: 400px) {
    :root { --cell-size: clamp(24px, 8.8vw, 32px); }
    .menu-ships { font-size: 1.6rem; }
}

