/* «Что дальше», the builder (js/library/builder.js): the start (a first track or genres, the draft in work), then the
   loop: the set on the left, three cards after its last track on the right, each with the preview's waveform.
   The theme's tokens (theme.css); text on the canvas, cards on --raised. Loaded after next.css. */
#nextPane { max-width: var(--w-page); padding: var(--s-6) var(--s-5) var(--s-8); --wave-base: rgba(255, 255, 255, .2); --wave-played: rgba(255, 255, 255, .82); }
#nextPane .empty-state { margin: 8vh auto 0; }
.bld-loading { display: grid; place-items: center; min-height: 40vh; }
.spin.sm { width: 12px; height: 12px; border-width: 1.5px; margin-right: 6px; }
.bld-cap { color: var(--text-3); font: var(--t-caption); text-transform: uppercase; letter-spacing: .06em; margin-bottom: var(--s-2); }
.bld-row { display: flex; gap: var(--s-3); flex-wrap: wrap; justify-content: center; }

/* ---- the start */
.bld-start { max-width: var(--w-read); margin: 0 auto; }
.bld-start .sub { margin-bottom: var(--s-6); }
.bld-resume { margin-bottom: var(--s-6); }
.bld-resume:empty { display: none; }
.bld-rcard { display: flex; align-items: center; gap: var(--s-4); padding: var(--s-4) var(--s-5); background: var(--raised); border-radius: var(--r-l); }
.bld-rt { flex: 1; min-width: 0; display: grid; gap: 2px; }
.bld-rt b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bld-rt .muted { font: var(--t-small); }
.bld-search { display: flex; gap: var(--s-2); }
.bld-search input { flex: 1; }
.bld-genre { flex: none; max-width: 220px; height: 40px; }
.bld-genre.on { background: var(--accent-soft); color: var(--text); }
.bld-genre { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#bldErr { margin-top: var(--s-2); }
.bld-picks { margin-top: var(--s-3); display: grid; }
.bld-pick { display: flex; align-items: center; gap: var(--s-3); width: 100%; height: auto; min-height: var(--row-2); padding: 8px var(--s-3); border-radius: var(--r-m);
  background: transparent; text-align: left; font: var(--t-body); justify-content: flex-start; }
.bld-pick:hover:not(:disabled) { background: var(--fill); }
.bld-pick.on { background: var(--accent-soft); }
.bld-pick:disabled { background: transparent; opacity: .45; }
.bld-pt { flex: 1; min-width: 0; display: grid; }
.bld-pt b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bld-pt span { color: var(--text-2); font: var(--t-small); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bld-pick .num { flex: none; width: 34px; text-align: right; font: var(--t-small); font-feature-settings: var(--ff-num); }
.bld-ck { flex: none; width: 18px; color: var(--accent); }
.bld-go { position: sticky; bottom: var(--s-4); display: flex; align-items: center; gap: var(--s-3); margin-top: var(--s-4); min-height: 44px; }
.bld-go:empty { display: none; }
.bld-go button { height: 44px; padding: 0 28px; box-shadow: var(--shadow-float); }

/* the genre sheet */
.bld-gs { display: grid; gap: var(--s-3); }
.bld-gs label.switch span { display: grid; }
.bld-gl { display: grid; max-height: 52vh; overflow-y: auto; margin: 0 calc(-1 * var(--s-2)); }
.bld-g { justify-content: flex-start; gap: var(--s-2); width: 100%; height: 40px; padding: 0 var(--s-3); border-radius: var(--r-s); background: transparent; font: var(--t-body); }
.bld-g span:first-child { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bld-g .ic { color: var(--accent); }
.bld-g.on { color: var(--text); }

/* ---- the loop: the set | the cards */
.bld { display: grid; grid-template-columns: var(--w-side) minmax(0, 1fr); gap: var(--s-7); align-items: start; }
.bld-set { position: sticky; top: calc(var(--bar-h) + var(--s-4)); max-height: calc(100vh - var(--bar-h) - var(--s-6)); overflow-y: auto; min-width: 0; padding-right: 2px; }
.bld-count { font: var(--t-title); letter-spacing: -.01em; }
.bld-sg { color: var(--text-2); font: var(--t-small); margin-top: 2px; }
.bld-tl { list-style: none; margin: var(--s-4) 0 0; padding: 0; }
.bld-tr { display: flex; align-items: center; gap: var(--s-2); min-height: 44px; padding: 4px 0; }
.bld-tr .n { flex: none; width: 20px; color: var(--text-3); font: var(--t-small); }
.bld-tt { flex: 1; min-width: 0; display: grid; }
.bld-tt b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bld-tt span { color: var(--text-2); font: var(--t-small); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bld-tr > .num { flex: none; font: var(--t-small); font-feature-settings: var(--ff-num); min-width: 26px; text-align: right; }
.bld-tr.last .bld-tt b { color: var(--text); }
.bld-tr.new { animation: bld-new 900ms var(--ease-out); border-radius: var(--r-s); }
@keyframes bld-new { from { background: var(--accent-soft); } to { background: transparent; } }
.bld-lops { display: flex; flex: none; }
.bld-lops button.icon { width: 32px; height: 32px; }
.bld-seam { display: flex; align-items: center; gap: 6px; padding: 0 0 0 28px; color: var(--text-3); font: var(--t-caption); min-height: 18px; }
.bld-seam.risky { color: var(--warn); }
.bld-strip { margin-top: var(--s-3); padding: var(--s-3); background: var(--raised); border-radius: var(--r-m); display: grid; gap: var(--s-2); }
.bld-st1 { display: flex; justify-content: space-between; gap: var(--s-2); font: var(--t-small); }
.bld-st2 { display: flex; align-items: center; gap: var(--s-2); }
.bld-strip button.wide { height: 36px; font-size: 14px; }
.bld-sfoot { margin-top: var(--s-4); }
.bld-sfoot button { padding: 0; height: 28px; }

.bld-main { min-width: 0; }
.bld-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-4); }
.bld-h { font: var(--t-display); letter-spacing: -.02em; overflow-wrap: anywhere; }
.bld-sub { color: var(--text-2); margin-top: var(--s-1); }
.bld-tools { display: flex; gap: var(--s-2); flex: none; padding-top: 2px; }
.bld-status { min-height: 22px; margin: var(--s-3) 0 var(--s-4); color: var(--text-2); font: var(--t-small); display: flex; align-items: center; }

/* the three cards */
.bld-trio { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-4); transition: opacity var(--d-2) linear; }
.bld-trio.dim { opacity: .5; }
.bc { position: relative; display: flex; flex-direction: column; gap: var(--s-2); min-width: 0; padding: var(--s-4) var(--s-4) var(--s-4); background: var(--raised);
  border-radius: var(--r-l); box-shadow: inset 0 0 0 1px var(--hairline); cursor: pointer; transition: box-shadow var(--d-2) var(--ease-out), transform var(--d-3) var(--ease-out), opacity var(--d-3) var(--ease-out); }
.bc:hover { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .14); }
.bc.on { box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 70%, transparent), 0 12px 32px rgba(0, 0, 0, .35); cursor: default; }
.bc.taking { transform: scale(.94) translateX(-24px); opacity: .25; }
.bc.pulse .take { animation: bld-pulse 350ms var(--ease-out); }
@keyframes bld-pulse { 50% { transform: scale(1.08); } }
.bc-top { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); min-height: 18px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.bc-top .verdict { flex: none; }
.bc-t { font: 600 22px/27px var(--font-ui); letter-spacing: -.015em; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.bc-a { font: var(--t-small); min-height: 18px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; margin-top: -4px; }
.bc-num { display: flex; flex-wrap: wrap; gap: 4px var(--s-4); font: 500 15px/22px var(--font-ui); }
.bc-num .from { color: var(--text-3); font-weight: 400; }
.bc-num b { font-weight: 600; }
.bc-num .amber, .bc-num .amber b, .bc-num .amber .from { color: var(--warn); }
.bc-tr { min-height: 18px; }
.bc-wave { display: grid; grid-template-columns: 40px minmax(0, 1fr); align-items: center; gap: var(--s-3); margin-top: var(--s-2); position: relative; }
.bc-wave .play-btn.off { background: var(--fill); color: var(--text-3); }
.bc-time { position: absolute; right: 0; top: -16px; font: var(--t-caption); }
canvas.bw { display: block; width: 100%; height: 56px; cursor: pointer; touch-action: none; }
canvas.bw.sm { height: 28px; flex: 1; min-width: 0; }
canvas.bw.breath { animation: bld-breath 1.6s ease-in-out infinite; }
@keyframes bld-breath { 50% { opacity: .45; } }
.bc-st { min-height: 18px; display: flex; align-items: center; gap: 4px; }
.bc-act { display: flex; align-items: center; gap: var(--s-1); margin-top: auto; padding-top: var(--s-2); }
.bc-act .take { flex: 1; height: 40px; background: var(--accent); color: var(--on-light); font-weight: 600; }
.bc-act .take:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, #fff); }
.bc-act .take.locked { background: linear-gradient(90deg, var(--accent-soft) var(--ring, 0%), var(--fill) var(--ring, 0%)); color: var(--text-2); font-weight: 500; }
.bc-act .take.locked:hover:not(:disabled) { color: var(--text); }
.bc-act .take .ic { width: 16px; height: 16px; }
.bc-act .icon { width: 36px; flex: none; }
.bc:not(.on) .take:not(.locked) { background: var(--fill-strong); color: var(--text); }

.sk-card { gap: var(--s-3); min-height: 300px; cursor: default; }
.sk-card .bw-sk { height: 56px; margin-top: auto; border-radius: var(--r-s); }
.sk-card .bc-sk-btn { height: 40px; }

.bld-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-top: var(--s-4); flex-wrap: wrap; }
.bld-keys kbd { margin: 0 2px; }
.bld-note { margin-top: var(--s-3); color: var(--text-2); font: var(--t-small); text-align: center; }
.bld-empty { display: grid; justify-items: center; gap: var(--s-3); text-align: center; padding: var(--s-7) var(--s-4); background: var(--raised); border-radius: var(--r-l); }
.bld-empty h2 { font: var(--t-title); }
.bld-empty p { margin: 0; }

