:root {
  --primary-font: 'Lora', serif;
  --heading-font: 'Playfair Display', serif;
  --bg-color: #fdfcf8;
  /* Slightly warmer off-white */
  --text-color: #2c2c2c;
  /* Softer black */
  --accent-color: #a68b6a;
  /* Muted gold/bronze */
  --accent-light: #e6dfd5;
  --link-color: #8b7355;
  --link-hover-color: #5e4b35;
  --sidebar-bg: #f7f5f0;
  --border-color: #e0e0e0;
  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.05);
  --shadow-hover: 0 15px 40px rgba(0, 0, 0, 0.08);
  --radius-lg: 12px;
  --radius-md: 8px;
}

body {
  font-family: var(--primary-font);
  font-size: 19px;
  /* Increased base size */
  line-height: 1.8;
  /* Increased line height */
  color: var(--text-color);
  background-color: var(--bg-color);
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--heading-font);
  font-weight: 700;
  color: #1a1a1a;
  margin-top: 1.5em;
  margin-bottom: 0.6em;
  line-height: 1.3;
}

a {
  color: var(--link-color);
  text-decoration: none;
  transition: all 0.3s ease;
  border-bottom: 1px solid transparent;
}

a:hover {
  color: var(--link-hover-color);
  border-bottom-color: var(--link-hover-color);
}

/* Header */
header {
  padding: 120px 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  z-index: 1;
}

.header-glass-card {
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.05);
  border-radius: var(--radius-lg);
  padding: 50px;
  display: flex;
  align-items: center;
  gap: 50px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.header-glass-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
  border-color: rgba(255, 255, 255, 0.8);
}

.portrait img {
  width: 240px;
  height: 240px;
  object-fit: cover;
  border-radius: var(--radius-lg);
  border: 4px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  transition: transform 0.5s ease;
}

.portrait img:hover {
  transform: scale(1.03) rotate(2deg);
}

.poet-description {
  flex: 1;
  text-align: left;
}

.poet-description h1 {
  font-family: var(--heading-font);
  font-size: 3.8em;
  font-weight: 700;
  margin: 0 0 15px 0;
  color: #1a1a1a;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.header-divider {
  width: 60px;
  height: 3px;
  background-color: var(--accent-color);
  margin: 0 0 20px 0;
  border-radius: 2px;
}

.poet-description p {
  font-family: var(--primary-font);
  font-size: 1.25em;
  color: #4a4a4a;
  line-height: 1.6;
  font-style: italic;
  margin: 0;
}

/* Layout */
.container {
  display: flex;
  max-width: 1300px;
  margin: 0 auto;
  padding: 60px 20px;
  gap: 60px;
}

/* Sidebar (Table of Contents) */
.table-of-contents {
  flex: 1;
  min-width: 300px;
  background-color: #fff;
  padding: 40px;
  border-radius: var(--radius-lg);
  height: fit-content;
  position: sticky;
  top: 40px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--border-color);
}

.table-of-contents h2 {
  margin-top: 0;
  font-size: 1.4em;
  border-bottom: 2px solid var(--accent-color);
  padding-bottom: 15px;
  margin-bottom: 25px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent-color);
}

.table-of-contents ul {
  list-style: none;
  padding: 0;
}

.table-of-contents li {
  margin-bottom: 12px;
}

.toggle-button {
  background: none;
  border: none;
  font-family: var(--heading-font);
  font-size: 1.15em;
  cursor: pointer;
  padding: 8px 0;
  text-align: left;
  width: 100%;
  color: var(--text-color);
  font-weight: 600;
  transition: color 0.2s;
}

.toggle-button:hover {
  color: var(--accent-color);
}

.toggle-button a {
  color: inherit;
  border: none;
}

.table-of-contents ul ul {
  margin-left: 15px;
  margin-top: 8px;
  border-left: 2px solid var(--accent-light);
  padding-left: 15px;
}

.table-of-contents ul ul li {
  font-size: 0.95em;
}

.table-of-contents ul ul li a {
  color: #666;
}

.table-of-contents ul ul li a:hover {
  color: var(--accent-color);
}

.collapsed {
  display: none;
}

/* Main Content */
.content {
  flex: 3;
  background-color: #fff;
  padding: 80px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--border-color);
}

.poem {
  white-space: pre-wrap;
  margin-bottom: 60px;
  padding-bottom: 60px;
  border-bottom: 1px solid var(--border-color);
  position: relative;
}

.poem:last-child {
  border-bottom: none;
}

.prose {
  white-space: normal;
  margin-bottom: 60px;
  padding-bottom: 60px;
  border-bottom: 1px solid var(--border-color);
}

.prose:last-child {
  border-bottom: none;
}

.poem img {
  max-width: 45%;
  float: left;
  margin-right: 40px;
  margin-bottom: 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
}

.poem::after {
  content: "";
  display: table;
  clear: both;
}

/* Video Container */
.video-container {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%;
  /* 16:9 Aspect Ratio */
  height: 0;
  background-color: #000;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
  margin: 20px 0;
  cursor: pointer;
}

.video-container iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.video-cover {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  opacity: 0.8;
  transition: opacity 0.3s;
}

.video-container:hover .video-cover {
  opacity: 0.6;
}

.play-button {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 68px;
  height: 48px;
  background-color: rgba(33, 33, 33, 0.8);
  border-radius: 12px;
  z-index: 1;
  transition: background-color 0.2s;
}

