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

/* ─── Base ───────────────────────────────────────────────────────────────── */
body {
  background: #111;
  color: #eee;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
}

/* ─── Header ─────────────────────────────────────────────────────────────── */
header {
  background: #1a1a1a;
  border-bottom: 1px solid #2a2a2a;
  padding: 14px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 16px;
}

header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #fff;
}
header h1 span { color: #1d9bf0; }

.disk-info {
  display: flex;
  gap: 12px;
  font-size: 0.8rem;
  color: #888;
  white-space: nowrap;
}
.disk-info span {
  background: #222;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 2px 10px;
}

.back-btn {
  color: #1d9bf0;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
}
.back-btn:hover { text-decoration: underline; }

.author-link {
  color: #fff;
  text-decoration: none;
  font-size: 1rem;
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.delete-btn {
  align-self: center;
  background: transparent;
  border: 1px solid #ef4444;
  color: #ef4444;
  border-radius: 6px;
  padding: 0.2rem 0.7rem;
  font-size: 0.78rem;
  line-height: 1.4;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.delete-btn:hover:not(:disabled) { background: #ef4444; color: #fff; }
.delete-btn:disabled { opacity: 0.5; cursor: default; }
.author-link span { color: #1d9bf0; }
.author-link:hover span { text-decoration: underline; }

.count {
  font-size: 0.85rem;
  color: #666;
  white-space: nowrap;
}

.logout {
  margin-left: auto;
  color: #666;
  text-decoration: none;
  font-size: 0.82rem;
  white-space: nowrap;
}
.logout:hover { color: #aaa; }

/* 导航链接组（首页、喜欢页等） */
.header-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;        /* 推到右侧 */
  flex-shrink: 0;
}
.header-nav .logout { margin-left: 0; }

/* 作者页 header 中的标题 */
.header-author {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.header-author span { color: #1d9bf0; }

/* ─── Main layout ────────────────────────────────────────────────────────── */
main { padding: 28px 20px 48px; max-width: 1400px; margin: 0 auto; }

section { margin-bottom: 44px; }

section h2 {
  font-size: 1rem;
  font-weight: 600;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid #222;
}

/* ─── Grid & Cards ───────────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.card {
  background: #1a1a1a;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #222;
  transition: border-color 0.2s, transform 0.2s;
}
.card:hover { border-color: #444; transform: translateY(-2px); }

.thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
}

.thumb a {
  display: block;
  width: 100%;
  height: 100%;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 0.2s;
}
.thumb:hover img { opacity: 0.85; }

.thumb .no-thumb {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #222;
  color: #555;
  font-size: 2rem;
}

.play-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  background: rgba(0, 0, 0, 0.65);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  pointer-events: none;
  transition: background 0.2s, transform 0.2s;
}
.thumb:hover .play-btn {
  background: rgba(29, 155, 240, 0.85);
  transform: translate(-50%, -50%) scale(1.1);
}

.card-info { padding: 10px 12px; }
.card-info a {
  color: #1d9bf0;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
}
.card-info a:hover { text-decoration: underline; }

.card-meta {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  font-size: 0.75rem;
  color: #666;
}
.card-meta span { white-space: nowrap; }

.empty {
  color: #555;
  font-size: 0.9rem;
  padding: 20px 0;
}

/* ─── Play page ──────────────────────────────────────────────────────────── */
body.play {
  background: #000;
  display: flex;
  flex-direction: column;
}

body.play header { flex-shrink: 0; }

.player-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.player-wrap video {
  width: 100%;
  max-width: 1080px;
  max-height: calc(100vh - 80px);
  background: #000;
  border-radius: 8px;
  outline: none;
}

/* ─── Login page ─────────────────────────────────────────────────────────── */
body.login {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-box {
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 360px;
}

.login-box h1 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 28px;
  text-align: center;
  color: #fff;
}
.login-box h1 span { color: #1d9bf0; }

label {
  display: block;
  font-size: 0.82rem;
  color: #888;
  margin-bottom: 6px;
  margin-top: 18px;
}
label:first-of-type { margin-top: 0; }

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  background: #111;
  border: 1px solid #333;
  border-radius: 7px;
  color: #eee;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}
input:focus { border-color: #1d9bf0; }

.error {
  margin-top: 14px;
  padding: 9px 12px;
  background: rgba(220, 60, 60, 0.15);
  border: 1px solid rgba(220, 60, 60, 0.35);
  border-radius: 7px;
  color: #f87171;
  font-size: 0.85rem;
}

.login-box button {
  margin-top: 24px;
  width: 100%;
  padding: 11px;
  background: #1d9bf0;
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.login-box button:hover { background: #1a8cd8; }
.login-box button:active { background: #1677b3; }

/* ─── Timeline page ──────────────────────────────────────────────────────── */
.tl-wrap {
  overflow-x: auto;
}

.tl-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.tl-table th {
  text-align: left;
  padding: 9px 12px;
  background: #1a1a1a;
  color: #777;
  border-bottom: 1px solid #2a2a2a;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  white-space: nowrap;
}

.tl-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #1e1e1e;
  vertical-align: middle;
}

.tl-table tbody tr:hover td { background: #161616; }

.tl-table .center { text-align: center; }

.tl-table .num {
  color: #555;
  font-size: 0.8rem;
  text-align: right;
  padding-right: 8px;
}

.tl-table .author-cell a {
  color: #1d9bf0;
  text-decoration: none;
  font-weight: 500;
}
.tl-table .author-cell a:hover { text-decoration: underline; }
.tl-table .author-cell small { color: #666; font-size: 0.78rem; }
.tl-table .user-tl-link small { color: #555; }
.tl-table .user-tl-link:hover small { color: #1d9bf0; text-decoration: underline; }

.tl-table .snippet {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #ccc;
}

.tl-table .ops-cell { white-space: nowrap; }
.tl-table .no-video { color: #444; }

/* Thumbnail cell */
.tl-table .thumb-cell { padding: 6px 12px; }

.tl-thumb-wrap {
  position: relative;
  display: inline-block;
  line-height: 0;
}

.tl-thumb {
  width: 80px;
  height: 45px;
  object-fit: cover;
  border-radius: 4px;
  display: block;
  cursor: pointer;
  transition: opacity 0.15s;
}
.tl-thumb-wrap:hover .tl-thumb { opacity: 0.8; }

/* Large preview popup */
.tl-thumb-preview {
  display: none;
  position: fixed;
  z-index: 200;
  width: 320px;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.7);
  pointer-events: none;
  /* positioned via JS */
}
.tl-thumb-wrap:hover .tl-thumb-preview { display: block; }

/* Duration + size cell */
.meta-cell { line-height: 1.6; }
.meta-dur  { display: block; color: #ccc; font-size: 0.85rem; }
.meta-size { display: block; color: #666; font-size: 0.78rem; }

/* Download button (scoped, overrides .login-box button) */
.dl-btn {
  display: inline-block;
  width: auto;
  margin: 0;
  padding: 4px 14px;
  background: #1d9bf0;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.dl-btn:hover:not(:disabled) { background: #1a8cd8; }
.dl-btn:active:not(:disabled) { background: #1677b3; }
.dl-btn:disabled { background: #2a2a2a; color: #555; cursor: default; }
.dl-btn.downloaded { background: #14532d; color: #4ade80; border-color: #166534; cursor: default; }

/* Download item wrapper — fixed layout so progress bar appearing doesn't shift the button */
.dl-item {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  margin: 2px 4px 2px 0;
  vertical-align: top;
}

/* Progress bar — always reserve space (visibility toggled via hidden attr) */
.prog-wrap {
  width: 100px;
  height: 16px;          /* fixed height: 5px bar + 2px gap + ~9px text */
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: transparent;
}
.prog-wrap[hidden] {
  display: flex !important;   /* keep space even when hidden */
  visibility: hidden;
}

.prog-track {
  height: 5px;
  background: #222;
  border-radius: 4px;
  overflow: hidden;
  flex-shrink: 0;
}

.prog-bar {
  height: 100%;
  width: 0;
  background: #1d9bf0;
  border-radius: 4px;
  transition: width 0.25s ease;
}
.prog-bar.done  { background: #22c55e; }
.prog-bar.error { background: #ef4444; }

.prog-text {
  display: block;
  font-size: 0.7rem;
  color: #666;
  line-height: 1;
  white-space: nowrap;
}

.load-status {
  text-align: center;
  padding: 1.2rem;
  color: #666;
  font-size: 0.85rem;
}

/* ─── Star rating ────────────────────────────────────────────────────────── */
.star-rating {
  display: flex;
  gap: 2px;
  align-items: center;
}

.star {
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  color: #444;
  transition: color 0.12s, transform 0.1s;
  user-select: none;
}

.star.active { color: #f59e0b; }
.star:hover  { transform: scale(1.2); }

/* 卡片内只读星级 */
.card-stars {
  font-size: 0.82rem;
  letter-spacing: 1px;
  line-height: 1;
}
.card-stars .s-on  { color: #f59e0b; }
.card-stars .s-off { color: #3a3a3a; }

/* ─── Responsive ─────────────────────────────────────────────────────────── */

/* 平板 */
@media (max-width: 768px) {
  header {
    padding: 10px 16px;
    gap: 10px;
    flex-wrap: wrap;
  }

  header h1 { font-size: 1.1rem; }

  .disk-info { gap: 8px; font-size: 0.75rem; }

  main { padding: 20px 14px 40px; }

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

  /* 预览图缩小 */
  .tl-thumb { width: 64px; height: 36px; }
}

/* 手机 */
@media (max-width: 480px) {
  header {
    padding: 8px 12px;
    gap: 8px;
  }

  header h1 { font-size: 1rem; }

  /* 磁盘信息在最小屏幕缩小字号，不再隐藏 */
  .disk-info { font-size: 0.7rem; gap: 6px; }
  .disk-info span { padding: 2px 6px; }

  /* 导航组换行，撑满第二行 */
  .header-nav {
    width: 100%;
    margin-left: 0;
    gap: 10px;
    flex-wrap: wrap;
  }

  .back-btn { font-size: 0.82rem; }

  .logout { margin-left: auto; }

  main { padding: 14px 10px 36px; }

  section { margin-bottom: 30px; }

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

  .card-info { padding: 8px 10px; }

  /* 播放页 */
  .player-wrap { padding: 8px 0; }

  .player-wrap video {
    border-radius: 0;
    /* header 折两行约 90px，再留 10px 余量 */
    max-height: calc(100dvh - 100px);
    max-height: calc(100vh - 100px);  /* 回退：不支持 dvh 的浏览器 */
  }

  /* 播放页 header：第一行 返回+作者+退出，第二行 星级+删除 同行 */
  body.play header {
    flex-wrap: wrap;
    row-gap: 4px;
  }

  body.play header .back-btn { order: 1; }
  body.play header .author-link {
    order: 2;
    flex: 1;
    min-width: 0;
  }
  body.play header .logout { order: 3; margin-left: auto; }
  body.play header .star-rating {
    order: 4;
    flex: 1;                  /* 第二行，占剩余空间 */
    justify-content: flex-start;
  }
  body.play header .delete-btn {
    order: 4;                 /* 与星级同 order，同行显示 */
    align-self: center;
  }

  /* 时间线：表格转卡片布局 */
  .tl-wrap { overflow-x: visible; }

  .tl-table thead { display: none; }  /* 隐藏表头 */

  .tl-table,
  .tl-table tbody,
  .tl-table tr { display: block; }

  /* 每行变成一张卡片：预览图 | 作者+摘要 | 时长大小 */
  .tl-table tbody tr {
    background: #1a1a1a;
    border: 1px solid #222;
    border-radius: 10px;
    margin-bottom: 10px;
    padding: 10px;
    display: grid;
    grid-template-columns: 96px 1fr auto;
    grid-template-rows: auto auto;
    column-gap: 10px;
    row-gap: 6px;
  }
  .tl-table tbody tr:hover td { background: transparent; }

  /* 序号：隐藏 */
  .tl-table td.num { display: none; }

  /* 预览图：左列，跨两行 */
  .tl-table td.thumb-cell {
    grid-column: 1;
    grid-row: 1 / 3;
    padding: 0;
    align-self: start;
  }
  .tl-thumb { width: 96px; height: 54px; border-radius: 6px; }

  /* 作者：中列第一行 */
  .tl-table td.author-cell {
    grid-column: 2;
    grid-row: 1;
    padding: 0;
  }

  /* 时长/大小：右列第一行，顶部对齐 */
  .tl-table td.meta-cell {
    display: block;
    grid-column: 3;
    grid-row: 1;
    padding: 0;
    text-align: right;
    align-self: start;
  }

  /* 摘要：中列+右列第二行，允许换行 */
  .tl-table td.snippet {
    display: block;
    grid-column: 2 / 4;
    grid-row: 2;
    padding: 0;
    max-width: 100%;
    white-space: normal;
    font-size: 0.78rem;
    color: #999;
    overflow: visible;
  }

  /* 操作按钮：横跨全部列，底部 */
  .tl-table td.ops-cell {
    grid-column: 1 / -1;
    grid-row: 3;
    padding: 6px 0 0;
    border-top: 1px solid #222;
    white-space: normal;
    text-align: left;
  }

  .tl-table { font-size: 0.82rem; }

  /* 登录页 */
  .login-box {
    margin: 16px;
    padding: 28px 20px;
  }
}
