/* Сброс и базовые стили */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* Оптимизация производительности */
* {
    -webkit-backface-visibility: hidden;
    -webkit-perspective: 1000;
    -webkit-transform: translate3d(0,0,0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000;
    transform: translate3d(0,0,0);
    transform: translateZ(0);
}

:root {
    /* Темная мрачная палитра */
    --primary-color: #8B0000; /* Темно-красный */
    --secondary-color: #4B0000; /* Очень темно-красный */
    --accent-color: #DC143C; /* Малиновый */
    --gold-color: #B8860B; /* Темное золото */
    
    --bg-dark: #0a0a0a; /* Почти черный */
    --bg-medium: #141414; /* Очень темно-серый */
    --bg-light: #1a1a1a; /* Темно-серый */
    --bg-card: #1f1f1f; /* Карточки */
    
    --text-primary: #e0e0e0; /* Светло-серый */
    --text-secondary: #999999; /* Серый */
    --text-dark: #666666; /* Темно-серый */
    
    --border-color: #2a2a2a;
    --success-color: #2d5016;
    --danger-color: #8B0000;
    
    /* Компактные размеры для мобильных */
    --top-bar-height: 36px;
    --bottom-nav-height: 48px;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-size: 14px; /* Базовый размер меньше */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.3;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Верхняя панель - очень компактная */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--top-bar-height);
    background: linear-gradient(to bottom, var(--bg-medium), var(--bg-dark));
    border-bottom: 1px solid var(--primary-color);
    z-index: 100;
    display: flex;
    align-items: center;
    padding: 0 8px;
}

.player-info-bar {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 10px;
    font-size: 12px;
}

.player-level {
    background-color: var(--primary-color);
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
}

.player-name {
    flex: 1;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.player-gold {
    display: flex;
    align-items: center;
    gap: 2px;
    color: var(--gold-color);
    font-weight: 600;
}

/* Основной контент */
.main-content {
    position: fixed;
    top: var(--top-bar-height);
    left: 0;
    right: 0;
    bottom: var(--bottom-nav-height);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background-color: var(--bg-dark);
    scrollbar-width: none;
    -ms-overflow-style: none;
    overscroll-behavior: contain;
}

.main-content::-webkit-scrollbar {
    display: none;
}

/* Нижняя навигация - компактная */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: linear-gradient(to top, var(--bg-medium), var(--bg-dark));
    border-top: 1px solid var(--border-color);
    display: flex;
    z-index: 100;
}

.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-dark);
    padding: 4px;
    cursor: pointer;
    transition: color 0.2s;
    min-height: 44px;
    touch-action: manipulation;
}

.nav-btn.active {
    color: var(--accent-color);
}

.nav-icon {
    font-size: 18px;
    margin-bottom: 2px;
}

.nav-label {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
}

/* Компактные карточки */
.content-card {
    background-color: var(--bg-card);
    margin: 6px;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 12px 0;
}

/* Компактные действия */
.action-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.action-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background-color: var(--bg-medium);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 13px;
    min-height: 44px;
    touch-action: manipulation;
}

.action-item:active {
    background-color: var(--bg-light);
    border-color: var(--primary-color);
}

.action-icon {
    font-size: 16px;
    width: 24px;
    text-align: center;
}

.action-name {
    flex: 1;
    font-weight: 500;
}

.action-info {
    font-size: 11px;
    color: var(--text-dark);
}

/* Картинка локации - компактная */
.location-image {
    width: 100%;
    height: 120px;
    background-size: cover;
    background-position: center;
    border-radius: 6px;
    margin-bottom: 8px;
    position: relative;
}

.location-image::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to bottom, transparent 0%, rgba(0,0,0,0.7) 100%);
    border-radius: 6px;
}

/* Компактная статистика */
.stats-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 12px;
    border-bottom: 1px solid var(--border-color);
}

.stats-row:last-child {
    border-bottom: none;
}

.stat-label {
    color: var(--text-secondary);
}

.stat-value {
    font-weight: 600;
    color: var(--text-primary);
}

