/* Подключаем шрифт локально */
@font-face {
    font-family: 'Old Standard';
    src: url('../fonts/OldStandard-Regular.ttf') format('truetype'); 
    font-weight: normal;
    font-style: normal;
}

/* --- СТИЛЬ В ДУХЕ ЭПОХИ ДОСТОЕВСКОГО И 18 ВЕКА --- */
:root {
    --color-bg: #2c1a10; 
    --color-card-bg: #fdfcf5; 
    --color-text: #1a1a1a;
    --color-accent: #8e7355; 
    --color-accent-hover: #a68a68;
    --color-back-base: #561111; 
    --bg-card-back: var(--color-back-base) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cg fill='%23bf9b30' fill-opacity='0.15'%3E%3Cpath d='M40 0C26.19 0 15 11.19 15 25c0 11.79 8.16 21.66 19 24.34V80h2v-30.66C46.84 46.66 55 36.79 55 25 55 11.19 43.81 0 40 0zm0 2C52.7 2 63 12.3 63 25c0 10.74-7.44 19.73-17.41 22.18L40 54.34l-5.59-7.16C24.44 44.73 17 35.74 17 25c0-12.7 10.3-23 23-23zM22.21 68.21a5 5 0 1 1-7.07-7.07 5 5 0 0 1 7.07 7.07zM64.86 68.21a5 5 0 1 0-7.07-7.07 5 5 0 0 0 7.07 7.07z'/%3E%3C/g%3E%3C/svg%3E");
    
    --font-main: 'Georgia', serif;
    --font-ui: 'Old Standard', 'Times New Roman', serif;
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--color-bg);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23noise)' opacity='0.05'/%3E%3C/svg%3E");
    font-family: var(--font-main);
    color: #e0d0b0; 
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent; 
    touch-action: none; 
}

.game-wrapper {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 2vh 3vw;
    box-sizing: border-box;
}

.header {
    text-align: center;
    margin-bottom: 1.5vh;
    flex-shrink: 0;
}

h1 {
    font-family: var(--font-ui); 
    font-size: clamp(2.5rem, 5vw, 6rem); 
    margin: 0;
    color: var(--color-accent); 
    font-weight: normal;
    letter-spacing: 1px;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

.subtitle {
    font-family: var(--font-ui); 
    font-size: clamp(1.1rem, 2.2vw, 3rem); 
    color: #b0a080;
    font-style: italic;
    font-weight: 400;
    margin-top: 0.5vh;
}

.timer-display {
    text-align: center;
    font-family: var(--font-ui);
    font-size: clamp(1.3rem, 2vh, 3rem);
    color: var(--color-accent);
    height: auto;
    margin-bottom: 1vh;
    visibility: hidden; 
}

.timer-display.active {
    visibility: visible;
}

.timer-display span {
    font-weight: bold;
    font-size: clamp(1.6rem, 2.5vh, 4rem); 
}

/* --- ИГРОВОЕ ПОЛЕ --- */
.game-board {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
    gap: 1.5vw; 
    flex-grow: 1;
    min-height: 0;
    padding-bottom: 2vh;
}

.card {
    perspective: 1000px;
    cursor: pointer;
    width: 100%;
    height: 100%;
    touch-action: manipulation; 
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
    border-radius: 12px; 
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.4);
    will-change: transform;
    transform: rotateY(0deg);
}

.card.flipped .card-inner,
.card.matched .card-inner {
    transform: rotateY(180deg);
}

.card-front,
.card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    border-radius: 12px;
    overflow: hidden;
    box-sizing: border-box;
}

/* РУБАШКА КАРТЫ */
.card-back {
    background: var(--bg-card-back);
    border: 4px solid #3a0a0a; 
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.6);
    z-index: 2; 
}

.card-back::after {
    content: '';
    position: absolute;
    width: 85%;
    height: 85%;
    border: 2px solid rgba(191, 155, 48, 0.3); 
    border-radius: 6px;
}

/* ЛИЦЕВАЯ СТОРОНА КАРТЫ */
.card-front {
    background-color: var(--color-card-bg);
    transform: rotateY(180deg); 
    display: flex;
    flex-direction: column;
    border: 3px solid #d0c0a0;
    color: var(--color-text);
    z-index: 1;
}

