:root {
    --bg1: #0b0716;
    --bg2: #271855;
    --bg3: #40286e;
    --brand: #8a2be2;
    --brand-light: #9d4edd;
    --brand-2: #8e44ad;
    --brand-3: #b06ab3;
    --accent: #ff6b6b;
    --accent-light: #ff8e8e;
    --text: #f7f3ff;
    --muted: #cfc7e9;
    --card: #160e2b90;
    --glass: rgba(255, 255, 255, .08);
    --glass-2: rgba(255, 255, 255, .12);
    --ok: #2ecc71;
    --warn: #f1c40f;
    --bad: #e74c3c;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
    --radius: 20px;
}

* {
    box-sizing: border-box
}

html,
body {
    height: 100%
}

body {
    margin: 0;
    font-family: "Nunito", system-ui, -apple-system, Segoe UI, Roboto, Arial, Helvetica, sans-serif;
    color: var(--text);
    background: radial-gradient(1200px 600px at 20% 0%, var(--bg3), transparent), radial-gradient(800px 400px at 80% 10%, #2b115e, transparent), linear-gradient(180deg, var(--bg1), var(--bg2));
    overflow-x: hidden;
}

/* Волшебный фон с анимацией */
.magic-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.magic-particle {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle, var(--brand-light) 0%, transparent 70%);
    opacity: 0.3;
    animation: float 15s infinite linear;
}

@keyframes float {
    0% {
        transform: translateY(0) translateX(0) rotate(0deg);
    }
    25% {
        transform: translateY(-20px) translateX(10px) rotate(90deg);
    }
    50% {
        transform: translateY(0) translateX(20px) rotate(180deg);
    }
    75% {
        transform: translateY(20px) translateX(10px) rotate(270deg);
    }
    100% {
        transform: translateY(0) translateX(0) rotate(360deg);
    }
}

.wrap {
    min-height: 100svh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: clamp(16px, 2.2vw, 32px);
    gap: 18px;
}

header {
    width: 100%;
    max-width: 1100px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border-radius: 16px;
    position: relative;
    z-index: 999;
    background: linear-gradient(180deg, rgba(255, 255, 255, .09), rgba(255, 255, 255, .02));
    border: 1px solid rgba(255, 255, 255, .1);
    box-shadow: var(--shadow);
    backdrop-filter: blur(6px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text)
}

.brand-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: conic-gradient(from 0deg, var(--brand), var(--brand-2), var(--brand-3), var(--brand));
    box-shadow: 0 0 30px #6a11cb66 inset, 0 8px 24px #0006;
    font-size: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand h1 {
    font-size: clamp(18px, 3.2vw, 26px);
    background: linear-gradient(135deg, var(--brand), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin: 0;
    font-weight: 900;
    letter-spacing: .3px
}

.lang-switch button,
.nav-secondary button {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, .2);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 12px;
    cursor: pointer;
}

.lang-switch button:hover,
.nav-secondary button:hover {
    background: rgba(255, 255, 255, .07)
}

.nav-secondary {
    display: flex;
    gap: 8px;
    align-items: center
}

main {
    width: 100%;
    max-width: 1100px;
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr;
}

.view {
    background: linear-gradient(180deg, rgba(255, 255, 255, .08), rgba(255, 255, 255, .02));
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: clamp(18px, 2.6vw, 28px);
    display: none;
    opacity: 0;
    transform: translateY(8px) scale(.98);
    transition: .45s cubic-bezier(.2, .8, .2, 1);
    backdrop-filter: blur(8px);
}

.view.active {
    display: block;
    opacity: 1;
    transform: translateY(0) scale(1)
}

.hero {
    text-align: center;
    padding: clamp(24px, 5vw, 48px) 12px;
    background: radial-gradient(600px 200px at 50% -10%, rgba(106, 17, 203, .35), transparent 60%), linear-gradient(180deg, rgba(255, 255, 255, .03), transparent 40%);
    border-radius: var(--radius);
    z-index: 1;
}

