@import url('https://fonts.googleapis.com/css2?family=Alegreya&family=Montserrat&family=UnifrakturCook&display=swap');

:root {
  --color-bg-light-start: #f3f0fa;
  --color-bg-light-end: #e1d4f2;
  --color-text-light: #563a7d;
  --color-accent-light: #7a5fff;

  --color-bg-dark-start: #231f33;
  --color-bg-dark-end: #2e2850;
  --color-text-dark: #c2b1ff;
  --color-accent-dark: #01cfff;

  --color-bg-contrast: #fff;
  --color-text-contrast: #000;
  --color-accent-contrast: #000;
}

/* Общие стили body */

body {
  font-family: 'Alegreya', serif;
  margin: 0;
  padding: 0;
  background: linear-gradient(135deg, var(--color-bg-light-start), var(--color-bg-light-end));
  color: var(--color-text-light);
  transition: background 0.4s ease, color 0.4s ease;
  line-height: 1.5;
}

body.theme-dark {
  background: linear-gradient(135deg, var(--color-bg-dark-start), var(--color-bg-dark-end));
  color: var(--color-text-dark);
}

body.theme-contrast {
  background: var(--color-bg-contrast);
  color: var(--color-text-contrast);
}

/* Панель переключения тем и кнопка Назад */

#theme-switcher {
  position: fixed;
  top: 1rem;
  left: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6em;
  width: 160px;
  font-family: 'Montserrat', sans-serif;
  user-select: none;
  z-index: 1000;
}

#theme-switcher button,
#theme-switcher [data-back-button] {
  background: var(--color-bg-light-end);
  border: 2px solid var(--color-accent-light);
  border-radius: 12px;
  padding: 0.5em 1em;
  font-weight: 700;
  cursor: pointer;
  color: var(--color-accent-light);
  transition: background 0.3s, color 0.3s;
  width: 100%;
  box-sizing: border-box;
  text-align: center;
  user-select: none;
  outline-offset: 2px;
}

body.theme-dark #theme-switcher button,
body.theme-dark #theme-switcher [data-back-button] {
  background: var(--color-bg-dark-end);
  border-color: var(--color-accent-dark);
  color: var(--color-accent-dark);
}

body.theme-contrast #theme-switcher button,
body.theme-contrast #theme-switcher [data-back-button] {
  background: var(--color-bg-contrast);
  border-color: var(--color-accent-contrast);
  color: var(--color-accent-contrast);
}

#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(--color-accent-light);
  color: white;
  outline: none;
}

body.theme-dark #theme-switcher button.active,
body.theme-dark #theme-switcher button:hover,
body.theme-dark #theme-switcher [data-back-button]:hover,
body.theme-dark #theme-switcher [data-back-button]:focus-visible {
  background: var(--color-accent-dark);
  color: var(--color-bg-dark-start);
}

body.theme-contrast #theme-switcher button.active,
body.theme-contrast #theme-switcher button:hover,
body.theme-contrast #theme-switcher [data-back-button]:hover,
body.theme-contrast #theme-switcher [data-back-button]:focus-visible {
  background: var(--color-accent-contrast);
  color: var(--color-bg-contrast);
}

/* Заголовок */

#site-title {
  text-align: center;
  margin: 2rem 0 1rem;
  font-family: 'UnifrakturCook', 'Alegreya', serif;
  color: var(--color-accent-light);
  transition: color 0.4s ease;
  user-select: none;
}

body.theme-dark #site-title {
  color: var(--color-accent-dark);
}

body.theme-contrast #site-title {
  color: var(--color-accent-contrast);
}

#site-title h1 {
  font-size: 3rem;
  margin: 0;
  text-shadow: 0 2px 14px #b6aeea66;
}

#site-title p {
  font-size: 1.2rem;
  margin-top: 0.3rem;
}

/* Основной контент */

.character-main {
  max-width: 900px;
  margin: 0 auto 3rem;
  padding: 2rem 2rem 3rem;
  background: linear-gradient(135deg, var(--color-bg-light-start), var(--color-bg-light-end));
  border-radius: 28px;
  box-shadow: 0 12px 40px #7a5fff33;
  transition: background 0.4s ease, color 0.4s ease;
}