.card-front.quote-card {
    align-items: center;
    justify-content: center;
    padding: 2vw; 
    text-align: center;
}

.card-front p {
    font-size: clamp(1.2rem, 2.8vh, 3rem); 
    line-height: 1.3;
    margin: 0;
    padding: 0 15px;
    font-style: italic;
    color: #2c3e50;
    font-family: var(--font-main);
}

.card-front.quote-card.long-quote p {
    font-size: clamp(1rem, 2.3vh, 2.5rem); 
}

.card-front.image-card {
    justify-content: space-between;
    background-color: var(--color-card-bg);
}

.card-front img {
    width: 100%;
    height: 75%;
    object-fit: cover;
    object-position: center 20%;
    border-bottom: 2px solid #d0c0a0;
    filter: sepia(0.3) contrast(0.9);
}

.card-front span {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 25%;
    font-size: clamp(1.1rem, 2.2vh, 3rem); 
    font-family: var(--font-ui);
    text-align: center;
    padding: 0 10px; 
    width: 100%; 
    box-sizing: border-box;
}

.card.matched .card-front {
    background-color: #f0fdf4; 
    border-color: #4ade80; 
    box-shadow: 0 0 20px rgba(191, 155, 48, 0.6), inset 0 0 15px rgba(74, 222, 128, 0.2);
}

/* --- КНОПКИ И УПРАВЛЕНИЕ В ИГРЕ --- */
.controls {
    text-align: center;
    margin-top: 1.5vh;
    flex-shrink: 0;
    height: auto;
}

.btn {
    font-family: var(--font-ui); 
    background-color: var(--color-accent);
    color: #2c1a10; 
    border: 2px solid #6f5940;
    padding: 2vh 4vw; 
    font-size: clamp(1.3rem, 2.5vh, 3rem); 
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.3s;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.4);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: bold;
}

.btn:hover {
    background-color: var(--color-accent-hover);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.5);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

/* --- МОДАЛЬНЫЕ ОКНА (ФИНАЛ) --- */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85); 
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: var(--color-card-bg);
    color: var(--color-text);
    padding: 5vh 4vw;
    text-align: center;
    border-radius: 12px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.6);
    max-width: 60vw; 
    width: 90%;
    border: 4px solid var(--color-accent);
}

.modal-content h2 {
    font-family: var(--font-ui);
    margin-top: 0;
    font-size: clamp(2.5rem, 5vh, 6rem); 
    color: #8e1111; 
}

.modal-content p {
    font-size: clamp(1.5rem, 3vh, 3.5rem); 
    margin-bottom: 30px;
    font-style: italic;
}

/* --- СТИЛИ ДЛЯ ВСТУПЛЕНИЯ (INTRO) --- */
.intro-wrapper {
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 3vh 3vw;
    box-sizing: border-box;
    position: fixed;
    top: 0;
    left: 0;
    background-color: var(--color-bg);
    z-index: 500;
    overflow: hidden; 
}

.intro-content {
    background: var(--color-card-bg);
    color: var(--color-text);
    padding: 4vh 2vw; 
    border-radius: 12px;
    border: 4px solid var(--color-accent);
    
    width: 96vw;
    max-width: 96vw; 
    height: 82vh; 
    
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.6);
    text-align: center;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: space-between; 
    overflow: hidden;
}

.intro-content *, 
.intro-content *::before, 
.intro-content *::after {
    box-sizing: border-box;
}

.intro-content h1 {
    color: #8e1111;
    margin: 0 0 1vh 0;
    font-size: clamp(2rem, 4.5vh, 5rem); 
    flex-shrink: 0;
}

/* Переключатели вкладок */
.intro-tabs {
    display: flex;
    justify-content: center;
    gap: clamp(20px, 4vw, 50px);
    margin: 0 0 2vh 0;
    border-bottom: 2px solid #d0c0a0;
    padding-bottom: 1vh;
    flex-shrink: 0;
}

.tab-btn {
    font-family: var(--font-ui);
    background: none;
    border: none;
    font-size: clamp(1.1rem, 2.3vh, 2.5rem); 
    color: #7f8c8d;
    cursor: pointer;
    padding: 0.8vh 2vw; 
    transition: all 0.3s;
}

