:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --sidebar-bg: #111827;
  --sidebar-hover: #1f2937;
  --sidebar-active: #2563eb;
  --sidebar-text: #d1d5db;
  --sidebar-muted: #9ca3af;
  --text: #111827;
  --text-muted: #4b5563;
  --border: #e5e7eb;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --accent-bg: #eff6ff;
  --warm-bg: #fffbeb;
  --warm-border: #fde68a;
  --radius: 10px;
  --sidebar-width: 290px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: 96px;
}

a {
  color: var(--primary);
  text-decoration: none;
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Mobile bar */
.mobile-bar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--sidebar-bg);
  color: #fff;
  padding: 10px 16px;
  align-items: center;
  justify-content: space-between;
}

.mobile-brand {
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
}

.icon-btn {
  background: var(--sidebar-hover);
  color: #fff;
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.9rem;
  cursor: pointer;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #1f2937;
}

.sidebar-brand {
  padding: 18px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #1f2937;
}

.brand-link {
  display: flex;
  flex-direction: column;
  color: #fff;
}

.brand-title {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-subtitle {
  font-size: 0.8rem;
  color: var(--sidebar-muted);
}

.total-badge {
  font-size: 0.72rem;
  background: #1f2937;
  color: #93c5fd;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.sidebar-search {
  padding: 12px 14px;
  display: flex;
  gap: 6px;
  border-bottom: 1px solid #1f2937;
}

.sidebar-search input {
  flex: 1;
  min-width: 0;
  background: #1f2937;
  border: 1px solid #374151;
  color: #fff;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 0.85rem;
}

.sidebar-search input::placeholder {
  color: var(--sidebar-muted);
}

.sidebar-search button {
  background: var(--sidebar-active);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 7px 11px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 90px;
}

.nav-section {
  margin-bottom: 18px;
}

.nav-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  font-size: 0.73rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sidebar-muted);
}

.nav-all-link {
  color: #93c5fd;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}

.tree-list,
.tree-sublist,
.massechet-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree-row {
  display: flex;
  align-items: center;
  border-radius: 6px;
}

.tree-row:hover {
  background: var(--sidebar-hover);
}

.tree-row.active {
  background: var(--sidebar-active);
}

.tree-toggle {
  background: transparent;
  border: none;
  color: var(--sidebar-muted);
  width: 24px;
  height: 28px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: transform 0.15s ease;
}

.tree-toggle[aria-expanded="true"] {
  transform: rotate(90deg);
  color: #fff;
}

.tree-spacer {
  width: 24px;
  display: inline-block;
}

.tree-link,
.tree-sublink,
.massechet-link {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px 6px 2px;
  color: var(--sidebar-text);
  font-size: 0.87rem;
  border-radius: 6px;
  min-width: 0;
}

.tree-row.active .tree-link,
.tree-sublink.active,
.massechet-link.active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 600;
}

.tree-sublist {
  display: none;
  padding-left: 24px;
  margin-top: 2px;
}

.tree-sublist.open {
  display: block;
}

.tree-sublink {
  padding: 5px 8px;
  font-size: 0.83rem;
}

.tree-sublink:hover,
.massechet-link:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.massechet-link {
  justify-content: space-between;
  padding: 6px 10px;
}

.tree-name,
.massechet-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.today-dot {
  display: inline-block;
  margin-left: 5px;
  padding: 1px 6px;
  font-size: 0.68rem;
  background: #f59e0b;
  color: #111827;
  border-radius: 999px;
  font-weight: 700;
}

.count-pill {
  font-size: 0.73rem;
  color: var(--sidebar-muted);
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 7px;
  border-radius: 999px;
}

.active .count-pill {
  color: #fff;
  background: rgba(255, 255, 255, 0.22);
}

/* Main Content */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 24px 32px 48px;
  max-width: 1200px;
  width: 100%;
}

.dedication-banner {
  background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 18px 22px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
  box-shadow: 0 4px 14px rgba(29, 78, 216, 0.14);
}

.site-kicker {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #bfdbfe;
  font-weight: 600;
}

.dedication-memorial {
  margin: 4px 0 0;
  font-size: 0.96rem;
  color: #f8fafc;
}

.daf-yomi-card {
  background: rgba(255, 255, 255, 0.13);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.daf-date {
  font-size: 0.76rem;
  color: #dbeafe;
}

.daf-link {
  color: #fff;
  font-size: 0.92rem;
}

.daf-link:hover {
  text-decoration: underline;
}

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.crumb-sep {
  color: #9ca3af;
}

.crumb-current {
  font-weight: 600;
  color: var(--text);
}

/* Featured Direct Class Hero & Recent 7 Section */
.featured-class-card {
  background: var(--surface);
  border: 2px solid #93c5fd;
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 26px;
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.08);
}

.featured-badge-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.featured-kicker {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
}

