/* =========================================
   1. VARIABLES & SETUP
   ========================================= */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');

:root {
    /* "Cute + Khatarnak" Palette */
    --bg-dark: #0f172a;
    --primary: #8b5cf6; /* Violet */
    --accent: #ec4899;  /* Pink */
    --cyan: #06b6d4;    /* Cyan highlight */
    
    /* Gradients */
    --gradient-main: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
    --gradient-hover: linear-gradient(135deg, #7c3aed 0%, #db2777 100%);
    
    /* Glassmorphism Variables */
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    
    --text-white: #f8fafc;
    --text-gray: #cbd5e1;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent; /* Mobile tap blue box fix */
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-dark);
}
::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* =========================================
   2. BODY & BACKGROUND ANIMATION
   ========================================= */
body {
    background-color: var(--bg-dark);
    color: var(--text-white);
    font-family: 'Poppins', sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden; /* Horizontal scroll prevention */
    position: relative;
    padding: 20px; /* Mobile safe area */
}

/* Animated Floating Blobs */
.background-anim {
    position: fixed;
    top: 0; 
    left: 0;
    width: 100%; 
    height: 100%;
    z-index: -1;
    overflow: hidden;
    background: radial-gradient(circle at 50% 50%, #1e293b 0%, #0f172a 100%);
}

.background-anim::before,
.background-anim::after {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    animation: float 10s infinite alternate ease-in-out;
}

.background-anim::before {
    background: var(--primary);
    top: -100px;
    left: -100px;
}

.background-anim::after {
    background: var(--cyan);
    bottom: -100px;
    right: -100px;
    animation-delay: -5s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(50px, 50px) scale(1.1); }
}

/* =========================================
   3. CONTAINER & GLASS BOX
   ========================================= */
.container {
    width: 100%;
    max-width: 950px;
    margin-top: -15px;
    text-align: center;
    animation: popIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.9) translateY(30px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}


/* --- Header Wrapper (New) --- */
.tool-header {
    display: flex;
    align-items: center;
    justify-content: center; /* Title ko beech mein rakhega */
    gap: 20px;
    margin-bottom: 20px;
    position: relative;
}

/* --- Back Button Style (Slice Tool Jaisa) --- */
.back-btn {
    text-decoration: none;
    color: var(--text-white);
    background: rgba(255, 255, 255, 0.05);
    width: 45px;
    height: 45px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--glass-border);
    transition: all 0.3s ease;
    font-size: 1.2rem;
    flex-shrink: 0; /* Button ko pitchakne se bachayega */
}

.back-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    transform: translateX(-3px);
    box-shadow: 0 5px 15px rgba(139, 92, 246, 0.3);
}


h1 {
    font-weight: 700;
    margin-bottom: 0px;
    font-size: 2.5rem;
    letter-spacing: -1px;
    text-shadow: 0 10px 20px rgba(0,0,0,0.5);
}

h1 i {
    color: var(--cyan);
    margin-right: 10px;
    filter: drop-shadow(0 0 10px rgba(6, 182, 212, 0.5));
}

h1 span {
    background: var(--gradient-main);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    position: relative;
}

.box {
    display: flex;
    flex-wrap: wrap;
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 80px;
    box-shadow: var(--glass-shadow);
    gap: 50px;
    align-items: center; /* Vertical center alignment */
    justify-content: center;
    position: relative;
    overflow: hidden;
}

/* Shiny effect on box top */
.box::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
}

/* =========================================
   4. PREVIEW SECTION
   ========================================= */
.preview-section {
    flex: 1;
    min-width: 300px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.preview-wrapper {
    position: relative;
    padding: 15px;
    border: 2px dashed rgba(255,255,255,0.1);
    border-radius: 50%; 
    transition: all 0.3s ease;
}

.preview-wrapper:hover {
    border-color: var(--primary);
    transform: scale(1.02);
}

.preview {
    width: 320px;
    height: 320px;
    overflow: hidden; /* Ensures image gets cut */
    background: #111;
    position: relative;
    /* Important: Removed border-radius transition for instant slider feel */
    transition: box-shadow 0.3s ease, border-color 0.3s ease; 
    box-shadow: 0 20px 50px rgba(0,0,0,0.6);
    /* Default styling logic.js will override */
    border: 5px solid white; 
    border-radius: 50%;
}

.preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none; 
}

/* Placeholder Styling */
.placeholder-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-gray);
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    pointer-events: none;
}

