/* =========================================================================
   BASE RESET & IOS TWEAKS
========================================================================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    /* Evitar selección de texto y zoom para una experiencia nativa */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #000;
    /* Prevenir el overscroll bounce en Safari iOS */
    overscroll-behavior-y: none;
}

/* =========================================================================
   STATE CONTAINERS
========================================================================= */
.app-state {
    display: none;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

.app-state.active {
    display: flex;
    flex-direction: column;
}

/* =========================================================================
   STATE 1: GAME
========================================================================= */
#state-game {
    background: #70c5ce; /* Color del cielo de Flappy Bird */
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#touch-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    /* Permite capturar eventos táctiles sin interferir visualmente */
}

/* =========================================================================
   STATE 2: PASSWORD INPUT (Glassmorphism Premium Design)
========================================================================= */
#state-password {
    background: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%);
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.glass-panel {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 28px;
    padding: 40px 30px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    text-align: center;
    animation: scaleUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes scaleUp {
    0% { opacity: 0; transform: scale(0.9); }
    100% { opacity: 1; transform: scale(1); }
}

.glass-panel h2 {
    color: #ffffff;
    font-size: 26px;
    font-weight: 600;
    margin-bottom: 35px;
    letter-spacing: 0.5px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.input-group {
    margin-bottom: 30px;
}

.input-group input {
    width: 100%;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 18px;
    padding: 18px;
    color: #fff;
    font-size: 20px;
    text-align: center;
    outline: none;
    transition: all 0.3s ease;
    user-select: auto;
    -webkit-user-select: auto;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.2);
}

.input-group input:focus {
    border-color: #4a90e2;
    box-shadow: 0 0 15px rgba(74, 144, 226, 0.3), inset 0 2px 5px rgba(0,0,0,0.2);
    background: rgba(0, 0, 0, 0.4);
}

.primary-btn {
    width: 100%;
    padding: 18px;
    background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%);
    border: none;
    border-radius: 18px;
    color: #fff;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 15px;
    transition: all 0.2s ease;
    box-shadow: 0 10px 20px rgba(74, 144, 226, 0.3);
}

.primary-btn:active {
    opacity: 0.8;
    transform: scale(0.97);
}

.secondary-btn {
    width: 100%;
    padding: 18px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 18px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.secondary-btn:active {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(0.97);
}

/* =========================================================================
   STATE 3: CHAT (WhatsApp Style - Dark Premium)
========================================================================= */
#state-chat {
    background-color: #0b141a;
}

.chat-header {
    background: rgba(32, 44, 51, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 50px 20px 15px 20px; /* Espacio superior para Status Bar iOS */
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    z-index: 100;
}

.chat-title {
    display: flex;
    align-items: center;
    gap: 15px;
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00b4db, #0083b0);
    box-shadow: 0 2px 10px rgba(0, 180, 219, 0.3);
}

.status h3 {
    color: #e9edef;
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 2px;
}

.online-indicator {
    color: #00a884;
    font-size: 13px;
    font-weight: 500;
}

.chat-actions {
    display: flex;
    gap: 10px;
}

.panic-btn {
    background: rgba(241, 92, 109, 0.15);
    color: #f15c6d;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.panic-btn:active {
    background: rgba(241, 92, 109, 0.3);
    transform: scale(0.9);
}

.exit-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #e9edef;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.exit-btn:active {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(0.9);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    /* Scrolling nativo para Webkit */
    -webkit-overflow-scrolling: touch;
    /* Pattern de fondo estilo WhatsApp */
    background-image: url('data:image/svg+xml,%3Csvg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"%3E%3Cg fill="%231a242c" fill-opacity="0.6" fill-rule="evenodd"%3E%3Ccircle cx="3" cy="3" r="3"/%3E%3Ccircle cx="13" cy="13" r="3"/%3E%3C/g%3E%3C/svg%3E');
}

.msg-bubble {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
    user-select: none; /* Mejor para el long-press nativo en móviles */
    -webkit-user-select: none;
    animation: fadeInMsg 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    min-width: 80px;
    transition: opacity 0.2s; /* Para efecto visual al pulsar largo */
}

.msg-content {
    margin-bottom: 2px;
    user-select: auto;
    -webkit-user-select: auto;
}

.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
}

.msg-ticks {
    font-size: 13px;
    letter-spacing: -2px;
    margin-right: 2px;
}

.msg-ticks.read {
    color: #53bdeb; /* Ticks azules */
}

@keyframes fadeInMsg {
    0% { opacity: 0; transform: translateY(15px) scale(0.95); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

.msg-bubble.received {
    align-self: flex-start;
    background-color: #202c33;
    color: #e9edef;
    border-top-left-radius: 4px;
}

.msg-bubble.sent {
    align-self: flex-end;
    background-color: #005c4b;
    color: #e9edef;
    border-top-right-radius: 4px;
}

.chat-footer {
    padding: 15px 20px 30px 20px; /* Espacio inferior para Home Indicator en iOS */
    background: rgba(32, 44, 51, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-input-wrapper {
    display: flex;
    align-items: center;
    background: #2a3942;
    border-radius: 28px;
    padding: 6px 6px 6px 20px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.chat-input-wrapper input {
    flex: 1;
    background: transparent;
    border: none;
    color: #e9edef;
    font-size: 16px;
    outline: none;
    user-select: auto;
    -webkit-user-select: auto;
}

.chat-input-wrapper input::placeholder {
    color: #8696a0;
}

.send-btn {
    background: #00a884;
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-left: 10px;
    box-shadow: 0 4px 10px rgba(0, 168, 132, 0.3);
}

.send-btn:active {
    transform: scale(0.9);
    background: #008f6f;
}
