/* ---------- base ---------- */
:root {
  --bg: #0f1216;
  --panel: #1a1f27;
  --panel-2: #232a34;
  --fg: #e6e9ef;
  --muted: #8a93a3;
  --accent: #4ea1ff;
  --accent-2: #ffbe5c;
  --like: #ff4f7a;
  --ok: #4cd09a;
  --err: #ff6e6e;
  --radius: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg); color: var(--fg);
  user-select: none;
}
.muted { color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

.view { display: none; }
.view.active { display: block; }

/* ---------- auth ---------- */
#view-auth.active {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 360px;
  background: var(--panel); border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.auth-card h1 { margin: 0 0 4px; font-size: 22px; text-align: center; }
.auth-card .muted { text-align: center; margin: 0 0 20px; }
.auth-tabs {
  display: flex; gap: 4px; padding: 3px;
  background: var(--bg); border-radius: 8px; margin-bottom: 18px;
}
.auth-tabs .tab {
  flex: 1; background: transparent; color: var(--muted);
  border: none; border-radius: 6px; padding: 8px 0; font-size: 14px;
}
.auth-tabs .tab.active { background: var(--panel-2); color: var(--fg); }

#auth-form { display: flex; flex-direction: column; gap: 12px; }
#auth-form label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--muted);
}
#auth-form input, #auth-form select {
  padding: 10px 12px; font-size: 15px; font-family: inherit;
  background: var(--bg); color: var(--fg);
  border: 1px solid #3a4555; border-radius: 6px;
}
#auth-form input:focus, #auth-form select:focus {
  outline: none; border-color: var(--accent);
}
.auth-error {
  color: var(--err); font-size: 13px; min-height: 18px;
}
.primary {
  background: var(--accent); color: white; border: none;
  border-radius: 6px; padding: 12px; font-size: 15px; font-weight: 600;
  margin-top: 4px;
}
.primary:disabled { opacity: 0.5; }

/* ---------- feed ---------- */
#view-feed.active {
  display: flex; flex-direction: column;
  width: 100%; height: 100%;
}
.feed-topbar {
  position: absolute; top: 0; left: 0; right: 0;
  padding: calc(8px + var(--safe-top)) 10px 8px;
  display: flex; align-items: center; gap: 5px;
  z-index: 10; pointer-events: none;
}
.feed-topbar .brand { font-weight: 600; font-size: 14px; pointer-events: auto;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
}
.feed-topbar .spacer { flex: 1; min-width: 0; }
.icon-btn {
  pointer-events: auto;
  background: rgba(15, 18, 22, 0.6); color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 14px;
  padding: 5px 10px; font-size: 12px;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  white-space: nowrap;
}
.icon-btn:hover { background: rgba(35, 42, 52, 0.8); }
/* Narrow phones: 4 count-pills + 退出 + brand don't all fit. Drop the brand
   wordmark so the action pills stay roomy and readable. */
@media (max-width: 400px) {
  .feed-topbar .brand { display: none; }
  .feed-topbar { gap: 4px; padding-left: 8px; padding-right: 8px; }
  .feed-topbar .icon-btn { padding: 5px 8px; }
}

/* Stream tabs — the three top-level playback flows (推荐/播放列表/喜欢).
   Sits inside .feed-topbar; pointer-events:auto re-enabled per tab so swipe
   gestures keep passing through the rest of the topbar's transparent area. */
