:root {
    --primary: #6366F1;
    /* Indigo 500 */
    --primary-hover: #4F46E5;
    /* Indigo 600 */
    --accent: #EC4899;
    /* Pink 500 */

    --bg-base: #F8FAFC;
    --bg-panel: rgba(255, 255, 255, 0.8);
    --text-main: #0F172A;
    --text-muted: #64748B;
    --border: rgba(15, 23, 42, 0.1);

    --success: #10B981;
    --danger: #EF4444;

    --radius: 16px;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.05);
}

.dark-mode {
    --bg-base: #0B0F19;
    --bg-panel: rgba(30, 41, 59, 0.6);
    --text-main: #F1F5F9;
    --text-muted: #94A3B8;
    --border: rgba(255, 255, 255, 0.1);
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--bg-base);
    color: var(--text-main);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;

    /* Subtle background mesh */
    background-image:
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(236, 72, 153, 0.1) 0px, transparent 50%);
}

.app-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 1.5rem max(1.5rem, 3vw);
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-icon {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.brand h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Theme Switch */
.theme-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
    cursor: pointer;
}

.theme-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(148, 163, 184, 0.3);
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

input:checked+.slider {
    background-color: var(--primary);
}

input:checked+.slider:before {
    transform: translateX(24px);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-height: 0;
}

.panel-container {
    display: flex;
    gap: 1.5rem;
    flex: 1;
    min-height: 0;
}

/* Glassmorphism Panel Base */
.glass {
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* Panels */
.panel {
    display: flex;
    flex-direction: column;
}

.editor-panel {
    flex: 2;
    min-width: 0;
    /* Flexbox text clipping fix */
}

.config-panel {
    flex: 1;
    min-width: 250px;
    max-width: 350px;
}

.panel-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.actions {
    display: flex;
    gap: 0.5rem;
}

/* Buttons */
.btn {
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

.btn-ghost {
    background: transparent;
    color: var(--text-main);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.05);
}

.btn-ghost.danger:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.3);
}

.extract-action {
    width: 100%;
    padding: 1rem;
    font-size: 1rem;
    margin-top: 2rem;
    background: linear-gradient(135deg, var(--primary), var(--accent));
}

/* Editors */
.editor-wrap {
    flex: 1;
    position: relative;
    padding: 1rem;
}

.code-editor {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    font-family: 'Fira Code', ui-monospace, monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-main);
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    white-space: pre;
}

.dark-mode .code-editor {
    background: rgba(0, 0, 0, 0.3);
}

.code-editor:focus {
    border-color: var(--primary);
}

.code-editor.output {
    background: transparent;
    border: none;
    padding: 0;
}

/* Config Controls */
.config-body {
    padding: 1.5rem;
    overflow-y: auto;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.checkbox-label {
    cursor: pointer;
    user-select: none;
}

.checkbox-label input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.custom-chk {
    height: 20px;
    width: 20px;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 6px;
    position: relative;
    display: inline-block;
    transition: all 0.2s;
}

.checkbox-label:hover input~.custom-chk {
    background-color: rgba(255, 255, 255, 0.1);
}

.checkbox-label input:checked~.custom-chk {
    background-color: var(--primary);
    border-color: var(--primary);
}

.custom-chk:after {
    content: "";
    position: absolute;
    display: none;
    left: 6px;
    top: 2px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.checkbox-label input:checked~.custom-chk:after {
    display: block;
}

/* Range Slider */
.range-wrap {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 0.5rem;
}

.range-slider {
    flex: 1;
    -webkit-appearance: none;
    height: 6px;
    background: rgba(148, 163, 184, 0.3);
    border-radius: 3px;
    outline: none;
}

.range-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    transition: transform 0.1s;
}

.range-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.range-val {
    min-width: 24px;
    text-align: center;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
}

/* Stats */
.stats-box {
    margin-top: 2rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    animation: fadeIn 0.4s ease;
}

.hidden {
    display: none !important;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-val {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Bottom Variables Preview */
.variable-preview {
    padding: 1.5rem;
    max-height: 150px;
    overflow-y: auto;
}

.variable-preview h3 {
    font-size: 0.9rem;
    margin-bottom: 1rem;
    color: var(--text-muted);
}

.var-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.var-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    padding: 0.4rem 0.75rem;
    border-radius: 8px;
    font-size: 0.75rem;
    font-family: var(--font-mono);
}

.color-dot {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 1024px) {
    .panel-container {
        flex-direction: column;
    }

    .config-panel {
        max-width: none;
    }

    .main-content {
        overflow-y: auto;
    }

    .editor-wrap {
        min-height: 250px;
    }
}