.hero h2 {
    margin: 0 0 10px;
    font-size: clamp(24px, 5.6vw, 44px);    
    background: linear-gradient(135deg, var(--brand), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.1
}

.hero p {
    margin: 0 auto 18px;
    font-size: clamp(14px, 2.4vw, 18px);
    max-width: 720px;
    color: var(--muted)
}

.cta {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 40px;
    border-radius: 14px;
    border: none;
    cursor: pointer;
    font-weight: 800;
    letter-spacing: .2px;
    font-size: 16px;
    color: white;
    background: linear-gradient(90deg, var(--brand), var(--brand-2));
    box-shadow: 0 8px 24px #6a11cb66;
    transition: transform .15s ease, box-shadow .2s ease;
}

.cta:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 26px #6a11cb88
}

.subcta {
    display: block;
    margin-top: 10px;
    font-size: 13px;
    color: #e9e0ff99
}

.upload {
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr;
}

.dropzone {
    border: 2px dashed rgba(255, 255, 255, .28);
    border-radius: 18px;
    padding: 20px;
    text-align: center;
    position: relative;
    background: linear-gradient(180deg, rgba(255, 255, 255, .04), rgba(255, 255, 255, .02));
    transition: .25s ease;
}

.dropzone.hover {
    border-color: #ffffff88;
    background: linear-gradient(180deg, rgba(255, 255, 255, .08), rgba(255, 255, 255, .03))
}

.dropzone input {
    display: none
}

.dz-icon {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    margin: 6px auto 10px;
    background: radial-gradient(circle at 30% 30%, #fff, #ffffff00 60%), conic-gradient(from 0deg, var(--brand), var(--brand-3));
    box-shadow: 0 12px 40px #0006;
}

.dz-title {
    font-weight: 900;
    margin: 4px 0 6px
}

.dz-hint {
    color: var(--muted);
    font-size: 14px
}

.dz-actions {
    margin-top: 14px;
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap
}

.btn {
    background: rgba(255, 255, 255, .06);
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, .12);
    padding: 10px 14px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 700;
    transition: .2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn:hover {
    background: rgba(255, 255, 255, .12)
}

.preview {
    display: none;
    justify-content: center;
    margin-top: 8px
}

.preview img {
    max-width: 100%;
    width: min(560px, 100%);
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, .12);
    box-shadow: var(--shadow)
}

.options {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.field {
    background: var(--glass);
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 16px;
    padding: 12px;
}

.field label {
    font-size: 14px;
    opacity: .9
}

.field select {
    width: 100%;
    margin-top: 8px;
    padding: 10px 12px;
    font-size: 16px;
    color: var(--text);
    background: rgba(255, 255, 255, .06);
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 12px;
    outline: none;
}

.gen {
    display: grid;
    place-items: center;
    text-align: center;
    gap: 10px;
}

.spark {
    width: 74px;
    height: 74px;
    border-radius: 50%;
    border: 3px solid transparent;
    border-top-color: #fff;
    border-right-color: #fff;
    animation: spin 1.2s linear infinite;
    box-shadow: 0 0 0 6px #ffffff14 inset, 0 0 20px #ffffff22 inset;
}

@keyframes spin {
    to {
        transform: rotate(360deg)
    }
}

.progress {
    width: min(520px, 92%);
    height: 10px;
    border-radius: 999px;
    overflow: hidden;
    background: #ffffff14;
    margin-top: 4px;
}

.progress .bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--brand), var(--brand-2), var(--brand-3));
    transition: width .3s ease;
}

.result {
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr;
}

.title {
    font-size: clamp(18px, 4.2vw, 28px);
    margin: 0;
    font-weight: 900;
    color: #f4e7ff;
}

.characters,
.story,
.actions {
    background: var(--glass);
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 16px;
    padding: 14px;
}

.characters h3 {
    margin: 0 0 8px
}

.characters ul {
    margin: 0;
    padding-left: 18px;
    line-height: 1.6
}

.story {
    line-height: 1.8
}

.actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap
}

.pill {
    font-size: 12px;
    font-weight: 800;
    padding: 6px 10px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--brand), var(--brand-2));
    border: 1px solid rgba(255, 255, 255, .16);
}
/* History (server) */

