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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f9fafb;
    min-height: 100vh;
    padding: 10px;
    color: #1f2937;
    /* Removed flex display from body */
}

.app-layout {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px 0;
}

.header-section {
    text-align: center;
    margin-bottom: 30px;
}

.mode-view {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.main-panel {
    flex: 1;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 25px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    min-width: 0;
    /* Prevent flex overflow */
}

.palette-panel {
    width: 280px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    height: fit-content;
    max-height: calc(100vh - 20px);
    overflow-y: auto;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.palette-panel.collapsed {
    transform: translateX(-240px);
    opacity: 0.7;
}

/* hidden on desktop */
.panel-toggle {
    display: none;
}

/* Mobile Presets (Hidden on Desktop) */
.mobile-presets {
    display: none;
}

.preset-chip {
    white-space: nowrap;
    padding: 8px 16px;
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
    border-radius: 9999px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.preset-chip.active {
    background: #3b82f6;
    color: white;
    border-color: #3b82f6;
    box-shadow: 0 2px 5px rgba(59, 130, 246, 0.3);
}

.preset-chip.more-btn {
    background: white;
    border: 1px dashed #cbd5e1;
    color: #64748b;
}

.palette-section {
    margin-bottom: 25px;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 12px;
    padding-bottom: 6px;
    border-bottom: 2px solid #e2e8f0;
}

.palette-button {
    width: 100%;
    padding: 12px 20px;
    margin-bottom: 8px;
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 9999px;
    /* Rounded full */
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    font-weight: 600;
    /* Semibold */
    color: #475569;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    /* Shadow lg-ish */
}

.palette-button:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    transform: translateX(5px);
}

.palette-button.active {
    background: #22c55e;
    color: white;
    border-color: #22c55e;
}

/* Old container class removed or aliased if needed, but we use main-panel now */
.container {
    flex: 1;
}

h1 {
    text-align: center;
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 10px;
    background: linear-gradient(to right, #3b82f6, #2563eb);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    text-align: center;
    color: #64748b;
    margin-bottom: 20px;
    font-size: 1.1rem;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 15px;
}

.control-group {
    background: #f8fafc;
    padding: 20px;
    border-radius: 15px;
    border: 1px solid #e2e8f0;
}

.control-group h3 {
    margin-bottom: 15px;
    color: #1e293b;
    font-weight: 600;
}

.control-row {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    gap: 10px;
}

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

label {
    min-width: 80px;
    font-weight: 500;
    color: #475569;
}

input[type="range"] {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #e2e8f0;
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.3);
}

input[type="number"] {
    width: 40px;
    max-width: 50px;
    padding: 6px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    text-align: center;
    background: white;
    flex-shrink: 0;
    appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.mode-tabs {
    display: inline-flex;
    background: #e2e8f0;
    padding: 4px;
    border-radius: 9999px;
    margin-top: 20px;
    gap: 0;
}

.mode-tab {
    flex: 1;
    padding: 10px 15px;
    background: transparent;
    border: none;
    border-radius: 9999px;
    color: #64748b;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-tab.active {
    background: white;
    color: #0f172a;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.mode-tab.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: transparent !important;
    box-shadow: none !important;
}

/* ===== SEQUENTIAL MODE STYLES ===== */

.color-stops-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 15px;
}

.color-stop-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    transition: all 0.2s ease;
}

.color-stop-row:hover {
    border-color: #cbd5e1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.color-stop-row.dragging {
    opacity: 0.5;
    border-style: dashed;
}

.stop-label {
    font-weight: 600;
    color: #64748b;
    font-size: 0.85rem;
    min-width: 50px;
}

.color-stop-row input[type="color"] {
    width: 50px;
    height: 36px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    padding: 0;
    background: none;
}

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

.color-stop-row input[type="color"]::-webkit-color-swatch {
    border: 2px solid #e2e8f0;
    border-radius: 6px;
}

.color-stop-row input[type="text"] {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-family: monospace;
    font-size: 0.9rem;
    text-transform: uppercase;
    max-width: 100px;
}

.remove-stop-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: #fee2e2;
    color: #dc2626;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.remove-stop-btn:hover {
    background: #fecaca;
}

.remove-stop-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.add-stop-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    background: white;
    border: 2px dashed #cbd5e1;
    border-radius: 12px;
    color: #64748b;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.add-stop-btn:hover {
    border-color: #3b82f6;
    color: #3b82f6;
    background: #eff6ff;
}

.add-stop-btn span {
    font-size: 1.3rem;
    font-weight: 400;
}

