/* Opera: скрыть встроенную кнопку поверх видео (body + div[is-visible]) */
body + div[is-visible] {
    display: none !important;
}

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

:root {
    --app-bg: linear-gradient(135deg, #ff5fa2 0%, #a855f7 55%, #6d28d9 100%);
}

/* П. 1.10.2: отсутствие браузерной прокрутки и pull-to-refresh (тянуть вниз не обновляет страницу) */
html {
    height: 100%;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    overflow: hidden !important;
    overflow-x: hidden !important;
    overflow-y: hidden !important;
    overscroll-behavior: none;
    overscroll-behavior-x: none;
    overscroll-behavior-y: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    overflow: hidden !important;
    overflow-x: hidden !important;
    overflow-y: hidden !important;
    overscroll-behavior: none;
    overscroll-behavior-x: none;
    overscroll-behavior-y: none;
    -webkit-overflow-scrolling: auto;
    background: linear-gradient(135deg, #ff5fa2 0%, #a855f7 55%, #6d28d9 100%);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    min-height: -webkit-fill-available;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: manipulation;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Контейнер игры: на мобильных — на всю ширину/высоту, на широких — фиксированная ширина */
/* П. 1.6.2.7 / 1.6.1.8: без выделения и контекстного меню во внутреннем поле игры */
#game-root {
    width: 100%;
    height: 100%;
    height: calc(var(--vh, 1vh) * 100);
    min-height: 0;
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, #ff5fa2 0%, #a855f7 55%, #6d28d9 100%);
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* iOS/Safari: лонгтап — без системного меню «Сохранить картинку» / выделения на дочерних узлах */
#game-root * {
    -webkit-touch-callout: none;
}

#game-root ::selection {
    background: transparent;
    color: inherit;
}

#game-root input,
#game-root textarea {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

#game-root img,
#game-root video {
    -webkit-user-drag: none;
    user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    pointer-events: auto;
}

/* Прозрачный оверлей поверх медиа — при наведении курсор на div, не на картинку/видео */
.hover-block-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    pointer-events: auto;
}

/* Маскирующая полоса сверху — скрывает панель браузера (субтитры и т.д.), только для видео */
.video-controls-mask {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 48px;
    z-index: 10000;
    pointer-events: auto;
    background: linear-gradient(to bottom, rgba(102, 126, 234, 0.85) 0%, rgba(102, 126, 234, 0.4) 50%, transparent 100%);
    border-radius: 12px 12px 0 0;
    display: none;
}
.pre-story-image-wrap.has-video .video-controls-mask,
.dialog-media-wrap--video .video-controls-mask {
    display: block;
}

/* Широкие экраны (ПК): фиксированная ширина 720px, пропорции 9:16 */
@media (min-width: 721px) {
    #game-root {
        aspect-ratio: 9 / 16;
        width: min(100vw, calc(100vh * 9 / 16));
        height: min(100vh, calc(100vw * 16 / 9));
        max-width: 720px;
        box-shadow: 0 0 30px rgba(0, 0, 0, 0.3);
    }
}

@supports (height: 100dvh) {
    @media (min-width: 721px) {
        #game-root {
            width: min(100vw, calc(100dvh * 9 / 16));
            height: min(100dvh, calc(100vw * 16 / 9));
        }
    }
}

/* Сцены: overflow hidden — прокрутка только внутри контейнеров (.shop-container, .dialogs-list и т.д.) */
.scene {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
}

.scene.active {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Титульная сцена — полка с историями */
#scene-title {
    position: relative;
    flex-direction: column;
    align-items: stretch;
    min-height: 0;
    background: linear-gradient(135deg, #ff5fa2 0%, #a855f7 55%, #6d28d9 100%);
    padding: 0;
}

.title-top-left {
    position: absolute;
    top: 12px;
    left: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 5;
}

.version-label {
    position: absolute;
    top: 12px;
    left: 12px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    z-index: 5;
}

.title-score-display {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    max-width: calc(100% - 100px);
    font-size: clamp(13px, 3.5vw, 16px);
    font-weight: 700;
    color: #fff;
    background: rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.55);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.title-score-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #fbbf24;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25));
}

.title-score-star-svg {
    display: block;
}

.title-score-count {
    font-variant-numeric: tabular-nums;
    min-width: 2ch;
}

.top-telegram-btn {
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    color: #ffffff;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.55);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    letter-spacing: 0.02em;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.top-telegram-btn:active {
    background: rgba(255, 255, 255, 0.35);
}

.shelf-title {
    padding: 16px 16px 8px;
    font-size: clamp(16px, 4.2vw, 22px);
    font-weight: bold;
    color: white;
    text-align: center;
    flex-shrink: 0;
    line-height: 1.2;
}

.stories-shelf {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--app-bg);
}

.scroll-container {
    height: 80%;
    max-height: 850px;
    overflow-y: scroll;
    overflow-x: hidden;
    background: transparent;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    overscroll-behavior-y: contain;
}

.scroll-container::-webkit-scrollbar {
    display: none;
}

/* Высота контейнера = высота экрана минус заголовок и нижнее меню */
.stories-shelf-scroll-container {
    flex: 1;
    min-height: 0;
    height: calc(var(--vh, 1vh) * 100 - 100px);
    max-height: calc(var(--vh, 1vh) * 100 - 100px);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    padding: 15px 15px 90px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.5) transparent;
}

.stories-shelf-scroll-container::-webkit-scrollbar {
    width: 8px;
}

.stories-shelf-scroll-container::-webkit-scrollbar-track {
    background: transparent;
}

.stories-shelf-scroll-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.5);
    border-radius: 4px;
}

.stories-shelf-scroll-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.7);
}

.stories-shelf-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    align-content: start;
    min-height: min-content;
}

