:root {
    --bg-base: #f8fafc;
    --bg-panel: #ffffff;
    --bg-panel-secondary: #f1f5f9;

    --border-light: #e2e8f0;
    --border-highlight: #cbd5e1;

    --text-main: #0f172a;
    --text-muted: #64748b;

    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-glow: rgba(99, 102, 241, 0.2);

    --grad-1: #4f46e5;
    --grad-2: #db2777;

    --graph-grid: #f1f5f9;
    --graph-line: #94a3b8;
    --graph-curve: #0f172a;
    --graph-handle-1: #ec4899;
    --graph-handle-2: #06b6d4;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body.dark-theme {
    --bg-base: #020617;
    --bg-panel: #0f172a;
    --bg-panel-secondary: #1e293b;

    --border-light: rgba(255, 255, 255, 0.1);
    --border-highlight: rgba(255, 255, 255, 0.2);

    --text-main: #f8fafc;
    --text-muted: #94a3b8;

    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-glow: rgba(129, 140, 248, 0.15);

    --graph-grid: rgba(255, 255, 255, 0.05);
    --graph-line: rgba(255, 255, 255, 0.3);
    --graph-curve: #f8fafc;
    --graph-handle-1: #f472b6;
    --graph-handle-2: #22d3ee;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
}

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

body {
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--bg-base);
    color: var(--text-main);
    line-height: 1.5;
    transition: background-color 0.3s, color 0.3s;
    min-height: 100vh;
}

svg {
    display: block;
}

.w-4 {
    width: 1rem;
}

.h-4 {
    height: 1rem;
}

.w-5 {
    width: 1.25rem;
}

.h-5 {
    height: 1.25rem;
}

.w-6 {
    width: 1.5rem;
}

.h-6 {
    height: 1.5rem;
}

.mt-4 {
    margin-top: 1rem;
}

.mt-6 {
    margin-top: 1.5rem;
}

.mt-8 {
    margin-top: 2rem;
}

.text-muted {
    color: var(--text-muted);
}

.text-sm {
    font-size: 0.875rem;
}

.text-xs {
    font-size: 0.75rem;
}

.font-semibold {
    font-weight: 600;
}

.hidden {
    display: none !important;
}

.text-accent {
    color: var(--accent);
}

.text-white {
    color: #ffffff;
}

.text-gradient {
    background: linear-gradient(135deg, var(--grad-1), var(--grad-2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Layout */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    gap: 2rem;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.375rem;
    font-weight: 700;
}

/* Buttons */
.btn-icon {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 0.5rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    color: var(--text-main);
    background: var(--bg-panel-secondary);
}

.btn-primary {
    background: linear-gradient(135deg, var(--grad-1), var(--grad-2));
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: filter 0.2s, transform 0.2s;
}

.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(1px);
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Main Workspace */
.workspace {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    flex: 1;
}

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

    .app-container {
        padding: 1rem;
    }
}

.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

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

/* Inputs */
.input-modern {
    background: var(--bg-panel-secondary);
    border: 1px solid var(--border-light);
    color: var(--text-main);
    border-radius: 0.5rem;
    padding: 0.5rem;
    font-family: inherit;
    font-size: 0.875rem;
    transition: all 0.2s;
    width: 100%;
}

.input-modern:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.control-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

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

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Canvas Area */
.canvas-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 1/1;
    background: var(--bg-panel-secondary);
    border-radius: 0.75rem;
    border: 1px solid var(--border-light);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
    overflow: visible;
    /* Handles overflow handles */
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}

#curveCanvas {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
    /* important for smooth mobile drag */
    cursor: grab;
}

#curveCanvas:active {
    cursor: grabbing;
}

.bezier-param-text {
    position: absolute;
    top: 1rem;
    left: 1rem;
    font-family: 'Fira Code', monospace;
    font-size: 0.875rem;
    color: var(--text-main);
    z-index: 10;
    background: rgba(var(--bg-panel), 0.8);
    backdrop-filter: blur(4px);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    pointer-events: none;
}

/* Range Slider */
.range-modern {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    background: var(--border-light);
    border-radius: 3px;
    outline: none;
}

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

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

/* Animation Tracks */
.preview-track-container {
    background: var(--bg-panel-secondary);
    border-radius: 0.75rem;
    padding: 1rem;
    border: 1px solid var(--border-light);
}

.track-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.track {
    width: 100%;
    height: 48px;
    background: var(--bg-panel);
    border: 1px inset var(--border-light);
    border-radius: 0.5rem;
    position: relative;
    overflow: hidden;
}

.target-block {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 48px;
    background: linear-gradient(135deg, var(--grad-1), var(--grad-2));
    border-radius: 0.5rem;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateX(0);
    will-change: transform;
}

.target-block.linear {
    background: var(--text-muted);
}

/* Export Code Box */
.export-box {
    background: var(--bg-panel-secondary);
    border: 1px solid var(--border-light);
    border-radius: 0.75rem;
    overflow: hidden;
}

.export-header {
    background: rgba(0, 0, 0, 0.03);
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-light);
}

.code-block {
    position: relative;
    padding: 1rem;
    font-family: 'Fira Code', monospace;
    font-size: 0.875rem;
    color: var(--text-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.code-block code {
    flex: 1;
    word-break: break-all;
}

.btn-copy {
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
    color: var(--text-main);
    padding: 0.5rem;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    margin-left: 1rem;
}

.btn-copy:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-main);
    color: var(--bg-base);
    padding: 0.75rem 1.5rem;
    border-radius: 999px;
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 100;
    pointer-events: none;
    box-shadow: var(--shadow-lg);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}