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

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

/* Палитра (K-pop / неон): фон cyan→lavender→pink, акценты magenta #ec4899, cyan #22d3ee, золото #ffd700 */
:root {
    --bg-gradient: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    --accent-pink: #ec4899;
    --accent-cyan: #22d3ee;
    --accent-gold: #ffd700;
    --text-dark: #0f172a;
}

/* П. 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-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: 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(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 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(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* iOS / WebApp: без меню «Сохранить картинку» / «Копировать» и без выделения текста (п. 1.6.1.8 / 1.6.2.7) */
#game-root *:not(input):not(textarea) {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

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

#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(34, 211, 238, 0.85) 0%, rgba(34, 211, 238, 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(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 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(15, 23, 42, 0.45);
    z-index: 5;
}

.top-telegram-btn {
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    color: #0f172a;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.88);
    border-radius: 999px;
    border: 1px solid rgba(236, 72, 153, 0.28);
    box-shadow: 0 2px 12px rgba(34, 211, 238, 0.15);
    letter-spacing: 0.02em;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

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

.crystals-display {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    z-index: 5;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: background 0.2s;
}

.crystals-display:active {
    background: rgba(255, 255, 255, 0.4);
}

.crystals-icon {
    font-size: 20px;
    line-height: 1;
}

.crystals-count {
    font-size: 16px;
    font-weight: bold;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.shelf-title {
    padding: 16px 16px 8px;
    font-size: 20px;
    font-weight: bold;
    color: #0f172a;
    text-align: center;
    flex-shrink: 0;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}

.stories-shelf {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
}

.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 {
    display: block;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    font-size: clamp(12px, 3.5vw, 16px);
    font-weight: bold;
    color: #fff;
    text-align: center;
    line-height: 1.35;
    margin-bottom: 8px;
    padding: 10px 12px;
    background: rgba(15, 23, 42, 0.58);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    box-shadow:
        0 4px 18px rgba(0, 0, 0, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.12);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.story-tile-completed .story-tile-name {
    background: rgba(15, 23, 42, 0.68);
    border-color: rgba(255, 215, 0, 0.4);
    box-shadow:
        0 4px 18px rgba(0, 0, 0, 0.35),
        0 0 0 1px rgba(255, 215, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.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, #22d3ee, #ec4899);
    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: var(--bg-gradient);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 20px;
    pointer-events: none;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    box-shadow: 0 3px 14px rgba(34, 211, 238, 0.35), 0 2px 10px rgba(236, 72, 153, 0.3);
}

.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, #f472b6 0%, #06b6d4 100%);
    color: white;
    box-shadow: 0 3px 12px rgba(34, 211, 238, 0.45);
}

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


/* Сцена переодевания */
#scene-dressing {
    background: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    min-height: 0;
    height: 100%;
    height: calc(var(--vh, 1vh) * 100);
    max-height: calc(var(--vh, 1vh) * 100);
    position: relative;
    overflow: hidden;
}

.crystals-display-dressing {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 10;
}

.dressing-background {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100%;
    min-height: calc(var(--vh, 1vh) * 100);
    background: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.dressing-content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 12px;
    padding-bottom: max(80px, 60px + env(safe-area-inset-bottom, 0px));
    position: relative;
    z-index: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.dressing-character-selector {
    display: flex;
    gap: 10px;
    justify-content: center;
    padding: 8px 0;
    flex-shrink: 0;
}

.dressing-char-btn {
    width: 96px;
    height: 96px;
    padding: 0;
    border-radius: 50%;
    border: 4px solid rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.2);
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.2s, transform 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.dressing-char-btn.active {
    border-color: rgba(236, 72, 153, 1);
    box-shadow: 0 0 12px rgba(236, 72, 153, 0.6);
}

.dressing-char-btn:hover {
    transform: scale(1.05);
}

.dressing-char-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.dressing-viewport {
    flex: 1 1 auto;
    min-height: 180px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.dressing-character-wrap {
    position: relative;
    width: 75%;
    max-width: 340px;
    height: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dressing-character {
    width: 100%;
    height: 100%;
    min-height: 200px;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
}

.dressing-controls {
    flex-shrink: 0;
    padding: 12px 16px;
    margin: 0 12px 0;
    background: rgba(255, 255, 255, 0.45);
    border-radius: 20px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.dressing-costumes-scroll-wrap {
    overflow: hidden;
}

.dressing-costumes-scroll {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 8px 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.dressing-costumes-scroll::-webkit-scrollbar {
    height: 6px;
}

.dressing-costume-btn {
    position: relative;
    flex-shrink: 0;
    width: 72px;
    height: 72px;
    border-radius: 16px;
    border: 3px solid rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.dressing-costume-btn:hover {
    border-color: rgba(255, 255, 255, 0.9);
}

.dressing-costume-btn.active {
    border-color: rgba(236, 72, 153, 1);
    box-shadow: 0 0 12px rgba(236, 72, 153, 0.6);
}

.dressing-costume-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.dressing-costume-btn.dressing-costume-base {
    flex-direction: column;
    padding: 4px 4px 6px;
}
.dressing-costume-btn.dressing-costume-base img {
    width: 100%;
    flex: 1;
    min-height: 0;
    object-fit: contain;
}
.dressing-costume-base-label {
    font-size: 10px;
    color: rgba(0, 0, 0, 0.85);
    margin-top: 4px;
    line-height: 1.1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.dressing-costume-empty {
    font-size: 11px;
    color: rgba(0, 0, 0, 0.6);
}

.dressing-costume-price-badge {
    position: absolute;
    bottom: 2px;
    right: 2px;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 2px 6px;
    background: rgba(0, 0, 0, 0.75);
    border-radius: 8px;
    font-size: 11px;
    font-weight: bold;
    color: #fbbf24;
    z-index: 2;
}

.dressing-costume-price-badge .costume-crystal-icon {
    font-size: 12px;
}

/* Модалка покупки костюма */
.costume-purchase-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2600;
    padding: 20px;
}

.costume-purchase-content {
    background: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    border-radius: 20px;
    max-width: 320px;
    width: 100%;
    padding: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}

.costume-purchase-title {
    font-size: 18px;
    font-weight: bold;
    color: white;
    text-align: center;
    margin-bottom: 12px;
}

.costume-purchase-image-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 3/4;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 12px;
}

.costume-purchase-image {
    width: 100%;
    height: 100%;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
}

.costume-purchase-price {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #fbbf24;
    margin-bottom: 16px;
}

.costume-purchase-buttons {
    display: flex;
    gap: 10px;
}

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

.costume-purchase-yes {
    background: linear-gradient(135deg, #fde047 0%, #fbbf24 100%);
    color: white;
}

.costume-purchase-no {
    background: rgba(255, 255, 255, 0.9);
    color: #be185d;
}

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

/* Сцена переодевания — мобильные экраны */
@media (max-width: 720px) {
    .dressing-content {
        gap: 12px;
    }
    .dressing-char-btn {
        width: 72px;
        height: 72px;
    }
    .dressing-character-selector {
        padding: 6px 0;
    }
    .dressing-costume-btn {
        width: 64px;
        height: 64px;
    }
    .dressing-viewport {
        min-height: 140px;
    }
    .dressing-character-wrap {
        width: 70%;
        max-width: 260px;
    }
    .dressing-controls {
        padding: 8px 0;
    }
}

/* Сцена интро */
#scene-intro {
    background: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    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: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    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: var(--bg-gradient);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 25px;
    cursor: pointer;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    box-shadow: 0 5px 22px rgba(34, 211, 238, 0.35), 0 3px 14px rgba(236, 72, 153, 0.3);
    transition: transform 0.2s;
}

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

/* Сцена игры */
#scene-game {
    background: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    padding-bottom: 0;
}

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

/* Викторина */
.quiz-game-container {
    position: relative;
    padding: 12px 16px max(12px, env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
    overflow: hidden;
    /* Сторона квадрата картинки — от неё масштабируются ответы и нижняя кнопка */
    --quiz-img-cap: min(300px, max(120px, calc(100vh - 252px)));
    --quiz-option-fs: clamp(10px, calc(var(--quiz-img-cap) * 0.052), 17px);
    --quiz-option-py: clamp(5px, calc(var(--quiz-img-cap) * 0.04), 16px);
    --quiz-option-px: clamp(8px, calc(var(--quiz-img-cap) * 0.045), 20px);
    --quiz-option-radius: clamp(8px, calc(var(--quiz-img-cap) * 0.046), 15px);
    --quiz-option-gap: clamp(4px, calc(var(--quiz-img-cap) * 0.024), 10px);
    --quiz-option-shadow-y: clamp(2px, calc(var(--quiz-img-cap) * 0.018), 8px);
    --quiz-option-shadow-blur: clamp(8px, calc(var(--quiz-img-cap) * 0.07), 20px);
}

@supports (height: 100svh) {
    .quiz-game-container {
        --quiz-img-cap: min(
            300px,
            max(120px, min(calc(100svh - 252px), calc(100vh - 252px)))
        );
    }
}

.quiz-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    position: relative;
    justify-content: center;
}

.quiz-top-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    z-index: 2;
}

.quiz-top-actions .crystals-display {
    position: relative;
    top: 0;
    right: 0;
    padding: 6px 10px;
    border-radius: 999px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.12);
}

.quiz-top-actions .crystals-count {
    font-size: 14px;
}

.quiz-top-action-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.42);
    background: rgba(255, 255, 255, 0.16);
    color: rgba(255, 255, 255, 0.95);
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.18);
    backdrop-filter: blur(10px);
}
.quiz-top-action-btn:active {
    transform: translateY(1px);
}

.scene-topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 12px 8px;
}

