* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #17212b;
    --bg-secondary: #1e2c3a;
    --bg-tertiary: #242f3d;
    --text-primary: #f5f5f5;
    --text-secondary: #8b9bab;
    --accent: #5eaaef;
    --accent-hover: #4a9ae0;
    --accent-dark: #3d8ad4;
    --border-color: #2d3b4b;
    --success: #4fae5e;
    --error: #e05555;
    --shadow: rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

.container {
    max-width: 480px;
    margin: 0 auto;
    padding: 16px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    text-align: center;
    padding: 20px 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.header h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 6px;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Sections */
.section {
    margin-bottom: 24px;
}

.section-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Niche Grid */
.niche-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.niche-btn {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 14px 8px;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.niche-btn:hover {
    border-color: var(--accent);
    background: var(--bg-tertiary);
    transform: translateY(-2px);
}

.niche-btn.selected {
    border-color: var(--accent);
    background: var(--accent-dark);
    box-shadow: 0 0 12px rgba(94, 170, 239, 0.3);
}

.niche-btn .emoji {
    font-size: 24px;
}

/* Input Field */
.input-field {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s ease;
}

.input-field::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

.input-field:focus {
    border-color: var(--accent);
}

/* Generate Button */
.generate-btn {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, var(--accent), #7c5eef);
    border: none;
    border-radius: 12px;
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(94, 170, 239, 0.3);
}

.generate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(94, 170, 239, 0.4);
}

.generate-btn:active {
    transform: translateY(0);
}

.generate-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Loading */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30px 0;
    gap: 16px;
}

.loading.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--bg-tertiary);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Result Section */
.result-section {
    text-align: center;
}

.result-section.hidden {
    display: none;
}

.image-container {
    background: var(--bg-secondary);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 16px;
    border: 2px solid var(--border-color);
}

.image-container img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 8px;
}

.download-btn {
    width: 100%;
    padding: 14px;
    background: var(--bg-secondary);
    border: 2px solid var(--success);
    border-radius: 12px;
    color: var(--success);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.download-btn:hover {
    background: var(--success);
    color: white;
}

/* Footer */
.footer {
    margin-top: auto;
    padding-top: 30px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 12px;
    opacity: 0.6;
}

/* Utility */
.hidden {
    display: none !important;
}

/* Error message */
.error-msg {
    background: rgba(224, 85, 85, 0.15);
    border: 1px solid var(--error);
    color: var(--error);
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 14px;
    margin-bottom: 16px;
}

/* Responsive */
@media (max-width: 360px) {
    .niche-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Telegram WebApp adaptation */
body.telegram-theme {
    background: var(--tg-theme-bg-color, var(--bg-primary));
    color: var(--tg-theme-text-color, var(--text-primary));
}

.telegram-theme .input-field {
    background: var(--tg-theme-secondary-bg-color, var(--bg-secondary));
    border-color: var(--tg-theme-hint-color, var(--border-color));
}

.telegram-theme .niche-btn {
    background: var(--tg-theme-secondary-bg-color, var(--bg-secondary));
    border-color: var(--tg-theme-hint-color, var(--border-color));
}