/* =========================================
   1. ПЕРЕМЕННЫЕ И ОСНОВЫ
   ========================================= */
:root {
    --wood-dark: #3e2723;
    --wood-main: #5d4037;
    --wood-light: #8d6e63;
    --gold: #ffecb3;
    --gold-bright: #ffd700;
    --parchment-bg: #f4ece1;
    --danger: #a62626;
    --header-h: 85px; /* Немного увеличили для девиза */
    --shadow-main: 0 5px 15px rgba(0,0,0,0.6);
    --border-main: 2px solid var(--wood-main);
}

* { 
    box-sizing: border-box; 
    -webkit-tap-highlight-color: transparent; 
}

body {
    margin: 0; padding: 0;
    font-family: 'Georgia', serif;
    background-color: #2b1d1a;
    color: var(--wood-dark);
    display: flex; flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
}

/* КАСТОМНЫЙ СКРОЛЛБАР */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #d7ccc8; }
::-webkit-scrollbar-thumb { 
    background: var(--wood-main); 
    border-radius: 4px; 
    border: 1px solid var(--wood-dark); 
}

/* =========================================
   2. ГЕНЕРАТОРЫ ТЕКСТУР
   ========================================= */
.wood-texture {
    background-color: var(--wood-main);
    background-image: 
        repeating-linear-gradient(90deg, rgba(0,0,0,0.05) 0px, rgba(0,0,0,0.05) 1px, transparent 1px, transparent 30px),
        repeating-linear-gradient(180deg, rgba(255,255,255,0.02) 0px, rgba(255,255,255,0.02) 1px, transparent 1px, transparent 2px),
        linear-gradient(to bottom, rgba(0,0,0,0.2), transparent);
}

.parchment-texture {
    background-color: var(--parchment-bg);
    background-image: 
        radial-gradient(circle at 50% 50%, rgba(255,255,255,0.3), transparent),
        repeating-radial-gradient(circle at 0 0, rgba(0,0,0,0.02) 0, rgba(0,0,0,0.02) 20px, transparent 20px, transparent 40px);
}

/* =========================================
   3. ШАПКА И ПРОФИЛЬ
   ========================================= */
.main-header {
    height: var(--header-h); 
    color: #fff;
    padding: 0 30px; 
    display: flex; 
    justify-content: space-between;
    align-items: center;
    border-bottom: 5px solid #1a100e;
    z-index: 1000;
    box-shadow: var(--shadow-main);
    gap: 15px;
}

/* ЛЕВО: ПРОФИЛЬ */
.user-profile { 
    display: flex; 
    align-items: center; 
    gap: 12px; 
    min-width: 200px;
}

.user-avatar-wrapper {
    width: 50px; height: 50px; min-width: 50px;
    border: 2px solid var(--gold); border-radius: 6px;
    overflow: hidden; background: #2b1d1a;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
    display: flex; justify-content: center; align-items: center;
}

#user-avatar { width: 100%; height: 100%; object-fit: cover; display: block; }