/* Топбар на экранах наград/настроек делаем контрастным */
#scene-stories .scene-topbar,
#scene-settings .scene-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
}

@media (min-width: 721px) {
    #scene-stories .stories-container,
    #scene-settings .settings-container {
        background: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%) !important;
    }
}

#scene-stories .stories-container,
#scene-settings .settings-container {
    background: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%) !important;
}

#scene-stories .stories-tab-content,
#scene-settings .settings-list {
    padding-top: 8px;
}

.scene-back-btn {
    border: none;
    border-radius: 12px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.18);
    color: rgba(255, 255, 255, 0.95);
    font-weight: 700;
    cursor: pointer;
}

.scene-topbar .section-title {
    margin: 0;
    flex: 1;
    text-align: center;
}

.scene-topbar-spacer {
    width: 42px;
}

.our-games-panel {
    display: none !important;
    margin-top: 10px;
    padding: 12px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.28);
    backdrop-filter: blur(10px);
    width: min(520px, 100%);
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
}

.our-games-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.our-games-title {
    font-weight: 800;
    color: rgba(255, 255, 255, 0.95);
}

.our-games-devlink {
    color: rgba(255, 255, 255, 0.95);
    font-weight: 700;
    text-decoration: none;
    padding: 6px 10px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.28);
}

