/* --- Сброс и базовые стили --- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Alegreya', 'Georgia', serif;
  font-size: 1.22em;
  line-height: 1.9;
  letter-spacing: 0.01em;
  color: #2d1d3a;
  background: radial-gradient(ellipse at top, #e5e0f9 0%, #b6aeea 100%);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background 0.4s ease, color 0.4s ease;
}

/* --- Панель переключения темы слева --- */
#theme-switcher {
  position: fixed;
  top: 32px;
  left: 32px;
  width: 180px;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  gap: 0.7em;
  background: rgba(255, 255, 255, 0.82);
  padding: 0.7em 0.8em;
  border-radius: 14px;
  box-shadow: 0 2px 12px #7a5fff33;
  font-family: 'Montserrat', 'Arial', sans-serif;
}

#theme-switcher button,
#theme-switcher [data-back-button] {
  padding: 0.6em 1.2em;
  font-size: 1em;
  font-weight: 700;
  cursor: pointer;
  border-radius: 7px;
  border: 1.5px solid #7a5fff;
  background: #e1d4f2;
  color: #4d2e8c;
  text-align: left;
  transition: background 0.2s, color 0.2s;
  user-select: none;
  box-sizing: border-box;
}

#theme-switcher button.active,
#theme-switcher button:hover,
#theme-switcher button:focus-visible,
#theme-switcher [data-back-button]:hover,
#theme-switcher [data-back-button]:focus-visible {
  background: #7a5fff;
  color: white;
  outline: none;
}

/* --- Заголовок страницы --- */
#site-title {
  text-align: center;
  margin: 1.5em 0 1.8em 0;
  user-select: none;
  font-family: 'Montserrat', 'Arial', sans-serif;
  color: #5e3a9d;
}
#site-title h1 {
  margin: 0;
  font-size: 2.6em;
  font-weight: 700;
}
#site-title p {
  margin: 0.3em 0 0 0;
  font-size: 1.2em;
  font-style: italic;
  color: #7a5fff;
}

/* --- Основной контейнер, горизонтальный флекс --- */
#main-content {
  max-width: 1300px;
  margin: 0 auto 3rem auto;
  height: calc(100vh - 150px);
  padding: 0 1rem 1rem 1rem;
  display: flex;
}

/* --- Окно текста книги (главный контент) --- */
#bookContent {
  flex-grow: 1;
  background: rgba(255, 255, 255, 0.96);
  border-radius: 28px;
  box-shadow: 0 12px 48px #7a5fff44, inset 0 0 0 8px #d1c6f7bb;
  padding: 2.5em 3em;
  overflow-y: auto;
  border: 4px double #7a5fff;
  font-size: 1.15em;
  line-height: 1.7;
  color: #2d1d3a;
  user-select: text;
  min-width: 0;
  height: calc(100vh - 150px);
}

#right-panel {
  width: 340px;
  margin-left: 2.2rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  position: sticky;
  top: 120px;
  height: fit-content;
  font-family: 'Alegreya', serif;
  color: #6a00ff;
}

/* --- Навигация по главам --- */
#chapter-navigation {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
}

/* Кнопка открытия списка глав */
#chapter-navigation button#openChapterList {
  background-color: #7a5fff;
  border: none;
  border-radius: 16px;
  color: white;
  font-weight: 700;
  font-size: 1.1em;
  padding: 0.75em 1.3em;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(122, 95, 255, 0.6);
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
  user-select: none;
  width: 100%;
  text-align: center;
  font-family: 'Montserrat', sans-serif;
}
#chapter-navigation button#openChapterList:hover,
#chapter-navigation button#openChapterList:focus-visible {
  background-color: #5e3a9d;
  box-shadow: 0 10px 32px rgba(94, 58, 157, 0.8);
  outline: none;
}

/* --- Навигация по страницам --- */
#page-navigation {
  display: flex;
  flex-direction: column;
  gap: 0.75em;
}

#page-navigation button {
  background: #7a5fff;
  border: none;
  border-radius: 16px;
  padding: 0.8em 1.6em;
  color: white;
  font-weight: 700;
  font-size: 1.1em;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(122, 95, 255, 0.6);
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
  user-select: none;
  width: 100%;
  font-family: 'Montserrat', sans-serif;
  margin-top: 0.2rem;
}

#page-navigation button:disabled {
  background: #b6aeea;
  cursor: default;
  box-shadow: none;
  color: #7a5fff;
}

#page-navigation button:hover:not(:disabled),
#page-navigation button:focus-visible {
  background-color: #5e3a9d;
  box-shadow: 0 10px 32px rgba(94, 58, 157, 0.9);
  outline: none;
}

