.d2-coins-pulsing {
    animation: d2CoinsPulse 1.3s ease-in-out infinite;
}

@keyframes d2CoinsPulse {
    0% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(255,215,0,0)); }
    50% { transform: scale(1.12); filter: drop-shadow(0 0 6px rgba(58, 14, 109, 0.55)); }
    100% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(255,215,0,0)); }
}
/* Enhanced AI Designer Styles */
.d2-enhanced-container {
    margin: 20px 0 30px 0;
    padding: 25px;
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    border: 2px solid #e1e4e8;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    position: relative;
    overflow: hidden;
}

.d2-enhanced-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    border-radius: 16px 16px 0 0;
}

.d2-header {
    text-align: center;
    margin-bottom: 25px;
    padding-top: 20px;
}

.d2-header h3 {
    margin: 0 0 8px 0;
    color: #2c3e50;
    font-size: 24px;
    font-weight: 700;
}

.d2-header p {
    margin: 0;
    color: #7f8c8d;
    font-size: 15px;
    font-weight: 500;
}

.d2-style-presets {
    margin-bottom: 20px;
}

.d2-style-presets h4 {
    margin: 0 0 12px 0;
    color: #34495e;
    font-size: 16px;
    font-weight: 600;
}

.d2-presets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
    margin-bottom: 15px;
}

/* Screen Reader Only Class */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Enhanced Card Expansion Styles */
.d2-preset-button {
    padding: 12px 16px;
    border: 2px solid #e1e4e8;
    border-radius: 10px;
    background: #ffffff;
    color: #2c3e50;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px; /* match tighter icon-label spacing like FPD main nav */
    position: relative;
    overflow: hidden;
    min-height: 70px;
    max-height: 70px;
}

.d2-preset-button:hover {
    border-color: #667eea;
    background: #f8f9ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

.d2-enhanced-container .d2-presets-grid .d2-preset-button.active {
    border-color: #667eea;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
    transform: translateY(-2px);
}

.d2-enhanced-container .d2-presets-grid .d2-preset-button.active .d2-preset-icon,
.d2-enhanced-container .d2-presets-grid .d2-preset-button.active .d2-preset-name {
    color: white;
}

/* Background toggle button - ON state uses purple gradient; OFF handled below */
#d2-background-toggle-button {
    border-color: #667eea !important;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
    box-shadow: none !important;
    transform: none !important;
    /* Match height/spacing of the other two buttons */
    padding: 14px 24px !important;
    min-height: 48px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

#d2-background-toggle-button .d2-preset-icon,
#d2-background-toggle-button .d2-preset-name {
    color: white !important;
}

#d2-background-toggle-button:hover {
    background: linear-gradient(135deg, #5a6fd8 0%, #6b4d94 100%) !important;
    box-shadow: none !important;
    transform: none !important;
    padding: 14px 24px !important;
    min-height: 48px !important;
}

/* OFF state: when data-background="none" or aria-pressed=false -> transparent look */
#d2-background-toggle-button[aria-pressed="false"],
#d2-background-toggle-button[data-background="none"] {
    background: #ffffff !important;
    color: #667eea !important; /* match other inactive buttons */
    border-color: #d6daf6 !important;
}

#d2-background-toggle-button[aria-pressed="false"]:hover,
#d2-background-toggle-button[data-background="none"]:hover {
    background: #f8f9ff !important;
}

/* Ensure nested label/icon use the correct color on OFF state */
#d2-background-toggle-button[aria-pressed="false"] .d2-preset-name,
#d2-background-toggle-button[aria-pressed="false"] .d2-preset-icon,
#d2-background-toggle-button[data-background="none"] .d2-preset-name,
#d2-background-toggle-button[data-background="none"] .d2-preset-icon {
    color: #667eea !important; /* blue-purple like Styles/Custom */
}

/* ON state: explicit re-affirmation for gradient + white label/icon */
#d2-background-toggle-button[aria-pressed="true"],
#d2-background-toggle-button[data-background="transparent"] {
    border-color: #667eea !important;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: #ffffff !important;
}

#d2-background-toggle-button[aria-pressed="true"] .d2-preset-name,
#d2-background-toggle-button[aria-pressed="true"] .d2-preset-icon,
#d2-background-toggle-button[data-background="transparent"] .d2-preset-name,
#d2-background-toggle-button[data-background="transparent"] .d2-preset-icon {
    color: #ffffff !important;
}

#d2-background-toggle-button[aria-pressed="true"]:hover,
#d2-background-toggle-button[data-background="transparent"]:hover {
    background: linear-gradient(135deg, #5a6fd8 0%, #6b4d94 100%) !important;
}

/* Expanded Card Styles */
.d2-preset-button.expanded {
    max-height: none; /* Remove fixed height to allow proper aspect ratio */
    padding: 16px;
    z-index: 100;
    position: relative;
    grid-column: 1 / -1; /* Take full width in grid */
    margin: 10px 0;
    box-shadow: 0 8px 32px rgba(102, 126, 234, 0.25);
    border-radius: 16px;
}

.d2-preset-button.expanded:hover {
    transform: none; /* Disable hover transform when expanded */
}

/* Preview Image Container */
.d2-preview-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0;
    transition: opacity 0.4s ease-in-out;
    z-index: -1;
    border-radius: 10px;
    overflow: hidden;
}

.d2-preset-button.expanded .d2-preview-container {
    opacity: 1;
    z-index: 1;
    position: relative;
    margin-top: 12px;
    /* Use aspect ratio 2:3 (1024x1536) for optimal image display */
    aspect-ratio: 2 / 3;
    width: 200px; /* Fixed width for consistent sizing */
    height: 300px; /* Fallback height for browsers without aspect-ratio support (200px * 1.5 = 300px) */
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

/* Modern browsers with aspect-ratio support will override the height */
@supports (aspect-ratio: 2 / 3) {
    .d2-preset-button.expanded .d2-preview-container {
        height: auto;
    }
    
    /* Also override mobile fallback heights when aspect-ratio is supported */
    @media (max-width: 768px) {
        .d2-preset-button.expanded .d2-preview-container {
            height: auto;
        }
    }
    
    @media (max-width: 480px) {
        .d2-preset-button.expanded .d2-preview-container {
            height: auto;
        }
    }
}

.d2-preview-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
    transform: scale(1);
    transition: transform 0.3s ease;
}

.d2-preset-button.expanded:hover .d2-preview-image {
    transform: scale(1.02);
}

