:root {
    /* Fonts */
    --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Light Mode Palette */
    --bg-light: #f4f4f9;
    --text-light: #1a1a2e;
    --glass-bg-light: rgba(255, 255, 255, 0.65);
    --glass-border-light: rgba(255, 255, 255, 0.8);
    --primary-light: #6c5ce7;
    --accent-light: #ff7675;
    --blob-1-light: #a29bfe;
    --blob-2-light: #fab1a0;

    /* Dark Mode Palette */
    --bg-dark: #0f0c29;
    --text-dark: #e0e0e0;
    --glass-bg-dark: rgba(16, 16, 28, 0.6);
    --glass-border-dark: rgba(255, 255, 255, 0.08);
    --primary-dark: #6c5ce7;
    /* Electric Purple */
    --accent-dark: #00cec9;
    /* Cyan Neon */
    --blob-1-dark: #30336b;
    --blob-2-dark: #6c5ce7;

    /* Noise Texture */
    --noise-bg: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.5'/%3E%3C/svg%3E");

    /* Common */
    --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    --shadow-light: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
    --shadow-dark: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

/* Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-ui);
    background-color: var(--bg-light);
    color: var(--text-light);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    overflow-x: hidden;
    transition: background-color 0.5s ease, color 0.3s ease;
}

[data-theme="dark"] body {
    background-color: var(--bg-dark);
    color: var(--text-dark);
}

/* Dynamic Background Blobs */
.background-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.6;
    animation: blob-float 10s infinite alternate;
}

@keyframes blob-float {
    0% {
        transform: translate3d(0, 0, 0) scale(1);
    }

    100% {
        transform: translate3d(30px, 50px, 0) scale(1.1);
    }
}

/* Mobile Gradient & Performance Fix */
@media (max-width: 768px) {
    .blob {
        filter: blur(40px);
        /* Reduced blur radius for performance */
        will-change: transform;
    }

    /* Disable Noise on Mobile (Heavy on GPU) */
    .glass-header::before,
    .glass-card::before,
    .glass-panel::before {
        display: none !important;
    }

    /* Reduce Glass Blur */
    .glass-header,
    .glass-card,
    .glass-panel {
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
    }

    .blob-1 {
        width: 120vw;
        height: 120vw;
        top: -30%;
        left: -30%;
    }

    .blob-2 {
        width: 120vw;
        height: 120vw;
        bottom: -30%;
        right: -30%;
    }
}

@media (min-width: 769px) {

    /* Desktop Blobs */
    .blob-1 {
        top: -10%;
        left: -10%;
        width: 50vw;
        height: 50vw;
        background: var(--blob-1-light);
        transition: background 0.5s;
    }

    [data-theme="dark"] .blob-1 {
        background: var(--blob-1-dark);
    }

    .blob-2 {
        bottom: -10%;
        right: -10%;
        width: 40vw;
        height: 40vw;
        background: var(--blob-2-light);
        animation-delay: -5s;
        transition: background 0.5s;
    }

    [data-theme="dark"] .blob-2 {
        background: var(--blob-2-dark);
    }
}

/* Ensure colors for mobile too */
.blob-1 {
    background: var(--blob-1-light);
    transition: background 0.5s;
}

[data-theme="dark"] .blob-1 {
    background: var(--blob-1-dark);
}

.blob-2 {
    background: var(--blob-2-light);
    transition: background 0.5s;
}

[data-theme="dark"] .blob-2 {
    background: var(--blob-2-dark);
}


/* App Container */
.app-container {
    width: 100%;
    max-width: 1100px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Header */
.glass-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    /* True centering */
    align-items: center;
    padding: 1rem 2rem;
    background: var(--glass-bg-light);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border-light);
    border-radius: 20px;
    box-shadow: var(--shadow-light);
    position: relative;
    overflow: hidden;
}

[data-theme="dark"] .glass-header {
    background: var(--glass-bg-dark);
    border-color: var(--glass-border-dark);
    box-shadow: var(--shadow-dark);
}

.logo-area {
    grid-column: 2;
    /* Place in center column */
    display: flex;
    align-items: center;
    gap: 0.8rem;
    position: relative;
    z-index: 2;
    /* Above noise */
}

#theme-toggle {
    grid-column: 3;
    justify-self: end;
    position: relative;
    z-index: 2;
}

.logo-icon {
    color: var(--primary-light);
}

[data-theme="dark"] .logo-icon {
    color: var(--accent-dark);
}

h1 {
    font-family: var(--font-ui);
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

/* Buttons */
.icon-btn {
    background: transparent;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: var(--transition);
}

.icon-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    transform: rotate(15deg);
}

[data-theme="dark"] .icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Main Grid */
.editor-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}

