/* Готические шрифты */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --scale-factor: 1;
    --mobile-scale: 1.2;
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
}

body {
    background: linear-gradient(135deg, #0c0c0c 0%, #1a1a1a 50%, #2d2d2d 100%);
    color: #e0e0e0;
    /* Улучшенная система шрифтов с резервными вариантами */
    font-family: 'MedievalSharp', 'Georgia', 'Times New Roman', serif;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow: hidden;
    font-size: 16px;
    line-height: 1.5;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Улучшенные шрифты для читабельности - убрали сложный курсив */
.main-title, .gothic-title, .clan-title, .scroll-content h2 {
    font-family: 'MedievalSharp', 'Georgia', 'Times New Roman', serif;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    /* Улучшенное сглаживание для мобильных */
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Основной текст - улучшенная читаемость */
body, .start-btn, .play-btn, .gothic-btn, .confirm-btn {
    font-family: 'MedievalSharp', 'Georgia', 'Times New Roman', serif;
    line-height: 1.6;
    font-weight: normal;
    /* Улучшенное отображение текста */
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

/* Экранная система */
.screen {
    position: fixed;
    top: var(--safe-area-inset-top);
    left: var(--safe-area-inset-left);
    width: calc(100% - var(--safe-area-inset-left) - var(--safe-area-inset-right));
    height: calc(100% - var(--safe-area-inset-top) - var(--safe-area-inset-bottom));
    display: none;
    align-items: center;
    justify-content: center;
    padding: 10px;
    overflow: auto;
}

.screen.active {
    display: flex;
}

/* Начальный экран */
.start-container {
    text-align: center;
    background: rgba(0, 0, 0, 0.9);
    padding: 20px 15px;
    border: 3px solid #8B0000;
    border-radius: 15px;
    box-shadow: 0 0 30px rgba(139, 0, 0, 0.7);
    position: relative;
    max-width: min(95vw, 500px);
    width: 100%;
    margin: auto;
}

.main-title {
    color: #8B0000;
    font-size: clamp(1.8rem, 8vw, 3rem);
    margin-bottom: 12px;
    text-shadow: 2px 2px 4px #000;
    line-height: 1.2;
    word-wrap: break-word;
}

.subtitle {
    color: #c0c0c0;
    font-size: clamp(1rem, 4vw, 1.3rem);
    margin-bottom: 20px;
    font-style: italic;
    line-height: 1.4;
}

.start-btn {
    background: linear-gradient(135deg, #8B0000, #660000);
    color: white;
    border: 2px solid #FF0000;
    padding: 16px 30px;
    font-size: clamp(1rem, 4vw, 1.3rem);
    border-radius: 10px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.3s ease;
    text-shadow: 1px 1px 2px #000;
    font-family: 'MedievalSharp', cursive;
    margin-bottom: 20px;
    width: 100%;
    max-width: 280px;
}

.start-btn:hover {
    background: linear-gradient(135deg, #A52A2A, #8B0000);
    transform: scale(1.05);
    box-shadow: 0 0 25px rgba(255, 0, 0, 0.6);
}

/* Свечи в строку */
.candles-start {
    position: relative;
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.candles-start .candle {
    font-size: clamp(1.5rem, 6vw, 2rem);
    text-shadow: 0 0 10px #8B0000, 0 0 20px #FF0000;
    animation: flicker 3s infinite alternate;
}

/* Летучие мыши - начальный экран */
.bats-start {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    padding: 0 10px;
    pointer-events: none;
    transform: translateY(-50%);
}

.bats-start .bat {
    font-size: 1.5rem;
    animation: batFly 4s infinite ease-in-out;
}

@keyframes batFly {
    0%, 100% { 
        transform: translateY(0px) rotate(0deg); 
        opacity: 0.7;
    }
    25% { 
        transform: translateY(-15px) rotate(-10deg); 
        opacity: 1;
    }
    50% { 
        transform: translateY(8px) rotate(10deg); 
        opacity: 0.8;
    }
    75% { 
        transform: translateY(-12px) rotate(-5deg); 
        opacity: 0.9;
    }
}

@keyframes flicker {
    0%, 100% { opacity: 0.8; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.1); }
}

/* Управление музыкой */
.music-controls {
    margin-top: 15px;
}

.music-btn {
    background: rgba(139, 0, 0, 0.3);
    color: #c0c0c0;
    border: 1px solid #8B0000;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    font-family: 'MedievalSharp', cursive;
    width: 100%;
    max-width: 220px;
}

.music-btn:hover {
    background: rgba(139, 0, 0, 0.5);
    border-color: #FF0000;
}

.music-credit {
    color: #8B0000;
    font-size: 0.85rem;
    margin-top: 8px;
    font-style: italic;
}

/* Экран выбора клана */
.clan-container {
    text-align: center;
    background: rgba(0, 0, 0, 0.9);
    padding: 20px 15px;
    border: 3px solid #8B0000;
    border-radius: 15px;
    box-shadow: 0 0 30px rgba(139, 0, 0, 0.7);
    max-width: min(95vw, 600px);
    width: 100%;
    margin: auto;
}

.clan-title {
    color: #8B0000;
    font-size: clamp(1.5rem, 6vw, 2.2rem);
    margin-bottom: 12px;
    text-shadow: 2px 2px 4px #000;
    line-height: 1.2;
}

.clan-subtitle {
    color: #c0c0c0;
    font-size: clamp(0.9rem, 3vw, 1.1rem);
    margin-bottom: 20px;
    font-style: italic;
    line-height: 1.4;
}

.clans-selection {
    display: flex;
    gap: 12px;
    margin: 20px 0;
    justify-content: center;
    flex-wrap: wrap;
}

.clan-option {
    background: rgba(139, 0, 0, 0.2);
    border: 2px solid #8B0000;
    border-radius: 12px;
    padding: 15px 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex: 1;
    min-width: min(280px, 85vw);
    max-width: 350px;
    font-size: 0.9rem;
}

.clan-option:hover {
    background: rgba(139, 0, 0, 0.4);
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(255, 0, 0, 0.3);
}

.clan-option.selected {
    background: rgba(139, 0, 0, 0.6);
    border-color: #FF0000;
    box-shadow: 0 0 20px rgba(255, 0, 0, 0.5);
}

.clan-symbol {
    font-size: clamp(2.5rem, 8vw, 3rem);
    margin-bottom: 12px;
}

.clan-option h3 {
    color: #8B0000;
    font-size: clamp(1.1rem, 4vw, 1.5rem);
    margin-bottom: 10px;
    font-family: 'MedievalSharp', 'Georgia', 'Times New Roman', serif;
    font-weight: bold;
    line-height: 1.2;
}

.clan-option p {
    color: #c0c0c0;
    margin-bottom: 12px;
    line-height: 1.4;
    font-size: 0.9rem;
    font-weight: normal;
}

.clan-stats {
    display: flex;
    flex-direction: column;
    gap: 5px;
    color: #a0a0a0;
    font-size: 0.85rem;
    font-weight: normal;
}

.confirm-btn {
    background: linear-gradient(135deg, #8B0000, #660000);
    color: white;
    border: 2px solid #8B0000;
    padding: 14px 25px;
    font-size: clamp(0.9rem, 3vw, 1.1rem);
    border-radius: 8px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.3s ease;
    text-shadow: 1px 1px 2px #000;
    margin-top: 12px;
    width: 100%;
    max-width: 260px;
}

.confirm-btn:enabled {
    border-color: #FF0000;
    background: linear-gradient(135deg, #A52A2A, #8B0000);
    box-shadow: 0 0 12px rgba(255, 0, 0, 0.4);
}

.confirm-btn:enabled:hover {
    transform: scale(1.03);
    box-shadow: 0 0 15px rgba(255, 0, 0, 0.6);
}

/* Свиток с правилами */
.scroll-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    max-width: min(95vw, 700px);
    margin: auto;
}

.ancient-scroll {
    background: #f5e6c8;
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" opacity="0.1"><path d="M0,0 L100,0 L100,100 L0,100 Z" fill="none" stroke="%238B0000" stroke-width="2"/></svg>');
    border: 8px solid #8B4513;
    border-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50"><path d="M0,0 L50,0 L50,50 L0,50 Z" fill="%23592c0f" stroke="%233d1f0a" stroke-width="2"/></svg>') 30 round;
    padding: 20px 15px;
    max-width: 95vw;
    max-height: 75vh;
    overflow-y: auto;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
    position: relative;
    animation: scrollUnfold 1.5s ease-out;
}

@keyframes scrollUnfold {
    0% { transform: scale(0.8) rotate(-5deg); opacity: 0; }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.scroll-content {
    color: #3d1f0a;
    text-align: center;
    font-family: 'MedievalSharp', 'Georgia', 'Times New Roman', serif;
    font-size: 1rem;
    line-height: 1.5;
    font-weight: normal;
}

.scroll-content h2 {
    color: #8B0000;
    font-size: clamp(1.3rem, 5vw, 1.8rem);
    margin-bottom: 15px;
    border-bottom: 2px solid #8B0000;
    padding-bottom: 6px;
    font-family: 'MedievalSharp', 'Georgia', 'Times New Roman', serif;
    font-weight: bold;
}

.rule-section {
    margin: 15px 0;
    padding: 12px;
    background: rgba(139, 0, 0, 0.1);
    border-radius: 6px;
    border-left: 3px solid #8B0000;
    font-size: 0.95rem;
    text-align: left;
    font-weight: normal;
}

.rule-section h3 {
    color: #8B0000;
    margin-bottom: 8px;
    font-size: clamp(1rem, 3vw, 1.3rem);
    font-family: 'MedievalSharp', 'Georgia', 'Times New Roman', serif;
    font-weight: bold;
}

.rule-section ul {
    margin-left: 12px;
}

.rule-section li {
    margin-bottom: 6px;
    line-height: 1.4;
    font-weight: normal;
}

.highlight {
    color: #8B0000;
    font-weight: bold;
    font-size: 1rem;
}

.warning-text {
    color: #8B0000;
    font-weight: bold;
    font-style: italic;
    font-size: 1rem;
}

.player-clan {
    margin-top: 12px;
    padding: 10px;
    background: rgba(139, 0, 0, 0.2);
    border-radius: 6px;
    border: 2px solid #8B0000;
    font-size: 1rem;
}

.play-btn {
    background: linear-gradient(135deg, #8B0000, #660000);
    color: white;
    border: 2px solid #FF0000;
    padding: 14px 25px;
    font-size: clamp(0.9rem, 3vw, 1.1rem);
    border-radius: 8px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.3s ease;
    text-shadow: 1px 1px 2px #000;
    width: 100%;
    max-width: 260px;
}

.play-btn:hover {
    background: linear-gradient(135deg, #A52A2A, #8B0000);
    transform: scale(1.03);
    box-shadow: 0 0 12px rgba(255, 0, 0, 0.5);
}

/* Игровые стили */
.gothic-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100%;
    position: relative;
    padding: 10px;
    width: 100%;
}

/* Летучие мыши в игре */
.bats-left, .bats-right {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 30px;
    pointer-events: none;
    z-index: 1;
}

.bats-left {
    left: 10px;
}

.bats-right {
    right: 10px;
}

.bats-left .bat, .bats-right .bat {
    font-size: 1.2rem;
    animation: batFloat 3s infinite ease-in-out;
}

@keyframes batFloat {
    0%, 100% { 
        transform: translateY(0px) rotate(0deg); 
        opacity: 0.6;
    }
    50% { 
        transform: translateY(-10px) rotate(5deg); 
        opacity: 1;
    }
}

.game-area {
    background: rgba(0, 0, 0, 0.8);
    border: 2px solid #8B0000;
    border-radius: 12px;
    padding: 15px 12px;
    text-align: center;
    box-shadow: 0 0 15px rgba(139, 0, 0, 0.5);
    max-width: min(95vw, 400px);
    width: 100%;
    margin: 0 auto;
    position: relative;
    z-index: 2;
}

.gothic-title {
    color: #8B0000;
    font-size: clamp(1.3rem, 5vw, 1.8rem);
    margin-bottom: 12px;
    text-shadow: 1px 1px 3px #000;
    font-weight: bold;
    letter-spacing: 1px;
    line-height: 1.2;
}

.game-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 12px;
    font-size: 0.9rem;
}

.stat {
    background: rgba(139, 0, 0, 0.2);
    padding: 8px;
    border-radius: 6px;
    border: 1px solid #8B0000;
}

.stat-label {
    display: block;
    font-size: 0.85rem;
    color: #c0c0c0;
    margin-bottom: 2px;
    font-weight: normal;
}

.stat-value {
    display: block;
    font-size: 1rem;
    color: #ffffff;
    font-weight: bold;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 4px;
    margin: 12px auto;
    max-width: min(85vw, 250px);
    background: rgba(139, 0, 0, 0.1);
    padding: 6px;
    border-radius: 8px;
}

.cell {
    background: #1a1a1a;
    border: 2px solid #8B0000;
    border-radius: 4px;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.5rem, 8vw, 2rem);
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    min-height: 50px;
}

.cell:hover {
    background: #2a2a2a;
    border-color: #FF0000;
    transform: scale(1.03);
    box-shadow: 0 0 8px rgba(255, 0, 0, 0.3);
}

.cell.revealed {
    background: rgba(139, 0, 0, 0.3);
    cursor: default;
    transform: scale(1);
}

.cell.revealed:hover {
    transform: scale(1);
    box-shadow: none;
}

.cell.death {
    background: rgba(255, 0, 0, 0.5);
    animation: pulse 0.5s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.message-area {
    margin: 12px 0;
    padding: 10px;
    background: rgba(139, 0, 0, 0.2);
    border-radius: 6px;
    border-left: 3px solid #8B0000;
    font-style: normal; /* Убрали курсив для лучшей читаемости */
    min-height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    line-height: 1.3;
    font-weight: normal;
}

.controls {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 12px;
    flex-wrap: wrap;
}

.gothic-btn {
    background: linear-gradient(135deg, #8B0000, #660000);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    text-shadow: 1px 1px 2px #000;
    font-family: 'MedievalSharp', 'Georgia', 'Times New Roman', serif;
    flex: 1;
    min-width: 120px;
    max-width: 180px;
}

.gothic-btn:hover {
    background: linear-gradient(135deg, #A52A2A, #8B0000);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(139, 0, 0, 0.4);
}

.music-btn-small {
    background: rgba(139, 0, 0, 0.3);
    color: #c0c0c0;
    border: 1px solid #8B0000;
    padding: 10px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    min-width: 50px;
}

.music-btn-small:hover {
    background: rgba(139, 0, 0, 0.5);
    border-color: #FF0000;
}

/* Экран результата */
.result-container {
    background: rgba(0, 0, 0, 0.95);
    padding: 20px 15px;
    border: 3px solid #8B0000;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 0 20px rgba(139, 0, 0, 0.8);
    max-width: min(95vw, 500px);
    width: 100%;
    margin: auto;
}

.result-title {
    font-family: 'MedievalSharp', 'Georgia', 'Times New Roman', serif;
    font-size: clamp(1.5rem, 6vw, 2.2rem);
    margin-bottom: 15px;
    font-weight: bold;
    line-height: 1.2;
}

.result-message {
    font-size: clamp(1rem, 3vw, 1.1rem);
    margin-bottom: 15px;
    line-height: 1.4;
}

/* Адаптивность для мобильных */
@media (max-width: 768px) {
    body {
        font-size: 15px;
        line-height: 1.5;
        overflow: auto;
    }
    
    .screen {
        padding: 8px;
        align-items: flex-start;
    }
    
    .bats-left, .bats-right, .bats-start {
        display: none;
    }
    
    .start-container,
    .clan-container,
    .game-area {
        padding: 15px 12px;
        margin: 5px auto;
    }
    
    .clans-selection {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }
    
    .clan-option {
        min-width: 100%;
        max-width: 100%;
        padding: 12px 10px;
    }
    
    .game-stats {
        grid-template-columns: 1fr;
        gap: 6px;
    }
    
    .controls {
        flex-direction: column;
        align-items: center;
        gap: 6px;
    }
    
    .gothic-btn {
        width: 100%;
        max-width: 220px;
    }
    
    .game-board {
        max-width: 90vw;
        gap: 3px;
    }
    
    .cell {
        font-size: clamp(1.8rem, 10vw, 2.2rem);
        min-height: 45px;
    }
    
    .ancient-scroll {
        max-height: 70vh;
        padding: 15px 12px;
    }
}

@media (max-width: 480px) {
    body {
        font-size: 14px;
    }
    
    .screen {
        padding: 5px;
    }
    
    .start-container,
    .clan-container,
    .game-area {
        padding: 12px 10px;
        border-width: 2px;
    }
    
    .main-title {
        font-size: clamp(1.5rem, 9vw, 2rem);
        margin-bottom: 8px;
    }
    
    .clan-title {
        font-size: clamp(1.3rem, 7vw, 1.7rem);
    }
    
    .gothic-title {
        font-size: clamp(1.2rem, 6vw, 1.5rem);
    }
    
    .candles-start {
        gap: 10px;
        margin-bottom: 15px;
    }
    
    .candles-start .candle {
        font-size: 1.3rem;
    }
    
    .game-board {
        max-width: 95vw;
    }
    
    .cell {
        min-height: 40px;
        border-width: 1px;
    }
    
    .stat {
        padding: 6px;
    }
    
    .scroll-content {
        font-size: 0.95rem;
        line-height: 1.5;
    }
    
    .rule-section {
        font-size: 0.9rem;
        padding: 10px;
    }
    
    .message-area {
        font-size: 0.95rem;
        line-height: 1.4;
    }
}

/* Ландшафтные мобильные устройства */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
    .screen {
        padding: 3px;
        align-items: flex-start;
    }
    
    .start-container,
    .clan-container {
        margin-top: 3px;
        max-height: 94vh;
        overflow-y: auto;
        padding: 10px 8px;
    }
    
    .game-area {
        padding: 8px;
        max-width: 98vw;
        margin-top: 2px;
    }
    
    .game-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 4px;
        margin-bottom: 8px;
    }
    
    .game-board {
        max-width: 60vw;
        margin: 8px auto;
    }
    
    .cell {
        min-height: 35px;
        font-size: 1.5rem;
    }
    
    .message-area {
        margin: 8px 0;
        min-height: 35px;
        font-size: 0.9rem;
    }
    
    body {
        font-size: 14px;
    }
    
    .stat-label {
        font-size: 0.8rem;
    }
    
    .stat-value {
        font-size: 0.9rem;
    }
}

/* Очень маленькие экраны */
@media (max-height: 600px) {
    .screen {
        align-items: flex-start;
        padding-top: 5px;
        overflow-y: auto;
    }
    
    .start-container,
    .clan-container,
    .game-area {
        margin-top: 5px;
        margin-bottom: 5px;
    }
    
    .main-title,
    .clan-title,
    .gothic-title {
        margin-bottom: 8px;
    }
    
    .subtitle,
    .clan-subtitle {
        margin-bottom: 12px;
    }
}

/* Поддержка safe-area для iPhone X и новее */
@supports(padding: max(0px)) {
    .screen {
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
        padding-top: max(10px, env(safe-area-inset-top));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
}

/* Улучшение для очень узких экранов */
@media (max-width: 360px) {
    body {
        font-size: 13px;
    }
    
    .start-container,
    .clan-container,
    .game-area {
        padding: 10px 8px;
        border-radius: 10px;
    }
    
    .game-board {
        max-width: 98vw;
    }
    
    .cell {
        min-height: 35px;
        font-size: 1.5rem;
    }
    
    .gothic-btn {
        min-width: 100px;
        padding: 8px 12px;
        font-size: 0.85rem;
    }
}

/* Предотвращение масштабирования при фокусе на iOS */
@media (max-width: 768px) {
    input, select, textarea, button {
        font-size: 16px;
    }
}