* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

a:focus-visible,
button:focus-visible {
    outline: 3px solid #4CAF50;
    outline-offset: 2px;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: system-ui, -apple-system, sans-serif;
    position: fixed;
    -webkit-overflow-scrolling: touch;
}

/* Force video to be visible and behind everything */
video {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    object-fit: cover !important;
    z-index: -2 !important;
    display: block !important;
}

a-scene {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    display: block !important;
    width: 100vw !important;
    height: 100vh !important;
}

/* Canvas de A-Frame */
canvas {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
}

#loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    color: white;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

#back-btn {
    position: fixed;
    top: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    z-index: 300;
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    gap: 5px;
}

#back-btn:active {
    transform: scale(0.95);
}

#info-panel {
    position: fixed;
    bottom: 130px;
    left: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    color: white;
    padding: 15px;
    border-radius: 12px;
    max-width: 350px;
    display: none;
    z-index: 100;
    font-size: 0.9rem;
}

#info-panel h3 {
    margin: 0 0 5px 0;
    font-size: 1.2rem;
}

#info-panel p {
    margin: 0 0 8px 0;
    opacity: 0.8;
    font-style: italic;
    font-size: 0.85rem;
}

#info-panel #animal-details {
    font-size: 0.8rem;
}

#info-panel #animal-details p {
    margin: 3px 0;
    font-size: 0.8rem;
}

#gps-status {
    position: fixed;
    top: 70px;
    left: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 15px;
    border-radius: 10px;
    z-index: 100;
}

#gps-status p {
    margin: 5px 0;
}

/* Controles de cámara tipo app móvil */
#camera-controls {
    position: fixed;
    bottom: 30px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
    z-index: 200;
    padding: 0 20px;
}

/* Botón de captura principal (circular grande) */
#capture-btn {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: white;
    border: 5px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    position: relative;
    transition: transform 0.1s, background 0.1s;
}

#capture-btn:active {
    transform: scale(0.9);
    background: rgba(255, 255, 255, 0.7);
}

#capture-btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: white;
}

/* Botón de captura de modelo */
#capture-model-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(76, 175, 80, 0.9);
    border: 3px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    position: relative;
    transition: transform 0.1s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

#capture-model-btn::before {
    content: '🦌';
    filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.5));
}

#capture-model-btn:active {
    transform: scale(0.9);
}

#capture-model-btn.captured {
    background: rgba(244, 67, 54, 0.9);
}

#capture-model-btn.captured::before {
    content: '✕';
    color: white;
}

/* Botón de galería (miniaturas) */
#gallery-btn {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.3);
    border: 2px solid white;
    cursor: pointer;
    overflow: hidden;
    position: relative;
    backdrop-filter: blur(10px);
}

#gallery-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#gallery-btn::before {
    content: '📷';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
}

/* Botón de diario de campo */
#field-journal-btn {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    background: rgba(139, 69, 19, 0.8);
    border: 2px solid rgba(255, 255, 255, 0.8);
    cursor: pointer;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    transition: transform 0.2s, background 0.2s;
    position: relative;
}

#field-journal-btn:active {
    transform: scale(0.9);
    background: rgba(139, 69, 19, 1);
}

#field-journal-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: rgba(220, 53, 69, 0.95);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 11px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease;
}

/* Modal de vista de foto */
#photo-preview {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: none;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 20px;
}

#photo-preview-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    flex: 1;
}

#photo-preview img {
    max-width: 100%;
    max-height: 70vh;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

#photo-counter {
    color: white;
    font-size: 14px;
    margin-top: 10px;
    opacity: 0.8;
}

#prev-photo-btn,
#next-photo-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 32px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.2s;
    margin: 0 10px;
}

#prev-photo-btn:active,
#next-photo-btn:active {
    transform: scale(0.9);
    background: rgba(255, 255, 255, 0.3);
}

#prev-photo-btn:disabled,
#next-photo-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

#photo-preview-actions {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 15px;
}

#photo-preview-actions button {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: transform 0.2s;
}

#photo-preview-actions button:active {
    transform: scale(0.95);
}

#download-btn {
    background: rgba(76, 175, 80, 0.9);
    color: white;
}

#share-btn {
    background: rgba(33, 150, 243, 0.9);
    color: white;
}

#close-preview-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

/* Flash de captura */
#capture-flash {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    opacity: 0;
    pointer-events: none;
    z-index: 1500;
    transition: opacity 0.15s;
}

#capture-flash.flash {
    opacity: 0.8;
}

/* Galería de fotos */
#photo-gallery {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: none;
    flex-direction: column;
    z-index: 2000;
    overflow-y: auto;
}

#photo-gallery-header {
    padding: 20px;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
}

#photo-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    padding: 20px;
}

.gallery-photo-item {
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s;
}

.gallery-photo-item:active {
    transform: scale(0.95);
}