/* Content Positioning in Expanded State */
.d2-preset-button.expanded .d2-preset-icon {
    font-size: 24px;
    margin-bottom: 4px;
    z-index: 2;
    position: relative;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.d2-preset-button.expanded .d2-preset-name {
    font-size: 14px;
    font-weight: 700;
    z-index: 2;
    position: relative;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    margin-bottom: 8px;
}

/* Global tweak: when expanded, hide the emoji/icon and title to maximize image visibility */
.d2-preset-button.expanded .d2-preset-icon,
.d2-preset-button.expanded .d2-preset-name {
    display: none !important;
}

/* Global tweak: reduce preview image size by 10% in expanded state */
.d2-preset-button.expanded .d2-preview-image {
    transform: scale(0.9);
}

/* Keep a subtle hover bump while staying reduced overall */
.d2-preset-button.expanded:hover .d2-preview-image {
    transform: scale(0.92);
}

/* Close Button */
.d2-close-preview {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    color: #666;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.3s ease;
    z-index: 3;
    backdrop-filter: blur(4px);
}

.d2-preset-button.expanded .d2-close-preview {
    opacity: 1;
    transform: scale(1);
}

.d2-close-preview:hover {
    background: rgba(255, 255, 255, 1);
    color: #333;
    transform: scale(1.1);
}

/* Loading State */
.d2-preview-container.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(102, 126, 234, 0.1);
}

.d2-preview-loading {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(102, 126, 234, 0.3);
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: d2-spin 1s linear infinite;
}

@keyframes d2-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Grid Adjustments for Expansion */
.d2-presets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
    margin-bottom: 15px;
    position: relative;
    /* Ensure smooth transitions */
    transition: all 0.3s ease;
}

/* Touch Support */
.d2-preset-button.touch-active {
    background: #f0f4ff;
    transform: scale(0.98);
}

/* Keyboard Focus Support */
.d2-preset-button:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

.d2-close-preview:focus {
    outline: 2px solid #fff;
    outline-offset: 1px;
}

/* High Contrast Support */
@media (prefers-contrast: high) {
    .d2-preset-button {
        border-width: 3px;
    }
    
    .d2-enhanced-container .d2-presets-grid .d2-preset-button.active {
        border-width: 4px;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    .d2-preset-button,
    .d2-preview-container,
    .d2-preview-image,
    .d2-close-preview,
    .d2-presets-grid {
        transition: none;
        animation: none;
    }
    
    .d2-preview-loading {
        animation: none;
        border: 3px solid #667eea;
    }
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .d2-presets-grid {
        grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
        gap: 8px;
    }
    
    .d2-preset-button.expanded {
        padding: 12px;
        margin: 8px 0;
    }
    
    .d2-preset-button.expanded .d2-preview-container {
        width: 160px; /* Smaller but maintains 2:3 ratio */
        height: 240px; /* Fallback: 160px * 1.5 = 240px */
    }
    
    .d2-preset-button.expanded .d2-preset-icon {
        font-size: 20px;
    }
    
    .d2-preset-button.expanded .d2-preset-name {
        font-size: 12px;
    }

    /* Ensure Background/No Background button matches the height of the other two on mobile */
    .d2-primary-style-controls #d2-background-toggle-button {
        padding: 10px 12px;
        min-height: 60px;
    }
}

@media (max-width: 480px) {
    .d2-presets-grid {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
        gap: 6px;
    }
    
    .d2-preset-button.expanded {
        padding: 10px;
    }
    
    .d2-preset-button.expanded .d2-preview-container {
        width: 120px; /* Even smaller but still maintains 2:3 ratio */
        height: 180px; /* Fallback: 120px * 1.5 = 180px */
        margin-top: 8px;
    }

    /* Extra small screens: keep background toggle consistent with the others */
    .d2-primary-style-controls #d2-background-toggle-button {
        padding: 8px 10px;
        min-height: 55px;
    }
}

/* Ensure Expanded Cards Don't Break Layout */
.d2-preset-button.expanded ~ .d2-preset-button {
    transition-delay: 0.1s;
}

.d2-preset-button.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.d2-preset-icon {
    font-size: 20px;
    margin-top: 0px;   /* small top spacing */
    margin-bottom: 0px;/* match bottom spacing to be equal */
}

.d2-preset-name {
    font-size: 12px;
    line-height: 1.2;
    margin: 0; /* ensure symmetric spacing like FPD */
}

.d2-advanced-toggle {
    margin-bottom: 15px;
    text-align: center;
}

.d2-toggle-button {
    background: none;
    border: none;
    color: #667eea;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    padding: 8px 16px;
    border-radius: 20px;
    transition: all 0.3s ease;
}

.d2-toggle-button:hover {
    background: rgba(102, 126, 234, 0.1);
}

.d2-color-section {
    margin-bottom: 15px;
}

.d2-color-section h5, .d2-mood-section h5 {
    margin: 0 0 12px 0;
    color: #2c3e50;
    font-size: 14px;
    font-weight: 600;
}

/* NEW: Color Palette Styles */
.d2-palette-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    border-bottom: 2px solid #e1e4e8;
}

.d2-palette-tab {
    padding: 8px 16px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: #7f8c8d;
    position: relative;
    top: 2px;
    border-bottom: 2px solid transparent;
    transition: all 0.3s ease;
}

.d2-palette-tab:hover {
    color: #34495e;
}

.d2-palette-tab.active {
    color: #667eea;
    border-bottom-color: #667eea;
}

.d2-palettes-grid {
    display: grid;
    /* Match Styles grid sizing */
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
    margin-bottom: 15px;
    min-height: 10px; /* prevent collapse when children fail to size on mobile */
}

.d2-palette-button {
    /* Visually match style cards */
    padding: 12px 16px;
    border: 2px solid #e1e4e8;
    border-radius: 10px;
    background: #ffffff;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-height: 70px;
    max-height: 70px;
    overflow: hidden;
}

.d2-palette-button:hover {
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.1);
}

.d2-enhanced-container .d2-palettes-grid .d2-palette-button.active {
    border-color: #667eea;
    background: #f8f9ff;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.2);
    transform: translateY(-2px);
}
/* Ensure selected custom card overrides palette active visuals */
.d2-enhanced-container .d2-palettes-grid .d2-palette-button.d2-custom-card.selected {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    border-color: #667eea !important;
    color: #ffffff !important;
}

.d2-palette-info {
    text-align: center;
}

.d2-palette-name {
    font-size: 12px;
    font-weight: 600;
    color: #2c3e50;
}

.d2-palette-visualizer {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0; /* chips stuck together */
    height: auto;
    order: 1; /* ensure chips are above title */
    border-radius: 10px; /* match card rounding */
    overflow: hidden; /* clip inner squares to the rounded mask */
}

.d2-palette-color {
    flex: 1;
    transition: transform 0.2s ease;
}

.d2-palette-button:hover .d2-palette-color {
    transform: scaleY(1.1);
}

/* Ensure palette bars render correctly on mobile (resilient overrides) */
.d2-enhanced-container .d2-palettes-grid .d2-palette-visualizer {
    height: auto !important;
    display: inline-flex !important;
    gap: 0 !important; /* no gaps between chips */
    border-radius: 10px !important; /* match card rounding */
    overflow: hidden !important;
}
.d2-enhanced-container .d2-palettes-grid .d2-palette-visualizer .d2-palette-color {
    width: 20px !important;  /* square, emoji height */
    height: 20px !important; /* square */
    border-radius: 0 !important; /* no rounding */
    display: block !important;
    flex: 0 0 auto !important;
    margin: 0 !important; /* ensure stuck together */
}

