/* Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #000;
    color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Desktop-specific styles */
@media (hover: hover) and (pointer: fine) {
    #fractal-canvas {
        cursor: grab;
    }

    #fractal-canvas:active {
        cursor: grabbing;
    }

    .fractal-selector:hover,
    .color-selector:hover {
        background: rgba(0, 0, 0, 0.75);
    }

    .fractal-btn:hover,
    .color-btn:hover,
    .info-btn:hover {
        background: rgba(255, 255, 255, 0.15);
    }

    .close-btn:hover {
        transform: scale(1.02);
        box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
    }

    /* Show UI controls more prominently on desktop */
    .ui-controls {
        opacity: 0.9;
    }

    .ui-controls.hidden {
        opacity: 0.3;
    }
}

/* Fullscreen Canvas */
#fractal-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
}

/* Loading Screen */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0a0a1a 0%, #1a0a2a 50%, #0a1a2a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.3s ease-out;
}

#loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    text-align: center;
    padding: 2rem;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    margin: 0 auto 1.5rem;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #8b5cf6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    font-size: 1.25rem;
    font-weight: 300;
    letter-spacing: 0.1em;
    margin-bottom: 1.5rem;
    color: rgba(255, 255, 255, 0.9);
}

.loading-progress {
    width: 200px;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    margin: 0 auto;
    overflow: hidden;
}

#loading-progress-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #8b5cf6, #06b6d4);
    border-radius: 2px;
    transition: width 0.2s ease-out;
}

/* Error Screen */
#error-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a0a0a 0%, #2a0a1a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1001;
}

.error-content {
    text-align: center;
    padding: 2rem;
    max-width: 320px;
}

.error-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 1.5rem;
    border: 3px solid #ef4444;
    border-radius: 50%;
    font-size: 2rem;
    line-height: 54px;
    color: #ef4444;
}

.error-content h2 {
    font-size: 1.25rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
}

.error-content p {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

#error-retry {
    background: #8b5cf6;
    color: #fff;
    border: none;
    padding: 0.75rem 2rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

#error-retry:active {
    background: #7c3aed;
}

/* Photo Button - matches info button style */
.photo-btn {
    position: fixed;
    top: 16px;
    right: 16px;
    top: max(16px, env(safe-area-inset-top));
    right: max(16px, env(safe-area-inset-right));
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border: none;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, opacity 0.3s;
    z-index: 100;
    padding: 0;
    margin: 0;
    -webkit-tap-highlight-color: transparent;
}

.photo-btn:active {
    background: rgba(0, 0, 0, 0.8);
}

.photo-btn.hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden;
}

.ui-controls.hidden ~ .photo-btn {
    opacity: 0;
    pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
    .photo-btn:hover {
        background: rgba(0, 0, 0, 0.75);
    }
}

/* Prevent pull-to-refresh */
body {
    overscroll-behavior: none;
}

/* Hide scrollbars */
::-webkit-scrollbar {
    display: none;
}

/* ========== Phase 2 UI Controls ========== */

/* UI Controls Container */
.ui-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    z-index: 100;
    pointer-events: none;
    transition: opacity 0.3s ease-out;
}

.ui-controls.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Desktop: Keep UI controls more visible */
@media (hover: hover) and (pointer: fine) {
    .ui-controls {
        opacity: 0.85;
    }
    
    .ui-controls.hidden {
        opacity: 0;
        pointer-events: none;
    }
}

.ui-controls > * {
    pointer-events: auto;
}

/* Fractal Selector */
.fractal-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 10px 14px;
    width: 180px;
    justify-content: center;
    min-height: 44px;
    cursor: pointer;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.fractal-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
    padding: 0;
    margin: 0;
    -webkit-tap-highlight-color: transparent;
}

.fractal-selector:active {
    background: rgba(0, 0, 0, 0.85);
}

.fractal-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

.fractal-icon {
    width: 28px;
    height: 28px;
    object-fit: cover;
    border-radius: 4px;
    filter: grayscale(100%) brightness(0.9);
    opacity: 0.9;
    pointer-events: none;
}

.fractal-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

/* Color Selector */
.color-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 10px 14px;
    width: 180px;
    justify-content: center;
    min-height: 44px;
    cursor: pointer;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.color-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
    padding: 0;
    margin: 0;
    -webkit-tap-highlight-color: transparent;
}

.color-selector:active {
    background: rgba(0, 0, 0, 0.85);
}

.color-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

.color-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

/* Info Button */
.info-btn {
    position: fixed;
    top: 16px;
    left: 16px;
    top: max(16px, env(safe-area-inset-top));
    left: max(16px, env(safe-area-inset-left));
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border: none;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, opacity 0.3s;
    z-index: 100;
    padding: 0;
    margin: 0;
    -webkit-tap-highlight-color: transparent;
}

.info-btn:active {
    background: rgba(0, 0, 0, 0.8);
}

.ui-controls.hidden ~ .info-btn {
    opacity: 0;
    pointer-events: none;
}

.info-btn.hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden;
}

/* Zoom Indicator */
#zoom-indicator {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    top: max(16px, env(safe-area-inset-top));
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.875rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.5px;
    pointer-events: none;
    user-select: none;
    z-index: 100;
    transition: opacity 0.2s;
}

#zoom-indicator.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Info Overlay */
.info-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease-out;
}

.info-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.info-content {
    text-align: center;
    padding: 2rem;
    max-width: 320px;
}

.info-content h2 {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, #8b5cf6, #06b6d4);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.info-content > p {
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 2rem;
}

.info-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
}

.control-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.control-item .icon {
    font-size: 1.25rem;
    width: 32px;
    text-align: center;
}

.control-item span:last-child {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
}

.close-btn {
    background: linear-gradient(135deg, #8b5cf6, #06b6d4);
    color: #fff;
    border: none;
    min-height: 44px;
    padding: 0.875rem 2.5rem;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.close-btn:active {
    transform: scale(0.98);
}

/* Julia Parameter Indicator */
.julia-param {
    position: fixed;
    top: 60px;
    right: 16px;
    top: calc(max(16px, env(safe-area-inset-top)) + 44px);
    right: max(16px, env(safe-area-inset-right));
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 6px;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.7);
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease-out;
    pointer-events: none;
}

.julia-param.visible {
    opacity: 1;
}