.our-games-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    max-height: min(46vh, 420px);
    overflow: auto;
    padding-right: 2px;
}

.our-game-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.12);
    width: 100%;
    box-sizing: border-box;
}

.our-game-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.our-game-meta {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.our-game-title {
    font-weight: 800;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.our-game-open {
    border: none;
    border-radius: 14px;
    padding: 10px 12px;
    background: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    color: white;
    font-weight: 800;
    cursor: pointer;
    flex-shrink: 0;
}

.our-games-empty {
    color: rgba(255, 255, 255, 0.92);
    font-weight: 700;
    text-align: center;
    padding: 10px 6px 2px;
}

/* В новом флоу нижнее меню не используется */
.bottom-nav {
    display: none !important;
}

/* В новом флоу не показываем кнопку "на главную" в игре */
#quiz-back-btn {
    display: none !important;
}

.quiz-back-btn {
    background: var(--bg-gradient);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: #fff;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    box-shadow: 0 2px 12px rgba(34, 211, 238, 0.3);
}

/* Название викторины скрыто в UI (остаётся для скринридеров) */
.quiz-title.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
    flex: 0;
}

/* В бесконечном маджонге не показываем заголовок "Маджонг" сверху */
.shelf-title {
    display: none !important;
}

/* Салют при завершении викторины (не перекрывает нижнюю кнопку «Пройти заново») */
.quiz-fireworks {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 64px;
    pointer-events: none;
    z-index: 14;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.35s ease;
}

.quiz-fireworks.quiz-fireworks--active {
    opacity: 1;
}

.quiz-firework-particle {
    position: absolute;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    margin-left: -3.5px;
    margin-bottom: 0;
    background: var(--fw-color, #fff);
    box-shadow: 0 0 10px var(--fw-color, #fff);
    animation: quiz-fw-burst var(--fw-dur, 1.1s) ease-out var(--fw-delay, 0s) forwards;
}

@keyframes quiz-fw-burst {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    55% {
        opacity: 1;
    }
    100% {
        transform: translate(var(--fw-dx, 0px), var(--fw-dy, -120px)) scale(0.35);
        opacity: 0;
    }
}

.quiz-progress-text {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.96);
    width: fit-content;
    max-width: calc(100% - 24px);
    text-align: center;
    line-height: 1.25;
    margin: 0 auto;
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.28);
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.12);
    position: absolute;
    left: calc(50% - clamp(10px, 3.2vw, 42px));
    top: 0;
    transform: translateX(-50%);
}

/* Экран «Результат» — белый заголовок с обводкой и мягким свечением */
.quiz-progress-text.quiz-progress-text--result {
    flex-basis: 100%;
    font-size: clamp(1.35rem, 4.2vw, 1.85rem);
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #fff;
    -webkit-text-fill-color: #fff;
    paint-order: stroke fill;
    -webkit-text-stroke: 0.07em rgba(15, 23, 42, 0.22);
    text-shadow:
        0 2px 14px rgba(236, 72, 153, 0.45),
        0 1px 0 rgba(255, 255, 255, 0.35);
    filter: drop-shadow(0 2px 8px rgba(15, 23, 42, 0.18));
}

.quiz-progress-holder {
    display: none !important;
    position: relative;
    width: 100%;
    margin-bottom: 16px;
    padding-top: 10px;
}

.quiz-progress-track {
    height: 8px;
    background: rgba(15, 23, 42, 0.1);
    border-radius: 5px;
    overflow: hidden;
}

.quiz-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #ec4899 0%, #22d3ee 100%);
    border-radius: 5px;
    transition: width 0.42s cubic-bezier(0.33, 1, 0.68, 1);
    box-shadow:
        0 0 12px rgba(236, 72, 153, 0.45),
        0 0 18px rgba(34, 211, 238, 0.25);
    will-change: width;
}

/* Якорь для «фейерверка» звёздочек на правом краю заполненной полосы */
.quiz-progress-sparkle-host {
    position: absolute;
    left: 0%;
    top: 14px;
    width: 0;
    height: 0;
    transform: translateX(-50%);
    pointer-events: none;
    z-index: 4;
}

.quiz-progress-star-bit {
    position: absolute;
    left: 0;
    top: 0;
    font-size: 11px;
    line-height: 1;
    color: #fff;
    text-shadow:
        0 0 6px #22d3ee,
        0 0 10px #ec4899,
        0 0 4px #fff;
    animation: quiz-prg-star-pop 0.65s ease-out forwards;
    transform: translate(-50%, -50%);
}

