/* Library tab (library/view.js), laid out like Spotify's. The song rows and the player bar are Create's (.cr-row, .cr-art, .cr-player in
   create.css, which is loaded for the whole page); this file adds the sidebar of collections, the header of the open one, and the
   details dialog. Phone: one screen at a time (your library, then a playlist) with the player above the tab bar. 960 px and up: the
   sidebar and the open collection side by side. The tab does not scroll; the sidebar and the list do. The practice player it opens
   is styled in learn.css and scrolls the tab itself. */
.view.library { --cr-pl-h: 64px; }
.lib-home { height: 100%; }
.lib-app { position: relative; display: flex; flex-direction: column; height: 100%; }
.lib-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.lib-side, .lib-main { min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.lib-app[data-pane="home"] .lib-main, .lib-app[data-pane="list"] .lib-side { display: none; }

.lib-warn { margin: 8px 12px; padding: 10px 12px; border-radius: 12px; background: var(--rec-soft); color: var(--rec); font-size: 13px; }

/* ---- covers: an icon, one item's art, or four in a grid ---- */
.lib-cover { --s: 56px; position: relative; flex: none; display: grid; place-items: center; width: var(--s); height: var(--s); border-radius: 10px; overflow: hidden; color: #fff;
  background: linear-gradient(135deg, hsl(var(--h1, 230) 78% 58%), hsl(var(--h2, 285) 72% 38%)); }
.lib-cover > svg.i { width: 44%; height: 44%; stroke-width: 1.8; }
.lib-cover .cr-art { width: 100%; height: 100%; border-radius: 0; }
.lib-cover.mos { grid-template: 1fr 1fr / 1fr 1fr; }
.lib-cover.mos .cr-art .cr-art-ic { width: 46%; height: 46%; }
.lib-cover.liked { background: var(--cr-grad); }
.lib-cover.liked > svg.i { fill: currentColor; }
.lib-cover.all { background: linear-gradient(135deg, #3b5bfd, #8a4dff); }
.lib-cover.lg { --s: 148px; border-radius: 14px; box-shadow: 0 10px 32px rgba(0, 0, 0, .28); }

/* ---- the sidebar: Your Library ---- */
.lib-side-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: calc(12px + env(safe-area-inset-top)) 10px 6px 16px; }
.lib-side-head h1 { margin: 0; font: 700 22px/1.2 var(--font-display); letter-spacing: -0.01em; }
.lib-side-head .icon-btn { background: var(--raised); color: var(--ink); border-radius: 50%; }
.lib-side-head .icon-btn:hover { background: var(--line); }
.lib-side-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 8px 16px; display: flex; flex-direction: column; gap: 2px; }
.lib-coll { width: 100%; display: flex; align-items: center; gap: 12px; padding: 8px; border: 0; border-radius: 12px; background: none; color: inherit; text-align: left; }
.lib-coll:hover { background: var(--raised); }
.lib-coll.on { background: color-mix(in srgb, var(--cr-a2) 9%, var(--surface)); }
.lib-coll.drop { outline: 2px dashed var(--cr-a2); outline-offset: -2px; background: color-mix(in srgb, var(--cr-a2) 12%, var(--surface)); }
.lib-coll-t { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lib-coll-t b { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-coll-t small { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-coll.on .lib-coll-t b { color: var(--cr-a2); }
.lib-side-empty { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin: 10px 4px 0; padding: 14px; border-radius: 14px; background: var(--raised); border: 1px solid var(--line); }
.lib-side-empty b { font-size: 15px; }
.lib-side-empty span { font-size: 13px; color: var(--muted); line-height: 1.4; }
.lib-side-empty .btn { margin-top: 6px; }

/* ---- the open collection ---- */
.lib-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.lib-back { position: absolute; z-index: 4; left: 6px; top: calc(6px + env(safe-area-inset-top)); background: color-mix(in srgb, var(--surface) 70%, transparent); color: var(--ink); border-radius: 50%; }
.lib-hero { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: calc(34px + env(safe-area-inset-top)) 20px 14px; text-align: center;
  background: linear-gradient(180deg, hsl(var(--h1, 230) 60% 52% / .30), transparent); }
.lib-hero-t { min-width: 0; }
.lib-hero-t small { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.lib-hero-t h2 { margin: 4px 0 6px; font: 800 clamp(24px, 6vw, 28px)/1.12 var(--font-display); letter-spacing: -0.02em; overflow-wrap: anywhere; }
.lib-hero-t p { margin: 0; font-size: 13px; color: var(--muted); }
.lib-sticky { position: sticky; top: 0; z-index: 3; background: var(--bg); }
.lib-bar { display: flex; align-items: center; gap: 8px; padding: 8px 14px; }
.lib-bar .cr-search { flex: 1 1 160px; min-width: 0; max-width: 320px; margin-left: auto; }
.lib-bigplay { flex: none; display: grid; place-items: center; width: 54px; height: 54px; border: 0; border-radius: 50%; background: var(--cr-grad); color: #fff;
  box-shadow: 0 6px 22px color-mix(in srgb, var(--cr-a2) 35%, transparent); transition: transform .12s, filter .12s; }
.lib-bigplay svg.i { width: 24px; height: 24px; }
.lib-bigplay:hover:not(:disabled) { filter: brightness(1.06); transform: scale(1.04); }
.lib-bigplay:disabled { opacity: .45; box-shadow: none; }
.lib-bar .icon-btn.on { color: var(--cr-a2); background: none; }
.lib-bar .icon-btn[hidden] { display: none; }

/* pills: one row that scrolls sideways on a phone */
.lib-chips { display: flex; align-items: center; gap: 6px; padding: 2px 14px 8px; overflow-x: auto; scrollbar-width: none; }
.lib-chips[hidden] { display: none; }
.lib-chips::-webkit-scrollbar { display: none; }
.lib-chip { flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border-radius: 999px;
            border: 1px solid var(--line-strong); background: var(--surface); font-size: 13px; font-weight: 600; color: var(--ink); white-space: nowrap; }
.lib-chip small { font-size: 12px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.lib-chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.lib-chip[aria-pressed="true"] small { color: inherit; opacity: .7; }

.lib-rows { padding: 4px 8px 24px; }
/* picking several rows (the bar and the picked row are Create's .cr-selbar and .cr-row.msel) */
.lib-bar .lib-pick { flex: none; white-space: nowrap; }
.lib-bar .lib-pick[hidden] { display: none; }
.lib-bar .lib-pick svg.i { width: 16px; height: 16px; margin-right: 6px; }
.lib-bar .lib-pick[aria-pressed="true"] { background: color-mix(in srgb, var(--cr-a2) 14%, var(--surface)); border-color: var(--cr-a2); color: var(--cr-a2); }
.lib-sticky .cr-selbar { border-top: 1px solid var(--line); }
.lib-app.picking .lib-row, .lib-app.picking .lib-row .cr-thumb, .lib-app.picking .lib-row .cr-meta { cursor: pointer; }
.lib-row.msel .cr-art::after { content: "✓"; position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; border-radius: inherit;
  background: color-mix(in srgb, var(--cr-a2) 80%, transparent); color: #fff; font-size: 22px; font-weight: 700; }
.lib-row[draggable="true"] { cursor: default; }
.lib-menu-ck { margin-left: auto; display: inline-flex; }
.lib-menu-ck svg.i { color: var(--cr-a2); }
.lib-mn { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cr-pl-song .cr-like { flex: none; }
.lib-app .cr-player .icon-btn.on { color: var(--cr-a2); }

/* ---- desktop ---- */
@media (min-width: 960px) {
  .lib-body { grid-template-columns: minmax(280px, 330px) minmax(0, 1fr); }
  .lib-app[data-pane] .lib-main, .lib-app[data-pane] .lib-side { display: flex; }
  .lib-side { border-right: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 55%, var(--bg)); }
  .lib-side-head { padding: calc(18px + env(safe-area-inset-top)) 14px 8px 20px; }
  .lib-coll { --s: 48px; }
  .lib-coll .lib-cover { --s: 48px; }
  .lib-hero { flex-direction: row; align-items: flex-end; gap: 22px; padding: calc(28px + env(safe-area-inset-top)) 24px 18px; text-align: left; }
  .lib-hero .lib-cover.lg { --s: 160px; }
  .lib-hero-t h2 { font-size: clamp(28px, 3.6vw, 46px); }
  .lib-bar { padding: 10px 20px; }
  .lib-chips { padding: 2px 20px 10px; }
  .lib-rows { padding: 4px 12px 24px; }
}
@media (max-width: 959px) {
  .lib-coll.on { background: none; }                    /* on a phone the list is a menu, not a selection */
  .lib-coll.on .lib-coll-t b { color: inherit; }
  .lib-coll.on:hover { background: var(--raised); }
}
@media (max-width: 520px) {
  .lib-bar { flex-wrap: wrap; }                         /* the buttons on one line, the search box on its own below them */
  .lib-bar .cr-search { flex-basis: 100%; max-width: none; }
  .lib-bar .lib-pick { padding: 0 9px; }                /* Select: the tick alone, so the buttons stay on one line */
  .lib-bar .lib-pick span { display: none; }
  .lib-bar .lib-pick svg.i { margin: 0; }
  .lib-app .cr-pl-x { display: none; }                  /* shuffle and repeat: no room in the phone's player; shuffle is beside the big play button */
}

/* ---- details dialog ---- */
.lib-dmeta { margin: 0 0 4px; font-size: 13px; color: var(--muted); }
.lib-link { padding: 0; border: 0; background: none; color: var(--accent-text); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.lib-dacts { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.lib-dmain audio, .lib-dmain video { display: block; width: 100%; }
.lib-dmain .meta { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.lib-dh { margin: 18px 0 8px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.lib-dgroups { display: flex; flex-wrap: wrap; gap: 6px; }
.lib-gcheck { display: inline-flex; }
.lib-gcheck input { position: absolute; opacity: 0; pointer-events: none; }
.lib-gcheck span { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px; border-radius: 999px; cursor: pointer;
                   border: 1px solid var(--line-strong); background: var(--surface); font-size: 13px; font-weight: 600; }
.lib-gcheck span svg.i { width: 15px; height: 15px; }
.lib-gcheck input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.lib-gcheck input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.lib-newgroup { display: flex; gap: 6px; margin-top: 10px; }
.lib-newgroup input { flex: 1; min-width: 0; min-height: 36px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--surface); font-size: 15px; }
.lib-dstar[aria-pressed="true"] { color: var(--cr-a2); border-color: color-mix(in srgb, var(--cr-a2) 50%, var(--line-strong)); }
.lib-dstar[aria-pressed="true"] svg.i { fill: currentColor; }

/* Add music (the dialog and its buttons) */
.lib-side-btns { display: flex; gap: 6px; flex: none; }
.lib-bar .lib-add-btn { flex: none; white-space: nowrap; }
.lib-bar .lib-add-btn[hidden] { display: none; }
.cr-empty .btn { margin-top: 10px; }
.cr-empty .btn svg.i { width: 17px; height: 17px; margin: 0; color: inherit; }
.lib-add .lib-add-pick { align-self: flex-start; }
.lib-rights { display: flex; gap: 10px; align-items: flex-start; margin: 0; padding: 10px 12px; border-radius: 12px; font-size: 13px; line-height: 1.45;
  color: var(--ink); background: color-mix(in srgb, var(--warn) 14%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent); }
.lib-rights svg.i { flex: none; width: 18px; height: 18px; margin-top: 1px; color: var(--warn); }
.lib-check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 14px; font-weight: 400; color: var(--ink); cursor: pointer; }
.fld .lib-check input { flex: none; width: 20px; height: 20px; min-height: 0; padding: 0; margin: 0; accent-color: var(--accent); }
.lib-add .form-note.err { color: var(--rec); }
.lib-add-out:empty { display: none; }
.lib-add-fail { margin: 0 0 6px; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.lib-add-fail b { color: var(--ink); margin-right: 6px; }
.lib-steps { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; line-height: 1.45; color: var(--ink); }
.lib-steps a, .form-note a { color: var(--accent); text-decoration: underline; }
