/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-dark: #0f172a;
    --bg-surface: #1e293b;
    --bg-surface-hover: #253349;
    --accent: #60a5fa;
    --accent-strong: #3b82f6;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-dim: #64748b;
    --border: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.12);
    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --transition: 0.2s ease;
}

html {
    font-size: 14px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--text-dim);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ===== Top Bar ===== */
.top-bar {
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 50%, #7c3aed 100%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.4);
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.top-bar-left,
.top-bar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.top-bar-center {
    display: flex;
    align-items: center;
}

/* Gradient type tabs */
.gradient-type-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.25);
    border-radius: var(--radius);
    padding: 3px;
    gap: 2px;
}

.type-tab {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    padding: 6px 18px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--transition);
}

.type-tab:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.type-tab.active {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

/* Action buttons */
.action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #fff;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    transition: var(--transition);
    white-space: nowrap;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ===== Main Layout ===== */
.main-layout {
    display: flex;
    min-height: calc(100vh - 56px);
}

.content-area {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* ===== Gradient Preview ===== */
.preview-section {
    padding: 20px 24px 0;
}

.gradient-preview {
    position: relative;
    width: 100%;
    height: 45vh;
    min-height: 280px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.checkerboard-bg {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(45deg, #2a2a3a 25%, transparent 25%),
        linear-gradient(-45deg, #2a2a3a 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #2a2a3a 75%),
        linear-gradient(-45deg, transparent 75%, #2a2a3a 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
    opacity: 0.3;
}

.gradient-display {
    position: absolute;
    inset: 0;
    transition: background 0.15s ease;
}

/* ===== Color Stop Bar ===== */
.stop-bar-section {
    padding: 12px 24px 0;
}

.stop-bar-container {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px 10px;
}

.stop-bar-track {
    position: relative;
    height: 28px;
    border-radius: 14px;
    cursor: crosshair;
    border: 1px solid var(--border-light);
    overflow: visible;
}

.stop-bar-gradient {
    position: absolute;
    inset: 0;
    border-radius: 14px;
}

.stop-handles {
    position: absolute;
    inset: 0;
}

.stop-handle {
    position: absolute;
    top: 50%;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 3px solid #fff;
    transform: translate(-50%, -50%);
    cursor: grab;
    z-index: 2;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(0, 0, 0, 0.2);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.stop-handle:hover {
    transform: translate(-50%, -50%) scale(1.15);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6), inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.stop-handle.active {
    transform: translate(-50%, -50%) scale(1.2);
    box-shadow: 0 0 0 3px var(--accent), 0 2px 8px rgba(0, 0, 0, 0.6);
    z-index: 3;
}

.stop-handle.dragging {
    cursor: grabbing;
}

.stop-bar-hint {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.72rem;
    margin-top: 8px;
}

/* ===== Controls Section ===== */
.controls-section {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
    padding: 16px 24px;
}

.control-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
}

.panel-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 14px;
}

.type-controls {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.type-controls.hidden {
    display: none;
}

.control-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.control-row {
    margin-bottom: 12px;
}

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

/* Angle controls */
.angle-input-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.angle-wheel-container {
    flex-shrink: 0;
}

.angle-wheel {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid var(--border-light);
    background: var(--bg-dark);
    position: relative;
    cursor: pointer;
}

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

.angle-needle::after {
    content: '';
    position: absolute;
    top: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
}

/* Slider */
.slider {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: var(--bg-dark);
    outline: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-dark);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-dark);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.slider-input-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Number input */
.num-input {
    width: 50px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    text-align: center;
    outline: none;
}

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

.angle-value-box {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.unit {
    color: var(--text-dim);
    font-size: 0.75rem;
}

/* Direction grid */
.direction-grid,
.position-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.dir-btn,
.pos-btn,
.cpos-btn {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1rem;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.dir-btn:hover:not(:disabled),
.pos-btn:hover,
.cpos-btn:hover {
    background: var(--bg-surface-hover);
    border-color: var(--accent);
    color: var(--accent);
}

.dir-btn.active,
.pos-btn.active,
.cpos-btn.active {
    background: rgba(59, 130, 246, 0.15);
    border-color: var(--accent);
    color: var(--accent);
}

.dir-btn:disabled {
    cursor: default;
    opacity: 0.4;
}

.dir-center {
    font-size: 1.4rem;
    line-height: 1;
}

/* Toggle group */
.toggle-group {
    display: flex;
    background: var(--bg-dark);
    border-radius: var(--radius-sm);
    padding: 2px;
    gap: 2px;
}

.toggle-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-dim);
    padding: 5px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 500;
    transition: var(--transition);
}

.toggle-btn:hover {
    color: var(--text-secondary);
}

.toggle-btn.active {
    background: var(--accent-strong);
    color: #fff;
}

/* Select input */
.select-input {
    width: 100%;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.8rem;
    outline: none;
    cursor: pointer;
}

.select-input:focus {
    border-color: var(--accent);
}

.select-input option {
    background: var(--bg-dark);
}

/* ===== Stop Details ===== */
.stop-details {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stop-detail-row {
    display: flex;
    flex-direction: column;
}

.color-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-picker {
    -webkit-appearance: none;
    appearance: none;
    width: 36px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: none;
    padding: 2px;
}

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

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

.hex-input {
    flex: 1;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-family: 'Courier New', monospace;
    font-size: 0.82rem;
    outline: none;
}

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

.delete-stop-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.25);
    color: #f87171;
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 500;
    transition: var(--transition);
}

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

/* Size inputs */
.size-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
}

.size-x {
    color: var(--text-dim);
    font-size: 0.78rem;
}

/* ===== Presets Gallery ===== */
.presets-section {
    padding: 0 24px 16px;
}

.presets-gallery {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 8px;
}

.preset-swatch {
    flex-shrink: 0;
    width: 72px;
    height: 48px;
    border-radius: var(--radius);
    cursor: pointer;
    border: 2px solid transparent;
    transition: var(--transition);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.preset-swatch:hover {
    transform: scale(1.08);
    border-color: var(--accent);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* ===== CSS Output ===== */
.css-output-section {
    padding: 0 24px 24px;
}

.css-output-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.css-output-header .panel-title {
    margin-bottom: 0;
}

.css-output-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.vendor-prefix-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-dim);
    font-size: 0.78rem;
    cursor: pointer;
}

.vendor-prefix-toggle input[type="checkbox"] {
    accent-color: var(--accent-strong);
    cursor: pointer;
}

.copy-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--accent-strong);
    border: none;
    color: #fff;
    padding: 7px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    transition: var(--transition);
}

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

.copy-btn.copied {
    background: #22c55e;
}

.css-output {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    overflow-x: auto;
    margin: 0;
}

.css-output code {
    font-family: 'Courier New', 'Fira Code', monospace;
    font-size: 0.82rem;
    line-height: 1.7;
    color: var(--text-primary);
    white-space: pre;
}

/* Syntax highlighting classes */
.css-prop {
    color: #7dd3fc;
}
.css-value {
    color: #c4b5fd;
}
.css-func {
    color: #fbbf24;
}
.css-color-val {
    color: #34d399;
}
.css-number {
    color: #fb923c;
}
.css-punct {
    color: var(--text-dim);
}
.css-comment {
    color: var(--text-dim);
    font-style: italic;
}

/* ===== History Panel ===== */
.history-panel {
    width: 220px;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.3s ease, opacity 0.3s ease;
}

.history-panel.hidden {
    width: 0;
    overflow: hidden;
    opacity: 0;
    border: none;
    padding: 0;
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.history-header .panel-title {
    margin-bottom: 0;
}

.clear-history-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: var(--transition);
    display: flex;
    align-items: center;
}

.clear-history-btn:hover {
    color: #f87171;
    background: rgba(239, 68, 68, 0.1);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.history-item {
    width: 100%;
    height: 48px;
    border-radius: var(--radius);
    cursor: pointer;
    border: 2px solid transparent;
    transition: var(--transition);
    flex-shrink: 0;
}

.history-item:hover {
    border-color: var(--accent);
    transform: scale(1.03);
}

/* ===== Fullscreen Overlay ===== */
.fullscreen-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    transition: opacity 0.3s ease;
}

.fullscreen-overlay.hidden {
    display: none;
}

.exit-fullscreen-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    z-index: 10000;
}

.exit-fullscreen-btn:hover {
    background: rgba(0, 0, 0, 0.7);
}

/* ===== Hidden utility ===== */
.hidden {
    display: none !important;
}

/* Override for panels that use flex */
.history-panel.hidden {
    display: flex !important;
    width: 0;
    overflow: hidden;
    opacity: 0;
    border: none;
    padding: 0;
}

/* ===== Responsive ===== */
@media (max-width: 1100px) {
    .controls-section {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 768px) {
    .top-bar {
        flex-wrap: wrap;
        height: auto;
        padding: 10px 16px;
        gap: 8px;
    }

    .top-bar-right .action-btn span {
        display: none;
    }

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

    .preview-section {
        padding: 12px 16px 0;
    }

    .gradient-preview {
        height: 35vh;
        min-height: 200px;
    }

    .stop-bar-section {
        padding: 12px 16px 0;
    }

    .presets-section,
    .css-output-section {
        padding: 0 16px 16px;
    }

    .history-panel {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        z-index: 200;
        box-shadow: -4px 0 24px rgba(0, 0, 0, 0.5);
    }
}
