/* CSS Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #252542;
    --text-primary: #ffffff;
    --text-secondary: #b0b0c0;
    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
    --border-color: #3a3a5c;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.3s ease;
}

html {
    scroll-behavior: smooth;
}

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

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

/* Header */
header {
    text-align: center;
    padding: 30px 0;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

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

/* Main Content */
main {
    flex: 1;
    display: grid;
    gap: 24px;
}

/* Preview Section */
.preview-section {
    width: 100%;
}

.gradient-preview {
    width: 100%;
    height: 300px;
    border-radius: var(--radius);
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.preview-label {
    position: absolute;
    top: 12px;
    left: 12px;
    background: rgba(0, 0, 0, 0.5);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--text-secondary);
    backdrop-filter: blur(4px);
}

/* Controls Section */
.controls-section {
    display: grid;
    gap: 24px;
}

.control-group {
    background: var(--bg-secondary);
    padding: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

.control-group h3 {
    font-size: 1.1rem;
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* Color Stops */
.color-stops-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.color-stop {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    flex-wrap: wrap;
}

.color-stop input[type="color"] {
    width: 50px;
    height: 40px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: transparent;
}

.color-stop input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.color-stop input[type="color"]::-webkit-color-swatch {
    border-radius: 4px;
    border: 2px solid var(--border-color);
}

.color-stop input[type="text"] {
    flex: 1;
    min-width: 100px;
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9rem;
}

.color-stop input[type="range"] {
    flex: 1;
    min-width: 80px;
}

.color-stop .position-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    min-width: 40px;
    text-align: right;
}

.color-stop .remove-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius-sm);
    color: #ef4444;
    cursor: pointer;
    transition: var(--transition);
    font-size: 1.2rem;
}

.color-stop .remove-btn:hover {
    background: rgba(239, 68, 68, 0.4);
}

/* Control Rows */
.control-row {
    margin-bottom: 16px;
}

.control-row:last-child {
    margin-bottom: 0;
}

.control-row label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.range-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.range-container span {
    min-width: 40px;
    text-align: right;
    font-family: 'Consolas', 'Monaco', monospace;
    color: var(--text-secondary);
}

/* Range Input Styling */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent-gradient);
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* Select Styling */
select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    outline: none;
    transition: border-color var(--transition);
}

select:hover, select:focus {
    border-color: var(--accent-primary);
}

/* Presets */
.presets-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.preset-btn {
    padding: 10px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
}

.preset-btn:hover {
    border-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.1);
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

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

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    width: 100%;
}

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

/* Output Section */
.output-section {
    background: var(--bg-secondary);
    padding: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

.output-section h3 {
    margin-bottom: 16px;
}

.code-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.code-tabs {
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}

.code-tab {
    padding: 8px 16px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
}

.code-tab:hover {
    color: var(--text-primary);
}

.code-tab.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.code-content {
    position: relative;
}

.code-block {
    display: none;
    background: var(--bg-primary);
    padding: 16px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    color: #e0e0e0;
    max-height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.code-block.active {
    display: block;
}

#copy-btn {
    align-self: flex-end;
}

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

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

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

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

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--accent-gradient);
    color: white;
    padding: 14px 28px;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 500;
    box-shadow: var(--shadow);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

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

/* Responsive Design */
@media (min-width: 768px) {
    .controls-section {
        grid-template-columns: repeat(2, 1fr);
    }

    .control-group:first-child {
        grid-column: 1 / -1;
    }

    .gradient-preview {
        height: 350px;
    }
}

@media (min-width: 1024px) {
    header h1 {
        font-size: 3rem;
    }

    main {
        grid-template-columns: 1fr 400px;
        grid-template-rows: auto auto;
    }

    .preview-section {
        grid-column: 1;
        grid-row: 1 / 3;
    }

    .gradient-preview {
        height: 100%;
        min-height: 500px;
    }

    .controls-section {
        grid-column: 2;
        grid-row: 1;
        display: flex;
        flex-direction: column;
    }

    .output-section {
        grid-column: 1 / -1;
    }
}

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

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

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

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

/* Animation for preview */
@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
