/* ============================================================
   CUBROID RESPONSIVE - COMPATIBLE WITH EXISTING TEMPLATE
   Works with position: absolute layout
   ============================================================ */

/* ===================================
   CSS VARIABLES
   =================================== */
   :root {
    --mobile-header-height: 60px;
    --mobile-bottom-nav: 70px;
}

/* ===================================
   BASE - HIDE MOBILE ELEMENTS ON DESKTOP
   =================================== */
.mobile-only {
    display: none !important;
}

.tablet-only {
    display: none !important;
}

/* Desktop elements visible by default */
.hide-mobile {
    display: flex !important;
}

/* ===================================
   MOBILE (0-767px) COMPLETE OVERRIDE
   =================================== */
@media screen and (max-width: 767px) {
    
    /* ===== VISIBILITY ===== */
    .mobile-only {
        display: flex !important;
    }
    
    .hide-mobile {
        display: none !important;
    }
    
    /* ===== APP WRAPPER ===== */
    #cubroid-app-wrapper {
        position: fixed !important;
        inset: 0 !important;
        overflow: hidden !important;
    }
    
    /* ===== UI LAYER ===== */
    #ui-layer {
        position: fixed !important;
        inset: 0 !important;
    }
    
    /* ===== HEADER ===== */
    #header {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: var(--mobile-header-height) !important;
        padding: 8px 12px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        z-index: 100 !important;
        background: rgba(13,17,23,0.98) !important;
        backdrop-filter: blur(20px) !important;
    }
    
    #header h1 {
        font-size: 0.9rem !important;
        margin: 0 !important;
    }
    
    #header span {
        font-size: 0.6rem !important;
    }
    
    /* ===== PALETTE MOBILE ===== */
    #palette {
        position: fixed !important;
        left: 0 !important;
        top: var(--mobile-header-height) !important;
        bottom: var(--mobile-bottom-nav) !important;
        width: 280px !important;
        max-width: 85vw !important;
        height: auto !important;
        transform: translateX(-100%) !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        z-index: 90 !important;
        border-radius: 0 !important;
        padding: 12px !important;
        overflow-y: auto !important;
    }
    
    #palette.open {
        transform: translateX(0) !important;
    }
    
    /* Palette content scaling */
    #palette .category-title,
    #palette .category-group .category-title {
        font-size: 0.8rem !important;
        margin: 12px 0 8px 0 !important;
    }
    
    #palette .part-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
    }
    
    #palette .part-btn {
        padding: 8px 6px !important;
        min-height: 90px !important;
    }
    
    #palette .part-thumb,
    #palette .part-btn img {
        width: 55px !important;
        height: 55px !important;
    }
    
    #palette .part-name {
        font-size: 0.7rem !important;
    }
    
    #palette .qty-badge {
        min-width: 24px !important;
        height: 24px !important;
        font-size: 0.65rem !important;
        top: 4px !important;
        right: 4px !important;
    }
    
    /* ===== CANVAS ===== */
    #canvas-container {
        position: fixed !important;
        top: var(--mobile-header-height) !important;
        left: 0 !important;
        right: 0 !important;
        bottom: var(--mobile-bottom-nav) !important;
        width: 100% !important;
        height: auto !important;
    }
    
    /* ===== RIGHT TOOLS - HIDE ===== */
    #right-tools-bar {
        display: none !important;
    }
    
    /* Show tools when triggered */
    #right-tools-bar.mobile-active {
        display: block !important;
        position: fixed !important;
        right: 8px !important;
        bottom: calc(var(--mobile-bottom-nav) + 8px) !important;
        top: auto !important;
        left: auto !important;
        transform: none !important;
        z-index: 95 !important;
    }
    
    #right-tools-bar.mobile-active > div {
        flex-direction: row !important;
        padding: 6px !important;
        gap: 4px !important;
    }
    
    #right-tools-bar.mobile-active button {
        width: 38px !important;
        height: 38px !important;
        font-size: 0.85rem !important;
    }
    
    /* ===== BLOCKLY ===== */
    #blockly-container {
        position: fixed !important;
        top: var(--mobile-header-height) !important;
        left: 0 !important;
        right: 0 !important;
        bottom: var(--mobile-bottom-nav) !important;
        width: 100% !important;
        height: auto !important;
    }
    
    /* ===== PANELS ===== */
    #color-picker-panel {
        position: fixed !important;
        right: 8px !important;
        bottom: calc(var(--mobile-bottom-nav) + 8px) !important;
        top: auto !important;
        left: auto !important;
        transform: none !important;
        max-width: 280px !important;
    }
    
    #simple-control-panel {
        position: fixed !important;
        left: 50% !important;
        top: 50% !important;
        right: auto !important;
        bottom: auto !important;
        transform: translate(-50%, -50%) !important;
        max-width: 90vw !important;
        max-height: 70vh !important;
        overflow-y: auto !important;
    }
    
    /* ===== CONTROLS AREA ===== */
    #controls-area {
        position: fixed !important;
        bottom: calc(var(--mobile-bottom-nav) + 12px) !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
    }
    
    #controls-area .dpad {
        transform: scale(0.85);
    }
    
    /* ===== TOAST ===== */
    #toast {
        position: fixed !important;
        bottom: calc(var(--mobile-bottom-nav) + 12px) !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: calc(100% - 32px) !important;
        max-width: 380px !important;
    }
    
    /* ===== PRESENTATION CONTROLS ===== */
    #presentation-controls {
        bottom: calc(var(--mobile-bottom-nav) + 12px) !important;
        width: min(420px, 95vw) !important;
    }
}

