// Variables
$text-color: #2c3e50;
$text-light: #666;
$primary-color: #3498db;

// Shared Content Variables
$content-max-width: 800px;
$content-padding: 20px;
$content-line-height: 1.5;
$content-font-size: 18px;

// Mobile breakpoint
$mobile-breakpoint: 768px;

// Shared Paragraph Styles
@mixin paragraph-styles {
  margin: 8px 0;
  text-align: justify;
}

// Shared Content Styles
@mixin shared-content-styles {
  display: flex;
  flex-direction: column;
  margin: 0 10px;
  line-height: $content-line-height;
  color: $text-color;
  font-size: inherit;
  flex: 1;
  padding: $content-padding;
  box-sizing: border-box;
  width: $content-max-width;

  div {
    padding: 0;
    margin: 0;
  }
  
  p {
    @include paragraph-styles;
  }

  section {
    position: relative;
  }

  .aligncenter {
    justify-self: center;
  }

  .book-cover {
    text-align: center;
    max-width: 100%;
    height: auto;
    width: 100%;
    margin: auto;
  }

  h1 {
    text-align: center;
  }
  
  h2 {
    text-align: center;
  }
  
  .book-title {
    font-size: 3rem;
    font-weight: 700;
    margin: auto;
    padding: 0 18px;
    color: inherit;
  }
  
  .book-subtitle {
    font-size: 2rem;
    font-weight: 300;
    margin: auto;
    padding: 0 18px;
    color: inherit;
    font-style: italic;
  }
  
  .book-author {
    font-size: 3rem;
    text-align: center;
    margin: auto;
    padding: 0 18px;
    color: inherit;
  }

  .book-copyright-page {
    margin: auto;
  }
  
  .book-dedication {
    margin: auto;
  }

  .book-toc-list {
    text-align: center;
    list-style-type: none;
    padding: 0;
    margin: 0;
    
    li {
      margin-bottom: 18px;
    }
  }

  .book-chapter-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 18px;
    padding: 0 18px;
    color: inherit;
  }

  // Ensure images are loaded and measured
  img {
    max-width: 100%;
  }

  // Ensure figures are measured correctly
  figure {
    margin: 1em 0;
    max-height: 70vh;
    
    img {
      padding: 0;
      max-width: 100%;
      max-height: 100%;
    }
  }

  // Mobile styles
  @media (max-width: $mobile-breakpoint) {
    width: 100% !important;
    margin: 0;
    padding: 0;
    
    .book-title {
      font-size: 2rem;
    }
    
    .book-subtitle {
      font-size: 1.5rem;
    }
    
    .book-author {
      font-size: 2rem;
    }
    
    .book-chapter-title {
      font-size: 1.25rem;
      margin-bottom: 8px;
    }
    
    .book-toc-list {
      li {
        margin-bottom: 10px;
      }

      figure {
        max-height: 60vh;
      }
    }
  }
}

// Book Content Specific Styles
.book-content {
  height: calc(var(--content-height) - #{$content-padding * 2});
  @include shared-content-styles;
}

// Measurement container
.book-content-measure {
  min-height: calc(var(--content-height) - #{$content-padding * 2});
  position: absolute;
  top: 20px;
  left: 0;
  visibility: hidden;
  z-index: -1;
  box-sizing: border-box;
  height: fit-content;
  @include shared-content-styles;
}