/* Корневые CSS переменные для тем */
:root {
  /* Светлая тема (по умолчанию) */
  --bg-gradient-start: #e5e0f9;
  --bg-gradient-end: #b6aeea;
  --text-color: #2d1d3a;
  --accent-color: #7a5fff;
  --accent-color-light: #b6aeea;
  --button-bg: #e1d4f2;
  --button-color: #4d2e8c;
  --button-bg-active: #7a5fff;
  --button-color-active: #fff;
  --shadow-color: #7a5fff22;
  --link-color: #5e3a9d;
  --link-hover-color: #ffd700;
  --border-color: #7a5fff;
  --monologue-bg: linear-gradient(90deg, #f3f0fa 70%, #e1d4f2 100%);
  --monologue-border-left: #a085ff;
  --monologue-color: #563a7d;
  --monologue-shadow: #7a5fff22;
}

/* Тёмная тема */
body.theme-dark {
  background: radial-gradient(ellipse at top, #1e1930 0%, #2a2443 100%);
  color: #e5e3f7;
}

body.theme-dark #main-container {
  background: linear-gradient(90deg, #231f33 70%, #2e2850 100%);
  color: #e5e3f7;
  box-shadow: 0 8px 48px #00000088;
  border-color: #01cfff;
  transition: background 0.4s ease, color 0.4s ease;
}

body.theme-dark #main-container p,
body.theme-dark #main-container h2,
body.theme-dark #main-container a {
  color: #e5e3f7;
}

body.theme-dark #main-container a:hover {
  color: #01cfff;
}

/* Высокая контрастность */
body.theme-accessible {
  background: #fff !important;
  color: #000 !important;
  font-family: 'Arial Rounded MT Bold', 'Arial', 'Verdana', 'Tahoma', sans-serif !important;
  letter-spacing: 0.03em;
  line-height: 1.8;
}

/* Общие стили */
body {
  background: radial-gradient(ellipse at top, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
  min-height: 100vh;
  margin: 0;
  font-family: 'Alegreya', 'Georgia', serif;
  color: var(--text-color);
  font-size: 1.22em;
  line-height: 1.9;
  letter-spacing: 0.01em;
  transition: background 0.4s ease, color 0.4s ease;
  overflow-x: hidden;
}

/* Переключатель тем и кнопка "назад" */
#theme-switcher {
  position: fixed;
  top: 32px;
  left: 32px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 0.7em;
  background: rgba(255,255,255,0.82);
  border-radius: 14px;
  box-shadow: 0 2px 12px var(--shadow-color);
  padding: 0.7em 0.8em;
  align-items: stretch;
  font-family: 'Montserrat', 'Arial', sans-serif;
  width: 180px;
}

#theme-switcher button,
#theme-switcher [data-back-button] {
  padding: 0.6em 1.2em;
  font-size: 1em;
  border-radius: 7px;
  background: var(--button-bg);
  color: var(--button-color);
  border: 1.5px solid var(--accent-color);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  text-align: left;
}

#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: var(--button-bg-active);
  color: var(--button-color-active);
}

body.theme-dark #theme-switcher {
  background: rgba(46, 40, 80, 0.9);
  border-radius: 14px;
  box-shadow: 0 2px 12px #01cfff55;
}

body.theme-dark #theme-switcher button,
body.theme-dark #theme-switcher [data-back-button] {
  background: #2e2850;
  color: #01cfff;
  border-color: #01cfff;
}

body.theme-accessible #theme-switcher {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 2px 12px #00000033;
}

body.theme-accessible #theme-switcher button,
body.theme-accessible #theme-switcher [data-back-button] {
  background: #fff;
  color: #000;
  border-color: #000;
}

/* Навигация дерево справа */
#nav-panel-floating {
  position: fixed;
  top: 32px;
  right: 32px;
  max-width: 280px;
  max-height: 80vh;
  overflow-y: auto;
  background: rgba(255,255,255,0.85);
  border-radius: 12px;
  box-shadow: 0 2px 12px var(--shadow-color);
  padding: 10px 16px;
  font-family: 'Montserrat', 'Arial', sans-serif;
  color: var(--link-color);
  z-index: 1050;
}

body.theme-dark #nav-panel-floating {
  background: rgba(35, 32, 58, 0.9);
  box-shadow: 0 2px 12px #01cfff88;
  color: #a0cfff;
}

body.theme-accessible #nav-panel-floating {
  background: #fff;
  color: #000;
}