.placeholder-text i {
    font-size: 3.5rem;
    margin-bottom: 15px;
    background: linear-gradient(to bottom, #fff, #555);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    opacity: 0.5;
}

.placeholder-text p {
    font-size: 0.9rem;
    font-weight: 500;
    letter-spacing: 0.5px;
    opacity: 0.7;
}

/* =========================================
   5. CONTROLS SECTION
   ========================================= */
.controls-section {
    flex: 1;
    min-width: 280px;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 25px;
}

/* Labels */
.control-group label {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    font-size: 0.95rem;
    color: var(--text-gray);
    font-weight: 500;
}

.control-group label i { 
    margin-right: 10px; 
    color: var(--accent);
    background: rgba(236, 72, 153, 0.1);
    padding: 6px;
    border-radius: 6px;
    font-size: 0.8rem;
}

/* Custom Upload Button */
.upload-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    background: rgba(255,255,255,0.03);
    border: 1px dashed var(--text-gray);
    color: var(--text-white);
    padding: 18px;
    border-radius: 16px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.upload-btn:hover {
    background: rgba(139, 92, 246, 0.1);
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(139, 92, 246, 0.2);
}

/* -----------------------------
   Custom Range Sliders (The Cute Part)
   ----------------------------- */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 8px;
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
    outline: none;
    cursor: pointer;
    position: relative;
    z-index: 1;
}

/* Slider Thumb (The Knob) */
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 24px;
    height: 24px;
    background: var(--text-white);
    border-radius: 50%;
    box-shadow: 0 0 15px var(--accent); /* Glowing effect */
    cursor: grab;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    margin-top: -8px; /* Alignment fix */
}

/* Firefox Support */
input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: var(--text-white);
    border: none;
    border-radius: 50%;
    box-shadow: 0 0 15px var(--accent);
    cursor: grab;
}

input[type="range"]::-webkit-slider-thumb:active {
    cursor: grabbing;
    transform: scale(1.3);
    background: var(--accent);
}

input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 8px;
    border-radius: 10px;
    /* Optional: Linear Gradient Track */
    background: linear-gradient(90deg, #334155 0%, #475569 100%);
}

/* -----------------------------
   Color Picker
   ----------------------------- */
.color-wrapper {
    height: 50px;
    border-radius: 14px;
    overflow: hidden;
    border: 2px solid var(--glass-border);
    position: relative;
    cursor: pointer;
    transition: transform 0.2s;
}

.color-wrapper:hover {
    transform: scale(1.02);
    border-color: var(--text-gray);
}

input[type="color"] {
    position: absolute;
    top: -50%; left: -50%;
    width: 200%; height: 200%;
    border: none;
    cursor: pointer;
    padding: 0;
    margin: 0;
}

/* =========================================
   6. DOWNLOAD BUTTON (The Khatarnak Part)
   ========================================= */
.download-btn {
    margin-top: 15px;
    width: 100%;
    padding: 18px;
    border: none;
    background: var(--gradient-main);
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    border-radius: 16px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    box-shadow: 0 10px 25px -5px rgba(236, 72, 153, 0.5); /* Pinkish glow */
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
}

/* Shine Effect */
.download-btn::after {
    content: '';
    position: absolute;
    top: 0; left: -100%;
    width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: 0.5s;
}

.download-btn:hover {
    transform: translateY(-4px) scale(1.01);
    box-shadow: 0 20px 35px -5px rgba(139, 92, 246, 0.6); /* Purple intense glow */
}

.download-btn:hover::after {
    left: 100%;
}

.download-btn:active {
    transform: scale(0.96);
}

/* =========================================
   7. RESPONSIVE DESIGN (Mobile Friendly)
   ========================================= */
@media (max-width: 900px) {
    .container {
        padding: 10px;
        margin-top: 20px;
    }
    
    .box {
        flex-direction: column;
        padding: 30px 20px;
        gap: 30px;
    }
    
    .preview {
        width: 260px;
        height: 260px;
    }
    
    h1 {
        font-size: 1.8rem;
    }
}

@media (max-width: 400px) {
    .preview {
        width: 220px;
        height: 220px;
    }
    
    .download-btn {
        font-size: 1rem;
    }
}

/* =========================================
   MOBILE RESPONSIVE FIXES (Copy Paste this at bottom)
   ========================================= */

