:root {
    --bg-color: #121212;
    --chat-bg: #1e1e1e;
    --primary-color: #1db954; /* Spotify Green-ish */
    --primary-dark: #1aa34a;
    --text-color: #ffffff;
    --text-secondary: #b3b3b3;
    --bubble-user: #1db954;
    --bubble-ai: #2a2a2a;
    --border-color: #333;
    --safe-area-bottom: env(safe-area-inset-bottom, 20px);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100dvh;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 600px;
    margin: 0 auto;
    background-color: var(--bg-color);
    position: relative;
    overflow: hidden; /* Ensure bg slides don't spill */
}

/* Mobile Background Carousel */
.mobile-bg-carousel {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.mobile-bg-slide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 1.5s ease-in-out;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.mobile-bg-slide.active {
    opacity: 1;
}

.mobile-bg-slide.dalle-generated {
    opacity: 0.6 !important;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background-color: rgba(30, 30, 30, 0.6);
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 10;
    position: relative; /* Ensure it sits above bg */
}

.logo {
    font-weight: 700;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-controls button {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.2rem;
    padding: 8px;
    cursor: pointer;
    transition: color 0.3s ease, transform 0.2s ease;
}

.header-controls button.ready-green {
    color: var(--primary-color);
    text-shadow: 0 0 10px rgba(29, 185, 84, 0.5);
    animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Chat Area */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scroll-behavior: smooth;
    position: relative;
    background: transparent;
}

.chat-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    pointer-events: none;
}

.chat-container > * {
    position: relative;
    z-index: 1;
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

.message.user {
    align-self: flex-end;
    align-items: flex-end;
}

.message.ai {
    align-self: flex-start;
    align-items: flex-start;
}

/* AI messages with song grids use full width */
.message.ai.has-grid {
    max-width: 100%;
    width: 100%;
}

.message.ai.has-grid .bubble {
    width: 100%;
    background: transparent;
    padding: 0;
}

.bubble {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 1rem;
    line-height: 1.4;
    word-wrap: break-word;
}

.message.user .bubble {
    background-color: var(--bubble-user);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.ai .bubble {
    background-color: var(--bubble-ai);
    color: var(--text-color);
    border-bottom-left-radius: 4px;
}

/* Song Cards */
.song-card {
    margin-top: 8px;
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.2s;
    height: 100%; /* Fill grid cell */
    min-height: 120px; /* Consistent height */
}

.album-art {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    object-fit: cover;
    background-color: transparent;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

.song-card:active {
    background-color: rgba(255, 255, 255, 0.1);
}

.song-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1;
}

.card-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.play-links {
    display: flex;
    gap: 12px;
    margin-left: auto; /* Push to right */
}

.play-icon {
    font-size: 1.5rem;
    cursor: pointer;
    transition: transform 0.2s;
}

.play-icon:active {
    transform: scale(0.9);
}

.spotify-icon {
    color: #1DB954;
}

.youtube-icon {
    color: #FF0000;
}

.action-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
}

/* Hide redundant + button (AI is only source) */
.song-card .action-btn:not(.anchor-btn) {
    display: none;
}
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.action-btn:active {
    background-color: rgba(255, 255, 255, 0.1);
}

.action-btn:disabled {
    border-color: var(--primary-color);
    color: var(--primary-color);
    opacity: 0.8;
}

.song-title {
    font-weight: 600;
    font-size: 0.95rem;
    /* Allow wrapping */
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.2;
}

.song-artist {
    font-size: 0.8rem;
    color: var(--text-secondary);
    /* Allow wrapping */
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.2;
    margin-top: 4px;
}

.play-icon {
    color: var(--primary-color);
    font-size: 1.2rem;
}

/* Input Area */
.input-area {
    padding: 15px;
    padding-bottom: calc(15px + var(--safe-area-bottom));
    background-color: rgba(30, 30, 30, 0.6);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: flex-start; /* Align to top for textarea */
    gap: 10px;
    height: 20vh; /* User requested 20% height */
    min-height: 100px;
}

#chat-input {
    flex: 1;
    background-color: #2a2a2a;
    border: none;
    border-radius: 16px; /* Slightly less rounded for boxy feel */
    padding: 12px 16px;
    color: white;
    font-size: 1rem;
    font-family: inherit;
    resize: none; /* Prevent manual resize */
    height: 100%; /* Fill the container */
}

#chat-input:focus {
    outline: 2px solid var(--primary-color);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    padding: 10px;
    cursor: pointer;
    border-radius: 50%;
    transition: color 0.2s, background-color 0.2s;
    margin-top: 5px; /* Align with top of textarea */
}

.icon-btn:active {
    background-color: rgba(255, 255, 255, 0.1);
}

.icon-btn.primary {
    color: var(--primary-color);
}

