/* ============================================
   Gradient Maker — Styles
   ============================================ */

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

:root {
    --primary: #6366F1;
    --secondary: #8B5CF6;
    --accent: #22D3EE;
    --bg: #0F1219;
    --bg-card: #171C28;
    --bg-elevated: #1E2433;
    --bg-input: #242B3A;
    --border: rgba(99, 102, 241, 0.15);
    --border-hover: rgba(99, 102, 241, 0.35);
    --text: #F1F3F8;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;
    --success: #4ADE80;
    --error: #FB7185;
    --radius: 12px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --transition: 250ms ease;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding: 1.5rem;
    background-image:
        radial-gradient(ellipse at 15% 0%, rgba(99, 102, 241, 0.07) 0%, transparent 50%),
        radial-gradient(ellipse at 85% 100%, rgba(34, 211, 238, 0.05) 0%, transparent 50%);
}

.app {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* --- Header --- */
.header {
    text-align: center;
    padding: 0.5rem 0;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
}

.logo-icon {
    animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {

    0%,
    100% {
        filter: drop-shadow(0 0 4px rgba(99, 102, 241, 0.4));
    }

    50% {
        filter: drop-shadow(0 0 12px rgba(99, 102, 241, 0.7));
    }
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    color: var(--text-secondary);
    font-size: 0.82rem;
    margin-top: 0.2rem;
}

/* --- Main Layout --- */
.main {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 1.25rem;
    align-items: start;
}

/* --- Preview --- */
.preview-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.preview-box {
    aspect-ratio: 16/10;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: linear-gradient(135deg, #6366F1, #22D3EE);
    position: relative;
    overflow: hidden;
    transition: background var(--transition), background-size 0.5s ease;
}

.preview-box.animating {
    animation: gradient-shift 4s ease infinite;
    background-size: 200% 200%;
}

@keyframes gradient-shift {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

.preview-label {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(8px);
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.8);
}

.preview-controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    user-select: none;
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.toggle-label input {
    display: none;
}

.toggle-switch {
    width: 32px;
    height: 18px;
    background: var(--bg-input);
    border-radius: 999px;
    position: relative;
    transition: var(--transition);
    border: 1px solid var(--border);
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: var(--transition);
}

.toggle-label input:checked+.toggle-switch {
    background: var(--primary);
    border-color: transparent;
}

.toggle-label input:checked+.toggle-switch::after {
    transform: translateX(14px);
    background: white;
}

.size-controls {
    flex: 1;
}

.size-controls label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.range-input {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: var(--bg-input);
    border-radius: 999px;
    outline: none;
}

.range-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 150ms ease;
}

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

/* --- Controls --- */
.controls-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

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

.control-group.hidden {
    display: none;
}

.control-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

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

/* Type Buttons */
.type-buttons {
    display: flex;
    gap: 0.4rem;
}

.type-btn {
    flex: 1;
    padding: 0.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
    font-family: var(--font);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.type-btn:hover {
    background: var(--bg-elevated);
    color: var(--text);
}

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

/* Angle */
.angle-control {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.angle-dial {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-input);
    border: 2px solid var(--border);
    position: relative;
    cursor: grab;
    transition: border-color var(--transition);
}

.angle-dial:hover,
.angle-dial:focus {
    border-color: var(--primary);
    outline: none;
}

.angle-needle {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2px;
    height: 40%;
    background: var(--primary);
    border-radius: 999px;
    transform-origin: bottom center;
    transform: translate(-50%, -100%) rotate(135deg);
    pointer-events: none;
}

.num-input {
    width: 60px;
    padding: 0.4rem 0.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.82rem;
    font-family: var(--font);
    text-align: center;
    outline: none;
    transition: border-color var(--transition);
}

.num-input:focus {
    border-color: var(--primary);
}

.unit {
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* Position */
.pos-control {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.pos-control label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.72rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.pos-control span {
    min-width: 30px;
    text-align: right;
    font-size: 0.72rem;
}

/* Color Stops */
.color-stops {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.color-stop {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.5rem;
    background: var(--bg-input);
    border-radius: 8px;
    border: 1px solid var(--border);
    transition: border-color var(--transition);
}

.color-stop:hover {
    border-color: var(--border-hover);
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    padding: 0;
    overflow: hidden;
}

.color-swatch::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-swatch::-webkit-color-swatch {
    border: none;
    border-radius: 6px;
}

.color-hex {
    width: 72px;
    padding: 0.3rem 0.4rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    outline: none;
    text-transform: uppercase;
}

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

.stop-pos {
    flex: 1;
}

.stop-pos-val {
    min-width: 28px;
    text-align: right;
    font-size: 0.68rem;
    color: var(--text-muted);
}

.remove-stop {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
    font-size: 1rem;
    transition: var(--transition);
}

.remove-stop:hover {
    background: rgba(251, 113, 133, 0.15);
    color: var(--error);
}

/* CSS Output */
.css-output {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    line-height: 1.6;
    color: var(--accent);
    white-space: pre-wrap;
    word-break: break-all;
    overflow: auto;
    max-height: 120px;
    outline: none;
}

/* Buttons */
.btn-sm {
    padding: 0.3rem 0.6rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 600;
    font-family: var(--font);
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-sm:hover {
    background: var(--primary);
    border-color: transparent;
    color: white;
}

.action-row {
    display: flex;
    gap: 0.5rem;
}

.btn-action {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.55rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    font-family: var(--font);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-action:hover {
    background: var(--bg-elevated);
    border-color: var(--border-hover);
    color: var(--text);
}

.btn-action:active {
    transform: scale(0.96);
}

.output-actions {
    display: flex;
    gap: 0.35rem;
}

/* --- Gallery --- */
.gallery-section,
.favorites-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.favorites-section.hidden {
    display: none;
}

.section-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}

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

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.75rem;
}

.gallery-item {
    aspect-ratio: 16/10;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
    position: relative;
    overflow: hidden;
}

.gallery-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.gallery-item:active {
    transform: scale(0.97);
}

.gallery-item-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.35rem 0.5rem;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    font-size: 0.68rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.85);
    opacity: 0;
    transform: translateY(100%);
    transition: var(--transition);
}

.gallery-item:hover .gallery-item-name {
    opacity: 1;
    transform: translateY(0);
}

/* --- Toast --- */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    padding: 0.6rem 1.2rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    color: var(--text);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(12px);
    opacity: 0;
    transition: 350ms cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 100;
    pointer-events: none;
}

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

/* --- Responsive --- */
@media (max-width: 840px) {
    .main {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    body {
        padding: 1rem;
    }

    .preview-controls {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }

    .action-row {
        flex-wrap: wrap;
    }

    .gallery {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    }
}