/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* Font scaling */
  --book-font-scale: 100%;
  
  /* Light theme colors */
  --bg-color: #ffffff;
  --text-color: #333;
  --primary-color: #007cba;
  --primary-dark: #005577;
  --secondary-bg: #f8f9fa;
  --border-color: #e9ecef;
  --card-bg: #ffffff;
  --card-shadow: rgba(0, 124, 186, 0.1);
  --card-shadow-hover: rgba(0, 124, 186, 0.15);
}

[data-theme="dark"] {
  /* Dark theme colors */
  --bg-color: #1a1a1a;
  --text-color: #e0e0e0;
  --primary-color: #4da6d9;
  --primary-dark: #3a8bc2;
  --secondary-bg: #2d2d2d;
  --border-color: #404040;
  --card-bg: #2d2d2d;
  --card-shadow: rgba(0, 0, 0, 0.3);
  --card-shadow-hover: rgba(0, 0, 0, 0.4);
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  line-height: 1.6;
  color: var(--text-color);
  background-color: var(--bg-color);
  font-size: calc(1rem * var(--book-font-scale));
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Header */
.site-header {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
  color: white;
  position: relative;
  z-index: 1000;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0;
}

.site-title {
  font-size: calc(1.5rem * var(--book-font-scale));
  font-weight: 600;
  color: white;
  text-decoration: none;
}

.site-title:hover {
  color: white;
  text-decoration: none;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.control-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  padding: 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: calc(0.9rem * var(--book-font-scale));
  font-weight: 500;
  transition: background-color 0.3s ease;
  min-width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.control-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.control-btn:focus {
  outline: 2px solid white;
  outline-offset: 2px;
}

/* Mobile Navigation */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: white;
  cursor: pointer;
  padding: 0.5rem;
}

.site-nav {
  background-color: rgba(0, 85, 119, 0.95);
}

.nav-menu {
  display: flex;
  justify-content: center;
  align-items: center;
  list-style: none;
  padding: 0.5rem 0;
}

.nav-menu li {
  margin: 0 0.5rem;
}

.nav-menu a {
  color: white;
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  transition: background-color 0.3s ease;
  display: block;
  font-size: calc(1rem * var(--book-font-scale));
}

.nav-menu a:hover {
  background-color: rgba(255, 255, 255, 0.2);
  color: white;
  text-decoration: none;
}

/* Main content */
.main-content {
  min-height: calc(100vh - 200px);
  padding: 2rem 0;
}

/* Hero section */
.hero {
  text-align: center;
  margin-bottom: 3rem;
}

.hero h1 {
  font-size: calc(2.5rem * var(--book-font-scale));
  color: var(--primary-color);
  margin-bottom: 1rem;
  font-weight: 700;
}

.hero .subtitle {
  font-size: calc(1.2rem * var(--book-font-scale));
  color: var(--text-color);
  opacity: 0.8;
  margin-bottom: 1.5rem;
}

.hero .description {
  font-size: calc(1.1rem * var(--book-font-scale));
  line-height: 1.7;
  max-width: 800px;
  margin: 0 auto 2rem;
  color: var(--text-color);
  opacity: 0.9;
}

.hero-image {
  max-width: 300px;
  margin: 2rem auto;
  display: block;
}

/* Book sections */
.book-sections {
  margin-top: 3rem;
}

.book-sections h2 {
  text-align: center;
  font-size: calc(2rem * var(--book-font-scale));
  color: var(--primary-color);
  margin-bottom: 2rem;
}

.sections-grid {
  display: grid;
  gap: 2rem;
  margin-top: 2rem;
}

.section-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 2px 10px var(--card-shadow);
  transition: all 0.3s ease;
}

.section-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 20px var(--card-shadow-hover);
}

.section-header {
  display: flex;
  align-items: center;
  margin-bottom: 1rem;
}

.section-number {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: calc(1.2rem * var(--book-font-scale));
  margin-right: 1rem;
  flex-shrink: 0;
}

.section-title {
  font-size: calc(1.3rem * var(--book-font-scale));
  color: var(--primary-color);
  margin: 0;
  font-weight: 600;
}

.section-description {
  color: var(--text-color);
  opacity: 0.8;
  margin-bottom: 1.5rem;
  font-style: italic;
}

.chapter-list {
  list-style: none;
}

.chapter-list li {
  margin-bottom: 0.5rem;
}

.chapter-list a {
  color: var(--text-color);
  text-decoration: none;
  padding: 0.3rem 0;
  display: block;
  transition: color 0.2s ease;
  font-size: calc(0.95rem * var(--book-font-scale));
}

.chapter-list a:hover {
  color: var(--primary-color);
  text-decoration: none;
}

.chapter-list a.last-read {
  background: linear-gradient(90deg, var(--primary-color), transparent);
  background-size: 4px 100%;
  background-repeat: no-repeat;
  background-position: left;
  padding-left: 1rem;
  font-weight: 500;
  color: var(--primary-color);
}

/* About section */
.about-section {
  background: linear-gradient(135deg, var(--secondary-bg) 0%, var(--border-color) 100%);
  padding: 3rem 0;
  margin-top: 4rem;
  border-radius: 12px;
}

.about-section h2 {
  text-align: center;
  color: var(--primary-color);
  margin-bottom: 2rem;
}