.story-tile {
    position: relative;
    width: 100%;
    aspect-ratio: 3/4;
    min-height: 200px;
    flex-shrink: 0;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    background: white;
    transition: transform 0.2s, box-shadow 0.2s;
}

.story-tile:active {
    transform: scale(0.98);
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.2);
}

.story-tile-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.story-tile-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 40%, transparent 100%);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    padding: 12px;
}

.story-tile-name {
    font-size: clamp(12px, 3.5vw, 16px);
    font-weight: bold;
    color: white;
    text-align: center;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
    margin-bottom: 8px;
}

.story-tile-price-badge {
    position: absolute;
    bottom: 85px;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 12px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
    color: white;
    z-index: 2;
}

.story-tile-progress-top {
    position: absolute;
    top: 8px;
    left: 10%;
    right: 10%;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 8px;
}

.story-tile-progress-bar {
    flex: 1;
    width: 100%;
    height: 4px;
    background: rgba(80, 80, 80, 0.65);
    border-radius: 2px;
    overflow: hidden;
}

.story-tile-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #f093fb, #f5576c);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.story-tile-percent {
    position: absolute;
    top: 6px;
    right: 0;
    font-size: clamp(10px, 2.5vw, 12px);
    font-weight: bold;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.story-tile-btn {
    padding: clamp(8px, 2vw, 12px) clamp(20px, 5vw, 28px);
    font-size: clamp(13px, 3.5vw, 16px);
    font-weight: bold;
    color: white;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border: none;
    border-radius: 20px;
    pointer-events: none;
    box-shadow: 0 3px 12px rgba(245, 87, 108, 0.4);
}

.story-tile-btn.loading {
    opacity: 0.7;
    pointer-events: none;
}

/* Пройденная история — окантовка и кнопка «Пройдена» */
.story-tile.story-tile-completed {
    border: 3px solid rgba(255, 215, 0, 0.9);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.3),
                0 0 20px rgba(255, 215, 0, 0.35),
                0 4px 15px rgba(0, 0, 0, 0.2);
}

.story-tile.story-tile-completed:active {
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.4),
                0 2px 8px rgba(0, 0, 0, 0.2);
}

.story-tile.story-tile-completed .story-tile-btn {
    background: linear-gradient(135deg, #2dd4bf 0%, #14b8a6 100%);
    color: white;
    box-shadow: 0 3px 12px rgba(45, 212, 191, 0.45);
}

.story-tile.story-tile-completed .story-tile-btn::before {
    content: '✓ ';
    font-weight: bold;
}


/* Сцена интро */
#scene-intro {
    background: var(--app-bg);
    justify-content: center;
    align-items: center;
}

.intro-video-wrap {
    position: relative;
    width: 100%;
    height: 100%;
}

.intro-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Сцена онбординг */
#scene-onboarding {
    background: var(--app-bg);
    justify-content: center;
    align-items: center;
    min-height: 0;
}

.onboarding-container {
    width: 100%;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.onboarding-image-wrap {
    position: relative;
    width: 90%;
    max-width: 350px;
    margin-bottom: 30px;
}

.onboarding-image {
    width: 100%;
    height: auto;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.next-button {
    padding: 15px 40px;
    font-size: 18px;
    font-weight: bold;
    color: white;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border: none;
    border-radius: 25px;
    cursor: pointer;
    box-shadow: 0 5px 20px rgba(245, 87, 108, 0.4);
    transition: transform 0.2s;
}

.next-button:active {
    transform: scale(0.95);
}

/* Сцена игры */
#scene-game {
    background: var(--app-bg);
    padding-bottom: 0;
}

.game-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* ПК-версия: чаты по центру 720px, по краям — градиент как на сцене 1 */
@media (min-width: 721px) {
    #scene-game,
    #scene-shop,
    #scene-stories,
    #scene-settings {
        background: var(--app-bg);
        justify-content: center;
    }

    #scene-game,
    #scene-shop,
    #scene-stories,
    #scene-settings {
        align-items: stretch;
    }

    #scene-game .game-container {
        max-width: 720px;
        width: 100%;
        height: 100%;
        min-height: 100%;
        background: var(--app-bg);
        border-radius: 0;
        box-shadow: 0 0 30px rgba(0, 0, 0, 0.2);
        overflow: hidden;
    }

    #scene-shop .shop-container,
    #scene-stories .stories-container,
    #scene-settings .settings-container {
        max-width: 720px;
        width: 100%;
        height: 100%;
        min-height: 100%;
        background: #f5f5f5;
        border-radius: 0;
        box-shadow: 0 0 30px rgba(0, 0, 0, 0.2);
    }

    .bottom-nav {
        width: min(720px, calc(100vw - 24px));
    }
}

/* Список диалогов */
.dialogs-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.dialogs-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 15px;
    background: var(--app-bg);
}

.dialogs-bottom {
    flex-shrink: 0;
    padding: 15px;
    padding-top: 0;
    padding-bottom: max(15px, env(safe-area-inset-bottom, 0px));
    background: var(--app-bg);
}

.dialog-item {
    display: flex;
    align-items: center;
    padding: 15px;
    margin-bottom: 10px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.dialog-item-to-title {
    background: white;
}

.dialog-item-to-title .dialog-name {
    color: #333;
}

.dialog-item-replay {
    background: rgba(255, 255, 255, 0.8);
    margin-top: 10px;
}

.dialog-item-replay .dialog-name {
    color: #666;
}

.dialog-item:active {
    transform: scale(0.98);
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.15);
}

.dialog-item-locked {
    opacity: 0.5;
    cursor: not-allowed !important;
    filter: grayscale(100%);
}

.dialog-item-locked:active {
    transform: none;
}

