/* ================================================
   Mandelbrot Fractal Explorer - Styles
   ================================================ */

/* CSS Variables for Safe Areas */
:root {
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* ================================================
   Base Styles
   ================================================ */

body {
    font-family: sans-serif;
    background-color: #f0f0f0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    box-sizing: border-box;
}

body.dark {
    background-color: black;
    color: white;
}

/* ================================================
   Header & Instructions
   ================================================ */

h1 {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    margin: 0;
    padding: calc(var(--safe-area-top) + 10px) 20px 10px 20px;
    background: linear-gradient(to bottom, rgba(240, 240, 240, 0.95), rgba(240, 240, 240, 0.7));
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 200;
    text-align: center;
    color: #333;
    font-size: clamp(1.5rem, 5vw, 2rem);
}

body.dark h1 {
    color: white;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.95), rgba(0, 0, 0, 0.7));
}

p {
    position: fixed;
    bottom: calc(70px + var(--safe-area-bottom));
    left: 0;
    right: 0;
    margin: 0;
    padding: 5px 10px;
    background: rgba(240, 240, 240, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 200;
    text-align: center;
    font-size: clamp(0.875rem, 3vw, 1rem);
}

body.dark p {
    background: rgba(0, 0, 0, 0.8);
}

/* Auto-hide UI elements */
h1, p {
    opacity: 1;
    transition: opacity 0.5s ease-in-out;
}

h1.hidden, p.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ================================================
   Fractal Container
   ================================================ */

#fractal-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    cursor: crosshair;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    overflow: hidden;
}

#fractalImage {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#selection-box {
    position: absolute;
    border: 1px dashed #fff;
    background-color: rgba(255, 255, 255, 0.3);
    display: none;
}

/* ================================================
   Loading Indicator
   ================================================ */

#loading-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 20px 30px;
    border-radius: 12px;
    font-size: 18px;
    z-index: 300;
    display: none;
    pointer-events: none;
}

#loading-indicator.active {
    display: block;
}

#loading-indicator::after {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-left: 10px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ================================================
   Controls Bar
   ================================================ */

#controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    padding: 10px 10px calc(var(--safe-area-bottom) + 10px) 10px;
    background: linear-gradient(to top, rgba(240, 240, 240, 0.95), rgba(240, 240, 240, 0.7));
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 200;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
}

body.dark #controls {
    background: linear-gradient(to top, rgba(0, 0, 0, 0.95), rgba(0, 0, 0, 0.7));
}

#controls button {
    min-height: 44px;
    min-width: 80px;
    padding: 10px 16px;
    font-size: 16px;
    border-radius: 8px;
    border: 1px solid #ccc;
    background: white;
    cursor: pointer;
    touch-action: manipulation;
}

#controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

body.dark #controls button {
    background: #333;
    color: white;
    border-color: #666;
}

#controls select {
    min-height: 44px;
    font-size: 16px;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #ccc;
}

body.dark #controls select {
    background: #333;
    color: white;
    border-color: #666;
}

#controls label {
    font-size: 16px;
    margin-right: 8px;
}

/* Pan mode button styling */
.mode-button {
    background: white !important;
    border: 2px solid #ccc !important;
}

.mode-button.active {
    background: #4CAF50 !important;
    color: white !important;
    border-color: #4CAF50 !important;
}

body.dark .mode-button {
    background: #333 !important;
    border-color: #666 !important;
}

body.dark .mode-button.active {
    background: #4CAF50 !important;
    border-color: #4CAF50 !important;
}

/* ================================================
   Help Overlay
   ================================================ */

.help-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    padding: 20px;
    box-sizing: border-box;
}

.help-overlay.visible {
    display: flex;
}

.help-content {
    background: white;
    border-radius: 12px;
    padding: 30px;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

body.dark .help-content {
    background: #1a1a1a;
    color: white;
}

.help-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 32px;
    cursor: pointer;
    color: #666;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.help-close:hover {
    background: rgba(0, 0, 0, 0.1);
}

body.dark .help-close {
    color: #999;
}

body.dark .help-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

.help-content h2 {
    margin: 0 0 20px 0;
    font-size: 24px;
    color: #333;
}

body.dark .help-content h2 {
    color: white;
}

.help-section {
    margin-bottom: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
}

body.dark .help-section {
    border-color: #444;
}

.help-section summary {
    padding: 12px 16px;
    font-size: 18px;
    font-weight: bold;
    color: #333;
    cursor: pointer;
    user-select: none;
    background: #f5f5f5;
    transition: background 0.2s;
}

body.dark .help-section summary {
    color: white;
    background: #252525;
}

.help-section summary:hover {
    background: #e8e8e8;
}

body.dark .help-section summary:hover {
    background: #333;
}

.help-section[open] summary {
    border-bottom: 1px solid #ddd;
}

body.dark .help-section[open] summary {
    border-bottom-color: #444;
}

.help-section summary::marker {
    font-size: 14px;
}

.help-section ul {
    margin: 0;
    padding: 16px 16px 16px 36px;
    background: white;
}

body.dark .help-section ul {
    background: #1a1a1a;
}

.help-section li {
    margin-bottom: 8px;
    line-height: 1.5;
}

/* ================================================
   Responsive Design - Media Queries
   ================================================ */

/* Hide title on short screens or mobile */
@media (max-height: 600px), (max-width: 480px) {
    h1 {
        display: none;
    }
}

/* Hide instructions on very short screens */
@media (max-height: 500px) {
    p {
        display: none;
    }
}

/* Compact controls on landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    #controls {
        padding: 5px 5px calc(var(--safe-area-bottom) + 5px) 5px;
    }

    #controls button,
    #controls select {
        min-height: 36px;
        padding: 6px 12px;
        font-size: 14px;
    }
}

/* Extra compact on very short screens */
@media (max-height: 400px) {
    #controls button,
    #controls select {
        min-height: 32px;
        padding: 4px 8px;
        font-size: 12px;
    }

    #controls {
        gap: 4px;
    }
}

/* Mobile portrait: make controls fit on one line */
@media (max-width: 480px) {
    #controls {
        gap: 6px;
    }

    #controls button {
        min-width: 44px;
        padding: 10px 12px;
        font-size: 14px;
    }

    #controls select {
        min-width: 80px;
        padding: 8px 8px;
    }

    /* Hide "Palette:" label on small screens */
    .palette-label {
        display: none;
    }
}

/* Even more compact for very narrow screens */
@media (max-width: 380px) {
    #controls {
        gap: 4px;
    }

    #controls button {
        min-width: 40px;
        padding: 10px 8px;
        font-size: 13px;
    }

    #controls select {
        min-width: 70px;
        padding: 8px 6px;
        font-size: 14px;
    }
}
