:root {
    --ink: #1B1712;
    --ink-soft: #2A241C;
    --page: #F2E9D8;
    --page-line: #DED2B8;
    --text-main: #2C2416;
    --text-muted: #8A7E68;
    --danger: #B0472B;
    --danger-bg: #F3DCD2;
    --calm: #5C6E4E;
    --calm-bg: #E4E9DC;
    --gold: #C9A227;
    --gold-bg: #3A2E12;
    --radius-page: 22px;
    --radius-ctrl: 10px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: #1C1712; /* Темный фон окружения на десктопе для контраста с книгой */
    font-family: 'Inter', sans-serif;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 0;
}

/* ---- Десктопный контейнер книги ---- */
.book-frame {
    width: 100%;
    max-width: 100%;
    background: transparent;
    border-radius: 0;
    padding: 0;
    margin: 0 auto;
    box-shadow: none;
}

.page {
    background: var(--page);
    border-radius: 0;
    overflow: visible;
    padding-left: 0;
    min-height: 100vh;
    position: relative;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 0.5px solid var(--page-line);
}

.page-header button {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 6px;
    line-height: 1;
}

.page-header .book-title {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-main);
    text-transform: none;
}

.world-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 16px 24px 0;
    padding: 10px 14px;
    background: var(--danger-bg);
    border-radius: var(--radius-ctrl);
}

.world-banner .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
    flex-shrink: 0;
}

.world-banner .text {
    flex: 1;
    font-size: 12px;
    color: var(--danger);
}

.world-banner .percent {
    font-size: 15px;
    font-weight: 700;
    color: var(--danger);
}

.scene {
    position: relative;
    overflow: hidden;
    clip-path: none;
    background: var(--page-line);
    max-height: 480px; /* Ограничиваем высоту картинки на десктопе, чтобы не растягивало */
}

.scene::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg,
            var(--page-line) 25%,
            #e8ddc4 50%,
            var(--page-line) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.scene.loaded::before {
    opacity: 0;
    pointer-events: none;
}

.sound-toggle {
    width: 22px;
    height: 22px;
    min-width: 22px;
    padding: 0;
    border: 1px solid var(--page-line);
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    font-size: 10px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sound-toggle:active {
    transform: scale(0.9);
}

.scene::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 4px;
    background: repeating-linear-gradient(to right,
            var(--gold) 0px, var(--gold) 8px,
            transparent 8px, transparent 16px);
}

.scene img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    object-position: center;
    position: relative;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.scene img.loaded {
    opacity: 1;
}

.scene svg {
    display: block;
    width: 100%;
    height: 100%;
}

.chapter-badge {
    display: inline-block;
    margin: -20px 24px 0;
    position: relative;
    background: var(--gold-bg);
    color: var(--gold);
    font-size: 11px;
    font-weight: 600;
    padding: 5px 13px;
    border-radius: 20px;
    z-index: 2;
}

.narrative {
    padding: 20px 24px 6px;
    font-family: 'Fraunces', serif;
    font-size: 18px;
    line-height: 1.85;
    color: var(--text-main);
}

.narrative p {
    margin: 0 0 16px;
}

.narrative p:last-child {
    margin-bottom: 0;
}

.narrative.mood-calm p:first-of-type::first-letter {
    color: var(--calm);
}

.sound-tag {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 4px 24px 16px;
    font-size: 11px;
    font-style: italic;
    color: var(--text-muted);
}

.sound-tag .ico {
    font-size: 13px;
}

.divider {
    height: 1px;
    background: var(--page-line);
    margin: 0 24px;
}

.choices {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 20px 24px 12px;
}

.choice-btn {
    text-align: left;
    padding: 15px 18px;
    background: transparent;
    border: 1px solid #C9BC9E;
    border-radius: var(--radius-ctrl);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    color: var(--text-main);
    cursor: pointer;
    transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
}

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

.choice-btn:hover {
    background: rgba(0, 0, 0, 0.04);
    border-color: var(--text-muted);
}

.choice-btn.item-choice {
    background: var(--danger);
    border-color: var(--danger);
    color: #FAECE7;
}

.choice-btn.item-choice:hover {
    background: #99401f;
}

.choice-btn.choice-locked {
    opacity: 0.5;
    cursor: not-allowed;
    border-style: dashed;
}

.continue-btn {
    width: calc(100% - 48px);
    margin: 18px 24px 24px;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--ink);
    border: none;
    border-radius: var(--radius-ctrl);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 600;
    color: var(--page);
    cursor: pointer;
    transition: background 0.2s;
}

.continue-btn:hover {
    background: #332B22;
}

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

.footer-nav {
    display: flex;
    border-top: 1px solid var(--page-line);
    padding: 8px 0 6px;
    margin-top: 12px;
    background: rgba(242, 233, 216, 0.95);
}

.footer-nav .nav-item {
    flex: 1;
    text-align: center;
    padding: 6px 0;
    cursor: pointer;
    transition: opacity 0.2s;
}

.footer-nav .nav-item:hover {
    opacity: 0.7;
}

.footer-nav .nav-item .ico {
    font-size: 18px;
    color: var(--text-muted);
}

.footer-nav .nav-item .lbl {
    display: block;
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 3px;
}

.panel {
    padding: 20px 24px 24px;
    border-top: 1px solid var(--page-line);
    background: rgba(0, 0, 0, 0.01);
}

.panel h3 {
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
    margin: 0 0 12px;
}

.stat-row {
    margin-bottom: 12px;
}

