* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #020204;
    font-family: 'monospace', sans-serif;
    color: #fff;
}

/* DETECCIÓN DE ROTACIÓN OPTIMIZADA */
#rotate-device-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #05050c;
    z-index: 99999 !important; 
    display: none;
    justify-content: center;
    align-items: center;
    text-align: center;
}
.rotate-box { padding: 2rem; }
.phone-icon {
    font-size: 4rem;
    display: block;
    margin-bottom: 1rem;
    animation: rotateAnim 2s infinite ease-in-out;
}
@keyframes rotateAnim {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(90deg); }
}

@media screen and (max-width: 900px) and (orientation: portrait) {
    #rotate-device-screen { 
        display: flex !important; 
    }
    .main-layout, #welcome-screen {
        display: none !important;
    }
}

/* BIENVENIDA RESPONSIVA (ADAPTADA A MÓVILES) */
#welcome-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 5, 12, 0.95);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px; /* Evita que choque con los bordes físicos del celular */
}

.welcome-box { 
    text-align: center; 
    padding: 2rem 1.5rem; 
    background: #0d0d1a; 
    border: 2px solid #00f2fe; 
    border-radius: 16px;
    width: 100%;              /* Ocupa el ancho disponible */
    max-width: 450px;         /* Límite en pantallas grandes */
    max-height: 90vh;         /* Evita salirse del alto del celular */
    overflow-y: auto;         /* Activa scroll interno si el texto es muy largo en pantallas pequeñas */
}

#btn-start { 
    margin-top: 1.5rem; 
    padding: 12px 30px; 
    background: #ff007f; 
    border: none; 
    color: #fff; 
    font-weight: bold; 
    border-radius: 8px; 
    cursor: pointer; 
    font-size: 1.1rem;
}

#btn-library {
    margin-top: 10px;
    padding: 10px 20px;
    background: transparent;
    border: 1px solid #ffaa00;
    color: #ffaa00;
    font-family: monospace;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
}

#btn-library:hover,
#btn-library:focus-visible {
    background: rgba(255, 170, 0, 0.15);
    box-shadow: 0 0 15px rgba(255, 170, 0, 0.5);
}

/* LAYOUT */
.main-layout { display: flex; width: 100%; height: 100%; }
.credits-sidebar { width: 20%; height: 100%; background: #05050d; border-right: 2px solid rgba(255, 0, 127, 0.2); position: relative; overflow: hidden; }
#game-container { width: 80%; height: 100%; position: relative; }

@media (max-width: 900px) and (orientation: landscape) {
    .credits-sidebar { display: none !important; }
    #game-container { width: 100% !important; }
    
    /* 🟢 REGLA CORREGIDA: Los controles táctiles solo se muestran si la pantalla de bienvenida ya está oculta */
    #welcome-screen.modal-hidden ~ .main-layout .hidden-controls { 
        display: block !important; 
    }
}

/* MARQUESINA OPTIMIZADA */
.starwars-wrapper { position: absolute; width: 100%; height: 100%; }
.starwars-content { 
    position: absolute; 
    width: 100%; 
    padding: 15px; 
    text-align: center; 
    animation: scrollCredits 260s linear infinite; 
    animation-play-state: paused; 
}
.starwars-content h3 { color: #ff007f; margin-bottom: 15px; }
.starwars-content p { color: #00f2fe; font-size: 1.275rem; margin-bottom: 15px; }

.starwars-content.start-animation {
    animation-play-state: running;
}

@keyframes scrollCredits { 
    0% { transform: translateY(100vh); } 
    100% { transform: translateY(-100%); } 
}

/* ZONA JOYSTICK VIRTUAL ESTABLE */
#joystick-zone {
    position: absolute;
    bottom: 25px;
    left: 45px;
    width: 110px;
    height: 110px;
    z-index: 250;
    display: none; /* Por defecto oculto */
}

/* BOTÓN DE ACCIÓN MÓVIL ACOMODADO MEJOR */
#btn-mobile-action {
    position: absolute;
    bottom: 35px;
    right: 140px; /* Acomodado a una distancia cómoda del pulgar derecho */
    z-index: 250;
    padding: 16px 28px;
    background: rgba(255, 0, 127, 0.75);
    border: 2px solid #ff007f;
    color: white;
    font-weight: bold;
    font-family: monospace;
    font-size: 1.1rem;
    border-radius: 14px;
    box-shadow: 0 0 15px rgba(255, 0, 127, 0.5);
    display: none; /* Por defecto oculto */
}

#btn-mobile-action:active {
    background: #ff007f;
    transform: scale(0.95);
}

