@import url('https://fonts.googleapis.com/css2?family=Instrument+Sans:ital,wdth,wght@0,75..100,400..700;1,75..100,400..700&family=JetBrains+Mono:wght@400;500&display=swap');

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --plyr-color-main: #0047AB;
  --plyr-video-controls-background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.75));
  --plyr-font-family: "Instrument Sans", -apple-system, sans-serif;
  --plyr-font-size-time: 13px;
  --plyr-font-size-small: 12px;

  --primary:        #0047AB;
  --primary-light:  #0047AB;
  --primary-dark:   #0047AB;
  --primary-ghost:  rgba(0, 86, 210, .07);
  --primary-ghost-hover: rgba(0, 86, 210, .13);

  --bg:             #F8F9FB;
  --surface:        #FFFFFF;
  --surface-alt:    #F2F4F7;
  --surface-hover:  #EBEDF0;
  --border:         #E0E3E8;
  --border-strong:  #C5C9D0;

  --text:           #1A1D23;
  --text-secondary: #6B7280;
  --text-muted:     #9CA3AF;

  --success:        #059669;
  --success-bg:     #D1FAE5;
  --danger:         #DC2626;
  --danger-bg:      #FEE2E2;

  --radius:         14px;
  --radius-sm:      9px;
  --radius-xs:      6px;

  --shadow-sm:      0 1px 2px rgba(0,0,0,.05);
  --shadow:         0 2px 8px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg:      0 12px 32px rgba(0,0,0,.1), 0 3px 8px rgba(0,0,0,.05);

  --font:           "Instrument Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:      "JetBrains Mono", ui-monospace, monospace;

  --ease-out:       cubic-bezier(.16, 1, .3, 1);
  --transition:     .18s ease;
}

[data-theme="dark"] {
  --primary:        #3B82F6;
  --primary-light:  #60A5FA;
  --primary-dark:   #2563EB;
  --primary-ghost:  rgba(59, 130, 246, .12);
  --primary-ghost-hover: rgba(59, 130, 246, .2);

  --bg:             #0F1115;
  --surface:        #1A1D24;
  --surface-alt:    #242830;
  --surface-hover:  #2E333D;
  --border:         #363B45;
  --border-strong:  #4B515E;

  --text:           #F0F2F5;
  --text-secondary: #9CA3B0;
  --text-muted:     #6B7280;

  --success:        #34D399;
  --success-bg:     rgba(5, 150, 105, .15);
  --danger:         #F87171;
  --danger-bg:      rgba(220, 38, 38, .15);

  --shadow-sm:      0 1px 2px rgba(0,0,0,.25);
  --shadow:         0 2px 8px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
  --shadow-lg:      0 12px 32px rgba(0,0,0,.45), 0 3px 8px rgba(0,0,0,.25);
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app { min-height: 100vh; }

.view { display: none; }
.view.active { display: flex; flex-direction: column; }
#course-view.view.active { min-height: 100vh; }

/* ===== Home ===== */
#home-view {
  align-items: center;
  padding: 24px 24px 0;
  background: var(--bg);
  min-height: 100vh;
}

.home-card {
  margin: auto 0;
}

.home-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  padding: 44px 40px;
  max-width: 520px;
  width: 100%;
  text-align: center;
}

.logo {
  display: block;
  margin: 0 auto 6px;
  height: 3em;
  width: auto;
}

.tagline {
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 1rem;
  letter-spacing: -.01em;
}

.import-form {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.import-form input {
  flex: 1;
  padding: 11px 15px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.import-form input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ghost);
}

.import-form input::placeholder {
  color: var(--text-muted);
}

.api-key-section {
  text-align: left;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  background: var(--surface-alt);
}

.api-key-section summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: .875rem;
  font-weight: 500;
  padding: 2px 0;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.api-key-section summary::after {
  content: '›';
  margin-left: auto;
  font-size: 1rem;
  transition: transform var(--transition);
  color: var(--text-muted);
}

.api-key-section[open] summary::after {
  transform: rotate(90deg);
}

.api-key-section summary:hover {
  color: var(--text);
}

