* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html {
    background: radial-gradient(circle at 50% 20%, #101016 0%, #08080c 55%, #050507 100%);
}
body {
    background-color: #08080c;
    color: #e0e0e0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, monospace;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    height: 100vh;
    height: 100dvh; /* evita saltos por la barra de navegación del navegador móvil */
    max-height: 100vh;
    max-height: 100dvh;
    overflow: hidden;
    padding-top: env(safe-area-inset-top);
}

/* Encabezado */
header {
    width: 100%;
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
    text-align: center;
    background: rgba(12, 12, 18, 0.9);
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
}
h1 {
    font-size: 1.1rem;
    letter-spacing: 2px;
    color: #ffffff;
    text-transform: uppercase;
}

/* Visor de Cámara Principal */
.viewport {
    flex: 1;
    width: 100%;
    max-width: 500px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: #000000;
    border-radius: 12px;
    overflow: hidden;
    margin: 5px 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 25px rgba(0,0,0,0.9);
}

#asciiCanvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000000;
}

/* Selector de Modos (FOTO / VIDEO) */
.mode-selector {
    display: flex;
    gap: 20px;
    margin-bottom: 8px;
    z-index: 5;
}
.mode-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.4);
    font-size: 0.85rem;
    font-weight: bold;
    letter-spacing: 1px;
    cursor: pointer;
    padding: 5px 10px;
    transition: all 0.3s;
}
.mode-btn.active {
    color: #ff3b30;
    text-shadow: 0 0 8px rgba(255,59,48,0.6);
}

/* Barra de Control */
.camera-controls {
    width: 100%;
    max-width: 500px;
    background: rgba(18, 18, 24, 0.85);
    backdrop-filter: blur(15px);
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 18px 30px;
    padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 10;
}

/* Botones secundarios circulares */
.icon-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #fff;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    backdrop-filter: blur(5px);
    transition: transform 0.2s, background 0.2s;
}
.icon-btn:active { transform: scale(0.9); }

/* Botón de Disparo 3D Transparente */
.shutter-outer {
    width: 75px;
    height: 75px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 3px solid rgba(255, 255, 255, 0.85);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.6), inset 0 0 15px rgba(255,255,255,0.25);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}
.shutter-inner {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: inset 0 -3px 6px rgba(0,0,0,0.3);
    transition: all 0.3s ease;
}

/* Estado en Modo Video */
.video-mode .shutter-inner {
    background: #ff3b30;
    box-shadow: inset 0 -3px 6px rgba(0,0,0,0.5);
}
.recording .shutter-inner {
    border-radius: 12px;
    transform: scale(0.6);
    animation: pulse-rec 1.2s infinite alternate;
}

@keyframes pulse-rec {
    from { opacity: 1; }
    to { opacity: 0.4; }
}

/* Visor Multimedia / Galería Rediseñado */
.viewer-container {
    position: fixed;
    inset: 0;
    background: #08080c;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.1, 0.9, 0.2, 1);
}
.viewer-container.open { transform: translateY(0); }

.viewer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    width: 100%;
    box-sizing: border-box;
    background: rgba(12, 12, 18, 0.9);
    z-index: 10;
}

.dropdown-menu { position: relative; }

.dropdown-content {
    position: absolute;
    right: 0;
    top: 48px;
    background: #181822;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 8px 20px rgba(0,0,0,0.7);
    display: flex;
    flex-direction: column;
    width: 140px;
    z-index: 20;
}

.dropdown-content button {
    padding: 12px 16px;
    background: none;
    border: none;
    color: #fff;
    text-align: left;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}
.dropdown-content button:active { background: rgba(255,255,255,0.1); }
.dropdown-content button.danger { color: #ff453a; }

.media-display-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}

.full-media-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

