@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Space+Mono:wght@400;700&display=swap');

:root {
    --primary-gradient: linear-gradient(135deg, #f7df1e 0%, #f59e0b 100%);
    --bg-color: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #f7df1e;
    --accent-dark: #ca8a04;
    --border: rgba(255, 255, 255, 0.1);
    --shadow-premium: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.15);
    --panel-bg: rgba(255, 255, 255, 0.03);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 2rem;
}

/* ── Background Blobs ── */
.bg-blobs {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    overflow: hidden;
}

.blob {
    position: absolute;
    width: 700px;
    height: 700px;
    background: var(--primary-gradient);
    filter: blur(160px);
    opacity: 0.09;
    border-radius: 50%;
    top: -200px;
    left: -200px;
    animation: blobFloat 15s ease-in-out infinite alternate;
}

.blob-2 {
    bottom: -200px;
    right: -200px;
    top: auto;
    left: auto;
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    animation-delay: -7s;
}

@keyframes blobFloat {
    from {
        transform: translate(0, 0) scale(1);
    }

    to {
        transform: translate(40px, 25px) scale(1.06);
    }
}

/* ── Container ── */
.tool-container {
    width: 100%;
    max-width: 1120px;
    background: var(--card-bg);
    backdrop-filter: blur(24px);
    border: 1px solid var(--border);
    border-radius: 28px;
    padding: 3rem;
    box-shadow: var(--shadow-premium);
    margin: 1rem auto;
}

/* ── Header ── */
.header {
    text-align: center;
    margin-bottom: 2rem;
}

.header-icon {
    display: inline-block;
    font-size: 1.6rem;
    font-weight: 900;
    font-family: 'Space Mono', monospace;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    letter-spacing: -0.05em;
    margin-bottom: 0.6rem;
    padding: 0.3em 0.6em;
    border: 2px solid rgba(247, 223, 30, 0.35);
    border-radius: 10px;
}

.header h1 {
    font-size: 2.4rem;
    font-weight: 800;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin-bottom: 0.5rem;
}

.header p {
    color: var(--text-secondary);
    font-size: 1.05rem;
}

/* ── Options Bar ── */
.options-bar {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
    padding: 0.9rem 1.5rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 16px;
}

.option-toggle {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    user-select: none;
}

.option-toggle input {
    display: none;
}

.toggle-track {
    width: 38px;
    height: 21px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 100px;
    position: relative;
    transition: background 0.25s;
    flex-shrink: 0;
}

.option-toggle input:checked~.toggle-track {
    background: var(--accent-dark);
}

.toggle-thumb {
    position: absolute;
    left: 3px;
    top: 3px;
    width: 15px;
    height: 15px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.25s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.option-toggle input:checked~.toggle-track .toggle-thumb {
    transform: translateX(17px);
}

.toggle-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* ── Stats Bar ── */
.stats-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    padding: 1rem 1.5rem;
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid var(--border);
    border-radius: 16px;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    transition: all 0.3s;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.stat-val {
    font-size: 1.1rem;
    font-weight: 700;
    font-family: 'Space Mono', monospace;
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
    transition: color 0.3s;
}

.stat-item.saving .stat-val {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.stat-lbl {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-secondary);
}

.stat-divider {
    width: 1px;
    height: 36px;
    background: var(--border);
    flex-shrink: 0;
}

.stats-bar.active .stat-val {
    color: var(--text-primary);
}

/* ── Editor Layout ── */
.editor-layout {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 1rem;
    align-items: start;
}

/* ── Editor Panels ── */
.editor-panel {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 1.25rem 1.5rem 0.75rem;
    transition: border-color 0.3s, box-shadow 0.3s;
    position: relative;
}

.editor-panel:focus-within {
    border-color: rgba(247, 223, 30, 0.5);
    box-shadow: 0 0 0 3px rgba(247, 223, 30, 0.07);
}

.output-panel {
    border-color: rgba(59, 130, 246, 0.25);
    background: rgba(59, 130, 246, 0.03);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.panel-header label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

textarea {
    width: 100%;
    height: 360px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: 'Space Mono', monospace;
    font-size: 0.83rem;
    resize: vertical;
    outline: none;
    line-height: 1.65;
    min-height: 200px;
}

textarea::placeholder {
    color: rgba(148, 163, 184, 0.4);
}

.line-count {
    padding-top: 0.5rem;
    font-size: 0.72rem;
    color: rgba(148, 163, 184, 0.5);
    font-family: 'Space Mono', monospace;
    font-variant-numeric: tabular-nums;
}

/* ── Process center ── */
.process-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 3.5rem;
    gap: 0.75rem;
}

.process-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    width: 74px;
    height: 74px;
    border-radius: 50%;
    background: var(--primary-gradient);
    border: none;
    color: #111827;
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    box-shadow: 0 6px 24px rgba(247, 223, 30, 0.3);
    transition: all 0.25s ease;
    flex-shrink: 0;
}

.process-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 10px 30px rgba(247, 223, 30, 0.4);
}

.process-btn:active {
    transform: scale(0.96);
}

.process-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Loading spinner */
.loader {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(247, 223, 30, 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: none;
}

.loader.visible {
    display: block;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── Action Buttons ── */
.action-link {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    transition: all 0.2s;
}

.action-link:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.07);
}

.action-link.danger:hover {
    color: #f87171;
    background: rgba(248, 113, 113, 0.08);
}

.copy-btn,
.download-btn {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.38rem 0.85rem;
    border-radius: 9px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s;
}

.copy-btn:hover {
    background: rgba(247, 223, 30, 0.8);
    border-color: var(--accent);
    color: #111;
}

.download-btn:hover {
    background: rgba(59, 130, 246, 0.8);
    border-color: rgba(59, 130, 246, 0.8);
}

.copy-btn.copied {
    background: #10b981;
    border-color: #10b981;
}

/* ── Error Box ── */
.error-box {
    margin-top: 1rem;
    padding: 1rem 1.25rem;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 12px;
    color: #fca5a5;
    font-size: 0.87rem;
    font-family: 'Space Mono', monospace;
    line-height: 1.6;
    white-space: pre-wrap;
}

/* ── Info Section ── */
.info-section {
    margin-top: 2rem;
    padding: 1.5rem 2rem;
    background: rgba(247, 223, 30, 0.04);
    border-radius: 18px;
    border: 1px solid rgba(247, 223, 30, 0.12);
}

.info-section h3 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.6rem;
    color: #fde68a;
}

.info-section p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.7;
}

.info-section strong {
    color: var(--text-primary);
}

/* ── Responsive ── */
@media (max-width: 900px) {
    .editor-layout {
        grid-template-columns: 1fr;
    }

    .process-bar {
        flex-direction: row;
        padding-top: 0;
        justify-content: center;
    }

    .process-btn {
        width: auto;
        height: auto;
        border-radius: 14px;
        padding: 0.85rem 2.5rem;
        flex-direction: row;
        font-size: 0.95rem;
        gap: 0.5rem;
    }
}

@media (max-width: 640px) {
    body {
        padding: 1rem;
    }

    .tool-container {
        padding: 1.5rem 1.25rem;
    }

    .header h1 {
        font-size: 1.8rem;
    }

    .options-bar {
        gap: 0.75rem;
    }

    .stats-bar {
        gap: 0.75rem;
    }

    .stat-divider {
        display: none;
    }

    textarea {
        height: 250px;
    }
}