/* Тонкие прогресс бары */
.progress-bar {
    width: 100%;
    height: 12px;
    background-color: var(--bg-medium);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(to right, var(--secondary-color), var(--primary-color));
    transition: width 0.3s ease;
}

.progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 10px;
    font-weight: 600;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

/* Компактные кнопки */
.btn {
    display: inline-block;
    padding: 6px 12px;
    background-color: var(--bg-light);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    min-height: 44px;
    touch-action: manipulation;
}

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

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.btn-block {
    display: block;
    width: 100%;
}

/* Модальное окно */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-content {
    background-color: var(--bg-card);
    border: 1px solid var(--primary-color);
    border-radius: 8px;
    padding: 16px;
    max-width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(139, 0, 0, 0.3);
}

.modal-content h3 {
    font-size: 16px;
    margin-bottom: 10px;
    color: var(--accent-color);
}

.modal-content p {
    font-size: 13px;
    margin-bottom: 8px;
}

/* Экран загрузки */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-dark);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-content {
    text-align: center;
}

.game-logo {
    font-size: 28px;
    color: var(--primary-color);
    margin-bottom: 20px;
    text-shadow: 0 0 10px rgba(139, 0, 0, 0.5);
    font-weight: 700;
    letter-spacing: 2px;
}

.loading-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--bg-light);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    color: var(--text-secondary);
    font-size: 12px;
}

/* Компактная сетка */
.compact-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.grid-item {
    aspect-ratio: 1;
    background-color: var(--bg-medium);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 10px;
    text-align: center;
}

.grid-item:active {
    border-color: var(--primary-color);
    background-color: var(--bg-light);
}

.grid-icon {
    font-size: 20px;
    margin-bottom: 2px;
}

/* Формы */
.form-group {
    margin-bottom: 10px;
}

