/* Сброс */
*,
*::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 150px; /* 100px от левого края, но справа авто */
  height: calc(100vh - 150px);
  padding: 0 1rem 1rem 1rem;
  display: flex;
  flex-direction: column;
}

/* Контейнер с текстом и панелью */

#reader-container {
  margin-left: 220px; /* отступ под панель слева */
  height: 100%;
  display: flex;
  gap: 1.8rem;
  position: relative;
}

/* Текст книги */

#bookContent {
  flex: 3 1 auto;
  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: 100%;
}

/* Правая панель */

#right-panel {
  position: fixed;
  top: 120px;
  right: 32px;
  width: 320px;
  height: calc(100vh - 150px);
  background: rgba(255, 255, 255, 0.9);
  border-radius: 20px;
  box-shadow: 0 8px 28px rgba(122, 95, 255, 0.15);
  padding: 1.5rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  overflow-y: auto;
  font-family: 'Alegreya', serif;
  color: #563a7d;
  z-index: 1100;
}

/* Загрузка текста */

#load-text-container h2 {
  font-family: 'UnifrakturCook', 'Alegreya', serif;
  font-size: 1.5em;
  margin-bottom: 0.3em;
  color: #5e3a9d;
  user-select: none;
}

#text-input {
  width: 100%;
  height: 130px;
  resize: vertical;
  font-family: 'Alegreya', serif;
  font-size: 1em;
  line-height: 1.5;
  padding: 0.7em 1em;
  border: 2px solid #a085ff;
  border-radius: 12px;
  box-shadow: inset 0 1px 6px rgba(122, 95, 255, 0.35);
  transition: border-color 0.3s, background 0.3s;
  color: #2d1d3a;
  background-color: #f3f0fa;
  user-select: text;
}

#text-input:focus {
  outline: none;
  border-color: #7a5fff;
  box-shadow: inset 0 1px 6px rgba(122, 95, 255, 0.7);
}

#load-text-btn {
  padding: 0.7em 1.4em;
  font-size: 1.05em;
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  background-color: #7a5fff;
  color: white;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(122, 95, 255, 0.35);
  transition: background-color 0.3s ease;
  user-select: none;
}

#load-text-btn:hover,
#load-text-btn:focus-visible {
  background-color: #5e3a9d;
  outline: none;
}

/* Загрузка файла */

#file-label {
  display: inline-block;
  padding: 0.5em 1em;
  font-family: 'Montserrat', sans-serif;
  color: #7a5fff;
  border: 2px solid #7a5fff;
  border-radius: 12px;
  cursor: pointer;
  user-select: none;
  text-align: center;
  transition: background-color 0.3s ease, color 0.3s ease;
}

#file-label:hover,
#file-label:focus-visible {
  background-color: #7a5fff;
  color: white;
  outline: none;
}

#file-input {
  display: none;
}

#file-name {
  display: block;
  margin-top: 0.3em;
  font-family: 'Alegreya', serif;
  font-size: 0.9em;
  color: #5e3a9d;
  user-select: none;
}

/* Навигация */

#chapter-navigation {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
}
#chapter-navigation button#openChapterList {
  background-color: #7a5fff;
  border: none;
  border-radius: 12px;
  color: white;
  font-weight: 700;
  font-size: 1em;
  padding: 0.6em 1em;
  cursor: pointer;
  box-shadow: 0 5px 15px rgba(122, 95, 255, 0.4);
  transition: background-color 0.3s ease;
  user-select: none;
  width: 100%;
  text-align: center;
}

#chapter-navigation button#openChapterList:hover,
#chapter-navigation button#openChapterList:focus-visible {
  background-color: #5e3a9d;
  outline: none;
}

/* Кнопки навигации по страницам вертикально */

#page-navigation {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  margin-top: 1em;
}

#page-navigation button {
  background: #7a5fff;
  border: none;
  border-radius: 12px;
  padding: 0.6em 1em;
  color: white;
  font-weight: 700;
  font-size: 1em;
  cursor: pointer;
  box-shadow: 0 5px 15px rgba(122, 95, 255, 0.4);
  transition: background-color 0.3s ease;
  user-select: none;
}

#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;
  outline: none;
}

/* Список глав */

.chapter-list-dropdown {
  position: absolute;
  top: 3.5rem;
  right: 0;
  background: white;
  max-height: 300px;
  width: 280px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(122, 95, 255, 0.25);
  overflow-y: auto;
  padding: 0.5em 0;
  display: none;
  z-index: 1500;
}