@media (max-width: 768px) {
  .d2-enhanced-container .d2-palettes-grid .d2-palette-visualizer {
      gap: 0 !important;
  }
  /* Make palette grid responsive like styles grid */
  .d2-palettes-grid {
      grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
      gap: 8px;
  }
  .d2-enhanced-container .d2-palettes-grid .d2-palette-visualizer .d2-palette-color {
      width: 18px !important;
      height: 18px !important;
  }
}

@media (max-width: 480px) {
  .d2-enhanced-container .d2-palettes-grid .d2-palette-visualizer {
      gap: 0 !important;
  }
  .d2-palettes-grid {
      grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
      gap: 6px;
  }
  .d2-enhanced-container .d2-palettes-grid .d2-palette-visualizer .d2-palette-color {
      width: 16px !important;
      height: 16px !important;
  }
}

/* Ensure the palette name is below the chips */
.d2-palette-info { order: 2; }

#d2-custom-palette-container {
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
    border: 1px dashed #e1e4e8;
}

.d2-custom-palette-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin-bottom: 15px;
}

.d2-custom-color-input-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.d2-custom-color-input {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 50px;
    height: 50px;
    background-color: transparent;
    border: none;
    cursor: pointer;
}
.d2-custom-color-input::-webkit-color-swatch {
    border-radius: 50%;
    border: 3px solid #ffffff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.d2-custom-color-input::-moz-color-swatch {
    border-radius: 50%;
    border: 3px solid #ffffff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.d2-custom-color-input-wrapper label {
    font-size: 12px;
    color: #7f8c8d;
}

.d2-apply-custom-button {
    width: 100%;
    padding: 10px;
    border: 2px dashed #667eea;
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.d2-apply-custom-button:hover {
    background: rgba(102, 126, 234, 0.2);
    border-style: solid;
}

.d2-apply-custom-button.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: 2px solid #667eea;
}

.d2-mood-section {
    margin-top: 25px; /* Added margin to separate from new palette section */
    margin-bottom: 15px;
}
/* Align mood subtabs visuals with palettes subtabs */
#d2-mood-subtabs { margin-bottom: 10px; }
#d2-common-moods-container { margin-top: 5px; }
#d2-my-moods-container { margin-top: 5px; }
/* Floating save button inside My Moods container */
#d2-my-moods-container { position: relative; }
#d2-my-moods-container .d2-save-floating {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid #e1e4e8;
    background: #ffffff;
    color: #667eea;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(102,126,234,0.12);
}
#d2-my-moods-container .d2-save-floating:hover { box-shadow: 0 3px 10px rgba(102,126,234,0.18); background:#f8f9ff; }
/* Match custom mood apply button visuals to custom palette button */
#d2-apply-custom-mood { margin-top: 4px; display: none !important; }
/* Ensure mood input sits below floating save button */
#d2-my-moods-container .d2-text-input { position: relative; z-index: 1; }
/* Raise save-floating above inputs so it remains clickable */
#d2-my-moods-container .d2-save-floating { z-index: 10; }
/* Same for palette custom container */
#d2-custom-palette-container .d2-text-input { position: relative; z-index: 1; }
#d2-custom-palette-container .d2-save-floating { z-index: 10; }
/* Floating save button for Custom Palettes (same position/size as styles & moods) */
/* Save button embedded in the palette name input wrapper (same as styles) */
#d2-custom-palette-container .d2-text-wrapper { position: relative; }
#d2-custom-palette-container .d2-text-wrapper #d2-save-custom-palette-btn,
#d2-custom-palette-container .d2-text-wrapper .d2-save-style-button {
    position: absolute;
    right: -12px;  /* align to outer corner like other save bubbles */
    top: -12px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid #e1e4e8;
    background: #fff;
    color: #667eea;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(102,126,234,0.12);
}
#d2-custom-palette-container .d2-text-wrapper #d2-save-custom-palette-btn:hover { box-shadow: 0 3px 10px rgba(102,126,234,0.18); background:#f8f9ff; }

.d2-selection-counter {
    font-size: 12px;
    font-weight: 500;
    color: #667eea;
    background: rgba(102, 126, 234, 0.1);
    padding: 2px 8px;
    border-radius: 12px;
    margin-left: 8px;
    display: inline-block;
    transition: all 0.3s ease;
}

.d2-selection-counter.at-limit {
    background: rgba(255, 193, 7, 0.2);
    color: #ff6b35;
}

.d2-selection-counter.over-limit {
    background: rgba(220, 53, 69, 0.1);
    color: #dc3545;
    animation: pulse 0.5s ease-in-out;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.d2-mood-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
}

.d2-mood-tag {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 70px;
    max-height: 70px;
    padding: 12px 16px;
    border: 2px solid #e1e4e8;
    border-radius: 10px;
    background: #ffffff;
    color: #2c3e50;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
}

.d2-mood-tag:hover {
    border-color: #667eea;
    background: #f8f9ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.1);
}

.d2-enhanced-container .d2-mood-options .d2-mood-tag.active {
    background: #667eea;
    color: white;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    transform: translateY(-2px);
}

.d2-mood-emoji { font-size: 20px; }
.d2-mood-name { font-size: 12px; font-weight: 600; }

.d2-mood-tag.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

/* Unified Tabs (reuse AIM styles, namespaced) */
.d2-tab-system .aim-filter-tabs {
    display: flex;
    background: #f8f9ff;
    border-radius: 16px;
    padding: 4px;
    margin: 10px 0 16px 0;
    box-shadow: inset 0 2px 8px rgba(102, 126, 234, 0.08);
    overflow-x: auto;
}
.d2-tab-system .aim-filter-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border: none;
    background: transparent;
    border-radius: 12px;
    font-size: 13px;
    color: #7f8c8d;
    cursor: pointer;
    transition: all 0.25s ease;
    white-space: nowrap;
}
.d2-tab-system .aim-filter-tab:hover {
    background: rgba(255, 255, 255, 0.6);
    color: #667eea;
    transform: translateY(-1px);
}
.d2-tab-system .aim-filter-tab.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.3);
    transform: translateY(-2px);
}
.d2-tab-system .aim-tab-count {
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 6px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 700;
}
.d2-tab-system .aim-tab-content-container {
    background: #fff;
    border: 1px solid #f1f3f4;
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}
.d2-tab-system .d2-tab-pane {
    animation: fadeInUp 0.25s ease;
}

/* Hide duplicate inner titles and counters for Mood/Color sections when placed
   inside the unified tab contents. The badges/counters are already shown on
   the tabs above; we only remove the visual here without affecting logic. */
.d2-tab-contents .d2-color-section h5,
.d2-tab-contents .d2-mood-section h5 {
    display: none;
}