.stream-tabs {
  display: inline-flex; gap: 2px;
  background: rgba(15, 18, 22, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  padding: 3px;
  backdrop-filter: blur(6px);
  pointer-events: auto;
}
.stream-tab {
  background: transparent; color: rgba(255, 255, 255, 0.62);
  border: none; border-radius: 15px;
  padding: 5px 12px; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: background 0.18s ease, color 0.18s ease;
  pointer-events: auto;
}
.stream-tab:hover { color: rgba(255, 255, 255, 0.88); }
.stream-tab.active {
  background: var(--accent, #5b8cff);
  color: white;
}
.stream-tab.active:hover { color: white; }

.feed {
  flex: 1; height: 100%;
  overflow-y: scroll; overscroll-behavior: contain;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
}
.feed::-webkit-scrollbar { display: none; }

.clip-section {
  height: 100%; min-height: 100%;
  scroll-snap-align: start; scroll-snap-stop: always;
  position: relative;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  /* Top pad clears the topbar (~44px) + a comfortable gap so the cover's own
     corner badges (e.g. TED-Ed logo) don't visually butt against the pills. */
  padding: calc(76px + var(--safe-top)) 24px calc(80px + var(--safe-bottom));
  overflow: hidden;
}

/* Hero block (cover + title + meta) — slides upward and shrinks when
   subtitles appear, so the meta row sits well above the cue strip's fade. */
.clip-hero {
  position: relative; z-index: 1;
  width: 100%;
  display: flex; flex-direction: column; align-items: center;
  gap: 22px;
  transition: transform 0.42s cubic-bezier(0.4, 0, 0.2, 1),
              gap 0.32s ease;
  will-change: transform;
}
body.subs-on .clip-hero {
  transform: translateY(-22vh);
  gap: 12px;   /* tighter stack so title+meta land just under the small cover */
}
/* When subs-on, the album chip is a non-essential detail. Hide it so the
   hero block stays short enough that the meta row doesn't collide with the
   faded top of the cue strip. */
body.subs-on .album-chip { display: none; }

/* ---- ambient backdrop: blurred cover, light touch ---- */
.clip-bg { position: absolute; inset: 0; z-index: 0; overflow: hidden; }
.clip-bg-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover; object-position: center;
  /* Restrained blur — adds atmosphere without erasing the image. The dim is
     just deep enough that the foreground card has separation. */
  filter: blur(28px) brightness(0.55) saturate(1.15);
  transform: scale(1.18);    /* hide blurred edges only */
  opacity: 0; transition: opacity 0.45s ease-out;
}
.clip-bg-img.loaded { opacity: 1; }
.clip-bg::after {
  /* Soft vignette: title-area gets a subtle dim, bottom strip darker for the
     progress bar / side-rail to read against busy backgrounds. */
  content: "";
  position: absolute; inset: 0;
  background:
    radial-gradient(120% 70% at 50% 35%, transparent 0%, rgba(0,0,0,0.18) 75%, rgba(0,0,0,0.42) 100%),
    linear-gradient(180deg, rgba(0,0,0,0.18) 0%, rgba(0,0,0,0) 28%, rgba(0,0,0,0) 60%, rgba(0,0,0,0.55) 100%);
  pointer-events: none;
}

/* ---- foreground cover card: the actual hero ---- */
.clip-cover-frame {
  position: relative; z-index: 1;
  width: min(86%, 380px);
  aspect-ratio: 16 / 9;
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
  box-shadow:
    0 1px 0 rgba(255,255,255,0.08) inset,
    0 0 0 1px rgba(255,255,255,0.06),
    0 18px 48px rgba(0,0,0,0.55),
    0 4px 14px rgba(0,0,0,0.40);
  /* Sit slightly higher than dead-center for visual balance with the title. */
  margin-top: -16px;
  transition: width 0.32s ease, margin-top 0.32s ease;
}
/* Shrink the cover when reading subs so the hero is short enough not to
   collide with the cue strip's faded top. */
body.subs-on .clip-cover-frame {
  width: min(56%, 240px);
  margin-top: -8px;
}
.clip-cover {
  width: 100%; height: 100%;
  object-fit: cover; object-position: center;
  display: block;
  opacity: 0; transition: opacity 0.45s ease-out;
}
.clip-cover.loaded { opacity: 1; }

/* Placeholder when no thumbnail available (~6 upload-kind clips) */
.clip-cover-frame.no-cover {
  display: flex; align-items: center; justify-content: center;
  font-size: 64px; color: rgba(255,255,255,0.18);
  text-shadow: 0 2px 12px rgba(0,0,0,0.4);
  letter-spacing: -0.04em;
}

/* Play / pause indicator: lives ON the cover card, not floating in space */
.clip-cover-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(closest-side at 50% 50%, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0.30) 60%, transparent 100%);
  font-size: 56px; color: rgba(255,255,255,0.95);
  text-shadow: 0 4px 16px rgba(0,0,0,0.7);
  opacity: 0; transition: opacity 0.16s ease-out;
  pointer-events: none;
}
.clip-section.show-play .clip-cover-overlay,
.clip-section.is-paused .clip-cover-overlay { opacity: 1; }