.api-key-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.api-key-row input {
  flex: 1;
  padding: 9px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: .85rem;
  font-family: var(--font-mono);
  background: var(--surface);
  color: var(--text);
  outline: none;
  letter-spacing: .02em;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.api-key-row input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ghost);
}

.hint {
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.5;
}

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

.hint a:hover {
  text-decoration: underline;
}

/* ===== Explore Section ===== */
.explore-section {
  width: 100%;
  max-width: 1200px;
  margin: 32px auto 0;
  padding: 0 24px 24px;
}

.explore-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.explore-header h3 {
  font-size: .85rem;
  color: var(--text);
  font-weight: 700;
  letter-spacing: -.01em;
}

#explore-count {
  font-size: .78rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ===== Category Filters ===== */
.category-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.category-filter {
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: var(--surface);
  color: var(--text-secondary);
  font-size: .78rem;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: -.01em;
}

.category-filter:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-ghost);
}

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

.explore-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: .875rem;
}

.explore-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.explore-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  transition: transform .2s var(--ease-out);
  display: flex;
  flex-direction: column;
}

.explore-card:hover {
  transform: translateY(-4px);
}

.explore-card-thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--border);
}

.explore-card-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.explore-card-thumb-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .2s ease;
}

.explore-card:hover .explore-card-thumb-overlay {
  opacity: 1;
}

.explore-card-play {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255,255,255,.9);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}

.explore-card-body {
  padding: 10px 0 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.explore-card-title {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.01em;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.explore-card-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .76rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.explore-card-meta > span:not(:last-child)::after {
  content: '·';
  margin-left: 4px;
  color: var(--text-muted);
}

.explore-card-institution {
  color: var(--text-secondary);
}

.explore-card-desc {
  font-size: .76rem;
  color: var(--text-muted);
  line-height: 1.45;
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.import-export {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

#file-input { display: none; }

/* ===== Saved Courses ===== */
.saved-courses {
  text-align: left;
  margin-bottom: 20px;
}

.saved-courses h3 {
  font-size: .72rem;
  color: var(--text-muted);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: .1em;
  font-weight: 600;
}

.saved-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.saved-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  gap: 12px;
  transition: background var(--transition), border-color var(--transition);
}

.saved-item:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

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

.saved-item-info strong {
  font-size: .875rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -.01em;
}

.saved-item-info span {
  font-size: .78rem;
  color: var(--text-secondary);
  margin-top: 1px;
}

.saved-item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* ===== Course Header ===== */
.course-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  z-index: 10;
}

.course-header-info {
  flex: 1;
  min-width: 0;
}

.course-header-info h2 {
  font-size: .95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -.015em;
  color: var(--text);
}

.progress-section {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
}

.progress-bar {
  flex: 1;
  max-width: 128px;
  height: 3px;
  background: var(--border);
  border-radius: 100px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 100px;
  transition: width .5s var(--ease-out);
  width: 0%;
}

.progress-text {
  font-size: .7rem;
  color: var(--primary);
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: .01em;
}

.progress-total {
  font-size: .68rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ===== Layout ===== */
.course-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

/* ===== Sidebar ===== */
.sidebar {
  width: 288px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .22s var(--ease-out);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-header h3 {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-muted);
  font-weight: 600;
}

.search-wrapper {
  position: relative;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-icon {
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.lesson-search {
  width: 100%;
  padding: 7px 10px 7px 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface-alt);
  color: var(--text);
  font-size: .82rem;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.lesson-search:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--primary-ghost);
}

.lesson-search::placeholder {
  color: var(--text-muted);
}

.lesson-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.lesson-list::-webkit-scrollbar { width: 4px; }
.lesson-list::-webkit-scrollbar-track { background: transparent; }
.lesson-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.lesson-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: background var(--transition);
  margin-bottom: 1px;
}

.lesson-item:hover {
  background: var(--surface-hover);
}

.lesson-item.active {
  background: var(--primary-ghost);
  outline: 1.5px solid var(--primary);
  outline-offset: -1.5px;
}

.lesson-item.active .lesson-title {
  color: var(--primary);
  font-weight: 600;
}

.lesson-item.active .lesson-duration {
  color: var(--primary);
  opacity: .7;
}

.lesson-item.completed .lesson-number {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.lesson-number {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .72rem;
  font-weight: 700;
  flex-shrink: 0;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.lesson-item.active .lesson-number {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-ghost);
}

.lesson-number svg {
  display: block;
}

.lesson-info {
  min-width: 0;
  flex: 1;
}

.lesson-title {
  font-size: .82rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  letter-spacing: -.01em;
}

.lesson-duration {
  font-size: .7rem;
  color: var(--text-muted);
  margin-top: 1px;
  font-variant-numeric: tabular-nums;
}

/* ===== Content ===== */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  min-width: 0;
  background: var(--bg);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.content::-webkit-scrollbar { width: 5px; }
.content::-webkit-scrollbar-track { background: transparent; }
.content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.player-container {
  position: relative;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  aspect-ratio: 16 / 9;
  background: #000;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

#player {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0; left: 0;
}

/* Plyr overrides to ensure proper sizing */
.plyr,
.plyr__video-wrapper,
.plyr--youtube {
  width: 100% !important;
  height: 100% !important;
}

.plyr--youtube .plyr__video-wrapper {
  padding-bottom: 0 !important;
  height: 100% !important;
}

.lesson-details {
  padding: 22px 32px 32px;
  flex: 1;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  min-width: 0;
}

#lesson-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: -.025em;
  line-height: 1.3;
  color: var(--text);
}

.lesson-description {
  color: var(--text-secondary);
  font-size: .875rem;
  line-height: 1.65;
  margin-bottom: 20px;
  max-height: 80px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.watch-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  color: var(--primary);
  font-size: .82rem;
  text-decoration: none;
  font-weight: 600;
  letter-spacing: -.01em;
  transition: opacity var(--transition);
}

.watch-link:hover { opacity: .75; }

.lesson-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.lesson-nav {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

/* ===== Notes ===== */
.lesson-notes {
  margin-top: 22px;
  border-top: 1px solid var(--border);
  padding-top: 18px;
}

#btn-toggle-notes {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
  letter-spacing: -.01em;
  transition: color var(--transition);
}

#btn-toggle-notes:hover {
  color: var(--text);
}

.lesson-notes-input {
  display: none;
  width: 100%;
  min-height: 88px;
  padding: 11px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: .85rem;
  font-family: var(--font);
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.lesson-notes-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ghost);
}