/* Selection summary above Generate button */
.d2-active-selection-summary {
    display: none;
    position: relative;
    margin: 10px 0 0 0;
    padding: 8px 12px;
    background: rgba(102, 126, 234, 0.08);
    border: 1px solid rgba(102, 126, 234, 0.2);
    border-radius: 10px;
    gap: 10px; /* a bit more space between items */
    flex-wrap: wrap;
}
.d2-active-selection-summary .d2-selection-chips {
    display: flex;           /* ensure chips participate in a flex row */
    flex-wrap: wrap;         /* allow wrapping on small screens */
    gap: 10px;               /* visual space between each chip */
    align-items: center;
}
.d2-active-selection-summary.visible {
    display: flex;
}
.d2-active-selection-summary .d2-chip,
.d2-active-selection-summary .d2-selection-chips .d2-chip {
    position: relative;
    background: #fff;
    color: #667eea;
    border: 1px solid rgba(102, 126, 234, 0.25);
    padding: 6px 12px; /* slightly larger padding per item */
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

/* Close (remove) button on each chip */
.d2-chip-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #ffffff;
    border: 1px solid #e1e4e8;
    color: #c0392b;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
}
.d2-chip-remove:hover { background:#ffeaea; border-color:#e67e73; }

/* Palette colors inside summary chip */
.d2-active-selection-summary .d2-palette-visualizer--chip {
  display: inline-flex;
  gap: 0;
  margin-right: 8px;
  vertical-align: middle;
  border-radius: 10px; /* pill outer */
  overflow: hidden;    /* square centers */
}
.d2-active-selection-summary .d2-palette-visualizer--chip .d2-palette-color--chip {
  width: 14px;
  height: 14px;
  border-radius: 0; /* square centers */
  display: inline-block;
}

/* Right-aligned save button inside summary */
#d2-active-selection-summary #d2-save-config-btn,
.d2-active-selection-summary #d2-save-config-btn {
    position: absolute;
    top: -8px; /* slightly above content for prominence */
    right: -8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid #e1e4e8;
    background: #ffffff;
    color: #667eea;
    z-index: 2; /* above summary chips */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(102,126,234,0.12);
    z-index: 3; /* ensure button does not collapse chip gap */
}
.d2-active-selection-summary #d2-save-config-btn:hover { box-shadow: 0 3px 10px rgba(102,126,234,0.18); background:#f8f9ff; }

/* Floating save button for Custom Styles container (same look/feel and position at container's top-right) */
#d2-custom-styles-container { position: relative; }
#d2-custom-styles-container #d2-save-custom-style-btn,
#d2-custom-styles-container .d2-save-floating {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid #e1e4e8;
    background: #ffffff;
    color: #667eea;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(102,126,234,0.12);
}
#d2-custom-styles-container #d2-save-custom-style-btn:hover { box-shadow: 0 3px 10px rgba(102,126,234,0.18); background:#f8f9ff; }

/* Save configuration button below Generate button (mic-like minimal style) */
#d2-save-config-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid #e1e4e8;
    background: #ffffff;
    color: #667eea;
}
#d2-save-config-btn:hover { box-shadow: 0 2px 8px rgba(102,126,234,0.18); background:#f8f9ff; }