/* BOTÓN DE CONTROLES CON ANIMACIÓN DE LATIDO RÁPIDO Y RGB NEÓN */
#btn-help-toggle { 
    position: absolute; 
    bottom: 20px; 
    right: 20px; 
    z-index: 50; 
    padding: 10px 16px; 
    background: rgba(13, 13, 30, 0.8); 
    border: 1px solid #00f2fe; 
    color: #00f2fe; 
    border-radius: 8px; 
    cursor: pointer;
    transition: background 0.3s, transform 0.1s;
    font-weight: bold;
    animation: pulseAndGlowControls 1.2s infinite cubic-bezier(0.4, 0, 0.6, 1);
    will-change: transform, border-color, box-shadow, color;
}

#btn-help-toggle:hover {
    background: rgba(0, 242, 254, 0.15) !important;
    box-shadow: 0 0 30px #00f2fe !important;
}

@keyframes pulseAndGlowControls {
    0% {
        transform: scale(1);
        color: #00f2fe;
        border-color: #00f2fe;
        box-shadow: 0 0 8px rgba(0, 242, 254, 0.4);
    }
    30% {
        transform: scale(1.12); 
        color: #ff007f;          
        border-color: #ff007f;
        box-shadow: 0 0 25px rgba(255, 0, 127, 0.9);
    }
    60% {
        transform: scale(1.05);
        color: #ffaa00;          
        border-color: #ffaa00;
        box-shadow: 0 0 18px rgba(255, 170, 0, 0.7);
    }
    100% {
        transform: scale(1);
        color: #00f2fe;          
        border-color: #00f2fe;
        box-shadow: 0 0 8px rgba(0, 242, 254, 0.4);
    }
}

#help-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.7); z-index: 600; display: flex; justify-content: center; align-items: center; }
.modal-content { background: rgba(13, 13, 26, 0.95); border: 1px solid #ff007f; padding: 1.5rem; border-radius: 12px; max-width: 500px; width: 90%; }
.modal-hidden { display: none !important; }
#btn-close-help { margin-top: 1rem; padding: 8px 16px; background: #00f2fe; color: #000; border: none; font-weight: bold; border-radius: 6px; width: 100%; }

/* TERMINAL DE LA CALCULADORA CYBERPUNK */
#cyber-calc {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #0d0d20;
    border: 3px solid #00f2fe;
    box-shadow: 0 0 30px rgba(0, 242, 254, 0.6);
    border-radius: 12px;
    padding: 18px;
    width: 290px;
    z-index: 9999 !important;
    display: flex;
    flex-direction: column;
    gap: 10px;
    touch-action: auto !important; 
}

.calc-hidden {
    display: none !important;
}

.calc-screen {
    background: #02020a;
    border: 1px solid #ff007f;
    border-radius: 6px;
    padding: 12px;
    text-align: right;
    font-family: monospace;
}

#calc-history { font-size: 0.8rem; color: #ff007f; min-height: 16px; font-weight: bold; }
#calc-display { font-size: 1.8rem; color: #00f2fe; overflow: hidden; font-weight: bold; }

.calc-buttons {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 8px !important;
}

.calc-buttons button {
    padding: 14px 10px !important;
    background: #161636 !important;
    border: 1px solid #00f2fe !important;
    color: #00f2fe !important;
    font-family: monospace !important;
    font-size: 1.2rem !important;
    font-weight: bold !important;
    border-radius: 6px !important;
    cursor: pointer !important;
    touch-action: manipulation !important;
}