.lock-icon {
    position: absolute;
    top: -5px;
    right: -5px;
    font-size: 20px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.dialog-icon-wrapper {
    position: relative;
    margin-right: 15px;
    flex-shrink: 0;
}

.dialog-icon-frame {
    position: absolute;
    left: 0;
    top: 0;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    background-image: none;
    pointer-events: none;
}

.dialog-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #e0e0e0;
    position: relative;
    z-index: 1;
}

.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    z-index: 10;
    background: #f5576c;
    color: white;
    border-radius: 50%;
    min-width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    padding: 0 5px;
    box-shadow: 0 2px 5px rgba(245, 87, 108, 0.5);
    border: 2px solid white;
}

.dialog-info {
    flex: 1;
}

.dialog-name {
    font-size: 18px;
    font-weight: bold;
    color: #333;
    margin-bottom: 5px;
}

.dialog-preview {
    font-size: 14px;
    color: #666;
}

/* Окно чата */
.chat-window {
    width: 100%;
    height: 100%;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, #ff5fa2 0%, #a855f7 55%, #6d28d9 100%);
    position: relative;
}

.vn-stage {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
    background: #000;
    z-index: 1;
    /* Зазор под шапкой; на мобиле чуть меньше — персонаж крупнее к «Назад» */
    --vn-char-top-gap: clamp(8px, 2vmin, 18px);
}
.vn-bg {
    position: absolute;
    inset: 0;
    background: var(--vn-bg, linear-gradient(135deg, #ff5fa2 0%, #a855f7 55%, #6d28d9 100%));
    background-size: cover;
    background-position: center;
    filter: saturate(1.02) contrast(1.02);
}
.vn-characters {
    position: absolute;
    top: var(--vn-char-top-gap);
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 2;
}
.vn-character {
    position: absolute;
    /* Нижняя часть спрайта (~20%) за кадром; ширина/высота зоны больше — contain рисует крупнее */
    top: 0;
    bottom: -24%;
    max-height: none;
    width: min(175vw, 960px);
    background-position: bottom center;
    background-repeat: no-repeat;
    background-size: contain;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 160ms ease, transform 160ms ease, filter 160ms ease;
    filter: brightness(0.92) saturate(0.98);
}
.vn-character.is-visible {
    opacity: 1;
    transform: translateY(0);
}
.vn-character.is-active {
    filter: brightness(1) saturate(1.04);
}
/* Ближе к центру, чем раньше (-45%), но с лёгким заходом за край для двух персонажей.
   +15% ширины сцены от центра: НПС (.vn-left) — влево, ГГ (.vn-right) — вправо */
.vn-left {
    left: calc(-18% - 15%);
    right: auto;
}
.vn-right {
    right: calc(-18% - 15%);
    left: auto;
}

@media (max-width: 720px) {
    .vn-stage {
        --vn-char-top-gap: clamp(6px, 1.8vw, 14px);
    }
    .vn-character {
        /* без жёсткого max-width — иначе спрайт слишком мелкий на телефоне */
        width: min(205vw, 900px);
        top: 0;
        bottom: -22%;
    }
    .vn-left {
        left: calc(-20% - 15%);
    }
    .vn-right {
        right: calc(-20% - 15%);
    }
}

@media (min-width: 721px) {
    .vn-character {
        width: min(135%, 780px);
        top: 0;
        bottom: -26%;
    }
    .vn-left {
        left: calc(-24% - 15%);
    }
    .vn-right {
        right: calc(-24% - 15%);
    }
}

.vn-ui {
    position: absolute;
    inset: 0;
    /* Текстовый блок по центру экрана */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: stretch;
    padding: 14px 22px 18px;
    z-index: 3;
    pointer-events: none;
}
.vn-textbox {
    pointer-events: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: rgba(15, 18, 30, 0.68);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 14px;
    padding: 0;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: min(680px, 92vw);
    margin: 0 auto;
}
.vn-speaker-wrap {
    flex-shrink: 0;
    padding: 11px 16px 10px;
    background: linear-gradient(
        135deg,
        rgba(180, 120, 220, 0.35) 0%,
        rgba(120, 90, 180, 0.22) 50%,
        rgba(90, 70, 140, 0.28) 100%
    );
    border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}
.vn-speaker {
    font-size: 15px;
    font-weight: 700;
    color: #f5d4ff;
    letter-spacing: 0.04em;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
.vn-text {
    font-size: 22px;
    line-height: 1.38;
    color: rgba(255, 255, 255, 0.95);
    white-space: pre-wrap;
    padding: 16px 18px 18px;
}
.vn-choices {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: auto;
    max-width: min(680px, 92vw);
    margin-left: auto;
    margin-right: auto;
}
.vn-choice-btn {
    width: 100%;
    min-height: 64px;
    padding: 16px 18px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(15, 18, 30, 0.68);
    color: #fff;
    font-size: 18px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.vn-choice-btn:active {
    transform: scale(0.99);
    background: rgba(15, 18, 30, 0.78);
}
.vn-tap-layer {
    position: absolute;
    inset: 0;
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    z-index: 4;
}

.chat-header {
    background: white;
    padding: 15px;
    display: flex;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    z-index: 10;
    position: relative;
}

.back-button {
    background: none;
    border: none;
    font-size: 18px;
    color: #667eea;
    cursor: pointer;
    padding: 5px 10px;
    margin-right: 10px;
}

/* Название главы/чата в шапке не показываем — имя спикера в VN в текстовом окне */
.chat-title {
    display: none;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    padding-bottom: 100px; /* место под лентой, чтобы кнопки ответов не перекрывались сообщениями */
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
    background-image: url('assets/back_chat.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    -webkit-overflow-scrolling: touch;
}

.message {
    max-width: 75%;
    margin-bottom: 15px;
    animation: slideIn 0.3s ease-out;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

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

.message.left {
    align-self: flex-start;
    flex-direction: row;
}

.message.right {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar-frame {
    width: 54px;
    height: 54px;
    flex-shrink: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    background-image: none;
}
.message-avatar-frame .message-avatar {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.message-avatar {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.message-content {
    display: flex;
    flex-direction: column;
}

.message-sender-name {
    font-size: 12px;
    color: white;
    margin-bottom: 4px;
    font-weight: 600;
    text-shadow: 0 0 1px #555, 0 0 2px #555, 1px 1px 1px #555, -1px -1px 1px #555, 1px -1px 1px #555, -1px 1px 1px #555;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    font-size: 16px;
    line-height: 1.4;
}

.message.left .message-bubble,
.message.right .message-bubble {
    text-align: left;
}

.message.left .message-bubble {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.message.right .message-bubble {
    background: var(--app-bg);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 5px rgba(102, 126, 234, 0.3);
    text-align: left;
}

/* Реакции на сообщения НПС */
.message-reactions {
    display: flex;
    gap: 4px;
    margin-top: 6px;
    align-items: center;
}

.message-reaction-btn {
    background: rgba(0, 0, 0, 0.05);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background 0.2s;
}

.message-reaction-btn:hover {
    background: rgba(102, 126, 234, 0.15);
    transform: scale(1.15);
}

.message-reaction-btn:active {
    transform: scale(0.95);
}

.message-reactions-fixed .message-reaction-fixed {
    display: inline-block;
    font-size: 22px;
    animation: reactionPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes reactionPop {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.3);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Предистория при входе в историю */
.pre-story-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2610;
    padding: 20px;
}

.pre-story-content {
    background: var(--app-bg);
    border-radius: 24px;
    max-width: 560px;
    width: 100%;
    max-height: 92vh;
    padding: 20px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.pre-story-viewer {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: stretch;
    justify-content: center;
    margin-bottom: 16px;
}

.pre-story-arrow {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    color: white;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.pre-story-arrow:hover,
.pre-story-arrow:active {
    background: rgba(255, 255, 255, 0.5);
}

.pre-story-arrow:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pre-story-image-wrap {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    border-radius: 12px;
    overflow: hidden;
}

.pre-story-img,
.pre-story-video {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.2);
}

.pre-story-img {
    object-fit: contain;
}

.pre-story-video {
    object-fit: cover;
}

.pre-story-btn {
    flex-shrink: 0;
    padding: 16px 32px;
    font-size: 18px;
    font-weight: bold;
    background: white;
    color: #667eea;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.2s;
}

.pre-story-btn:active {
    transform: scale(0.98);
}

/* Окно подтверждения сброса прогресса */
.reset-progress-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2595;
    padding: 20px;
}

.reset-progress-content {
    background: var(--app-bg);
    border-radius: 24px;
    max-width: 360px;
    width: 100%;
    padding: 24px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.reset-progress-title {
    font-size: 20px;
    font-weight: bold;
    color: white;
    text-align: center;
    margin-bottom: 24px;
}

.reset-progress-buttons {
    display: flex;
    gap: 12px;
}

.reset-progress-btn {
    flex: 1;
    padding: 14px 20px;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.2s;
}

.reset-progress-yes {
    background: white;
    color: #667eea;
}

.reset-progress-no {
    background: rgba(255, 255, 255, 0.3);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.6);
}

.reset-progress-btn:active {
    transform: scale(0.98);
}

/* Окно по завершении всех глав чата */
.chat-completion-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2600;
    padding: 20px;
}

.chat-completion-content {
    background: var(--app-bg);
    border-radius: 24px;
    max-width: 360px;
    width: 100%;
    padding: 24px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.chat-completion-title {
    font-size: 20px;
    font-weight: bold;
    color: white;
    text-align: center;
    margin-bottom: 12px;
}

.chat-completion-text {
    font-size: 15px;
    color: rgba(255, 255, 255, 0.95);
    text-align: center;
    margin-bottom: 12px;
    line-height: 1.4;
}

.chat-completion-progress {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.85);
    text-align: center;
    margin-bottom: 16px;
    line-height: 1.4;
}

.chat-completion-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-completion-btn {
    padding: 14px 20px;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.2s;
}

.chat-completion-reward {
    font-size: 18px;
    font-weight: bold;
    color: #fbbf24;
    text-align: center;
    margin-bottom: 20px;
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.3);
}

.chat-completion-exit {
    background: rgba(255, 255, 255, 0.95);
    color: #667eea;
}

.chat-completion-telegram {
    background: linear-gradient(135deg, #2aabee 0%, #229ed9 100%);
    color: #fff;
}

.chat-completion-btn:active {
    transform: scale(0.98);
}

/* Экран истории: продолжить / переиграть */
.story-hub-card {
    margin: 12px 0 24px;
    padding: 20px 16px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
    text-align: center;
}

.story-hub-title {
    font-size: 20px;
    font-weight: bold;
    color: #fff;
    margin: 0 0 12px;
}

.story-hub-progress {
    font-size: 15px;
    color: rgba(255, 255, 255, 0.9);
    margin: 0 0 20px;
    line-height: 1.4;
}

.story-hub-btn {
    display: block;
    width: 100%;
    margin-bottom: 12px;
    padding: 16px 20px;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    transition: transform 0.15s;
}

.story-hub-btn:last-child {
    margin-bottom: 0;
}

.story-hub-btn:active {
    transform: scale(0.98);
}

.story-hub-continue {
    background: rgba(255, 255, 255, 0.95);
    color: #764ba2;
}

.story-hub-replay {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.35);
}

/* Окно покупки товара в магазине */
.shop-purchase-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2590;
    padding: 20px;
}

.shop-purchase-content {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border-radius: 24px;
    max-width: 400px;
    width: 100%;
    padding: 24px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.shop-purchase-title {
    font-size: 22px;
    font-weight: bold;
    color: white;
    text-align: center;
    margin-bottom: 20px;
}

.shop-purchase-preview {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
}

.shop-purchase-icon {
    width: 100px;
    height: 100px;
    object-fit: contain;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
}

.shop-purchase-info {
    flex: 1;
    min-width: 0;
}

.shop-purchase-name {
    font-size: 18px;
    font-weight: bold;
    color: white;
    margin-bottom: 8px;
}

.shop-purchase-desc {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.4;
}

.shop-purchase-price {
    font-size: 16px;
    font-weight: 600;
    color: white;
    margin-top: 10px;
}

.shop-purchase-currency-icon {
    vertical-align: middle;
    height: 1.2em;
    margin-left: 2px;
}

.shop-purchase-buttons {
    display: flex;
    gap: 12px;
}

.shop-purchase-btn {
    flex: 1;
    padding: 14px 20px;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.2s;
}

.shop-purchase-yes {
    background: white;
    color: #059669;
}

.shop-purchase-no {
    background: rgba(255, 255, 255, 0.3);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.6);
}

.shop-purchase-btn:active {
    transform: scale(0.98);
}

/* Панель «Купить историю» */
.purchase-story-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2600;
    padding: 20px;
}

.purchase-story-content {
    background: var(--app-bg);
    border-radius: 24px;
    max-width: 400px;
    width: 100%;
    padding: 24px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.purchase-story-title {
    font-size: 22px;
    font-weight: bold;
    color: white;
    text-align: center;
    margin-bottom: 20px;
}

.purchase-story-preview {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
}

.purchase-story-cover-wrap {
    position: relative;
    flex-shrink: 0;
}

.purchase-story-cover {
    width: 100px;
    height: 133px;
    border-radius: 12px;
    background-size: cover;
    background-position: center;
    background-color: rgba(0, 0, 0, 0.2);
}

.purchase-story-info {
    flex: 1;
    min-width: 0;
}

.purchase-story-name {
    font-size: 18px;
    font-weight: bold;
    color: white;
    margin-bottom: 8px;
}

.purchase-story-desc {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.4;
}

.purchase-story-price-line {
    margin-top: 10px;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.85);
}

.purchase-story-buttons {
    display: flex;
    gap: 12px;
}

.purchase-story-btn {
    flex: 1;
    padding: 14px 20px;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.2s;
}

.purchase-story-yes {
    background: white;
    color: #667eea;
}

.purchase-story-no {
    background: rgba(255, 255, 255, 0.3);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.6);
}

.purchase-story-btn:active {
    transform: scale(0.98);
}

/* Плашка «Бейдж получен» */
.badge-notification {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2500;
    padding: 12px 16px;
    transform: translateY(-100%);
    opacity: 0;
    transition: transform 0.4s ease-out, opacity 0.3s ease-out;
}

.badge-notification.visible {
    transform: translateY(0);
    opacity: 1;
}

.badge-notification.leaving {
    transform: translateY(-100%);
    opacity: 0;
}

.badge-notification-content {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--app-bg);
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
    max-width: 100%;
}

.badge-notification-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    flex-shrink: 0;
    overflow: hidden;
}

.badge-notification-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.badge-notification-text {
    flex: 1;
    min-width: 0;
}

.badge-notification-name {
    font-size: 16px;
    font-weight: bold;
    color: white;
    margin-bottom: 2px;
}

.badge-notification-desc {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.9);
}

.message-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 12px;
    object-fit: cover;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    cursor: pointer;
}

/* Модальное окно увеличения изображения */
.image-zoom-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    padding: 20px;
}