/* Custom styles grid (reuses style card sizing) */
.d2-custom-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
}
.d2-custom-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border: 2px solid #e1e4e8;
  border-radius: 10px;
  background: #ffffff;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: visible; /* allow corner buttons to show fully */
  text-align: center;
}
.d2-custom-card:hover { border-color:#667eea; background:#f8f9ff; transform: translateY(-2px); box-shadow:0 4px 12px rgba(102,126,234,0.15); }
.d2-custom-card .d2-custom-emoji { font-size: 18px; color:#667eea; }
.d2-custom-card .d2-custom-name { font-size: 11px; font-weight: 600; color:#2c3e50; line-height:1.2; }
.d2-custom-card .d2-custom-delete {
  position: absolute;
  top: -10px;  /* pull to outer corner for consistent corner placement */
  right: -10px;
  width: 20px;
  height: 20px;
  line-height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid #e1e4e8;
  color: #c0392b;
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.d2-custom-card .d2-custom-delete:hover { background:#ffeaea; border-color:#e67e73; }
/* Ensure relative context for corner placement on palette-style and other cards */
.d2-palettes-grid .d2-custom-card { position: relative; }
.d2-palettes-grid .d2-custom-card .d2-custom-delete { top: -10px; right: -10px; width: 20px; height: 20px; }
/* Ensure delete button is above card content */
.d2-custom-card .d2-custom-delete { z-index: 5; }

/* Custom config card (palette-like without gradient bars) */
.d2-custom-config-card { display:flex; flex-direction:column; gap:10px; }
/* Emoji only (no container background) */
.d2-custom-config-card .d2-custom-emoji { font-size:18px; color:#667eea; line-height:1; }

/* Highlight selected custom style card (purple background, white text) */
/* Ensure selected custom cards override palette button defaults */
.d2-palettes-grid .d2-palette-button.d2-custom-card.selected,
.d2-palettes-grid .d2-custom-card.selected,
#d2-custom-styles-container .d2-palette-button.d2-custom-card.selected,
#d2-custom-styles-container .d2-custom-card.selected,
#d2-my-configs-list .d2-custom-card.selected,
.d2-custom-grid .d2-custom-card.selected {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
  border-color: #667eea !important;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3) !important;
  color: #ffffff !important;
}
#d2-custom-styles-container .d2-custom-card.selected .d2-palette-name,
#d2-custom-styles-container .d2-custom-card.selected .d2-custom-emoji,
#d2-custom-styles-container .d2-palette-button.d2-custom-card.selected .d2-palette-name,
#d2-custom-styles-container .d2-palette-button.d2-custom-card.selected .d2-custom-emoji,
#d2-my-configs-list .d2-custom-card.selected .d2-custom-name,
#d2-my-configs-list .d2-custom-card.selected .d2-custom-emoji,
.d2-palettes-grid .d2-custom-card.selected .d2-palette-name,
.d2-palettes-grid .d2-palette-button.d2-custom-card.selected .d2-palette-name,
.d2-palettes-grid .d2-custom-card.selected .d2-custom-emoji,
.d2-palettes-grid .d2-palette-button.d2-custom-card.selected .d2-custom-emoji,
.d2-custom-grid .d2-custom-card.selected .d2-custom-name,
.d2-custom-grid .d2-custom-card.selected .d2-custom-emoji { color: #ffffff !important; }

/* In case palette button base rules override background on hover/focus */
.d2-custom-card.selected:hover { background: linear-gradient(135deg, #5a6fd8 0%, #6b4d94 100%) !important; }

/* Style subtabs reuse palette tab visuals */
#d2-style-subtabs { margin-bottom: 10px; }
#d2-ready-styles-container, #d2-custom-styles-container { margin-top: 5px; }
.d2-custom-styles-hint { margin: 6px 0 10px 0; color:#7f8c8d; font-size:12px; }

/* Save icon next to custom style input (reuse mic/robot circle) */
.d2-save-style-button {
  position: absolute;
  right: 8px;
  top: 6px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid #e1e4e8;
  background: #fff;
  color: #667eea;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: box-shadow .2s ease, background .2s ease, color .2s ease;
  z-index: 5;
}

/* Ensure input sits below icon */
#d2-custom-styles-container .d2-text-input { position: relative; z-index: 1; }
.d2-save-style-button:hover { box-shadow: 0 2px 8px rgba(102,126,234,0.18); background:#f8f9ff; }
.d2-save-style-button .d2-icon { display:block; }

.d2-prompt-section {
    margin-bottom: 20px;
}

.d2-prompt-section label {
    display: block;
    color: #34495e;
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 0;
}

.d2-prompt-header {
    display: flex;
    justify-content: flex-end; /* align controls to the right when the label is visually hidden */
    align-items: center;
    margin-bottom: 8px;
}

.d2-icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    line-height: 0; /* prevent baseline from shifting the SVG box */
    width: 32px;
    height: 32px;
    border: 1px solid #e1e4e8;
    border-radius: 50%;
    background: #ffffff;
    color: #667eea; /* match mic */
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.d2-icon-button:hover {
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.18);
}

.d2-icon-button:disabled,
.d2-icon-button.disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.d2-icon-button .d2-icon { display: block; width: 18px; height: 18px; }

/* Nudge coins icon by half a pixel for optical centering on some renderers */
#d2-credits-icon-btn .d2-icon { transform: translateY(0.5px); }

.d2-prompt-controls {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

/* Upload button visually matches mic via .d2-icon-button now */
.d2-upload-button { border: none; background: transparent; padding: 0; }

/* Pill-style upload button with text */
.d2-pill-button {
    display: inline-flex;
    flex-direction: row; /* icon before text, horizontal layout */
    align-items: center;
    gap: 8px;
    border: 1px solid #d6daf6;
    border-radius: 10px; /* match other buttons' 10px radius */
    background: #ffffff;
    color: #667eea; /* match mic/robot color */
    padding: 6px 12px;
    font-size: 13px;
    line-height: 1;
}
.d2-pill-button:hover {
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.18);
    color: #4e5ed2;
    background: #f8f9ff;
}

/* Make icons in the three primary style buttons larger than text */
.d2-primary-style-controls .d2-pill-button .d2-icon {
    width: 26px;
    height: 26px;
    margin-right: 6px; /* additional optical balance */
    align-self: center; /* ensure vertical centering relative to text */
}

.d2-reference-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 4px 0 8px 0; /* small, stable spacing; do not alter prompt input margins */
}

/* Logo thumb styling - uses same styling as reference thumbs */
.d2-logo-thumb {
    border-color: #48bb78 !important; /* Green border to distinguish from reference images */
}

.d2-logo-thumb:hover {
    border-color: #38a169 !important;
}

.d2-reference-list {
    display: flex;
    align-items: center;
    gap: 8px;
}

.d2-reference-thumb {
    width: 70px; /* 30% larger */
    height: 70px; /* 30% larger */
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #e1e4e8;
    background: #fff;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
}

#d2-reference-thumb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Removed actions container; replaced with corner X */

/* filename hidden (no longer used) */

/* Keep prompt wrapper height consistent even when a reference image is attached,
   so absolutely positioned anchors (mic, counter) don't shift */
/* .d2-prompt-wrapper.has-reference .d2-prompt-input { margin-bottom: 8px !important; } */

.d2-reference-remove {
    position: absolute;
    top: 4px;    /* push inside to avoid clipping */
    right: 4px;  /* push inside to avoid clipping */
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(0,0,0,0.75);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    border: 2px solid #fff;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    z-index: 2;
}

.d2-reference-remove:hover,
.d2-reference-remove:focus {
    background: rgba(0,0,0,0.85);
}

.d2-reference-empty-hint {
    font-size: 12px;
    color: #7f8c8d;
    margin-top: 4px;
}

.d2-robot-icon {
    background: linear-gradient(135deg, #2b6bc7 0%, #cf3a74 50%, #e53143 75%, #ff6b35 100%) !important;
    color: white !important;
    border: none !important;
}

.d2-robot-icon:hover {
    background: linear-gradient(135deg, #3574d4 0%, #d94580 50%, #ea4450 75%, #ff7842 100%) !important;
    transform: scale(1.2) rotate(5deg);
    box-shadow: 0 4px 12px rgba(43, 107, 199, 0.3);
}

.d2-robot-icon:active {
    transform: scale(1.1) rotate(-5deg);
}

.d2-robot-icon.d2-robot-thinking {
    animation: spin 1s linear infinite;
}

.d2-prompt-wrapper {
    position: relative;
    /* Ensure anchors remain fixed when content above/below changes */
    /* If needed, set a minimum height equal to the input's min-height plus padding */
    min-height: 80px; /* matches .d2-prompt-input min-height */
}

/* Controls sitting on top border, right-aligned */
.d2-top-controls {
    position: absolute;
    top: -16px; /* pull up to sit over the top border area */
    right: 10px;
    z-index: 12;
    background: transparent;
}

.d2-enhanced-container .d2-prompt-input {
    width: 100% !important;
    box-sizing: border-box !important;
    padding: 18px 16px 14px 16px !important; /* extra top padding so text doesn't collide with top controls */
    border: 2px solid #e1e4e8 !important;
    border-radius: 10px !important;
    font-size: 16px !important;
    line-height: 1.5 !important;
    resize: vertical !important;
    min-height: 80px !important;
    transition: all 0.3s ease !important;
    font-family: inherit !important;
    background: #ffffff !important;
    margin: 0 0 20px !important;
}

.d2-enhanced-container .d2-prompt-input:focus {
    border-color: #667eea !important;
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
    background: #fafbff !important;
}

.d2-prompt-counter {
    position: absolute;
    bottom: 8px;
    right: 48px; /* leave room for mic button on the far right */
    font-size: 11px;
    color: #7f8c8d;
    background: rgba(255, 255, 255, 0.9);
    padding: 2px 6px;
    border-radius: 4px;
    z-index: 20; /* above text selection */
    pointer-events: none; /* avoid interfering with selection */
}

/* Minimal microphone button anchored bottom-right inside prompt input */
.d2-mic-button {
    position: absolute;
    bottom: 8px;
    right: 12px;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #e1e4e8;
    border-radius: 50%;
    background: #ffffff;
    color: #667eea;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
    z-index: 11;
}

.d2-mic-button:hover {
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.18);
}

.d2-mic-button.active {
    background: #f0f3ff;
    color: #4e5ed2;
    border-color: #d6daf6;
}

.d2-mic-icon {
    display: block;
}

/* While recording, add subtle glow */
.d2-mic-button.recording {
    animation: d2-mic-pulse 1.4s ease-in-out infinite;
}

/* While holding (press-and-hold), emphasize purple indicator */
.d2-mic-button.holding {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.18);
}

@keyframes d2-mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(102,126,234,0.25); }
    50% { box-shadow: 0 0 0 6px rgba(102,126,234,0.12); }
}

.d2-text-section {
    margin-bottom: 15px;
}

.d2-text-section label {
    display: block;
    margin-bottom: 8px;
    color: #2c3e50;
    font-weight: 600;
    font-size: 14px;
}

.d2-text-wrapper {
    position: relative;
}

/* Ensure text input has same base structure as prompt input */
.d2-text-wrapper .d2-text-input {
    width: 100%;
    box-sizing: border-box;
    /* Inherit from prompt input pattern */
    resize: none; /* Prevent resize that might affect layout */
}

.d2-enhanced-container .d2-text-input {
    width: 100% !important;
    box-sizing: border-box !important;
    padding: 12px 60px 12px 16px !important;
    border: 2px solid #e1e4e8 !important;
    border-radius: 10px !important;
    font-size: 16px !important;
    line-height: 1.5 !important;
    transition: all 0.3s ease !important;
    font-family: inherit !important;
    background: #ffffff !important;
    font-weight: normal !important;
    text-transform: none !important;
    letter-spacing: normal !important;
    margin: 0 0 20px !important;
}

.d2-enhanced-container .d2-text-input:focus {
    border-color: #667eea !important;
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
    background: #fafbff !important;
}

.d2-enhanced-container .d2-text-input::placeholder {
    text-transform: none !important;
    letter-spacing: normal !important;
    font-weight: normal !important;
    font-size: 16px !important;
}

.d2-text-counter {
    position: absolute;
    bottom: 8px;
    right: 12px;
    font-size: 11px;
    color: #7f8c8d;
    background: rgba(255, 255, 255, 0.9);
    padding: 2px 6px;
    border-radius: 4px;
}

.d2-input-action-icon {
    position: absolute;
    top: 50%;
    right: 12px;
    transform: translateY(-55%); /* slight optical correction so it sits perfectly centered */
    z-index: 10;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 22px;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    color: #667eea;
    opacity: 0.9;
    padding: 0;
}

.d2-input-action-icon:hover {
    opacity: 1;
}

/* My Styles library */
.d2-my-styles-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.d2-my-styles-title {
    font-size: 12px;
    font-weight: 600;
    color: #2c3e50;
}

.d2-my-styles-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.d2-my-style-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #ffffff;
    border: 1px solid #e1e4e8;
    border-radius: 16px;
    padding: 6px 10px;
    font-size: 12px;
    color: #2c3e50;
    cursor: pointer;
    transition: all 0.2s ease;
}

.d2-my-style-chip:hover {
    border-color: #667eea;
    background: #f8f9ff;
}

.d2-my-style-chip .d2-chip-actions {
    display: inline-flex;
    gap: 6px;
}

.d2-chip-action {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    font-size: 14px;
    line-height: 1;
    color: #95a5a6;
}

.d2-chip-action:hover {
    color: #34495e;
}

/* Adjust spacing for My Styles block: closer to input, a bit more after */
#d2-my-styles-container {
    margin-top: 0 !important; /* remove own top margin */
    margin-bottom: 27px; /* a little more space after */
}

/* Reduce spacing under ONLY the custom-style input to bring My Styles closer */
#d2-custom-style-input {
    margin-bottom: 8px !important; /* target 7–10px requested spacing */
}

.d2-text-counter.at-limit {
    color: #ff6b35;
    background: rgba(255, 107, 53, 0.1);
}

.d2-action-section {
    display: block;
    margin-bottom: 20px;
}

.d2-action-section #generate-image-btn + #d2-active-selection-summary {
    margin-top: 10px;
}

.d2-generate-button {
    display: flex;
    width: 100%;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: transparent;
    color: #2c3e50;
    border: 1px solid rgba(102, 126, 234, 0.5);
    border-radius: 10px;
    font-size: 14px;
    font-weight: 900;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
    box-shadow: none;
}

.d2-generate-button:hover {
    background: rgba(102, 126, 234, 0.15);
    border-color: rgba(102, 126, 234, 0.75);
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.15);
}

.d2-generate-button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.d2-generate-label { 
    flex: 1; 
    text-align: left; 
    text-transform: uppercase;
    font-size: 16px; /* 24px - 2px */
    font-weight: 800;
    color: #2c3e50;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.d2-stats-panel {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.d2-stats-inline {
    background: transparent;
    padding: 0;
    border-radius: 0;
    min-width: 0;
    display: inline-flex;
    flex-direction: row;
    gap: 6px;
    align-items: baseline;
    white-space: nowrap;
}

.d2-stats-label {
    color: #2c3e50; /* fallback color */
    font-size: inherit; /* match button font size */
    text-transform: none; /* no caps */
    font-weight: 700;
    margin-bottom: 0;
    line-height: 1.1;
}

.d2-stats-value {
    color: #2c3e50;
    font-size: inherit; /* match button font size */
    font-weight: 800;
    line-height: 1.1;
}

.d2-stats-subtext {
    color: #7f8c8d;
    font-size: inherit; /* match button font size */
    margin-top: 0;
}

/* Apply one smooth gradient across the entire stats section */
.d2-generate-button .d2-stats-inline {
    background: linear-gradient(135deg, #2b6bc7 0%, #cf3a74 50%, #e53143 75%, #ff6b35 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Reset individual elements to inherit from parent */
.d2-generate-button .d2-stats-inline .d2-stats-value,
.d2-generate-button .d2-stats-inline .d2-stats-label,
.d2-generate-button .d2-stats-inline .d2-stats-subtext { 
    background: none;
    color: inherit;
    font-weight: 700;
}

.d2-feedback {
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.5;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.d2-feedback.success {
    background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
    color: #155724;
    border: 2px solid #b3d4b8;
    padding: 15px;
}

.d2-feedback.error {
    background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%);
    color: #721c24;
    border: 2px solid #f1b0b7;
    padding: 15px;
}

.error-container {
    border-radius: 12px;
    margin: 15px 0;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    animation: slideInDown 0.4s ease-out;
}

.error-container .error {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a52 100%);
    color: white;
    padding: 20px;
    margin: 0;
    font-size: 14px;
    line-height: 1.6;
    border: none;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.error-container .error:before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(circle at 20% 80%, rgba(255,255,255,0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255,255,255,0.1) 0%, transparent 50%);
    pointer-events: none;
}

/* Critical error styles for policy violations, API key issues, etc. */
.error-container .error:has-text("🚫"),
.error-container .error:has-text("💳"),
.error-container .error:has-text("🔑") {
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
    border-left: 6px solid #b21e2d;
    animation: slideInDown 0.4s ease-out, criticalPulse 2s ease-in-out 0.5s;
}

/* Warning-level errors (timeouts, rate limits, etc.) */
.error-container .error:has-text("⏱️"),
.error-container .error:has-text("⏰"),
.error-container .error:has-text("🔧") {
    background: linear-gradient(135deg, #ffc107 0%, #ffb300 100%);
    color: #212529;
    text-shadow: none;
    border-left: 6px solid #ff8f00;
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes criticalPulse {
    0%, 100% { box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); }
    50% { box-shadow: 0 4px 20px rgba(220, 53, 69, 0.4); }
}

.d2-feedback.loading {
    background: linear-gradient(135deg, #d1ecf1 0%, #bee5eb 100%);
    color: #0c5460;
    border: 2px solid #abdde5;
    padding: 15px;
}

.d2-feedback.notice {
    background: linear-gradient(135deg, #fff3cd 0%, #ffeeba 100%);
    color: #856404;
    border: 2px solid #fde68a;
    padding: 15px;
}

.d2-loading-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    box-sizing: border-box;
    border: 2px solid rgba(102, 126, 234, 0.25); /* light ring */
    border-top-color: #667eea; /* purple tip */
    animation: d2-spin 0.9s linear infinite; /* simple constant spin */
    margin-right: 8px;
}

.d2-loading-spinner--sm {
    width: 14px;
    height: 14px;
    border-width: 2px;
}

/* Center spinner inside the mic button without side margin */
.d2-mic-button .d2-loading-spinner {
    margin-right: 0;
}

.loading-message {
    display: inline-block;
    font-weight: 500;
    margin-left: 5px;
}

#retry-generation-btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    min-width: auto;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
}

#retry-generation-btn:hover {
    background: linear-gradient(135deg, #5a6fd8 0%, #6b4d94 100%);
    transform: translateY(-1px);
}

@keyframes spin { to { transform: rotate(360deg); } } /* legacy - kept for safety */

/* ===================================
   FANCY TITLE STYLES
   =================================== */

.d2-fancy-title-container {
    width: 100%;
    margin: -195px 0 30px 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    position: relative;
    overflow: visible;
}

.d2-fancy-title-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(circle at 20% 80%, rgba(255,255,255,0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255,255,255,0.1) 0%, transparent 50%);
    pointer-events: none;
}

.d2-fancy-title-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding: 130px 20px 60px 20px;
    position: relative;
    z-index: 2;
}

.d2-fancy-title-content {
    text-align: center;
    color: white;
}

.d2-fancy-product-title {
    font-size: 48px;
    font-weight: 800;
    line-height: 1.2;
    margin: 0 0 16px 0;
    color: white;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
    letter-spacing: -0.5px;
}

.d2-fancy-title-subtitle {
    font-size: 18px;
    font-weight: 500;
    color: rgba(255,255,255,0.9);
    margin-bottom: 30px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.d2-fancy-title-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-top: 30px;
}

.d2-divider-line {
    width: 80px;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.6) 50%, transparent 100%);
}

