:root {
  --font-family-primary: "Inter", sans-serif;

  /* Light Mode Colors */
  --background-color-light: #ffffff;
  --sidebar-bg-light: #f8f8f8;
  --text-color-light: #212121;
  --primary-color-light: #366348;
  --block-bg-light: #f0f0f0;
  --border-color-light: #e0e0e0;
  --header-footer-bg-light: #f5f5f5;
  --shadow-light: 0 4px 12px rgba(0, 0, 0, 0.1);
  --tooltip-bg-light: #f0f0f0;
  --tooltip-text-light: #333;
  --scrollbar-bg-light: #f5f5f5;
  --scrollbar-thumb-light: #366348;

  /* Dark Mode Colors */
  --background-color-dark: #121614;
  --sidebar-bg-dark: #1a1f1c;
  --text-color-dark: #e0e0e0;
  --primary-color-dark: #96c5a9;
  --block-bg-dark: #15271d;
  --border-color-dark: #264532;
  --header-footer-bg-dark: #0f1c14;
  --shadow-dark: 0 4px 12px rgba(0, 0, 0, 0.422);
  --tooltip-bg-dark: #333;
  --tooltip-text-dark: #fff;
  --scrollbar-bg-dark: #0f1c14;
  --scrollbar-thumb-dark: #96c5a9;

  /* Current Theme Colors */
  --background-color: var(--background-color-light);
  --sidebar-bg: var(--sidebar-bg-light);
  --text-color: var(--text-color-light);
  --primary-color: var(--primary-color-light);
  --block-bg: var(--block-bg-light);
  --border-color: var(--border-color-light);
  --header-footer-bg: var(--header-footer-bg-light);
  --shadow: var(--shadow-light);
  --tooltip-bg: var(--tooltip-bg-light);
  --tooltip-text: var(--tooltip-text-light);
  --scrollbar-bg: var(--scrollbar-bg-light);
  --scrollbar-thumb: var(--scrollbar-thumb-light);
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden; /* Prevent body from scrolling */
}

body {
  font-family: var(--font-family-primary);
  background-color: var(--background-color);
  color: var(--text-color);
  transition: background-color 0.3s, color 0.3s;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
}

html.dark-mode {
  --background-color: var(--background-color-dark);
  --sidebar-bg: var(--sidebar-bg-dark);
  --text-color: var(--text-color-dark);
  --primary-color: var(--primary-color-dark);
  --block-bg: var(--block-bg-dark);
  --border-color: var(--border-color-dark);
  --header-footer-bg: var(--header-footer-bg-dark);
  --shadow: var(--shadow-dark);
  --tooltip-bg: var(--tooltip-bg-dark);
  --tooltip-text: var(--tooltip-text-dark);
  --scrollbar-bg: var(--scrollbar-bg-dark);
  --scrollbar-thumb: var(--scrollbar-thumb-dark);
}

/* Custom Scrollbar Styling */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-bg);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 6px;
  border: 2px solid var(--scrollbar-bg);
}

::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--scrollbar-thumb) 80%, #000);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-bg);
}

/* Layout */
.page-container {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  min-height: 0;
}

.content-wrapper {
  display: flex;
  flex-grow: 1;
  min-height: 0;
}

.center-pane-wrapper {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto; /* This is the key change */
}

.main-content {
  flex-grow: 1;
  padding: 2rem 3rem;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

.sidebar-left,
.sidebar-right {
  flex: 0 0 250px;
  padding: 0; /* Remove padding to be handled by children */
  min-height: 0; /* Allow sidebar to shrink */
  overflow-y: auto;
  border-right: 1px solid var(--border-color);
  border-left: 1px solid var(--border-color);
  background-color: var(--sidebar-bg); /* Apply sidebar background color */

  /* Ensure scrollbars in sidebars also use custom styling */
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-bg);
  max-width: 100%;
  transition: width 0.3s ease-in-out, padding 0.3s ease-in-out,
    opacity 0.3s ease-in-out;
  overflow-x: hidden;
}

.sidebar-left {
  border-right: 1px solid var(--border-color);
}

.sidebar-right {
  border-left: 1px solid var(--border-color);
}

/* Course Outline Sidebar Styling */
.sidebar-left nav,
.sidebar-right nav {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 250px;
}

.sidebar-left h3,
.sidebar-right h3 {
  margin: 0;
  padding: 1rem;
  background-color: var(--header-footer-bg);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
  font-size: 1.2em;
  font-weight: 700;
}

.sidebar-left ul,
.sidebar-right ul {
  list-style: none;
  padding: 0;
  margin: 0;
  flex-grow: 1;
}

