/* ===================================
   Mobile-First Responsive Styles
   Touch-Optimized Interactions
   =================================== */

/* Mobile Devices (Default - 320px and up) */

/* Touch Optimization */
@media (hover: none) and (pointer: coarse) {

    /* Larger touch targets */
    .btn,
    .shape-btn,
    .object-item,
    .view-btn {
        min-height: 48px;
    }

    .btn-icon {
        min-width: 48px;
        min-height: 48px;
    }

    /* Remove hover effects on touch devices */
    .btn:hover,
    .shape-btn:hover,
    .object-item:hover {
        transform: none;
    }

    /* Active states for touch feedback */
    .btn:active {
        transform: scale(0.95);
    }
}

/* Small Mobile (up to 480px) */
@media (max-width: 480px) {

    /* Toolbar adjustments */
    .toolbar {
        padding: var(--spacing-xs) var(--spacing-sm);
    }

    .app-title {
        font-size: 1rem;
    }

    .toolbar-center {
        order: 3;
        flex-basis: 100%;
        margin-top: var(--spacing-xs);
    }

    /* Collapsible panels */
    .side-panel {
        position: absolute;
        top: 0;
        bottom: 0;
        width: 85%;
        max-width: 300px;
        z-index: var(--z-panel);
        box-shadow: var(--shadow-lg);
    }

    .left-panel {
        left: 0;
        transform: translateX(-100%);
    }

    .left-panel.open {
        transform: translateX(0);
    }

    .right-panel {
        right: 0;
        transform: translateX(100%);
    }

    .right-panel.open {
        transform: translateX(0);
    }

    /* Viewport controls at bottom */
    .viewport-controls {
        bottom: var(--spacing-sm);
        left: var(--spacing-sm);
        right: var(--spacing-sm);
        transform: none;
        flex-direction: column;
        width: auto;
    }

    .view-buttons {
        width: 100%;
        justify-content: space-between;
    }

    .view-btn {
        flex: 1;
    }

    .viewport-info {
        width: 100%;
        justify-content: space-between;
    }

    /* Shape grid single column on very small screens */
    .shape-grid {
        grid-template-columns: 1fr;
    }

    /* Modal full screen on mobile */
    .modal {
        padding: 0;
    }

    .modal-content {
        max-width: 100%;
        max-height: 100%;
        height: 100%;
        border-radius: 0;
    }

    /* Project grid single column */
    .project-grid {
        grid-template-columns: 1fr;
    }

    /* Toast notifications */
    .toast-container {
        top: var(--spacing-sm);
        right: var(--spacing-sm);
        left: var(--spacing-sm);
    }

    .toast {
        max-width: 100%;
    }
}

/* Tablet Portrait (481px to 768px) */
@media (min-width: 481px) and (max-width: 768px) {
    .side-panel {
        width: 300px;
    }

    .shape-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .project-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Panels can be toggled */
    .left-panel.collapsed {
        transform: translateX(-100%);
    }

    .right-panel.collapsed {
        transform: translateX(100%);
    }
}

/* Tablet Landscape & Small Desktop (769px to 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .side-panel {
        width: 280px;
    }

    .shape-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .project-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Desktop (1025px and up) */
@media (min-width: 1025px) {
    .side-panel {
        width: 320px;
    }

    .shape-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .project-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    /* Show tooltips on desktop */
    [title]:hover::after {
        content: attr(title);
        position: absolute;
        bottom: 100%;
        left: 50%;
        transform: translateX(-50%);
        padding: var(--spacing-xs) var(--spacing-sm);
        background: var(--bg-overlay);
        color: var(--text-primary);
        font-size: 0.75rem;
        white-space: nowrap;
        border-radius: var(--border-radius-sm);
        margin-bottom: var(--spacing-xs);
        pointer-events: none;
        z-index: 1000;
    }
}

/* Large Desktop (1440px and up) */
@media (min-width: 1440px) {
    .side-panel {
        width: 360px;
    }

    .shape-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Panel Overlay for Mobile */
.panel-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-overlay);
    z-index: calc(var(--z-panel) - 1);
    opacity: 0;
    transition: opacity var(--transition-normal);
}

@media (max-width: 768px) {
    .panel-overlay.active {
        display: block;
        opacity: 1;
    }
}

/* Landscape Orientation Adjustments */
@media (max-height: 500px) and (orientation: landscape) {
    .toolbar {
        padding: var(--spacing-xs) var(--spacing-sm);
    }

    .app-title {
        display: none;
    }

    .viewport-controls {
        bottom: var(--spacing-xs);
        padding: var(--spacing-xs);
    }

    .side-panel {
        width: 240px;
    }

    .panel-content {
        padding: var(--spacing-sm);
    }
}

/* Reduced Motion Preference */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --border-color: hsl(0, 0%, 50%);
    }

    .btn,
    .shape-btn,
    .object-item {
        border: 2px solid var(--border-color);
    }
}

/* Dark Mode (System Preference) - Already default */
@media (prefers-color-scheme: dark) {
    /* Our default theme is dark, so this is already applied */
}

/* Light Mode Override (if needed in future) */
@media (prefers-color-scheme: light) {
    /* Can add light theme variables here if requested */
}

/* Print Styles */
@media print {

    .toolbar,
    .side-panel,
    .viewport-controls,
    .modal,
    .toast-container {
        display: none !important;
    }

    .viewport-container {
        width: 100%;
        height: 100vh;
    }
}

/* Touch Gestures Helper Classes */
.touch-active {
    background: var(--bg-primary) !important;
}

.no-select {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Swipe Indicators */
.swipe-indicator {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 60px;
    background: var(--color-primary);
    border-radius: 2px;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.swipe-indicator.left {
    left: 0;
}

.swipe-indicator.right {
    right: 0;
}

.swipe-indicator.active {
    opacity: 0.5;
}