/* ============================================
   SERPENT ATTACK - CSS RESPONSIVE OPTIMIZADO
   ============================================ */

/* --- RESET Y BASE --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: manipulation;
    -webkit-font-smoothing: antialiased;
}

body {
    background: #1a1a1a;
    color: white;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* --- PANTALLAS BASE --- */
#menu-screen,
#help-screen,
#game-screen,
#exit-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 100%;
    max-width: 90vw;
    padding: 10px;
}

/* --- MENU PRINCIPAL --- */
#menu-screen h1 {
    font-size: clamp(1.8rem, 6vw, 3rem);
    margin-bottom: 8px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

#high-score-display {
    font-size: clamp(0.9rem, 3.5vw, 1.3rem);
    color: #008CBA;
    margin-bottom: 8px;
}

#challenge-description {
    font-size: clamp(0.8rem, 2.8vw, 1.1rem);
    color: #FFD700;
    margin: 8px 10px;
    max-width: 90%;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: min(280px, 85vw);
    gap: 10px;
    margin-top: 10px;
}

.menu-btn {
    font-size: clamp(0.95rem, 3.5vw, 1.3rem);
    padding: clamp(10px, 2.5vh, 14px) clamp(16px, 4vw, 24px);
    background-color: #4CAF50;
    border: none;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.15s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    font-weight: 500;
}

.menu-btn:active {
    transform: scale(0.96);
}

.menu-btn:disabled {
    background-color: #555;
    cursor: not-allowed;
    opacity: 0.7;
}

#help-button { background-color: #008CBA; }
#settings-button { background-color: #6f42c1; }
#exit-button { background-color: #f44336; }

/* --- PANTALLA DE JUEGO --- */
#game-screen {
    width: 100%;
    height: 100%;
    padding: 5px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

#info-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: min(480px, 92vw);
    padding: 5px 10px;
    gap: 10px;
}

#info-bar h2,
#info-bar h3 {
    font-size: clamp(0.85rem, 3vw, 1.2rem);
    margin: 0;
    white-space: nowrap;
    font-weight: 600;
}

#timer-display {
    color: #FFD700;
}

/* --- CANVAS (TAMAÑO CONTROLADO POR JS) --- */
.canvas-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: none;
}

#gameCanvas {
    display: block;
    background: #000;
    border: 3px solid #4a4a4a;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.6);
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    touch-action: none;
    user-select: none;
    /* NO establecer width/height aquí - lo maneja JavaScript */
}

/* --- PANTALLA DE AYUDA --- */
#help-screen {
    text-align: left;
    max-width: min(500px, 88vw);
}

#help-screen h2 {
    color: #FFD700;
    margin-bottom: 15px;
    font-size: clamp(1.3rem, 4.5vw, 2rem);
    text-align: center;
}

#help-screen ul {
    font-size: clamp(0.9rem, 3vw, 1.1rem);
    line-height: 1.5;
    padding-left: 20px;
    margin-bottom: 20px;
}

#help-screen li {
    margin-bottom: 8px;
}

/* --- PANTALLA DE SALIDA --- */
#exit-screen h2 {
    font-size: clamp(1.5rem, 5vw, 2rem);
    color: #4CAF50;
}

/* --- MODALES --- */
#modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 100;
    backdrop-filter: blur(3px);
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #2a2a2a;
    color: white;
    padding: clamp(15px, 4vh, 25px) clamp(18px, 5vw, 30px);
    border-radius: 12px;
    border: 2px solid #4CAF50;
    text-align: center;
    z-index: 110;
    width: min(380px, 90vw);
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.7);
}

.modal h2 {
    color: #FFD700;
    margin-top: 0;
    margin-bottom: 12px;
    font-size: clamp(1.2rem, 4vw, 1.7rem);
}

.modal p {
    font-size: clamp(0.85rem, 3vw, 1.05rem);
    line-height: 1.4;
    margin: 10px 0;
}

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
    flex-wrap: wrap;
}

#new-record-message {
    color: #4CAF50;
    font-weight: bold;
    font-size: clamp(1rem, 3.5vw, 1.3rem);
    animation: pulse 1s infinite;
}

/* --- CONFIGURACION --- */
.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.settings-row label {
    font-size: clamp(0.8rem, 2.5vw, 0.95rem);
    color: #ddd;
    text-align: left;
    flex: 1;
    min-width: 100px;
}

#settings-controls {
    width: 100%;
    margin: 15px 0;
}

