/* =========================================================================
   🌌 KANATA LINK (彼方 LINK) - HOJA DE ESTILOS BASE (ALPHA V1 - MOSAICO FIX)
   ========================================================================= */

:root {
    --bg-main: #0a0a12;       /* Fondo oscuro profundo */
    --bg-card: #121222;       /* Fondo de contenedores y tarjetas */
    --bg-input: #1a1a3a;      /* Fondo de entradas de texto */
    
    --neon-cyan: #00f3ff;     /* Color de acento principal */
    --neon-pink: #ff007f;     /* Color secundario / Energía */
    --text-main: #e2e8f0;     /* Texto claro */
    --text-muted: #8a99ad;    /* Texto secundario/desactivado */
    
    --border-glow: 0 0 10px rgba(0, 243, 255, 0.2);
    --transition-smooth: all 0.3s ease;
}

/* 🎚️ PERSONALIZACIÓN DE LA BARRA DE DESPLAZAMIENTO (SCROLLBAR) */
/* Para navegadores basados en Webkit (Brave, Chrome, Safari, Edge) */
::-webkit-scrollbar {
    width: 6px; /* Súper delgada y elegante */
    height: 6px;
}

/* El fondo por donde corre la barra */
::-webkit-scrollbar-track {
    background: var(--bg-main);
}

/* La barra que se mueve */
::-webkit-scrollbar-thumb {
    background: rgba(0, 243, 255, 0.2); /* Cyan sutil por defecto */
    border-radius: 10px;
    transition: var(--transition-smooth);
}

/* Cuando el usuario pasa el mouse o interactúa con la barra */
::-webkit-scrollbar-thumb:hover {
    background: var(--neon-cyan); /* Brillo cyan total */
    box-shadow: var(--border-glow);
}

/* Regla para Firefox (Soporte básico estándar) */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 243, 255, 0.2) #0a0a12;
}

/* 🎛️ RESETS & CONFIGURACIÓN GENERAL */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    overflow: hidden; /* Evita barras de desplazamiento raras en la SPA */
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    width: 100vw;
}

/* 📱 CONTENEDOR GLOBAL (Formato Móvil Ajustado) */
#app-container {
    width: 100%;
    max-width: 480px; /* Centrado como si fuera una app de celular */
    height: 100vh;
    background-color: #0d0d1a;
    border-left: 1px solid #1f1f3d;
    border-right: 1px solid #1f1f3d;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* 🔝 BARRA SUPERIOR (UI GLOBAL) */
#global-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background-color: var(--bg-card);
    border-bottom: 1px solid #1f1f3d;
    z-index: 10;
}

.logo {
    font-weight: 800;
    letter-spacing: 2px;
    color: var(--neon-cyan);
    text-shadow: 0 0 8px rgba(0, 243, 255, 0.5);
}

#energy-display {
    font-weight: bold;
    color: var(--neon-pink);
    background: rgba(255, 0, 127, 0.1);
    padding: 4px 12px;
    border-radius: 20px;
    border: 1px solid rgba(255, 0, 127, 0.3);
}

/* 🖼️ GESTIÓN DE VISTAS (SPA) */
.view {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow-y: auto;
    width: 100%;
    background-color: transparent !important;
}

.hidden {
    display: none !important;
}

/* 🚪 VISTA 1: LOGIN CERRADO ELEGANTE */
#view-login {
    justify-content: center;
    align-items: center;
}

.login-card {
    background-color: var(--bg-card);
    padding: 30px 25px;
    border-radius: 12px;
    width: 100%;
    border: 1px solid #232342;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    text-align: center;
}

.logo-title {
    font-size: 2.2rem;
    color: var(--neon-cyan);
    text-shadow: 0 0 12px rgba(0, 243, 255, 0.4);
    margin-bottom: 5px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 25px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#login-form {
    text-align: left;
}

.input-group {
    margin-bottom: 18px;
}

.input-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    letter-spacing: 0.5px;
}

.input-group input {
    width: 100%;
    padding: 12px;
    background-color: var(--bg-input);
    border: 1px solid #2d2d54;
    border-radius: 6px;
    color: var(--text-main);
    font-size: 0.95rem;
    transition: var(--transition-smooth);
}

.input-group input:focus {
    outline: none;
    border-color: var(--neon-cyan);
    box-shadow: var(--border-glow);
}

button {
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition-smooth);
}

#btn-login {
    width: 100%;
    padding: 14px;
    background-color: var(--neon-cyan);
    color: #000;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    margin-top: 10px;
}

#btn-login:hover {
    box-shadow: 0 0 15px rgba(0, 243, 255, 0.6);
    transform: translateY(-1px);
}

.error-text {
    color: #ff4a4a;
    font-size: 0.85rem;
    margin-top: 15px;
}

/* 🌌 VISTA 2: MENÚ "DESCUBRE" (Mosaico de 2 Columnas Estilo App Moderna) */
.section-title {
    margin-bottom: 20px;
}