.image-zoom-img-wrap {
    position: relative;
    width: 100%;
    height: 80vh;
    max-width: 95vw;
    max-height: 85vh;
}

.image-zoom-modal .image-zoom-img {
    width: 100%;
    height: 100%;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 8px;
}

.image-zoom-close {
    position: fixed;
    top: 15px;
    right: 15px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    font-size: 36px;
    color: white;
    cursor: pointer;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    z-index: 3001;
}

.image-zoom-close:active {
    background: rgba(255, 255, 255, 0.3);
}

/* Видео в круге: прогресс по краю, кнопка плей по центру */
.video-container.video-circle {
    position: relative;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    cursor: pointer;
}

.video-circle .message-video-wrap {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 0;
}

.video-circle .message-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

.video-circle .video-progress-ring {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
    pointer-events: none;
    z-index: 1;
}

.video-circle .video-progress-bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.3);
    stroke-width: 4;
}

.video-circle .video-progress-fill {
    fill: none;
    stroke: #667eea;
    stroke-width: 4;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.1s linear;
}

.video-circle .video-play-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 3;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.9);
    color: #667eea;
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    padding-left: 4px;
}

.video-circle .video-play-btn:active {
    transform: translate(-50%, -50%) scale(0.95);
}

.chat-input-panel {
    background: transparent;
    padding: 15px;
    display: flex;
    gap: 10px;
    position: relative;
    z-index: 10;
    flex-shrink: 0;
}