@media (min-width: 768px) {
    .editor-grid {
        grid-template-columns: 1fr 280px 1fr;
        align-items: start;
    }
}

/* Glass Cards & Noise Effect */
.glass-card {
    background: var(--glass-bg-light);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border-light);
    border-radius: 24px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    box-shadow: var(--shadow-light);
    height: 500px;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

[data-theme="dark"] .glass-card {
    background: var(--glass-bg-dark);
    border-color: var(--glass-border-dark);
    box-shadow: var(--shadow-dark);
}

/* Noise overlay for Glass Elements */
.glass-header::before,
.glass-card::before,
.glass-panel::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: var(--noise-bg);
    opacity: 0.08;
    /* Subtle grain */
    mix-blend-mode: overlay;
    pointer-events: none;
    z-index: 1;
}

/* Content z-index fix */
.glass-card>*,
.glass-panel>* {
    position: relative;
    z-index: 2;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    opacity: 0.9;
}

.badge {
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.05);
    font-weight: 600;
}

[data-theme="dark"] .badge {
    background: rgba(255, 255, 255, 0.1);
}

.badge-success {
    color: #00b894;
    background: rgba(0, 184, 148, 0.1);
}

/* Text Areas */
.textarea-wrapper {
    flex: 1;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 16px;
    padding: 1rem;
    border: 1px solid transparent;
    transition: var(--transition);
}

[data-theme="dark"] .textarea-wrapper {
    background: rgba(0, 0, 0, 0.2);
}

.textarea-wrapper:focus-within {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 2px rgba(108, 92, 231, 0.2);
}

[data-theme="dark"] .textarea-wrapper:focus-within {
    border-color: var(--accent-dark);
    box-shadow: 0 0 0 2px rgba(0, 206, 201, 0.2);
}

textarea {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    resize: none;
    font-family: var(--font-mono);
    font-size: 0.95rem;
    line-height: 1.6;
    color: inherit;
    outline: none;
}

/* Controls Section */
.controls-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding-top: 2rem;
}

.glass-panel {
    background: var(--glass-bg-light);
    border: 1px solid var(--glass-border-light);
    border-radius: 20px;
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    position: relative;
    overflow: hidden;
}

[data-theme="dark"] .glass-panel {
    background: var(--glass-bg-dark);
    border-color: var(--glass-border-dark);
}

/* Modules Grid */
.toggles-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
}

.toggle-card {
    flex: 1 1 45%;
    position: relative;
    cursor: pointer;
}

.toggle-card input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.toggle-content {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
    transition: var(--transition);
    user-select: none;
    text-align: center;
}

[data-theme="dark"] .toggle-content {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}

.toggle-card input:checked~.toggle-content {
    background: rgba(108, 92, 231, 0.2);
    border-color: var(--primary-light);
    color: var(--primary-light);
}

[data-theme="dark"] .toggle-card input:checked~.toggle-content {
    background: rgba(0, 206, 201, 0.2);
    border-color: var(--accent-dark);
    color: var(--accent-dark);
}


.primary-btn {
    background: linear-gradient(135deg, var(--primary-light), #a29bfe);
    color: white;
    border: none;
    padding: 1rem;
    border-radius: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition);
    box-shadow: 0 4px 15px rgba(108, 92, 231, 0.3);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(108, 92, 231, 0.4);
}

[data-theme="dark"] .primary-btn {
    background: linear-gradient(135deg, #6c5ce7, #0984e3);
}

.secondary-btn {
    background: transparent;
    border: 1px solid currentColor;
    color: inherit;
    padding: 0.6rem 1rem;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    transition: var(--transition);
    opacity: 0.8;
}

.secondary-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

/* Slider */
input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
    margin: 10px 0;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: var(--primary-light);
    cursor: pointer;
    margin-top: -8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] input[type=range]::-webkit-slider-thumb {
    background: var(--accent-dark);
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 2px;
}

[data-theme="dark"] input[type=range]::-webkit-slider-runnable-track {
    background: rgba(255, 255, 255, 0.2);
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    opacity: 0.7;
    margin-top: 0.5rem;
}

/* Noise Meter */
.noise-meter {
    font-size: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.progress-bar {
    height: 6px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
    overflow: hidden;
}

[data-theme="dark"] .progress-bar {
    background: rgba(255, 255, 255, 0.1);
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(to right, #00b894, #fdcb6e, #ff7675);
    background-size: 200% 100%;
    transition: width 0.5s ease;
}

@media (max-width: 768px) {
    .editor-grid {
        grid-template-columns: 1fr;
    }

    .glass-card {
        height: 300px;
    }

    .controls-section {
        padding-top: 0;
    }
}