@keyframes quiz-prg-star-pop {
    0% {
        transform: translate(-50%, -50%) scale(0.15) rotate(0deg);
        opacity: 1;
    }
    35% {
        opacity: 1;
    }
    100% {
        transform: translate(calc(-50% + var(--sx, 0px)), calc(-50% + var(--sy, -28px))) scale(0.85) rotate(var(--rot, 180deg));
        opacity: 0;
    }
}

.quiz-root {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Вопрос: карточка сверху, кнопки сразу под ней (без пустого «колодца» по центру) */
.quiz-flow {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: var(--quiz-option-gap, 6px);
    overflow: hidden;
}

/* Место под шапку, прогресс, текст, кнопки — картинка сжимается, без скролла внутри карточки */
.quiz-question-stage {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 2px 6px 0;
    overflow: hidden;
}

.quiz-question-card {
    width: 100%;
    max-width: min(420px, 100%, calc(var(--quiz-img-cap, 300px) + 120px));
    max-height: 100%;
    min-height: 0;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.97) 0%, rgba(253, 242, 248, 0.95) 100%);
    border-radius: clamp(14px, 4vw, 22px);
    padding: clamp(10px, 2.8vw, 22px) clamp(12px, 3.2vw, 20px) clamp(10px, 2.5vw, 20px);
    box-shadow:
        0 16px 48px rgba(236, 72, 153, 0.12),
        0 8px 24px rgba(34, 211, 238, 0.1),
        0 4px 12px rgba(15, 23, 42, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.95);
}

.quiz-question-badge {
    display: block;
    width: fit-content;
    margin: 0 auto clamp(6px, 1.8vw, 14px);
    padding: 3px clamp(10px, 2.5vw, 14px);
    font-size: clamp(9px, 2.4vw, 11px);
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #be185d;
    background: rgba(236, 72, 153, 0.12);
    border-radius: 999px;
    border: 1px solid rgba(236, 72, 153, 0.25);
}

.quiz-question-text {
    color: #0f172a;
    font-size: clamp(12px, calc(var(--quiz-img-cap, 300px) * 0.058), 18px);
    font-weight: 600;
    line-height: 1.45;
    letter-spacing: 0.02em;
    margin: 0;
    text-align: center;
    text-wrap: balance;
    flex-shrink: 0;
}

/*
 * Квадрат: сторона уменьшается на низком экране (svh − запас под UI),
 * чтобы карточка целиком помещалась без overflow.
 */
.quiz-question-image-wrap {
    position: relative;
    margin: clamp(6px, 1.8vw, 16px) auto 0;
    width: min(100%, var(--quiz-img-cap, 300px));
    max-width: 100%;
    border-radius: clamp(10px, calc(var(--quiz-img-cap, 300px) * 0.052), 16px);
    overflow: hidden;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
    flex-shrink: 1;
    min-height: 0;
}

.quiz-question-image-wrap::before {
    content: '';
    display: block;
    width: 100%;
    padding-bottom: 100%;
}

.quiz-question-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    pointer-events: none;
    -webkit-user-drag: none;
    user-select: none;
    transition: opacity 0.22s ease;
    border-radius: inherit;
}

/* Прозрачный слой поверх: нет клика по картинке, сложнее вызвать «Сохранить» по фону */
.quiz-question-image-shield {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    background: transparent;
    cursor: default;
    pointer-events: auto;
    touch-action: pan-y;
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
}

.quiz-options {
    flex-shrink: 0;
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: var(--quiz-option-gap, 8px);
    width: 100%;
    max-width: min(420px, 100%);
    margin: 0 auto;
    padding: 0 0 4px;
    box-sizing: border-box;
}

