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

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

/* П. 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;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

.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: white;
    text-align: center;
    flex-shrink: 0;
}

.stories-shelf {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 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 {
    font-size: clamp(12px, 3.5vw, 16px);
    font-weight: bold;
    color: white;
    text-align: center;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
    margin-bottom: 8px;
}

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

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

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

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

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

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

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

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

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

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

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


/* Сцена переодевания */
#scene-dressing {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 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(135deg, #667eea 0%, #764ba2 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(245, 87, 108, 1);
    box-shadow: 0 0 12px rgba(245, 87, 108, 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(245, 87, 108, 1);
    box-shadow: 0 0 12px rgba(245, 87, 108, 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;
}

.dressing-costume-price-badge--discount {
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
    padding: 3px 6px 2px;
}
.dressing-costume-price-new {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    line-height: 1.1;
}
.dressing-costume-price-old {
    font-size: 9px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.75);
    text-decoration: line-through;
    line-height: 1.1;
}

.costume-purchase-price .costume-price-new {
    display: block;
    font-size: 18px;
    font-weight: 800;
    color: white;
    margin-bottom: 4px;
}
.costume-purchase-price .costume-price-old {
    display: block;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.75);
    text-decoration: line-through;
}

/* Модалка покупки костюма */
.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(135deg, #667eea 0%, #764ba2 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, #f59e0b 0%, #d97706 100%);
    color: white;
}

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

.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(135deg, #667eea 0%, #764ba2 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(135deg, #667eea 0%, #764ba2 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: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border: none;
    border-radius: 25px;
    cursor: pointer;
    box-shadow: 0 5px 20px rgba(245, 87, 108, 0.4);
    transition: transform 0.2s;
}

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

/* Сцена игры */
#scene-game {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding-bottom: 0;
}

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

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

.dialogs-bottom {
    flex-shrink: 0;
    padding: 15px;
    padding-top: 0;
    padding-bottom: max(15px, env(safe-area-inset-bottom, 0px));
    background: linear-gradient(135deg, #667eea 0%, #764ba2 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: #f5576c;
    color: white;
    border-radius: 50%;
    min-width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    padding: 0 5px;
    box-shadow: 0 2px 5px rgba(245, 87, 108, 0.5);
    border: 2px solid white;
}

.dialog-info {
    flex: 1;
}

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

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

/* Окно чата */
.chat-window {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 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: #667eea;
    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, url('assets/back_chat.webp'));
    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(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 5px rgba(102, 126, 234, 0.3);
    text-align: left;
}

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

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

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

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

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

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

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

.pre-story-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 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: #667eea;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.2s;
}

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

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

.reset-progress-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 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: #667eea;
}

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

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

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

.chat-completion-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 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);
}

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

.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, #10b981 0%, #059669 100%);
    border-radius: 24px;
    max-width: 400px;
    width: 100%;
    padding: 24px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

.purchase-story-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 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: #667eea;
}

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

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

/* Ежедневные награды (7 дней) */
.daily-rewards-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: 2500;
    padding: 20px;
}

.daily-rewards-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 24px;
    max-width: 420px;
    width: 100%;
    padding: 28px 24px;
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.daily-rewards-title {
    font-size: 24px;
    font-weight: bold;
    color: white;
    text-align: center;
    margin-bottom: 6px;
}

.daily-rewards-subtitle {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.9);
    text-align: center;
    margin-bottom: 24px;
}

.daily-sale-banner {
    margin: -8px 0 18px;
    padding: 12px 14px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.45);
    background: linear-gradient(135deg, rgba(245, 87, 108, 0.85) 0%, rgba(240, 147, 251, 0.75) 100%);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
    text-align: center;
}

.daily-sale-title {
    font-size: 16px;
    font-weight: 900;
    color: white;
    letter-spacing: 0.02em;
    margin-bottom: 2px;
}

.daily-sale-text {
    font-size: 13px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.95);
}

.daily-rewards-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.daily-reward-item {
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 8px;
    text-align: center;
    border: 2px solid rgba(255, 255, 255, 0.4);
}

.daily-reward-item.claimed {
    background: rgba(255, 255, 255, 0.4);
    border-color: rgba(255, 255, 255, 0.7);
}

