/* Reset y configuración base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #000;
    overflow: hidden;
    height: 100vh;
}

/* Contenedor del dispositivo */
.device-container {
    position: relative;
    width: 100%;
    height: 100vh;
    max-width: 414px; /* iPhone 14 Pro Max width */
    margin: 0 auto;
    background: #000;
    border-radius: 0;
    overflow: hidden;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
}

/* Modo escritorio - simular iPad */
@media (min-width: 768px) {
    .device-container {
        max-width: 1200px;
        height: 90vh;
        margin: 5vh auto;
        border-radius: 20px;
        border: 8px solid #1d1d1f;
    }
}


/* Pantalla principal */
.home-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    pointer-events: auto;
    opacity: 0;
}

.home-screen.loaded {
    opacity: 1;
}

.home-screen[style*="hidden"] {
    pointer-events: none;
}

.wallpaper {
    position: relative;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* Widget de usuario */
.user-widget {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 16px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.3);
    z-index: 10;
    /* Grid positioning - desktop (4x4) - 1 fila x 1 columna */
    grid-column: 4 / 5;
    grid-row: 1 / 2;
    width: 100%;
    height: 100%;
    /* Estructura interna igual que móvil: 4 filas (nombre, GM, Estrella, Robot) */
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto;
    row-gap: 8px;
    align-items: start;
    justify-items: stretch;
    transform: translateY(-15%);
}

@media (max-width: 768px) {
    .user-widget {
        /* Grid positioning - mobile (4x6): 2 filas x 2 columnas, desde la segunda fila */
        grid-column: 1 / 3;
        grid-row: 2 / 4;
        padding: 8px 10px;
        transform: none;
        width: 100%;
        height: 100%;
        /* Estructura interna en 4 filas: nombre, GM, Estrella, Robot */
        display: grid;
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto; /* evitar crecimiento excesivo */
        row-gap: 6px;
        align-items: start;
        justify-items: stretch; /* estirar para alinear contenido a la izquierda por defecto */
        /* Asegurar que se coloca antes que los iconos para no solaparlos */
        order: -1;
    }
    /* Permitir que los hijos puedan encoger dentro del grid */
    .user-widget > * { min-width: 0; }
}

.widget-left { display: contents; }

.widget-right { display: contents; }

.widget-header {
    margin: 0;
    padding: 0;
    text-align: center;
}

.app-name {
    color: white;
    font-size: 26px;
    font-weight: 700;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    letter-spacing: 0.5px;
    text-align: center;
}

@media (max-width: 768px) {
    .app-name {
        font-size: 16px;
    }
}

.widget-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex: 1;
    justify-content: center;
}

@media (max-width: 768px) {
    .widget-body { gap: 10px; }
}