.chat-end-panel {
    background: var(--app-bg);
    padding: 16px 20px 24px;
    margin-bottom: 16px;
    text-align: center;
    box-shadow: 0 -2px 10px rgba(102, 126, 234, 0.3);
    flex-shrink: 0;
}

.chat-end-text {
    color: white;
    font-size: 15px;
    font-weight: 500;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    display: block;
    margin-bottom: 12px;
}

.chat-end-home-btn {
    display: block;
    width: 100%;
    max-width: 280px;
    margin: 0 auto;
    padding: 12px 20px;
    font-size: 16px;
    font-weight: 600;
    color: #5a3d8a;
    background: white;
    border: 2px solid rgba(255, 255, 255, 0.9);
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}

.chat-end-home-btn:hover {
    background: rgba(255, 255, 255, 0.95);
    transform: scale(1.02);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

.chat-end-home-btn:active {
    transform: scale(0.98);
}

.response-button {
    flex: 1;
    padding: 12px 20px;
    font-size: 16px;
    color: white;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    background-clip: padding-box;
    border: 2px solid transparent;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(245, 87, 108, 0.3);
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    min-width: 0;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.response-button-text {
    display: block;
    width: 100%;
    text-align: center;
    line-height: 1.4;
}

.response-button:active {
    transform: scale(0.95);
}


/* Скрытие скроллбара но сохранение функциональности */
.dialogs-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.dialogs-list::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.dialogs-list::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
}

/* Основные сцены с навигацией */
.main-scene {
    padding-bottom: 0;
}

/* Когда открыт диалог/VN: список историй скрывают только через display:none на .dialogs-list,
   а .dialogs-panel с flex:1 оставался в потоке и забирал ~половину экрана (пустой градиент сверху). */
#scene-game.in-chat {
    padding-bottom: 0;
}