.daily-reward-item.current {
    background: linear-gradient(135deg, rgba(240, 147, 251, 0.8) 0%, rgba(245, 87, 108, 0.8) 100%);
    border-color: white;
    box-shadow: 0 4px 16px rgba(245, 87, 108, 0.5);
}

.daily-reward-day {
    font-size: 13px;
    font-weight: bold;
    color: white;
    margin-bottom: 4px;
    overflow-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
}

.daily-reward-gift {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.95);
    overflow-wrap: break-word;
    word-break: break-word;
}

.daily-rewards-btn {
    width: 100%;
    padding: 16px 24px;
    font-size: 18px;
    font-weight: bold;
    color: #667eea;
    background: white;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, box-shadow 0.2s;
}

.daily-rewards-btn:active {
    transform: scale(0.98);
}

.daily-rewards-btn:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

/* Плашка «Бейдж получен» */
.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(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
    max-width: 100%;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

.chat-end-panel {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 16px 20px 24px;
    margin-bottom: 16px;
    text-align: center;
    box-shadow: 0 -2px 10px rgba(102, 126, 234, 0.3);
    flex-shrink: 0;
}

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

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

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

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

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

/* Кнопки выбора ответа в цвет стиля (золотой / лесной / красный) */
#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: white;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 8px 4px;
    border-radius: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    box-sizing: border-box;
}

.nav-button.games-nav-pulse {
    animation: games-nav-pulse 1.4s ease-in-out infinite;
    box-shadow: 0 0 0 0 rgba(245, 87, 108, 0.55);
}
@keyframes games-nav-pulse {
    0% { box-shadow: 0 0 0 0 rgba(245, 87, 108, 0.55); }
    70% { box-shadow: 0 0 0 12px rgba(245, 87, 108, 0); }
    100% { box-shadow: 0 0 0 0 rgba(245, 87, 108, 0); }
}

.games-nav-hint {
    position: fixed;
    z-index: 1100;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    border: none;
    background: transparent;
    padding: 0;
    cursor: pointer;
    pointer-events: auto;
    transform: translateX(-50%);
    animation: games-hint-bob 1.2s ease-in-out infinite;
}
.games-nav-hint-label {
    background: rgba(30, 30, 45, 0.92);
    color: #fff;
    font-size: 13px;
    font-weight: 800;
    line-height: 1.25;
    padding: 8px 12px;
    border-radius: 12px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.25);
    white-space: nowrap;
    max-width: min(240px, 70vw);
}
.games-nav-hint-finger {
    font-size: 34px;
    line-height: 1;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
}
@keyframes games-hint-bob {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(8px); }
}

.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: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
}

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

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

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

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

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

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

/* Сцена магазин */
#scene-shop {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 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(102, 126, 234, 0.2) 0%, rgba(118, 75, 162, 0.2) 100%);
    border: 1px solid rgba(102, 126, 234, 0.4);
}

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

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

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

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

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

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

.shop-item-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: #667eea;
}
.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(102, 126, 234, 0.1);
    border-radius: 12px;
}

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

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

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

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

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

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

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

/* Сцена истории */
#scene-stories {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 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: #667eea;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/* Сцена настройки */
#scene-settings {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 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: #667eea;
    flex-shrink: 0;
}

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

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

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

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

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

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

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

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

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

.dialog-media-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 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: #667eea;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.2s;
}

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

/* ===== Мини-игры: каталог (одна карточка в ряд) ===== */
#minigames-shelf-grid {
    grid-template-columns: 1fr;
    gap: 14px;
}

.minigame-row-tile {
    display: flex;
    align-items: stretch;
    width: 100%;
    min-height: 132px;
    background: rgba(255, 255, 255, 0.96);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.minigame-row-tile:active {
    transform: scale(0.98);
}

.minigame-row-tile-completed {
    box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.85), 0 8px 24px rgba(0, 0, 0, 0.2);
}

.minigame-row-cover-wrap {
    flex: 0 0 38%;
    max-width: 160px;
    min-width: 110px;
    align-self: stretch;
    background: #e8e8f0;
    overflow: hidden;
}

.minigame-row-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.minigame-row-body {
    flex: 1;
    min-width: 0;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}