.form-input {
    width: 100%;
    padding: 8px 10px;
    background-color: var(--bg-medium);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 13px;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Разрешаем выделение только в формах */
input, textarea {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Компактный профиль */
.profile-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar-placeholder {
    width: 48px;
    height: 48px;
    background-color: var(--bg-medium);
    border: 2px solid var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.profile-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-color);
}

/* Страница профиля дополнительные стили */
.player-class-badge {
    background-color: var(--bg-medium);
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 14px;
}

.profile-info {
    flex: 1;
}

.profile-level {
    color: var(--text-secondary);
    margin-top: 5px;
}

.exp-section {
    margin-top: 15px;
}

.exp-section .stat-label {
    margin-bottom: 5px;
}

/* Страница локаций дополнительные стили */
.location-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.location-name {
    font-size: 24px;
    margin: 0;
    color: var(--primary-color);
}

.location-type {
    background-color: var(--bg-medium);
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 14px;
    color: var(--text-secondary);
}

.location-desc {
    line-height: 1.6;
    color: var(--text-secondary);
}

.location-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.location-action-btn {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background-color: var(--bg-medium);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

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

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

.location-tile {
    aspect-ratio: 1;
    background-color: var(--bg-medium);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.location-tile.active {
    border-color: var(--primary-color);
    background-color: var(--bg-light);
}

.location-tile.locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.location-tile-icon {
    font-size: 32px;
    margin-bottom: 5px;
}

.location-tile-name {
    font-size: 12px;
    font-weight: 600;
}

.location-tile-lock {
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 16px;
}

/* Страница главная дополнительные стили */
.quick-stats {
    display: flex;
    justify-content: space-around;
    gap: 10px;
}

.quick-stat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    padding: 10px;
    background-color: var(--bg-medium);
    border-radius: 8px;
}

.quick-stat-icon {
    font-size: 28px;
}

.quick-stat-info {
    flex: 1;
}

.quick-stat-value {
    font-size: 16px;
    font-weight: 600;
    color: var(--primary-color);
}

.quick-stat-label {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Страница инвентаря дополнительные стили */
.equipment-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 10px;
}

.equipment-slot {
    text-align: center;
}

.slot-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.slot-content {
    background-color: var(--bg-medium);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.slot-content.equipped {
    border-color: var(--primary-color);
}

.empty-icon {
    font-size: 24px;
    opacity: 0.3;
}

.empty-text {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 5px;
}

.inventory-tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 15px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab-btn {
    padding: 8px 16px;
    background-color: var(--bg-medium);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.tab-btn.active {
    background-color: var(--primary-color);
    color: var(--bg-dark);
    border-color: var(--primary-color);
}

.inventory-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
    margin-bottom: 10px;
}

.inventory-slot {
    aspect-ratio: 1;
    background-color: var(--bg-medium);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
}

.inventory-slot.occupied {
    border-color: var(--text-secondary);
}

.inventory-slot.occupied:active {
    transform: scale(0.95);
}

.item-icon {
    font-size: 24px;
}

.item-quantity {
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-size: 11px;
    font-weight: 600;
    background-color: rgba(0, 0, 0, 0.7);
    padding: 1px 4px;
    border-radius: 3px;
}

.inventory-capacity {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}

.item-details {
    text-align: center;
}

.item-icon-large {
    font-size: 64px;
    margin: 20px 0;
}

.item-description {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.item-stats {
    background-color: var(--bg-medium);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
}

.stat-line {
    padding: 5px 0;
    text-align: left;
}

.item-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Страница меню дополнительные стили */
.menu-section {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 15px;
}

.menu-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.menu-label {
    color: var(--text-secondary);
}

.menu-value {
    font-weight: 600;
    color: var(--text-primary);
}

.menu-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.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: var(--bg-medium);
    border: 1px solid var(--border-color);
    transition: .3s;
    border-radius: 34px;
}

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

input:checked + .toggle-slider {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

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

.menu-links {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.menu-link-btn {
    display: flex;
    align-items: center;
    padding: 15px;
    background-color: var(--bg-medium);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-primary);
    text-align: left;
}

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

.link-icon {
    font-size: 20px;
    margin-right: 15px;
}

.link-arrow {
    margin-left: auto;
    font-size: 20px;
    color: var(--text-secondary);
}

.version-info {
    text-align: center;
    color: var(--text-secondary);
    font-size: 12px;
    padding: 20px;
}

.help-content {
    text-align: left;
    color: var(--text-secondary);
}

.help-content h4 {
    color: var(--primary-color);
    margin: 15px 0 5px;
}

.premium-features {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin: 20px 0;
}

.premium-item {
    text-align: center;
}

.premium-icon {
    font-size: 32px;
    display: block;
    margin-bottom: 10px;
}

.premium-item h4 {
    color: var(--primary-color);
    margin: 5px 0;
}

.premium-item p {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Оптимизация анимаций для слабых устройств */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Оптимизация для маленьких экранов */
@media (max-height: 600px) {
    :root {
        --top-bar-height: 32px;
        --bottom-nav-height: 44px;
    }
    
    .content-card {
        margin: 4px;
        padding: 8px;
    }
    
    .nav-label {
        display: none;
    }
}

/* Адаптивность для очень маленьких экранов */
@media (max-width: 320px) {
    .nav-label {
        display: none;
    }
    
    .nav-icon {
        font-size: 20px;
    }
    
    .content-card {
        margin: 4px;
        padding: 8px;
    }
}

/* Убираем лишние отступы на iPhone */
@supports (padding: max(0px)) {
    .top-bar {
        padding-top: max(0px, env(safe-area-inset-top));
        height: calc(var(--top-bar-height) + max(0px, env(safe-area-inset-top)));
    }
    
    .bottom-nav {
        padding-bottom: max(0px, env(safe-area-inset-bottom));
        height: calc(var(--bottom-nav-height) + max(0px, env(safe-area-inset-bottom)));
    }
    
    .main-content {
        top: calc(var(--top-bar-height) + max(0px, env(safe-area-inset-top)));
        bottom: calc(var(--bottom-nav-height) + max(0px, env(safe-area-inset-bottom)));
    }
}

/* Индикатор подключения */
.connection-status {
    position: fixed;
    top: var(--top-bar-height);
    left: 0;
    right: 0;
    background-color: var(--success-color);
    color: white;
    text-align: center;
    padding: 4px;
    font-size: 11px;
    z-index: 99;
    display: none;
}

.connection-status.error {
    background-color: var(--danger-color);
}
