﻿:root {
    --font-F: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --Base_font: 16px;
    --FSB: 1rem;
    --H_Indicator: 5px;
    --H_header: 85px;
    --padding_breadcrumb: 6px;
    color-scheme: light dark;
    --Fon: light-dark(#F0F0F0, #222222f3);
    --Fon_a: light-dark(#FFF, #666666);
    --Fon_b: light-dark(#7a3215c4, #CCCCCC);
    --Text_C: light-dark(#000, #EEEEEE);
    --Akcent_C: light-dark(#4a6fa5, #6f9ecc);
    --V_C: light-dark(#CCCCCC, #666666);
    --V_C2: light-dark(#ff9e6d, #ffb347);
    --border-color: light-dark(#000, #EEEEEE);
    --a_Bukvica: light-dark(#4a306d, #ffb347);
    --dialogue: light-dark(#CCCCCC, #666666);
    --akcent: light-dark(#fff3e0, #7a3215c4);
    --footer_color: #CCCCCC;
}


[data-theme="dark"] {
    --Fon: #222222f3;
    --Fon_a: #666666;
    --Fon_b: #CCCCCC;
    --Text_C: #EEEEEE;
    --Akcent_C: #6f9ecc;
    --V_C: #666666;
    --V_C2: #ffb347;
    --border-color: #EEEEEE;
    --a_Bukvica: #ffb347;
    --menu-text: #e6e6e6;
    --menu-border: #2d4059;
    --progress-bg: #2d4059;
    --progress-fill: #6f9ecc;
    --dialogue: #666666;
    --akcent: #7a3215c4;
    --shadow: 0 4px 6px #0000004d;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    font-size: var(--Base_font);
    text-size-adjust: 100%; /* Предотвращает автоматическое изменение размера текста на iOS */
}

a {
    text-decoration: none;
}

body {
    font-family: var(--font-F);
    font-size: var(--FSB);
    line-height: 1.6;
    color: var(--Text_C);
    background-color: var(--Fon);
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100dvh;
}

#Body_grid {
    display: grid;
    grid-template-areas:
        "header"
        "main"
        "footer";
    grid-template-columns: 1fr;
}

@media (min-width: 900px) {
    #Body_grid {
        grid-template-areas:
            "header header"
            "aside main"
            "aside footer";
        grid-template-columns: minmax(max-content, 320px) 1fr;
    }
}
/* Оптимизировать анимации */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none;
        transition: none;
    }
}
h1:focus {outline: none;}
.h1-mega {
    text-align: center;
    font-size: clamp(1.9rem, 2vw + 1rem, 3rem);
    text-wrap: balance;
    color: var(--Akcent_C);
}
.story {
  /* CSS-логические свойства с fallback */
  --story-gap: 1rem;
  --story-padding: clamp(0.625rem, 2vi, 1.25rem);
  --border-radius: 0.9375rem;
  
  /* Основные стили */
  max-inline-size: min(680px, 90vi);
  margin-inline: auto;
  padding: var(--story-padding);
  
  background: var(--Fon, #fefefe);
  border-radius: var(--border-radius);
  box-shadow: 0 0.3125rem 0.9375rem rgb(0 0 0 / 0.1);
  
  /* Семантические улучшения */
  line-height: 1.6;
  color: var(--Text_C);

  /* Убираем отступы у первого и последнего элементов */
  & > :first-child {
    margin-block-start: 0;
  }

  & > :last-child {
    margin-block-end: 0;
  }

  /* Стили для заголовка с микроданными */
  & > h2 {
    color: var(--Akcent_C, #2a9d8f);
    text-align: center;
    border-block-end: 0.125rem solid var(--Akcent_C, #2a9d8f);
    padding-block-end: 0.625rem;
    margin-block: var(--story-gap);
    
    /* Улучшенная типографика */
    font-size: clamp(1.5rem, 4vi, 2rem);
    font-weight: 700;
    line-height: 1.2;
  }

  /* Стили для всех параграфов */
  & > p {
    text-align: justify;
    hyphens: auto;
    margin-block: 0.75rem;
    
    /* Улучшенная читаемость */
    text-wrap: pretty;
    hanging-punctuation: first;

    /* Специфичные стили для первого параграфа */
    &:first-of-type {
      margin-block-start: 0.625rem;
      font-weight: 500;
      
      /* Буквица с улучшенной поддержкой */
      &::first-letter {
        font-size: 4em;
        float: inline-start;
        line-height: 0.8;
        margin-inline-end: 0.5rem;
        color: var(--a_Bukvica, #e76f51);
        font-weight: 700;
        text-shadow: 0.0625rem 0.0625rem 0.125rem rgb(0 0 0 / 0.2);
        
        /* Поддержка для старых браузеров */
        @supports not (float: inline-start) {
          float: left;
        }
      }
    }

    /* Отступ для последующих параграфов */
    &:not(:first-of-type) {
      text-indent: 1rem;
    }
  }

  /* Диалоги с улучшенной семантикой */
  & .dialogue {
    
    background-color: var(--dialogue, rgb(85 165 134 / 0.08));
    padding: 1rem;
    border-inline-start: 0.375rem solid #55a586;;
    margin-block: 1.25rem;
    border-start-end-radius: 0.625rem;
    border-end-end-radius: 0.625rem;
    
    /* Улучшенная типографика для диалогов */
    font-style: italic;
    color: var(--Text_C);
    
    & p {
      margin-block: 0.5rem;
      text-indent: 0 !important; /* Убираем отступ в диалогах */
      text-align: start;
      
      &:first-child {
        margin-block-start: 0;
      }
      
      &:last-child {
        margin-block-end: 0;
      }
    }
  }

  /* Акцентные блоки */
  & .akcent {
    background-color: var(--akcent, rgb(255 245 204 / 0.8));
    padding: 1.5rem;
    border-radius: var(--border-radius);
    margin-block: 1.5rem;
    border: 0.0625rem solid rgb(255 235 143 / 0.6);
    
    /* Типографика акцентного блока */
    font-style: italic;
    font-size: 1.1em;
    line-height: 1.5;
    text-align: justify;
    
    & p {
      margin: 0;
      text-indent: 0 !important;
      font-style: inherit;
      font-size: inherit;
    }
  }

  /* Игнорируем ненужные <br> элементы */
  & > br {
    display: none;
  }
}

/* Адаптивность для мобильных устройств */
@media (max-width: 768px) {
  .story {
    max-inline-size: 95vi;
    padding: 1rem;
    
    & > p {
      text-align: start;
      hyphens: manual;
      text-indent: 0; /* Убираем отступ на мобильных */
      margin-block: 1rem;
      
      &:first-of-type::first-letter {
        font-size: 3em;
        margin-inline-end: 0.375rem;
      }
    }
    
    & .dialogue,
    & .akcent {
      margin-inline: -0.5rem; /* Выступ на мобильных */
      border-radius: 0;
      
      @media (hover: none) and (pointer: coarse) {
        /* Дополнительные улучшения для тач-устройств */
        padding: 1.25rem 1rem;
      }
    }
    
    & .akcent {
      font-size: 1em;
      padding: 1.25rem;
    }
  }
}

/* Улучшенная доступность */
@media (prefers-reduced-motion: reduce) {
  .story {
    * {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }
}

/* Контраст для пользователей с повышенными требованиями */
@media (prefers-contrast: high) {
  .story {
    --Akcent_C: #006400;
    --a_Bukvica: #8b0000;
    
    box-shadow: 0 0 0 0.125rem currentColor;
    
    & .dialogue {
      border-inline-start-width: 0.5rem;
    }
  }
}



/* Стили для печати */
@media print {
  .story {
    max-inline-size: 100%;
    box-shadow: none;
    background: white !important;
    color: black !important;
    
    & > p:first-of-type::first-letter {
      color: black !important;
    }
    
    & .dialogue {
      background: white !important;
      border: 0.0625rem solid #ccc;
    }
    
    & .akcent {
      background: white !important;
      border: 0.125rem solid black;
    }
  }
}