.featured-date {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.featured-title {
  margin: 0 0 6px;
  font-size: 1.5rem;
}

.featured-path {
  margin: 0 0 16px;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.featured-path code {
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.82rem;
}

.featured-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.recent-section {
  margin-bottom: 28px;
}

.recent-list {
  border-color: #bfdbfe;
}

.section-subtitle {
  margin: 2px 0 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.btn-icon {
  padding: 6px 9px;
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  font-size: 0.9rem;
}

.btn-icon:hover {
  background: #eff6ff;
  border-color: #93c5fd;
}

.btn-icon.copied,
.btn.copied {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}

.btn-whatsapp {
  background: #16a34a;
  color: #fff;
}

.btn-whatsapp:hover {
  background: #15803d;
  color: #fff;
}

.btn-whatsapp-icon:hover {
  background: #dcfce7;
  border-color: #86efac;
}

.btn-outline-dark {
  background: #1e293b;
  color: #e2e8f0;
  border-color: #334155;
}

.btn-outline-dark:hover {
  background: #334155;
  color: #fff;
}

.copy-toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  background: #1e293b;
  color: #ffffff;
  border: 1px solid #334155;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.28);
  animation: toastFadeIn 0.18s ease-out;
}

.copy-toast.hidden {
  display: none !important;
}

@keyframes toastFadeIn {
  from {
    opacity: 0;
    transform: translate(-50%, -8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.player-status-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.resume-pill {
  background: #1e293b;
  color: #93c5fd;
  border: 1px solid #334155;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.7rem;
  cursor: pointer;
}

.resume-pill.hidden {
  display: none;
}

/* Folder Showcase Cards */
.folders-showcase {
  margin-bottom: 28px;
}

.section-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title {
  margin: 0;
  font-size: 1.1rem;
}

.text-link {
  font-size: 0.88rem;
  font-weight: 600;
}

.folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.subfolders-grid {
  margin-bottom: 20px;
}

.folder-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}

.folder-card:hover {
  border-color: #93c5fd;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.08);
  transform: translateY(-1px);
}

.folder-card-icon {
  font-size: 1.55rem;
}

.folder-card-title {
  font-weight: 600;
  font-size: 0.94rem;
}

.folder-card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Classes Section */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.page-heading {
  margin: 0;
  font-size: 1.55rem;
}

.page-subheading {
  margin: 3px 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.source-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.source-tab {
  padding: 6px 13px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.source-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.local-filter-wrap {
  flex: 1;
  min-width: 220px;
  max-width: 420px;
}

.local-filter-wrap input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--surface);
}

.sort-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.results-count {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.classes-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.class-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s ease;
}

.class-row:last-child {
  border-bottom: none;
}

.class-row:nth-child(even) {
  background: #f9fafb;
}

.class-row:hover {
  background: var(--accent-bg);
}

.class-row.playing {
  background: #dbeafe;
}

.class-main {
  flex: 1;
  min-width: 0;
}

.play-trigger {
  width: 100%;
  background: none;
  border: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  font: inherit;
}

.play-circle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  flex-shrink: 0;
}

.class-row.playing .play-circle {
  background: var(--primary);
  color: #fff;
}

.class-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.class-title {
  font-weight: 600;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.class-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.meta-tag {
  background: #f3f4f6;
  padding: 0 6px;
  border-radius: 4px;
}

.meta-ext {
  text-transform: uppercase;
  font-weight: 600;
  color: #6b7280;
}

.class-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px 14px;
  border-radius: 7px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.82rem;
}

.btn-listen {
  background: var(--primary);
  color: #fff;
}

.btn-listen:hover {
  background: var(--primary-hover);
  color: #fff;
}

.btn-download {
  background: #f3f4f6;
  color: #1f2937;
  border-color: #d1d5db;
}

.btn-download:hover {
  background: #e5e7eb;
  color: #111827;
}

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-outline:hover {
  background: #f3f4f6;
}

.alert-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
}

.empty-state {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  color: var(--text-muted);
}

/* Sticky Player Bar */
.player-bar {
  position: fixed;
  left: var(--sidebar-width);
  right: 0;
  bottom: 0;
  z-index: 50;
  background: #0f172a;
  color: #fff;
  border-top: 1px solid #334155;
  padding: 10px 20px;
  box-shadow: 0 -6px 20px rgba(15, 23, 42, 0.25);
}

.player-bar.hidden {
  display: none;
}

.player-inner {
  max-width: 1140px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.player-meta {
  display: flex;
  flex-direction: column;
  min-width: 180px;
  max-width: 340px;
}

.player-badge {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #60a5fa;
  font-weight: 700;
}

.player-title {
  font-size: 0.94rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-folder {
  font-size: 0.75rem;
  color: #94a3b8;
}

.player-controls {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.player-controls audio {
  height: 36px;
  min-width: 240px;
  flex: 1;
  max-width: 440px;
}

.player-btn {
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 0.8rem;
  cursor: pointer;
}

.player-btn:hover {
  background: #334155;
}

.speed-control {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  color: #cbd5e1;
}

.speed-control select {
  background: #1e293b;
  color: #fff;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 5px 6px;
}

.player-close {
  background: transparent;
  color: #94a3b8;
  border: none;
  font-size: 1.05rem;
  cursor: pointer;
  padding: 4px 8px;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 900px) {
  body {
    padding-bottom: 175px;
  }

  .app-layout {
    flex-direction: column;
  }

  .mobile-bar {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.48);
    z-index: 35;
  }

  .main-content {
    margin-left: 0;
    padding: 16px;
  }

  .player-bar {
    left: 0;
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .player-inner {
    position: relative;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .player-meta {
    max-width: 100%;
    padding-right: 32px;
  }

  .player-controls {
    justify-content: flex-start;
    gap: 6px;
  }

  .player-controls audio {
    order: 10;
    flex: 1 0 100%;
    width: 100%;
    min-width: 100%;
    max-width: none;
    height: 44px;
    margin-top: 4px;
  }

  .player-close {
    position: absolute;
    top: -2px;
    right: -4px;
  }

  .class-row {
    flex-direction: column;
    align-items: stretch;
  }

  .class-actions {
    justify-content: flex-end;
  }
}