.minigame-row-title {
    margin: 0;
    font-size: 18px;
    font-weight: 800;
    color: #333;
    line-height: 1.2;
}

.minigame-row-desc {
    margin: 0;
    font-size: 13px;
    color: #666;
    line-height: 1.35;
}

.minigame-row-progress {
    margin: 2px 0 8px;
    font-size: 13px;
    font-weight: 700;
    color: #667eea;
}

.minigame-row-btn {
    align-self: flex-start;
    border: none;
    border-radius: 14px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 800;
    color: #fff;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    box-shadow: 0 4px 14px rgba(245, 87, 108, 0.35);
    pointer-events: none;
}

.minigame-row-tile-completed .minigame-row-btn {
    background: linear-gradient(135deg, #2dd4bf 0%, #14b8a6 100%);
    box-shadow: 0 4px 14px rgba(45, 212, 191, 0.4);
}

.minigame-row-tile-completed .minigame-row-btn::before {
    content: '✓ ';
}

#scene-minigames {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* ===== Собери слова ===== */
#scene-words {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
@media (min-width: 721px) {
    #scene-words {
        justify-content: center;
        align-items: stretch;
    }
    #scene-words .words-root {
        max-width: 720px;
        width: 100%;
        margin: 0 auto;
    }
}
.words-root {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    position: relative;
}
.words-header {
    background: #fff;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    z-index: 10;
    position: relative;
    padding-right: 76px;
}
.words-header .back-button {
    background: none;
    border: none;
    font-size: 18px;
    color: #667eea;
    cursor: pointer;
    padding: 5px 8px;
    flex: 0 0 auto;
}
.words-level-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1 1 auto;
}
.words-level-text {
    font-size: 15px;
    font-weight: 800;
    color: #333;
}
.words-progress-text {
    font-size: 12px;
    font-weight: 700;
    color: #667eea;
}
.words-header-actions {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
}
.words-crystals {
    position: static;
    top: auto;
    right: auto;
}
.words-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 12px 14px 16px;
    gap: 10px;
    overflow: hidden;
}
.words-chat {
    flex: 0 0 auto;
    padding: 4px 2px 2px;
}
.words-chat .message {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    max-width: 100%;
}
.words-chat .message-sender-name {
    color: #fff;
}
.words-chat .message-bubble {
    background: #fff;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    font-size: 15px;
}
.words-found-list {
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    flex: 0 0 auto;
}
.words-found-chip {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.06em;
    padding: 6px 10px;
    border-radius: 999px;
    box-shadow: 0 3px 10px rgba(245, 87, 108, 0.3);
}
.words-build-area {
    flex: 1 1 auto;
    min-height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.words-drop-slots {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-items: center;
    max-width: 100%;
    padding: 8px;
}
.words-drop-slots.shake {
    animation: words-shake 0.4s ease;
}
@keyframes words-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-6px); }
    80% { transform: translateX(6px); }
}
.words-drop-slot {
    width: 48px;
    height: 54px;
    border-radius: 12px;
    border: 2px dashed rgba(255,255,255,0.65);
    background: rgba(255,255,255,0.14);
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}
.words-drop-slot.filled {
    border-style: solid;
    border-color: rgba(255,255,255,0.85);
    background: rgba(255,255,255,0.22);
}
.words-tray,
#words-letters {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    padding: 8px 4px;
    min-height: 64px;
    touch-action: none;
}
.words-letter {
    width: 48px;
    height: 52px;
    border: none;
    border-radius: 14px;
    background: #fff;
    color: #333;
    font-size: 22px;
    font-weight: 900;
    cursor: grab;
    box-shadow: 0 6px 16px rgba(0,0,0,0.18);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
    box-sizing: border-box;
}
.words-letter--in-slot {
    width: 42px;
    height: 46px;
    font-size: 20px;
    box-shadow: 0 3px 10px rgba(0,0,0,0.18);
}
.words-letter.dragging-source {
    opacity: 0.25;
}
.words-letter--ghost {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    margin: 0;
    cursor: grabbing;
    box-shadow: 0 10px 24px rgba(0,0,0,0.28);
    transform: scale(1.06);
}
.words-drag-layer {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9998;
    pointer-events: none;
}
.words-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}
.words-action-btn {
    border: none;
    border-radius: 14px;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 800;
    color: #fff;
    background: rgba(255,255,255,0.22);
    border: 1px solid rgba(255,255,255,0.45);
    cursor: pointer;
}
.words-action-btn--clear {
    background: rgba(245, 87, 108, 0.35);
}
.words-action-btn--hint {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border-color: transparent;
    box-shadow: 0 4px 14px rgba(245, 87, 108, 0.35);
}
.words-action-btn--restore {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: transparent;
    box-shadow: 0 4px 14px rgba(102, 126, 234, 0.4);
    width: 100%;
    max-width: 320px;
}
.words-action-btn:disabled {
    opacity: 0.55;
    cursor: default;
}
.words-drop-slot.locked {
    border-style: solid;
    border-color: rgba(255, 215, 0, 0.95);
    background: rgba(255, 215, 0, 0.22);
}
.words-letter--locked {
    cursor: default;
    box-shadow: 0 0 0 2px rgba(255, 215, 0, 0.7), 0 3px 10px rgba(0,0,0,0.18);
}
.words-hint {
    margin: 0;
    text-align: center;
    font-size: 12px;
    color: rgba(255,255,255,0.85);
}
.words-toast {
    position: absolute;
    left: 50%;
    top: 36%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.7);
    color: #fff;
    padding: 10px 16px;
    border-radius: 12px;
    font-weight: 700;
    z-index: 20;
    pointer-events: none;
}
.words-win-modal {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 30;
    padding: 20px;
}
.words-win-content {
    width: min(360px, 100%);
    background: #fff;
    border-radius: 20px;
    padding: 24px 20px;
    text-align: center;
    box-shadow: 0 16px 40px rgba(0,0,0,0.3);
}
.words-win-title {
    font-size: 22px;
    font-weight: 900;
    color: #333;
    margin-bottom: 8px;
}
.words-win-earned {
    font-size: 28px;
    font-weight: 900;
    color: #667eea;
    margin-bottom: 18px;
}
.words-win-btn {
    width: 100%;
    border: none;
    border-radius: 14px;
    padding: 14px 16px;
    font-size: 16px;
    font-weight: 800;
    color: #fff;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(245, 87, 108, 0.35);
}

