:root {
  --bg-light: #f6f8fa;
  --bg-dark: #0e1419;
  --surface-light: #ffffff;
  --surface-dark: #17212b;
  --surface-alt-light: #eef2f6;
  --surface-alt-dark: #202d3a;
  --text-light: #17212b;
  --text-dark: #edf2f7;
  --muted-light: #5c6c7c;
  --muted-dark: #94a6b8;
  --border-light: #dce3ea;
  --border-dark: #273646;
  --brand-light: #1e9aa5;
  --brand-dark: #4ad0dc;

  --bg: var(--bg-light);
  --surface: var(--surface-light);
  --surface-alt: var(--surface-alt-light);
  --text: var(--text-light);
  --muted: var(--muted-light);
  --border: var(--border-light);
  --brand: var(--brand-light);

  @media (prefers-color-scheme: dark) {
    --bg: var(--bg-dark);
    --surface: var(--surface-dark);
    --surface-alt: var(--surface-alt-dark);
    --text: var(--text-dark);
    --muted: var(--muted-dark);
    --border: var(--border-dark);
    --brand: var(--brand-dark);
  }

  @supports (color: light-dark(white, black)) {
    --bg: light-dark(var(--bg-light), var(--bg-dark));
    --surface: light-dark(var(--surface-light), var(--surface-dark));
    --surface-alt: light-dark(var(--surface-alt-light), var(--surface-alt-dark));
    --text: light-dark(var(--text-light), var(--text-dark));
    --muted: light-dark(var(--muted-light), var(--muted-dark));
    --border: light-dark(var(--border-light), var(--border-dark));
    --brand: light-dark(var(--brand-light), var(--brand-dark));
  }

  color-scheme: light dark;
  accent-color: var(--brand);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  padding-bottom: calc(118px + env(safe-area-inset-bottom));
}

button, input {
  font: inherit;
  color: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0.7rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: 0;
  background: none;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  padding: 0.25rem 0.4rem;
}

.brand-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--brand);
}

.search-wrap {
  flex: 1 1 220px;
}

.search-wrap input {
  width: 100%;
  padding: 0.5rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}

.nav-tabs {
  display: flex;
  gap: 0.35rem;
}

.tab-btn {
  border: 1px solid transparent;
  background: transparent;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 500;
  color: var(--muted);
}

.tab-btn.active {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border);
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.25rem 1rem;
}

.section-block {
  margin-bottom: 2rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.section-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.9rem;
}

@media (max-width: 480px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.7rem;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
  text-align: left;
  padding: 0;
}

.card:hover {
  transform: translateY(-2px);
  border-color: var(--brand);
}

.card-cover {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background-color: #e9f1f4;
  background-color: color-mix(in srgb, var(--card-accent, var(--brand)) 28%, #f4f7f9);
  display: block;
}

.card-body {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.card-title {
  font-weight: 600;
  font-size: 0.95rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

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

.filter-pills {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}

.pill {
  white-space: nowrap;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.pill.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.detail-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.25rem;
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
  margin-bottom: 1.25rem;
}

@media (max-width: 640px) {
  .detail-hero {
    flex-direction: column;
  }
}

.detail-cover {
  width: 140px;
  height: 140px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
  background-color: #e9f1f4;
  background-color: color-mix(in srgb, var(--card-accent, var(--brand)) 28%, #f4f7f9);
}

.detail-info h1 {
  margin: 0 0 0.4rem;
  font-size: 1.4rem;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.85rem;
}

.back-btn, .pill-btn, .primary-btn {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 10px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  font-weight: 500;
}

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

.pill-btn[aria-pressed="true"] {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.lesson-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.lesson-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.lesson-row.playing {
  border-color: var(--brand);
}

.lesson-play {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  font-weight: 700;
}

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

.lesson-title {
  font-weight: 600;
  font-size: 0.96rem;
}

.lesson-sub {
  font-size: 0.82rem;
  color: var(--muted);
  display: flex;
  gap: 0.65rem;
  align-items: center;
  margin-top: 0.15rem;
}

.badge-done {
  color: var(--brand);
  font-weight: 600;
}

.lesson-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 8px;
  padding: 0.4rem 0.65rem;
  cursor: pointer;
  font-size: 0.85rem;
}

.player-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.35rem 1rem calc(0.6rem + env(safe-area-inset-bottom));
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.14);
}

.player-progress-wrap {
  max-width: 1120px;
  margin: 0 auto 0.35rem;
}

#seek-bar {
  width: 100%;
  cursor: pointer;
}

@supports not (accent-color: auto) {
  #seek-bar {
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 4px;
    background: var(--border);
  }
}

.player-row {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.player-meta {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  flex: 1 1 200px;
}

.player-cover {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-alt);
  flex-shrink: 0;
}

.player-titles {
  min-width: 0;
}

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

.player-subtitle {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.ctrl-btn, .play-btn {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 999px;
  min-width: 40px;
  height: 40px;
  padding: 0 0.65rem;
  cursor: pointer;
  font-weight: 600;
}

.play-btn {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
  width: 46px;
  height: 46px;
}

.player-extra {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.player-time {
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

dialog {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  padding: 1rem 1.25rem;
  max-width: min(92vw, 760px);
  width: 100%;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
  overflow: hidden;
  overscroll-behavior: contain;
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.dialog-head h1 {
  margin: 0;
  font-size: 1.1rem;
}

.close-btn {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
}

.video-wrap video {
  width: 100%;
  max-height: 75vh;
  border-radius: 10px;
  background: #000;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.login-form input {
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}

.muted {
  color: var(--muted);
}

.error-text {
  color: #e05252;
  margin: 0;
  font-size: 0.9rem;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 2.5rem 1rem;
}