.gallery-photo-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Diario de campo */
#field-journal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(20, 20, 20, 0.98);
    display: none;
    flex-direction: column;
    z-index: 2000;
    overflow: hidden;
}

#field-journal-header {
    padding: 20px;
    background: rgba(139, 69, 19, 0.9);
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
}

#field-journal-header h2 {
    margin: 0;
    font-size: 1.4rem;
}

#field-journal-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

#field-journal-map,
#field-journal-animals {
    background: rgba(40, 40, 40, 0.8);
    border-radius: 12px;
    padding: 20px;
    backdrop-filter: blur(10px);
}

#field-journal-map h3,
#field-journal-animals h3 {
    color: white;
    margin: 0 0 15px 0;
    font-size: 1.1rem;
    border-bottom: 2px solid rgba(139, 69, 19, 0.6);
    padding-bottom: 10px;
}

#map-image {
    width: 100%;
    height: auto;
    max-height: 60vh;
    object-fit: contain;
    border-radius: 8px;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

#map-placeholder {
    width: 100%;
    height: 300px;
    background: rgba(60, 60, 60, 0.5);
    border-radius: 8px;
    border: 2px dashed rgba(255, 255, 255, 0.3);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.6);
    font-size: 14px;
}

#map-placeholder p {
    font-size: 64px;
    margin: 0 0 10px 0;
}

#animals-progress {
    background: rgba(60, 60, 60, 0.6);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    color: white;
    text-align: center;
    font-size: 1.1rem;
}

#animals-progress .progress-bar {
    width: 100%;
    height: 20px;
    background: rgba(40, 40, 40, 0.8);
    border-radius: 10px;
    overflow: hidden;
    margin-top: 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

#animals-progress .progress-fill {
    height: 100%;
    background: linear-gradient(90deg, rgba(139, 69, 19, 0.8), rgba(205, 133, 63, 0.8));
    transition: width 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    color: white;
}

#animals-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 15px;
}

.animal-item {
    aspect-ratio: 1;
    background: rgba(60, 60, 60, 0.6);
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

.animal-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.animal-item.locked {
    opacity: 0.4;
    cursor: default;
}

.animal-item.locked:hover {
    transform: none;
    box-shadow: none;
}

.animal-item.unlocked {
    border-color: rgba(139, 69, 19, 0.8);
    background: rgba(80, 80, 80, 0.8);
}

.animal-icon {
    font-size: 48px;
    margin-bottom: 8px;
    filter: grayscale(100%);
}

.animal-item.unlocked .animal-icon {
    filter: grayscale(0%);
}

.animal-silhouette {
    width: 60px;
    height: 60px;
    margin-bottom: 8px;
    object-fit: contain;
    filter: grayscale(100%) brightness(0.5);
    transition: filter 0.3s ease;
}

.animal-item.unlocked .animal-silhouette {
    filter: grayscale(0%) brightness(1);
}

.animal-name {
    color: white;
    font-size: 12px;
    text-align: center;
    font-weight: 600;
}

.animal-item.locked .animal-name {
    color: rgba(255, 255, 255, 0.4);
}

.lock-icon {
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 16px;
    opacity: 0.7;
}

/* Responsive: vista móvil */
@media (max-width: 768px) {
    #field-journal-content {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }

    #field-journal-map {
        max-height: 40vh;
    }

    #map-image {
        max-height: 30vh;
    }

    #animals-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 10px;
    }

    .animal-icon {
        font-size: 36px;
    }

    .animal-name {
        font-size: 10px;
    }
}

/* Ajustes para móvil */
@media (max-width: 768px) {
    #info-panel {
        max-width: 90%;
        left: 5%;
        right: 5%;
    }

    #camera-controls {
        bottom: 20px;
    }
}

/* Ajustes específicos para iOS/Safari */
@supports (-webkit-touch-callout: none) {
    body {
        height: -webkit-fill-available;
    }

    a-scene, video, canvas {
        height: 100vh;
        height: -webkit-fill-available;
    }
}

/* Prevenir zoom accidental en iOS */
input, button, select, textarea {
    font-size: 16px;
}

/* Ocultar barras de scroll en webkit */
::-webkit-scrollbar {
    display: none;
}

/* Asegurar que el video de la cámara no se distorsione */
video {
    object-fit: cover !important;
    object-position: center !important;
}

/* Protección contra notch en dispositivos modernos */
@supports (padding: max(0px)) {
    #back-btn {
        top: max(10px, env(safe-area-inset-top));
        left: max(10px, env(safe-area-inset-left));
    }

    #info-toggle-btn {
        top: max(10px, env(safe-area-inset-top));
        right: max(10px, env(safe-area-inset-right));
    }

    #camera-controls {
        bottom: max(30px, env(safe-area-inset-bottom));
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }

    #info-panel {
        bottom: max(130px, calc(130px + env(safe-area-inset-bottom)));
        left: max(20px, env(safe-area-inset-left));
        right: max(20px, env(safe-area-inset-right));
    }
}