/* Contenedor alternativo para vídeos */
.video-placeholder {
    text-align: center;
    color: #ccc;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.video-icon { font-size: 3.5rem; margin-bottom: 12px; }
.notice-text { font-size: 1rem; font-weight: 500; color: #aaa; }

/* Modal de Ajustes */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: #14141c;
    color: #fff;
    padding: 24px;
    border-radius: 14px;
    width: 85%;
    max-width: 380px;
    border: 1px solid rgba(255,255,255,0.12);
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.modal-header h2 { font-size: 1.1rem; letter-spacing: 1px; }

.close-btn {
    background: none;
    border: none;
    color: #aaa;
    font-size: 1.5rem;
    cursor: pointer;
}

.social-links {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.social-btn {
    background: rgba(255,255,255,0.06);
    color: #58a6ff;
    text-decoration: none;
    padding: 12px;
    text-align: center;
    border-radius: 8px;
    font-weight: 500;
    border: 1px solid rgba(255,255,255,0.08);
    transition: background 0.2s;
}
.social-btn:active { background: rgba(255,255,255,0.12); }

.divider {
    border: none;
    height: 1px;
    background: rgba(255,255,255,0.1);
    margin: 16px 0;
}

.custom-info {
    font-size: 0.85rem;
    color: #aaa;
    line-height: 1.4;
    margin-bottom: 20px;
    text-align: center;
}

.credits {
    text-align: center;
    opacity: 0.7;
    font-size: 0.8rem;
    letter-spacing: 1px;
}

.hidden { display: none !important; }
video#videoStream { display: none; }

/* Overlay de permiso de cámara (pantalla de activación / error) */
.camera-perm-overlay {
    position: absolute;
    inset: 0;
    background: rgba(8, 8, 12, 0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    z-index: 6;
    gap: 16px;
}
.camera-perm-overlay p {
    color: #ccc;
    font-size: 0.9rem;
    line-height: 1.4;
    max-width: 320px;
}
.activar-btn {
    background: #ff3b30;
    color: #fff;
    border: none;
    padding: 12px 24px;
    border-radius: 24px;
    font-weight: bold;
    letter-spacing: 0.5px;
    cursor: pointer;
}
.activar-btn:active { transform: scale(0.96); }

/* ==========================================================================
   MÓVIL EN HORIZONTAL
   Evita que la interfaz se aplaste cuando el teléfono se gira.
   ========================================================================== */
@media (orientation: landscape) and (max-height: 500px) {
    body {
        display: grid;
        grid-template-columns: 1fr 200px;
        grid-template-rows: auto 1fr auto;
        grid-template-areas:
            "header header"
            "viewport modeselector"
            "viewport controls";
        padding-top: env(safe-area-inset-top);
    }
    header { grid-area: header; }
    .viewport {
        grid-area: viewport;
        max-width: none;
        height: auto;
        margin: 6px;
    }
    .mode-selector {
        grid-area: modeselector;
        flex-direction: column;
        justify-content: center;
        margin: 0;
        gap: 10px;
        padding: 0 14px;
    }
    .camera-controls {
        grid-area: controls;
        max-width: none;
        flex-direction: column;
        border-top: none;
        border-left: 1px solid rgba(255,255,255,0.1);
        padding: 12px calc(16px + env(safe-area-inset-right, 0px)) 12px 16px;
        gap: 14px;
    }
}

/* ==========================================================================
   ESCRITORIO / PC
   Panel de control tipo visor profesional: viewfinder + consola lateral.
   No reutiliza el layout móvil apilado; es una composición propia.
   ========================================================================== */
@media (min-width: 900px) {
    body {
        display: grid;
        grid-template-columns: 1fr 300px;
        grid-template-rows: auto 1fr auto;
        grid-template-areas:
            "header    header"
            "viewport  sidebar-top"
            "viewport  sidebar-bottom";
        width: 100%;
        max-width: 1180px;
        height: 92vh;
        max-height: 860px;
        margin: 4vh auto;
        border-radius: 16px;
        border: 1px solid rgba(255,255,255,0.08);
        box-shadow: 0 40px 100px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.02);
        overflow: hidden;
        padding-top: 0;
    }

    /* Encabezado con indicador "en vivo" */
    header {
        grid-area: header;
        padding: 18px 30px;
        background: rgba(14, 14, 20, 0.9);
        border-bottom: 1px solid rgba(255,255,255,0.08);
    }
    h1 {
        font-size: 1.15rem;
        letter-spacing: 4px;
        display: flex;
        align-items: center;
        gap: 10px;
    }
    h1::before {
        content: "";
        width: 8px;
        height: 8px;
        flex-shrink: 0;
        border-radius: 50%;
        background: #ff3b30;
        box-shadow: 0 0 8px 2px rgba(255,59,48,0.7);
        animation: pulse-rec 1.4s infinite alternate;
    }
    header .icon-btn:hover { background: rgba(255,255,255,0.16); }

    /* Visor principal con reticula tipo cámara profesional */
    .viewport {
        grid-area: viewport;
        max-width: none;
        margin: 28px 0 28px 28px;
        border-radius: 6px;
    }
    .viewport::before,
    .viewport::after {
        content: "";
        position: absolute;
        width: 26px;
        height: 26px;
        border: 2px solid rgba(255, 59, 48, 0.55);
        z-index: 4;
        pointer-events: none;
    }
    .viewport::before {
        top: 12px;
        left: 12px;
        border-right: none;
        border-bottom: none;
    }
    .viewport::after {
        bottom: 12px;
        right: 12px;
        border-left: none;
        border-top: none;
    }

    /* Consola lateral: MODO */
    .mode-selector {
        grid-area: sidebar-top;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        gap: 8px;
        margin: 30px 28px 0 20px;
        padding-top: 22px;
        position: relative;
    }
    .mode-selector::before {
        content: "MODO";
        position: absolute;
        top: 0;
        left: 4px;
        font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
        font-size: 0.68rem;
        letter-spacing: 3px;
        color: rgba(255,255,255,0.35);
    }
    .mode-btn {
        text-align: left;
        padding: 10px 14px;
        border-radius: 8px;
        background: rgba(255,255,255,0.04);
        border: 1px solid rgba(255,255,255,0.08);
    }
    .mode-btn.active {
        background: rgba(255,59,48,0.12);
        border-color: rgba(255,59,48,0.4);
    }
    .mode-btn:hover { background: rgba(255,255,255,0.09); }

    /* Consola lateral: CAPTURA (dock vertical) */
    .camera-controls {
        grid-area: sidebar-bottom;
        max-width: none;
        flex-direction: column;
        gap: 20px;
        margin: 14px 28px 28px 20px;
        padding: 40px 16px 20px;
        border-top: 1px solid rgba(255,255,255,0.1);
        border-radius: 14px;
        background: rgba(18, 18, 24, 0.5);
        position: relative;
    }
    .camera-controls::before {
        content: "CAPTURA";
        position: absolute;
        top: 16px;
        left: 16px;
        font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
        font-size: 0.68rem;
        letter-spacing: 3px;
        color: rgba(255,255,255,0.35);
    }
    .icon-btn:hover { background: rgba(255,255,255,0.16); }
    .shutter-outer:hover {
        transform: scale(1.05);
        border-color: #ffffff;
        box-shadow: 0 8px 30px rgba(0,0,0,0.7), inset 0 0 15px rgba(255,255,255,0.35);
    }

    /* Galería en formato "reproductor" centrado */
    .media-display-area {
        max-width: 900px;
        max-height: 80vh;
        margin: 24px auto;
        border-radius: 14px;
        border: 1px solid rgba(255,255,255,0.1);
        background: #000;
    }
}