/* ===== Пазл ===== */
#scene-puzzle {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.puzzle-root {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    position: relative;
}
.puzzle-header {
    background: white;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    z-index: 10;
    position: relative;
    overflow: hidden;
    padding-right: 76px;
}
.puzzle-header .back-button {
    background: none;
    border: none;
    font-size: 18px;
    color: #667eea;
    cursor: pointer;
    padding: 5px 8px;
    margin-right: 6px;
    flex: 0 0 auto;
}
.puzzle-level-progress {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    flex: 1 1 auto;
    margin: 0 8px;
}
.puzzle-level-progress-top {
    display: flex;
    flex-direction: column;
    gap: 0;
    min-width: 0;
}
.puzzle-level-progress-text { display: none; }
.puzzle-level-progress-sub {
    font-size: clamp(12px, 3.4vw, 14px);
    font-weight: 800;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.puzzle-level-progress-bar,
.puzzle-level-progress-dots { display: none; }
.puzzle-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    min-width: 0;
    margin-left: auto;
    padding-right: 72px;
}
.puzzle-hint-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: #fff;
    font-size: clamp(11px, 3.2vw, 13px);
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 3px 12px rgba(245, 87, 108, 0.35);
    max-width: 100%;
}
.puzzle-hint-btn--header {
    padding: 7px 12px;
    max-width: min(42vw, 220px);
    min-width: 0;
    flex: 1 1 auto;
}
.puzzle-hint-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}
.puzzle-hint-btn:active { transform: scale(0.97); }
.puzzle-hint-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.puzzle-hint-btn.solving { opacity: 0.6; pointer-events: none; }
.puzzle-crystals {
    margin-left: 0;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(102, 126, 234, 0.1);
    border: 1px solid rgba(102, 126, 234, 0.25);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.puzzle-header .crystals-display {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    cursor: default;
}
.puzzle-hints-bar { display: none; }
.puzzle-board-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 12px max(16px, env(safe-area-inset-bottom, 0px));
}
.puzzle-board {
    width: min(92vw, 520px);
    aspect-ratio: 3 / 4;
    background: rgba(255,255,255,0.12);
    border-radius: 18px;
    border: 1px solid rgba(255,255,255,0.25);
    box-shadow: 0 10px 35px rgba(0,0,0,0.25);
    padding: 10px;
    display: grid;
    gap: 8px;
    touch-action: none;
    position: relative;
}
.puzzle-tutorial {
    position: absolute;
    inset: 0;
    z-index: 35;
    pointer-events: none;
}
.puzzle-tutorial-finger {
    position: fixed;
    left: 0;
    top: 0;
    transform: translate3d(var(--fx, 0px), var(--fy, 0px), 0) scale(1);
    font-size: clamp(28px, 6.8vw, 44px);
    filter: drop-shadow(0 10px 18px rgba(0,0,0,0.35));
    animation: tutorialMove 2600ms ease-in-out infinite;
}
@keyframes tutorialMove {
    0%   { transform: translate3d(var(--fx, 0px), var(--fy, 0px), 0) scale(1); opacity: 0.0; }
    10%  { opacity: 1; }
    55%  { transform: translate3d(var(--tx, 0px), var(--ty, 0px), 0) scale(0.98); opacity: 1; }
    70%  { opacity: 0.0; }
    100% { opacity: 0.0; }
}
.puzzle-tile {
    border-radius: 14px;
    background-color: rgba(255,255,255,0.22);
    border: 1px solid rgba(255,255,255,0.35);
    box-shadow: 0 2px 10px rgba(0,0,0,0.18);
    background-repeat: no-repeat;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    position: relative;
}
.puzzle-tile:active { cursor: grabbing; }
.puzzle-tile.dragging {
    cursor: grabbing;
    z-index: 30;
    box-shadow: 0 14px 35px rgba(0,0,0,0.35);
    filter: brightness(1.05);
}
.puzzle-tile.selected {
    outline: 3px solid rgba(255,255,255,0.9);
    box-shadow: 0 0 0 2px rgba(102,126,234,0.8), 0 10px 25px rgba(0,0,0,0.25);
}
@keyframes hintFlash {
    0%   { box-shadow: 0 0 0 0 rgba(255,214,0,0); filter: brightness(1); }
    20%  { box-shadow: 0 0 0 4px rgba(255,214,0,1); filter: brightness(1.35); }
    100% { box-shadow: 0 0 0 0 rgba(255,214,0,0); filter: brightness(1); }
}
.puzzle-tile.hint-flash {
    animation: hintFlash 1000ms ease-out forwards;
    z-index: 5;
    position: relative;
}
.puzzle-toast {
    position: absolute;
    left: 50%;
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(255,255,255,0.92);
    color: #5a3d8a;
    font-weight: 700;
    box-shadow: 0 10px 25px rgba(0,0,0,0.25);
    z-index: 20;
    max-width: calc(100% - 24px);
    text-align: center;
}
.puzzle-win-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
    padding: 16px;
    overflow: hidden;
}
.puzzle-win-content {
    width: 100%;
    max-width: 420px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 22px;
    padding: 22px 18px 18px;
    position: relative;
    overflow: hidden;
    max-height: calc(100dvh - 32px);
    box-shadow: 0 18px 55px rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255,255,255,0.25);
    display: flex;
    flex-direction: column;
}
.puzzle-win-image-wrap {
    width: 100%;
    aspect-ratio: 3 / 4;
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.22);
    height: min(56dvh, 520px);
}
.puzzle-win-image {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}
.puzzle-win-title {
    text-align: center;
    color: #fff;
    font-size: clamp(16px, 2.4vh, 22px);
    font-weight: 800;
    margin-top: 6px;
}
.puzzle-win-subtitle {
    text-align: center;
    color: rgba(255,255,255,0.9);
    font-size: 13px;
    font-weight: 700;
    margin-top: 6px;
}
.puzzle-win-earned {
    text-align: center;
    color: #ffd166;
    font-size: clamp(22px, 3.6vh, 34px);
    font-weight: 900;
    margin-top: 10px;
    text-shadow: 0 2px 10px rgba(0,0,0,0.35);
}
.puzzle-win-btn {
    width: 100%;
    margin-top: 16px;
    padding: clamp(10px, 1.8vh, 14px) 18px;
    border: none;
    border-radius: 16px;
    background: rgba(255,255,255,0.95);
    color: #5a3d8a;
    font-size: clamp(14px, 2.1vh, 18px);
    font-weight: 800;
    cursor: pointer;
}
.puzzle-win-btn:active { transform: scale(0.98); }
.puzzle-fireworks {
    position: absolute;
    inset: 0;
    pointer-events: none;
}
.puzzle-firework {
    position: absolute;
    left: 50%;
    top: 52%;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    animation: puzzleBurst 900ms ease-out forwards;
}
@keyframes puzzleBurst {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
    10% { opacity: 1; }
    100% {
        opacity: 0;
        transform: translate(calc(-50% + (var(--dx) * 260px)), calc(-50% + (var(--dy) * 260px))) rotate(var(--rot)) scale(0.9);
    }
}
.puzzle-crystal-fly {
    position: fixed;
    left: var(--sx);
    top: var(--sy);
    transform: translate(-50%, -50%);
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(255,255,255,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.25);
    z-index: 10050;
    pointer-events: none;
    animation: crystalFly 900ms cubic-bezier(0.2, 0.9, 0.2, 1) forwards;
}
@keyframes crystalFly {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
    10% { opacity: 1; }
    100% {
        opacity: 0;
        left: var(--tx);
        top: var(--ty);
        transform: translate(-50%, -50%) scale(0.25);
    }
}
@media (max-width: 720px) {
    .puzzle-header { padding: 8px; padding-right: 70px; gap: 6px; }
    .puzzle-header-actions { gap: 6px; padding-right: 66px; }
    .puzzle-hint-btn--header { padding: 6px 10px; max-width: min(36vw, 160px); }
    .puzzle-win-content { max-height: calc(var(--vh, 1vh) * 100 - 24px); padding: 16px 14px 14px; }
    .puzzle-win-image-wrap { aspect-ratio: auto; height: min(46vh, 360px); }
    .puzzle-win-image { object-fit: contain; background: rgba(0,0,0,0.08); }
}