.history {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.card {
    background: var(--glass);
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 16px;
    overflow: hidden;
    transition: .25s ease;
    display: flex;
    flex-direction: column;
}

.card:hover {
    transform: translateY(-2px)
}

.card img {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover
}

.card .info {
    padding: 10px 12px;
    display: grid;
    gap: 8px
}

.card .meta {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap
}

.card .meta span {
    font-size: 12px;
    opacity: .8
}

.card .row-mini {
    display: flex;
    gap: 6px;
    flex-wrap: wrap
}

.btn.icon {
    padding: 8px 10px
}

.paginator {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 10px;
    flex-wrap: wrap
}

.paginator .page {
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, .14);
    background: rgba(255, 255, 255, .06);
    cursor: pointer
}

.paginator .page.active {
    background: linear-gradient(90deg, var(--brand), var(--brand-2));
    border-color: transparent
}

footer {
    width: 100%;
    max-width: 1100px;
    margin: 6px auto 10px;
    color: #cfc7e9aa;
    font-size: 12px;
    text-align: center;
}

.row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 5px
}

.right {
    margin-left: auto
}

.muted {
    color: var(--muted)
}

.center {
    text-align: center
}

.hidden {
    display: none !important
}

.hr {
    height: 1px;
    background: linear-gradient(90deg, transparent, #fff3, transparent);
    margin: 6px 0
}

@media (min-width: 960px) {
    .upload {
        grid-template-columns: 1.4fr 1fr
    }
    .result {
        grid-template-columns: 1fr
    }
}
/* Custom select */

.custom-select {
    position: relative;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    cursor: pointer;
    user-select: none;
    transition: 0.3s ease;
}

.custom-select .selected {
    padding: 14px;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: space-between;
}

.custom-select .selected::after {
    content: "▼";
    font-size: 12px;
    opacity: 0.6;
    transition: 0.3s ease;
}

.custom-select.open .selected::after {
    transform: rotate(180deg);
}

.custom-select .options {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    max-height: 0;
    overflow: hidden;
    background: rgba(15, 10, 30, .95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, .45);
    list-style: none;
    margin: 0;
    padding: 0;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: max-height .3s ease, opacity .25s ease;
}

.custom-select.drop-up .options {
    top: auto;
    bottom: calc(100% + 8px);
}

.custom-select .options::-webkit-scrollbar {
    width: 8px
}

.custom-select .options::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #6a11cb88, #8e44ad88);
    border-radius: 8px;
}

.custom-select.open .options {
    max-height: min(52vh, 420px);
    overflow-y: auto;
    opacity: 1;
    pointer-events: auto;
    padding: 6px 0;
}

.custom-select .options li {
    padding: 12px 16px;
    font-size: 16px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: 0.25s ease;
}

.custom-select .options li:hover {
    background: linear-gradient(90deg, rgba(106, 17, 203, 0.3), rgba(142, 68, 173, 0.3));
    padding-left: 22px;
}
/* Modal */

.modal-back {
    position: fixed;
    inset: 0;
    background: #0009;
    display: none;
    place-items: center;
    z-index: 9999;
    padding: 16px;
}

.modal-back.open {
    display: grid
}

.modal {
    width: min(880px, 100%);
    max-height: 90svh;
    overflow: auto;
    background: linear-gradient(180deg, rgba(255, 255, 255, .09), rgba(255, 255, 255, .03));
    border: 1px solid rgba(255, 255, 255, .16);
    border-radius: 18px;
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow);
    padding: 16px 16px 0px 16px;
    position: relative;
}

.modal-header {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: space-between
}

.modal-header h3 {
    margin: 0;
    font-size: 20px
}

.modal-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin: 4px 0 8px
}

.modal-body {
    line-height: 1.8;
    margin-bottom: 70px; /* ����� ��� ������������� ������ */
}

.modal .actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    /* margin-top: 12px */
}

.btn.primary {
    background: linear-gradient(90deg, var(--brand), var(--brand-2));
    border: 1px solid rgba(255, 255, 255, .2)
}

.story-modal-image {
    width: 100%;
    max-height: 300px;
    object-fit: cover;
    border-radius: 12px;
    margin-bottom: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.story-description {
    font-size: 16px;
    line-height: 1.6;
    color: var(--text);
    margin: 16px 0;
    white-space: pre-wrap;
}

.characters-list {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 12px;
    margin: 16px 0;
}

.characters-list strong {
    display: block;
    margin-bottom: 8px;
}

.characters-list ul {
    margin: 8px 0 0 0;
    padding-left: 20px;
}

/* ����� ��� ����������� ���� ������� */
.user-menu {
    position: relative;
    display: flex;
    align-items: center;
    z-index: 1000;
}

.user-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, .2);
    color: var(--text);
    padding: 6px 10px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
}