.nav-tree,
.nav-subtree {
  list-style: none;
  margin: 0;
  padding-left: 0;
}

.nav-subtree {
  padding-left: 1.2em;
  margin-top: 0.4em;
  border-left: 2px solid var(--border-color);
}

.nav-toggle {
  background: var(--accent-color);
  color: white;
  border: none;
  border-radius: 9px;
  width: 100%;
  text-align: left;
  font-weight: bold;
  font-size: 1.1em;
  padding: 0.4em 1em;
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: background-color 0.3s ease;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}

.nav-toggle:hover {
  background: #5e3a9d;
}

.nav-toggle:focus-visible {
  outline: 3px solid var(--accent-color-light);
  outline-offset: 2px;
}

.nav-toggle::after {
  content: '+';
  font-weight: bold;
  font-size: 1.3em;
  line-height: 1;
  transition: transform 0.3s ease;
  color: #dcd6fc;
}

.nav-toggle[aria-expanded="true"]::after {
  content: '−';
  color: #fff;
}

body.theme-dark .nav-toggle {
  background: linear-gradient(90deg, var(--accent-color), #004466 80%);
  color: white;
}

body.theme-dark .nav-toggle:hover {
  background: #0099cc;
}

body.theme-accessible .nav-toggle {
  background: #000;
  color: #fff;
}

.nav-subtree a {
  display: block;
  padding: 0.35em 1em;
  color: var(--link-color);
  text-decoration: none;
  font-size: 1em;
  border-radius: 7px;
  transition: background-color 0.25s, color 0.25s;
  user-select: text;
}

.nav-subtree a:hover,
.nav-subtree a:focus-visible {
  background: var(--button-bg);
  color: var(--accent-color);
  outline: none;
}

body.theme-dark .nav-subtree a {
  color: #a0cfff;
}

body.theme-dark .nav-subtree a:hover,
body.theme-dark .nav-subtree a:focus-visible {
  color: #01cfff;
}

body.theme-accessible .nav-subtree a {
  color: #000;
}

body.theme-accessible .nav-subtree a:hover,
body.theme-accessible .nav-subtree a:focus-visible {
  background: #000;
  color: #fff;
}

/* Основной контейнер */
#main-container {
  max-width: 860px;
  margin: 48px auto 32px auto;
  background: rgba(255,255,255,0.96);
  border-radius: 28px;
  box-shadow: 0 12px 48px var(--shadow-color), 0 0 0 8px #d1c6f7bb inset;
  padding: 2.9em 2.6em 2.5em 2.6em;
  position: relative;
  min-height: 60vh;
  border: 4px double var(--border-color);
  border-top: none;
  border-bottom: none;
  overflow: hidden;
  z-index: 2;
  color: var(--text-color);
  transition: color 0.4s ease;
}

body.theme-dark #main-container {
  background: linear-gradient(90deg, #231f33 70%, #2e2850 100%);
  box-shadow: 0 8px 48px #00000088, inset 0 0 0 8px #01cfff;
  border-color: #01cfff;
  color: #e5e3f7;
}

/* Магические бордеры сверху и снизу */
#magic-border-top,
#magic-border-bottom {
  width: 100%;
  height: 36px;
  background: url('data:image/svg+xml;utf8,<svg width="400" height="36" xmlns="http://www.w3.org/2000/svg"><path d="M0,18 Q40,0 80,18 T160,18 T240,18 T320,18 T400,18" fill="none" stroke="%237a5fff" stroke-width="2"/><text x="20" y="28" font-size="24" fill="%239c7be6" font-family="serif">&#x16B1;&#x16B7;&#x16B9;&#x16B1;</text><text x="340" y="28" font-size="24" fill="%239c7be6" font-family="serif">&#x16B1;&#x16B7;&#x16B9;&#x16B1;</text></svg>') repeat-x center;
  opacity: 0.27;
  pointer-events: none;
  position: absolute;
  left: 0;
  z-index: 1;
}
#magic-border-top {
  top: 0;
}
#magic-border-bottom {
  bottom: 0;
}

