/* ============================================
   Latent App Unified Styles
   ============================================ */

/* ============================================
   Base Styles & Layout
   ============================================ */

body {
    padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

/* ============================================
   Prevent Text Selection in Interactive Areas
   ============================================ */

/* Prevent text selection in main app and viewport */
#latent-app,
#viewport-container,
#viewport-container *,
#ar-canvas,
#ar-ui-container,
#ar-ui-container *,
#camera-aspect-overlay,
#camera-aspect-overlay *,
#image-slider,
#viewport-controls,
#video-controls,
#pinned-thumbnails,
.btn-base,
.btn-primary,
.btn-secondary,
.btn-tertiary,
.btn-shoot,
.btn-sparkle,
button {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none; /* Prevents iOS callout menu on long-press */
}

/* Allow text selection in text input areas */
input[type="text"],
input[type="search"],
textarea,
.allow-select {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Fullscreen mode */
#viewport-container:fullscreen #viewport-image {
    object-fit: contain;
}

/* Scrollbar styling */
#pinned-thumbnails::-webkit-scrollbar {
    height: 6px;
}

#pinned-thumbnails::-webkit-scrollbar-track {
    background: transparent;
}

#pinned-thumbnails::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.3);
    border-radius: 3px;
}

#pinned-thumbnails::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.5);
}

/* Recording pulse animation */
@keyframes record-pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

.recording-pulse {
    animation: record-pulse 1s ease-in-out infinite;
}

/* Long press cancel animation */
@keyframes cancel-pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

.cancelling-recording {
    animation: cancel-pulse 0.8s ease-out;
}

/* ============================================
   Button Base Styles
   ============================================ */

.btn-base {
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
}

.btn-base:hover {
    transform: translateY(-1px);
}

.btn-base:active {
    transform: scale(0.95);
}

/* ============================================
   PRIMARY BUTTONS (Circular Icon Buttons)
   Mic, Pen, Drawing tools
   ============================================ */

.btn-primary {
    width: 46px;
    height: 46px;
    background: rgba(38, 38, 42, 0.7);
    border-radius: 50%;
    color: white;
    font-size: 14px;
    padding: 0;
}

.btn-primary:hover {
    background: rgba(55, 55, 60, 0.85);
}

.btn-primary:active {
    background: rgba(65, 65, 70, 0.9);
}

/* Primary button variants */
.btn-primary.recording {
    background: rgba(239, 68, 68, 0.8);
}

.btn-primary.processing {
    background: rgba(107, 114, 128, 0.5);
}

.btn-primary.active {
    background: rgba(34, 197, 94, 0.8);
}

/* ============================================
   SECONDARY BUTTONS (Viewport Controls)
   EXACT MATCH to download/bin/pin style
   ============================================ */

.btn-secondary {
    position: relative;
    width: 32px;
    height: 32px;
    background: rgba(38, 38, 42, 0.7);
    border-radius: 6px !important;
    color: white;
    cursor: pointer;
    transition: 0.2s;
    border: none;
    padding: 0;
    box-sizing: border-box;
}