@media (max-width: 900px) {
    /* 1. Container ki width fix */
    .container {
        padding: 15px;
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center; /* Sab kuch horizontal center */
    }

    /* 2. Title ko adjust karo taaki wo toote nahi */
    h1 {
        font-size: 1.8rem; /* Font thoda chhota */
        line-height: 1.3;
        margin-bottom: 20px;
        display: flex;
        flex-direction: column; /* Mobile pe icon upar, text neeche (optional) */
        align-items: center;
        width: 100%;
        white-space: nowrap; /* Text ko ek line me force karega */
    }
    
    h1 span {
        display: inline-block; /* Gradient text fix */
    }
    
    /* 3. Glass Box ko mobile fit banao */
    .box {
        flex-direction: column; /* Upar Image, Neeche Controls */
        padding: 30px 20px;
        width: 100%;
        max-width: 400px; /* Mobile pe box zyada failna nahi chahiye */
        margin: 0 auto; /* Box ko center karo */
        gap: 30px;
    }

    /* 4. Preview Section Fix */
    .preview-section {
        width: 100%;
        min-width: auto; /* Purana constraint hatao */
    }
    
    .preview {
        width: 250px; /* Size thoda control mein */
        height: 250px;
        margin: 0 auto; /* Image box center */
        box-shadow: 0 10px 30px rgba(0,0,0,0.4);
    }

    /* 5. Controls Alignment (Sabse Important) */
    .controls-section {
        width: 100%;
        min-width: auto;
        text-align: center; /* Text center */
        align-items: center; /* Flex items center */
    }

    /* Labels aur Sliders ko align karo */
    .control-group {
        width: 100%;
        margin-bottom: 15px;
        display: flex;
        flex-direction: column;
        align-items: center; /* Labels ko center mein lao */
    }
    
    .control-group label {
        align-self: center; /* Explicitly label ko center */
        margin-bottom: 8px;
        justify-content: center; /* Icon aur Text center */
        width: 100%;
    }

    /* Sliders aur Inputs ko full width do par margin ke saath */
    input[type="range"] {
        width: 100%;
        max-width: 280px; /* Slider zyada lamba na ho */
    }

    .upload-btn {
        width: 100%;
        max-width: 280px; /* Button zyada lamba na ho */
        margin: 0 auto; /* Center alignment */
    }

    .color-wrapper {
        width: 100%;
        max-width: 280px;
        margin: 0 auto;
    }

    .download-btn {
        width: 100%;
        max-width: 280px;
        margin: 15px auto 0 auto; /* Top gap aur center */
    }
}

/* Chote phones ke liye extra adjustment */
@media (max-width: 380px) {
    h1 { font-size: 1.5rem; white-space: normal; } /* Agar screen bahut choti hai to wrap hone do */
    .preview { width: 200px; height: 200px; }
        /* Is part ko @media (max-width: 900px) ke andar daalna */
    .tool-header {
        flex-direction: column; /* Mobile pe button upar, title neeche */
        gap: 10px;
    }

}
/* =========================================
   MOBILE RESPONSIVE FIXES (UPDATED)
   ========================================= */

@media (max-width: 900px) {
    /* 1. Container Fix */
    .container {
        padding: 15px;
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    /* 2. Header Fix (Ye wala change kiya hai maine) */
    .tool-header {
        display: flex;
        flex-direction: row;       /* Ab ye bagal mein aayega */
        align-items: center;
        justify-content: center;
        gap: 15px;
        width: 100%;
        margin-bottom: 20px;
    }

    /* 3. Title Adjustments */
    h1 {
        font-size: 1.6rem;         /* Font thoda adjust */
        line-height: 1.2;
        margin: 0;                 /* Margin hata diya taaki center rahe */
        white-space: normal;       /* Text wrap hone do agar zaroorat ho */
        text-align: left;          /* Text thoda left align button ke saath */
    }
    
    /* 4. Glass Box Fix */
    .box {
        flex-direction: column;
        padding: 30px 20px;
        width: 100%;
        max-width: 400px;
        margin: 0 auto;
        gap: 30px;
    }

    /* 5. Baaki Elements */
    .preview-section, .controls-section {
        width: 100%;
        min-width: auto;
    }
    
    .preview {
        width: 250px;
        height: 250px;
        margin: 0 auto;
    }

    /* Controls Alignment */
    .control-group {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    .control-group label {
        align-self: center;
        margin-bottom: 8px;
    }

    input[type="range"], .upload-btn, .color-wrapper, .download-btn {
        width: 100%;
        max-width: 280px;
        margin-left: auto;
        margin-right: auto;
    }
}