.play-button::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-style: solid;
  border-width: 10px 0 10px 18px;
  border-color: transparent transparent transparent #fff;
}

.video-container:hover .play-button {
  background-color: #f00;
}

/* Footer */
footer {
  text-align: center;
  padding: 40px;
  background-color: #fff;
  color: #888;
  font-size: 0.9em;
  margin-top: 60px;
  border-top: 1px solid var(--border-color);
}

/* Scrollbar for sidebar */
.table-of-contents::-webkit-scrollbar {
  width: 6px;
}

.table-of-contents::-webkit-scrollbar-track {
  background: transparent;
}

.table-of-contents::-webkit-scrollbar-thumb {
  background-color: #d1d1d1;
  border-radius: 3px;
}

/* Search Bar Styles */
.search-container {
  margin-bottom: 30px;
  position: relative;
}

#search-input {
  width: 100%;
  padding: 15px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-family: var(--primary-font);
  font-size: 1rem;
  box-sizing: border-box;
  background-color: #fafafa;
  transition: all 0.3s;
}

#search-input:focus {
  outline: none;
  border-color: var(--accent-color);
  background-color: #fff;
  box-shadow: 0 0 0 3px rgba(166, 139, 106, 0.1);
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  background: white;
  border: 1px solid var(--border-color);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  max-height: 350px;
  overflow-y: auto;
  z-index: 1000;
  display: none;
  box-shadow: var(--shadow-hover);
}

.search-results.active {
  display: block;
}

.search-result-item {
  padding: 15px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  transition: background-color 0.2s;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background-color: #f9f9f9;
}

.search-result-title {
  font-family: var(--heading-font);
  font-weight: 700;
  color: var(--accent-color);
  margin-bottom: 5px;
}

.search-result-preview {
  font-size: 0.9em;
  color: #666;
}

/* Back to Top Button */
#back-to-top {
  display: none;
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 99;
  font-size: 20px;
  border: none;
  outline: none;
  background-color: var(--accent-color);
  color: white;
  cursor: pointer;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  box-shadow: var(--shadow-soft);
  transition: all 0.3s;
  opacity: 0.9;
  display: flex;
  align-items: center;
  justify-content: center;
}

#back-to-top:hover {
  background-color: var(--link-hover-color);
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
  opacity: 1;
}

/* Responsive Design */
@media screen and (max-width: 1024px) {
  .container {
    flex-direction: column;
    padding: 40px 20px;
  }

  .table-of-contents {
    position: static;
    max-height: none;
    width: auto;
    margin-bottom: 40px;
  }

  .content {
    padding: 40px;
  }

  .poem img {
    max-width: 100%;
    float: none;
    margin-right: 0;
  }
}

@media screen and (max-width: 600px) {
  body {
    font-size: 17px;
  }

  .poet-description h1 {
    font-size: 2.8em;
  }

  header {
    padding: 60px 20px;
  }

  .content {
    padding: 25px;
  }

  h1 {
    font-size: 2.2em;
  }


  h2 {
    font-size: 1.8em;
  }

  /* Mobile Navigation Toggle */
  .table-of-contents {
    position: relative;
    padding: 20px;
  }

  #toc-toggle-mobile {
    display: block;
    width: 100%;
    padding: 12px;
    background-color: var(--accent-color);
    color: white;
    text-align: center;
    border: none;
    border-radius: var(--radius-md);
    margin-bottom: 15px;
    cursor: pointer;
    font-family: var(--heading-font);
    font-size: 1.1em;
    font-weight: 600;
  }

  .table-of-contents ul {
    display: none;
  }

  .table-of-contents.expanded ul {
    display: block;
  }
}

@media screen and (min-width: 601px) {
  #toc-toggle-mobile {
    display: none;
  }
}

/* Background Animation */
.background-animation {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  background-size: cover;
  background-position: center;
  opacity: 0;
  pointer-events: none;
  animation: bg-pan 90s ease-in-out infinite alternate, bg-fade 50s infinite;
}

.bg-1 {
  background-image: url('st_petersburg_bg.png');
  animation-delay: 0s;
}

.bg-2 {
  background-image: url('st_petersburg_kanal_griboedov.png');
  animation-delay: 10s;
}

.bg-3 {
  background-image: url('st_petersburg_isaac_cathedral.png');
  animation-delay: 20s;
}

.bg-4 {
  background-image: url('st_petersburg_winter_palace.png');
  animation-delay: 30s;
}

.bg-5 {
  background-image: url('st_petersburg_peter_paul_fortress.png');
  animation-delay: 40s;
}

@keyframes bg-fade {
  0% {
    opacity: 0;
  }

  4% {
    opacity: 0.15;
    /* Fade in over 2s (4% of 50s) */
  }

  20% {
    opacity: 0.15;
    /* Stay visible for 8s (16% of 50s) */
  }

  24% {
    opacity: 0;
    /* Fade out over 2s */
  }

  100% {
    opacity: 0;
  }
}

@keyframes bg-pan {
  0% {
    transform: scale(1.05) translate(0, 0);
  }

  25% {
    transform: scale(1.08) translate(-1%, -1%);
  }

  50% {
    transform: scale(1.1) translate(-2%, 0);
  }

  75% {
    transform: scale(1.08) translate(-1%, 1%);
  }

  100% {
    transform: scale(1.05) translate(0, 0);
  }
}

@media (max-width: 768px) {
  .background-animation {
    animation: none;
    background-attachment: scroll;
    opacity: 0.05;
  }
}