/* Mobile-first layout tweaks for vertical view
   - Move UI to a bottom bar / sheet
   - Make buttons larger and touch-friendly
   - Settings panel becomes a full-width bottom sheet
   - Keep canvas full-bleed behind UI
*/

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #1a1a1a;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

#canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

/* Bottom-mounted UI container for mobile vertical */
#app-title {
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 90;
    color: #ffffff; /* White text for better contrast */
    font-weight: 900;
    font-size: 20px;
    letter-spacing: 0.6px;
    padding: 8px 16px;
    border-radius: 12px;
    pointer-events: none;

    /* Glass-panel look with subtle gradient and blur */
    background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.03));
    border: 1px solid rgba(255,255,255,0.06);
    backdrop-filter: blur(6px) saturate(120%);
    -webkit-backdrop-filter: blur(6px) saturate(120%);

    /* Decorative accent line and shadow for depth */
    box-shadow: 0 10px 30px rgba(0,0,0,0.45), 0 1px 0 rgba(255,255,255,0.02) inset;
    outline: 1px solid rgba(0,0,0,0.08);
}

/* Horizontal pan scrollbar under title (appears when zoomed) */
#h-scroll {
    pointer-events: auto;
    display: none;
}
#h-scroll-slider {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 6px;
    background: rgba(255,255,255,0.08);
    outline: none;
}
#h-scroll-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #00d4ff;
    box-shadow: 0 6px 18px rgba(0,212,255,0.12);
    border: none;
}
#h-scroll-slider::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #00d4ff;
    border: none;
}

#ui-container {
    position: fixed;
    bottom: 32px !important;
    left: 50%;
    transform: translateX(-50%);
    z-index: 30;
    width: calc(100% - 24px);
    max-width: 740px;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
}

/* Make controls stacked and easy to tap */
.controls-row {
    display: flex;
    gap: 8px;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
    background: rgba(0,0,0,0.55);
    padding: 10px;
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}

/* When space is tight, wrap to a vertical stack */
.controls-row.wrap {
    flex-direction: column;
    gap: 8px;
}

/* Larger, touch-friendly buttons */
.upload-btn, .mode-btn, .audio-btn {
    background: #ff007f;
    color: white;
    /* Unified icon-only sizing to match Original Mode button */
    padding: 0;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 700;
    box-shadow: 0 6px 18px rgba(255, 0, 127, 0.25);
    transition: transform 0.12s, background 0.12s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    min-height: 44px;
    min-width: 44px;
    font-size: 18px;
    text-transform: none;
}

.mode-btn {
    background: #444;
    box-shadow: 0 6px 18px rgba(0,0,0,0.25);
}

.audio-btn {
    background: #7a00ff;
}

.creator-btn {
    background: #007bff;
    box-shadow: 0 6px 18px rgba(0,123,255,0.25);
    appearance: none;
    padding-left: 8px;
    padding-right: 8px;
    background-image: none;
    height: 44px;
    min-width: 44px;
    font-size: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Compact music controls inside the bar */
.music-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: auto;
    /* Match visual style of the top controls bar */
    background: rgba(0,0,0,0.55);
    padding: 10px;
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}

.bpm-control {
    display: flex;
    align-items: center;
    gap: 6px;
    color: white;
    font-weight: 700;
}

/* Make the zoom slider narrower so the background picker button remains visible */
#zoom-slider {
    width: 80px;
    max-width: 120px;
    min-width: 64px; /* smaller touch-friendly minimum so adjacent button is visible */
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: #000000; /* solid black track for consistent visibility */
    border-radius: 6px;
    outline: none;
}
#zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #00d4ff;
    box-shadow: 0 6px 18px rgba(0,212,255,0.12);
    border: none;
}
#zoom-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #00d4ff;
    border: none;
}

#bpm-input {
    width: 64px;
    background: #222;
    border: 1px solid #444;
    color: white;
    padding: 6px;
    border-radius: 6px;
    text-align: center;
    font-size: 0.95rem;
    min-height: 36px;
}

/* Make play and reset icon-only buttons match the unified 44x44 controls */
#play-btn, .reset-btn {
    /* match .mode-btn / .upload-btn sizing */
    padding: 0;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    font-size: 18px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.25);
}

/* Slight visual tweaks to match their previous colors */
#play-btn {
    background: #444;
    color: white;
}

.reset-btn {
    background: #555;
    color: white;
    box-shadow: 0 6px 18px rgba(0,0,0,0.25);
}

/* Small inline buttons */
.small-btn {
    background: #333;
    color: #00d4ff;
    border: 1px solid #00d4ff;
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 0.85rem;
    cursor: pointer;
}

/* Loading state for the small detect BPM button - no text change, just color/animation */
.small-btn.loading {
    background: #00d4ff;
    color: #000;
    border-color: rgba(0,0,0,0.08);
    box-shadow: 0 6px 18px rgba(0,212,255,0.12);
    animation: bpm-pulse 900ms infinite;
}
.small-btn.loading i {
    /* slightly scale the icon while detecting */
    transform: scale(0.95);
    transition: transform 180ms;
}

@keyframes bpm-pulse {
    0% { transform: translateY(0); filter: brightness(1); }
    50% { transform: translateY(-2px); filter: brightness(1.06); }
    100% { transform: translateY(0); filter: brightness(1); }
}

.mode-btn.active {
    background: #00d4ff;
    box-shadow: 0 6px 18px rgba(0,212,255,0.18);
}

.upload-btn:hover, .mode-btn:hover {
    transform: translateY(-2px);
}

.upload-btn input {
    display: none;
}