.tab-btn.active, .tab-btn:hover {
    color: #8e1111;
    font-weight: bold;
}

/* Контейнер для содержимого вкладок */
.tab-content {
    display: none;
    text-align: left;
    flex-grow: 1;
    min-height: 0; 
    width: 100%;
}

.tab-content.active {
    display: flex;
    align-items: center; 
    justify-content: center;
}

/* Вкладка "Об авторе" */
.author-info {
    display: flex;
    gap: 4vw;
    align-items: center;
    width: 100%;
    height: 100%;
}

.author-portrait {
    height: 42vh; 
    width: auto;  
    max-height: 50vh; 
    border-radius: 6px;
    border: 3px solid var(--color-accent);
    box-shadow: 0 6px 15px rgba(0,0,0,0.3);
    flex-shrink: 0;
}

.author-text {
    font-size: clamp(1.1rem, 2.2vh, 2.2rem); 
    line-height: 1.55;
    color: var(--color-text);
}

.author-text p {
    margin: 0 0 1.5vh 0;
    text-indent: 30px;
}
.author-text p:last-child {
    margin-bottom: 0;
}

/* --- Вкладка "Персонажи" — 1 ряд с горизонтальным прокрутом --- */
.characters-grid {
    display: flex;
    flex-direction: row;
    justify-content: flex-start; 
    align-items: center;
    gap: 30px; 
    width: 100%;
    height: 100%;
    
    padding: 10px 40px; 
    box-sizing: border-box;
    
    overflow-x: auto;
    overflow-y: hidden;
    
    scroll-snap-type: x mandatory; 
    -webkit-overflow-scrolling: touch; 
    cursor: grab;
}

.characters-grid:active {
    cursor: grabbing;
}

.char-card {
    display: flex;
    flex-direction: column;
    width: 290px;
    min-width: 290px;
    max-width: 290px;
    height: 96%; 
    
    background-color: #ffffff; 
    border: 2px solid #d0c0a0;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    flex-shrink: 0; 
    scroll-snap-align: center; 
}

.char-card img {
    width: 100%;
    height: 46%; 
    object-fit: cover;
    object-position: center 20%;
    display: block;
    flex-shrink: 0;
}