.stat-row .stat-label {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.stat-track {
    height: 6px;
    background: var(--page-line);
    border-radius: 4px;
    overflow: hidden;
}

.stat-fill {
    height: 100%;
    background: var(--danger);
    border-radius: 4px;
}

.inventory-list {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.inventory-item {
    font-size: 12px;
    padding: 6px 12px;
    background: var(--page-line);
    border-radius: 20px;
    color: var(--text-main);
}

/* -------------------------------------------------------------- */
/* Универсальные модалки (Bottom sheet на мобилках, центр на ПК)   */
/* -------------------------------------------------------------- */

.item-toast, .stat-modal, .story-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 999;
    pointer-events: none;
    transition: background 0.3s ease;
}

.item-toast.visible, .stat-modal.visible, .story-modal.visible {
    background: rgba(0, 0, 0, 0.5);
    pointer-events: auto;
}

.item-toast-sheet, .stat-modal-sheet, .story-modal-sheet {
    position: relative;
    width: 100%;
    max-width: 480px;
    background: var(--page);
    border-radius: 20px 20px 0 0;
    padding: 28px 24px calc(24px + env(safe-area-inset-bottom));
    text-align: center;
    transform: translateY(100%);
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.25);
}

.item-toast.visible .item-toast-sheet,
.stat-modal.visible .stat-modal-sheet,
.story-modal.visible .story-modal-sheet {
    transform: translateY(0);
}

.item-toast-close, .story-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    background: var(--page-line);
    border: none;
    border-radius: 50%;
    font-size: 18px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
}

.item-toast-icon {
    width: 88px;
    height: 88px;
    margin: 4px auto 18px;
    border-radius: 14px;
    overflow: hidden;
    background: var(--page-line);
    border: 1px solid var(--page-line);
}

.item-toast-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.item-toast-label, .stat-modal-label, .story-modal-label {
    font-size: 11px;
    letter-spacing: 0.08em;
    color: var(--gold);
    text-transform: uppercase;
    margin: 0 0 6px;
    font-weight: 700;
}

.item-toast-name, .stat-modal-name {
    font-family: 'Fraunces', serif;
    font-size: 22px;
    font-weight: 600;
    color: var(--text-main);
    margin: 0 0 22px;
}

.item-toast-desc {
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-muted);
    margin: -14px 0 22px;
}

.item-toast-ok, .stat-modal-ok, .story-modal-ok {
    width: 100%;
    padding: 15px;
    background: var(--ink);
    border: none;
    border-radius: 12px;
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 600;
    color: var(--page);
    cursor: pointer;
    transition: background 0.2s;
}

.item-toast-ok:hover, .stat-modal-ok:hover, .story-modal-ok:hover {
    background: #332B22;
}

.item-toast-ok:active, .stat-modal-ok:active, .story-modal-ok:active {
    transform: scale(0.98);
}

.stat-modal-track {
    height: 12px;
    background: var(--page-line);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 10px;
}

.stat-modal-fill {
    height: 100%;
    border-radius: 8px;
    width: 0%;
    background: var(--danger);
    transition: width 1.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.stat-modal-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    margin: 0 0 22px;
}

.story-modal-icon {
    font-size: 32px;
    color: var(--gold);
    margin-bottom: 10px;
    animation: story-modal-pulse 1.1s ease-in-out infinite;
}

.story-modal-text {
    font-family: 'Fraunces', serif;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-main);
    margin: 0 0 22px;
}

#minigameWrap {
    min-height: calc(100vh - 120px);
}

#minigameWrap iframe {
    height: 100% !important;
    min-height: calc(100vh - 120px);
}

.page-content {
    animation: page-turn-in 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.page-content.leaving {
    animation: page-turn-out 0.2s ease forwards;
}

@keyframes page-turn-in {
    from {
        opacity: 0;
        transform: translateX(24px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes page-turn-out {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(-24px);
    }
}

@keyframes skeleton-shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

@keyframes story-modal-pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
}

/* -------------------------------------------------------------- */
/* МЕДИА-ЗАПРОСЫ ДЛЯ ДЕСКТОПА (Планшеты и ПК от 768px и выше)     */
/* -------------------------------------------------------------- */
@media (min-width: 768px) {
    body {
        padding: 30px 0;
        background-color: #16120E;
        background-image: radial-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 0);
        background-size: 24px 24px;
    }

    .book-frame {
        max-width: 620px; /* Идеальная ширина для чтения книги на ПК */
        border-radius: 16px;
        box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
        overflow: hidden;
    }

    .page {
        min-height: auto;
        border-radius: 16px;
    }

    /* На ПК модальные окна элегантно центрируются */
    .item-toast, .stat-modal, .story-modal {
        align-items: center;
    }

    .item-toast-sheet, .stat-modal-sheet, .story-modal-sheet {
        border-radius: 20px;
        max-width: 440px;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
        transform: scale(0.95);
        opacity: 0;
        transition: all 0.25s cubic-bezier(0.32, 0.72, 0, 1);
    }

    .item-toast.visible .item-toast-sheet,
    .stat-modal.visible .stat-modal-sheet,
    .story-modal.visible .story-modal-sheet {
        transform: scale(1);
        opacity: 1;
    }
}

.header-back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: transparent;
    border: 1px solid var(--page-line);
    border-radius: 50%;
    color: var(--text-main);
    text-decoration: none;
    font-size: 15px;
    transition: all 0.15s ease;
}

.header-back-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    border-color: var(--text-muted);
}

.d-flex {
    display: flex !important;
}

.header-actions-group {
    display: flex;
    align-items: center;
    gap: 8px;
}