:root {
  --bg: #ffffff;
  --muted: #f5f5f5;
  --border: #e3e3e3;
  --hover: #e9e9e9;
  --header-height: 80px;
}

* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  margin: 0;
  background: var(--bg);
  color: #111;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.top-header {
  background: url('Thumbnail.jpg') center 40%;
  background-size: cover;
  background-repeat: no-repeat;
  color: white;
  text-align: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 8/1;
  min-height: 80px;
  padding: 0 20px;
  flex-shrink: 0;
}


.top-header h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-shadow: 2px 2px 8px rgba(0,0,0,0.8), 0 0 4px rgba(0,0,0,0.6);
  position: relative;
  z-index: 2;
}

/* Hamburger Menu */
.nav-toggle {
  position: absolute;
  left: 20px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 4px;
  display: none;
  flex-direction: column;
  gap: 4px;
  transition: background-color 0.2s ease;
  z-index: 2;
}

.nav-toggle:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.nav-toggle span {
  width: 24px;
  height: 3px;
  background-color: white;
  border-radius: 2px;
  transition: all 0.3s ease;
}

.nav-toggle.active span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.nav-toggle.active span:nth-child(2) {
  opacity: 0;
}

.nav-toggle.active span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Desktop layout by default */
.main-wrapper {
  display: flex;
  flex: 1;
  overflow: hidden;
}

nav {
  width: 280px;
  background: var(--muted);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px;
  flex-shrink: 0;
  z-index: 10;
}

main {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  width: 100%;
}

/* Nav overlay - completely hidden on desktop */
.nav-overlay {
  display: none;
}

/* Only show on mobile/tablet screens */
@media (max-width: 1024px) {
  .nav-overlay {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
  }
  
  .nav-overlay.active {
    opacity: 1;
    visibility: visible;
  }
}

nav h2 {
  margin: 12px 0 6px;
  font-size: 18px;
  padding: 6px 8px 6px 6px;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background-color 0.2s ease;
}

nav h2:hover {
  background: var(--hover);
}

nav h2::after {
  content: "▼";
  font-size: 12px;
  transition: transform 0.2s ease;
  opacity: 0.6;
}

nav h2.collapsed::after {
  transform: rotate(-90deg);
}

nav h3 {
  margin: 8px 0 6px;
  font-size: 15px;
  opacity: 0.9;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background-color 0.2s ease;
}

nav h3:hover {
  background: var(--hover);
  opacity: 1;
}

nav h3::after {
  content: "▼";
  font-size: 10px;
  transition: transform 0.2s ease;
  opacity: 0.5;
}

nav h3.collapsed::after {
  transform: rotate(-90deg);
}

nav ul {
  list-style: none;
  padding: 0;
  margin: 0 0 10px 0;
  transition: max-height 0.3s ease, opacity 0.2s ease;
  overflow: hidden;
}

nav ul.collapsed {
  max-height: 0;
  opacity: 0;
  margin: 0;
}

.sefer-section,
.section-level-1,
.section-level-2,
.section-level-3,
.section-level-4,
.section-level-5 {
  transition: max-height 0.3s ease, opacity 0.2s ease;
  overflow: hidden;
  opacity: 1;
}

.sefer-section.collapsed,
.section-level-1.collapsed,
.section-level-2.collapsed,
.section-level-3.collapsed,
.section-level-4.collapsed,
.section-level-5.collapsed {
  max-height: 0;
  opacity: 0;
}

nav li {
  margin: 2px 0;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
}

nav li:hover {
  background: var(--hover);
}

nav li.active {
  background: #dcdcdc;
  font-weight: 600;
}

nav li.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  font-style: italic;
}

nav li.disabled:hover {
  background: none;
}


