:root {
  color-scheme: light dark;
  --bg: #f5f7fb;
  --surface: #ffffffcc;
  --surface-strong: #ffffff;
  --border: #e1e5ee;
  --text: #1b1f2a;
  --text-soft: #5f6575;
  --accent: #3461ff;
  --accent-soft: rgba(52, 97, 255, 0.16);
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  font-family: "Inter", "PingFang SC", "Hiragino Sans GB", "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

.app-header {
  padding: 24px clamp(16px, 4vw, 48px) 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.08em;
}

.brand-text h1 {
  margin: 0;
  font-size: clamp(1.4rem, 2vw, 1.8rem);
}

.brand-text p {
  margin: 4px 0 0;
  color: var(--text-soft);
  font-size: 0.95rem;
}

.course-switcher {
  display: inline-flex;
  gap: 12px;
  background: var(--surface-strong);
  padding: 6px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.course-switcher button {
  position: relative;
  border: none;
  background: transparent;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-soft);
  padding: 10px 22px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 120ms ease, color 120ms ease, background 160ms ease;
}

.course-switcher button:hover,
.course-switcher button:focus-visible {
  background: rgba(52, 97, 255, 0.08);
  color: var(--accent);
}

.course-switcher button.active {
  background: var(--accent);
  color: white;
  box-shadow: 0 8px 18px rgba(52, 97, 255, 0.35);
}

/* Player page navigation */
.player-nav {
  display: flex;
  align-items: center;
  gap: 16px;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface-strong);
  color: var(--text);
  text-decoration: none;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.95rem;
  transition: all 160ms ease;
  box-shadow: var(--shadow);
}

.back-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
  transform: translateY(-2px);
}

.course-info {
  padding: 8px 16px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
}

.app-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1.7fr);
  gap: clamp(24px, 4vw, 32px);
  padding: 0 clamp(16px, 4vw, 48px) clamp(24px, 5vw, 56px);
}

/* List page layout */
.list-layout {
  flex: 1;
  padding: 0 clamp(16px, 4vw, 48px) clamp(24px, 5vw, 56px);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* History panel styles */
.history-panel {
  background: var(--surface-strong);
  border-radius: 20px;
  padding: 20px;
  box-shadow: var(--shadow);
}

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

.history-header h2 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--text);
}

.clear-btn {
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 160ms ease;
}

.clear-btn:hover {
  background: var(--accent);
  color: white;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: none;
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  transition: all 160ms ease;
  text-align: left;
}

.history-item:hover {
  background: var(--accent-soft);
  transform: translateY(-2px);
}

.history-item .thumb {
  position: relative;
  width: 60px;
  height: 40px;
  border-radius: 8px;
  overflow: hidden;
  background: #101828;
  flex-shrink: 0;
}

.history-item .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-item .badge {
  position: absolute;
  top: 4px;
  left: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.8);
  color: #f8fafc;
  font-size: 0.7rem;
  font-weight: 600;
}

.history-item .content {
  flex: 1;
  min-width: 0;
}

.history-item .title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item .meta {
  font-size: 0.8rem;
  color: var(--text-soft);
}

/* Player page layout */
.player-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  gap: clamp(24px, 4vw, 32px);
  padding: 0 clamp(16px, 4vw, 48px) clamp(24px, 5vw, 56px);
}

.player-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.video-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 24px;
  background: #0f172a;
  overflow: hidden;
  box-shadow: var(--shadow);
}

#player {
  width: 100%;
  height: 100%;
  background: transparent;
  object-fit: cover;
}

.now-playing h2 {
  margin: 0 0 6px;
  font-size: clamp(1.2rem, 1.8vw, 1.5rem);
}

.now-playing p {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.95rem;
}

.playlist-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.playlist-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
}

.search {
  flex: 1 1 280px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.search .icon {
  font-size: 1rem;
  opacity: 0.6;
}

.search input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 1rem;
  color: var(--text);
}

.stats {
  font-size: 0.9rem;
  color: var(--text-soft);
}

.playlist {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  padding-bottom: 32px;
}

.playlist-item {
  list-style: none;
  display: flex;
  flex-direction: column;
  background: var(--surface-strong);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease;
  position: relative;
}

button.playlist-item {
  border: none;
  text-align: left;
}

.playlist-item:focus-visible,
.playlist-item:hover {
  transform: translateY(-6px);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14);
}

.playlist-item.active {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

.playlist-item .thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #101828;
}

.playlist-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 200ms ease;
}

.playlist-item:hover img {
  transform: scale(1.05);
}

.playlist-item .badge {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.76);
  color: #f8fafc;
  font-size: 0.75rem;
  font-weight: 600;
}

.playlist-item .title {
  padding: 14px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

.empty-state {
  padding: 48px;
  text-align: center;
  color: var(--text-soft);
  font-size: 0.98rem;
}

@media (max-width: 1024px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .player-layout {
    grid-template-columns: 1fr;
  }

  .playlist-panel {
    order: -1;
  }

  .playlist {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }

  /* Mobile player page - smaller video cards */
  .player-layout .playlist {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
  }
}

/* Mobile layout for player page - show related videos below player */
@media (max-width: 768px) {
  .player-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .player-layout .player-panel {
    order: 1;
  }

  .player-layout .playlist-panel {
    order: 2;
  }
}

@media (max-width: 720px) {
  .app-header {
    padding: 16px 16px 8px;
  }

  .course-switcher {
    width: 100%;
    justify-content: center;
  }

  .app-layout {
    padding: 0 16px 32px;
    gap: 20px;
  }

  .list-layout {
    padding: 0 16px 32px;
    gap: 16px;
  }

  .history-panel {
    padding: 16px;
  }

  .history-list {
    gap: 8px;
  }

  .history-item {
    padding: 10px;
  }

  .history-item .thumb {
    width: 50px;
    height: 35px;
  }

  .player-layout {
    padding: 0 16px 32px;
    gap: 20px;
  }

  .brand {
    width: 100%;
  }

  .player-nav {
    flex-direction: column;
    gap: 12px;
    width: 100%;
  }

  .back-btn {
    width: 100%;
    justify-content: center;
  }

  .now-playing h2 {
    font-size: 1.2rem;
  }

  .playlist-toolbar {
    gap: 12px;
  }

  .search {
    flex: 1 1 100%;
  }

  /* Extra small screens - even more compact layout */
  .player-layout .playlist {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
  }

  .player-layout .playlist-item .title {
    padding: 8px;
    font-size: 0.85rem;
  }

  .player-layout .playlist-item .badge {
    font-size: 0.7rem;
    padding: 2px 6px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #080c16;
    --surface: rgba(15, 23, 42, 0.76);
    --surface-strong: #111a2e;
    --border: rgba(148, 163, 184, 0.2);
    --text: #f8fafc;
    --text-soft: #94a3b8;
    --accent-soft: rgba(52, 97, 255, 0.26);
    --shadow: 0 16px 40px rgba(15, 23, 42, 0.45);
  }

  body {
    background: linear-gradient(150deg, #070a13 0%, #151f37 100%);
  }

  .brand-mark {
    background: rgba(52, 97, 255, 0.16);
  }

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

  .search {
    background: var(--surface);
  }
}