.hint {
    display: none; /* Keep UI minimal on mobile */
}

/* SETTINGS: Make it a bottom-sheet full width on mobile */
.settings-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10001;
    background: linear-gradient(180deg, rgba(16,16,16,0.98), rgba(10,10,10,0.98));
    color: white;
    padding: 14px;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    display: none;
    flex-direction: column;
    gap: 12px;
    max-height: 78vh;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.04);
    box-shadow: 0 -12px 40px rgba(0,0,0,0.6);
}

/* Provide a drag handle */
.settings-panel::before {
    content: "";
    width: 46px;
    height: 5px;
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
    display: block;
    margin: 6px auto 0;
}

/* Scroll area inside sheet */
.settings-scroll {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-right: 6px;
    padding-bottom: 6px;
}

/* Scrollbar subtle for mobile */
.settings-scroll::-webkit-scrollbar {
    width: 6px;
}
.settings-scroll::-webkit-scrollbar-track {
    background: transparent;
}
.settings-scroll::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.06);
    border-radius: 3px;
}

/* compact groups */
.settings-group {
    background: rgba(255,255,255,0.02);
    padding: 8px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.03);
}

.settings-group > label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #00d4ff;
    display: block;
    margin-bottom: 8px;
    font-weight: 700;
}

.setting-item.mini {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
}

.setting-item.mini label {
    min-width: 48px;
    font-size: 0.8rem;
}

#setting-filter {
    background: #111;
    color: white;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 8px;
}

/* Buttons in the sheet are full-width for easier tapping */
#close-settings, .fix-btn, .delete-btn {
    width: 100%;
    min-height: 44px;
    border-radius: 10px;
    font-weight: 800;
}

/* Tweak individual button colors */
.delete-btn {
    background: #ff3b3b;
    color: white;
}

.fix-btn {
    background: #00d4ff;
    color: #000;
}

.help-btn {
    background: #00d4ff;
    color: #000;
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Modal becomes centered card but limited height for mobile */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: none;
    /* align to top so modal-content can scroll naturally on small viewports */
    align-items: flex-start;
    justify-content: center;
    z-index: 10002; /* ensure modals always sit above the app title and other UI */
    padding: 12px 12px 20px; /* small top padding and extra bottom space for finger reach */
    box-sizing: border-box;
    overflow: auto; /* enable scrolling if modal content grows beyond viewport */
    -webkit-overflow-scrolling: touch;
}

.modal-content {
    background: #141414;
    color: white;
    padding: 18px;
    border-radius: 12px;
    width: 100%;
    max-width: 600px;
    max-height: 86vh;
    overflow-y: auto;
    border: 1px solid rgba(255,255,255,0.04);
    -webkit-overflow-scrolling: touch; /* smooth native scrolling on iOS */
}

.modal-content h3 {
    margin-top: 0;
    color: #00d4ff;
}

/* Examples and code block tweaks */
.example-item code {
    display: block;
    color: #ff8fb5;
    font-family: monospace;
    font-size: 0.95rem;
    margin-bottom: 6px;
}

/* Responsive tweaks for larger screens (tablets/desktop) */
@media (min-width: 760px) {
    #ui-container {
        bottom: auto;
        top: 64px;
        left: 50%;
        transform: translateX(-50%);
        width: 90%;
        max-width: 900px;
        align-items: center;
    }
    .controls-row {
        background: transparent;
        padding: 0;
        box-shadow: none;
    }
    .creator-btn {
        padding-right: 35px;
        background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23FFFFFF%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
        height: 44px;
        min-width: 44px;
        font-size: 16px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .settings-panel {
        position: absolute;
        left: 20px;
        right: auto;
        bottom: 20px;
        width: 260px;
        max-height: 80vh;
        border-radius: 12px;
    }

    /* Background picker button / modal */
    #bg-picker-btn { background: #333; display:inline-flex; align-items:center; justify-content:center; }
    #bg-modal .modal-content { max-width: 560px; }
    #bg-preview { border-radius: 8px; background-size: cover; background-position: center center; }

    /* Show/hide blocks in modal responsively */
    #bg-solid-controls, #bg-gradient-controls, #bg-image-controls { transition: opacity 160ms ease; }

}
/* Ensure bg-modal content and controls never overflow: box-sizing and responsive width rules */
#bg-modal .modal-content {
    box-sizing: border-box;
    width: calc(100% - 32px);
    max-width: 560px;
    padding: 12px;
    /* Allow vertical scrolling inside the background picker modal content
       and enable smooth native touch scrolling on mobile. */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-height: 80vh;
}

/* Force file input and controls inside bg modal to wrap and fit */
#bg-image-file {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* Make the preview container safe from overflow and keep background image contained */
#bg-preview {
    width: 100%;
    height: 100%;
    min-height: 120px;
    max-height: 320px;
    overflow: hidden;
    border-radius: 8px;
    background-size: cover;
    background-position: center center;
    box-sizing: border-box;
}

/* Ensure color controls and selectors inside modal do not overflow their column */
#bg-modal .modal-content input[type="color"],
#bg-modal .modal-content select,
#bg-modal .modal-content input[type="file"] {
    max-width: 100%;
    box-sizing: border-box;
    word-break: break-word;
}

/* small tweak: make modal padding consistent on mobile to prevent lateral overflow */
.modal {
    padding: 12px;
}

/* Hide the DOM footer to avoid duplicate visible text:
   keep the footer element in the DOM so its innerText can still be
   read for canvas snapshots/recording, but remove the visible duplicate. */
#app-footer {
    display: none !important;
}