.lesson-notes-input::placeholder {
  color: var(--text-muted);
}

.lesson-notes-input.visible { display: block; }

/* ===== Buttons ===== */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-xs);
  font-size: .875rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  letter-spacing: -.01em;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,.15), inset 0 1px 0 rgba(255,255,255,.1);
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0,0,0,.18), inset 0 1px 0 rgba(255,255,255,.1);
}

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

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: .875rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  letter-spacing: -.01em;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}

.btn-secondary:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

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

.btn-secondary:disabled {
  opacity: .35;
  cursor: not-allowed;
  transform: none;
}

.btn-small {
  padding: 6px 13px;
  font-size: .78rem;
}

.btn-icon {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition), border-color var(--transition), transform var(--transition);
  flex-shrink: 0;
}

.btn-icon:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  color: var(--text);
  transform: translateY(-1px);
}

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

.btn-danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}

.btn-danger:hover {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

.mobile-only { display: none; }

/* ===== Sidebar Toggle ===== */
.sidebar-toggle {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 288px;
  z-index: 10;
  width: 16px;
  height: 48px;
  border-radius: 0 8px 8px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  padding: 0;
  transition: left .22s var(--ease-out), color var(--transition), background var(--transition);
  box-shadow: 2px 0 6px rgba(0,0,0,.05);
}

.sidebar-toggle:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.sidebar-toggle svg {
  transition: transform .22s var(--ease-out);
}

.sidebar:not(.collapsed) + .sidebar-toggle svg {
  transform: rotate(0deg);
}

.sidebar.collapsed + .sidebar-toggle {
  left: 0;
}

.sidebar.collapsed + .sidebar-toggle svg {
  transform: rotate(180deg);
}

.sidebar.collapsed {
  width: 0 !important;
  min-width: 0;
  overflow: hidden;
  border: none;
  padding: 0;
}

/* ===== Bottom Bar (mobile only) ===== */
.bottom-bar {
  display: none;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(0,0,0,.06);
  z-index: 50;
  flex-shrink: 0;
}

.bottom-bar-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: .78rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
  position: relative;
  letter-spacing: -.01em;
}