/* ===== Каталог: обложка memory ===== */
.minigame-card-cover-wrap--memory {
    position: relative;
    background: linear-gradient(135deg, #2a1a4a 0%, #5a2d7a 100%);
}
.minigame-card-cover-wrap--memory .minigame-card-cover {
    object-fit: cover;
    object-position: top center;
    width: 58%;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
    clip-path: polygon(0 0, 100% 0, 78% 100%, 0 100%);
}
.minigame-card-cover-overlay {
    position: absolute;
    right: 0;
    top: 0;
    width: 58%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    clip-path: polygon(22% 0, 100% 0, 100% 100%, 0 100%);
}

/* ===== Memory ===== */
#scene-memory {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
@media (min-width: 721px) {
    #scene-memory {
        justify-content: center;
        align-items: stretch;
    }
    #scene-memory .memory-root {
        max-width: 720px;
        width: 100%;
        margin: 0 auto;
    }
}
.memory-root {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    position: relative;
}
.memory-header {
    background: #fff;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    z-index: 10;
    position: relative;
    padding-right: 76px;
}
.memory-header .back-button {
    background: none;
    border: none;
    font-size: 18px;
    color: #667eea;
    cursor: pointer;
    padding: 5px 8px;
    flex: 0 0 auto;
}
.memory-level-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1 1 auto;
}
.memory-level-text {
    font-size: clamp(13px, 3.4vw, 15px);
    font-weight: 800;
    color: #333;
}
.memory-pairs-text {
    font-size: 12px;
    font-weight: 700;
    color: #667eea;
}
.memory-header .crystals-display {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    cursor: default;
}
.memory-crystals {
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(102, 126, 234, 0.1);
    border: 1px solid rgba(102, 126, 234, 0.25);
}
.memory-board-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px 12px max(16px, env(safe-area-inset-bottom, 0px));
}
.memory-board {
    width: min(94vw, 480px);
    display: grid;
    gap: 10px;
    touch-action: manipulation;
}
.memory-card {
    aspect-ratio: 3 / 4;
    border: none;
    padding: 0;
    background: transparent;
    cursor: pointer;
    perspective: 800px;
    -webkit-tap-highlight-color: transparent;
}
.memory-card-inner {
    display: block;
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.35s ease;
    border-radius: 14px;
}
.memory-card.flipped .memory-card-inner,
.memory-card.matched .memory-card-inner {
    transform: rotateY(180deg);
}
.memory-card-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 14px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(0,0,0,0.22);
}
.memory-card-back {
    background: linear-gradient(145deg, #f093fb 0%, #667eea 55%, #764ba2 100%);
    color: #fff;
    font-size: clamp(22px, 6vw, 32px);
    border: 2px solid rgba(255,255,255,0.35);
}
.memory-card-front {
    transform: rotateY(180deg);
    background: #fff;
}
.memory-card-front img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    display: block;
}
.memory-card.matched {
    pointer-events: none;
}
.memory-card.matched .memory-card-front {
    box-shadow: 0 0 0 3px rgba(6, 214, 160, 0.85), 0 6px 18px rgba(0,0,0,0.2);
}
.memory-toast {
    position: absolute;
    left: 50%;
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(255,255,255,0.92);
    color: #5a3d8a;
    font-weight: 700;
    z-index: 20;
}
.memory-win-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
    padding: 16px;
}
.memory-win-content {
    width: 100%;
    max-width: 360px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 22px;
    padding: 28px 20px 20px;
    text-align: center;
    box-shadow: 0 18px 55px rgba(0,0,0,0.45);
    border: 1px solid rgba(255,255,255,0.25);
}
.memory-win-title {
    color: #fff;
    font-size: 20px;
    font-weight: 800;
    margin-bottom: 10px;
}
.memory-win-earned {
    color: #ffd166;
    font-size: 32px;
    font-weight: 900;
    margin-bottom: 18px;
    text-shadow: 0 2px 10px rgba(0,0,0,0.35);
}
.memory-win-btn {
    width: 100%;
    border: none;
    border-radius: 16px;
    padding: 14px;
    background: rgba(255,255,255,0.95);
    color: #5a3d8a;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
}
.memory-win-btn:active { transform: scale(0.98); }