/* ===================================
   MOBILE UI COMPONENTS
   =================================== */

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mobile-bottom-nav);
    background: rgba(20,25,35,0.98);
    backdrop-filter: blur(25px);
    border-top: 2px solid rgba(0,229,255,0.3);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 6px 4px;
    gap: 3px;
    z-index: 100;
    box-shadow: 0 -6px 30px rgba(0,0,0,0.5);
}

.nav-item {
    flex: 1;
    max-width: 72px;
    height: 52px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
    transition: all 0.2s;
    padding: 3px;
    -webkit-tap-highlight-color: transparent;
}

.nav-item:active {
    transform: scale(0.92);
    background: rgba(0,229,255,0.1);
}

.nav-item.active {
    background: linear-gradient(135deg, #00e5ff, #00b4d8);
    color: #000;
    border-color: #00e5ff;
    box-shadow: 0 0 18px rgba(0,229,255,0.6);
}

.nav-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.nav-label {
    font-size: 0.62rem;
    font-weight: 700;
    text-align: center;
    line-height: 1;
    text-transform: uppercase;
}

/* FAB Button */
.fab {
    position: fixed;
    bottom: calc(var(--mobile-bottom-nav) + 10px);
    right: 14px;
    z-index: 95;
}

.fab-main {
    width: 52px;
    height: 52px;
    background: linear-gradient(135deg, #00e5ff, #9C27B0);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 1.8rem;
    font-weight: 300;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0,229,255,0.5);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.fab-main:active {
    transform: scale(0.88) rotate(90deg);
}

/* Overlay */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    z-index: 85;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.overlay.active {
    display: block;
    animation: fadeIn 0.2s ease-out;
}

/* Hamburger */
.hamburger {
    width: 40px;
    height: 40px;
    background: rgba(0,229,255,0.12);
    border: 2px solid rgba(0,229,255,0.4);
    border-radius: 8px;
    color: #00e5ff;
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.hamburger:active {
    transform: scale(0.9);
    background: rgba(0,229,255,0.2);
    border-color: #00e5ff;
}

/* ===================================
   TABLET (768-1023px)
   =================================== */
@media screen and (min-width: 768px) and (max-width: 1023px) {
    
    .tablet-only {
        display: block !important;
    }
    
    /* Header compact */
    #header {
        padding: 12px 18px !important;
    }
    
    #header h1 {
        font-size: 1.1rem !important;
    }
    
    .btn {
        padding: 7px 11px !important;
        font-size: 0.8rem !important;
    }
    
    /* Mini sidebar with hover */
    #palette {
        width: 68px !important;
        transition: width 0.3s ease, padding 0.3s ease !important;
        padding: 14px 6px !important;
    }
    
    #palette:hover {
        width: 300px !important;
        padding: 20px 16px !important;
    }
    
    /* Hide text when mini */
    #palette:not(:hover) .category-title {
        font-size: 0 !important;
        margin: 8px 0 !important;
        height: 3px;
        overflow: hidden;
    }
    
    #palette:not(:hover) .part-grid {
        grid-template-columns: 1fr !important;
    }
    
    #palette:not(:hover) .part-name {
        font-size: 0.65rem !important;
    }
    
    #palette:not(:hover) .qty-badge {
        position: static !important;
        margin-top: 4px !important;
    }
    
    /* Right tools compact */
    #right-tools-bar button {
        width: 36px !important;
        height: 36px !important;
    }
}

/* ===================================
   TOUCH OPTIMIZATIONS
   =================================== */
@media (hover: none) and (pointer: coarse) {
    
    /* Larger tap targets */
    .btn,
    .part-btn,
    .nav-item,
    button {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Touch feedback */
    .btn:active,
    .part-btn:active {
        transform: scale(0.96);
        opacity: 0.88;
    }
    
    /* Remove hover states */
    .btn:hover,
    .part-btn:hover {
        transform: none;
    }
}

/* ===================================
   ANIMATIONS
   =================================== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ===================================
   PERFORMANCE
   =================================== */
#palette,
#right-tools-bar,
.bottom-nav,
.overlay,
.fab,
.hamburger {
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===================================
   SAFE AREA (iPhone notch)
   =================================== */
@supports (padding: env(safe-area-inset-bottom)) {
    @media (max-width: 767px) {
        .bottom-nav {
            padding-bottom: calc(6px + env(safe-area-inset-bottom));
            height: calc(var(--mobile-bottom-nav) + env(safe-area-inset-bottom));
        }
        
        #palette {
            bottom: calc(var(--mobile-bottom-nav) + env(safe-area-inset-bottom)) !important;
        }
        
        .fab {
            bottom: calc(var(--mobile-bottom-nav) + 10px + env(safe-area-inset-bottom));
        }
    }
}

/* ===================================
   UTILITY CLASSES
   =================================== */
.no-scroll {
    overflow: hidden !important;
}

.mobile-visible {
    display: block !important;
}

@media (max-width: 767px) {
    .mobile-visible {
        display: flex !important;
    }
}