.icon-btn.recording {
    color: #ff4444;
    animation: pulse 1.5s infinite;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background-color: var(--chat-bg);
    width: 90%;
    max-width: 400px;
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--border-color);
}

.modal-content.full-screen {
    width: 100%;
    height: 100%;
    max-width: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.setting-group {
    margin-bottom: 20px;
}

.setting-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

select {
    width: 100%;
    padding: 12px;
    background-color: #2a2a2a;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: white;
    font-size: 1rem;
}

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

.full-width {
    width: 100%;
    padding: 12px;
    background-color: var(--primary-color);
    border: none;
    border-radius: 8px;
    color: white;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
}

/* Builder Styles */
.builder-body {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 20px;
}

.input-group.anchor input {
    border: 2px solid var(--primary-color);
}

.seed-inputs input {
    width: 100%;
    padding: 12px;
    background-color: #2a2a2a;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: white;
    margin-bottom: 10px;
}

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

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

/* ==========================================================================
   Gutter Background Carousel (Desktop Only)
   ========================================================================== */

.gutter-bg-carousel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: -1;
    pointer-events: none;
}

.gutter-bg-slide {
    position: absolute;
    top: 3%;
    left: 3%;
    width: 94%;
    height: 94%;
    opacity: 0;
    transition: opacity 1.5s ease-in-out;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 16px;
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
}

.gutter-bg-slide.active {
    opacity: 1;
}

.gutter-bg-carousel.locked .gutter-bg-slide {
    opacity: 0 !important;
}

.gutter-bg-carousel.locked .gutter-bg-slide.dalle-generated {
    opacity: 0.6 !important;
    background-size: cover;
    background-position: center;
}

/* Hide carousel on mobile — use chat background instead */
@media (max-width: 768px) {
    .gutter-bg-carousel {
        display: none;
    }
    
    /* Default gradient backgrounds for mobile chat */
    .chat-container {
        position: relative;
        background: transparent;
    }
    
    .chat-container::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.6);
        pointer-events: none;
    }
    
    .chat-container > * {
        position: relative;
        z-index: 1;
    }
    
    /* Custom DALL-E/Gemini background */
    .chat-container.has-bg {
        /* No longer needed as app-container handles it */
    }
    
    .chat-container.has-bg::before {
        /* No longer needed */
    }
}
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* DALL-E Toggle Button */
.dalle-btn {
    color: #9f7aea !important;
    transition: all 0.3s ease;
}

.dalle-btn:hover {
    color: #b794f4 !important;
}

.dalle-btn.locked {
    color: #ffd700 !important;
}

/* Swiper Styles */
.swiper {
    width: 100%;
    padding-top: 20px;
    padding-bottom: 20px;
    /* Ensure it captures focus for keyboard events */
    outline: none;
}

.swiper-slide {
    background-position: center;
    background-size: cover;
    width: 250px; /* Fixed width for cards */
    height: auto;
    /* Remove default song-card margins since Swiper handles spacing */
}

.swiper-slide .song-card {
    margin: 0;
    width: 100%;
    height: 100%;
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
    /* Add 3D transform for flip effect later */
    transform-style: preserve-3d;
    transition: transform 0.6s;
}

/* Desktop Grid Styles */
.song-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    width: 100%;
    padding: 20px 0;
}

.action-card {
    background-color: rgba(255, 255, 255, 0.05);
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-secondary);
    height: 100%;
    min-height: 120px; /* Match song card height approx */
}

.action-card:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: translateY(-2px);
}

.action-card i {
    font-size: 1.5rem;
    margin-bottom: 10px;
}

.action-card span {
    font-size: 0.9rem;
    font-weight: 600;
}

/* Desktop Enhancements */
@media (min-width: 768px) {
    .app-container {
        max-width: 1000px; /* Wider layout for desktop */
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
        box-shadow: 0 0 40px rgba(0,0,0,0.3);
    }

    /* Hide Mobile Buttons on Desktop */
    #mobile-retry-btn, #mobile-like-all-btn {
        display: none !important;
    }

    /* Adjust Swiper for Desktop */
    .swiper-slide {
        width: 300px; /* Slightly wider cards on desktop */
    }
    
    .swiper-slide .song-card {
        /* Ensure cards look good in 'cards' or 'slide' effect */
        height: 100%;
    }

    .message {
        max-width: 85%; /* Allow wider bubbles on desktop to fit the carousel */
    }

    .input-area {
        width: 100%;
        border-top: 1px solid var(--border-color);
    }
    
    /* Better scrollbar for desktop */
    ::-webkit-scrollbar {
        width: 8px;
    }
    ::-webkit-scrollbar-track {
        background: var(--bg-color);
    }
    ::-webkit-scrollbar-thumb {
        background: #333;
        border-radius: 4px;
    }
    ::-webkit-scrollbar-thumb:hover {
        background: #555;
    }
}