.sidebar-left li,
.sidebar-right li {
  padding: 0.75rem 1rem; /* Increased vertical padding */
  border-bottom: 1px solid var(--border-color); /* Light gray line separator */
  margin: 0;
}

.sidebar-left li:last-child,
.sidebar-right li:last-child {
  border-bottom: none;
}

/* On-Page Table of Contents Specific Styling */
#on-page-toc .toc-h2 a {
  font-size: 1em;
  font-weight: 600;
}

#on-page-toc .toc-h3 {
  padding-left: 1.5rem; /* Tab in h3 entries */
}

#on-page-toc .toc-h3 a {
  font-size: 0.9em; /* Smaller font for h3 entries */
  font-weight: normal;
}

.sidebar-left a,
.sidebar-right a {
  text-decoration: none;
  color: var(--text-color);
  display: block;
  transition: color 0.3s;
}

.sidebar-left a:hover,
.sidebar-right a:hover {
  color: var(--primary-color);
  text-decoration: none;
}

/* Course Outline Specific Styling */
.sidebar-left .section a {
  font-size: 1em;
  font-weight: 600;
}

.sidebar-left .subsection a {
  font-weight: normal;
}

.sidebar-left .subsection {
  padding-left: 1.5rem;
}

.sidebar-left .subsection a {
  font-size: 0.9em;
}

header {
  flex-shrink: 0;
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--header-footer-bg);
  box-shadow: var(--shadow);
  z-index: 1000;
  height: 60px;
  transition: transform 0.3s ease-in-out;
}

.header-hidden {
  transform: translateY(-100%);
}

/* Classes for hiding sidebars */
.sidebar-hidden {
  flex-basis: 0;
  width: 0 !important;
  padding: 0;
  opacity: 0;
  overflow: hidden;
}

footer {
  flex-shrink: 0;
  padding: 0;
  border-top: 1px solid var(--border-color);
  background-color: var(--header-footer-bg);
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
  height: 60px;
}

/* Other styles... */

footer {
  flex-shrink: 0;
  padding: 0;
  border-top: 1px solid var(--border-color);
  background-color: var(--header-footer-bg);
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
  height: 60px;
}

.header-content {
  display: flex;
  align-items: center;
  width: 100%;
  height: 100%;
}

.logo {
  height: 32px;
  margin-right: 1rem;
  filter: invert(100%);
  flex-shrink: 0;
}

html.dark-mode .logo {
  filter: invert(0%);
}

.course-title {
  font-size: 1.2em;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-grow: 1;
  min-width: 0;
  margin-right: 1rem;
}

.toggles {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.menu-toggle {
  display: none;
}

.toggles .toggle-button {
  background-color: var(--block-bg);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  padding: 0.5rem;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.3s ease;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2em;
  position: relative;
  flex-shrink: 0;
}

/* Ensure icons inside toggle buttons use the correct color */
.toggles .toggle-button .theme-icon,
.toggles .toggle-button .status-icon {
  /* Inherit color from parent by default */
  transition: filter 0.3s ease; /* Smooth transition for icon color changes */
  width: 20px; /* Fixed width to prevent scaling */
  height: 20px; /* Fixed height to prevent scaling */
  flex-shrink: 0; /* Prevent shrinking */
}

/* Light mode: Icons use the default text color (no filter needed) */
/* Light mode hover: Keep the same icon color */
.toggles .toggle-button:hover .theme-icon,
.toggles .toggle-button:hover .status-icon {
  /* No filter needed - keep dark icons on hover in light mode */
}

/* Dark mode: Force icons to use a light color */
html.dark-mode .toggles .toggle-button .theme-icon,
html.dark-mode .toggles .toggle-button .status-icon {
  filter: invert(100%); /* Light color for icons in dark mode */
}

/* Dark mode hover: Use dark icons on dark background for better contrast */
html.dark-mode .toggles .toggle-button:hover .theme-icon,
html.dark-mode .toggles .toggle-button:hover .status-icon {
  filter: invert(0%); /* Dark icons on hover in dark mode */
}

/* Hover effect for toggle buttons */
.toggles .toggle-button:hover {
  background-color: #96c5a9; /* Use the dark mode primary color for both modes */
  transform: scale(1.1); /* Slight scale up on hover */
  border-color: #96c5a9;
}

.toggles .toggle-button:active {
  transform: scale(0.95); /* Slight scale down on click */
}

/* Menu toggle specific styling */
.menu-toggle {
  border: none;
  background-color: transparent; /* Transparent background to avoid flashing */
  transition: top 0.3s, background-color 0.3s, box-shadow 0.3s; /* Match all transition properties of header */
}

/* Light mode menu toggle */
.menu-toggle .menu-icon {
  filter: invert(0%); /* Normal colors in light mode */
  transition: filter 0.3s; /* Smooth transition for icon color changes */
  width: 20px; /* Fixed width to prevent scaling */
  height: 20px; /* Fixed height to prevent scaling */
  flex-shrink: 0; /* Prevent shrinking */
}

.menu-toggle:hover .menu-icon {
  filter: invert(50%); /* Gray shade on hover in light mode */
}

/* Dark mode menu toggle */
html.dark-mode .menu-toggle {
  background-color: transparent; /* Transparent background in dark mode too */
}

html.dark-mode .menu-toggle .menu-icon {
  filter: invert(100%); /* White bars in dark mode */
}

html.dark-mode .menu-toggle:hover .menu-icon {
  filter: invert(70%); /* Lighter gray on hover in dark mode */
}

.toggles .toggle-button:active {
  transform: scale(0.95); /* Slight scale down on click */
}

.footer-nav {
  display: flex;
  justify-content: space-between;
  height: 100%;
}

.footer-button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  transition: background-color 0.3s;
  cursor: pointer;
  user-select: none;
}