.d2-divider-icon {
    font-size: 24px;
    background: rgba(255,255,255,0.2);
    padding: 12px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.3);
}

/* Responsive Design */
@media (max-width: 768px) {
    .d2-fancy-title-wrapper {
        padding: 100px 15px 40px 15px;
    }
    
    .d2-fancy-product-title {
        font-size: 36px;
    }
    
    .d2-fancy-title-subtitle {
        font-size: 16px;
    }
    
    .d2-divider-line {
        width: 60px;
    }
    
    .d2-fancy-title-divider {
        gap: 15px;
    }
}

@media (max-width: 480px) {
    .d2-fancy-title-wrapper {
        padding: 90px 15px 30px 15px;
    }
    
    .d2-fancy-product-title {
        font-size: 28px;
    }
    
    .d2-fancy-title-subtitle {
        font-size: 14px;
    }
    
    .d2-divider-line {
        width: 40px;
    }
    
    .d2-divider-icon {
        font-size: 20px;
        padding: 10px;
    }
}

/* Integration with WooCommerce single product layout */
.single-product .d2-fancy-title-container {
    margin-left: calc(-50vw + 50%);
    margin-right: calc(-50vw + 50%);
    width: 100vw;
    max-width: 100vw;
}

/* Mobile-safe full-width implementation */
@media (max-width: 768px) {
    .single-product .d2-fancy-title-container {
        margin-left: calc(-50vw + 50%) !important;
        margin-right: calc(-50vw + 50%) !important;
        width: 100vw !important;
        max-width: 100vw !important;
        box-sizing: border-box;
        overflow-x: hidden;
    }
}

