/* =========================================
   1. VARIABLES & THEMES
   ========================================= */
:root {
    /* Shared settings */
    --primary-accent: #6366f1;
    --font-heading: 'Space Grotesk', sans-serif;
    --font-body: 'Inter', sans-serif;

    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2.5rem;

    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1);

    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);

    /* Dynamic Palette Defaults */
    --c-1: #6366f1;
    --c-2: #8b5cf6;
    --c-3: #d946ef;
    --c-4: #06b6d4;
    --c-5: #10b981;
    --text-c-1: #ffffff;
    --text-c-2: #ffffff;
    --text-c-3: #ffffff;
    --text-c-4: #000000;
    --text-c-5: #000000;
}

/* Dark Theme (Default) */
.theme-dark {
    --bg-body: #0f1219;
    --bg-surface: #1a1f2b;
    --bg-surface-glass: rgba(26, 31, 43, 0.85);
    --bg-element: #2d3342;
    --text-primary: #ffffff;
    --text-secondary: #9ca3af;
    --border-color: rgba(255, 255, 255, 0.08);
}

/* Light Theme */
.theme-light {
    --bg-body: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-glass: rgba(255, 255, 255, 0.85);
    --bg-element: #e2e8f0;
    --text-primary: #5B4B55;
    --text-secondary: #64748b;
    --border-color: rgba(0, 0, 0, 0.08);
}

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

body {
    background-color: var(--bg-body);
    color: var(--text-primary);
    font-family: var(--font-body);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

button {
    font-family: inherit;
    border: none;
    background: none;
    cursor: pointer;
    color: inherit;
}

/* =========================================
   2. LAYOUT
   ========================================= */
.app-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--spacing-sm);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

/* =========================================
   3. HEADER
   ========================================= */
.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-sm) 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    font-size: 1.8rem;
    color: var(--c-1);
}

.brand-text h1 {
    font-family: var(--font-heading);
    font-size: 1.4rem;
    font-weight: 700;
}

.icon-btn-large {
    padding: 0.5rem;
    border-radius: 50%;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    display: grid;
    place-items: center;
    transition: transform var(--transition-fast);
}

.icon-btn-large:hover {
    transform: rotate(15deg) scale(1.1);
}

/* =========================================
   4. PALETTE CONTAINER
   ========================================= */
.palette-container {
    display: grid;
    grid-template-columns: repeat(var(--total-colors, 5), 1fr);
    gap: var(--spacing-sm);
    min-height: 300px;
}

.color-card {
    background: var(--bg-surface);
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    transition: transform var(--transition-bounce), box-shadow 0.3s ease;
}

.color-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-lg);
    z-index: 5;
}

.color-swatch-area {
    flex: 1;
    min-height: 180px;
    background-color: var(--bg-element);
    position: relative;
    transition: background-color 0.4s ease;
}

/* Dynamic Colors binding - now handled via style attribute or nth-child if preferred, 
   but since we generate them we can use CSS variables directly on elements */
.color-card .color-swatch-area {
    background-color: var(--card-color);
    color: var(--card-text);
}

.color-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
    background: rgba(0, 0, 0, 0.1);
}

.color-card:hover .color-overlay,
.color-card.locked .color-overlay {
    opacity: 1;
}

.color-card.locked .color-overlay {
    background: transparent;
    /* No dimming when just locked */
}

.action-btn {
    background: rgba(255, 255, 255, 0.9);
    color: #000;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transform: scale(0.8);
    transition: transform 0.2s ease;
}

.color-card.locked .action-btn[title="Lock Color"] {
    background: var(--c-1);
    color: white;
}

.action-btn:hover {
    transform: scale(1);
}

.color-details {
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-surface);
}

.hex-input {
    font-family: monospace;
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    background: transparent;
    border: 1px solid transparent;
    color: inherit;
    width: 100px;
    padding: 2px 4px;
    border-radius: 4px;
    transition: border-color 0.2s;
}

.hex-input:focus {
    outline: none;
    border-color: var(--primary-accent);
    background: var(--bg-element);
}

.copy-btn {
    color: var(--text-secondary);
    padding: 4px;
    border-radius: 4px;
    transition: 0.2s;
}

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


/* =========================================
   5. STICKY CONTROLS
   ========================================= */
.sticky-controls {
    position: sticky;
    top: 1rem;
    z-index: 100;
    padding: 0 var(--spacing-xs);
    /* Slight breathing room */
}

.controls-inner {
    background: var(--bg-surface-glass);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    border-radius: 16px;
    padding: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    transition: background-color 0.3s ease;
}

.input-group {
    display: flex;
    align-items: center;
    background: var(--bg-element);
    padding: 0.25rem 1rem;
    border-radius: 10px;
    gap: 0.5rem;
    flex: 1;
    max-width: 300px;
}

.select-icon {
    color: var(--text-secondary);
}

select,
#color-count {
    background: transparent;
    border: none;
    color: var(--text-primary);
    flex: 1;
    font-family: inherit;
    font-size: 1rem;
    padding: 0.5rem 0;
    cursor: pointer;
    outline: none;
}

#color-count {
    width: 40px;
    flex: none;
    text-align: center;
    font-weight: 600;
}

.input-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
}