.section-title h2 {
    font-size: 1.4rem;
    color: #fff;
}

.section-title p {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Modificado a un Grid responsivo con espacio inferior para el desfase */
#characters-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    width: 100%;
    padding-bottom: 40px; /* Margen extra abajo para que el desfase no corte el último elemento */
}

/* Tarjeta individual adaptada para diseño vertical en mosaico */
.character-card {
    display: flex;
    flex-direction: column;
    background-color: var(--bg-card);
    border-radius: 12px;
    border: 1px solid #1f1f3d;
    overflow: hidden;
    transition: var(--transition-smooth);
    height: max-content; /* Permite que se acomoden de forma orgánica */
}

/* ✨ EL TRUCO MÁGICO: Empuja la segunda columna hacia abajo exactamente la mitad */
.character-card:nth-child(even) {
    transform: translateY(35px);
}

/* Reajustamos el hover para que respete el desfase de la segunda columna */
.character-card:hover {
    border-color: var(--neon-cyan);
    box-shadow: 0 5px 15px rgba(0, 243, 255, 0.15);
}
.character-card:nth-child(even):hover {
    transform: translateY(32px); /* Mantiene el desfase restando el sutil movimiento del hover */
}

/* Imagen cuadrada y adaptada al ancho del mosaico */
.char-thumb {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1; /* Forzar que sea un cuadrado perfecto */
    object-fit: cover;
    background-color: #1a1a2e;
}

/* Detalles del personaje en bloque inferior */
.char-details {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 8px;
}

.char-details h3 {
    font-size: 1rem;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; /* Evita que nombres largos rompan la tarjeta */
}

.char-details p {
    color: var(--text-muted);
    font-size: 0.75rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2; /* Recorta la descripción a máximo 2 líneas */
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 4px;
}

/* Botón de Vínculo expandido al ancho de su columna */
.btn-link {
    width: 100%;
    align-self: center;
    text-align: center;
    padding: 8px 12px;
    background-color: transparent;
    border: 1px solid var(--neon-cyan);
    color: var(--neon-cyan);
    border-radius: 6px;
    font-size: 0.75rem;
}

.btn-link:hover {
    background-color: var(--neon-cyan);
    color: #000;
}

/* 💬 VISTA 3: SALA DE CHAT ESTILO NOVELA VISUAL */
.chat-header {
    display: flex;
    align-items: center;
    gap: 15px;
    background-color: var(--bg-card);
    padding: 10px 15px;
    border-bottom: 1px solid #1f1f3d;
    margin: -20px -20px 0 -20px; /* Rompe el padding del contenedor view */
}

.btn-secondary {
    background: transparent;
    border: 1px solid #3d3d7a;
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.8rem;
}

.btn-secondary:hover {
    border-color: var(--text-main);
    color: var(--text-main);
}

.character-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

#chat-char-name {
    font-weight: bold;
    font-size: 1.1rem;
}

/* 💬 VISTA 3: SALA DE CHAT GLOBAL (MÁXIMO BRILLO FIX) */
#view-chat {
    background-color: transparent !important; /* Quitamos cualquier azul base */
    padding: 20px;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

/* Forzamos a que la caja de los mensajes y el fondo no se superpongan con sombras */
#chat-messages-box {
    flex: 1;
    overflow-y: auto;
    padding: 15px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-color: transparent !important; /* 100% transparente */
    box-shadow: none !important;
}
/* Burbujas de mensajes */
.msg {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 14px;
    font-size: 0.95rem;
    line-height: 1.4;
    word-break: break-word;
}

.msg.user {
    align-self: flex-end;
    background-color: #24244d;
    color: #fff;
    border-bottom-right-radius: 2px;
}

.msg.character {
    align-self: flex-start;
    background-color: var(--bg-card);
    color: var(--text-main);
    border-bottom-left-radius: 2px;
    border: 1px solid #1f1f3d;
}

/* Barra inferior del chat input */
.chat-input-area {
    display: flex;
    gap: 10px;
    padding: 15px 0 0 0;
    border-top: 1px solid #1f1f3d;
}

#input-message {
    flex: 1;
    padding: 12px;
    background-color: var(--bg-input);
    border: 1px solid #2d2d54;
    border-radius: 6px;
    color: var(--text-main);
    font-size: 0.95rem;
}

#input-message:focus {
    outline: none;
    border-color: var(--neon-cyan);
}

#btn-send {
    padding: 0 18px;
    background-color: var(--neon-pink);
    border: none;
    color: #fff;
    border-radius: 6px;
    font-size: 0.9rem;
}

#btn-send:hover {
    box-shadow: 0 0 12px rgba(255, 0, 127, 0.6);
}

/* ANIMACIONES */
.pulse {
    animation: pulseKey 2s infinite;
}

@keyframes pulseKey {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; text-shadow: 0 0 10px rgba(0, 243, 255, 0.5); }
}