/* General Styles */
:root {
  --bg-color: #f8f8f8;
  --text-color: #333;
  --header-bg: #fff;
  --sidebar-bg: #f0f0f0;
  --border-color: #ddd;
  --link-color: #007bff;
  --link-hover-color: #0056b3;
  --blockquote-bg: #e9ecef;
  --code-bg: #e9ecef;
  --code-border: #ced4da;
  --table-header-bg: #e2e6ea;
  --table-border: #dee2e6;
  --button-bg: #007bff;
  --button-text: #fff;
  --button-hover-bg: #0056b3;
}

body.dark-mode {
  --bg-color: #282c34;
  --text-color: #e0e0e0;
  --header-bg: #21252b;
  --sidebar-bg: #2c313a;
  --border-color: #444;
  --link-color: #8ab4f8;
  --link-hover-color: #6a9df8;
  --blockquote-bg: #3a3f47;
  --code-bg: #3a3f47;
  --code-border: #555;
  --table-header-bg: #3a3f47;
  --table-border: #444;
  --button-bg: #8ab4f8;
  --button-text: #282c34;
  --button-hover-bg: #6a9df8;
}

body {
  font-family: "Cairo", sans-serif;
  margin: 0;
  padding: 0;
  background-color: var(--bg-color);
  color: var(--text-color);
  line-height: 1.6;
  transition: background-color 0.3s, color 0.3s;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.site-header {
  background-color: var(--header-bg);
  color: var(--text-color);
  padding: 1rem 1.5rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 1000;
  transition: background-color 0.3s, color 0.3s, box-shadow 0.3s;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
}

.book-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 770; /* Cairo Bold */
  flex-grow: 1;
  text-align: center;
}

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

.header-controls button,
.menu-toggle,
.nav-button {
  background-color: var(--button-bg);
  color: var(--button-text);
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background-color 0.3s, color 0.3s;
}

.header-controls button:hover,
.menu-toggle:hover,
.nav-button:hover {
  background-color: var(--button-hover-bg);
}

.menu-toggle {
  display: block; /* Show on all screen sizes */
  background-color: var(--button-bg);
  color: var(--button-text);
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background-color 0.3s, color 0.3s;
}

.menu-toggle:hover,
.nav-button:hover {
  background-color: var(--button-hover-bg);
}

/* Layout */
.sidebar-and-content {
  display: flex;
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  min-height: calc(100vh - 70px); /* Account for header height */
}

/* Sidebar */
.sidebar {
  width: 280px;
  background-color: var(--sidebar-bg);
  padding: 1.5rem;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
  overflow-y: auto;
  position: relative;
  height: calc(100vh - 70px);
  transition: background-color 0.3s, transform 0.3s ease-in-out;
  flex-shrink: 0;
  transform: translateX(-100%); /* Start hidden */
}

.sidebar.active {
  transform: translateX(0%); /* Show when active */
}

.toc h2 {
  margin-top: 0;
  font-size: 1.3rem;
  font-weight: 770;
  color: var(--text-color);
}

.toc ul {
  list-style: none;
  padding: 0;
}

.toc ul li {
  margin-bottom: 0.5rem;
}

.toc ul li a {
  text-decoration: none;
  color: var(--link-color);
  display: block;
  padding: 0.3rem 0;
  transition: color 0.2s;
}

.toc ul li a:hover {
  color: var(--link-hover-color);
}

.toc ul li.active > a {
  font-weight: 770;
  color: var(--link-hover-color);
}

/* Hero Section */
.hero-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  position: relative;
  background: linear-gradient(
    135deg,
    var(--header-bg) 0%,
    var(--sidebar-bg) 100%
  );
  border-radius: 12px;
  margin-bottom: 2rem;
  padding: 2rem;
}

.hero-content {
  max-width: 600px;
}

.hero-title {
  font-size: 3rem;
  font-weight: 770;
  margin-bottom: 1rem;
  color: var(--text-color);
  animation: fadeInUp 1s ease-out;
}