#settings-controls input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: linear-gradient(90deg, #4CAF50, #008CBA);
    border-radius: 6px;
    outline: none;
    flex: 1;
    min-width: 100px;
    cursor: pointer;
}

#settings-controls input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

#settings-controls input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.small-btn {
    background: #333;
    color: #fff;
    border: none;
    padding: clamp(6px, 1.5vh, 8px) clamp(8px, 2vw, 12px);
    border-radius: 6px;
    cursor: pointer;
    font-size: clamp(0.75rem, 2vw, 0.9rem);
    transition: background 0.2s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.small-btn:active {
    background: #222;
}

/* --- D-PAD PROFESIONAL (CONTROLADO POR JS) --- */
#dpad-pro {
    position: fixed;
    bottom: 15px;
    left: 15px;
    width: 110px;
    height: 110px;
    z-index: 9999;
    display: none; /* JS controla la visibilidad */
    transition: none; /* Sin transiciones para evitar bugs */
}

.btn {
    position: absolute;
    width: 33.3%;
    height: 33.3%;
    border: 2px solid #ff2a2a;
    background: rgba(17, 17, 17, 0.9);
    border-radius: 8px;
    box-shadow: 0 0 8px rgba(255, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: none;
}

.btn::before {
    content: "";
    width: 0;
    height: 0;
    border-style: solid;
}

.up { 
    top: 0; 
    left: 33.3%;
}

.down { 
    bottom: 0; 
    left: 33.3%;
}

.left { 
    left: 0; 
    top: 33.3%;
}

.right { 
    right: 0; 
    top: 33.3%;
}

.up::before {
    border-width: 0 8px 12px;
    border-color: transparent transparent white transparent;
}

.down::before {
    border-width: 12px 8px 0;
    border-color: white transparent transparent transparent;
}

.left::before {
    border-width: 8px 12px 8px 0;
    border-color: transparent white transparent transparent;
}

.right::before {
    border-width: 8px 0 8px 12px;
    border-color: transparent transparent transparent white;
}

.btn:active {
    transform: scale(0.88);
    border-color: #ff5555;
    box-shadow: 0 0 15px #ff0000;
    background: rgba(17, 17, 17, 1);
}

/* --- UTILIDADES --- */
.hidden {
    display: none !important;
}

/* --- ANIMACIONES --- */
@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(1.05); }
}

/* --- RESPONSIVE MOBILE --- */
@media (max-width: 768px) {
    /* JS controla el D-Pad dinámicamente */
    body {
        overflow: hidden;
    }
}

/* --- LANDSCAPE MODE --- */
@media (max-height: 500px) and (orientation: landscape) {
    #menu-screen h1 {
        font-size: 1.5rem;
        margin-bottom: 5px;
    }
    
    #challenge-description,
    #high-score-display {
        font-size: 0.8rem;
        margin: 3px 0;
    }
    
    .menu-buttons {
        gap: 6px;
    }
    
    .menu-btn {
        padding: 6px 12px;
        font-size: 0.95rem;
    }
    
    #game-screen {
        padding: 2px;
        gap: 3px;
    }
    
    #info-bar {
        padding: 2px 8px;
    }
}

/* --- PORTRAIT MODE EN MOVIL --- */
@media (max-width: 768px) and (orientation: portrait) {
    #info-bar {
        flex-wrap: wrap;
        justify-content: center;
        gap: 5px 15px;
    }
}

/* --- PANTALLAS MUY PEQUENAS --- */
@media (max-width: 360px) {
    #menu-screen h1 {
        font-size: 1.6rem;
    }
    
    .menu-buttons {
        max-width: 90vw;
    }
    
    #info-bar h2,
    #info-bar h3 {
        font-size: 0.8rem;
    }
}

/* --- DESKTOP --- */
@media (min-width: 769px) {
    .menu-btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    }
    
    .small-btn:hover {
        background: #444;
    }
}

/* --- ACCESIBILIDAD --- */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

button:focus-visible {
    outline: 3px solid #FFD700;
    outline-offset: 2px;
}

/* --- ROTACION DE PANTALLA --- */
#rotate-screen {
    position: fixed;
    inset: 0;
    background: #000;
    color: #fff;
    display: none;
    justify-content: center;
    align-items: center;
    font-size: clamp(1rem, 4vw, 1.5rem);
    z-index: 999999;
    text-align: center;
    padding: 20px;
}