.gradient-preview {
    height: 60px;
    border-radius: 15px;
    margin: 15px 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    background: linear-gradient(to right, #3b82f6, #f59e0b);
}

/* ===== FROM IMAGE MODE STYLES ===== */

.image-upload-area {
    background: #f8fafc;
    border: 2px dashed #cbd5e1;
    border-radius: 15px;
    margin-bottom: 20px;
    transition: all 0.3s ease;
    overflow: hidden;
}

.image-upload-area.drag-over {
    border-color: #3b82f6;
    background: #eff6ff;
}

.upload-prompt {
    padding: 40px 20px;
    text-align: center;
}

.upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    cursor: pointer;
    color: #64748b;
}

.upload-label:hover {
    color: #3b82f6;
}

.upload-icon {
    width: 48px;
    height: 48px;
    stroke: currentColor;
}

.upload-text {
    font-size: 1.1rem;
    font-weight: 600;
}

.upload-hint {
    font-size: 0.85rem;
    color: #94a3b8;
}

.image-preview-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #1e293b;
    min-height: 200px;
    max-height: 400px;
    overflow: hidden;
}

.canvas-wrapper {
    position: relative;
    display: inline-block;
}

.canvas-wrapper canvas {
    display: block;
    max-width: 100%;
    max-height: 400px;
}

#colorMarkersCanvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.click-hint {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.8rem;
    white-space: nowrap;
}

/* Toggle Switch Styles */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #f1f5f9;
}

.toggle-row:last-child {
    border-bottom: none;
}

.toggle-label {
    font-weight: 500;
    color: #475569;
    font-size: 0.9rem;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    transition: 0.3s;
    border-radius: 26px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked+.toggle-slider {
    background-color: #22c55e;
}

.toggle-switch input:checked+.toggle-slider:before {
    transform: translateX(22px);
}

/* Reset Button */
.reset-btn {
    padding: 15px 25px;
    background: white;
    color: #64748b;
    border: 2px solid #e2e8f0;
    border-radius: 9999px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.reset-btn:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

/* Color Marker Styles (drawn on canvas, but define for reference) */
.color-marker {
    width: 24px;
    height: 24px;
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.advanced-settings {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 15px;
    padding: 15px 20px;
    margin-bottom: 15px;
}

.advanced-settings summary {
    font-weight: 600;
    color: #475569;
    cursor: pointer;
    list-style: none;
    /* Hide default arrow */
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.advanced-settings summary span {
    font-size: 1.2rem;
    filter: grayscale(1);
    transition: transform 0.2s ease;
}

.advanced-settings[open] summary span {
    transform: rotate(45deg);
}

.advanced-settings[open] summary {
    margin-bottom: 15px;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 10px;
}

.generate-btn {
    width: 100%;
    padding: 15px;
    background: #22c55e;
    color: white;
    border: none;
    border-radius: 9999px;
    /* Rounded full */
    font-size: 1.1rem;
    font-weight: 600;
    /* Semibold */
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 10px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    /* Shadow lg */
}

.export-controls {
    background: #f8fafc;
    padding: 10px;
    border-radius: 15px;
    border: 1px solid #e2e8f0;
    margin-bottom: 20px;
}

.export-btn {
    padding: 10px 16px;
    background: white;
    color: #475569;
    border: 2px solid #e2e8f0;
    border-radius: 9999px;
    /* Rounded full */
    font-weight: 600;
    /* Semibold */
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 120px;
    box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.1);
}

.export-btn:hover {
    background: #22c55e;
    color: white;
    border-color: #22c55e;
    transform: translateY(-1px);
}

.generate-btn:hover {
    background: #16a34a;
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(34, 197, 94, 0.3);
}

.color-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
    margin-top: 10px;
}

app-color-swatch {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    /* border-radius: 15px;  -- Managed by component or attribute usually, but host styles can override if container allows */
    transition: all 0.3s ease;
    /* box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); -- Component likely has its own shadow */
}

app-color-swatch:hover {
    transform: translateY(-5px);
    z-index: 10;
}

/* .color-label styles removed as they are internal to app-color-swatch shadow DOM */

.info-panel {
    background: #f1f5f9;
    padding: 20px;
    border-radius: 15px;
    margin-top: 20px;
    border-left: 4px solid #667eea;
}

.info-panel h4 {
    margin-bottom: 10px;
    color: #1e293b;
}

.info-panel p {
    color: #64748b;
    line-height: 1.6;
}

.copied-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #10b981;
    color: white;
    padding: 12px 20px;
    border-radius: 10px;
    transform: translateX(300px);
    transition: transform 0.3s ease;
    z-index: 1000;
}

.copied-toast.show {
    transform: translateX(0);
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 900;
}

.overlay.show {
    opacity: 1;
    pointer-events: auto;
}


/* Mobile/tablet drawer style */
@media (max-width: 1024px) {
    .mode-view {
        flex-direction: column;
    }

    .palette-panel {
        position: fixed;
        top: 0;
        left: -100%;
        width: 80%;
        max-width: 320px;
        height: 100%;
        background: rgba(255, 255, 255, 0.98);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
        border-radius: 0;
        padding: 20px;
        overflow-y: auto;
        transition: left 0.3s ease;
        z-index: 1000;
    }

    .palette-panel.show {
        left: 0;
    }

    .panel-toggle {
        display: none !important;
        /* Hidden on mobile, effectively replaced by the 'More' chip */
    }

    .main-panel {
        padding-bottom: 80px;
        /* Give space for scrolling past the sticky button */
    }

    .panel-toggle:active {
        transform: scale(0.95);
    }

    .panel-toggle.hide {
        display: none;
    }

    /* Show Mobile Presets */
    .mobile-presets {
        display: flex !important;
        /* Force show */
        gap: 10px;
        overflow-x: auto;
        padding-bottom: 10px;
        margin-bottom: 15px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        /* Firefox */
    }

    .mobile-presets::-webkit-scrollbar {
        display: none;
        /* Chrome/Safari */
    }

    .generate-btn {
        position: sticky;
        /* Keep sticky generate */
        bottom: 0px;
        margin-bottom: 10px;
        /* Add spacing so it doesn't touch the grid */
        z-index: 500;
        border-radius: 15px;
        /* Slightly less round when full width */
    }

    .color-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 10px;
        margin-bottom: 15px;
        margin-top: 10px;
        /* Ensure gap from the sticky button */
    }

    /* Sequential Mode Mobile */
    .color-stop-row {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px;
    }

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

    .gradient-preview {
        height: 50px;
    }

    .add-stop-btn {
        padding: 10px 15px;
    }

    /* From Image Mode Mobile */
    .image-preview-container {
        max-height: 300px;
    }

    .canvas-wrapper canvas {
        max-height: 300px;
    }

    .upload-prompt {
        padding: 30px 15px;
    }

    .upload-icon {
        width: 40px;
        height: 40px;
    }

    .click-hint {
        font-size: 0.7rem;
        padding: 6px 12px;
    }

    .reset-btn {
        padding: 12px 20px;
        font-size: 0.9rem;
    }
}

