/* v2 pages: home, first visit, one series, film, lesson head and Watch, offline, report (js/v2-library.js) */

/* ---------- small shared bits of these pages ---------- */
.lib-grow { flex: 1; }
.lib-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.lib-clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.btn.lib-dark { background: var(--ink); color: var(--on-ink); }
.btn.lib-dark:hover { background: var(--ink); opacity: .88; }

/* a film in a grid: cover, title, "5 段 · 4:49" */
.lib-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 12px; padding-top: 4px; }
.lib-tile { display: flex; flex-direction: column; gap: 6px; min-width: 0; color: inherit; }
.lib-tile img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: var(--radius-c); background: var(--paper-deep); }
.lib-tile-title { font-size: 16px; font-weight: 600; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lib-tile-meta { font-size: 13px; color: var(--ink-soft); }
.lib-tile:hover .lib-tile-title { text-decoration: underline; text-underline-offset: 3px; }
@media (min-width: 760px) {
  .lib-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 24px 16px; }
}

/* a row of chips that scrolls sideways */
.lib-chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 12px 0 16px; }
.lib-chips::-webkit-scrollbar { display: none; }
.lib-chips .chip { flex: none; display: inline-flex; align-items: center; }

/* ---------- home ---------- */
.lib-today { display: flex; flex-direction: column; gap: 14px; margin: 8px 0 0; padding: 16px; background: var(--card); border-radius: var(--radius); }
.lib-today-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.lib-streak { display: inline-flex; align-items: center; gap: 4px; color: var(--flame); font-weight: 700; font-size: 15px; }
.lib-streak svg { width: 18px; height: 18px; fill: currentColor; stroke: none; }
.lib-today-lines { font-size: 13px; color: var(--ink-soft); white-space: nowrap; }
.lib-goalbar { display: block; width: 72px; height: 6px; flex: none; border-radius: 3px; background: var(--paper-deep); overflow: hidden; }
.lib-goalbar span { display: block; height: 100%; border-radius: 3px; background: var(--caramel); }
.lib-today-film { display: flex; flex-direction: column; gap: 12px; color: inherit; }
.lib-today-film img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: var(--radius-m); background: var(--paper-deep); }
.lib-today-text { display: flex; flex-direction: column; gap: 4px; }
.lib-today-title { font-size: 20px; font-weight: 700; line-height: 1.3; }
.lib-today-meta { font-size: 13px; color: var(--ink-soft); }
.lib-today-film:hover .lib-today-title { text-decoration: underline; text-underline-offset: 3px; }
.lib-today-buttons { display: flex; gap: 8px; }
.lib-today-buttons .btn { min-height: 56px; font-size: 17px; font-weight: 700; }
.lib-today-buttons .lib-dark { padding: 0 22px; }
.lib-h1 { margin: 28px 0 0; font-size: 26px; font-weight: 800; }
/* wider: the cover on the left, the words and buttons on the right */
@media (min-width: 760px) {
  .lib-today { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); grid-template-rows: auto 1fr auto; gap: 12px 20px; padding: 18px; }
  .lib-today-film { display: contents; }
  .lib-today-film img { grid-column: 1; grid-row: 1 / 4; }
  .lib-today-row { grid-column: 2; grid-row: 1; }
  .lib-today-text { grid-column: 2; grid-row: 2; }
  .lib-today-buttons { grid-column: 2; grid-row: 3; }
}

/* ---------- first visit ---------- */
.lib-welcome { max-width: 480px; margin: 0 auto; }
.lib-welcome .popfox { height: 236px; margin: 12px 0 0; }
.lib-welcome .popfox img { height: 262px; }
.lib-welcome .under { margin-top: -34px; }
.lib-welcome-head { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 20px 24px 16px; text-align: center; }
.lib-welcome-head h1 { margin: 0; font-size: 26px; font-weight: 800; }
.lib-welcome-head p { margin: 0; font-size: 15px; color: var(--ink-soft); }
.lib-goals .v2-li:first-child { border-top: 1px solid var(--line); }
.lib-goal { position: relative; cursor: pointer; }
.lib-goal input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.lib-goal input:checked + .v2-radio { border: 7px solid var(--red); }
.lib-goal input:focus-visible + .v2-radio { outline: 3px solid var(--focus); outline-offset: 2px; }
.lib-goal-title { font-size: 17px; font-weight: 700; }
.lib-welcome-actions { display: flex; flex-direction: column; gap: 8px; padding-top: 24px; }
.lib-welcome-actions .btn { min-height: 56px; font-size: 17px; }
.lib-welcome-actions .btn-quiet { color: var(--ink); font-weight: 600; }

