/* ==========================================================================
   智慧树视频 — 浅色简约主题
   方向:浅色、克制、以内容(视频缩略图)为主角,参考 Linear / Vercel 后台。
   三条纪律:
   1. 颜色只出现在三处 — 头像、主按钮、空态插画;其余全是冷调灰阶。
   2. 层次靠发丝边框 + 低对比双层阴影,不靠大色块。
   3. 移动端优先可用:触控目标 ≥40px、无 hover-only 交互、输入字号 ≥16px、
      全程不横向溢出。
   ========================================================================== */

:root {
  /* 颜色 */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fbfbfc;
  --surface-hover: #f3f4f7;
  --border: #e7e9ee;
  --border-strong: #d6dae2;
  --text: #14161a;
  --muted: #6a7280;
  --accent: #5b5bd6;
  --accent-hover: #4d4dc4;
  --accent-wash: #eef0ff;
  --accent-line: #dfe2ff;
  --danger: #d92d20;

  /* 圆角 */
  --radius: 12px;
  --radius-sm: 9px;

  /* 阴影:近处贴边 + 远处扩散,两层 */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 10px 28px -8px rgba(15, 23, 42, .12);
  --shadow-lg: 0 24px 64px -12px rgba(15, 23, 42, .28);

  /* 字体:正文用系统中文字体栈(不引外部字体);等宽只给 URL 这类真正的代码文本 */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --empty-pad-top: 72px;
}

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

/* .skeletons / .menu / .modal 都显式设了 display,会盖掉 UA 的 [hidden]{display:none},
   必须显式兜底,否则首屏会看到骨架屏和空菜单 */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------------ 顶栏 */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, .82);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 24px;
}

.brand {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.01em;
  white-space: nowrap;
}

/* 品牌标记:纯 CSS 的圆角方块 + 播放三角(全站唯一的图形元素) */
.brand::before {
  content: "";
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  background: var(--accent);
}

.brand::after {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  background: #fff;
  clip-path: polygon(38% 26%, 38% 74%, 74% 50%);
}

.account { position: relative; min-width: 0; }

.account-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  transition: background .15s, border-color .15s;
}

.account-chip:hover { background: var(--surface-2); border-color: var(--border-strong); }
.account-chip .caret { flex: 0 0 auto; color: var(--muted); font-size: 10px; }

.avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}

.account-chip:not(.logged) .avatar { background: #c3c8d1; }

.account-name {
  min-width: 0;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 30;
  display: grid;
  min-width: 160px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.menu-item {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  background: none;
  border: none;
  border-radius: 7px;
  color: var(--text);
  text-align: left;
}

.menu-item:hover { background: var(--surface-hover); }
.menu-item.danger { color: var(--danger); }

/* -------------------------------------------------------------- 工具行 */

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.count {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- 按钮 */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .15s;
}

.btn:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: default; transform: none; }

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

.btn-block { width: 100%; }

/* ------------------------------------------------------------ 卡片网格 */

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

.card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .18s, transform .18s, border-color .18s;
}

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

.thumb {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: none;
  aspect-ratio: 16 / 9;
  background: #eceef2;
  overflow: hidden;
}

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

/* 中心亮、四周暗的柔光:比整片灰蒙版更像"视频",也让白色三角始终有对比度 */
.thumb .play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 50%, rgba(15, 23, 42, .5) 0%, rgba(15, 23, 42, .16) 68%);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  text-shadow: 0 1px 3px rgba(15, 23, 42, .45);
  opacity: 0;
  transition: opacity .18s;
}

.card:hover .thumb .play,
.thumb:focus-visible .play { opacity: 1; }

/* 触屏没有 hover:播放遮罩必须常显,否则手机上完全看不到播放入口 */
@media (hover: none) {
  .thumb .play { opacity: 1; }
  .card:hover { transform: none; box-shadow: var(--shadow-sm); border-color: var(--border); }
}

.card-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  min-width: 0;
}