/* ---- title + meta row ---- */
.clip-title {
  position: relative; z-index: 1;
  width: 100%; max-width: 520px;
  margin: 0; padding: 0 8px;
  text-align: center;
  font-size: 21px; font-weight: 600; line-height: 1.36;
  letter-spacing: -0.005em;
  color: #f4f6fa;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6), 0 6px 22px rgba(0,0,0,0.35);
  word-break: break-word;
  /* Cap to 3 lines so titles don't crowd the meta row on long YouTube headlines */
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
  transition: font-size 0.32s ease, -webkit-line-clamp 0.32s ease;
}
/* Subs-on: title shrinks + clamps to 2 lines so a long title can't reflow the
   hero tall enough to clash with the cue strip. */
body.subs-on .clip-title {
  font-size: 16px; line-height: 1.3;
  -webkit-line-clamp: 2;
}
.clip-meta {
  position: relative; z-index: 1;
  display: inline-flex; flex-wrap: wrap; justify-content: center;
  align-items: center; gap: 6px 8px;
  font-size: 12px; color: rgba(255,255,255,0.78);
  letter-spacing: 0.01em;
}
.clip-meta .meta-dot { color: rgba(255,255,255,0.32); font-weight: 600; }
.clip-meta .meta-level {
  font-weight: 700; letter-spacing: 0.04em;
  padding: 2px 8px; border-radius: 999px;
  background: rgba(15,18,22,0.55);
  border: 1px solid rgba(255,255,255,0.10);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.clip-meta .meta-level.lvl-A2  { color: #6be3a8; }
.clip-meta .meta-level.lvl-A2p { color: #6be0e0; }
.clip-meta .meta-level.lvl-B1  { color: #76a8ff; }
.clip-meta .meta-dur { font-variant-numeric: tabular-nums; }
.clip-meta .meta-tag { color: rgba(255,255,255,0.72); }

/* ---- right-side rail: rounded glass capsules ---- */
.clip-side {
  position: absolute; right: 14px;
  bottom: calc(96px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 14px;
  z-index: 2; align-items: center;
}
.side-btn {
  background: rgba(15,18,22,0.45);
  color: var(--fg); border: 1px solid rgba(255,255,255,0.08);
  width: 46px; height: 46px; padding: 0;
  border-radius: 50%;
  font-size: 22px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  transition: transform 0.12s ease, background 0.12s ease, color 0.12s ease;
  text-decoration: none;
}
.side-btn:hover  { background: rgba(35,42,52,0.65); transform: translateY(-1px); }
.side-btn:active { transform: translateY(0) scale(0.94); }
.side-btn .side-label {
  /* Tiny line under the icon. 11px (was 10px) — at 10px it dipped below the
     project's caption minimum and got hard to read on small phones. */
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: -17px; font-size: 11px; color: rgba(255,255,255,0.82);
  text-shadow: 0 1px 3px rgba(0,0,0,0.7);
  white-space: nowrap;
}
.side-btn .heart-icon { display: inline-block; transition: transform 0.18s ease; }
.side-btn.like.liked  { color: var(--like); border-color: rgba(255,79,122,0.42); background: rgba(255,79,122,0.14); }
.side-btn.like.liked .heart-icon { transform: scale(1.1); }
.side-btn.like.liked .side-label { color: var(--like); }
/* Favorite ("save for later") uses the warm accent so it reads as distinct
   from the pink Like button at a glance. */
.side-btn .star-icon { display: inline-block; transition: transform 0.18s ease; }
.side-btn.fav.favorited {
  color: var(--accent-2);
  border-color: rgba(255,190,92,0.42);
  background: rgba(255,190,92,0.14);
}
.side-btn.fav.favorited .star-icon { transform: scale(1.15) rotate(8deg); }
.side-btn.fav.favorited .side-label { color: var(--accent-2); }
/* CC (subtitle toggle) — text glyph so it reads as "字幕"/"closed captions" */
.side-btn.cc .cc-icon {
  font-size: 13px; font-weight: 700; letter-spacing: 0.04em;
  font-family: -apple-system, system-ui, sans-serif;
}
body.subs-on .side-btn.cc {
  color: var(--accent);
  border-color: rgba(78, 161, 255, 0.42);
  background: rgba(78, 161, 255, 0.14);
}
body.subs-on .side-btn.cc .side-label { color: var(--accent); }
/* List button — appears only in playlist / likes streams, opens the
   management overlay. */
.side-btn.list-btn .list-icon {
  font-size: 20px; line-height: 1;
}
/* Spacing between buttons so the labels don't touch the next button */
.clip-side .side-btn { margin-bottom: 8px; }
.clip-side .side-btn:last-child { margin-bottom: 0; }

/* ---- subtitle strip: scrolling cue list near the bottom ---- */
/* Default: transparent and at its rest position. Animates upward with the
   hero when body.subs-on, so they end up close together instead of leaving
   a big gap in the middle of the viewport. */
.clip-subtitles {
  position: absolute;
  /* Symmetric horizontal padding so text-align: center lines up with the
     actual screen center. The side rail (z-index 2, painted later in DOM)
     floats over the bottom-right corner; its backdrop-blur reads as a layer
     instead of a collision. */
  left: 16px;
  right: 16px;
  bottom: calc(28px + var(--safe-bottom));
  z-index: 2;
  max-height: 30vh;
  opacity: 0;
  pointer-events: none;
  transform: translateY(0);
  transition:
    opacity 0.32s ease,
    transform 0.42s cubic-bezier(0.4, 0, 0.2, 1);
  /* Top + bottom fade so non-active cues feather out instead of clipping. */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 22%, #000 78%, transparent 100%);
          mask-image: linear-gradient(to bottom, transparent 0, #000 22%, #000 78%, transparent 100%);
}
body.subs-on .clip-subtitles {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(-22vh);   /* matches the hero shift, closing the gap */
}
.clip-subtitles.empty { display: none; }   /* never show empty (overrides all) */
.clip-subtitles > .cues {
  height: 30vh;
  max-height: 30vh;
  overflow: hidden;       /* JS drives scrollTop */
  scroll-behavior: smooth;
  padding: 10vh 0;         /* room above first / below last cue so they can center */
}
.clip-subtitles .cue {
  margin: 0 0 8px;
  padding: 4px 10px;
  font-size: 15px;
  line-height: 1.45;
  letter-spacing: 0.005em;
  color: rgba(255, 255, 255, 0.42);
  text-align: center;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7);
  border-radius: 6px;
  transition: color 0.18s ease, transform 0.18s ease, background 0.18s ease;
  cursor: pointer;
}
.clip-subtitles .cue:hover { color: rgba(255, 255, 255, 0.7); }
.clip-subtitles .cue.active {
  color: #fff;
  font-weight: 600;
  font-size: 17px;
  background: rgba(15, 18, 22, 0.42);
  transform: scale(1.02);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.85);
}

/* progress bar at the bottom */
.clip-progress {
  position: absolute; left: 0; right: 0; bottom: var(--safe-bottom);
  height: 3px; background: rgba(255, 255, 255, 0.1); z-index: 2;
}
.clip-progress > .bar {
  height: 100%; background: var(--accent); width: 0%;
  transition: width 0.2s linear;
}

/* end-of-feed marker */
.feed-end {
  height: 100%; scroll-snap-align: start;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  color: var(--muted); gap: 12px; padding: 24px;
}
.feed-end button { background: var(--accent); color: white; border: none; border-radius: 8px; padding: 10px 18px; font-size: 14px; }

/* ---------- likes / favorites / playlist overlay ---------- */
#view-likes.active,
#view-favorites.active,
#view-playlist.active,
#view-history.active {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; flex-direction: column; z-index: 20;
}

/* ---------- "我的" drawer (slides in from the left) ----------------------- */
#view-drawer.active {
  position: fixed; inset: 0; z-index: 30;
  display: block;
}
.drawer-scrim {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  animation: drawer-scrim-in 0.18s ease-out;
}
/* "Instant re-open" mode: used when the drawer is restored after the user
   returns from a drawer-opened overlay. Suppresses the slide+fade so the
   drawer is visually identical to where they left it, instead of slamming
   back in. Cleared on next close so a genuine ☰ tap re-animates. */
#view-drawer.no-anim .drawer-scrim,
#view-drawer.no-anim .drawer-panel { animation: none; }
@keyframes drawer-scrim-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.drawer-panel {
  position: absolute; top: 0; left: 0; bottom: 0;
  width: min(86vw, 360px);
  background: var(--bg);
  border-right: 1px solid #2a313d;
  display: flex; flex-direction: column;
  padding: calc(12px + var(--safe-top)) 0 calc(16px + var(--safe-bottom));
  box-shadow: 6px 0 28px rgba(0, 0, 0, 0.45);
  animation: drawer-slide-in 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes drawer-slide-in {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}
.drawer-head {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 16px 14px;
}
.drawer-head .brand { font-size: 16px; font-weight: 600; flex: 1; }
.drawer-head .icon-btn { padding: 4px 10px; font-size: 18px; line-height: 1; }
.profile-card {
  background: var(--panel);
  margin: 0 12px 14px; padding: 14px 14px;
  border-radius: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.profile-row {
  display: grid; grid-template-columns: 78px 1fr;
  align-items: center; gap: 12px;
  font-size: 13px;
}
.profile-label { color: var(--muted); }
.profile-value { display: flex; align-items: center; gap: 10px; min-width: 0; }
.profile-text {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.profile-text.muted { color: var(--muted); }
.profile-select {
  flex: 1;
  background: var(--panel-2); color: var(--fg);
  border: 1px solid #2a313d; border-radius: 6px;
  padding: 5px 8px; font-size: 13px;
}
.profile-select:disabled { opacity: 0.6; }
.link-btn {
  background: transparent; color: var(--accent);
  border: none; padding: 2px 4px; font-size: 12px; cursor: pointer;
}
.link-btn:hover { color: #8db4ff; }
.profile-nickname-input {
  flex: 1; min-width: 0;
  background: var(--panel-2); color: var(--fg);
  border: 1px solid #2a313d; border-radius: 6px;
  padding: 5px 8px; font-size: 13px;
}
.profile-saving { margin: 0 14px; font-size: 11px; color: var(--muted); }

.drawer-actions {
  display: flex; flex-direction: column;
  padding: 0 6px;
  border-top: 1px solid #1a1f27;
  flex: 1; overflow-y: auto;
}
.drawer-action {
  background: transparent; color: var(--fg);
  border: none; border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  padding: 14px 14px;
  display: grid; grid-template-columns: 28px 1fr auto; gap: 10px;
  align-items: center;
  font-size: 14px; cursor: pointer;
  text-align: left;
}
.drawer-action:hover { background: rgba(255, 255, 255, 0.04); }
.drawer-action-icon { font-size: 16px; color: var(--accent); text-align: center; }
.drawer-action[data-go="likes"]     .drawer-action-icon { color: var(--like, #ff4f7a); }
.drawer-action[data-go="favorites"] .drawer-action-icon { color: var(--accent-2, #ffbe5c); }
.drawer-action-chevron { color: var(--muted); font-size: 18px; }
.drawer-logout {
  margin: 14px 12px 0;
  background: transparent;
  color: var(--like, #ff4f7a);
  border: 1px solid rgba(255, 79, 122, 0.42);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px; font-weight: 500;
  cursor: pointer;
}
.drawer-logout:hover { background: rgba(255, 79, 122, 0.08); }

/* Hamburger button on the topbar */
.menu-btn { padding: 4px 12px; font-size: 20px; line-height: 1; }
.menu-btn .menu-icon { font-weight: 700; letter-spacing: -0.04em; }

/* ---------- history overlay ---------------------------------------------- */
.history-chart-wrap {
  padding: 12px 14px 4px;
  border-bottom: 1px solid #1a1f27;
  background: var(--panel);
}
.history-chart-head {
  display: flex; gap: 14px; flex-wrap: wrap;
  font-size: 11px; color: var(--muted);
  margin-bottom: 8px;
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch {
  display: inline-block; width: 12px; height: 3px; border-radius: 2px;
}
.swatch-time { background: var(--accent, #5b8cff); }
.swatch-done { background: var(--accent-2, #ffbe5c); }
.history-chart {
  width: 100%; height: 140px;
  position: relative;
}
.history-chart svg { width: 100%; height: 100%; display: block; }
.history-chart .axis-label {
  font-size: 10px; fill: var(--muted);
}
.history-chart .grid-line { stroke: rgba(255, 255, 255, 0.06); stroke-width: 1; }
.history-chart .line-time { stroke: var(--accent, #5b8cff); stroke-width: 2; fill: none; }
.history-chart .line-done { stroke: var(--accent-2, #ffbe5c); stroke-width: 2; fill: none; stroke-dasharray: 4 3; }
.history-chart .dot-time { fill: var(--accent, #5b8cff); }
.history-chart .dot-done { fill: var(--accent-2, #ffbe5c); }
.history-chart .day-tick { font-size: 10px; fill: var(--muted); text-anchor: middle; }
.history-chart .value-tag { font-size: 10px; fill: var(--fg); text-anchor: middle; }

.history-list { padding: 8px 12px; }
.history-list li {
  display: grid; grid-template-columns: 1fr auto; gap: 10px;
  align-items: start;
}
.history-list .h-title { font-size: 14px; line-height: 1.36; }
.history-list .h-meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.history-list .h-when { font-size: 11px; color: var(--muted); white-space: nowrap; }
.history-list .h-badge {
  display: inline-block; font-size: 10px; padding: 1px 6px;
  border-radius: 8px; margin-left: 6px;
  background: rgba(78, 161, 255, 0.18); color: var(--accent, #5b8cff);
}
.history-list .h-badge.done { background: rgba(80, 200, 120, 0.18); color: #4dd28a; }
.overlay-topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + var(--safe-top)) 12px 8px;
  border-bottom: 1px solid #2a313d;
}
.overlay-topbar .brand { font-weight: 600; }
.likes-list {
  list-style: none; padding: 8px 12px; margin: 0;
  flex: 1; overflow-y: auto;
}
.likes-list li {
  background: var(--panel); border-radius: 8px;
  padding: 12px 14px; margin-bottom: 8px;
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
}
.likes-list .heart { color: var(--like); font-size: 18px; }
.likes-list .title { font-size: 14px; line-height: 1.4; }
.likes-list .meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.likes-list .play-here { background: var(--panel-2); color: var(--fg); border: none; border-radius: 6px; padding: 6px 10px; font-size: 12px; }

/* Row layout v2: title gets the full second column; meta + action buttons
   share a compact second row inside .row-body. Applied only to lists that
   render with the new structure (favorites-audio / likes / playlist / album).
   The 专辑 tab in 我的收藏 still uses the legacy single-row grid. */
.likes-list li:has(> .row-body) {
  grid-template-columns: auto 1fr;
}
.album-clip-list li:has(> .row-body),
.playlist-list li:has(> .row-body) {
  grid-template-columns: 32px 1fr;
}
.row-body {
  display: flex; flex-direction: column;
  min-width: 0;
}
.row-bottom {
  display: flex; align-items: center; gap: 8px;
  margin-top: 4px; min-width: 0;
}
.row-bottom .meta {
  flex: 1 1 auto; margin-top: 0; min-width: 0;
}
.row-actions {
  display: inline-flex; align-items: center; gap: 6px;
  flex-shrink: 0;
}
/* Compact action buttons inside the meta row — sized to match meta height
   instead of the old standalone play-icon (was 38×38). */
.likes-list .row-bottom .play-icon {
  width: 26px; height: 26px;
  font-size: 12px;
}
.likes-list .row-bottom .add-one,
.likes-list .row-bottom .remove-one {
  padding: 3px 8px; font-size: 11px;
  margin-right: 0; line-height: 1.4;
  min-height: 26px;
}

.likes-empty,
.likes-list li.likes-empty {
  display: block;
  background: transparent;
  border-radius: 0;
  margin-bottom: 0;
  padding: 60px 20px;
  text-align: center;
  color: var(--muted);
}
/* Favorites: gold star marker + thin resume-progress bar under the title. */
.favorites-list .star { color: var(--accent-2); font-size: 18px; }
.favorites-list .play-here.resume { background: var(--accent-2); color: #1c1404; font-weight: 600; }
.fav-progress {
  margin-top: 6px;
  height: 3px; border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.fav-progress > .bar {
  display: block; height: 100%;
  background: var(--accent-2);
}
.fav-resume-hint { color: var(--accent-2); font-weight: 600; }

/* ---- album chip (under the title on the play page) ---- */
.album-chip {
  position: relative; z-index: 1;
  display: inline-flex; align-items: center; gap: 8px;
  max-width: 86%;
  margin: -8px 0 -6px;   /* tuck closer to title/meta */
  padding: 6px 12px;
  font-size: 12px; font-family: inherit;
  color: rgba(255,255,255,0.92);
  background: rgba(15,18,22,0.55);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 999px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  cursor: pointer;
  transition: background 0.14s ease, transform 0.12s ease;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.album-chip:hover  { background: rgba(35,42,52,0.75); }
.album-chip:active { transform: scale(0.96); }
.album-chip .album-icon  { color: var(--accent-2); font-size: 14px; }
.album-chip .album-name  { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.album-chip .album-count {
  color: rgba(255,255,255,0.68);
  font-variant-numeric: tabular-nums;
  padding-left: 6px; border-left: 1px solid rgba(255,255,255,0.16);
}

/* ---- album overlay ---- */
#view-album.active {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; flex-direction: column; z-index: 25;
}
.album-meta {
  padding: 10px 16px 14px; font-size: 13px; color: var(--muted);
  border-bottom: 1px solid #2a313d;
  /* CTA-first layout: count text reads as supporting info, the add-all
     button is the page's primary action. */
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
}
.album-actions {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  justify-content: flex-end;
}
.album-meta .ghost.small {
  background: transparent; color: var(--muted);
  border: 1px solid rgba(255,255,255,0.18);
  padding: 5px 12px; font-size: 12px; font-weight: 500;
  border-radius: 999px; min-height: 28px;
  font-family: inherit; cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.album-meta .ghost.small:hover {
  color: var(--fg);
  border-color: rgba(255,255,255,0.32);
  background: rgba(255,255,255,0.04);
}
.album-meta .ghost.small:active { transform: scale(0.97); }
#album-fav-btn.favorited {
  color: var(--accent-2);
  border-color: rgba(255,190,92,0.42);
  background: rgba(255,190,92,0.14);
}
.album-clip-list li {
  grid-template-columns: 32px 1fr auto;
}
.album-clip-list .track-num {
  color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums;
  text-align: center;
}
.likes-list li.now-playing {
  background: linear-gradient(135deg, rgba(78,161,255,0.16), rgba(78,161,255,0.06));
  border: 1px solid rgba(78,161,255,0.28);
}
.album-clip-list li.now-playing .track-num,
.playlist-list li.now-playing .track-num { color: var(--accent); }
/* Icon-only play/pause button in each clip-list row (album, favorites, likes,
   playlist — all share the .likes-list parent class). Reuses .play-here for
   click delegation, but layout is a circular icon — not a labeled CTA. */
.likes-list .play-icon {
  width: 38px; height: 38px;
  padding: 0; border-radius: 50%;
  font-size: 14px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.06);
  color: var(--fg);
  border: 1px solid rgba(255,255,255,0.14);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.likes-list .play-icon:hover {
  background: rgba(255,255,255,0.10);
  border-color: rgba(255,255,255,0.28);
}
.likes-list .play-icon.playing {
  background: var(--accent); color: white;
  border-color: var(--accent);
}

/* ---- favorites tabs ---- */
.fav-tabs {
  display: flex; gap: 4px; padding: 8px 12px 0;
  border-bottom: 1px solid #2a313d;
}
.fav-tab {
  flex: 1; background: transparent; color: var(--muted);
  border: none; padding: 10px 0; font-size: 14px;
  border-bottom: 2px solid transparent;
  font-family: inherit; cursor: pointer;
}
.fav-tab.active {
  color: var(--fg);
  border-bottom-color: var(--accent-2);
}
.fav-tab span {
  display: inline-block; margin-left: 4px;
  font-size: 11px; color: var(--muted);
  background: var(--panel); border-radius: 999px;
  padding: 1px 7px; font-variant-numeric: tabular-nums;
}
.fav-tab.active span { color: var(--fg); }

/* ---------- playlist + multi-select ---------- */

/* Overlay topbar gains a spacer so the right-side controls (select-toggle,
   album-fav, clear) push to the far edge. */
.overlay-topbar .spacer { flex: 1; }

/* Inline + button per row — sits between the title/meta block and the
   primary action (play / view). Ghost-style on purpose so the primary
   row action (播放 / 查看) reads as the dominant CTA. */
.likes-list .add-one,
.likes-list .add-album-one {
  background: transparent; color: rgba(255,190,92,0.78);
  border: 1px solid rgba(255,190,92,0.22);
  padding: 6px 10px; font-size: 12px; border-radius: 6px;
  margin-right: 6px; white-space: nowrap;
  line-height: 1;
}
.likes-list .add-one:hover,
.likes-list .add-album-one:hover {
  background: rgba(255,190,92,0.16);
  color: var(--accent-2);
  border-color: rgba(255,190,92,0.42);
}
/* Destructive — kept visually quieter than 播放 so an accidental tap doesn't
   delete an item. Transparent background, muted color until hover. */
.likes-list .remove-one {
  background: transparent; color: rgba(255,110,110,0.62);
  border: 1px solid rgba(255,110,110,0.18);
  padding: 6px 10px; font-size: 14px; border-radius: 6px; margin-right: 6px;
  line-height: 1;
}
.likes-list .remove-one:hover {
  background: rgba(255,110,110,0.12);
  color: var(--err);
  border-color: rgba(255,110,110,0.42);
}

/* Row grid widens to fit the extra +/remove button without crowding. The
   existing 3-column favorites/likes rows extend to 4 cols. */
.likes-list li {
  grid-template-columns: auto 1fr auto auto;
}
.album-clip-list li {
  grid-template-columns: 32px 1fr auto auto;
}

/* Row checkbox — hidden by default; shown only when the list is in
   select-mode. The leading icon (★/❤/track-num) hides in select-mode so
   we don't end up with TWO leading badges. */
.row-check { display: none; align-items: center; justify-content: center; width: 22px; }
.row-check input[type="checkbox"] {
  width: 18px; height: 18px;
  accent-color: var(--accent-2);
  cursor: pointer;
}
ul.select-mode .row-check { display: inline-flex; }
ul.select-mode .star,
ul.select-mode .heart,
ul.select-mode .track-num { display: none; }
ul.select-mode .add-one,
ul.select-mode .play-here,
ul.select-mode .remove-one { display: none; }
ul.select-mode li { cursor: pointer; }
ul.select-mode li.selected {
  background: linear-gradient(135deg, rgba(255,190,92,0.18), rgba(255,190,92,0.06));
  border: 1px solid rgba(255,190,92,0.32);
}
/* In select-mode the grid only needs 2 cols: checkbox + title; everything
   else is display:none. */
ul.select-mode li {
  grid-template-columns: auto 1fr;
}

/* Bottom-anchored selection bar. Slides up under the list, doesn't push
   the list around. */
.selection-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: var(--panel);
  border-top: 1px solid #2a313d;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.35);
}
.selection-bar .spacer { flex: 1; }
.selection-bar .primary {
  margin: 0; padding: 9px 16px; font-size: 13px;
  border-radius: 8px;
}
.selection-bar .primary:disabled {
  background: var(--panel-2); color: var(--muted);
}

/* Add-all button: this is the page's primary CTA. Slightly heavier weight
   than the ghost sibling, but the same compact pill height so the action row
   reads as a unified group instead of two mismatched buttons. */
.album-meta .primary.small {
  padding: 5px 14px; font-size: 12px; font-weight: 600; margin: 0;
  border-radius: 999px;
  min-height: 28px;
}
.album-meta .primary.small:hover {
  filter: brightness(1.12);
}
.album-meta .primary.small:active {
  transform: scale(0.97);
}

/* Playlist list — re-uses the favorites visual scaffold. Track number stays
   muted (matches .album-clip-list) so blue is reserved for the "now playing"
   state across both surfaces. */
.playlist-list .track-num {
  color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums;
  width: 28px; text-align: center;
}
.playlist-list li {
  grid-template-columns: 32px 1fr auto auto;
}
#playlist-clear-btn { color: var(--err); border-color: rgba(255,110,110,0.32); }

/* Toast pill — single-line confirmation for adds / errors. */
#app-toast {
  position: fixed; left: 50%; bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: rgba(20,24,30,0.92); color: var(--fg);
  border: 1px solid rgba(255,255,255,0.10);
  padding: 9px 16px; border-radius: 999px;
  font-size: 13px; backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  opacity: 0; pointer-events: none; z-index: 100;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
#app-toast.show {
  opacity: 1; transform: translateX(-50%) translateY(0);
}

/* desktop: cap section width and add a frame so scroll-snap is still snappy */
@media (min-width: 720px) {
  .clip-content { max-width: 560px; }
  .clip-title { font-size: 28px; }
  .clip-side { right: max(40px, calc((100vw - 600px) / 2 - 60px)); }
  .feed-topbar { padding: 14px 20px; }
}
