:root {
    --bg-color: #050508;
    --card-bg: rgba(20, 20, 30, 0.7);
    --accent-color: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.4);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --input-bg: rgba(10, 10, 15, 0.8);
    --border-color: rgba(255, 255, 255, 0.1);
    --radius: 16px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
    background: var(--bg-color);
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(99, 102, 241, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(168, 85, 247, 0.05) 0%, transparent 40%);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
}

#app {
    width: 100%;
    max-width: 600px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    width: 32px;
    height: 32px;
}

h1 {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

h1 span {
    color: var(--accent-color);
}

.icon-btn {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: var(--accent-color);
}

/* Card Styling */
.generator-card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.input-group, .input-subgroup {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.textarea-container {
    position: relative;
    display: flex;
}

.textarea-container textarea {
    width: 100%;
    padding-right: 48px;
}

.magic-btn {
    position: absolute;
    right: 8px;
    bottom: 8px;
    background: var(--accent-glow);
    border: 1px solid var(--accent-color);
    color: var(--text-primary);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.magic-btn:hover {
    background: var(--accent-color);
    transform: scale(1.05);
}

.magic-btn.loading {
    animation: pulse 1.5s infinite;
    pointer-events: none;
    opacity: 0.7;
}

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

label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

textarea, input, select {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.2s;
}

textarea:focus, input:focus, select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.controls-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.dimension-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dimension-inputs input {
    width: 100%;
    text-align: center;
}

.primary-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 16px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s;
    box-shadow: 0 4px 15px var(--accent-glow);
}

.primary-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

.primary-btn:active {
    transform: translateY(0);
}

.primary-btn:disabled {
    background: #475569;
    cursor: not-allowed;
    box-shadow: none;
}

/* Result Area */
#result-area {
    position: relative;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    min-height: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.placeholder {
    text-align: center;
    color: var(--text-secondary);
}

.large-icon {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    opacity: 0.3;
}

#image-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

#output-image {
    width: 100%;
    height: auto;
    max-height: 500px;
    object-fit: contain;
    background: #000;
}

.image-actions {
    display: flex;
    gap: 10px;
    padding: 12px;
    background: rgba(0,0,0,0.5);
    width: 100%;
    justify-content: center;
}

.secondary-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid var(--border-color);
    color: white;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
}

.reset-btn {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.5);
    color: #ef4444;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 12px;
    width: 100%;
}

.reset-btn:hover {
    background: rgba(239, 68, 68, 0.3);
    border-color: #ef4444;
}

/* Loader */
.loader {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top: 3px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#loading-overlay, .error-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    padding: 20px;
    text-align: center;
}

/* History */
.history-section {
    margin-top: 10px;
}

.history-section h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

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

.history-item {
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.history-item:hover {
    border-color: var(--accent-color);
    transform: scale(1.05);
}

.history-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Utilities */
.hidden { display: none !important; }

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: white;
    padding: 12px 24px;
    border-radius: 99px;
    font-size: 0.9rem;
    box-shadow: 0 10px 20px rgba(0,0,0,0.3);
    z-index: 1000;
    transition: opacity 0.3s;
}

@media (max-width: 480px) {
    #app {
        padding: 12px;
    }
    .controls-grid {
        grid-template-columns: 1fr;
    }
    
    /* Reduce padding and font size for better mobile fit */
    textarea, input, select {
        padding: 8px;
        font-size: 14px;
    }
    
    /* Tighter spacing for dimension inputs */
    .dimension-inputs {
        gap: 4px;
    }
    
    /* Ensure number inputs don't overflow */
    .dimension-inputs input {
        min-width: 0;
    }
}