@media (max-width: 768px) {
    .single-product .d2-fancy-title-container {
        padding: 10px;
    }
}

/* Styles for Primary/Advanced Style Controls */
.d2-primary-style-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px; /* Or as needed */
}

/* New 50/50 Tab Button Layout */
.d2-primary-style-controls .d2-styles-tab-button {
    flex: 1; /* Each button takes 50% of available width */
    max-width: none; /* Override any existing max-width */
    display: inline-flex;
    align-items: center; /* center icon and text vertically */
    justify-content: center; /* center content */
    gap: 10px; /* spacing between icon and text */
    border-radius: 10px; /* match global button roundness */
    padding: 14px 24px; /* match general button vertical height */
    min-height: 48px; /* ensure visual consistency */
}

/* Active state styling for both tab buttons */
.d2-enhanced-container .d2-primary-style-controls .d2-styles-tab-button.active {
    border-color: #667eea;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.d2-enhanced-container .d2-primary-style-controls .d2-styles-tab-button.active .d2-preset-icon,
.d2-enhanced-container .d2-primary-style-controls .d2-styles-tab-button.active .d2-preset-name {
    color: white;
}

/* Responsive behavior for mobile */
@media (max-width: 768px) {
    .d2-primary-style-controls {
        flex-direction: row; /* Keep horizontal even on mobile */
        gap: 8px;
    }
    
    .d2-primary-style-controls .d2-styles-tab-button {
        font-size: 12px;
        padding: 10px 12px;
        min-height: 60px; /* Ensure consistent height on mobile */
    }
    
    .d2-primary-style-controls .d2-preset-icon {
        font-size: 16px;
    }
}

/* Extra small mobile screens */
@media (max-width: 480px) {
    .d2-primary-style-controls {
        gap: 6px;
    }
    
    .d2-primary-style-controls .d2-styles-tab-button {
        font-size: 11px;
        padding: 8px 10px;
        min-height: 55px;
    }
    
    .d2-primary-style-controls .d2-preset-icon {
        font-size: 14px;
    }
    
    .d2-primary-style-controls .d2-preset-name {
        font-size: 11px;
        line-height: 1.2;
    }
}

/* Logo gradient for inactive state */
.d2-primary-style-controls .d2-styles-tab-button:not(.active) {
    background: linear-gradient(135deg, #2b6bc7 0%, #cf3a74 50%, #e53143 75%, #ff6b35 100%);
    color: white;
    border: none;
    padding: 15px 25px; /* compensate for removed border (14px+1px, 24px+1px) */
    min-height: 48px;
    line-height: 1;
    box-shadow: 0 2px 8px rgba(43, 107, 199, 0.2);
}

/* Hover state for inactive buttons */
.d2-primary-style-controls .d2-styles-tab-button:not(.active):hover {
    border: none;
    background: linear-gradient(135deg, #3574d4 0%, #d94580 50%, #ea4450 75%, #ff7842 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(43, 107, 199, 0.3);
    padding: 15px 25px; /* compensate for removed border (14px+1px, 24px+1px) */
    min-height: 48px;
    line-height: 1;
}

/* Advanced Options Button - inherits d2-preset-button styles but with specific tweaks */

.d2-advanced-options-button:hover {
    border-color: #667eea;
    background: #f8f9ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

/* Legacy styles for backward compatibility - keeping the original .open class behavior */
.d2-enhanced-container .d2-primary-style-controls .d2-advanced-options-button.open {
    border-color: #667eea;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
    transform: translateY(-2px);
}

.d2-enhanced-container .d2-primary-style-controls .d2-advanced-options-button.open .d2-preset-icon,
.d2-enhanced-container .d2-primary-style-controls .d2-advanced-options-button.open .d2-preset-name {
    color: white;
}

#d2-advanced-styles-container.open {
    display: block !important;
    border-top: 1px solid #e1e4e8;
    padding-top: 15px;
    margin-top: 15px;
}

#generate-image-btn:disabled .d2-loading-spinner {
    display: inline-block;
}

/*--------------------------------------------------------------
4.10. Insufficient Credits Notification
--------------------------------------------------------------*/
.d2-credits-notice {
    background: #ffffff;
    border: 1px solid #e1e4e8;
    border-radius: 12px;
    padding: 25px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    animation: d2-fade-in 0.5s ease-out;
    position: relative;
}

.d2-credits-notice-title {
    font-size: 1.3em;
    font-weight: 600;
    color: #333;
    margin-top: 0;
    margin-bottom: 8px;
}

.d2-credits-notice-subtitle {
    font-size: 0.95em;
    color: #666;
    margin-top: 0;
    margin-bottom: 20px;
}

.d2-credits-options {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
}

.d2-credit-pack-btn {
    display: block;
    background-image: linear-gradient(to right, #667eea 0%, #764ba2 100%);
    color: #fff;
    padding: 12px 0;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    font-size: 1.1em;
    width: 80px;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(118, 75, 162, 0.2);
    outline: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Center the standalone Login Now button */
.d2-login-now-btn {
    display: inline-block;
    width: auto;
    padding: 12px 18px;
    margin: 12px auto 0;
}

.d2-credit-pack-btn:hover,
.d2-credit-pack-btn:focus {
    transform: translateY(-3px);
    box-shadow: 0 7px 20px rgba(118, 75, 162, 0.3);
    color: #fff;
}

.d2-credit-pack-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 4px 15px rgba(118, 75, 162, 0.1);
}

/*--------------------------------------------------------------
4.11. Coupon Code Redemption Section
--------------------------------------------------------------*/
.d2-coupon-section {
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid #e1e4e8;
}

.d2-coupon-divider {
    font-size: 0.9em;
    color: #666;
    margin: 0 0 15px 0;
    text-align: center;
}

.d2-coupon-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: center;
}

.d2-coupon-input {
    flex: 1;
    padding: 10px 14px !important;
    border: 2px solid #e1e4e8 !important;
    border-radius: 8px;
    font-size: 0.95em !important;
    font-weight: 500;
    text-transform: uppercase;
    transition: all 0.3s ease;
    outline: none;
    height: 42px !important;
    line-height: normal !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    display: block !important;
    width: 100% !important;
}

.d2-coupon-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.d2-coupon-input::placeholder {
    text-transform: none;
    font-weight: 400;
}

.d2-redeem-coupon-btn {
    padding: 0 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95em;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
    height: 42px;
    box-sizing: border-box;
}

.d2-redeem-coupon-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.3);
}

