:root {
    --primary: #5B8DEE;
    --primary-dark: #4070D8;
    --accent-coral: #FF8B6A;
    --accent-mint: #6DD3B5;
    --bg-cream: #FBF8F4;
    --bg-card: rgba(255, 255, 255, 0.85);
    --text-dark: #2D3748;
    --text-muted: #718096;
    --shadow-soft: 0 4px 20px rgba(91, 141, 238, 0.15);
    --shadow-hover: 0 8px 30px rgba(91, 141, 238, 0.25);
}

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

body {
    font-family: 'Space Grotesk', sans-serif;
    background: linear-gradient(135deg, #F0F4FF 0%, #FBF8F4 50%, #FFF5F0 100%);
    min-height: 100vh;
    color: var(--text-dark);
}

.app-container {
    min-height: 100vh;
    padding: 2rem 1rem;
}

.content-wrapper {
    max-width: 680px;
    margin: 0 auto;
}

.header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.title {
    font-family: 'Bricolage Grotesque', sans-serif;
    font-size: 3rem;
    font-weight: 800;
    color: var(--text-dark);
    text-shadow: 3px 3px 0 var(--primary), 6px 6px 0 rgba(91, 141, 238, 0.2);
    margin-bottom: 0.5rem;
    animation: titleFloat 3s ease-in-out infinite;
}

.title-icon {
    display: inline-block;
    animation: iconBounce 2s ease-in-out infinite;
}

@keyframes titleFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

@keyframes iconBounce {
    0%, 100% { transform: rotate(-5deg); }
    50% { transform: rotate(5deg); }
}

.tagline {
    font-size: 1.1rem;
    color: var(--text-muted);
    font-weight: 400;
}

.mode-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

.mode-btn {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 2px solid transparent;
    border-radius: 16px;
    padding: 1.25rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    box-shadow: var(--shadow-soft);
}

.mode-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.mode-btn.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(91, 141, 238, 0.2), var(--shadow-hover);
}

.mode-preview {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--accent-mint) 0%, var(--primary) 100%);
    border-radius: 12px;
}

.triptych-preview {
    display: flex;
    gap: 3px;
    background: transparent;
    padding: 8px;
}

.triptych-panel {
    flex: 1;
    height: 44px;
    background: linear-gradient(135deg, var(--accent-mint) 0%, var(--primary) 100%);
    border-radius: 4px;
}

.mode-label {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-dark);
}

.mode-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.examples-section {
    margin-bottom: 1.5rem;
}

.examples-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-right: 0.5rem;
}

.examples-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.example-pill {
    background: var(--bg-card);
    border: 1px solid rgba(91, 141, 238, 0.2);
    border-radius: 20px;
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-dark);
}

.example-pill:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.input-section {
    margin-bottom: 1.5rem;
}

.topic-input-wrapper {
    position: relative;
}

.topic-input {
    width: 100%;
    padding: 1.25rem 1.5rem;
    font-size: 1.1rem;
    font-family: 'Space Grotesk', sans-serif;
    border: 2px solid rgba(91, 141, 238, 0.2);
    border-radius: 16px;
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    box-shadow: var(--shadow-soft);
}

.topic-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(91, 141, 238, 0.15), var(--shadow-hover);
}

.topic-input::placeholder {
    color: var(--text-muted);
}

.char-counter {
    position: absolute;
    right: 1rem;
    bottom: -1.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.options-section {
    margin-bottom: 1.5rem;
}

.option-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 0.75rem;
}

.ratio-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.ratio-btn {
    background: var(--bg-card);
    border: 2px solid transparent;
    border-radius: 12px;
    padding: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
}

.ratio-btn:hover {
    border-color: rgba(91, 141, 238, 0.3);
}

.ratio-btn.active {
    border-color: var(--primary);
    background: rgba(91, 141, 238, 0.08);
}