.char-card h3 {
    margin: 0;
    font-family: var(--font-ui);
    font-size: clamp(1.1rem, 2.2vh, 2.2rem); 
    font-weight: bold;
    text-align: center;
    padding: 1vh 10px;
    background-color: #fcfbfa;
    color: #1a1a1a;
    border-top: 1px solid #d0c0a0;
    border-bottom: 1px solid #eadecc;
    height: 14%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.char-card p {
    margin: 0;
    padding: 1.5vh 15px; 
    font-size: clamp(0.9rem, 1.8vh, 1.8rem); 
    line-height: 1.4;
    color: #2c3e50; 
    background: #ffffff;
    text-align: center;
    height: 40%;
    display: flex;
    align-items: center;
    justify-content: center;
    
    overflow-y: auto; 
    scrollbar-width: none;  
    -ms-overflow-style: none;  
}

.char-card p::-webkit-scrollbar {
    display: none; 
    width: 0px;
    height: 0px;
    background: transparent;
}

.characters-grid::-webkit-scrollbar {
    display: none; 
}
.characters-grid {
    -ms-overflow-style: none;  
    scrollbar-width: none;  
}

.intro-content .btn {
    align-self: center;
    padding: 1.8vh 4vw; 
    font-size: clamp(1.1rem, 2.3vh, 2.5rem);
    min-width: clamp(250px, 15vw, 400px); 
    flex-shrink: 0;
    margin-top: 1.5vh;
}

@media (max-width: 800px) {
    .author-info {
        flex-direction: column;
        text-align: center;
        gap: 2vh;
    }
    .author-portrait {
        height: 28vh;
    }
    .char-card {
        width: 32vw;
        min-width: 230px;
    }
   .intro-content {
        width: 90vw;
        max-width: 100vw; 
        height: 78vh; 
    }
}

.novels-list {
    margin-top: 3vh;
    padding: 2vh 2vw;
    background: rgba(142, 115, 85, 0.08); 
    border-left: 4px solid var(--color-accent);
    border-radius: 4px;
}

.novels-list strong {
    font-family: var(--font-ui);
    font-size: clamp(1.2rem, 2.5vh, 2.5rem);
    color: #8e1111;
    display: block;
    margin-bottom: 1.5vh;
    letter-spacing: 0.5px;
}

.novels-list ul {
    margin: 0;
    padding-left: 2.5vw;
    list-style-type: square;
}

.novels-list li {
    margin-bottom: 1vh;
    font-size: clamp(1rem, 2vh, 2rem);
    color: #2c3e50;
    font-style: italic;
}

.intro-content {
    position: relative;
    padding: 5vh 4vw 4vh 4vw !important;
}

.vintage-divider {
    width: 200px;
    height: 20px;
    margin: 1vh auto 2vh auto;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 20' fill='%238e7355'%3E%3Cpath d='M50 2c-5 0-9 4-10 6-1-2-5-6-10-6S21 6 20 8c-1-2-5-6-10-6H0v2h10c3 0 7 3 8 6-1 3-5 6-8 6H0v2h10c5 0 9-4 10-6 1 2 5 6 10 6s9-4 10-6c1 2 5 6 10 6s9-4 10-6c1 2 5 6 10 6s9-4 10-6c1 2 5 6 10 6h10v-2H90c-3 0-7-3-8-6 1-3 5-6 8-6h10V2H90c-5 0-9 4-10 6-1-2-5-6-10-6S61 6 60 8c-1-2-5-6-10-6z'/%3E%3Ccircle cx='50' cy='10' r='3'/%3E%3C/svg%3E") no-repeat center;
    background-size: contain;
    opacity: 0.7;
}

.corner-decor {
    position: absolute;
    width: 40px;
    height: 40px;
    border: 3px solid transparent;
    opacity: 0.4;
    pointer-events: none;
}
.corner-decor.top-left { top: 15px; left: 15px; border-top-color: var(--color-accent); border-left-color: var(--color-accent); }
.corner-decor.top-right { top: 15px; right: 15px; border-top-color: var(--color-accent); border-right-color: var(--color-accent); }
.corner-decor.bottom-left { bottom: 15px; left: 15px; border-bottom-color: var(--color-accent); border-left-color: var(--color-accent); }
.corner-decor.bottom-right { bottom: 15px; right: 15px; border-bottom-color: var(--color-accent); border-right-color: var(--color-accent); }

.novels-list {
    margin-top: 2.5vh;
    padding: 1.5vh 2vw;
    background: rgba(142, 115, 85, 0.06); 
    border-left: 3px solid var(--color-accent);
    border-right: 3px solid rgba(142, 115, 85, 0.2);
    border-radius: 4px;
    text-align: left;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.03);
}

.novels-list strong {
    font-family: var(--font-ui);
    font-size: clamp(1.1rem, 2.2vh, 2.2rem);
    color: #8e1111; 
    display: block;
    margin-bottom: 1vh;
    letter-spacing: 0.5px;
}

.novels-list ul {
    margin: 0;
    padding-left: 20px;
    list-style-type: square;
    display: grid;
    grid-template-columns: repeat(2, 1fr); 
    gap: 0.5vh 2vw;
}

.novels-list li {
    font-size: clamp(0.95rem, 1.8vh, 1.8rem);
    color: #2c3e50;
    font-style: italic;
}

.author-portrait {
    height: 48vh !important;
    max-height: 520px;
}

.intro-content + .novels-list {
    display: none;
}

/* --- НОВЫЕ ПРАВИЛА: Перераспределение высоты для карточек во вступлении --- */
.char-card h3 {
    flex-direction: column;
    line-height: 1.1;
    height: 18%; 
    padding: 0.5vh 5px;
}

.char-card img {
    height: 42%; 
}

/* Стили для названия книги во вступлении */
.char-book {
    font-size: 0.65em;
    font-weight: normal;
    color: #8e1111;
    font-style: italic;
    font-family: var(--font-main);
    margin-top: 4px;
}

/* Стили для названия книги на самой игровой карточке */
.card-front span {
    flex-direction: column;
    line-height: 1.1;
}

.card-book-title {
    font-size: 0.55em;
    color: #8e1111;
    font-style: italic;
    font-family: var(--font-main);
    margin-top: 2px;
}