main header {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

main header h1 {
  font-size: 22px;
  margin: 0;
}

.crumbs {
  font-size: 13px;
  opacity: 0.7;
}

.media {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}

/* Media embeds container - always at top */
.embeds-container {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
  order: 1;
}

/* Videos container for multiple YouTube videos */
.videos-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* PDF styling - always below embeds */
.pdf-wrap {
  width: 100%;
  aspect-ratio: 8.5 / 11;
  max-height: 80vh;
  order: 2;
}

.pdf {
  width: 100%;
  height: 100%;
  border: 1px solid var(--border);
}

/* Mobile PDF container */
.mobile-pdf-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.mobile-pdf-viewer {
  flex: 1;
  width: 100%;
  min-height: 60vh;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.pdf-download-btn {
  display: inline-block;
  padding: 12px 20px;
  background: #007bff;
  color: white;
  text-decoration: none;
  border-radius: 8px;
  text-align: center;
  margin-bottom: 12px;
  font-weight: 500;
  transition: background 0.2s ease;
}

.pdf-download-btn:hover {
  background: #0056b3;
}

/* YouTube aspect ratio container */
.youtube-wrapper {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 56.25%; /* 16:9 aspect ratio */
  overflow: hidden;
  border-radius: 8px;
}

.youtube-wrapper iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

/* Default iframe styles for other cases */
iframe {
  width: 100%;
  height: 360px;
  border: none;
}

/* Mobile Styles */
@media (max-width: 768px) {
  .nav-toggle {
    display: flex;
  }
  
  .top-header {
    aspect-ratio: 30 / 1;
    min-height: 60px;
  }
  
  .top-header h1 {
    font-size: 22px;
  }
  
  .main-wrapper {
    position: relative;
  }
  
  nav {
    position: fixed; /* Fixed to viewport, not relative container */
    top: 0; /* Will be updated by JavaScript */
    left: 0;
    height: 100vh; /* Will be updated by JavaScript */
    z-index: 200;
    transform: translateX(-100%);
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    padding: 14px; /* Standard padding */
    margin: 0; /* No margin */
  }
  
  nav.open {
    transform: translateX(0);
  }
  
  /* Overlay for mobile when nav is open */
  .nav-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
  }
  
  .nav-overlay.active {
    opacity: 1;
    visibility: visible;
  }
  
  main {
    margin-left: 0; /* No margin on mobile */
    padding: 12px;
  }
  
  main header h1 {
    font-size: 20px;
  }
  
  .crumbs {
    font-size: 12px;
  }
  
  /* Touch-friendly sizing */
  nav li {
    padding: 10px 12px;
    font-size: 16px;
  }
  
  nav h2, nav h3 {
    padding: 8px 12px;
  }
  
  /* Better spacing for mobile */
  .pdf-wrap {
    aspect-ratio: auto; /* Let mobile PDF viewer control its own aspect ratio */
    max-height: 70vh;
  }
  
  .mobile-pdf-viewer {
    min-height: 50vh; /* Smaller on mobile */
  }
  
  iframe {
    height: 300px;
  }
  
  /* Mobile audio player adjustments */
  .audio-controls {
    gap: 8px; /* Tighter spacing on mobile */
  }
  
  .progress-container {
    flex: 1;
    min-width: 120px; /* Smaller minimum width on mobile */
  }
  
  .audio-btn {
    min-width: 50px;
    height: 48px; /* Larger touch targets */
    padding: 6px 8px; /* Tighter padding */
  }
}

/* Tablet Styles - same as mobile */
@media (max-width: 1024px) and (min-width: 769px) {
  .nav-toggle {
    display: flex;
  }
  
  
  nav {
    position: fixed; /* Fixed to viewport, not relative container */
    top: 0; /* Will be updated by JavaScript */
    left: 0;
    width: 280px;
    height: 100vh; /* Will be updated by JavaScript */
    z-index: 200;
    transform: translateX(-100%);
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    transition: transform 0.3s ease;
    padding: 14px; /* Standard padding */
    margin: 0; /* No margin */
  }
  
  nav.open {
    transform: translateX(0);
  }
  
}

/* Desktop layout - Videos | Audio side by side, PDF below */
@media (min-width: 1024px) {
  .embeds-container {
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 8px;
    align-items: start; /* Align to top for multiple videos */
  }
  
  
  .youtube-wrapper {
    min-height: 250px;
    margin-bottom: 16px;
  }
  
  .youtube-wrapper:last-child {
    margin-bottom: 0;
  }
  
  .audio-wrapper {
    height: 280px; /* Match YouTube height better */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  
  .pdf-wrap {
    max-height: 85vh; /* Slightly larger on desktop */
  }
}

/* Modern Audio Player Styles */
.audio-wrapper {
  width: 100%;
  padding: 20px;
  background: var(--muted);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.audio-title {
  margin: 0 0 16px 0;
  font-size: 16px;
  font-weight: 600;
  color: #333;
  text-align: center;
}

.audio-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.audio-btn {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  text-decoration: none;
  color: #333;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 44px;
}

.audio-btn:hover {
  background: #f5f5f5;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.audio-btn:active {
  transform: translateY(0);
}

.play-btn {
  font-size: 16px;
  min-width: 50px;
}

.speed-btn {
  font-size: 12px;
  font-weight: 600;
  min-width: 50px;
}

.download-btn {
  font-size: 16px;
  color: #007bff;
  border-color: #007bff;
}

.download-btn:hover {
  background: #007bff;
  color: white;
}

.progress-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 150px;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: #e0e0e0;
  border-radius: 3px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #007bff, #0056b3);
  border-radius: 3px;
  width: 0%;
  transition: width 0.1s ease;
}

.time-display {
  font-size: 12px;
  color: #666;
  text-align: center;
  font-family: monospace;
}

/* Status messages at top of content */
.status-messages {
  margin-bottom: 16px;
}

.media-error {
  background: #fff3cd;
  color: #856404;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid #ffeaa7;
  margin-bottom: 8px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}