/* ---------- one series ---------- */
.lib-sort { position: relative; display: inline-flex; align-items: center; flex: none; }
.lib-sort select {
  -webkit-appearance: none; appearance: none; min-height: 44px; padding: 0 32px 0 12px; border: 0; border-radius: 999px;
  background: transparent; color: var(--ink); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; field-sizing: content;
}
.lib-sort select:hover { background: var(--paper-deep); }
.lib-sort select:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.lib-sort svg { position: absolute; right: 10px; width: 16px; height: 16px; pointer-events: none; }
.lib-search { display: flex; align-items: center; gap: 10px; height: 54px; padding: 0 14px; border-radius: var(--radius-c); background: var(--card); color: var(--ink-soft); }
.lib-search:focus-within { box-shadow: inset 0 0 0 2px var(--blue); }
.lib-search input { flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 16px; outline: none; }
.lib-search input::placeholder { color: var(--ink-faint); }
.lib-empty { margin: 24px 0; padding: 24px 16px; text-align: center; color: var(--ink-soft); font-size: 15px; background: var(--card); border-radius: var(--radius-l); }
@media (min-width: 760px) { .lib-search { max-width: 480px; } }

/* ---------- film page ---------- */
.lib-film-grid { display: flex; flex-direction: column; gap: 20px; }
.lib-film-head { display: flex; flex-direction: column; gap: 12px; }
.lib-film-cover { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: var(--radius-m); background: var(--paper-deep); margin-bottom: 2px; }
.lib-film-head h1 { margin: 0; font-size: 26px; font-weight: 800; line-height: 1.25; }
.lib-film-zh { margin: -6px 0 0; font-size: 15px; color: var(--ink-soft); }
.lib-film-meta { margin: 0; font-size: 14px; color: var(--ink-soft); }
.lib-progress-row { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--ink-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.lib-progress-row .bar { flex: 1; margin: 0; }
.lib-film-head .btn-primary { min-height: 56px; font-size: 17px; }
.lib-clips .v2-li-title { line-height: 1.35; }
.lib-clips .v2-li-meta { font-variant-numeric: tabular-nums; }
@media (min-width: 900px) {
  .lib-film-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 32px; align-items: start; }
}

/* ---------- a lesson's head ---------- */
.lib-modes { margin: 0 0 14px; }
.lib-next svg { width: 16px; height: 16px; }
@media (min-width: 760px) { .lib-modes { max-width: 480px; } }

/* ---------- Watch ---------- */
.lib-watch { display: flex; flex-direction: column; gap: 14px; }
.lib-watch-main { display: flex; flex-direction: column; gap: 4px; }
.lib-subs { margin-top: 6px; }

/* the shared player in Watch: the video with a round play button, the time row under it */
.player.watching { overflow: visible; background: transparent; border-radius: 0; }
.player.watching video { border-radius: var(--radius-m); }
.player.watching .subs { bottom: calc(54px + 5%); }
.player.watching .clip-bar { min-height: 44px; gap: 12px; padding: 10px 0 0; background: transparent; color: var(--ink-soft); }
.player.watching .clip-time { display: none; }
.player.watching .clip-play {
  position: absolute; left: 50%; top: calc((100% - 54px) / 2); z-index: 2; width: 72px; height: 72px; transform: translate(-50%, -50%);
  background: color-mix(in srgb, var(--night) 78%, transparent); color: #fff; transition: opacity .2s ease-out;
}
.player.watching .clip-play svg { width: 28px; height: 28px; }
.player.watching.playing .clip-play { opacity: 0; }
.player.watching.playing:hover .clip-play, .player.watching .clip-play:focus-visible { opacity: 1; }
.lib-clip-time { flex: none; min-width: 34px; font-size: 13px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
#libraryClipEnd { text-align: right; }
.player:not(.watching) .lib-clip-time { display: none; }
/* the clip's bar: thin, red up to where the video is (--lib-seek is set by js/v2-library.js) */
.player.watching #clipSeek { -webkit-appearance: none; appearance: none; flex: 1; height: 24px; margin: 0; background: transparent; }
.player.watching #clipSeek::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px; background: linear-gradient(to right, var(--red) var(--lib-seek, 0%), var(--line) var(--lib-seek, 0%));
}
.player.watching #clipSeek::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -4px; border: 0; border-radius: 50%; background: var(--red); }
.player.watching #clipSeek::-moz-range-track { height: 6px; border-radius: 3px; background: var(--line); }
.player.watching #clipSeek::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--red); }
.player.watching #clipSeek::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--red); }