.chapter-list-dropdown.open {
  display: block;
}

.chapter-list-dropdown button {
  background: none;
  border: none;
  width: 100%;
  padding: 0.6em 1.4em;
  text-align: left;
  font-family: 'Alegreya', serif;
  font-size: 1em;
  color: #5e3a9d;
  cursor: pointer;
  transition: background-color 0.2s ease;
  user-select: text;
}

.chapter-list-dropdown button:hover,
.chapter-list-dropdown button:focus-visible {
  background-color: #7a5fff22;
  outline: none;
}

/* Тёмная тема */

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 #text-input {
  background: #231f33;
  border-color: #01cfff;
  color: #e5e3f7;
  box-shadow: inset 0 1px 5px rgba(0, 0, 0, 0.3);
}

body.theme-dark #text-input:focus {
  border-color: #0099cc;
  box-shadow: inset 0 1px 5px rgba(0, 0, 0, 0.3), 0 0 0 3px rgba(1, 207, 255, 0.4);
}

body.theme-dark #load-text-btn {
  background: #01cfff;
  border-color: #0099cc;
  color: #1a1a2e;
  box-shadow: 0 4px 15px rgba(1, 207, 255, 0.3);
}

body.theme-dark #load-text-btn:hover {
  background: #0099cc;
  border-color: #0077aa;
  box-shadow: 0 6px 20px rgba(0, 153, 204, 0.4);
}

/* Высокая контрастность */

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 #text-input {
  background: #fff !important;
  color: #000 !important;
  border: 2px solid #000 !important;
  box-shadow: none !important;
  font-family: 'Arial Rounded MT Bold', 'Arial', 'Verdana', 'Tahoma', sans-serif !important;
}

body.theme-accessible #text-input:focus {
  border-color: #000 !important;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.3) !important;
}

body.theme-accessible #load-text-btn {
  background: #000 !important;
  color: #fff !important;
  border: 2px solid #000 !important;
  box-shadow: none !important;
  font-family: 'Arial Rounded MT Bold', 'Arial', 'Verdana', 'Tahoma', sans-serif !important;
}

body.theme-accessible #load-text-btn:hover {
  background: #333 !important;
  border-color: #000 !important;
  box-shadow: none !important;
}

/* Адаптив */
@media (max-width: 1024px) {
  #reader-container {
    margin-left: 0;
    flex-direction: column;
  }

  #bookContent,
  #right-panel {
    width: 100% !important;
    height: 50vh !important;
    max-height: none !important;
  }

  #theme-switcher {
    position: static;
    width: 100%;
    flex-direction: row;
    justify-content: center;
    margin: 1rem auto;
    border-radius: 0;
    box-shadow: none;
    background: none;
    padding: 0.5rem 0;
  }

  #reader-controls {
    width: 100%;
    margin-top: 0.5rem;
    padding: 0 1rem;
    flex-wrap: wrap;
    gap: 0.6rem;
    overflow-x: auto;
  }
}

@media (max-width: 480px) {
  #text-input {
    height: 100px;
  }
}

/* Анимация */
@keyframes rune-glow {
  from {
    text-shadow: 0 0 6px #b6aeea, 0 2px 8px #7a5fff44;
    color: #a085ff;
  }
  to {
    text-shadow: 0 0 16px #ffd700, 0 2px 8px #7a5fff99;
    color: #ffd700;
  }
}

/* --- Заголовки глав и частей --- */
.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;
}
@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; }
}
.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);
}

/* --- Тёмная тема для текста --- */
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 .monologue {
  background: linear-gradient(90deg, #231f33 70%, #2e2850 100%);
  color: #c2b1ff;
  border-left-color: #01cfff;
  box-shadow: 0 2px 16px #01cfff22;
}
body.theme-dark .monologue:before {
  color: #01cfff;
  opacity: 0.45;
}
body.theme-dark .monologue-thinker,
body.theme-dark .monologue-author {
  color: #01cfff;
}
body.theme-dark h2,
body.theme-dark .chapter,
body.theme-dark .part,
body.theme-dark .prologue {
  color: #01cfff;
  text-shadow: 0 2px 12px #23203a;
  border-bottom: 2px dashed #01cfff44;
}
body.theme-dark .speech {
  color: #01cfff;
}
body.theme-dark p {
  color: #e5e3f7;
}


.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;
}