#scene-game.in-chat .dialogs-panel {
    display: none;
}

#scene-game.in-chat .chat-window {
    flex: 1;
    min-height: 0;
    width: 100%;
}

/* Нижняя панель навигации */
.bottom-nav {
    position: absolute;
    bottom: max(10px, env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    width: min(calc(100vw - 24px), 450px);
    max-width: calc(100% - 24px);
    min-width: 0;
    background: white;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 8px 4px;
    border-radius: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    box-sizing: border-box;
}

.nav-button {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 6px 2px;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 10px;
    margin: 0 2px;
}

.nav-button:active {
    transform: scale(0.95);
}

.nav-button.active {
    background: var(--app-bg);
    border-radius: 12px;
}

.nav-button.active .nav-icon {
    transform: scale(1.1);
}

.nav-button.active .nav-label {
    color: white;
    font-weight: bold;
}

.nav-icon {
    font-size: clamp(18px, 5vw, 24px);
    margin-bottom: 2px;
    transition: transform 0.2s;
}

.nav-label {
    font-size: clamp(7px, 2.2vw, 12px);
    color: #666;
    transition: color 0.2s;
    white-space: nowrap;
}

.nav-button.active .nav-label {
    color: white;
}

@media (max-width: 360px) {
    .bottom-nav {
        padding: 6px 2px;
        border-radius: 16px;
    }
    .nav-button {
        padding: 4px 1px;
        margin: 0 1px;
    }
    .nav-icon {
        font-size: 18px;
    }
    .nav-label {
        font-size: 7px;
    }
}

/* Сцена магазин */
#scene-shop {
    background: var(--app-bg);
    align-items: stretch;
}

.shop-container {
    width: 100%;
    height: 100%;
    min-height: 100%;
    padding: 20px 15px 90px;
    overflow-y: auto;
    background: #f5f5f5;
}

.shop-header {
    position: relative;
    margin-bottom: 20px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.shop-header .section-title {
    margin-bottom: 0;
    text-align: center;
}

.shop-header .shop-crystals {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
}

.shop-crystals {
    position: static;
    padding: 8px 14px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.18) 0%, rgba(118, 75, 162, 0.18) 100%);
    border: 1px solid rgba(102, 126, 234, 0.35);
    backdrop-filter: blur(10px) saturate(1.1);
    -webkit-backdrop-filter: blur(10px) saturate(1.1);
    box-shadow: 0 2px 10px rgba(102, 126, 234, 0.12);
}

.shop-crystals .crystals-count {
    color: #667eea;
}

.section-title {
    font-size: 24px;
    font-weight: bold;
    color: #333;
    margin-bottom: 20px;
    text-align: center;
}

.shop-items {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.shop-item {
    background: white;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.shop-item:active {
    transform: scale(0.98);
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.15);
}

.shop-item.owned {
    opacity: 0.6;
}

.shop-item-icon-wrap {
    width: 64px;
    height: 64px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 12px;
}

.shop-item-icon {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.shop-item-icon-placeholder {
    font-size: 28px;
}

.shop-item-name {
    font-size: 18px;
    font-weight: bold;
    color: #333;
    margin-bottom: 10px;
}

.shop-item-price {
    font-size: 16px;
    color: #667eea;
    font-weight: bold;
}

.shop-item-currency-icon {
    vertical-align: middle;
    height: 1.1em;
    margin-left: 2px;
    display: inline-block;
}

.shop-item.owned .shop-item-price {
    color: #4caf50;
    content: 'Куплено';
}

.shop-item.owned .shop-item-price::after {
    content: ' ✓';
}

/* Сцена истории */
#scene-stories {
    background: var(--app-bg);
    align-items: stretch;
}

#scene-stories .stories-container {
    background: #f5f5f5;
}

.rewards-title {
    text-align: center;
    margin-bottom: 20px;
}

.stories-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 15px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 12px;
    padding: 4px;
}

.stories-tab {
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: transparent;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
}

.stories-tab.active {
    background: white;
    color: #667eea;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.stories-tab:active {
    opacity: 0.9;
}

.stories-tab-content.hidden {
    display: none !important;
}

.rewards-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stories-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.reward-item {
    display: flex;
    align-items: center;
    background: white;
    border-radius: 15px;
    padding: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    border: 2px solid #e0e0e0;
    opacity: 0.7;
    min-width: 0;
}

.reward-item.reward-earned {
    border-color: rgba(102, 126, 234, 0.5);
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
    opacity: 1;
}

.reward-item-avatar {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    margin-right: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    border-radius: 50%;
    overflow: hidden;
}

