/* static/css/style.css (Версия со 100% исправлением) */

:root {
    --bg-color: #FAF8F0;
    --text-color: #333333;
    --primary-color: #5a7a99;
    --accent-color: #D4AF37;
    --border-color: #ddd;
    --font-main: 'Merriweather', serif;
    --font-headings: 'Lato', sans-serif;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.7;
    margin: 0;
    font-size: 18px;
    overflow-x: hidden;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 20px;
    box-sizing: border-box;
}

/* --- Вся ваша базовая разметка остается без изменений --- */
.site-header, .site-footer { text-align: center; padding: 2rem 0; font-family: var(--font-headings); }
.site-header { border-bottom: 1px solid var(--border-color); margin-bottom: 2rem; }
.site-header h1 { margin: 0; font-size: 2.5rem; }
.site-header h1 a { color: var(--text-color); text-decoration: none; }
.site-header p { margin: 0.5rem 0 0; color: #777; font-size: 1.2rem; }
.site-footer { margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--border-color); font-size: 0.9rem; color: #888; }
a { color: var(--primary-color); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--accent-color); text-decoration: underline; }
.controls { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 2rem; }
.search-form { flex-grow: 1; display: flex; }
.search-form input[type="search"] { width: 100%; padding: 0.75rem; font-size: 1rem; border: 1px solid var(--border-color); border-radius: 5px; font-family: var(--font-headings); }
.search-form button { padding: 0.75rem 1rem; border: 1px solid var(--primary-color); background-color: var(--primary-color); color: white; cursor: pointer; border-radius: 0 5px 5px 0; margin-left: -1px; }
.volume-nav { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; margin-bottom: 2rem; border-top: 1px dashed var(--border-color); border-bottom: 1px dashed var(--border-color); padding: 1rem 0; }
.volume-nav a { padding: 0.2rem 0.5rem; border: 1px solid transparent; border-radius: 3px; font-family: var(--font-headings); }
.volume-nav a.active, .volume-nav a:hover { background-color: var(--accent-color); color: white; text-decoration: none; border-color: var(--accent-color); }
.icon-list ul { list-style: none; padding: 0; }
.icon-list li { margin-bottom: 0.5rem; }
.icon-list a { font-size: 1.2rem; font-family: var(--font-headings); }
.icon-detail-header h2 { font-size: 2.2rem; text-align: center; margin-bottom: 2rem; font-family: var(--font-headings); font-weight: 700; color: var(--text-color); }
.icon-image {max-width: 100% !important;  width: auto !important; height: auto !important; display: block; background: white; border: 1px solid var(--border-color); padding: 5px; box-sizing: border-box; box-shadow: 0 4px 12px rgba(0,0,0,0.15); margin-left: auto; margin-right: auto;}
.icon-description { font-size: 1.5rem; overflow-wrap: break-word; }
.icon-description p { margin-bottom: 1.5em;}
.icon-description h1, .icon-description h2, .icon-description h3 { font-family: var(--font-headings); margin-top: 2em; margin-bottom: 1em; color: #000; }
.back-link { display: inline-block; margin-bottom: 2rem; font-family: var(--font-headings); }
/* --- КОНЕЦ БАЗОВОЙ РАЗМЕТКИ --- */

/* --- Стили для красной строки --- */

/* --- Стили для текстовых абзацев в .icon-description --- */

/* 
  Применяем стили к абзацам (<p>), которые:
  1. НЕ содержат изображение (:not(:has(img)))
  2. И НЕ содержат в атрибуте style текст "text-align:center"
*/
.icon-description p:not(:has(img)):not([style*="text-align:center"]) {
  text-align: justify;
  text-indent: 1.5em;
  margin-bottom: 1em;
  overflow-wrap: break-word;
}

/* 
  Убираем "красную строку" у первого абзаца после заголовка
  (если он не центрирован)
*/
.icon-description h2 + p:not([style*="text-align:center"]) {
  text-indent: 0;
}

/* Центрируем все содержимое внутри блока .icon-description */
.icon-description {
  text-align: center;
}

/* Стили для рамки вокруг изображения */
.icon-description p:has(img) {
  display: inline-block;
  background-color: white;
  padding: 5px;
  border: 1px solid #ddd;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  margin: 0;
  line-height: 0;
}

/* Стили для самого изображения внутри рамки */
.icon-description img {
  display: block;
  max-width: 100%;
  height: auto;
}


/* --- Улучшенные стили для текстовых абзацев --- */

/* 
  Применяем стили к абзацам (<p>), которые:
  1. НЕ содержат изображение.
  2. И НЕ содержат инлайн-стиль для центрирования.
*/
.icon-description p:not(:has(img)):not([style*="text-align:center"]) {
  /* --- БЛОК ДЛЯ НАДЕЖНОГО ПЕРЕНОСА СЛОВ --- */
  
  /* 1. Включаем переносы для всех современных браузеров */
  -webkit-hyphens: auto; /* Для Chrome, Safari, Opera, Edge */
  -moz-hyphens: auto;    /* Для Firefox */
  -ms-hyphens: auto;     /* Для старого IE */
  hyphens: auto;
  
  /* 2. ПРИНУДИТЕЛЬНОЕ ВЫРАВНИВАНИЕ ПО ШИРИНЕ. */
  /* Некоторые мобильные браузеры не включают переносы, */
  /* если текст не выровнен по ширине (justify). */
  text-align: justify;

  /* 3. УЛУЧШЕНИЕ ДЛЯ МОБИЛЬНЫХ БРАУЗЕРОВ НА ДВИЖКЕ WEBKIT (CHROME, SAFARI) */
  /* Это свойство может помочь "подтолкнуть" браузер к переносам. */
  -webkit-hyphenate-character: '-'; /* Явно указываем символ переноса */
  
  /* --- Остальные стили --- */
  
  /* "Красная строка" */
  text-indent: 1.5em;
  
  /* Отступ между абзацами */
  margin-bottom: 1em;
  
  /* Защита от переполнения очень длинными словами */
  overflow-wrap: break-word;
}

/* 
  Убираем "красную строку" у первого абзаца после заголовка, 
  если он не центрирован.
*/
.icon-description h2 + p:not([style*="text-align:center"]) {
  text-indent: 0;
}


/*
 * ===================================================================
 *  УНИВЕРСАЛЬНЫЕ СТИЛИ ДЛЯ ИЗОБРАЖЕНИЙ ВНУТРИ ОПИСАНИЯ
 * ===================================================================
*/

/* 
  Стиль для ЛЮБОГО контейнера <figure> внутри .icon-description.
  Он сработает независимо от того, какой там класс.
*/
.icon-description figure {
    margin-bottom: 1.5rem;
    /* По умолчанию центрируем */
    margin-left: auto;
    margin-right: auto;
    text-align: center; /* Центрируем подпись, если она есть */
}

/* 
  Стиль для ЛЮБОГО изображения <img> внутри <figure> в .icon-description.
  Это самое важное правило!
*/
.icon-description figure img {
    /* ЗАСТАВЛЯЕМ ИЗОБРАЖЕНИЕ БЫТЬ АДАПТИВНЫМ */
    max-width: 100% !important;
    width: auto !important;
    height: auto !important;
    display: block;
    background: white;
    border: 1px solid var(--border-color);
    padding: 5px;
    box-sizing: border-box;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    margin-left: auto;
    margin-right: auto;
}

.icon-description figure {
  display: flex;
  justify-content: center;
}



/* --- ОБЩАЯ АДАПТИВНОСТЬ --- */
@media (max-width: 768px) {
    body { font-size: 16px; }
    .container { padding: 0 15px; }
    .controls { flex-direction: column; }
    .search-form { width: 100%; }
    .site-header h1 { font-size: 2rem; }
    .icon-detail-header h2 { font-size: 1.8rem; }

    /* 
      На мобильных устройствах мы дополнительно гарантируем, 
      что контейнер <figure> занимает всю ширину.
    */
    .icon-description figure {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/*
 * ===================================================================
 *  СТИЛИ ДЛЯ КНОПКИ "ПРОКРУТКА НАВЕРХ"
 * ===================================================================
*/
#scrollToTopBtn {
    /* Позиционирование */
    position: fixed; /* Фиксируем относительно окна браузера */
    bottom: 30px;
    right: 30px;
    z-index: 99; /* Чтобы была поверх всех элементов */

    /* Внешний вид */
    background-color: var(--primary-color);
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 50%; /* Делаем ее круглой */
    border: none;
    outline: none;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);

    /* Центрируем иконку внутри */
    display: flex;
    justify-content: center;
    align-items: center;

    /* Анимация появления/исчезновения */
    opacity: 0; /* По умолчанию кнопка прозрачна (скрыта) */
    visibility: hidden; /* И полностью невидима */
    transform: translateY(20px); /* Немного сдвинута вниз для красивого "вылета" */
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
}

/* Стиль для видимой кнопки */
#scrollToTopBtn.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Эффект при наведении */
#scrollToTopBtn:hover {
    background-color: var(--accent-color);
}

/* Контейнер для позиционирования */
.video-container {
    max-width: 100%;
    margin: 1em 0;
}

.video-link {
    position: relative;
    display: block;
    overflow: hidden;
    border-radius: 12px; /* Скругленные углы — это современно */
    box-shadow: 0 4px 15px rgba(0,0,0,0.1); /* Мягкая тень */
    transition: transform 0.3s ease;
}

.video-overlay {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Иконка Play */
.play-button {
    position: absolute;
    width: 70px;
    height: 70px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
    z-index: 2;
}

/* Треугольник внутри кнопки */
.play-button::after {
    content: '';
    display: block;
    margin-left: 5px;
    border-style: solid;
    border-width: 15px 0 15px 25px;
    border-color: transparent transparent transparent #2c3e50; /* Цвет иконки */
}

/* Эффекты при наведении */
.video-link:hover {
    transform: translateY(-5px); /* Легкий подъем */
}

.video-link:hover .play-button {
    transform: scale(1.1);
    background: #fff;
    box-shadow: 0 0 20px rgba(255,255,255,0.5);
}

.video-link:hover img {
    filter: brightness(0.8); /* Затемнение фото при наведении */
}

img {
    display: block;
    width: 100%;
    height: auto;
    transition: filter 0.3s ease;
}