.bottom-bar-tab:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.bottom-bar-tab.active {
  color: var(--primary);
}

.bottom-bar-tab.active::after {
  content: '';
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 2px;
  background: var(--primary);
  border-radius: 0 0 2px 2px;
}

/* ===== Bottom Sheet (mobile only) ===== */
.bottom-sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity .25s ease;
}

.bottom-sheet-backdrop.visible {
  display: block;
  opacity: 1;
}

.bottom-sheet {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 201;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow-lg);
  max-height: 85vh;
  height: 85vh;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform .35s var(--ease-out);
  will-change: transform;
}

.bottom-sheet.open {
  transform: translateY(0);
}

.bottom-sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
  margin: 8px auto 0;
  flex-shrink: 0;
  opacity: .5;
}

.bottom-sheet-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 8px;
  flex-shrink: 0;
}

.bottom-sheet-header h3 {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.02em;
}

.bottom-sheet-count {
  font-size: .75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.bottom-sheet-close {
  margin-left: auto;
}

/* ===== Footer ===== */
.app-footer {
  text-align: center;
  padding: 8px 16px;
  font-size: .75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.app-footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.app-footer a:hover {
  text-decoration: underline;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 22px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity .25s ease, transform .3s var(--ease-out);
  z-index: 1000;
  pointer-events: none;
  letter-spacing: -.01em;
  border: 1px solid rgba(255,255,255,.08);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Hints Panel ===== */
.hints-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 20px 22px;
  z-index: 1100;
  display: none;
  min-width: 270px;
}

.hints-panel.visible { display: block; }

.hints-header {
  font-weight: 700;
  font-size: .9rem;
  margin-bottom: 14px;
  color: var(--text);
  letter-spacing: -.02em;
}

.hints-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: .82rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

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

.hints-row kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 22px;
  padding: 0 6px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-bottom: 2px solid var(--border-strong);
  border-radius: var(--radius-xs);
  font-family: var(--font-mono);
  font-size: .72rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: 0;
}

/* ===== Course Meta / Description ===== */
.course-meta {
  margin-top: 4px;
}

.content-course-meta {
  padding: 10px 32px 0;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: .78rem;
  font-family: var(--font);
  cursor: pointer;
  padding: 2px 0;
  transition: color var(--transition);
  font-weight: 500;
}

.btn-text:hover { color: var(--text); }

.course-desc-text {
  display: none;
  margin-top: 8px;
  font-size: .85rem;
  color: var(--text-secondary);
  line-height: 1.6;
  max-height: 110px;
  overflow-y: auto;
  padding: 12px 14px;
  background: var(--surface-alt);
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
}

.course-desc-text.visible { display: block; }

/* ===== Loading ===== */
.loading-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  z-index: 999;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255,255,255,.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .65s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay p {
  color: #fff;
  font-size: .95rem;
  font-weight: 500;
  letter-spacing: -.01em;
}

/* ===== Scrollbar (global) ===== */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

*::-webkit-scrollbar { width: 5px; height: 5px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
*::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ===== Mobile overlay backdrop ===== */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 98;
  backdrop-filter: blur(2px);
}

.sidebar-backdrop.visible {
  display: block;
}

/* ===== Responsive ===== */

/* Desktop (≥1100px) - Right panel with always-visible lesson list */
@media (min-width: 1100px) {
  .course-layout {
    flex-direction: row;
  }

  .sidebar {
    width: 30%;
    max-width: 380px;
    min-width: 280px;
    border-right: none;
    border-left: 1px solid var(--border);
    order: 2;
  }

  .sidebar-toggle {
    display: flex;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: auto;
    z-index: 10;
    width: 18px;
    height: 44px;
    border-radius: 8px 0 0 8px;
    border: 1px solid var(--border);
    border-right: none;
    background: var(--surface);
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    align-items: center;
    justify-content: center;
    transition: right .22s var(--ease-out), color var(--transition), background var(--transition);
    box-shadow: -2px 0 6px rgba(0,0,0,.05);
    right: calc(30% - 9px);
  }

  .sidebar-toggle:hover {
    background: var(--surface-hover);
    color: var(--text);
  }

  .sidebar-toggle svg {
    transition: transform .22s var(--ease-out);
  }

  .sidebar:not(.collapsed) + .sidebar-toggle svg {
    transform: rotate(180deg);
  }

  .sidebar.collapsed + .sidebar-toggle {
    left: auto;
    right: 0;
  }

  .sidebar.collapsed + .sidebar-toggle svg {
    transform: rotate(0deg);
  }

  .sidebar-backdrop {
    display: none !important;
  }

  .content {
    order: 1;
    max-width: none;
  }

  .player-container {
    max-width: 1000px;
    margin: 0 auto;
    border-bottom: 1px solid var(--border);
  }

  .lesson-details,
  .content-course-meta {
    max-width: 1000px;
  }

  .bottom-bar,
  .bottom-sheet,
  .bottom-sheet-backdrop {
    display: none !important;
  }
}

/* Tablet (769px - 1099px) - Collapsible left drawer, collapsed by default */
@media (max-width: 1099px) and (min-width: 769px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(320px, 80vw);
    z-index: 100;
    transform: translateX(-100%);
    transition: transform .25s var(--ease-out);
    box-shadow: var(--shadow-lg);
  }

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

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 98;
    backdrop-filter: blur(2px);
  }

  .sidebar-backdrop.visible {
    display: block;
  }

  .sidebar-toggle {
    position: fixed;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    height: 44px;
    width: 18px;
    border-radius: 0 8px 8px 0;
    z-index: 99;
    border: 1px solid var(--border);
    border-left: none;
    box-shadow: 2px 0 8px rgba(0,0,0,.08);
  }

  .sidebar:not(.open) + .sidebar-toggle svg {
    transform: rotate(180deg);
  }

  .sidebar.open + .sidebar-toggle svg {
    transform: rotate(0deg);
  }

  .content-course-meta {
    padding: 8px 20px 0;
  }

  .lesson-details {
    padding: 16px 20px 32px;
  }

  .bottom-bar,
  .bottom-sheet,
  .bottom-sheet-backdrop {
    display: none !important;
  }
}