.quiz-option-btn {
    width: 100%;
    padding: var(--quiz-option-py, 12px) var(--quiz-option-px, 16px);
    border: none;
    border-radius: var(--quiz-option-radius, 14px);
    background: var(--bg-gradient);
    color: #fff;
    font-size: var(--quiz-option-fs, 15px);
    font-weight: 600;
    line-height: 1.35;
    text-align: center;
    cursor: pointer;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    box-shadow:
        0 var(--quiz-option-shadow-y, 4px) var(--quiz-option-shadow-blur, 16px) rgba(34, 211, 238, 0.35),
        0 calc(var(--quiz-option-shadow-y, 4px) * 0.45) calc(var(--quiz-option-shadow-blur, 16px) * 0.55) rgba(236, 72, 153, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.35);
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.quiz-option-btn:hover {
    filter: brightness(1.05);
    box-shadow:
        0 8px 26px rgba(129, 140, 248, 0.4),
        0 4px 14px rgba(236, 72, 153, 0.3);
}

.quiz-option-btn:active {
    transform: scale(0.98);
    filter: brightness(0.97);
}

.quiz-option-btn--with-image {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: clamp(6px, calc(var(--quiz-img-cap, 300px) * 0.028), 12px);
    text-align: left;
    padding: var(--quiz-option-py, 10px) clamp(8px, calc(var(--quiz-img-cap, 300px) * 0.042), 14px);
}

.quiz-option-thumb-img {
    flex-shrink: 0;
    width: clamp(36px, calc(var(--quiz-img-cap, 300px) * 0.17), 52px);
    height: clamp(36px, calc(var(--quiz-img-cap, 300px) * 0.17), 52px);
    border-radius: clamp(8px, calc(var(--quiz-img-cap, 300px) * 0.04), 12px);
    object-fit: cover;
    background: rgba(0, 0, 0, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.25);
}

.quiz-option-label {
    flex: 1;
    min-width: 0;
    text-align: left;
    line-height: 1.35;
}

.quiz-result {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    text-align: center;
    padding: 6px 8px 8px;
    overflow: hidden;
    /* Высота портрета 3:4 — остаток экрана под шапку, прогресс, донат, текст и нижнюю кнопку */
    --result-img-max-h: min(232px, max(76px, calc(100vh - 384px)));
}

@supports (height: 100svh) {
    .quiz-result {
        --result-img-max-h: min(232px, max(76px, calc(100svh - 384px)));
    }
}

/* Портрет 3:4 — явная высота (масштаб вниз), фон contain без обрезки */
.quiz-result-image-wrap {
    position: relative;
    width: min(100%, calc(var(--result-img-max-h) * 0.75), 300px);
    height: var(--result-img-max-h);
    margin: 0 auto 10px;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 8px 28px rgba(15, 23, 42, 0.18);
    flex-shrink: 1;
    min-height: 0;
    align-self: center;
    box-sizing: border-box;
    background: rgba(255, 255, 255, 0.12);
}

.quiz-result-image-wrap::before {
    display: none;
}

.quiz-result-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    pointer-events: none;
    -webkit-user-drag: none;
    user-select: none;
}

.quiz-result-image-shield {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    background: transparent;
    cursor: default;
    pointer-events: auto;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
}

.quiz-result-chart-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin: 0 auto 8px;
    padding: 0 8px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.quiz-result-donut {
    --correct-frac: 0.5;
    width: 108px;
    height: 108px;
    flex-shrink: 0;
    border-radius: 50%;
    background: conic-gradient(
        from -90deg,
        #14b8a6 0turn calc(var(--correct-frac) * 1turn),
        #fb7185 0
    );
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.15);
    position: relative;
}

.quiz-result-donut-hole {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(180deg, #fff 0%, #f8fafc 100%);
    border: 1px solid rgba(148, 163, 184, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1px;
    font-size: 17px;
    font-weight: 800;
    color: #0f172a;
    letter-spacing: -0.02em;
}

.quiz-result-donut-correct {
    color: #0d9488;
}

.quiz-result-donut-sep {
    color: #94a3b8;
    font-weight: 700;
    font-size: 15px;
}

.quiz-result-donut-total {
    color: #64748b;
    font-weight: 700;
}

.quiz-result-donut-legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
    font-size: 13px;
    font-weight: 600;
    color: #334155;
}

.quiz-result-legend {
    display: flex;
    align-items: center;
    gap: 8px;
}

.quiz-result-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.quiz-result-legend--ok .quiz-result-legend-dot {
    background: #14b8a6;
    box-shadow: 0 0 0 2px rgba(20, 184, 166, 0.25);
}

.quiz-result-legend--bad .quiz-result-legend-dot {
    background: #fb7185;
    box-shadow: 0 0 0 2px rgba(251, 113, 133, 0.25);
}

.quiz-result-title {
    color: #0f172a;
    font-size: clamp(17px, 4.8vw, 22px);
    margin: 0 0 6px;
    padding: 0 8px;
    line-height: 1.25;
    text-wrap: balance;
    flex-shrink: 0;
}

.quiz-result-score {
    color: #be185d;
    font-size: clamp(13px, 3.6vw, 15px);
    font-weight: 700;
    margin: 0 0 8px;
    padding: 0 12px;
    text-align: center;
    letter-spacing: 0.02em;
    flex-shrink: 0;
}

.quiz-result-desc-plate {
    width: 100%;
    max-width: 328px;
    margin: 0 auto 8px;
    padding: 10px 14px;
    box-sizing: border-box;
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.96) 0%, rgba(253, 242, 248, 0.94) 50%, rgba(238, 242, 255, 0.92) 100%);
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.95);
    box-shadow:
        0 12px 40px rgba(236, 72, 153, 0.12),
        0 6px 20px rgba(34, 211, 238, 0.1),
        0 2px 8px rgba(15, 23, 42, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 1);
}

.quiz-result-desc {
    color: #1e293b;
    font-size: 14px;
    line-height: 1.55;
    letter-spacing: 0.01em;
    margin: 0;
    text-align: center;
    text-wrap: pretty;
}

.quiz-footer-actions {
    position: relative;
    z-index: 20;
    flex-shrink: 0;
    padding-top: clamp(6px, calc(var(--quiz-img-cap, 300px) * 0.035), 14px);
    text-align: center;
}

.quiz-replay-btn {
    background: var(--bg-gradient);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: #fff;
    padding: var(--quiz-option-py, 10px) var(--quiz-option-px, 16px);
    border-radius: var(--quiz-option-radius, 12px);
    font-size: clamp(11px, calc(var(--quiz-img-cap, 300px) * 0.046), 15px);
    font-weight: 600;
    cursor: pointer;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    box-shadow: 0 var(--quiz-option-shadow-y, 3px) var(--quiz-option-shadow-blur, 14px) rgba(129, 140, 248, 0.35);
}