/* Explicitly setting option colors for visibility */
select option {
    background-color: var(--bg-surface);
    color: var(--text-primary);
}

.btn-primary {
    background: var(--text-primary);
    /* Invert logic usually pop */
    color: var(--bg-body);
    font-weight: 700;
    padding: 0.75rem 2rem;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-heading);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.theme-dark .btn-primary {
    background: linear-gradient(135deg, #fff, #e2e8f0);
    color: #000;
}

.theme-light .btn-primary {
    background: #0f172a;
    color: #fff;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

/* =========================================
   6. UI PREVIEW
   ========================================= */
.ui-preview-section {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    padding-bottom: 4rem;
}

.section-header {
    text-align: center;
    margin-top: 2rem;
}

.section-header h2 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.section-header p {
    color: var(--text-secondary);
}

/* Glass Panel Utility */
.glass-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 2rem;
    overflow: hidden;
    transition: background-color 0.3s ease;
}

.widget-info {
    display: flex;
    flex-direction: row;
    align-content: center;
    justify-content: space-between;
}

/* Hero Section */
.preview-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 400px;
    background: linear-gradient(135deg, var(--bg-surface) 0%, var(--bg-element) 100%);
    position: relative;
    padding: 4rem;
}

.hero-content {
    z-index: 2;
    max-width: 50%;
}

.hero-title {
    font-size: 3rem;
    line-height: 1.1;
    margin-bottom: 1rem;
}

.hero-text {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 1.1rem;
}

.hero-actions {
    display: flex;
    gap: 1rem;
}

.hero-btn {
    padding: 0.8rem 1.5rem;
    border-radius: 12px;
    font-weight: 600;
    cursor: default;
    /* Avoid interaction confusion */
}

.hero-btn.primary {
    background: var(--c-1);
    color: var(--text-c-1);
}

.hero-btn.secondary {
    border: 2px solid var(--border-color);
    color: var(--text-primary);
}

.hero-visual {
    position: relative;
    width: 50%;
    max-width: 600px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#svg-container {
    width: 100%;
    height: auto;
    filter: drop-shadow(0 20px 40px rgba(0, 0, 0, 0.2));
    animation: fadeIn 1s ease 0.5s backwards;
}

#svg-container svg {
    display: block;
    width: 100%;
    height: auto;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes float {

    0%,
    100% {
        transform: translate(0, 0);
    }

    50% {
        transform: translate(10px, -20px);
    }
}

/* Grid Layout for Cards */
.preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
}

/* Preview Card */
.preview-card-header {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.avatar-circle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--c-3);
}

.lines {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    justify-content: center;
}

.line {
    height: 8px;
    background: var(--bg-element);
    border-radius: 4px;
}

.line.short {
    width: 60%;
}

.preview-card-body {
    margin-bottom: 2rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.demo-btn {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-weight: 500;
}

.demo-btn.primary {
    background: var(--c-5);
    color: var(--text-c-5);
}

.demo-btn.ghost {
    color: var(--text-secondary);
}

/* Preview Widget */
.chart-area {
    height: 150px;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding-bottom: 20px;
}

.bar {
    flex: 1;
    border-radius: 5px 5px 0 0;
    background: var(--bg-element);
    transition: height 0.3s ease, background-color 0.3s ease;
}

.stat-badge {
    background: var(--bg-element);
    padding: 4px 12px;
    border-radius: 20px;
    color: var(--c-5);
    font-weight: bold;
}

/* =========================================
   7. RESPONSIVE DESIGN
   ========================================= */
@media (max-width: 900px) {
    .palette-container {
        grid-template-columns: repeat(2, 1fr);
    }

    .color-card:nth-last-child(1):nth-child(odd) {
        grid-column: span 2;
    }

    .preview-hero {
        flex-direction: column;
        padding: 2rem;
        text-align: center;
        gap: 2rem;
    }

    .hero-content {
        max-width: 100%;
    }

    .hero-actions {
        justify-content: center;
    }

    .hero-visual {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
        max-width: 100%;
        height: auto;
        margin-top: 1rem;
    }
}

@media (max-width: 600px) {
    .palette-container {
        display: flex;
        flex-direction: column;
    }

    .color-swatch-area {
        min-height: 120px;
    }

    .controls-inner {
        flex-direction: column;
        padding: 1rem;
    }

    .input-group,
    .btn-primary {
        width: 100%;
    }

    .hero-title {
        font-size: 2rem;
    }
}

/* =========================================
   8. TOAST NOTIFICATION
   ========================================= */
.toast-notification {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.75rem 1.5rem;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.27, 1.55);
    z-index: 1000;
}

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

.toast-notification .material-icons-round {
    color: var(--c-5);
    /* Success Color */
}

/* =========================================
   9. PREVIEW INTERACTIONS
   ========================================= */
.color-interactive {
    cursor: pointer;
    /* Removed transition for instant effect */
}

.color-interactive:hover {
    transform: scale(1.05);
    z-index: 10;
}

.preview-tooltip {
    position: fixed;
    background: var(--bg-surface);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: monospace;
    font-weight: 700;
    pointer-events: none;
    opacity: 0;
    /* Removed transition for instant appearance */
    z-index: 9999;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    transform: translate(-50%, -150%);
    /* Center above cursor */
    text-transform: uppercase;
}