/**
 * Mobile-Responsive Utility CSS
 * Add this to any project that needs better mobile optimization
 */

/* Base mobile-first styles */
* {
    box-sizing: border-box;
}

body {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Touch-friendly interactive elements */
button,
input[type="button"],
input[type="submit"],
input[type="range"],
select,
.btn,
.clickable {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
}

/* Prevent text overflow on small screens */
h1, h2, h3, h4, h5, h6, p {
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* Responsive images and canvases */
img, canvas {
    max-width: 100%;
    height: auto;
}

/* Mobile: Portrait phones (< 600px) */
@media (max-width: 599px) {
    body {
        font-size: 14px;
        line-height: 1.5;
    }

    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1.25rem;
    }

    /* Stack layout vertically */
    .container {
        padding: 10px !important;
        margin: 0 !important;
    }

    .main-layout,
    .controls,
    .left-panel,
    .right-panel {
        flex-direction: column !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 10px !important;
    }

    /* Full-width buttons */
    button,
    .btn {
        width: 100%;
        margin: 5px 0 !important;
        padding: 12px !important;
        font-size: 16px;
    }

    .button-group {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
    }

    /* Control groups */
    .control-group {
        width: 100% !important;
        margin: 10px 0 !important;
        padding: 10px !important;
    }

    /* Sliders and inputs */
    input[type="range"] {
        width: 100% !important;
        margin: 10px 0 !important;
    }

    input[type="text"],
    input[type="number"],
    select {
        width: 100% !important;
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 12px;
    }

    /* Canvas adjustments */
    canvas {
        width: 100% !important;
        height: auto !important;
        max-height: 400px !important;
        touch-action: pan-y pinch-zoom;
    }

    /* Stats and info boxes */
    .stats,
    .info,
    .legend {
        font-size: 12px !important;
        padding: 8px !important;
        margin: 10px 0 !important;
    }

    .stat-item {
        display: flex;
        justify-content: space-between;
        padding: 5px 0;
    }

    /* Hide non-essential elements on very small screens */
    .desktop-only {
        display: none !important;
    }

    /* Adjust spacing */
    .section {
        margin: 15px 0 !important;
        padding: 15px !important;
    }

    /* Back button adjustments */
    .back-to-projects {
        position: static !important;
        display: block;
        width: 100%;
        text-align: center;
        margin: 10px 0 !important;
    }
}

/* Mobile: Landscape phones (600px - 767px) */
@media (min-width: 600px) and (max-width: 767px) {
    body {
        font-size: 15px;
    }

    .container {
        padding: 15px;
    }

    canvas {
        max-height: 500px;
    }

    button,
    .btn {
        min-width: 120px;
    }
}

/* Tablet: Portrait (768px - 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
    body {
        font-size: 16px;
    }

    .container {
        padding: 20px;
    }

    .main-layout {
        flex-direction: column;
    }

    .left-panel,
    .right-panel {
        width: 100% !important;
    }

    canvas {
        max-height: 600px;
    }
}

/* Tablet: Landscape (1024px - 1365px) */
@media (min-width: 1024px) and (max-width: 1365px) {
    .container {
        max-width: 960px;
        margin: 0 auto;
        padding: 25px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    button,
    input,
    select,
    a {
        padding: 12px !important;
        margin: 5px !important;
    }

    /* Remove hover effects */
    *:hover {
        transition: none !important;
    }

    /* Disable pointer events for decorative elements */
    .decoration,
    .background-element {
        pointer-events: none;
    }
}

/* Accessibility: Reduce motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    button,
    .btn {
        border: 2px solid currentColor !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    body {
        background-color: #1a1a1a;
        color: #e0e0e0;
    }

    button,
    .btn {
        background-color: #2a2a2a;
        color: #e0e0e0;
        border: 1px solid #444;
    }

    input,
    select {
        background-color: #2a2a2a;
        color: #e0e0e0;
        border: 1px solid #444;
    }
}

/* Landscape orientation */
@media (orientation: landscape) and (max-height: 600px) {
    .container {
        padding: 10px;
    }

    h1 {
        font-size: 1.5rem;
    }

    canvas {
        max-height: 350px;
    }

    .controls {
        max-height: 350px;
        overflow-y: auto;
    }
}

/* iOS-specific fixes */
@supports (-webkit-touch-callout: none) {
    /* Prevent rubber-band scrolling */
    body {
        overscroll-behavior: none;
    }

    /* Fix iOS input zoom */
    input,
    select,
    textarea {
        font-size: 16px;
    }

    /* Fix iOS button styles */
    button,
    input[type="submit"],
    input[type="button"] {
        -webkit-appearance: none;
        border-radius: 0;
    }
}

/* Android-specific fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) and (min-resolution: 0.001dpcm) {
    select {
        background-image: none;
    }
}

/* Print styles (hide interactive elements) */
@media print {
    .controls,
    .button-group,
    button,
    .back-to-projects {
        display: none !important;
    }

    canvas {
        page-break-inside: avoid;
    }
}