.quiz-error {
    color: #ffcccc;
    padding: 24px;
    text-align: center;
    font-size: 15px;
}

/* --- Маджонг --- */
.quiz-mahjong-stage {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(6px, 1.5vmin, 12px);
    min-height: 0;
    flex: 1;
    overflow: hidden;
}

.mahjong-difficulty-hint {
    display: none !important;
    margin: 0;
    text-align: center;
    font-size: clamp(11px, calc(var(--quiz-img-cap, 300px) * 0.042), 14px);
    font-weight: 600;
    color: rgba(255, 255, 255, 0.92);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.mahjong-board-wrap {
    width: 100%;
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    max-height: min(calc(100svh - 220px), calc(100vh - 220px), 560px);
    overflow: hidden;
    padding: 6px 4px 8px;
    box-sizing: border-box;
}

.mahjong-board {
    /* Чуть компактнее под 9:16 */
    --mj-tw: clamp(58px, 16.5vmin, 96px);
    --mj-th: clamp(76px, 21.5vmin, 124px);
    --mj-layer-dx: 8px;
    --mj-layer-dy: -10px;
    position: relative;
    margin: 0 auto;
    flex-shrink: 0;
    touch-action: manipulation;
}

@media (max-width: 420px) {
    .mahjong-board {
        --mj-tw: clamp(52px, 15.2vmin, 86px);
        --mj-th: clamp(70px, 19.8vmin, 112px);
        --mj-layer-dx: 7px;
        --mj-layer-dy: -9px;
    }
}

@media (max-width: 360px) {
    .mahjong-board {
        --mj-tw: clamp(48px, 14.2vmin, 80px);
        --mj-th: clamp(64px, 18.4vmin, 104px);
        --mj-layer-dx: 6px;
        --mj-layer-dy: -8px;
    }
}

.mahjong-tile {
    position: absolute;
    left: 0;
    top: 0;
    width: var(--mj-tw);
    height: var(--mj-th);
    margin: 0;
    border-radius: clamp(10px, 2vmin, 16px);
    border: 3px solid rgba(255, 255, 255, 0.55);
    box-shadow:
        0 3px 0 rgba(15, 23, 42, 0.55),
        0 6px 14px rgba(0, 0, 0, 0.35);
    background-color: transparent;
    background-size: cover;
    background-position: center;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
    transition: transform 0.12s ease, opacity 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
    transform: translate(
        calc(var(--mj-lx, 0px) + var(--layer, 0) * var(--mj-layer-dx)),
        calc(var(--mj-ly, 0px) + var(--layer, 0) * var(--mj-layer-dy))
    );
    z-index: var(--mj-z, 1);
}

.mahjong-tile:focus-visible {
    outline: 2px solid #fde047;
    outline-offset: 2px;
}

.mahjong-tile--blocked {
    opacity: 0.45;
    cursor: default;
    pointer-events: none;
}

.mahjong-tile:not(.mahjong-tile--blocked):not(.mahjong-tile--vanishing):hover {
    transform: translate(
            calc(var(--mj-lx, 0px) + var(--layer, 0) * var(--mj-layer-dx)),
            calc(var(--mj-ly, 0px) + var(--layer, 0) * var(--mj-layer-dy) - 2px)
        )
        scale(1.02);
    box-shadow:
        0 4px 0 rgba(15, 23, 42, 0.45),
        0 10px 18px rgba(0, 0, 0, 0.38);
}

.mahjong-tile--selected {
    border-color: #fde047;
    box-shadow:
        0 0 0 2px rgba(253, 224, 71, 0.85),
        0 4px 18px rgba(251, 191, 36, 0.55);
    transform: translate(
            calc(var(--mj-lx, 0px) + var(--layer, 0) * var(--mj-layer-dx)),
            calc(var(--mj-ly, 0px) + var(--layer, 0) * var(--mj-layer-dy) - 4px)
        )
        scale(1.03);
}

.mahjong-tile--removed {
    visibility: hidden;
    pointer-events: none;
}

.mahjong-tile--vanishing {
    pointer-events: none;
    z-index: 9000 !important;
    animation: mahjongTileVanish 0.42s cubic-bezier(0.33, 1, 0.68, 1) forwards;
}

@keyframes mahjongHintBlink {
    0% {
        filter: brightness(1) saturate(1);
        box-shadow:
            0 3px 0 rgba(15, 23, 42, 0.55),
            0 6px 14px rgba(0, 0, 0, 0.35);
        transform: translate(
            calc(var(--mj-lx, 0px) + var(--layer, 0) * var(--mj-layer-dx)),
            calc(var(--mj-ly, 0px) + var(--layer, 0) * var(--mj-layer-dy))
        );
    }
    50% {
        filter: brightness(1.28) saturate(1.25);
        box-shadow:
            0 0 0 3px rgba(253, 224, 71, 0.6),
            0 14px 28px rgba(251, 191, 36, 0.28);
        transform: translate(
                calc(var(--mj-lx, 0px) + var(--layer, 0) * var(--mj-layer-dx)),
                calc(var(--mj-ly, 0px) + var(--layer, 0) * var(--mj-layer-dy) - 2px)
            )
            scale(1.02);
    }
    100% {
        filter: brightness(1) saturate(1);
        box-shadow:
            0 3px 0 rgba(15, 23, 42, 0.55),
            0 6px 14px rgba(0, 0, 0, 0.35);
        transform: translate(
            calc(var(--mj-lx, 0px) + var(--layer, 0) * var(--mj-layer-dx)),
            calc(var(--mj-ly, 0px) + var(--layer, 0) * var(--mj-layer-dy))
        );
    }
}

.mahjong-tile--hint {
    animation: mahjongHintBlink 1.1s ease-in-out infinite;
    z-index: 9200 !important;
}

@keyframes mahjongTileVanish {
    0% {
        opacity: 1;
        filter: brightness(1);
    }
    35% {
        filter: brightness(1.25) saturate(1.2);
        box-shadow:
            0 0 0 3px rgba(253, 224, 71, 0.65),
            0 12px 28px rgba(251, 191, 36, 0.45);
    }
    100% {
        opacity: 0;
        filter: brightness(1.4) blur(2px);
        transform: translate(
                calc(var(--mj-lx, 0px) + var(--layer, 0) * var(--mj-layer-dx)),
                calc(var(--mj-ly, 0px) + var(--layer, 0) * var(--mj-layer-dy))
            )
            scale(0.12)
            rotate(10deg);
    }
}

/* ПК-версия: чаты по центру 720px, по краям — градиент как на сцене 1 */
@media (min-width: 721px) {
    #scene-game,
    #scene-shop,
    #scene-stories,
    #scene-settings {
        background: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
        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: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
        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: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
}

.dialogs-bottom {
    flex-shrink: 0;
    padding: 15px;
    padding-top: 0;
    padding-bottom: max(15px, env(safe-area-inset-bottom, 0px));
    background: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
}

.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: var(--chat-avatar-border-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: #ec4899;
    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(236, 72, 153, 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%;
    display: flex;
    flex-direction: column;
    background: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    position: relative;
}

.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: #be185d;
    cursor: pointer;
    padding: 5px 10px;
    margin-right: 10px;
}

.chat-title {
    font-size: 18px;
    font-weight: bold;
    color: #333;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    padding-bottom: 100px; /* место под лентой, чтобы кнопки ответов не перекрывались сообщениями */
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
    background-image: var(--chat-bg-image, none);
    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: var(--chat-avatar-border-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: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 5px rgba(34, 211, 238, 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(34, 211, 238, 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: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    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: #be185d;
    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: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    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: #be185d;
}

.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: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    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: 24px;
    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);
}

/* Окно по завершении уровня (endless маджонг) */
.level-win-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;
}

.level-win-content {
    background: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    border-radius: 24px;
    max-width: 360px;
    width: 100%;
    padding: 24px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.level-win-title {
    font-size: 20px;
    font-weight: 800;
    color: white;
    text-align: center;
    margin: 0 0 10px;
}

.level-win-text {
    font-size: 15px;
    color: rgba(255, 255, 255, 0.95);
    text-align: center;
    margin: 0 0 10px;
}

.level-win-reward {
    font-size: 22px;
    font-weight: 900;
    color: #fbbf24;
    text-align: center;
    margin: 0 0 18px;
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.3);
}

.level-win-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.level-win-btn {
    padding: 14px 20px;
    font-size: 16px;
    font-weight: 800;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    background: white;
    color: #be185d;
    transition: transform 0.15s ease;
}

.level-win-btn:active {
    transform: scale(0.98);
}

.level-win-btn--ghost {
    background: rgba(255, 255, 255, 0.22);
    color: rgba(255, 255, 255, 0.95);
    border: 2px solid rgba(255, 255, 255, 0.38);
}

.crystal-fly {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 4000;
    pointer-events: none;
    font-size: 18px;
    filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.25));
    will-change: transform, opacity;
}

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

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