.hero-subtitle {
  font-size: 1.4rem;
  color: var(--text-color);
  opacity: 0.8;
  margin-bottom: 2rem;
  animation: fadeInUp 1s ease-out 0.3s both;
}

.get-started-btn {
  background: linear-gradient(45deg, var(--button-bg), var(--button-hover-bg));
  color: var(--button-text);
  border: none;
  padding: 1rem 2rem;
  font-size: 1.2rem;
  font-weight: 600;
  border-radius: 50px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.3s ease;
  box-shadow: 0 4px 20px rgba(0, 123, 255, 0.3);
  animation: fadeInUp 1s ease-out 0.6s both, pulse 2s infinite 2s;
}

.get-started-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0, 123, 255, 0.4);
}

.btn-arrow {
  font-size: 1.5rem;
  animation: bounce 1.5s infinite;
}

.scroll-indicator {
  position: absolute;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  animation: fadeInUp 1s ease-out 1s both;
}

.scroll-arrow {
  width: 2px;
  height: 30px;
  background: var(--button-bg);
  margin: 0 auto;
  border-radius: 2px;
  position: relative;
  animation: scrollDown 2s infinite;
}

.scroll-arrow::after {
  content: "";
  position: absolute;
  bottom: -5px;
  left: -3px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--button-bg);
  border-bottom: 2px solid var(--button-bg);
  transform: rotate(45deg);
}

/* Animations */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes bounce {
  0%,
  20%,
  50%,
  80%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-5px);
  }
  60% {
    transform: translateY(-3px);
  }
}

@keyframes pulse {
  0% {
    box-shadow: 0 4px 20px rgba(0, 123, 255, 0.3);
  }
  50% {
    box-shadow: 0 4px 25px rgba(0, 123, 255, 0.5);
  }
  100% {
    box-shadow: 0 4px 20px rgba(0, 123, 255, 0.3);
  }
}

@keyframes scrollDown {
  0% {
    transform: translateY(-10px);
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    transform: translateY(10px);
    opacity: 0;
  }
}

/* Main Content Area */
.main-content {
  flex-grow: 1;
  padding: 1rem 2rem;
  width: 100%;
  padding-top: 20px; /* Reduced padding when sidebar hidden */
  transition: all 0.3s ease;
}

.content-area {
  background-color: var(--bg-color);
  padding: 0;
  transition: background-color 0.3s;
  max-width: 800px; /* Max width for readability */
  margin: 0 auto; /* Center content within its container */
}

/* Fix scroll offset for section navigation */
.content-area section {
  scroll-margin-top: 80px; /* Account for header height */
}

.content-area h1,
.content-area h2,
.content-area h3,
.content-area h4,
.content-area h5,
.content-area h6 {
  font-weight: 770; /* Cairo Bold */
  color: var(--text-color);
  margin-top: 2rem;
  margin-bottom: 1rem;
  scroll-margin-top: 80px; /* Account for header height when linking to headings */
}

.content-area h1 {
  font-size: 2.2rem;
  margin-top: 100px; /* Increased to prevent overlap with header */
}
.content-area h2 {
  font-size: 1.8rem;
}
.content-area h3 {
  font-size: 1.5rem;
}
.content-area h4 {
  font-size: 1.2rem;
}

.content-area p {
  margin-bottom: 1rem;
}

.content-area ul,
.content-area ol {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}

.content-area li {
  margin-bottom: 0.5rem;
}

.content-area a {
  color: var(--link-color);
  text-decoration: none;
  transition: color 0.2s;
}

.content-area a:hover {
  color: var(--link-hover-color);
  text-decoration: underline;
}

/* Typography Adjustments */
body {
  font-size: 16px; /* Base font size */
}

.content-area {
  font-size: 1em; /* Relative to body */
}

/* Specific Markdown Element Styling */
blockquote {
  border-left: 4px solid var(--link-color);
  background-color: var(--blockquote-bg);
  margin: 1.5rem 0;
  padding: 1rem 1.5rem;
  color: var(--text-color);
  border-radius: 5px;
  transition: background-color 0.3s;
}

blockquote p {
  margin: 0;
  font-style: italic;
}