.reward-item-icon {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.reward-item-icon-emoji {
    font-size: 28px;
}

.reward-item-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.reward-item-name {
    font-size: clamp(11px, 3.2vw, 16px);
    font-weight: bold;
    color: #333;
    margin-bottom: 4px;
    line-height: 1.2;
    word-break: normal;
    overflow-wrap: normal;
}

.reward-item-desc {
    font-size: clamp(10px, 2.6vw, 13px);
    color: #666;
    margin-bottom: 4px;
    line-height: 1.2;
    word-break: normal;
    overflow-wrap: normal;
}

.reward-item-bonus {
    font-size: clamp(10px, 2.4vw, 12px);
    color: #b45309;
    margin-bottom: 4px;
    line-height: 1.2;
}

.reward-item-status {
    font-size: clamp(10px, 2.2vw, 12px);
    color: #22c55e;
    line-height: 1.2;
    word-break: normal;
    overflow-wrap: normal;
}

.reward-item:not(.reward-earned) .reward-item-status {
    color: #999;
}

.stories-container {
    width: 100%;
    height: 100%;
    min-height: 100%;
    padding: 20px 15px 90px;
    overflow-y: auto;
    overflow-x: hidden;
}

.story-item {
    display: flex;
    align-items: center;
    background: white;
    border-radius: 15px;
    padding: 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.story-item:active {
    transform: scale(0.98);
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.15);
}

.story-item-avatar {
    flex-shrink: 0;
    margin-right: 15px;
}

.story-item-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    object-fit: cover;
}

.story-item-info {
    flex: 1;
    min-width: 0;
}

.story-item-name {
    font-size: 18px;
    font-weight: bold;
    color: #333;
    margin-bottom: 5px;
}

.story-item-preview {
    font-size: 14px;
    color: #666;
}

/* Всплывающее окно истории */
.story-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 20px;
}

.story-modal-content {
    background: white;
    border-radius: 20px;
    max-width: 480px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

/* Модальное окно наград */
.rewards-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 20px;
}

.rewards-modal-content {
    background: white;
    border-radius: 20px;
    max-width: 380px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    padding: 24px;
}

.rewards-modal-title {
    font-size: 22px;
    font-weight: bold;
    color: #333;
    margin-bottom: 4px;
    padding-right: 35px;
}

.rewards-modal-subtitle {
    font-size: 14px;
    color: #666;
    margin-bottom: 20px;
}

.badges-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.badge-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 8px;
    background: #f5f5f5;
    border-radius: 12px;
    text-align: center;
    border: 2px solid #e0e0e0;
    opacity: 0.6;
}

.badge-item.badge-earned {
    background: linear-gradient(135deg, rgba(240, 147, 251, 0.2) 0%, rgba(245, 87, 108, 0.2) 100%);
    border-color: #f5576c;
    opacity: 1;
}

.badge-icon {
    font-size: 32px;
    margin-bottom: 6px;
    line-height: 1;
}

.badge-name {
    font-size: 12px;
    font-weight: 600;
    color: #333;
    margin-bottom: 2px;
}

.badge-status {
    font-size: 10px;
    color: #22c55e;
}

.badge-status.badge-locked {
    color: #999;
}

.rewards-modal-content .modal-close {
    top: 12px;
    right: 12px;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 32px;
    color: #666;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:active {
    transform: scale(0.9);
}

.story-modal-x-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(0, 0, 0, 0.08);
    color: #333;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: background 0.2s;
}

.story-modal-x-close:hover,
.story-modal-x-close:active {
    background: rgba(0, 0, 0, 0.15);
}

/* Био: картинка сверху, текст снизу, div вместо img (без контекстного меню) */
.story-modal-image-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    max-height: 35vh;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
    margin-bottom: 15px;
    flex-shrink: 0;
    background: #f0f0f0;
}

.story-modal-image {
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
}

.story-modal-text {
    font-size: 16px;
    line-height: 1.7;
    color: #333;
    text-align: left;
    flex: 1;
    min-height: 120px;
    overflow-y: auto;
    padding-right: 8px;
    margin-bottom: 8px;
}

.story-modal-text .story-bio-p {
    margin: 0 0 1em 0;
    text-indent: 1.5em;
}

.story-modal-text .story-bio-p:first-child {
    margin-top: 0;
    text-indent: 0;
}

.story-modal-text .story-bio-p:last-child {
    margin-bottom: 0;
}

.story-modal-close-btn {
    display: block;
    width: 100%;
    margin-top: 16px;
    padding: 14px 24px;
    font-size: 18px;
    font-weight: 600;
    color: white;
    background: var(--app-bg);
    border: none;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.35);
    transition: transform 0.2s, box-shadow 0.2s;
}

.story-modal-close-btn:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.45);
}

.story-modal-close-btn:active {
    transform: scale(0.98);
}

/* Сцена настройки */
#scene-settings {
    background: var(--app-bg);
    align-items: stretch;
}

.settings-container {
    width: 100%;
    height: 100%;
    min-height: 100%;
    padding: 20px 15px 90px;
    overflow-y: auto;
    background: #f5f5f5;
}

.settings-list {
    background: white;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid #e0e0e0;
}

.settings-list > *:last-child {
    border-bottom: none;
}

.setting-link-item {
    display: flex;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid #e0e0e0;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    background: none;
    border-left: none;
    border-right: none;
    border-top: none;
    width: 100%;
    font: inherit;
    text-align: left;
    transition: background 0.2s;
}

.setting-link-item:hover,
.setting-link-item:active {
    background: #f8f9fa;
}

.setting-link-icon {
    font-size: 28px;
    margin-right: 15px;
    flex-shrink: 0;
}

.setting-link-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.setting-link-label {
    font-size: 18px;
    font-weight: 500;
    color: #333;
}

.setting-link-desc {
    font-size: 13px;
    color: #666;
}

.setting-link-arrow {
    font-size: 20px;
    color: #667eea;
    flex-shrink: 0;
}

.setting-link-btn {
    appearance: none;
}

.setting-label {
    font-size: 18px;
    color: #333;
    font-weight: 500;
}