/* Окно покупки товара в магазине */
.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, #06b6d4 0%, #0891b2 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: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    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: #be185d;
}

.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: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: 0 4px 20px rgba(34, 211, 238, 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: #be185d;
    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: #be185d;
    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: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    padding: 16px 20px 24px;
    margin-bottom: 16px;
    text-align: center;
    box-shadow: 0 -2px 10px rgba(34, 211, 238, 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: var(--bg-gradient);
    background-clip: padding-box;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 999px;
    cursor: pointer;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    box-shadow: 0 3px 14px rgba(34, 211, 238, 0.35), 0 2px 8px rgba(236, 72, 153, 0.25);
    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;
}

/* Кнопки выбора ответа в цвет стиля (золотой / лесной / красный) */
#game-root[data-chat-style] .response-button {
    background: var(--chat-style-btn-bg);
    background-clip: padding-box;
    color: var(--chat-style-btn-text);
    border: 2px solid var(--chat-style-accent);
    box-shadow: 0 3px 10px rgba(0,0,0,0.25);
}
#game-root[data-chat-style] .response-button:active {
    filter: brightness(0.9);
}

/* Обводки под стили чата (золотой / лесной / красный) */
#game-root[data-chat-style] .chat-end-home-btn {
    border-color: var(--chat-style-accent);
    box-shadow: 0 2px 10px rgba(0,0,0,0.15), 0 0 0 2px var(--chat-style-accent);
}
#game-root[data-chat-style] .message-reaction-btn {
    border: 2px solid var(--chat-style-accent);
    box-shadow: 0 0 0 1px var(--chat-style-accent);
}
#game-root[data-chat-style] .message-avatar-frame,
#game-root[data-chat-style] .message-avatar-frame .message-avatar {
    border-color: var(--chat-style-accent) !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15), 0 0 0 2px var(--chat-style-accent);
}
#game-root[data-chat-style] .dialog-icon-wrapper .dialog-icon {
    border-color: var(--chat-style-accent);
    box-shadow: 0 0 0 2px var(--chat-style-accent);
}
#game-root[data-chat-style] .dialog-icon-frame {
    box-shadow: 0 0 0 2px var(--chat-style-accent);
    z-index: 0;
}