/* Заголовок сайта */
#site-title {
  text-align: center;
  margin-bottom: 1.1em;
  position: relative;
  z-index: 3;
}
#site-title h1 {
  font-family: 'UnifrakturCook', 'Alegreya', serif;
  color: var(--accent-color);
  font-size: 2.7em;
  letter-spacing: 0.09em;
  margin: 0.1em 0 0.15em 0;
  text-shadow: 0 2px 14px var(--accent-color-light), 0 0 2px #fff;
  line-height: 1.1;
  position: relative;
}
#site-title h1:before,
#site-title h1:after {
  content: 'ᚠᛇᚻ';
  font-family: 'UnifrakturCook', serif;
  font-size: 0.7em;
  color: var(--accent-color);
  opacity: 0.7;
  margin: 0 0.3em;
  vertical-align: middle;
  letter-spacing: 0.08em;
  text-shadow: 0 2px 8px var(--accent-color-light);
  animation: rune-glow 3s infinite alternate;
}
#site-title h1:before {
  margin-right: 0.5em;
}
#site-title h1:after {
  margin-left: 0.5em;
  animation-delay: 1.5s;
}
@keyframes rune-glow {
  from {
    text-shadow: 0 0 6px var(--accent-color-light), 0 2px 8px var(--shadow-color);
    color: var(--accent-color);
  }
  to {
    text-shadow: 0 0 16px #ffd700, 0 2px 8px #7a5fff99;
    color: #ffd700;
  }
}

#site-title p {
  font-family: 'Alegreya', serif;
  font-size: 1.2em;
  color: var(--accent-color);
  margin-top: -0.5em;
  letter-spacing: 0.05em;
  user-select: none;
}

/* Welcome section */
.welcome-section {
  max-width: 700px;
  margin: 2em auto 3em auto;
  padding: 1.5em 2em;
  background: var(--monologue-bg);
  border-radius: 18px;
  box-shadow: 0 8px 28px rgba(122, 95, 255, 0.15);
  font-family: 'Alegreya', serif;
  color: var(--monologue-color);
  text-align: center;
  letter-spacing: 0.01em;
  transition: background 0.4s ease, color 0.4s ease;
  user-select: text;
}

body.theme-dark .welcome-section {
  background: linear-gradient(135deg, #231f33 70%, #2e2850);
  color: #c2b1ff;
  box-shadow: 0 8px 28px rgba(1, 207, 255, 0.25);
}

.welcome-section h2 {
  font-family: 'UnifrakturCook', 'Alegreya', serif;
  font-size: 2.2em;
  margin-bottom: 0.6em;
  color: #5e3a9d;
  text-shadow: 0 2px 12px #b6aeea66;
  user-select: text;
}

body.theme-dark .welcome-section h2 {
  color: #01cfff;
  text-shadow: 0 2px 12px #23203a;
}

.inspiration-quote {
  font-style: italic;
  font-weight: 500;
  color: var(--accent-color);
  font-size: 1.5em;
  margin: 1em 0 1.8em 0;
  border-left: 6px solid var(--monologue-border-left);
  padding-left: 1.1em;
  box-shadow: 0 0 12px var(--monologue-shadow);
  user-select: none;
}

body.theme-dark .inspiration-quote {
  color: var(--color-accent-dark);
  border-left-color: var(--color-accent-dark);
  box-shadow: 0 0 14px #01cfff55;
}

.note-text {
  font-size: 1.1em;
  margin-top: 1em;
  font-style: oblique;
  color: var(--link-color);
  user-select: text;
}

body.theme-dark .note-text {
  color: #60c8ff;
}

/* Адаптив */

@media(max-width: 900px) {
  #nav-panel-floating {
    position: static;
    max-width: 100%;
    max-height: none;
    overflow: visible;
    padding: 8px 12px;
    margin-bottom: 1em;
  }
  .nav-toggle {
    font-size: 1em;
  }
  .nav-subtree a {
    font-size: 0.95em;
  }
  #main-container {
    margin: 30px auto;
    padding: 2em 1.5em;
  }
  #site-title h1 {
    font-size: 2.2em;
  }
}

@media(max-width: 640px) {
  body {
    font-size: 1em;
  }
  #main-container {
    max-width: 95%;
    margin: 15px auto;
    padding: 1.5em 1em;
    border-radius: 15px;
  }
  #site-title h1 {
    font-size: 1.8em;
  }
  #site-title h1:before,
  #site-title h1:after {
    display: none;
  }
  #theme-switcher button {
    padding: 0.4em 0.8em;
    font-size: 0.9em;
  }
}

@media (max-width: 400px) {
  #theme-switcher,
  #nav-panel-floating {
    flex-wrap: wrap;
  }
  #site-title h1 {
    font-size: 1.5em;
  }
}