/* Toggle switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.3s;
    border-radius: 28px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: #667eea;
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(22px);
}

/* Картинка/видео в плашке во время диалога (fullscreenImage / fullscreenVideo) — стиль как предистория */
.dialog-media-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    padding: 20px;
    box-sizing: border-box;
}

.dialog-media-content {
    background: var(--app-bg);
    border-radius: 24px;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    padding: 24px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.dialog-media-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
    position: relative;
}

.dialog-media-img,
.dialog-media-video {
    max-width: 100%;
    max-height: 60vh;
    object-fit: contain;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.2);
}

.dialog-media-video {
    width: 100%;
}

.dialog-media-btn {
    flex-shrink: 0;
    padding: 16px 32px;
    font-size: 18px;
    font-weight: bold;
    background: white;
    color: #667eea;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.2s;
}

.dialog-media-btn:active {
    transform: scale(0.98);
}

/* —— Мемо —— */
.memo-game-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    flex: 1;
    padding: 10px 12px 16px;
    box-sizing: border-box;
}

.memo-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
    flex-shrink: 0;
}

.memo-back-btn {
    flex-shrink: 0;
    padding: 10px 14px;
    font-size: 15px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.92);
    color: #6d28d9;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.memo-title-block {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    min-width: 0;
}

.memo-story-title {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.memo-level-progress {
    width: 100%;
    max-width: 200px;
    margin-top: 8px;
}

.memo-level-progress-track {
    height: 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.28);
    overflow: hidden;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12);
}

.memo-level-progress-fill {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, #fce7f3 0%, #ffffff 55%, #e9d5ff 100%);
    transition: width 0.35s ease;
}

.memo-moves {
    flex-shrink: 0;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
}

.memo-board-outer {
    flex: 1;
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    box-sizing: border-box;
    overflow: hidden;
}

.memo-board {
    width: 100%;
    max-width: min(96vw, 400px);
    margin: 0 auto;
    display: grid;
    gap: 8px;
    padding: 6px 0;
    align-content: start;
    justify-content: center;
    justify-items: center;
    box-sizing: border-box;
}

/* Пустые ячейки и «дыры» — те же пропорции, что у обложек (674×1000 px) */
.memo-grid-placeholder,
.memo-slot-empty {
    aspect-ratio: 674 / 1000;
    min-height: 0;
    width: 100%;
    max-width: var(--memo-cell-max-px, none);
    justify-self: center;
    visibility: hidden;
    pointer-events: none;
}

.memo-card {
    aspect-ratio: 674 / 1000;
    min-height: 0;
    width: 100%;
    max-width: var(--memo-cell-max-px, none);
    justify-self: center;
    padding: 0;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    perspective: 400px;
    background: transparent;
    -webkit-tap-highlight-color: transparent;
}

.memo-card:disabled {
    cursor: default;
}

.memo-card-inner {
    display: block;
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.35s ease;
    border-radius: 12px;
}

.memo-card.is-flipped .memo-card-inner {
    transform: rotateY(180deg);
}

/* Совпадение: плавное исчезновение перед снятием с поля */
.memo-card.memo-card--removing {
    pointer-events: none;
    z-index: 2;
    animation: memo-card-remove 0.58s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.memo-card.memo-card--removing .memo-card-inner {
    transition: none !important;
}

@keyframes memo-card-remove {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        opacity: 0;
        transform: scale(0.88);
    }
}

.memo-card-back,
.memo-card-front {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    backface-visibility: hidden;
    font-size: clamp(22px, 7vw, 36px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

.memo-card-back {
    background-color: #2d1b4e;
    background-image: url('assets/back_card.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    transform: rotateY(0deg);
}

.memo-card-front {
    background: linear-gradient(145deg, #fff 0%, #f3e8ff 100%);
    transform: rotateY(180deg);
    padding: 4px;
}

.memo-card-img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    pointer-events: none;
}

.memo-level-done {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 10, 30, 0.55);
    z-index: 80;
    padding: 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
}

.memo-level-done-inner {
    background: #fff;
    border-radius: 18px;
    padding: 24px 28px;
    max-width: 320px;
    width: 100%;
    text-align: center;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.memo-level-done-title {
    font-size: 20px;
    margin-bottom: 8px;
    color: #4c1d95;
}

.memo-level-done-points {
    font-size: clamp(26px, 7vw, 34px);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: #d97706;
    letter-spacing: 0.02em;
    margin-bottom: 10px;
    text-shadow: 0 2px 0 rgba(255, 255, 255, 0.9);
    opacity: 0;
    transform: scale(0.85) translateY(8px);
}

.memo-level-done-points.memo-level-done-points--pop {
    animation: memo-level-points-pop 0.65s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes memo-level-points-pop {
    0% {
        opacity: 0;
        transform: scale(0.7) translateY(12px);
    }
    55% {
        opacity: 1;
        transform: scale(1.08) translateY(-2px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.memo-level-done-stats {
    font-size: 15px;
    color: #555;
    margin-bottom: 18px;
}

.memo-next-btn {
    width: 100%;
    padding: 14px;
    font-size: 16px;
    font-weight: 700;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, #ec4899 0%, #a855f7 100%);
    color: #fff;
    cursor: pointer;
}

.memo-double-reward-btn {
    width: 100%;
    margin-top: 10px;
    padding: 12px 14px;
    font-size: 14px;
    font-weight: 700;
    border: 2px solid rgba(236, 72, 153, 0.55);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.95);
    color: #a21caf;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.memo-double-reward-btn:hover {
    box-shadow: 0 4px 14px rgba(168, 85, 247, 0.25);
}

.memo-double-reward-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    box-shadow: none;
}

.memo-double-reward-btn:active:not(:disabled) {
    transform: scale(0.98);
}

