/* ==================== 主题变量 ==================== */
/* 深色（默认） — 高级深石板蓝 */
:root {
  /* 背景层级 */
  --bg-page: #0b0f1a;
  --bg-page-grad:
    radial-gradient(circle at 15% 0%, rgba(99, 102, 241, 0.12) 0%, transparent 45%),
    radial-gradient(circle at 95% 100%, rgba(56, 189, 248, 0.08) 0%, transparent 50%),
    #0b0f1a;
  --bg-surface: #11172a;
  --bg-surface-2: #1a2238;
  --bg-input: #0d1322;
  --bg-active: rgba(99, 102, 241, 0.14);
  --bg-thumb: #0d1322;
  --bg-badge: rgba(0, 0, 0, 0.65);
  --bg-mask: rgba(7, 11, 22, 0.7);

  /* 阴影 */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);
  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 8px 32px rgba(0, 0, 0, 0.4);
  --shadow-drawer: 4px 0 24px rgba(0, 0, 0, 0.5);

  /* 边框 */
  --border: rgba(255, 255, 255, 0.06);
  --border-2: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.16);

  /* 文本 */
  --text: #e7eaf2;
  --text-2: #b6bdcc;
  --text-muted: #8892a8;
  --text-dim: #5d6680;
  --text-on-accent: #ffffff;

  /* 主色 — 蓝紫渐变（Indigo → Violet） */
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-active: #4f46e5;
  --accent-soft: rgba(99, 102, 241, 0.16);
  --accent-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);

  /* 语义 */
  --success: #34d399;
  --error: #f87171;
  --warning: #fbbf24;

  --color-scheme: dark;
  --radius: 10px;
  --radius-lg: 14px;
}

/* 浅色 — 温暖米白 */
[data-theme='light'] {
  --bg-page: #f6f7fb;
  --bg-page-grad:
    radial-gradient(circle at 15% 0%, rgba(99, 102, 241, 0.08) 0%, transparent 45%),
    radial-gradient(circle at 95% 100%, rgba(139, 92, 246, 0.06) 0%, transparent 50%),
    #f6f7fb;
  --bg-surface: #ffffff;
  --bg-surface-2: #f1f3f8;
  --bg-input: #ffffff;
  --bg-active: rgba(99, 102, 241, 0.1);
  --bg-thumb: #e7ebf3;
  --bg-badge: rgba(15, 23, 42, 0.7);
  --bg-mask: rgba(15, 23, 42, 0.45);

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 60px rgba(15, 23, 42, 0.12);
  --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-drawer: 4px 0 24px rgba(15, 23, 42, 0.18);

  --border: rgba(15, 23, 42, 0.06);
  --border-2: rgba(15, 23, 42, 0.1);
  --border-strong: rgba(15, 23, 42, 0.16);

  --text: #1e293b;
  --text-2: #475569;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --text-on-accent: #ffffff;

  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-active: #4338ca;
  --accent-soft: rgba(99, 102, 241, 0.1);
  --accent-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);

  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;

  --color-scheme: light;
}

/* ==================== 基础 ==================== */
* {
  box-sizing: border-box;
}

html {
  color-scheme: var(--color-scheme);
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei',
    'Segoe UI', Roboto, sans-serif;
  background: var(--bg-page-grad);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.3s, color 0.3s;
}

a {
  color: inherit;
  text-decoration: none;
}

[hidden] {
  display: none !important;
}

button {
  font-family: inherit;
}

::selection {
  background: var(--accent-soft);
  color: var(--text);
}

/* ==================== 主题开关 toggle ==================== */
.theme-toggle {
  position: relative;
  width: 56px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid var(--border-2);
  background: var(--bg-surface-2);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.25s, border-color 0.25s;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

.theme-toggle::before {
  /* 滑块 */
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-grad);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.45);
  transition: transform 0.25s ease, background 0.25s;
}

[data-theme='light'] .theme-toggle::before {
  transform: translateX(0);
}

[data-theme='dark'] .theme-toggle::before,
:root:not([data-theme='light']) .theme-toggle::before {
  transform: translateX(26px);
}

.theme-toggle .ico {
  width: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-muted);
  z-index: 1;
  transition: color 0.25s, opacity 0.25s;
  pointer-events: none;
}

[data-theme='light'] .theme-toggle .ico-sun {
  color: #fff;
}

[data-theme='light'] .theme-toggle .ico-moon {
  opacity: 0.5;
}

[data-theme='dark'] .theme-toggle .ico-moon,
:root:not([data-theme='light']) .theme-toggle .ico-moon {
  color: #fff;
}

[data-theme='dark'] .theme-toggle .ico-sun,
:root:not([data-theme='light']) .theme-toggle .ico-sun {
  opacity: 0.5;
}

/* 浮动版（登录页右上角） */
.theme-toggle-floating {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10;
  box-shadow: var(--shadow-md);
}

/* ==================== 登录页 ==================== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
}

.login-card::before {
  /* 顶部装饰渐变条 */
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent-grad);
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.login-card .sub-en {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
  letter-spacing: 0.02em;
}