body.theme-dark .character-main {
  background: linear-gradient(135deg, var(--color-bg-dark-start), var(--color-bg-dark-end));
  color: var(--color-text-dark);
}

body.theme-contrast .character-main {
  background: var(--color-bg-contrast);
  color: var(--color-text-contrast);
}

/* Аккордеон - группы персонажей */

.character-accordion,
.group-list {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.group {
  margin-bottom: 1.8rem;
}

.group-toggle {
  width: 100%;
  background: linear-gradient(90deg, var(--color-accent-light) 70%, #b6aeea 100%);
  color: white;
  font-weight: bold;
  font-size: 1.3rem;
  border: none;
  border-radius: 14px;
  padding: 0.75rem 1.2rem;
  text-align: left;
  cursor: pointer;
  position: relative;
  box-shadow: 0 3px 18px #7a5fff44;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

.group-toggle:hover,
.group-toggle:focus-visible {
  background: linear-gradient(90deg, #5e3a9d 70%, var(--color-accent-light) 100%);
  box-shadow: 0 6px 20px #7a5fff55;
  outline: none;
}

.group-toggle::after {
  content: '+';
  font-weight: bold;
  font-size: 1.6rem;
  color: rgba(255, 255, 255, 0.8);
  transition: transform 0.3s ease;
}

.group-toggle[aria-expanded="true"]::after {
  content: '−';
  transform: rotate(180deg);
}

body.theme-dark .group-toggle {
  background: linear-gradient(90deg, var(--color-accent-dark) 60%, #004466 100%);
  color: #231f33;
}

body.theme-dark .group-toggle:hover,
body.theme-dark .group-toggle:focus-visible {
  background: linear-gradient(90deg, #0099cc 60%, var(--color-accent-dark) 100%);
  box-shadow: 0 6px 20px #01cfff55;
}

/* Список персонажей внутри группы */

.group-list {
  border-left: 4px double #b6aeea77;
  margin-top: 0.6rem;
  padding-left: 1.5rem;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease;
}

.group-list[hidden] {
  max-height: 0 !important;
}

.group-list:not([hidden]) {
  max-height: 500px; /* Достаточно места для показа */
  transition: max-height 0.5s ease;
}

/* Карточка персонажа */

.character-card {
  display: flex;
  gap: 1rem;
  background: white;
  border-radius: 14px;
  padding: 0.8rem 1.2rem;
  box-shadow: 0 4px 16px #7a5fff22;
  margin-bottom: 1rem;
  user-select: none;
  color: #4d2e8c;
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

.character-card:hover,
.character-card:focus-within {
  background: #f3f0fa;
  box-shadow: 0 8px 20px #7a5fff44;
  outline: none;
}

body.theme-dark .character-card {
  background: #2e2850;
  color: #c2b1ff;
}

body.theme-dark .character-card:hover,
body.theme-dark .character-card:focus-within {
  background: #3a3453;
  box-shadow: 0 8px 20px #01cfff55;
}

/* Аватар персонажа */

.avatar {
  flex-shrink: 0;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  font-size: 1.7rem;
  font-weight: 900;
  display: flex;
  justify-content: center;
  align-items: center;
  color: white;
  box-shadow: 0 3px 10px #7a5fff33;
  user-select: none;
  user-drag: none;
}

.avatar.hero {
  background-color: #7aeca9;
}

.avatar.villain {
  background-color: #d84134;
}

.avatar.ally {
  background-color: #7abaff;
}

body.theme-dark .avatar.hero {
  background-color: #01cfa7;
  color: #231f33;
}

body.theme-dark .avatar.villain {
  background-color: #d93025;
}

body.theme-dark .avatar.ally {
  background-color: #0099cc;
}

/* Заголовки и описания в карточках */

.character-card h3 {
  margin: 0 0 0.2rem 0;
  font-family: 'UnifrakturCook', 'Alegreya', serif;
}

.character-card p {
  margin: 0;
  font-family: 'Alegreya', serif;
  font-size: 1rem;
  line-height: 1.4;
}

/* Адаптив */

@media (max-width: 600px) {
  #site-title h1 {
    font-size: 2.2rem;
  }

  .group-toggle {
    font-size: 1.1rem;
  }

  .character-card {
    flex-direction: column;
    align-items: flex-start;
  }

  .avatar {
    margin-bottom: 0.4rem;
  }
}