.user-name {
    color: white;
    font-size: 20px;
    font-weight: 700;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    letter-spacing: 0.5px;
    text-align: left;
    margin: 0;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .user-name {
        font-size: 24px;
        text-align: center;
        grid-row: 1;
        justify-self: stretch;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 10px 14px;
        background: rgba(255, 255, 255, 0.08);
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: 12px;
        width: 100%;
        box-sizing: border-box;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

.widget-stats-vertical { display: contents; }

.stat-row {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    padding: 0;
    background: transparent;
    border-radius: 0;
    border: none;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .stat-row {
        gap: 6px;
        padding: 0;
        width: 100%;
        justify-content: flex-start; /* alinear a la izquierda las filas de stats */
    }
    /* GM en fila 2 */
    .widget-stats-vertical .stat-row:nth-child(1) { grid-row: 2; }
    /* Estrella en fila 3 */
    .widget-stats-vertical .stat-row:nth-child(2) { grid-row: 3; }
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

@media (max-width: 768px) {
    .stat-item {
        gap: 10px;
    }
}

.stat-icon {
    font-size: 20px;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .stat-icon {
        font-size: 28px; /* emojis más grandes y unificados */
        width: 32px;
        min-width: 32px;
        text-align: center;
        margin-right: 6px; /* más separación hacia la derecha */
    }
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    color: white;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    margin-right: 0;
}

@media (max-width: 768px) {
    .stat-value {
        font-size: 20px; /* valores más grandes */
        margin-right: 0;
    }
}

.stat-label {
    color: rgba(255, 255, 255, 0.7);
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

@media (max-width: 768px) {
    .stat-label {
        font-size: 12px;
    }
}

.stat-divider {
    width: 1px;
    height: 50px;
    background: rgba(255, 255, 255, 0.2);
}

@media (max-width: 768px) {
    .stat-divider {
        height: 28px;
    }
}

/* AI Message - contenido del widget */
.ai-message {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0;
    width: 100%;
    justify-content: flex-start;
    grid-row: 4;
}

@media (max-width: 768px) {
    .ai-message {
        gap: 12px;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start; /* alinear a la izquierda para alinear con GM/estrella */
        width: 100%;
        grid-row: 4;
        min-width: 0;
        max-width: 100%;
        overflow: visible; /* permitir que el bocadillo sobresalga ligeramente */
        text-align: left;
    }
}

.ai-icon {
    font-size: 20px;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .ai-icon {
        font-size: 28px; /* igual que los otros emojis */
        width: 32px;
        min-width: 32px;
        text-align: center;
        height: 32px;
        line-height: 32px; /* asegurar centro vertical del emoji */
    }
}

.ai-text {
    color: rgba(255, 255, 255, 0.85);
    font-size: 11px;
    font-weight: 500;
    font-style: italic;
    line-height: 1.3;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    flex: 1;
    transition: opacity 0.3s ease;
}

@media (max-width: 768px) {
    .ai-text {
        display: inline-block; /* bubble */
        position: relative;
        font-size: 11px;
        line-height: 1.25;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        max-width: 100%;
        background: rgba(255, 255, 255, 0.04);
        border: 1px solid rgba(255, 255, 255, 0.12);
        border-radius: 12px;
        padding: 6px 10px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.18);
    }
    /* Bocadillo: borde */
    .ai-text::before {
        content: '';
        position: absolute;
        left: -4px; /* separa ligeramente el triángulo del emoji */
        top: 50%;
        transform: translateY(-50%);
        width: 0; height: 0;
        border-style: solid;
        border-width: 8px;
        border-color: transparent transparent transparent rgba(255, 255, 255, 0.12);
        pointer-events: none;
    }
    /* Bocadillo: relleno */
    .ai-text::after {
        content: '';
        position: absolute;
        left: -3px; /* relleno acompaña la separación */
        top: 50%;
        transform: translateY(-50%);
        width: 0; height: 0;
        border-style: solid;
        border-width: 7px;
        border-color: transparent transparent transparent rgba(255, 255, 255, 0.04);
        pointer-events: none;
    }
}


/* Grid de aplicaciones */
.apps-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 15px;
    padding: 80px 20px 30px;
    height: 100%;
    overflow: hidden;
    align-content: space-evenly;
    position: relative;
}

@media (max-width: 768px) {
    .apps-grid {
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(6, 1fr);
        gap: 10px;
        padding: 40px 15px 80px;
        align-content: center;
    }
}

/* Ajustes para diferentes alturas de pantalla en móvil */
@media (max-width: 768px) and (min-height: 800px) {
    .apps-grid {
        padding: 60px 15px 100px;
        gap: 15px;
    }
}

@media (max-width: 768px) and (min-height: 900px) {
    .apps-grid {
        padding: 80px 15px 120px;
        gap: 20px;
    }
}

/* Para PWA en pantalla completa (más altura disponible) */
@media (max-width: 768px) and (display-mode: standalone) {
    .apps-grid {
        padding: 50px 15px 30px;
        gap: 14px;
        align-content: space-evenly;
    }
}

@media (max-width: 768px) and (display-mode: standalone) and (min-height: 800px) {
    .apps-grid {
        padding: 70px 15px 40px;
        gap: 20px;
    }
}

@media (max-width: 768px) and (display-mode: standalone) and (min-height: 900px) {
    .apps-grid {
        padding: 90px 15px 50px;
        gap: 24px;
    }
}

/* Dock background */
.apps-grid::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 0;
    background: transparent;
    pointer-events: none;
    z-index: 0;
    display: none;
}



/* Iconos de aplicaciones */
.app-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    max-width: 80px;
    max-height: 80px;
    margin: 0 auto;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    z-index: 1;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

/* Dock apps - última fila con transparencia especial */
.app-icon.dock-app {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    align-self: center;
    justify-self: center;
    /* Forzar fila del dock en desktop (fila 4) */
    grid-row: 4 / 5;
}

@media (max-width: 768px) {
    /* Forzar fila del dock en móvil (fila 6) */
    .app-icon.dock-app {
        grid-row: 6 / 7;
    }
}

.app-icon:hover {
    transform: scale(1.05);
    background: rgba(0, 0, 0, 0.8);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.app-icon:active {
    transform: scale(0.95);
}

.app-icon .icon {
    font-size: 40px;
    margin-bottom: 5px;
}

.app-icon .name {
    font-size: 12px;
    color: white;
    text-align: center;
    font-weight: 500;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Contenedor de juegos */
.game-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a1a1a 0%, #0a0a0a 100%);
    z-index: 200;
    display: none;
    border: 1px solid rgba(76, 175, 80, 0.2);
}

/* Modo escritorio - forzar centrado */
@media (min-width: 768px) {
    .game-container {
        position: fixed !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        width: auto !important;
        max-width: 600px !important;
        height: 70vh !important;
        max-height: 70vh !important;
        z-index: 1000 !important;
        border: 1px solid rgba(76, 175, 80, 0.3);
    }
}

.game-container.active {
    display: block;
}

/* Header del juego */
.game-header {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 201;
}

.close-game {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.close-game:hover {
    background: rgba(0, 0, 0, 0.9);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

/* Contenido del juego */
.game-content {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: stretch;
    justify-content: center;
    background: transparent;
    position: relative;
    overflow: hidden;
}

/* Estilos adicionales para escritorio */
@media (min-width: 768px) {
    .game-container.active {
        display: block;
    }

    .game-content {
        border-radius: 0;
    }

    .game-container {
        border-radius: 0;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    }
}

/* Animaciones */
@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.game-container.active {
    animation: slideUp 0.3s ease forwards;
}

/* Scrollbar personalizado */
.apps-grid::-webkit-scrollbar {
    width: 0;
}