/* Фон главной выбора чатов (список диалогов) под выбранный стиль */
#game-root[data-chat-style] #scene-game,
#game-root[data-chat-style] .game-container,
#game-root[data-chat-style] .dialogs-list {
    background-image: var(--chat-bg-image);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}
#game-root[data-chat-style] .dialogs-list {
    background-attachment: scroll;
}
@media (min-width: 721px) {
    #game-root[data-chat-style] #scene-game .game-container {
        background-image: var(--chat-bg-image);
        background-size: cover;
        background-position: center;
        background-repeat: no-repeat;
    }
}

.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;
}

/* Когда открыт конкретный чат — убираем отступ под навигацию */
#scene-game.in-chat {
    padding-bottom: 0;
}

/* Нижняя панель навигации */
.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: rgba(255, 255, 255, 0.96);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 8px 4px;
    border-radius: 20px;
    box-shadow: 0 4px 24px rgba(236, 72, 153, 0.15), 0 2px 12px rgba(34, 211, 238, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.9);
    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(--bg-gradient);
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(34, 211, 238, 0.35), 0 2px 10px rgba(236, 72, 153, 0.25);
}

.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: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    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(34, 211, 238, 0.2) 0%, rgba(190, 24, 93, 0.2) 100%);
    border: 1px solid rgba(34, 211, 238, 0.4);
}

.shop-crystals .crystals-count {
    color: #be185d;
}

.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-style.owned {
    opacity: 1;
}

.shop-style-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}
.shop-style-toggle .shop-style-toggle-label {
    font-size: 12px;
    color: #666;
}
.shop-style-toggle input { display: none; }
.shop-style-toggle .toggle-slider {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    background: #ccc;
    border-radius: 24px;
    transition: background 0.2s;
}
.shop-style-toggle .toggle-slider::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    left: 2px;
    top: 2px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    transition: transform 0.2s;
}
.shop-style-toggle input:checked + .toggle-slider {
    background: #be185d;
}
.shop-style-toggle input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

.shop-item-icon-wrap {
    width: 64px;
    height: 64px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(34, 211, 238, 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: #be185d;
    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: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    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: #be185d;
    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(34, 211, 238, 0.5);
    background: linear-gradient(135deg, rgba(34, 211, 238, 0.05) 0%, rgba(190, 24, 93, 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-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;
}

/* --- Leaderboard (replaces rewards) --- */
.leaderboard-panel {
    width: min(520px, 100%);
    margin: 0 auto;
    box-sizing: border-box;
}

.leaderboard-meta {
    margin: 8px 0 10px;
    padding: 10px 12px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.28);
    color: rgba(255, 255, 255, 0.95);
    font-weight: 800;
    text-align: center;
    backdrop-filter: blur(10px);
}

.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.lb-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.12);
}

.lb-rank {
    width: 42px;
    text-align: center;
    font-weight: 900;
    color: #0f172a;
    flex-shrink: 0;
}

.lb-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, 0.1);
    background: rgba(0, 0, 0, 0.06);
}

.lb-name {
    flex: 1;
    min-width: 0;
    font-weight: 900;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lb-score {
    font-weight: 900;
    color: #be185d;
    flex-shrink: 0;
}

.lb-row--me {
    border: 2px solid rgba(253, 224, 71, 0.8);
    box-shadow: 0 0 0 3px rgba(253, 224, 71, 0.18), 0 10px 22px rgba(0, 0, 0, 0.12);
}

.leaderboard-empty {
    margin-top: 12px;
    padding: 12px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.28);
    color: rgba(255, 255, 255, 0.95);
    font-weight: 800;
    text-align: center;
    backdrop-filter: blur(10px);
}

.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(34, 211, 238, 0.2) 0%, rgba(236, 72, 153, 0.18) 100%);
    border-color: #ec4899;
    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: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    border: none;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(34, 211, 238, 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(34, 211, 238, 0.45);
}

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

/* Сцена настройки */
#scene-settings {
    background: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    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: #be185d;
    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: #be185d;
}

.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: linear-gradient(145deg, #22d3ee 0%, #818cf8 32%, #c084fc 68%, #f472b6 100%);
    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: #be185d;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.2s;
}

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