/* --- Выпадающий список глав --- */
.chapter-list-dropdown {
  position: absolute;
  top: 3.8rem;
  right: 0;
  background: #f9f9ff;
  max-height: 320px;
  min-width: 300px;
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(122, 95, 255, 0.35);
  overflow-y: auto;
  padding: 0.8em 0;
  display: none;
  z-index: 1500;
  transition: opacity 0.35s ease, transform 0.35s ease;
  opacity: 0;
  transform: translateY(-15px);
  pointer-events: none;
}

.chapter-list-dropdown.open {
  display: block;
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Кнопки в списке глав */
.chapter-list-dropdown button {
  background: linear-gradient(135deg, #7a5fffcc 0%, #5e3a9dcc 100%);
  border: none;
  margin: 0.2em 1.2em;
  padding: 0.75em 1.2em;
  border-radius: 12px;
  width: calc(100% - 2.4em);
  color: #f0eaff;
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  font-size: 1em;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(122, 95, 255, 0.55);
  transition: background 0.25s ease, box-shadow 0.25s ease;
  user-select: none;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chapter-list-dropdown button:hover,
.chapter-list-dropdown button:focus-visible {
  background: linear-gradient(135deg, #a085ff, #7a5fff);
  box-shadow: 0 6px 24px rgba(138, 120, 255, 0.85);
  outline: none;
  color: #fff;
}

/* --- Тёмная тема для выпадающего списка и кнопок --- */
body.theme-dark .chapter-list-dropdown {
  background: #2e2850;
  box-shadow: 0 10px 40px rgba(1, 207, 255, 0.33);
}

body.theme-dark .chapter-list-dropdown button {
  background: linear-gradient(135deg, #01cfffcc 0%, #005f99cc 100%);
  color: #d0f0ff;
  box-shadow: 0 4px 15px rgba(1, 207, 255, 0.55);
}

body.theme-dark .chapter-list-dropdown button:hover,
body.theme-dark .chapter-list-dropdown button:focus-visible {
  background: linear-gradient(135deg, #00aaff, #0077cc);
  box-shadow: 0 6px 24px rgba(0, 153, 204, 0.85);
  color: #e0ffff;
}

/* --- Тёмная тема для основных областей --- */
body.theme-dark {
  background: radial-gradient(ellipse at top, #1e1930 0%, #2a2443 100%);
  color: #e5e3f7;
}

body.theme-dark #bookContent {
  background: #231f33;
  box-shadow: 0 8px 48px #00000044;
  border-color: #5e3a9d;
  color: #e5e3f7;
}

body.theme-dark #right-panel,
body.theme-dark #theme-switcher {
  background: rgba(35, 32, 58, 0.9);
  box-shadow: 0 2px 12px #01cfff88;
  color: #a0cfff;
}

body.theme-dark #page-navigation button,
body.theme-dark #chapter-navigation button#openChapterList {
  background: #01cfff;
  color: #1a1a2e;
}

body.theme-dark #page-navigation button:hover:not(:disabled),
body.theme-dark #chapter-navigation button#openChapterList:hover {
  background-color: #0099cc;
}

/* --- Тёмная тема для мыслей (монологов) --- */
body.theme-dark .monologue {
  background: linear-gradient(90deg, #2a2443 70%, #3a335d 100%);
  color: #c2b1ff;
  border-left-color: #8a78ff;
  box-shadow: 0 2px 16px #8a78ff44;
}

/* Подсветка "ᚱ" в монологах для тёмной темы */
body.theme-dark .monologue:before {
  color: #a085ff;
  opacity: 0.6;
  animation: rune-float 3s infinite alternate;
}

/* --- Высокая контрастность --- */
body.theme-accessible {
  background: #fff !important;
  color: #000 !important;
  font-size: 1.22em !important;
  font-family: 'Arial Rounded MT Bold', 'Arial', 'Verdana', 'Tahoma', sans-serif !important;
  letter-spacing: 0.03em;
  line-height: 1.8;
}

body.theme-accessible #bookContent {
  background: #fff !important;
  color: #000 !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  border: 3px solid #000 !important;
  padding: 2.2em 1.2em 1.2em 1.2em;
}

body.theme-accessible #right-panel,
body.theme-accessible #theme-switcher {
  background: #fff !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  border: 2px solid #000 !important;
  color: #000 !important;
}

body.theme-accessible #page-navigation button,
body.theme-accessible #chapter-navigation button#openChapterList {
  background: #000 !important;
  color: #fff !important;
}

body.theme-accessible #page-navigation button:hover:not(:disabled),
body.theme-accessible #chapter-navigation button#openChapterList:hover {
  background: #333 !important;
}

