* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #8A2BE2;
    --primary-gradient: linear-gradient(135deg, #8A2BE2, #FF69B4);
    --secondary: #6e8efb;
    --accent: #FF69B4;
    --success: #4CAF50;
    --warning: #FF9800;
    --error: #f44336;
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #2d3748;
    --text-secondary: #718096;
    --text-tertiary: #a0aec0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1), 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1), 0 5px 10px rgba(0,0,0,0.05);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

body.dark-theme {
    --bg-primary: #1a202c;
    --bg-secondary: #2d3748;
    --bg-tertiary: #4a5568;
    --text-primary: #edf2f7;
    --text-secondary: #e2e8f0;
    --text-tertiary: #cbd5e0;
}

.app-container {
    max-width: 100%;
    min-height: 100vh;
    margin: 0 auto;
    background: var(--bg-primary);
    position: relative;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

.background-animation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--primary-gradient);
    opacity: 0.03;
    z-index: -1;
}

.app-header {
    background: var(--primary-gradient);
    color: white;
    padding: 20px 16px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-md);
}

.header-content {
    text-align: center;
    margin-bottom: 12px;
}

.header-content h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: -0.5px;
}

.header-content p {
    font-size: 0.9rem;
    opacity: 0.9;
    font-weight: 300;
}

.progress-container {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: white;
    transition: width 0.3s ease;
    border-radius: 2px;
}

.app-content {
    padding: 20px 16px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    flex: 1;
}

.section-hidden {
    display: none;
}

.section-active {
    display: block;
    animation: fadeInUp 0.5s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tabs-container {
    margin-bottom: 24px;
}

.tabs {
    display: flex;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 4px;
    margin-bottom: 16px;
}

.tab-button {
    flex: 1;
    padding: 12px 16px;
    background: none;
    border: none;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition);
}

.tab-button.active {
    background: white;
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.tab-button:hover:not(.active) {
    background: rgba(255, 255, 255, 0.1);
}

.tab-icon {
    font-size: 1.2rem;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.4s ease;
}

.characters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 20px;
}

.character-card {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid var(--bg-tertiary);
    position: relative;
}

.character-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.character-image {
    width: 100%;
    height: 200px;
    object-fit: cover;
    transition: var(--transition);
    background: linear-gradient(45deg, #f0f0f0, #e0e0e0);
    transition: opacity 0.3s ease;
}
.character-image[src*="base64"] {
    opacity: 0.6;
}

.character-card:hover .character-image {
    transform: scale(1.05);
}

.character-info {
    padding: 16px;
}

.character-name {
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary);
    font-size: 1rem;
}

.character-age {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 8px;
}

.character-description {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.4;
}

.detail-header {
    margin-bottom: 20px;
}

.back-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-secondary);
    border: none;
    color: var(--text-primary);
    font-weight: 500;
    cursor: pointer;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.back-button:hover {
    background: var(--bg-tertiary);
    transform: translateX(-4px);
}

.detail-card {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    margin-bottom: 32px;
    border: 1px solid var(--bg-tertiary);
}

.character-detail {
    display: flex;
    flex-direction: column;
}

.image-container {
    position: relative;
    overflow: hidden;
}

.detail-image {
    width: 100%;
    height: 350px;
    object-fit: cover;
}

.image-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(transparent, rgba(0,0,0,0.7));
}

.detail-info {
    padding: 24px;
    position: relative;
}

.character-badge {
    position: absolute;
    top: -12px;
    right: 24px;
    background: var(--primary-gradient);
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.detail-info h2 {
    font-size: 1.8rem;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-weight: 700;
}

.detail-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.detail-dot {
    color: var(--text-tertiary);
}

.character-status {
    color: var(--success);
    font-weight: 500;
}

.detail-info p {
    color: var(--text-secondary);
    line-height: 1.6;
    font-size: 0.95rem;
}

.scenarios-section {
    margin-top: 32px;
}

.section-title {
    text-align: center;
    margin-bottom: 24px;
}

.section-title h3 {
    font-size: 1.4rem;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-weight: 600;
}

.section-title p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.scenarios-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.scenario-card {
    background: var(--bg-primary);
    padding: 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid var(--bg-tertiary);
    position: relative;
    overflow: hidden;
}

.scenario-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 0;
    background: var(--primary-gradient);
    transition: var(--transition);
}

.scenario-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.scenario-card:hover::before {
    height: 100%;
}

.scenario-card.selected {
    border-color: var(--primary);
    background: linear-gradient(135deg, rgba(138, 43, 226, 0.05), rgba(255, 105, 180, 0.05));
}

.scenario-card.selected::before {
    height: 100%;
}

.scenario-name {
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-size: 1.1rem;
    position: relative;
    z-index: 1;
}

.scenario-description {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
    position: relative;
    z-index: 1;
}

.confirmation-content {
    text-align: center;
    padding: 40px 20px;
    max-width: 500px;
    margin: 0 auto;
}

.confirmation-icon {
    margin-bottom: 24px;
}