.d2-redeem-coupon-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.d2-coupon-message {
    margin-top: 12px;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 0.9em;
    text-align: center;
    animation: d2-fade-in 0.3s ease-out;
}

.d2-coupon-message.d2-coupon-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.d2-coupon-message.d2-coupon-success i {
    color: #28a745;
    margin-right: 6px;
}

.d2-coupon-message.d2-coupon-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.d2-coupon-message.d2-coupon-error i {
    color: #dc3545;
    margin-right: 6px;
}

.d2-close-notice-btn {
    background: none;
    border: none;
    color: #888;
    font-size: 0.9em;
    cursor: pointer;
    text-decoration: underline;
    padding: 5px;
    transition: color 0.3s ease;
}

.d2-close-notice-btn:hover {
    color: #333;
}

/* Unified close button for all notices */
.d2-notice-close {
    position: absolute;
    top: 10px;
    right: 12px;
    background: rgba(0,0,0,0.05);
    border: none;
    color: #555;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    line-height: 26px;
}
.d2-notice-close:hover { background: rgba(0,0,0,0.1); }

/* Font Awesome icon support for Designer-2 */
.d2-preset-icon i.fas,
.d2-preset-icon i.far,
.d2-preset-icon i.fab,
.d2-mood-emoji i.fas,
.d2-mood-emoji i.far,
.d2-mood-emoji i.fab,
.aim-tab-icon i.fas,
.aim-tab-icon i.far,
.aim-tab-icon i.fab,
.d2-palette-tab i.fas,
.d2-palette-tab i.far,
.d2-palette-tab i.fab {
    font-family: "Font Awesome 5 Free", "Font Awesome 5 Pro", "Font Awesome 5 Brands" !important;
    font-weight: 900 !important;
    font-style: normal !important;
    font-variant: normal !important;
    text-rendering: auto !important;
    -webkit-font-smoothing: antialiased !important;
    -moz-osx-font-smoothing: grayscale !important;
    display: inline-block !important;
    font-size: inherit !important;
}

/* Regular weight for FAR icons */
.d2-preset-icon i.far,
.d2-mood-emoji i.far,
.aim-tab-icon i.far,
.d2-palette-tab i.far {
    font-weight: 400 !important;
}

/* Brands weight for FAB icons */
.d2-preset-icon i.fab,
.d2-mood-emoji i.fab,
.aim-tab-icon i.fab,
.d2-palette-tab i.fab {
    font-family: "Font Awesome 5 Brands" !important;
    font-weight: 400 !important;
}

@keyframes d2-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ⚔️ SAMURAI ENHANCEMENT: Temporary chip styles */
.d2-chip--temporary {
    background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%) !important;
    border-color: rgba(255, 193, 7, 0.4) !important;
    color: #856404 !important;
    box-shadow: 0 2px 8px rgba(255, 193, 7, 0.15) !important;
    position: relative;
}

.d2-chip--temporary::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, rgba(255, 193, 7, 0.3), rgba(255, 152, 0, 0.3));
    border-radius: 8px;
    z-index: -1;
    animation: temporaryChipPulse 2s ease-in-out infinite;
}

.d2-chip--temporary small {
    font-size: 10px;
    font-weight: 600;
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.d2-chip--temporary .d2-chip-remove {
    background: rgba(255, 193, 7, 0.1);
    color: #856404;
    border-color: rgba(255, 193, 7, 0.3);
}

.d2-chip--temporary .d2-chip-remove:hover {
    background: rgba(255, 193, 7, 0.2);
    border-color: rgba(255, 193, 7, 0.5);
}

@keyframes temporaryChipPulse {
    0%, 100% { 
        opacity: 0.6; 
        transform: scale(1);
    }
    50% { 
        opacity: 1; 
        transform: scale(1.02);
    }
} 