/* --- Анимации для монологов --- */
@keyframes fadeInMonologue {
  from { opacity: 0; transform: translateX(-30px);}
  to { opacity: 1; transform: translateX(0);}
}
@keyframes rune-float {
  from { top: 0.1em; opacity: 0.45; }
  to   { top: -0.4em; opacity: 0.7; }
}

/* --- Текстовые стили для книги --- */

/* Заголовки глав и частей */
.chapter, .part {
  display: flex;
  flex-wrap: nowrap;
  align-items: baseline;
  gap: 0.5em;
  font-family: 'UnifrakturCook', 'Alegreya', serif;
  font-size: 1.35em;
  border-bottom: 2px dashed #a085ff44;
  padding-bottom: 0.2em;
  margin-top: 2.5em;
  margin-bottom: 1.2em;
  color: #5e3a9d;
  text-shadow: 0 2px 12px #b6aeea66;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chapter-label, .part-label {
  white-space: nowrap;
  font-weight: bold;
  font-size: 1.05em;
  letter-spacing: 0.04em;
}
.chapter-title, .part-title {
  word-break: break-word;
  font-weight: normal;
  font-size: 0.93em;
  color: #7a5fff;
  font-family: 'Alegreya', serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 70vw;
}

/* Пролог */
.prologue, h2.prologue {
  font-family: 'UnifrakturCook', 'Alegreya', serif;
  font-size: 1.3em;
  color: #5e3a9d;
  margin-top: 2.5em;
  margin-bottom: 1.2em;
  border-bottom: 2px dashed #a085ff44;
  padding-bottom: 0.2em;
}

/* Монологи */
.monologue {
  display: block;
  font-style: italic;
  color: #563a7d;
  margin: 1.7em 0;
  border-left: 7px solid #a085ff;
  padding-left: 1.4em;
  background: linear-gradient(90deg, #f3f0fa 70%, #e1d4f2 100%);
  border-radius: 0 18px 18px 0;
  box-shadow: 0 2px 18px #7a5fff22;
  font-size: 1.19em;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  animation: fadeInMonologue 0.9s;
  line-height: 2.02;
  letter-spacing: 0.02em;
  position: relative;
  overflow: visible;
}
.monologue:before {
  content: "ᚱ";
  color: #a085ff;
  font-size: 1.3em;
  position: absolute;
  left: -1.3em;
  top: 0.1em;
  opacity: 0.5;
  animation: rune-float 3s infinite alternate;
}
.monologue-thinker, .monologue-author {
  font-weight: bold;
  color: #01cfff;
  margin-right: 0.7em;
  font-style: normal;
  font-size: 1.09em;
  letter-spacing: 0.03em;
}

/* Речь */
.speech {
  color: #5b3ad6;
  font-style: normal;
  font-weight: 600;
  padding-left: 0.8em;
  display: block;
  margin: 1.1em 0;
  font-size: 1.13em;
  letter-spacing: 0.01em;
  font-family: 'Alegreya', serif;
}

/* Особенности речи: крик и шёпот */
.speech-shout, .speech-shout-last {
  color: #d93025;
  font-weight: 900;
  text-shadow: 0 0 6px rgba(217, 48, 37, 0.67);
  display: inline;
}

.speech-whisper {
  color: #666666cc; /* полупрозрачный тёмно-серый */
  font-style: italic;
  user-select: none;
  transition: color 0.3s ease;
}
.speech-whisper:hover {
  color: #666666ee;
}

/* Обычный текст */
p {
  margin: 1.3em 0;
  font-size: 1.16em;
  line-height: 2.05;
  font-family: 'Alegreya', 'Georgia', serif;
  letter-spacing: 0.01em;
}

/* Цитаты */
.quote {
  color: #a085ff;
  background: rgba(122, 95, 255, 0.1);
  padding: 0.1em 0.4em;
  border-radius: 6px;
  font-style: italic;
  transition: color 0.2s, background 0.2s;
}

body.theme-dark .quote {
  color: #01cfff;
  background: rgba(1, 207, 255, 0.15);
}

/* Подсветка локаций */
.location-name {
  color: #3a7d44;
  background-color: transparent;
  font-style: normal;
  font-weight: 600;
  border-radius: 4px;
  padding: 0 0.15em;
  user-select: text;
  cursor: help;
  transition: color 0.3s ease;
  white-space: nowrap;
}

.location-name:hover {
  color: #52b273;
  text-decoration: underline;
}

body.theme-dark .location-name {
  color: #6fc07d;
}

body.theme-accessible .location-name {
  color: #3a7d44;
  font-weight: 700;
  text-decoration: underline;
}