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

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #475569;
    --success: #22c55e;
    --graph-line: #6366f1;
    --graph-grid: #334155;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

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

header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

section {
    background: var(--surface);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
}

section h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

/* Controls Section */
.controls-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    align-items: end;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

input[type="number"],
select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.unit {
    color: var(--text-secondary);
    font-size: 0.875rem;
    white-space: nowrap;
}

.bezier-inputs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
}

.bezier-inputs input {
    padding: 0.5rem;
    text-align: center;
}

.button-group {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.98);
}

.btn.primary {
    background: var(--primary-color);
    color: white;
}

.btn.primary:hover {
    background: var(--primary-hover);
}

.btn.secondary {
    background: var(--secondary-color);
    color: white;
}

.btn.secondary:hover {
    background: var(--secondary-hover);
}

.btn.danger {
    background: var(--danger-color);
    color: white;
}

.btn.danger:hover {
    background: var(--danger-hover);
}

/* Visualization Section */
.visualization-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.visualization-container,
.animation-preview {
    background: var(--surface-light);
    border-radius: 8px;
    padding: 1rem;
}

.graph-wrapper {
    position: relative;
    aspect-ratio: 1;
    max-height: 300px;
}

#speed-graph {
    width: 100%;
    height: 100%;
}

.graph-labels {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.y-label {
    position: absolute;
    left: -30px;
    top: 50%;
    transform: rotate(-90deg) translateX(-50%);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.x-label {
    position: absolute;
    bottom: -25px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.preview-track {
    position: relative;
    height: 60px;
    background: var(--surface);
    border-radius: 30px;
    margin: 1rem 0;
    overflow: hidden;
}

.preview-ball {
    position: absolute;
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, var(--primary-color), #a855f7);
    border-radius: 50%;
    top: 5px;
    left: 5px;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.preview-ball.animating {
    animation: moveBall var(--duration) var(--timing-function) forwards;
}

@keyframes moveBall {
    from {
        left: 5px;
    }
    to {
        left: calc(100% - 55px);
    }
}

.time-indicator {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Comparison Section */
.comparison-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.comparison-graph-wrapper {
    background: var(--surface-light);
    border-radius: 8px;
    padding: 1rem;
    aspect-ratio: 2/1;
    max-height: 300px;
}

#comparison-graph {
    width: 100%;
    height: 100%;
}

.comparison-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.comparison-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--surface-light);
    border-radius: 20px;
    font-size: 0.875rem;
}

.comparison-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.comparison-remove {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    font-size: 1.2rem;
    line-height: 1;
    transition: color 0.2s;
}

.comparison-remove:hover {
    color: var(--danger-color);
}

/* Code Section */
.code-block {
    position: relative;
    background: var(--surface-light);
    border-radius: 8px;
    overflow: hidden;
}

#css-code {
    padding: 1rem;
    margin: 0;
    font-family: 'Fira Code', 'Monaco', 'Consolas', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--text-primary);
    overflow-x: auto;
}

.copy-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.5rem;
    background: var(--surface);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.copy-btn:hover {
    background: var(--primary-color);
}

.copy-btn.copied {
    background: var(--success);
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem 0 1rem;
    margin-top: 2rem;
    border-top: 1px solid var(--border-color);
}

footer p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

footer a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-container {
        padding: 1rem;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .subtitle {
        font-size: 0.9rem;
    }

    .visualization-section {
        grid-template-columns: 1fr;
    }

    .controls-section {
        grid-template-columns: 1fr;
    }

    .button-group {
        width: 100%;
    }

    .btn {
        flex: 1;
        text-align: center;
    }

    .bezier-inputs {
        grid-template-columns: repeat(2, 1fr);
    }

    .graph-wrapper {
        max-height: 250px;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.5rem;
    }

    section {
        padding: 1rem;
    }

    .bezier-inputs {
        grid-template-columns: 1fr 1fr;
    }

    .button-group {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

section {
    animation: fadeIn 0.3s ease-out;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--surface);
}

::-webkit-scrollbar-thumb {
    background: var(--secondary-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}