.btn-secondary i {
    font-size: 14px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.btn-secondary:hover {
    background: rgba(55, 55, 60, 0.85);
}

.btn-secondary:active {
    background: rgba(65, 65, 70, 0.9);
}

/* Secondary button variants */
.btn-secondary.large {
    padding: 8px 16px;
    width: auto;
    height: auto;
    font-size: 14px;
}

/* ============================================
   TERTIARY BUTTONS (Top Bar Controls)
   New, Import, Export - Dark grey squarish background
   ============================================ */

.btn-tertiary {
    padding: 8px 16px;
    color: white;
    background: rgba(38, 38, 42, 0.7);
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    gap: 6px;
}

.btn-tertiary i {
    margin-right: 6px;
}

.btn-tertiary:hover {
    background: rgba(55, 55, 60, 0.85);
}

.btn-tertiary:active {
    background: rgba(65, 65, 70, 0.9);
}

/* ============================================
   SPECIAL BUTTONS
   ============================================ */

/* Shoot button (camera/AR capture) */
.btn-shoot {
    width: 70px;
    height: 70px;
    background: white;
    color: #000;
    border: 5px solid rgba(0, 0, 0, 0.8);
    border-radius: 50%;
    padding: 0;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn-shoot:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.btn-shoot:active {
    transform: scale(0.92);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Sparkle button (AR sparkle capture) - magical AI generation */
.btn-sparkle {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, rgba(147, 51, 234, 0.9), rgba(219, 39, 119, 0.9));
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    padding: 0;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(147, 51, 234, 0.4);
}

.btn-sparkle:hover {
    background: linear-gradient(135deg, rgba(167, 71, 254, 1), rgba(239, 59, 139, 1));
    transform: scale(1.08);
    box-shadow: 0 6px 16px rgba(147, 51, 234, 0.6);
}

.btn-sparkle:active {
    transform: scale(0.92);
    box-shadow: 0 2px 8px rgba(147, 51, 234, 0.4);
}

/* Button icon - explicitly white color for all button icons */
.btn-icon {
    color: white !important;
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.pos-absolute {
    position: absolute;
}

.pos-fixed {
    position: fixed;
}

.flex {
    display: flex;
}

.inline-flex {
    display: inline-flex;
}

.hidden {
    display: none;
}

/* ============================================
   POSITIONING CLASSES
   ============================================ */

/* Viewport button stack (left side) */
.viewport-stack-1 {
    top: 20px;
    left: 20px;
}

.viewport-stack-2 {
    top: 64px;
    left: 20px;
}

.viewport-stack-3 {
    top: 108px;
    left: 20px;
}

.viewport-stack-4 {
    top: 152px;
    left: 20px;
}

/* Top right corner (adjusted for larger voice button) */
.top-right {
    top: 20px;
    right: 84px;
}

.top-right-corner {
    top: 20px;
    right: 20px;
}

/* Bottom center (shoot button) */
.bottom-center {
    bottom: max(20px, env(safe-area-inset-bottom, 20px));
    left: 50%;
    transform: translateX(-50%);
}

/* Bottom left */
.bottom-left {
    bottom: max(20px, env(safe-area-inset-bottom, 20px));
    left: max(20px, env(safe-area-inset-left, 20px));
}

/* Bottom right */
.bottom-right {
    bottom: max(20px, env(safe-area-inset-bottom, 20px));
    right: max(20px, env(safe-area-inset-right, 20px));
}

/* Top left with safe area */
.top-left-safe {
    top: max(20px, env(safe-area-inset-top, 20px));
    left: max(20px, env(safe-area-inset-left, 20px));
}

/* Sparkle button offset from shoot (adjusted for smaller size) */
.sparkle-offset {
    bottom: calc(max(20px, env(safe-area-inset-bottom, 20px)) + 15px);
    left: 50%;
    transform: translateX(55px);
}

/* ============================================
   Z-INDEX LAYERS
   ============================================ */

.z-viewport {
    z-index: 20;
}

.z-camera {
    z-index: 25;
}

.z-ar-canvas {
    z-index: 100;
}

.z-ar-controls {
    z-index: 25;
}

.z-voice {
    z-index: 20;
}

/* AR Canvas - renders at base level */
#ar-canvas {
    z-index: 1 !important;
    pointer-events: auto !important; /* Ensure the canvas can still receive 3D taps */
}

/* AR UI Container - WebXR DOM Overlay */
/* Container MUST be transparent to clicks so you can tap 3D objects */
#ar-ui-container {
    z-index: 10;
    pointer-events: none !important; /* CRITICAL: Lets clicks pass through empty space */
}

/* Buttons MUST capture clicks and block them from passing through */
#ar-ui-container button, 
#ar-ui-container .btn-secondary,
#ar-ui-container .btn-shoot,
#ar-ui-container .btn-base {
    pointer-events: auto !important; /* CRITICAL: Re-enables clicking on buttons */
    touch-action: manipulation;      /* Removes 300ms tap delay on mobile */
    z-index: 1001;                   /* Ensure they sit visually above everything */
}

/* ============================================
   INSTRUCTIONS & HINTS
   ============================================ */

.instruction-box {
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    text-align: center;
    pointer-events: none;
}

.instruction-box.large {
    padding: 12px 24px;
    font-size: 14px;
}

/* ============================================
   MOBILE OPTIMIZATIONS
   ============================================ */

@media (max-width: 768px) {
    .btn-text {
        display: none;
    }
    
    .btn-tertiary {
        padding: 6px 10px !important;
    }
    
    /* Always show viewport controls on mobile */
    #viewport-pin-icon,
    #viewport-delete-icon,
    #viewport-download-icon,
    #fullscreen-button,
    #viewport-new-frame-button,
    #viewport-camera-button,
    #viewport-ar-button,
    #viewport-mode-button,
    #viewport-drawing-button,
    #viewport-voice-button-container {
        display: block !important;
    }
    
    /* Smaller thumbnails on mobile */
    #pinned-thumbnails {
        right: 156px !important;
    }
    
    #pinned-thumbnails > div {
        width: 70px !important;
    }
    
    /* Adjust mode dialog on mobile */
    #mode-dialog {
        max-width: calc(100vw - 40px) !important;
    }
}

/* ============================================
   PORTRAIT MODE / VERTICAL ORIENTATION
   ============================================ */

@media (orientation: portrait) {
    /* AR buttons work same as camera buttons - no special handling needed */
    
    /* Viewport container fills available space in portrait mode too */
    #viewport-container {
        width: 100% !important;
        height: auto !important;
    }
}

/* ============================================
   LANDSCAPE MODE / HORIZONTAL ORIENTATION
   ============================================ */

@media (orientation: landscape) and (max-height: 600px) {
    /* Ensure AR controls don't overflow on landscape mobile */
    #ar-ui-container > div[style*="bottom"] {
        padding: 0 10px;
        gap: 8px !important;
    }
    
    /* Make buttons slightly smaller on landscape to fit better */
    #ar-shoot-button {
        width: 60px !important;
        height: 60px !important;
    }
    
    #ar-sparkle-button {
        width: 44px !important;
        height: 44px !important;
        font-size: 18px !important;
    }
    
    #ar-voice-button-container {
        width: 40px !important;
        height: 40px !important;
    }
    
    #ar-voice-button {
        width: 40px !important;
        height: 40px !important;
    }
    
    /* Reduce safe area insets on landscape */
    #ar-ui-container {
        padding-left: max(10px, env(safe-area-inset-left, 10px));
        padding-right: max(10px, env(safe-area-inset-right, 10px));
    }
}