/* Mobile-specific adjustments */
@media (max-width: 640px) {
    .header-section h1 {
        font-size: 1.8rem;
        line-height: 1.2;
        padding: 0 10px;
        overflow-wrap: break-word;
        /* Ensure long words don't overflow */
    }

    .subtitle {
        padding: 0 15px;
    }

    .mode-tabs {
        display: flex;
        /* Override inline-flex */
        flex-wrap: wrap;
        width: auto;
        margin: 0 15px;
        border-radius: 15px;
        padding: 4px;
        gap: 4px;
    }

    .mode-tab {
        flex: 1 1 auto;
        /* Force 2 per row mostly, or 1 if very narrow */
        font-size: 0.9rem;
        padding: 10px;
        text-align: center;
        margin-bottom: 0;
    }

    .main-panel {
        padding: 15px;
        width: 100%;
        /* Ensure it doesn't exceed parent */
    }

    /* Force container constraints */
    .container,
    .app-layout {
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Ensure flex containers wrap */
    .control-row {
        flex-wrap: wrap;
    }

    .control-row label {
        width: 100%;
        margin-bottom: 8px;
    }

    .color-space-mini-toggle {
        flex-direction: column;
        align-items: flex-start;
    }

    .color-space-mini-toggle select {
        width: 100%;
        margin-top: 5px;
    }

    /* Fix export buttons */
    .export-controls {
        width: 100%;
        overflow-x: hidden;
    }

    .export-controls div {
        flex-direction: column;
        /* Stack buttons vertically on mobile for better touch targets */
        width: 100%;
    }

    .export-btn {
        width: 100%;
        text-align: center;
    }

    /* Ensure Generate Button fits */
    .generate-btn {
        width: 100%;
        box-sizing: border-box;
        /* verified globally, but good to be same */
        border-radius: 12px;
    }

    /* Mobile Presets */
    .mobile-presets {
        width: 100%;
        max-width: 100vw;
        box-sizing: border-box;
    }
}