.user-trigger:hover {
    background: rgba(255, 255, 255, .07)
}

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: rgba(15, 10, 30, .95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, .16);
    border-radius: 12px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, .45);
    min-width: 180px;
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
}

.user-dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-dropdown .menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    color: var(--text);
    text-decoration: none;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s ease;
}

.user-dropdown .menu-item:hover {
    background: linear-gradient(90deg, rgba(106, 17, 203, 0.3), rgba(142, 68, 173, 0.3));
}

#donateBtn,
#logoutBtn {
    padding: 16px;
}

/* ��������� ��� ��������� */
@media (max-width: 768px) {
    .user-trigger {
        padding: 6px 8px;
        font-size: 13px;
    }
    
    .user-trigger span {
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .user-dropdown {
        min-width: 180px;
        right: -10px;
    }
}

@media (max-width: 480px) {
    .user-trigger span {
        max-width: 80px;
    }
}

@media (max-width: 768px) {
    header {
        padding: 10px 12px;
        gap: 12px;
    }
    
    .nav-secondary {
        gap: 6px;
        justify-content: flex-end;
        width: auto;
        order: 2;
        margin-top: 0;
    }
    
    .brand {
        flex: 1;
    }
    
    .brand h1 {
        font-size: 18px;
    }
    
    .nav-secondary button:not(.user-trigger) {
        padding: 6px 10px;
        font-size: 13px;
    }
    
    .lang-switch button {
        padding: 6px 10px;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .nav-secondary {
        gap: 4px;
    }
    
    .user-trigger span {
        display: none;
    }
    
    .user-trigger {
        padding: 6px;
    }
}

#userAvatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid #ffffff33;
    flex-shrink: 0;
}

/* ����� ��� ������������� ������ � ��������� ���� */
.sticky-actions {
    position: sticky;
    bottom: 0;
    background: linear-gradient(180deg, transparent, rgba(15, 10, 30, 0.95) 20%);
    padding: 16px 0 0 0;
    margin: 0 -16px -16px -16px;
    z-index: 10;
}

.sticky-actions::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 16px;
    background: linear-gradient(to bottom, transparent, rgba(15, 10, 30, 0.95));
}

.sticky-actions .row-mini {
    background: rgba(15, 10, 30, 0.95);
    padding: 12px 16px;
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.favorites-filter {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,.05);
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 12px;
    padding: 8px 12px;
    }

    .filter-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
    margin: 0;
    user-select: none;
    }

    .custom-checkbox {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    background: rgba(255,255,255,0.1);
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
    }

    .custom-checkbox:checked {
    background: var(--brand, #8B5FBF);
    border-color: var(--brand, #8B5FBF);
    }

    .custom-checkbox:checked::after {
    content: '✓';
    position: absolute;
    color: white;
    font-size: 12px;
    font-weight: bold;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    }

    .social-share-btn {
        transition: all 0.2s ease;
        border: none;
        border-radius: 8px;
        padding: 12px;
        color: white;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        font-size: 14px;
        font-weight: 500;
    }
    
    .social-share-btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    }
    
    .social-share-btn:active {
        transform: translateY(0);
    }
    
    /* Ца для конкретных платформ */
    .social-share-btn[data-platform="vk"] { background: #4C75A3; }
    .social-share-btn[data-platform="telegram"] { background: #0088cc; }
    .social-share-btn[data-platform="whatsapp"] { background: #25D366; }
    .social-share-btn[data-platform="x"] { background: #000000; }
    .social-share-btn[data-platform="facebook"] { background: #1877F2; }
    .social-share-btn[data-platform="viber"] { 
        background: #7360F2; 
        background: linear-gradient(135deg, #7360F2, #8B5FBF);
    }
    
    .social-share-btn[data-platform="viber"]:hover {
        background: linear-gradient(135deg, #8370FF, #9B6FCF);
        transform: translateY(-2px);
    }    
    .social-share-btn[data-platform="x"]:hover {
        background: #1a1a1a;
    }