.card-title {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.card-actions { display: flex; margin-top: auto; padding-top: 6px; }
.card-actions .btn { flex: 1; padding: 6px 10px; font-size: 13px; }

/* ------------------------------------------------- 空态 / 骨架屏 / 分页 */

.empty {
  position: relative;
  padding: var(--empty-pad-top) 20px 72px;
  color: var(--muted);
  text-align: center;
}

/* 空态插画:纯 CSS 的"播放"标记 — 首次打开页面时唯一有颜色的东西 */
.empty::before,
.empty::after {
  content: "";
  position: absolute;
  top: var(--empty-pad-top);
  left: 50%;
  width: 56px;
  height: 56px;
  margin-left: -28px;
  pointer-events: none;
}

.empty::before {
  border-radius: 16px;
  background: var(--accent-wash);
  box-shadow: inset 0 0 0 1px var(--accent-line);
}

.empty::after {
  background: var(--accent);
  clip-path: polygon(37% 26%, 37% 74%, 74% 50%);
}

/* 76px = 插画 56px + 间距 20px,插画是绝对定位的,这里要手动让位 */
.empty-title { margin: 76px 0 6px; font-size: 15px; font-weight: 500; color: var(--text); }
.empty-hint { margin: 0; font-size: 13px; }

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

.skeleton-card {
  height: 210px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(100deg, #eceef2 30%, #f5f6f8 50%, #eceef2 70%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.load-more { padding: 28px 0 8px; text-align: center; }
.hint { margin: 10px 0 0; color: var(--muted); font-size: 12px; }

/* ---------------------------------------------------------------- 弹窗 */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  padding-top: calc(20px + env(safe-area-inset-top));
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  background: rgba(15, 23, 42, .45);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 360px;
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  padding: 24px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
}

.modal-card.wide { max-width: 860px; padding: 0; overflow: hidden; }

.modal-title { margin: 0 0 18px; font-size: 17px; }

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 1;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.modal-close:hover { background: var(--surface-hover); color: var(--text); }

.player-modal .modal-card { background: #0b0d12; }
.player-modal .modal-close { color: #fff; background: rgba(255, 255, 255, .12); }
.player-modal .modal-close:hover { background: rgba(255, 255, 255, .22); color: #fff; }

#player { display: block; width: 100%; max-height: 70vh; background: #000; }

.player-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
  padding: 14px 16px;
  color: #fff;
}

.player-meta { flex: 1; min-width: 0; }
.player-title { margin: 0 0 2px; font-size: 14px; }
.player-url {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  color: #9aa1ad;
  word-break: break-all;
}

.player-bar .btn { flex: 0 0 auto; }

/* ---------------------------------------------------------------- 表单 */

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field span { font-size: 12px; color: var(--muted); }

.field input {
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}

.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91, 91, 214, .14); }

.form-error { margin: 0 0 12px; color: var(--danger); font-size: 12px; }

/* ---------------------------------------------------------------- 提示 */

.toast {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 60;
  max-width: calc(100vw - 40px);
  padding: 10px 16px;
  background: #14161a;
  border-radius: 10px;
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: rise .2s ease-out;
}

.toast.error { background: var(--danger); }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ------------------------------------------------------ 窄屏(手机) */

@media (max-width: 560px) {
  .topbar { padding-top: env(safe-area-inset-top); }

  .topbar-inner,
  .container {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }

  .container {
    padding-top: 16px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }

  /* 单列卡片 */
  .grid, .skeletons { grid-template-columns: 1fr; gap: 12px; }

  .account-name { max-width: 96px; }
  .toolbar { flex-wrap: wrap; }

  /* 触控目标 ≥40px */
  .btn { min-height: 40px; padding: 10px 16px; }
  .account-chip { min-height: 40px; padding: 8px 12px; }
  .menu-item { min-height: 44px; padding: 10px 12px; }
  .modal-close { top: 6px; right: 6px; width: 40px; height: 40px; }

  /* 16px 可避免 iOS 聚焦输入框时自动放大页面 */
  .field input { padding: 12px; font-size: 16px; }

  .empty { --empty-pad-top: 40px; }

  .modal {
    padding: 12px;
    padding-top: calc(12px + env(safe-area-inset-top));
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .modal-card { max-width: none; padding: 20px; }
  .player-bar { flex-direction: column; align-items: stretch; gap: 12px; }
  .player-bar .btn { width: 100%; }
  #player { max-height: 56vh; }

  .toast {
    left: max(16px, env(safe-area-inset-left));
    right: max(16px, env(safe-area-inset-right));
    bottom: calc(16px + env(safe-area-inset-bottom));
    max-width: none;
  }
}

@media (max-width: 360px) {
  .topbar-inner, .container { padding-left: 12px; padding-right: 12px; }
  .brand { font-size: 14px; }
  .brand::before, .brand::after { width: 16px; height: 16px; }
  .account-name { max-width: 72px; }
}

/* ------------------------------------------------------ 无障碍 / 动效 */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