.about-content {
  text-align: center;
  max-width: 600px;
  margin: 0 auto;
}

.about-content p {
  margin-bottom: 1rem;
  color: var(--text-color);
  opacity: 0.9;
}

/* Continue Reading Section */
.continue-reading {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: white;
  padding: 2rem;
  border-radius: 12px;
  text-align: center;
  margin: 2rem 0;
  box-shadow: 0 4px 20px var(--card-shadow);
}

.continue-reading h3 {
  color: white;
  margin-bottom: 1rem;
  font-size: calc(1.3rem * var(--book-font-scale));
}

.continue-btn {
  display: inline-block;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 500;
  transition: background-color 0.3s ease;
  font-size: calc(1rem * var(--book-font-scale));
}

.continue-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  color: white;
  text-decoration: none;
}

/* Footer */
.site-footer {
  background: linear-gradient(135deg, var(--secondary-bg) 0%, var(--border-color) 100%);
  border-top: 1px solid var(--border-color);
  padding: 2rem 0;
  margin-top: 3rem;
  text-align: center;
  color: var(--text-color);
  opacity: 0.8;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  color: var(--primary-color);
  font-weight: 600;
  line-height: 1.3;
}

a {
  color: var(--primary-color);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--primary-dark);
  text-decoration: underline;
}

img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

/* Responsive Design - Mobile First */

/* Mobile styles (default) */
@media (max-width: 768px) {
  .nav-toggle {
    display: block;
  }
  
  .header-controls {
    gap: 0.25rem;
  }
  
  .control-btn {
    min-width: 2rem;
    height: 2rem;
    font-size: calc(0.8rem * var(--book-font-scale));
  }
  
  .site-nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--primary-dark);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transform: translateY(-100%);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
  }
  
  .site-nav.active {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
  }
  
  .nav-menu {
    flex-direction: column;
    padding: 1rem 0;
  }
  
  .nav-menu li {
    margin: 0;
    width: 100%;
  }
  
  .nav-menu a {
    padding: 1rem;
    border-radius: 0;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  .hero h1 {
    font-size: calc(2rem * var(--book-font-scale));
  }
  
  .hero .subtitle {
    font-size: calc(1.1rem * var(--book-font-scale));
  }
  
  .container {
    padding: 0 1rem;
  }
  
  .main-content {
    padding: 1rem 0;
  }
  
  .sections-grid {
    gap: 1.5rem;
  }
  
  .section-card {
    padding: 1rem;
  }
  
  .section-header {
    flex-direction: column;
    text-align: center;
    margin-bottom: 1rem;
  }
  
  .section-number {
    margin-right: 0;
    margin-bottom: 0.5rem;
  }
  
  .about-section {
    padding: 2rem 0;
  }
  
  .continue-reading {
    padding: 1.5rem;
    margin: 1.5rem 0;
  }
  
  .hero-image {
    max-width: 250px;
  }
}

/* Tablet styles */
@media (min-width: 769px) and (max-width: 1024px) {
  .sections-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
  
  .hero h1 {
    font-size: calc(2.2rem * var(--book-font-scale));
  }
  
  .header-controls {
    gap: 0.4rem;
  }
}

/* Desktop styles */
@media (min-width: 1025px) {
  .sections-grid {
    grid-template-columns: 1fr;
    gap: 2rem;
  }
  
  .hero h1 {
    font-size: calc(2.5rem * var(--book-font-scale));
  }
  
  .section-header {
    flex-direction: row;
  }
}

/* Focus styles for accessibility */
.nav-toggle:focus,
.nav-menu a:focus {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

/* Print styles */
@media print {
  .site-header,
  .site-nav,
  .site-footer {
    display: none;
  }
  
  .main-content {
    min-height: auto;
  }
}

/* Continue reading section */
.continue-reading {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: white;
  padding: 2rem;
  margin: 2rem 0;
  border-radius: 12px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0, 124, 186, 0.2);
}

.continue-reading h3 {
  margin: 0 0 1rem 0;
  font-size: calc(1.3rem * var(--book-font-scale));
  font-weight: 600;
}

.continue-part {
  margin: 0 0 1rem 0;
  opacity: 0.9;
  font-size: calc(1rem * var(--book-font-scale));
  font-style: italic;
}

.continue-btn {
  display: inline-block;
  background: rgba(255, 255, 255, 0.2);
  color: white !important;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  text-decoration: none !important;
  font-weight: 500;
  font-size: calc(1.1rem * var(--book-font-scale));
  transition: all 0.3s ease;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.continue-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.5);
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* Last read indicator */
.last-read {
  background: linear-gradient(90deg, rgba(0, 124, 186, 0.1), transparent);
  border-left: 4px solid var(--primary-color);
  padding-left: 1rem !important;
  position: relative;
}

.last-read::before {
  content: "📖 Последняя прочитанная";
  position: absolute;
  top: -1.5rem;
  left: 0;
  font-size: calc(0.8rem * var(--book-font-scale));
  color: var(--primary-color);
  font-weight: 500;
  opacity: 0.8;
}

/* Section title links */
.section-title-link {
  color: inherit;
  text-decoration: none;
  transition: color 0.2s ease;
}

.section-title-link:hover {
  color: var(--primary-color);
  text-decoration: none;
}

.section-card:hover .section-title-link {
  color: var(--primary-color);
}