:root {
    --bg-color: #0f0f11;
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --accent-color: #8b5cf6;
    /* Violet */
    --accent-hover: #7c3aed;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --font-family: 'Fira Code', monospace;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-family);
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    background: rgba(15, 15, 17, 0.8);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--glass-border);
}

header h1 {
    font-family: "Tiny5", sans-serif;
    font-size: 3.5rem;
    font-weight: 400;
    margin: 0;
    line-height: 1;
    color: #ffffff;
    text-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
    /* subtle glow */
    letter-spacing: 0.05em;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #fff 0%, #a1a1aa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    padding: 0.5rem;
    transition: opacity 0.2s;
}

.btn-icon:hover {
    opacity: 0.7;
}

/* Main Layout */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    width: 100%;
    max-width: 1200px;
    /* Increased for side-by-side */
    margin: 0 auto;
    gap: 1.5rem;
    position: relative;
}

/* Preview Area */
.hidden {
    display: none !important;
}

[hidden] {
    display: none !important;
}

.preview-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Desktop Layout */
@media (min-width: 768px) {
    .preview-container {
        display: grid;
        grid-template-columns: 1.2fr 1fr;
        /* Image slightly larger */
        gap: 2rem;
        align-items: start;
    }

    .sticky-panel {
        position: sticky;
        top: 6rem;
        /* Account for header height */
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }
}

/* Ensure sticky behavior on mobile as well */
@media (max-width: 767px) {
    .sticky-panel {
        position: sticky;
        top: 6rem;
        /* Account for mobile header */
        z-index: 50;
        /* Keep it above controls */
        background: var(--bg-color);
        /* Prevent controls from showing through */
        padding-bottom: 0.5rem;
        /* Add some spacing below */
    }
}

.image-wrapper {
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 20px 50px -12px rgba(0, 0, 0, 0.5);
    background: #000;
    border: 1px solid var(--glass-border);
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.image-wrapper img {
    max-width: 100%;
    width: auto;
    height: auto;
    display: block;
    max-height: 60vh;
    object-fit: contain;
}

/* Limit height on mobile so it doesn't consume the whole screen when sticky */
@media (max-width: 767px) {

    .image-wrapper,
    .image-wrapper img {
        max-height: 45vh;
    }
}

/* Drop Zone */
.drop-zone {
    width: 100%;
    height: 300px;
    border: 2px dashed var(--glass-border);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--glass-bg);
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--accent-color);
    background: rgba(139, 92, 246, 0.05);
}

.icon-upload {
    width: 48px;
    height: 48px;
    color: var(--text-secondary);
}

.drop-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Tools Bar */
.tools-bar {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 0.5rem 0;
}

.btn-tool {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.btn-tool:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-primary);
}

.btn-preset {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.8rem;
    white-space: nowrap;
    transition: all 0.2s;
}

.btn-preset:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.btn-icon:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
    /* Optional: prevents hover effects */
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    /* Darker overlay */
    backdrop-filter: blur(8px);
    /* Stronger blur on backdrop */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 1;
    transition: opacity 0.3s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
    display: flex !important;
}

.modal-content {
    width: 90%;
    max-width: 400px;
    padding: 2.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    background: rgba(20, 20, 23, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.modal-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #fff 0%, #a1a1aa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.input-group label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    display: block;
}

.input-group input {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    padding: 1rem;
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: all 0.2s;
}

.input-group input:focus {
    border-color: var(--accent-color);
    background: rgba(0, 0, 0, 0.5);
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
}

.modal-footer {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
}

.modal-footer button {
    width: 100%;
    justify-content: center;
    /* Center text/icon */
}

/* Controls */
.controls {
    width: 100%;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
}

.slider-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
    /* Context for the overlay */
}

.slider-container label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
}

.value-display {
    color: var(--accent-color);
    font-family: 'JetBrains Mono', monospace;
    /* or fallback */
    font-size: 0.8rem;
}

input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    outline: none;
    position: relative;
    z-index: 1;
    /* Keep track behind overlay */
}

/* Invisible overlay that catches taps on the track */
.slider-track-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 24px;
    /* Covers the area of the track */
    z-index: 2;
    /* Sits ABOVE the track to catch taps */
    pointer-events: auto;
    /* Catch events */
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    transition: transform 0.1s;
    position: relative;
    z-index: 3;
    /* Thumb sits ABOVE the overlay! */
    pointer-events: auto;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.select-input {
    width: 100%;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    cursor: pointer;
}

.select-input:focus {
    border-color: var(--accent-color);
}

/* Advanced Settings */
.advanced-settings {
    width: 100%;
    border-top: 1px solid var(--glass-border);
    padding-top: 1rem;
}

.advanced-settings summary {
    cursor: pointer;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    color: var(--accent-color);
    font-weight: 600;
    user-select: none;
    transition: color 0.2s;
}

.advanced-settings summary:hover {
    color: var(--accent-hover);
}

.advanced-settings[open] summary {
    margin-bottom: 1rem;
}

.advanced-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

@media (max-width: 480px) {
    .advanced-grid {
        grid-template-columns: 1fr;
    }
}


/* Footer */
footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.8rem;
    opacity: 0.6;
    margin-top: auto;
    /* Push to bottom if flex container allows */
}

/* Actions */
.actions {
    display: flex;
    gap: 1rem;
    width: 100%;
}

.btn {
    flex: 1;
    min-width: 0;
    /* Ensures buttons can shrink below content size if needed, keeping them equal */
    padding: 1rem;
    border-radius: 12px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--text-primary);
    color: #000;
}

.btn-primary:hover {
    background: #e4e4e7;
    transform: translateY(-2px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Hue Slider */
/* Hue Slider */
.hue-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 14px !important;
    border-radius: 7px;
    background: linear-gradient(to right,
            #ff0000 0%, #ffff00 17%, #00ff00 33%,
            #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%) !important;
    outline: none;
    cursor: pointer;
    margin: 0;
    border: none;
}

/* Ensure track doesn't override it in some browsers */
.hue-slider::-webkit-slider-runnable-track {
    background: transparent;
    border: none;
    height: 14px;
}

.hue-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--thumb-color, #ff0000);
    /* Dynamic Color */
    border: 3px solid #ffffff;
    /* Thicker white border */
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    transition: transform 0.1s;
    margin-top: -4px;
    /* Center thumb */
}

.hue-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}