code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier,
    monospace;
  background-color: var(--code-bg);
  padding: 0.2em 0.4em;
  border-radius: 3px;
  font-size: 0.9em;
  border: 1px solid var(--code-border);
  transition: background-color 0.3s, border-color 0.3s;
}

pre {
  background-color: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 5px;
  padding: 1rem;
  overflow-x: auto;
  margin: 1.5rem 0;
  transition: background-color 0.3s, border-color 0.3s;
}

pre code {
  background-color: transparent;
  border: none;
  padding: 0;
  font-size: 0.85em;
  line-height: 1.4;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.9em;
}

table th,
table td {
  border: 1px solid var(--table-border);
  padding: 0.8rem;
  text-align: left;
  transition: border-color 0.3s;
}

table th {
  background-color: var(--table-header-bg);
  font-weight: 770;
  transition: background-color 0.3s;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
  border-radius: 5px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Chapter Navigation */
.chapter-navigation {
  display: flex;
  justify-content: space-between;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

.chapter-navigation .nav-button:disabled {
  background-color: var(--border-color);
  cursor: not-allowed;
  color: var(--text-color);
}

/* Responsive Design */
@media (max-width: 992px) {
  .sidebar {
    width: 250px;
    position: fixed;
    left: 0;
    top: 70px; /* Header height */
    height: calc(100vh - 70px);
    z-index: 999;
    transform: translateX(-100%);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
  }

  .sidebar.active {
    transform: translateX(0%);
  }

  .main-content {
    padding: 1rem;
    margin: 0 auto;
    padding-top: 20px;
  }

  .header-content {
    justify-content: flex-start;
    gap: 1rem;
  }

  .book-title {
    text-align: left;
    font-size: 1.3rem;
  }
}

@media (max-width: 768px) {
  .site-header {
    padding: 0.8rem 1rem;
  }

  .book-title {
    font-size: 1.2rem;
  }

  .header-controls button {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
  }

  .main-content {
    padding: 0.8rem;
    padding-top: 20px;
  }

  /* Adjust scroll margin for mobile header height */
  .content-area section,
  .content-area h1,
  .content-area h2,
  .content-area h3,
  .content-area h4,
  .content-area h5,
  .content-area h6 {
    scroll-margin-top: 70px; /* Smaller header on mobile */
  }

  .content-area h1 {
    font-size: 1.8rem;
  }
  .content-area h2 {
    font-size: 1.5rem;
  }
  .content-area h3 {
    font-size: 1.3rem;
  }

  /* Hero section responsive */
  .hero-section {
    min-height: 50vh;
    padding: 1.5rem;
    margin-bottom: 1rem;
  }

  .hero-title {
    font-size: 2rem;
  }

  .hero-subtitle {
    font-size: 1.1rem;
  }

  .get-started-btn {
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
  }
}

/* Desktop Styles */
@media (min-width: 1024px) {
  .sidebar-and-content {
    max-width: none; /* Full width on desktop */
    margin: 0; /* No centering margin */
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 70px; /* Below header */
    height: calc(100vh - 70px);
    z-index: 999;
    transform: translateX(-100%); /* Start hidden */
    transition: transform 0.3s ease;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
  }

  .sidebar.active {
    transform: translateX(0%); /* Show when active */
  }

  .main-content {
    margin-left: 0; /* No margin when sidebar is closed */
    transition: margin-left 0.3s ease;
    width: 100%;
    padding: 1rem 2rem; /* Consistent padding */
    padding-top: 20px; /* Reduced padding when sidebar hidden */
    max-width: none; /* Remove max-width restriction */
  }

  .content-area {
    max-width: 900px; /* Larger width for desktop */
    margin: 0 auto; /* Center the content area */
  }

  .header-content {
    justify-content: flex-start;
    padding-left: 80px; /* Space for menu button */
  }

  .site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
  }

  .menu-toggle {
    position: fixed;
    left: 20px;
    top: 20px;
    z-index: 1001;
    background: var(--button-bg);
    color: var(--button-text);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    border: none;
    cursor: pointer;
  }
}