/* Mobile (≤768px) - Bottom sheet navigation */
@media (max-width: 768px) {
  .home-card {
    padding: 28px 20px;
    border-radius: var(--radius);
  }

  .import-form {
    flex-direction: column;
  }

  .course-header {
    padding: 7px 10px;
    gap: 8px;
  }

  .course-header-info h2 {
    font-size: .82rem;
  }

  .progress-section {
    gap: 5px;
  }

  .progress-bar {
    max-width: 60px;
  }

  .progress-total {
    display: none;
  }

  @media (max-width: 400px) {
    #btn-hints { display: none; }
  }

  /* Hide sidebar and toggle on mobile - replaced by bottom sheet */
  .sidebar {
    display: none;
  }

  .sidebar-toggle {
    display: none;
  }

  .sidebar-backdrop {
    display: none !important;
  }

  .content-course-meta {
    padding: 8px 14px 0;
  }

  .mobile-only {
    display: flex;
  }

  .lesson-details {
    padding: 14px 14px 24px;
  }

  #lesson-title {
    font-size: 1rem;
  }

  .lesson-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .lesson-nav {
    margin-left: 0;
    justify-content: center;
  }

  .lesson-nav .btn-secondary {
    flex: 1;
    justify-content: center;
  }

  .lesson-description {
    max-height: 64px;
  }

  /* Bottom bar visible on mobile */
  .bottom-bar {
    display: flex;
  }

  /* Bottom sheet visible on mobile (hidden until opened) */
  .bottom-sheet {
    display: flex;
  }

  .app-footer {
    padding: 6px 12px;
    font-size: .7rem;
  }

  .saved-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .saved-item-actions {
    width: 100%;
    justify-content: flex-end;
  }

  #course-view.view.active {
    padding-bottom: 0;
  }

  .content {
    padding-bottom: 4px;
  }
}

@media (max-width: 480px) {
  .course-header-info h2 {
    font-size: .78rem;
  }
  .progress-bar {
    display: none;
  }
}