.calc-buttons button:active { background: #00f2fe !important; color: #000 !important; }
.calc-buttons button.op { border-color: #ff007f !important; color: #ff007f !important; }
.calc-buttons button.clear { border-color: #ffaa00 !important; color: #ffaa00 !important; }
.calc-buttons button.equal { background: #ff007f !important; color: white !important; border-color: #ff007f !important; }

#btn-close-calc {
    background: #ff007f;
    border: none;
    color: white;
    padding: 10px;
    font-family: monospace;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    margin-top: 5px;
    width: 100%;
}

/* CAMPOS DE CREDENCIALES EN BIENVENIDA */
.login-form {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.login-form input {
    width: 260px;
    padding: 10px 14px;
    background: #02020a;
    border: 1px solid #00f2fe;
    border-radius: 6px;
    color: #00f2fe;
    font-family: monospace;
    font-size: 1rem;
    outline: none;
    text-align: center;
}

.login-form input:focus {
    box-shadow: 0 0 10px rgba(0, 242, 254, 0.5);
    border-color: #ff007f;
}

/* EFECTO DE LATIDO MÁS VIVO, RÁPIDO Y GRANDE PARA LA PISTA */
.login-hint {
    margin-top: 1.5rem;
    font-size: 0.85rem;
    color: #ffaa00;
    max-width: 300px;
    line-height: 1.4;
    text-align: center;
    font-weight: bold;
    animation: pulseHintCustom 1.5s infinite cubic-bezier(0.4, 0, 0.6, 1);
    display: inline-block;
    will-change: transform, text-shadow;
}

@keyframes pulseHintCustom {
    0% {
        transform: scale(1);
        text-shadow: 0 0 5px rgba(255, 170, 0, 0.2);
    }
    30% {
        transform: scale(1.12); 
        text-shadow: 0 0 20px rgba(255, 170, 0, 0.8);
    }
    100% {
        transform: scale(1);
        text-shadow: 0 0 5px rgba(255, 170, 0, 0.2);
    }
}

#login-error {
    color: #ff007f;
    font-size: 0.85rem;
    min-height: 18px;
    font-weight: bold;
}

/* BOTÓN CERRAR SESIÓN FLOTANTE */
#btn-logout {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 50;
    padding: 10px 16px;
    background: rgba(13, 13, 30, 0.8);
    border: 1px solid #ff007f; 
    color: #ff007f;
    font-family: monospace;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

#btn-logout:hover {
    background: rgba(255, 0, 127, 0.2) !important;
    box-shadow: 0 0 15px #ff007f !important;
    transform: scale(1.05);
}

#library-login,
#library-panel {
    position: fixed;
    inset: 0;
    z-index: 12000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(2, 2, 4, 0.88);
    touch-action: auto;
}

.library-login-box {
    width: min(100%, 420px);
    text-align: center;
    border-color: #ffaa00;
}

.library-login-box p {
    margin-top: 10px;
    color: #d5d5e5;
}

#library-password {
    width: 100%;
    margin-top: 18px;
    padding: 12px;
    background: #02020a;
    border: 1px solid #00f2fe;
    border-radius: 6px;
    color: #fff;
    font: 1rem monospace;
    text-align: center;
}

#library-login-error {
    min-height: 20px;
    color: #ff007f;
    font-weight: bold;
}

.library-actions,
.upload-form {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.library-actions button,
.library-primary,
.library-close {
    padding: 10px 16px;
    border: 1px solid #00f2fe;
    border-radius: 6px;
    background: #101b2b;
    color: #00f2fe;
    cursor: pointer;
    font: bold 0.9rem monospace;
}

.library-primary {
    background: #00f2fe;
    color: #020204;
}

.library-primary:disabled {
    cursor: wait;
    opacity: 0.55;
}

.library-content {
    width: min(100%, 900px);
    max-height: 92vh;
    overflow-y: auto;
    padding: 24px;
    background: #0b0d18;
    border: 2px solid #00f2fe;
    box-shadow: 0 0 35px rgba(0, 242, 254, 0.35);
    border-radius: 12px;
}

.library-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 22px;
}

.library-kicker {
    color: #ffaa00;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
}

.library-header h2 {
    margin-top: 5px;
    color: #fff;
}

.library-close {
    padding: 2px 10px;
    border-color: #ff007f;
    color: #ff007f;
    font-size: 1.7rem;
    line-height: 1;
}

.bookshelf {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 18px 14px;
    min-height: 180px;
    padding: 22px 16px 28px;
    background: linear-gradient(#171a2c 0 94%, #8a4f2a 94% 100%);
    border: 1px solid rgba(255, 170, 0, 0.5);
    border-radius: 8px;
}

.book-item {
    position: relative;
    display: flex;
    min-height: 135px;
    flex-direction: column;
    justify-content: space-between;
    padding: 14px 12px;
    background: linear-gradient(135deg, #ef1040, #8d1238);
    border-left: 8px solid #ff9f1c;
    border-radius: 3px 8px 8px 3px;
    box-shadow: 5px 7px 0 rgba(0, 0, 0, 0.35);
    transform: rotate(-1deg);
}

.book-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    cursor: pointer;
    font: bold 1.1rem/1 monospace;
}

.book-delete:hover,
.book-delete:focus-visible {
    background: #ff007f;
    border-color: #fff;
    box-shadow: 0 0 12px rgba(255, 0, 127, 0.8);
}

.book-item:nth-child(3n) { background: linear-gradient(135deg, #00a9b5, #07566c); transform: rotate(1deg); }
.book-item:nth-child(4n) { background: linear-gradient(135deg, #6e43a7, #34215d); }
.book-item a { color: #fff; font-weight: bold; text-decoration: none; overflow-wrap: anywhere; }
.book-item small { color: rgba(255, 255, 255, 0.75); }
.library-status { min-height: 22px; margin: 12px 0; color: #ffaa00; text-align: center; }
.upload-form { justify-content: flex-start; }
#selected-pdf-name { color: #d5d5e5; font-size: 0.85rem; overflow-wrap: anywhere; }