.user-details h3 { margin: 0; color: #fff; font-size: 1em; line-height: 1.2; }
.user-details p { margin: 2px 0 0 0; font-size: 0.8em; color: #d7ccc8; line-height: 1.1; }
#display-money { color: var(--gold-bright); font-weight: bold; }

/* ЦЕНТР: НАЗВАНИЕ МИРА */
.village-branding {
    flex: 2;
    text-align: center;
    display: flex;
    flex-direction: column;
}

#main-title {
    margin: 0;
    font-size: 1.6em;
    color: var(--gold-bright);
    text-shadow: 2px 2px 0px #000, 0 0 10px rgba(255, 215, 0, 0.3);
    letter-spacing: 2px;
    text-transform: uppercase;
}

.village-motto {
    margin: 2px 0 0 0;
    font-style: italic;
    font-size: 0.85em;
    color: #d1b8a1;
    text-shadow: 1px 1px 1px #000;
}

/* ПРАВО: УПРАВЛЕНИЕ */
.header-controls {
    display: flex;
    gap: 8px;
    min-width: 280px;
    justify-content: flex-end;
}

/* =========================================
   4. КОНТЕЙНЕРЫ И АНИМАЦИИ
   ========================================= */
.container { display: flex; flex: 1; height: calc(100dvh - var(--header-h)); }

.content-area { flex: 1; display: flex; flex-direction: column; padding: 15px 15px 15px 0; overflow: hidden; }

.content-block { 
    flex: 1; display: flex; flex-direction: column; 
    background: #1a1a1a; border-radius: 8px; 
    border: 3px solid var(--wood-main); 
    box-shadow: 10px 10px 30px rgba(0,0,0,0.5); 
    overflow: hidden; 
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.block-header { 
    height: 55px; padding: 0 20px; color: var(--gold); 
    display: flex; justify-content: space-between; align-items: center; 
    border-bottom: 3px solid var(--wood-dark); 
}

/* =========================================
   5. ВЕЧЕВОЕ ОКО (ЧАТ)
   ========================================= */
.chat-sidebar {
    width: 300px; min-width: 300px; margin: 15px;
    border: var(--border-main); border-radius: 8px;
    display: flex; flex-direction: column;
    box-shadow: 5px 5px 15px rgba(0,0,0,0.4);
    overflow: hidden;
}

.chat-header { color: var(--gold); padding: 12px; text-align: center; font-weight: bold; border-bottom: 3px solid var(--wood-dark); }

.chat-window { 
    flex: 1; padding: 15px; overflow-y: auto; 
    background: rgba(0,0,0,0.05); list-style: none; margin: 0; 
}

.chat-msg { 
    background: rgba(255,255,255,0.85); padding: 10px; margin-bottom: 12px; 
    border-radius: 8px 8px 8px 0; border-left: 5px solid var(--wood-light);
    box-shadow: 2px 2px 5px rgba(0,0,0,0.1); font-size: 0.9em;
}

.chat-msg b { display: block; font-size: 0.75em; color: var(--wood-main); text-transform: uppercase; margin-bottom: 3px; }

.chat-input-area { padding: 10px; display: flex; gap: 5px; border-top: 2px solid var(--wood-dark); }
.chat-input-area input { flex: 1; padding: 8px; border: 1px solid var(--wood-main); border-radius: 4px; background: #fff; font-family: inherit; }

/* =========================================
   6. КАРТА (УГОДЬЯ)
   ========================================= */
.map-viewport { flex: 1; position: relative; background: #111; box-shadow: inset 0 0 60px #000; overflow: hidden; cursor: grab; }
.map-viewport:active { cursor: grabbing; }
#mapCanvas { display: block; position: absolute; top: 0; left: 0; }
#build-type { padding: 5px; border: 1px solid var(--wood-main); background: var(--parchment-bg); border-radius: 4px; font-weight: bold; }

/* =========================================
   7. КНОПКИ
   ========================================= */
.btn-wood { 
    background-color: var(--wood-light);
    background-image: linear-gradient(to bottom, rgba(255,255,255,0.1), rgba(0,0,0,0.1));
    border: 1px solid var(--wood-dark); border-bottom: 3px solid #2b1d1a;
    color: var(--gold); padding: 8px 15px; cursor: pointer; font-weight: bold;
    border-radius: 4px; transition: all 0.2s; text-shadow: 1px 1px 1px #000; font-size: 0.85em;
}

.btn-wood:hover { 
    background-color: #9e7e73; transform: translateY(-2px); 
    box-shadow: 0 0 12px rgba(255, 236, 179, 0.4); border-color: var(--gold);
}

.btn-wood:active { transform: translateY(1px); border-bottom-width: 1px; }

.btn-exit {
    background-color: #4e342e; border: 1px solid #261b18; border-bottom: 3px solid #1a100e;
    color: #bcaaa4; padding: 8px 15px; cursor: pointer; font-weight: bold; border-radius: 4px;
    font-size: 0.85em; text-shadow: 1px 1px 1px #000;
}
.btn-exit:hover { background-color: var(--danger); color: #fff; }

.btn-wood.danger { background: var(--danger); border-color: #5d0000; }

/* =========================================
   8. ВЕСТИ (СВИТКИ)
   ========================================= */
.news-feed { flex: 1; overflow-y: auto; padding: 30px; display: flex; flex-direction: column; gap: 30px; background: var(--wood-dark); }
.news-scroll { 
    position: relative; padding: 40px; border-radius: 2px; 
    border-left: 12px solid var(--wood-light); background-color: var(--parchment-bg);
    box-shadow: 8px 8px 20px rgba(0,0,0,0.5);
    background-image: linear-gradient(to right, rgba(0,0,0,0.03) 0%, transparent 5%);
}
.news-seal { position: absolute; top: -15px; right: 25px; width: 55px; height: 55px; background: radial-gradient(#a62626 60%, #7f0000); border-radius: 50%; border: 3px double #5d0000; box-shadow: 2px 4px 8px rgba(0,0,0,0.6); }

/* =========================================
   9. КНИЖНАЯ ПАЛАТА (БИБЛИОТЕКА)
   ========================================= */
.library-container { display: flex; flex: 1; background: var(--wood-dark); }
.library-nav { width: 260px; border-right: 4px solid var(--wood-main); display: flex; flex-direction: column; gap: 12px; padding: 25px; }
.lib-category { padding: 12px; background: rgba(255,255,255,0.05); color: var(--gold); cursor: pointer; transition: all 0.2s; border-radius: 4px; }
.lib-category.active { background: var(--wood-light); color: #fff; border: 1px solid var(--gold); }
.library-reader { flex: 1; padding: 50px; overflow-y: auto; background: var(--parchment-bg); box-shadow: inset 0 0 40px rgba(0,0,0,0.3); }

/* =========================================
   10. АДАПТИВНОСТЬ
   ========================================= */
@media (max-width: 850px) {
    .main-header { height: auto; padding: 10px; flex-direction: column; gap: 12px; }
    .village-branding { width: 100%; order: -1; }
    .village-motto { display: none; }
    #main-title { font-size: 1.2em; }
    .user-profile { width: 100%; justify-content: center; }
    .header-controls { width: 100%; justify-content: center; min-width: 0; }
    
    .container { flex-direction: column; height: calc(100dvh - 180px); overflow-y: auto; }
    .content-area { padding: 10px; min-height: 400px; flex: none; }
    .chat-sidebar { width: auto; min-width: 0; margin: 10px; height: 300px; }
}