/* sheets */
.bld-save { display: grid; gap: var(--s-3); }
.bld-mix h3 { font: var(--t-caption); color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; margin: var(--s-5) 0 var(--s-2); }
.bld-mix p { margin: 0 0 var(--s-2); }
.bld-facts { display: grid; grid-template-columns: max-content 1fr; gap: var(--s-2) var(--s-4); margin: var(--s-4) 0 0; }
.bld-facts dt { color: var(--text-2); }
.bld-facts dd { margin: 0; }
.bld-moments, .bld-why { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.bld-moments li { display: flex; gap: var(--s-3); }
.bld-moments .num { color: var(--text-2); width: 40px; flex: none; }
.bld-why li::before { content: "·"; color: var(--text-3); margin-right: 8px; }
.bld-np p { margin: 0 0 var(--s-3); }
.bld-reasons { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-bottom: var(--s-3); }

/* the summary */
.bld-done { display: grid; justify-items: center; gap: var(--s-2); text-align: center; margin: 10vh auto 0; max-width: 440px; }
.bld-done .muted { margin: 0; }
.bld-name { margin: var(--s-2) 0 var(--s-4); padding: 6px 14px; border-radius: var(--r-pill); background: var(--fill); }
.bld-fan { position: relative; width: 120px; height: 96px; margin-bottom: var(--s-4); }
.bld-fan i { position: absolute; left: 30px; top: 8px; width: 60px; height: 80px; border-radius: 10px; background: var(--fill-strong); box-shadow: inset 0 0 0 1px var(--hairline);
  transform-origin: 50% 120%; animation: bld-fan 700ms var(--ease-out) both; animation-delay: calc(var(--i) * 50ms); --r: calc((var(--i) - 2) * 9deg); transform: rotate(var(--r)); }
@keyframes bld-fan { from { transform: rotate(0) translateY(20px); opacity: 0; } }

@media (max-width: 1000px) {
  .bld { grid-template-columns: minmax(0, 1fr); gap: var(--s-5); }
  .bld-set { position: static; max-height: none; order: 2; }
  .bld-trio { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}
@media (max-width: 640px) {
  #nextPane { padding: var(--s-5) var(--s-4) var(--s-7); }
  .bld-trio { grid-template-columns: minmax(0, 1fr); }
  .bld-head { flex-direction: column; }
  .bld-h { font: var(--t-title); }
  .bld-keys { display: none; }
  .sk-card { min-height: 220px; }
}
@media (prefers-reduced-motion: reduce) {
  .bc, .bc.taking { transition: none; }
  canvas.bw.breath, .bld-fan i, .bld-tr.new { animation: none; }
}
/* touch screens: a finger gets 36 px */
@media (hover: none) and (pointer: coarse) {
  .bld-lops button.icon { width: 36px; height: 36px; }
  .bld-sfoot button { height: 36px; }
}
.bc-wave .play-btn.wait { background: var(--fill-strong); color: var(--text); }
.bc-wave .play-btn.wait .spin { border-top-color: var(--text); }