.ratio-preview {
    width: 100%;
    max-width: 40px;
    max-height: 40px;
    background: linear-gradient(135deg, #E8E4E0 0%, #D4C4E8 100%);
    border-radius: 4px;
}

.ratio-label {
    font-weight: 600;
    font-size: 0.85rem;
}

.ratio-desc {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.language-select {
    width: 100%;
    padding: 0.9rem 1.25rem;
    font-size: 1rem;
    font-family: 'Space Grotesk', sans-serif;
    border: 2px solid rgba(91, 141, 238, 0.2);
    border-radius: 12px;
    background: var(--bg-card);
    cursor: pointer;
    transition: all 0.2s ease;
}

.language-select:focus {
    outline: none;
    border-color: var(--primary);
}

.style-accordion {
    margin-bottom: 1.5rem;
}

.accordion-toggle {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    background: var(--bg-card);
    border: 2px solid rgba(91, 141, 238, 0.1);
    border-radius: 12px;
    cursor: pointer;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-dark);
    transition: all 0.2s ease;
}

.accordion-toggle:hover {
    border-color: rgba(91, 141, 238, 0.3);
}

.accordion-arrow {
    transition: transform 0.3s ease;
    font-size: 0.8rem;
}

.accordion-arrow.open {
    transform: rotate(180deg);
}

.accordion-content {
    padding: 1.25rem;
    background: var(--bg-card);
    border: 2px solid rgba(91, 141, 238, 0.1);
    border-top: none;
    border-radius: 0 0 12px 12px;
    margin-top: -2px;
}

.color-palette {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.color-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.color-btn:hover {
    transform: scale(1.1);
}

.color-btn.active {
    border-color: var(--text-dark);
    box-shadow: 0 0 0 3px rgba(45, 55, 72, 0.2);
}

.generate-btn {
    width: 100%;
    padding: 1.25rem 2rem;
    font-size: 1.2rem;
    font-weight: 700;
    font-family: 'Bricolage Grotesque', sans-serif;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(91, 141, 238, 0.4);
    margin-bottom: 1.5rem;
    position: relative;
    overflow: hidden;
}

.generate-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(91, 141, 238, 0.5);
}

.generate-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.generate-btn.loading {
    color: transparent;
}

.loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 28px;
    height: 28px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

.error-message {
    background: #FFF0F0;
    color: #C53030;
    padding: 1rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    text-align: center;
    font-weight: 500;
}

.result-section {
    margin-bottom: 2rem;
    animation: fadeIn 0.5s ease;
}

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

.result-image-wrapper {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 1rem;
    box-shadow: var(--shadow-hover);
    margin-bottom: 1rem;
}

.result-image {
    width: 100%;
    border-radius: 12px;
    display: block;
}

.action-buttons {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.action-btn {
    flex: 1;
    min-width: 100px;
    padding: 0.9rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: 'Space Grotesk', sans-serif;
    background: var(--bg-card);
    border: 2px solid rgba(91, 141, 238, 0.2);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-dark);
}

.action-btn:hover {
    border-color: var(--primary);
    background: rgba(91, 141, 238, 0.08);
}

.prompt-preview {
    margin-bottom: 2rem;
}

.prompt-toggle {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.9rem 1.25rem;
    background: rgba(109, 211, 181, 0.1);
    border: 2px solid rgba(109, 211, 181, 0.3);
    border-radius: 12px;
    cursor: pointer;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.9rem;
    color: var(--text-dark);
    transition: all 0.2s ease;
}

.prompt-toggle:hover {
    background: rgba(109, 211, 181, 0.15);
}

.prompt-content {
    padding: 1rem;
    background: rgba(109, 211, 181, 0.05);
    border: 2px solid rgba(109, 211, 181, 0.2);
    border-top: none;
    border-radius: 0 0 12px 12px;
    margin-top: -2px;
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.6;
}

.history-section {
    margin-bottom: 2rem;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.history-header h3 {
    font-family: 'Bricolage Grotesque', sans-serif;
    font-size: 1.2rem;
    font-weight: 600;
}

.clear-btn {
    padding: 0.4rem 0.9rem;
    font-size: 0.8rem;
    font-family: 'Space Grotesk', sans-serif;
    background: transparent;
    border: 1px solid var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s ease;
}

.clear-btn:hover {
    background: #FFF0F0;
    border-color: #C53030;
    color: #C53030;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
}

.history-item {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-soft);
}

.history-item:hover {
    transform: scale(1.03);
    box-shadow: var(--shadow-hover);
}

.history-item img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}

.history-topic {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.7));
    color: white;
    padding: 2rem 0.5rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    text-align: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.history-item:hover .history-topic {
    opacity: 1;
}

.footer {
    text-align: center;
    padding: 2rem 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.footer a:hover {
    text-decoration: underline;
}

.footer-credit {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    opacity: 0.7;
}

@media (max-width: 640px) {
    .title {
        font-size: 2.2rem;
    }
    
    .mode-selector {
        grid-template-columns: 1fr;
    }
    
    .ratio-buttons {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .action-btn {
        width: 100%;
    }
}