.checkmark-animation {
    animation: scaleIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes scaleIn {
    from {
        transform: scale(0);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.confirmation-content h2 {
    margin-bottom: 24px;
    color: var(--success);
    font-size: 1.8rem;
    font-weight: 700;
}

.confirmation-details {
    margin-bottom: 32px;
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: var(--radius-md);
}

.confirmation-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding: 8px 0;
}

.confirmation-item:last-child {
    margin-bottom: 0;
}

.confirmation-label {
    color: var(--text-secondary);
    font-weight: 500;
}

.confirmation-value {
    color: var(--text-primary);
    font-weight: 600;
}

.closing-notice {
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.9rem;
}

.loading-state, .error-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    grid-column: 1 / -1;
}

.error-state {
    color: var(--error);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--bg-tertiary);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Консоль теперь внизу страницы, не перекрывает контент */
.debug-panel {
    background: var(--bg-primary);
    border-top: 1px solid var(--bg-tertiary);
    margin-top: auto; /* Прижимаем к низу */
}

.debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--bg-tertiary);
}

.debug-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.debug-actions {
    display: flex;
    gap: 8px;
}

.debug-button {
    padding: 6px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--bg-tertiary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: var(--transition);
}

.debug-button:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.console-content {
    padding: 12px 16px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.8rem;
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg-primary);
    transition: max-height 0.3s ease;
}

.console-content.hidden {
    max-height: 0;
    padding: 0 16px;
    overflow: hidden;
}

.log-entry {
    margin-bottom: 6px;
    padding: 8px;
    border-radius: var(--radius-sm);
    border-left: 3px solid transparent;
}

.log-info {
    background: rgba(59, 130, 246, 0.08);
    border-left-color: #3b82f6;
    color: #3b82f6;
}

.log-success {
    background: rgba(34, 197, 94, 0.08);
    border-left-color: #22c55e;
    color: #22c55e;
}

.log-warning {
    background: rgba(234, 179, 8, 0.08);
    border-left-color: #eab308;
    color: #eab308;
}

.log-error {
    background: rgba(239, 68, 68, 0.08);
    border-left-color: #ef4444;
    color: #ef4444;
}

@media (min-width: 768px) {
    .character-detail {
        flex-direction: row;
    }
    
    .image-container {
        width: 350px;
        flex-shrink: 0;
    }
    
    .detail-image {
        width: 350px;
        height: 100%;
    }
    
    .detail-info {
        flex: 1;
        padding: 32px;
    }
    
    .characters-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

@media (max-width: 480px) {
    .app-header {
        padding: 16px 12px 12px;
    }
    
    .header-content h1 {
        font-size: 1.5rem;
    }
    
    .characters-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
    }
    
    .scenarios-list {
        grid-template-columns: 1fr;
    }
    
    .confirmation-content {
        padding: 20px 16px;
    }
    
    .debug-header {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }
    
    .debug-actions {
        width: 100%;
        justify-content: space-between;
    }
    
    .debug-button {
        flex: 1;
        text-align: center;
    }
}

.skeleton {
    animation: skeleton-loading 1.5s infinite;
}

.skeleton-image {
    width: 100%;
    height: 200px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}

.skeleton-text {
    height: 16px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    margin-bottom: 8px;
}

.skeleton-text.short {
    width: 60%;
}

@keyframes skeleton-loading {
    0% { opacity: 0.6; }
    50% { opacity: 0.8; }
    100% { opacity: 0.6; }
}

/* Добавьте эти стили в конец файла */

/* Глобальный индикатор загрузки */
.global-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, #8A2BE2, #FF69B4, #8A2BE2);
    background-size: 200% 100%;
    animation: loading-gradient 2s linear infinite;
    z-index: 9999;
    transition: opacity 0.3s ease;
}

.global-loader.hidden {
    opacity: 0;
    pointer-events: none;
}

@keyframes loading-gradient {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Стили для прелоадера */
.preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(-45deg, #8A2BE2, #FF69B4, #8A2BE2, #FF69B4);
    background-size: 400% 400%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: gradientShift 8s ease infinite;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.preloader__logo {
    width: 120px;
    height: 120px;
    margin-bottom: 20px;
    animation: pulse 2s infinite ease-in-out;
}

.preloader__img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 50%;
}

.preloader__text {
    color: white;
    font-size: 1.1rem;
    font-weight: 500;
    text-align: center;
    opacity: 0.9;
}

/* Анимация градиента фона */
@keyframes gradientShift {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

/* Анимация пульсации логотипа */
@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

/* Анимация появления контента */
@keyframes contentAppear {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Скрываем прелоадер после загрузки */
.preloader.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Показываем контент с анимацией */
.content-container.visible {
    animation: contentAppear 0.8s ease forwards;
}

/* Контейнер для контента с анимацией появления */
.content-container {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.content-container.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Улучшенный индикатор загрузки контента */
.content-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
}

.content-loading .spinner {
    width: 50px;
    height: 50px;
    border-width: 4px;
    margin-bottom: 20px;
}

.content-loading-text {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 10px;
}

.content-loading-subtext {
    color: var(--text-tertiary);
    font-size: 0.9rem;
}


/* Специфические стили для мини-приложения Telegram */
html, body {
    height: 100%;
}

body {
    overflow-x: hidden;
}

/* Улучшения для мобильных устройств */
@media (max-width: 768px) {
    .app-content {
        padding: 16px 12px;
    }
    
    .character-image {
        height: 180px;
    }
    
    .detail-image {
        height: 300px;
    }
    
    .character-info {
        padding: 12px;
    }
    
    .scenario-card {
        padding: 16px;
    }
}