.login-card .sub {
  margin: 0 0 28px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
}

.login-card .sub-en-line {
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}

.login-form .label-en {
  color: var(--text-dim);
  font-style: italic;
  font-size: 12px;
}

.login-form label {
  display: block;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 8px;
  font-weight: 500;
}

.login-form input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.login-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.login-form button {
  margin-top: 22px;
  width: 100%;
  padding: 12px;
  background: var(--accent-grad);
  color: var(--text-on-accent);
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.login-form button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
}

.login-form button:active:not(:disabled) {
  transform: translateY(0);
}

.login-form button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-msg {
  min-height: 20px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--error);
}

.login-msg.ok {
  color: var(--success);
}

/* ==================== 首页布局 ==================== */
.app {
  display: grid;
  grid-template-columns: 360px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  padding: 24px 0 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.sidebar .chapter-list {
  flex: 1;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  position: sticky;
  bottom: 0;
}

.sidebar-footer .logout-btn {
  width: 100%;
}

.sidebar-mask {
  display: none;
}

.menu-btn {
  display: none;
}

.sidebar-header {
  padding: 0 20px 18px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.sidebar-header .subtitle-en {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  letter-spacing: 0.02em;
}

.sidebar-header .subtitle-en:empty {
  display: none;
}

.sidebar-header .meta {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.chapter-list {
  list-style: none;
  margin: 0;
  padding: 12px 12px;
}

.chapter-item {
  padding: 10px 12px;
  cursor: pointer;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background 0.15s;
  position: relative;
}

.chapter-item:hover {
  background: var(--bg-surface-2);
}

.chapter-item.active {
  background: var(--bg-active);
}

.chapter-item.active::before {
  /* 左侧高亮条 */
  content: '';
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  border-radius: 0 2px 2px 0;
  background: var(--accent-grad);
}

/* 缩略图 */
.chapter-item .thumb {
  position: relative;
  width: 96px;
  aspect-ratio: 16 / 9;
  flex-shrink: 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-thumb);
  box-shadow: var(--shadow-sm);
}

.chapter-item .thumb-img {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-color: var(--bg-thumb);
  transition: transform 0.35s ease;
}

.chapter-item:hover .thumb-img {
  transform: scale(1.06);
}

.chapter-item .index {
  position: absolute;
  top: 4px;
  left: 4px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--bg-badge);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  backdrop-filter: blur(4px);
}

.chapter-item.active .index {
  background: var(--accent);
}

.chapter-item .play-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg-badge);
  color: #fff;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 2px;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s, transform 0.2s;
  z-index: 2;
  backdrop-filter: blur(4px);
}

.chapter-item:hover .play-icon,
.chapter-item.active .play-icon {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.chapter-item.active .play-icon {
  background: var(--accent);
}

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

.chapter-item .title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  letter-spacing: -0.01em;
}

.chapter-item.active .title {
  color: var(--accent);
}

.chapter-item .title-en {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chapter-item .title-en:empty {
  display: none;
}

.chapter-item .duration {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

.chapter-item .duration:empty {
  display: none;
}

.main {
  padding: 32px 40px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: 0;
}

.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

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

.main-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.main-header .subtitle-en {
  margin-top: 3px;
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  letter-spacing: 0.02em;
}

.main-header .subtitle-en:empty {
  display: none;
}

.main-header .actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.logout-btn {
  background: transparent;
  border: 1px solid var(--border-2);
  color: var(--text-2);
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.logout-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.player-wrap {
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  box-shadow: var(--shadow-md);
}

.player-wrap video {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
}

.player-info {
  padding: 4px 4px;
}

.player-info h3 {
  margin: 0 0 4px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.player-info .subtitle-en {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
}

.player-info .subtitle-en:empty {
  display: none;
}

.player-info .desc {
  font-size: 13px;
  color: var(--text-muted);
}

.player-info .desc:empty {
  display: none;
}

/* ==================== 占位 ==================== */
.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  color: var(--text-muted);
  font-size: 14px;
}

/* ==================== 滚动条 ==================== */
.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

/* ==================== 响应式 ==================== */
@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 82vw;
    max-width: 320px;
    min-height: 0;
    z-index: 1000;
    border-right: 1px solid var(--border);
    border-bottom: none;
    max-height: none;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-drawer);
  }

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

  .sidebar-mask {
    display: block;
    position: fixed;
    inset: 0;
    background: var(--bg-mask);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    backdrop-filter: blur(4px);
  }

  .sidebar-mask.is-open {
    opacity: 1;
    pointer-events: auto;
  }

  .menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: transparent;
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    color: var(--text-2);
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color 0.15s, color 0.15s;
  }

  .menu-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
  }

  .main {
    padding: 16px 14px;
    gap: 16px;
  }

  .main-header h1 {
    font-size: 18px;
  }

  .main-header .subtitle-en {
    font-size: 12px;
  }

  .chapter-item .thumb {
    width: 88px;
  }
}