/* ===== Rhythm Tap ===== */
.minigame-card-cover-wrap--rhythm {
    position: relative;
    background: linear-gradient(135deg, #1a1040 0%, #667eea 55%, #f093fb 100%);
}
.minigame-card-cover-wrap--rhythm .minigame-card-cover {
    object-fit: cover;
    object-position: top center;
    opacity: 0.92;
}
.minigame-card-rhythm-badge {
    position: absolute;
    right: 12px;
    bottom: 12px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255,255,255,0.92);
    color: #764ba2;
    font-size: 26px;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 18px rgba(0,0,0,0.25);
}

#scene-rhythm {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
@media (min-width: 721px) {
    #scene-rhythm { justify-content: center; align-items: stretch; }
    #scene-rhythm .rhythm-root {
        max-width: 720px;
        width: 100%;
        margin: 0 auto;
    }
}
.rhythm-root {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: linear-gradient(160deg, #1b1340 0%, #4a2d7a 45%, #667eea 100%);
    position: relative;
}
.rhythm-header {
    background: rgba(255,255,255,0.96);
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.12);
    position: relative;
    padding-right: 76px;
    z-index: 10;
}
.rhythm-header .back-button {
    background: none;
    border: none;
    font-size: 18px;
    color: #667eea;
    cursor: pointer;
    padding: 5px 8px;
}
.rhythm-level-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}
.rhythm-level-text {
    font-size: clamp(13px, 3.4vw, 15px);
    font-weight: 800;
    color: #333;
}
.rhythm-score-text {
    font-size: 12px;
    font-weight: 700;
    color: #667eea;
}
.rhythm-header .crystals-display {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    cursor: default;
}
.rhythm-crystals {
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(102, 126, 234, 0.1);
    border: 1px solid rgba(102, 126, 234, 0.25);
}
.rhythm-stage-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 10px max(12px, env(safe-area-inset-bottom, 0px));
    position: relative;
}
.rhythm-feedback {
    position: absolute;
    top: 8%;
    left: 50%;
    transform: translateX(-50%) scale(0.9);
    font-size: clamp(22px, 6vw, 34px);
    font-weight: 900;
    color: #fff;
    text-shadow: 0 4px 16px rgba(0,0,0,0.45);
    opacity: 0;
    pointer-events: none;
    z-index: 5;
    transition: opacity 0.15s, transform 0.15s;
}
.rhythm-feedback.show { opacity: 1; transform: translateX(-50%) scale(1); }
.rhythm-feedback.perfect { color: #ffd166; }
.rhythm-feedback.good { color: #7af0c8; }
.rhythm-feedback.miss { color: #ff6b8a; }

.rhythm-stage {
    width: min(96vw, 420px);
    height: min(72vh, 620px);
    display: flex;
    flex-direction: column;
    position: relative;
}
.rhythm-lanes {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    position: relative;
    padding-bottom: 8px;
}
.rhythm-lane {
    position: relative;
    border-radius: 16px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.16);
    overflow: hidden;
}
.rhythm-notes {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 18%;
    pointer-events: none;
}
.rhythm-note {
    position: absolute;
    left: 50%;
    top: 0;
    width: min(64px, 18vw);
    height: min(64px, 18vw);
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #fff 0%, #f093fb 35%, #667eea 100%);
    box-shadow: 0 6px 18px rgba(0,0,0,0.35), 0 0 0 3px rgba(255,255,255,0.25);
    transform: translate(-50%, -50%);
    will-change: top, opacity;
}
.rhythm-hit-line {
    position: absolute;
    left: 4px;
    right: 4px;
    bottom: calc(22% + 4px);
    height: 4px;
    border-radius: 999px;
    background: linear-gradient(90deg, transparent, #ffd166, #fff, #ffd166, transparent);
    box-shadow: 0 0 16px rgba(255, 209, 102, 0.7);
    z-index: 3;
    pointer-events: none;
}
.rhythm-pads {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    flex: 0 0 auto;
    padding-top: 8px;
}
.rhythm-pad {
    height: clamp(56px, 12vh, 72px);
    border: none;
    border-radius: 16px;
    background: rgba(255,255,255,0.92);
    color: #5a3d8a;
    font-size: 18px;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(0,0,0,0.22);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.08s, background 0.12s;
}
.rhythm-pad:active { transform: scale(0.96); }
.rhythm-pad.hit-perfect {
    background: #ffd166;
    animation: rhythmPadFlash 0.25s ease;
}
.rhythm-pad.hit-good {
    background: #7af0c8;
    animation: rhythmPadFlash 0.25s ease;
}
.rhythm-pad.hit-miss {
    background: #ffb3c1;
    animation: rhythmPadFlash 0.25s ease;
}
@keyframes rhythmPadFlash {
    0% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.rhythm-start-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 10, 40, 0.55);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 20;
    padding: 20px;
}
.rhythm-ready-btn {
    border: none;
    border-radius: 18px;
    padding: 16px 36px;
    font-size: 20px;
    font-weight: 900;
    color: #fff;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    box-shadow: 0 10px 28px rgba(245, 87, 108, 0.4);
    cursor: pointer;
}
.rhythm-ready-btn:active { transform: scale(0.97); }
.rhythm-hint {
    margin: 0;
    color: rgba(255,255,255,0.9);
    font-size: 14px;
    font-weight: 700;
    text-align: center;
}

.rhythm-win-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
    padding: 16px;
}
.rhythm-win-content {
    width: 100%;
    max-width: 380px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 22px;
    padding: 26px 18px 18px;
    text-align: center;
    box-shadow: 0 18px 55px rgba(0,0,0,0.45);
    border: 1px solid rgba(255,255,255,0.25);
}
.rhythm-win-title {
    color: #fff;
    font-size: 20px;
    font-weight: 800;
    margin-bottom: 10px;
}
.rhythm-win-stats {
    color: rgba(255,255,255,0.9);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.4;
    margin-bottom: 12px;
}
.rhythm-win-earned {
    color: #ffd166;
    font-size: 32px;
    font-weight: 900;
    margin-bottom: 16px;
    text-shadow: 0 2px 10px rgba(0,0,0,0.35);
}
.rhythm-win-btn {
    width: 100%;
    border: none;
    border-radius: 16px;
    padding: 14px;
    background: rgba(255,255,255,0.95);
    color: #5a3d8a;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
}
.rhythm-win-btn:active { transform: scale(0.98); }