/* the transcript: one grouped list, the playing line tinted */
.lib-transcript { display: flex; flex-direction: column; gap: 0; }
.lib-transcript li.lib-line { flex-shrink: 0; align-items: flex-start; gap: 10px; padding: 10px 4px 10px 12px; border-radius: 0; }
.lib-transcript li.lib-line:hover { background: var(--rule-soft); }
.lib-transcript li.lib-line.now { background: var(--blue-soft); box-shadow: none; outline: 0; }
.lib-transcript li > button.lib-line-time {
  display: block; flex: none; width: 38px; min-height: 24px; padding: 3px 0 0; border: 0; border-radius: 0; background: none; text-align: left;
  color: var(--ink-soft); font-size: 13px; font-variant-numeric: tabular-nums;
}
.lib-transcript li.now .lib-line-time { color: var(--blue); font-weight: 700; }
.lib-line-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; cursor: pointer; }
.lib-line-who { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.lib-line-en { font-size: 17px; font-weight: 600; line-height: 1.4; }
.lib-line-zh { font-size: 14px; color: var(--ink-soft); }
.lib-transcript li > button.lib-line-time:hover { background: none; color: var(--ink); }
.lib-line-tools { display: flex; flex: none; margin-top: -4px; }
.lib-flag, .lib-transcript .line-save {
  display: grid; place-items: center; width: 40px; height: 40px; min-height: 40px; padding: 0; border: 0; border-radius: 50%;
  background: none; color: var(--ink-faint);
}
.lib-flag svg { width: 18px; height: 18px; }
.lib-flag:hover, .lib-transcript .line-save:hover { background: var(--paper-deep); color: var(--ink); }
.lib-transcript .line-save[aria-pressed="true"], .lib-transcript .line-save[aria-pressed="true"] svg { color: var(--red-text); fill: var(--red-text); }

/* wide screens: the video stays on the left, the lines scroll beside it */
@media (min-width: 1000px) {
  .lib-watch { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 24px; align-items: start; }
  .lib-watch-main { position: sticky; top: 92px; }
  .lib-transcript { max-height: calc(100vh - 190px); overflow-y: auto; scrollbar-width: thin; }
}
@media (min-width: 1100px) { .lib-watch-main { top: 24px; } }

/* ---------- offline, and a video that will not load ---------- */
.lib-offline {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50; display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; background: var(--ink); color: var(--on-ink); font-size: 14px; line-height: 1.4;
}
.lib-offline svg { width: 16px; height: 16px; }
body.lib-offline-on { padding-top: var(--lib-banner-h, 0px); }
body.lib-offline-on .top { top: var(--lib-banner-h, 0px); }
.lib-video-error {
  position: absolute; top: 0; left: 0; right: 0; z-index: 3; aspect-ratio: 16 / 9; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; padding: 16px; text-align: center;
  background: var(--paper-deep); color: var(--ink); border-radius: inherit;
}
.player.watching .lib-video-error { border-radius: var(--radius-m); }
body.video-failed .player:not(.watching) { background: var(--paper-deep); }
.lib-video-error b { font-weight: 600; }
body.video-failed .player .clip-play { display: none; }
body.video-failed .player video { opacity: 0; }

/* ---------- report a line ---------- */
.lib-report-quote p { margin: 0; font-size: 15px; color: var(--ink-soft); }
.lib-report-quote p + p { margin-top: 4px; }
.lib-report-reasons { display: flex; flex-wrap: wrap; gap: 8px; }
.lib-report .chip { min-height: 40px; background: var(--paper); }
.lib-report .chip[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); }
.lib-report-note {
  width: 100%; min-height: 72px; padding: 12px 14px; resize: vertical; border: 1.5px solid transparent; border-radius: var(--radius-m);
  background: var(--paper); color: var(--ink); font: inherit; font-size: 17px; line-height: 1.5;
}
.lib-report .btn-primary { min-height: 56px; font-size: 17px; }
body.lib-sheet-open .toast { z-index: 45; }