.footer-button:not(.disabled):hover {
  background-color: var(--block-bg);
}

.footer-button.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.prev-page {
  border-right: 1px solid var(--border-color);
}

.arrow {
  font-size: 1.2em;
  font-weight: bold;
}

.button-text {
  white-space: normal;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* General Elements */
a {
  color: var(--primary-color);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

blockquote {
  background-color: var(--block-bg);
  border-left: 5px solid var(--primary-color);
  padding: 0 1.5rem;
  margin: 1.5rem 0;
  border-radius: 0.5rem; /* Rounded corners */
  overflow-x: auto; /* Handle long content */
  max-width: 100%;
}

details {
  background-color: var(--block-bg);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 0 2rem;
  margin: 0;
  max-width: 100%;
}

summary {
  cursor: pointer;
  font-weight: bold;
  color: var(--primary-color);
  padding: 1rem 0 1rem 0;
  /* Remove default focus and hover styles */
  outline: none;
}

summary:hover,
summary:focus {
  background-color: transparent;
  color: var(--primary-color);
}

/* Remove focus and hover effects on transcript summaries */
details.transcript summary {
  -webkit-tap-highlight-color: transparent;
  outline: none;
  background-color: transparent;
}

details.transcript summary:hover,
details.transcript summary:focus {
  background-color: transparent;
  color: var(--primary-color);
}

details.transcript summary::-webkit-details-marker {
  color: var(--primary-color);
}

/* Transcript styling - make content text smaller */
details.transcript {
  font-size: 0.9em;
}

/* Transcript hr styling - thin and theme-appropriate gray */
details.transcript hr {
  border: 0;
  height: 1px;
  background-color: var(--border-color);
  margin: 1em 0;
}

/* Audio Player Styling - Fixed width issues */
audio {
  width: 100%;
  max-width: 100%;
  background-color: var(--block-bg);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  margin: 1.5rem 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* Subtle shadow */
  box-sizing: border-box;
}

audio::-webkit-media-controls-panel {
  background-color: var(--block-bg);
  color: var(--text-color);
}

audio::-webkit-media-controls-play-button,
audio::-webkit-media-controls-current-time-display,
audio::-webkit-media-controls-time-remaining-display,
audio::-webkit-media-controls-timeline,
audio::-webkit-media-controls-volume-slider {
  color: var(--primary-color);
}

/* Ensure no element can cause horizontal overflow */
* {
  max-width: 100%;
  box-sizing: border-box;
}

/* Responsive Design */

/* First breakpoint: Hide left sidebar (index) and show menu toggle */
@media (max-width: 1200px) {
  .sidebar-left {
    display: none;
    position: fixed;
    top: 60px; /* Height of header */
    left: 0;
    width: 0;
    height: calc(100vh - 60px);
    z-index: 999;
    box-shadow: var(--shadow);
    transition: width 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    background-color: var(--background-color); /* Solid background */
  }

  .sidebar-left.show {
    display: block;
    width: 250px;
  }

  .menu-toggle {
    display: flex; /* Show menu toggle on narrow screens */
    margin-right: 1rem;
  }
  .sidebar-right {
    flex: 0 250px; /* Keep right sidebar full width */
  }

  header {
    height: 60px; /* Fixed height to prevent vertical overflow */
  }
}

/* Second breakpoint: Hide right sidebar (outline) but keep menu toggle */
@media (max-width: 992px) {
  .sidebar-right {
    display: none;
    position: fixed;
    top: 60px; /* Height of header */
    right: 0;
    width: 0;
    height: calc(100vh - 60px);
    z-index: 999;
    box-shadow: var(--shadow);
    transition: width 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    background-color: var(--background-color); /* Solid background */
  }

  .sidebar-right.show {
    display: block;
    width: 250px;
  }

  .menu-toggle {
    display: flex; /* Ensure menu toggle is still visible */
    margin-right: 1rem;
  }

  .main-content {
    padding: 1.5rem;
  }

  header {
    height: 60px; /* Fixed height to prevent vertical overflow */
  }
}

/* Third breakpoint: Adjust main content for small screens */
@media (max-width: 768px) {
  .page-container {
    flex-direction: column;
  }
  .main-content {
    padding: 1rem;
  }
  .footer-nav {
    flex-direction: row; /* Keep buttons side by side */
  }

  .course-title {
    font-size: 1em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .toggles {
    flex-shrink: 0;
  }

  /* Menu toggle button */
  .menu-toggle {
    display: flex; /* Show menu toggle on small screens */
    margin-right: 1rem;
  }

  /* Audio player adjustments for mobile */
  audio {
    padding: 0.5rem 0.75rem;
  }

  header {
    height: 60px; /* Fixed height to prevent vertical overflow */
  }
}

/* Extra small screens */
@media (max-width: 480px) {
  header {
    padding: 0.75rem;
    height: 60px; /* Fixed height to prevent vertical overflow */
  }

  .logo {
    height: 24px;
    margin-right: 0.5rem;
  }

  .course-title {
    font-size: 0.9em;
  }

  .toggles .toggle-button {
    width: 36px;
    height: 36px;
    padding: 0.4rem;
  }

  /* Adjust tooltip position for small screens */
  .toggles .toggle-button::after {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
  }

  .footer-nav {
    width: 100%;
    padding: 0 0.5rem;
  }

  /* Audio player adjustments for extra small screens */
  audio {
    padding: 0.4rem 0.6rem;
  }
}

/* Title Page Styles */
.title-page {
  text-align: center;
  padding: 2rem;
  max-width: 800px;
  margin: 0 auto;
}

.title-page-heading {
  font-size: 3em;
  font-weight: 900;
  margin-top: 2em;
  margin-bottom: 1em;
  color: var(--primary-color);
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.title-page-subtitle {
  font-size: 1.5em;
  font-weight: 500;
  margin-bottom: 2em;
  color: var(--text-color);
  opacity: 0.9;
}

.title-page-content {
  text-align: left;
  margin-top: 3em;
}

.title-page-content p {
  font-size: 1.1em;
  line-height: 1.7;
}

.title-page-content ul {
  font-size: 1.1em;
  line-height: 1.7;
  text-align: left;
  max-width: 600px;
  margin: 1.5em auto;
  padding-left: 1.5em;
}

.title-page-content li {
  margin-bottom: 0.5em;
}

/* Responsive adjustments for title page */
@media (max-width: 768px) {
  .title-page-heading {
    font-size: 2.2em;
  }

  .title-page-subtitle {
    font-size: 1.2em;
  }

  .title-page-content {
    margin-top: 2em;
  }
}

@media (max-width: 480px) {
  .title-page-heading {
    font-size: 1.8em;
  }

  .title-page-subtitle {
    font-size: 1em;
  }

  .title-page {
    padding: 1rem;
  }
}

/* Sutta Reference Styling */
.sutta-reference em {
  color: var(--primary-color);
  font-style: italic;
  /* font-weight: bold; */
}

/* Table Styling */
table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.5rem 0;
  background-color: var(--background-color);
}

th,
td {
  padding: 0.75rem 1rem;
  text-align: left;
  border: 1px solid var(--border-color);
}

th {
  background-color: var(--block-bg);
  font-weight: 600;
}

tr:nth-child(even) {
  background-color: var(--block-bg);
}

/* Responsive table handling */
@media (max-width: 768px) {
  table {
    font-size: 0.9em;
  }

  th,
  td {
    padding: 0.5rem 0.75rem;
  }
}

@media (max-width: 480px) {
  table {
    font-size: 0.8em;
  }

  th,
  td {
    padding: 0.4rem 0.6rem;
  }
}

/* Error Page Styles */
.error-page {
  text-align: center;
  padding: 2rem;
  max-width: 600px;
  margin: 0 auto;
}

.error-page h1 {
  font-size: 2.5em;
  color: var(--primary-color);
  margin-bottom: 1rem;
}

.error-page p {
  font-size: 1.2em;
  margin-bottom: 1.5rem;
}

.error-page a {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  background-color: var(--primary-color);
  color: var(--background-color);
  text-decoration: none;
  border-radius: 4px;
  font-weight: bold;
  transition: background-color 0.3s;
}

.error-page a:hover {
  background-color: color-mix(in srgb, var(--primary-color) 80%, #000);
  text-decoration: none;
}
