/* =========================================================
   Sona — track tiles view
   Самодостаточный файл: работает и без app.css (все токены с fallback).
   ========================================================= */

.track-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(140px, 15vw, 176px), 1fr));
  gap: 16px;
  align-items: stretch;
  min-width: 0;
}

.track-tiles > * { min-width: 0; }

/* ============ card ============ */

.track-tile {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 10px 10px 0;
  border-radius: var(--radius-lg, 18px);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.085));
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0) 48%),
    var(--panel, #111114);
  overflow: hidden;
  transition:
    transform 0.3s var(--ease, cubic-bezier(0.22, 1, 0.36, 1)),
    box-shadow 0.3s var(--ease, cubic-bezier(0.22, 1, 0.36, 1)),
    border-color 0.24s ease,
    background 0.24s ease;
}

.track-tile:hover {
  transform: translateY(-3px);
  border-color: var(--border-strong, rgba(255, 255, 255, 0.14));
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0) 52%),
    var(--panel-2, #17171b);
  box-shadow: 0 22px 46px -24px rgba(0, 0, 0, 0.85), 0 2px 10px rgba(0, 0, 0, 0.25);
}

.track-tile:focus-within {
  border-color: var(--border-strong, rgba(255, 255, 255, 0.14));
}

/* текущий трек — лаймовое кольцо и мягкое свечение */
.track-tile.is-current {
  border-color: rgba(184, 244, 92, 0.5);
  box-shadow: 0 0 0 1px rgba(184, 244, 92, 0.5), 0 18px 40px -18px rgba(184, 244, 92, 0.45);
}

.track-tile.is-current:hover {
  transform: translateY(-3px);
  box-shadow: 0 0 0 1px rgba(184, 244, 92, 0.62), 0 24px 50px -20px rgba(184, 244, 92, 0.5);
}

.track-tile.is-current .track-tile__title { color: var(--accent, #b8f45c); }

/* недоступный / плейсхолдер */
.track-tile.is-disabled {
  cursor: default;
  opacity: 0.66;
}

.track-tile.is-disabled:hover {
  transform: none;
  border-color: var(--border, rgba(255, 255, 255, 0.085));
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0) 48%),
    var(--panel, #111114);
  box-shadow: none;
}

.track-tile.is-disabled .track-tile__title { color: var(--text-2, #b7b7bf); }

/* ============ art ============ */

.track-tile__art {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: calc(var(--radius, 12px) + 2px);
  background: var(--panel-3, #202026);
  overflow: hidden;
  flex: 0 0 auto;
}

.track-tile__art .cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--cover-color, #202026);
  overflow: hidden;
}

.track-tile__art .cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.track-tile__art .cover__fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.5);
}

/* градиент для читаемости кнопки/времени */
.track-tile__art-shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.24) 0%,
    rgba(0, 0, 0, 0) 34%,
    rgba(0, 0, 0, 0) 56%,
    rgba(0, 0, 0, 0.64) 100%
  );
}

/* кнопка play */
.track-tile__play {
  position: absolute;
  right: 9px;
  bottom: 9px;
  z-index: 2;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 0;
  padding: 0;
  background: var(--accent, #b8f45c);
  color: var(--accent-ink, #0a0c07);
  cursor: pointer;
  opacity: 0;
  transform: translateY(6px) scale(0.94);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
  transition:
    opacity 0.22s var(--ease, cubic-bezier(0.22, 1, 0.36, 1)),
    transform 0.22s var(--ease, cubic-bezier(0.22, 1, 0.36, 1)),
    background 0.18s ease;
}

.track-tile:hover .track-tile__play,
.track-tile:focus-within .track-tile__play,
.track-tile.is-current .track-tile__play {
  opacity: 1;
  transform: none;
}

.track-tile__play:hover { background: var(--accent-strong, #c9ff78); transform: scale(1.06); }
.track-tile__play:active { transform: scale(0.98); }
.track-tile__play:focus-visible { outline: 2px solid var(--accent-strong, #c9ff78); outline-offset: 2px; }

/* недоступный вариант кнопки — «скачать/нет аудио» */
.track-tile__play--disabled {
  display: grid;
  place-items: center;
  background: var(--panel-3, #202026);
  color: var(--muted, #8a8a94);
  box-shadow: none;
  cursor: default;
  opacity: 1;
  transform: none;
}

/* эквалайзер текущего трека */
.track-tile__eq {
  position: absolute;
  left: 8px;
  top: 8px;
  z-index: 2;
  display: none;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
  padding: 4px 5px;
  border-radius: 7px;
  background: rgba(8, 8, 10, 0.6);
  backdrop-filter: blur(6px);
  pointer-events: none;
}

.track-tile.is-current .track-tile__eq { display: flex; }

.track-tile__eq i {
  display: block;
  width: 2px;
  border-radius: 2px;
  background: var(--accent, #b8f45c);
  transform-origin: bottom;
  animation: track-eq 0.9s ease-in-out infinite alternate;
}

.track-tile__eq i:nth-child(1) { height: 7px; animation-delay: -0.35s; }
.track-tile__eq i:nth-child(2) { height: 14px; animation-delay: -0.7s; }
.track-tile__eq i:nth-child(3) { height: 10px; animation-delay: -0.1s; }

@keyframes track-eq {
  from { transform: scaleY(0.35); }
  to { transform: scaleY(1); }
}

/* время на обложке */
.track-tile__time {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 2;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(8, 8, 10, 0.7);
  backdrop-filter: blur(6px);
  color: var(--text-2, #b7b7bf);
  font-size: 10.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

/* лайк (внутри обложки, справа сверху) */
.track-tile__like {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
}

.track-tile__like > * {
  position: static;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(8, 8, 10, 0.55);
  backdrop-filter: blur(6px);
  color: var(--text, #f5f5f2);
  opacity: 0.7;
  transition: background 0.18s ease, color 0.18s ease, opacity 0.18s ease;
}

.track-tile__like > *:hover,
.track-tile__like > *:focus-visible,
.track-tile:hover .track-tile__like > * {
  background: rgba(8, 8, 10, 0.78);
  color: var(--accent, #b8f45c);
  opacity: 1;
}

/* «лайк уже поставлен» — app.css красит .is-liked в акцент, нам достаточно видимости */
.track-tile__like > .is-liked { opacity: 1; }

/* ============ body ============ */

.track-tile__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 10px 2px 0;
}

.track-tile__title {
  display: block;
  min-width: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.012em;
  line-height: 1.3;
  color: var(--text, #f5f5f2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-tile__meta {
  display: block;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-tile__artist {
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--muted, #8a8a94);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
  max-width: 100%;
}

.track-tile__album {
  display: block;
  max-width: 100%;
  font-size: 10.5px;
  line-height: 1.35;
  color: var(--subtle, #5e5e68);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.track-tile__artist:hover,
.track-tile__album:hover {
  color: var(--text-2, #b7b7bf);
  text-decoration: underline;
}

/* ============ foot ============ */

.track-tile__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
  padding: 8px 2px 10px;
  min-width: 0;
  font-size: 10.5px;
  color: var(--subtle, #5e5e68);
  font-variant-numeric: tabular-nums;
}

.track-tile__date {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.track-tile__dur {
  flex: 0 0 auto;
  color: var(--muted, #8a8a94);
  font-weight: 600;
}

/* меню «⋯» — в правом нижнем углу карточки */
.track-tile__menu {
  position: absolute;
  right: 6px;
  bottom: 6px;
  z-index: 3;
}

.track-tile__menu > * {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted, #8a8a94);
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.track-tile:hover .track-tile__menu > *,
.track-tile__menu > *:focus-visible {
  opacity: 1;
}

.track-tile__menu > *:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text, #f5f5f2);
}

.track-tile__menu > *:focus-visible {
  outline: 2px solid var(--accent, #b8f45c);
  outline-offset: 1px;
}

/* если есть меню — не наезжаем на длительность */
.track-tile:has(.track-tile__menu) .track-tile__foot { padding-right: 30px; }

/* ============ toolbar ============ */

.track-view-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 4px 0 14px;
}

.track-view-bar__count {
  min-width: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted, #8a8a94);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============ selection mode ============ */

.track-tile.is-selecting { cursor: pointer; }

.track-tile.is-selected {
  border-color: rgba(184, 244, 92, 0.5);
  box-shadow: 0 0 0 1px rgba(184, 244, 92, 0.5), 0 18px 40px -18px rgba(184, 244, 92, 0.35);
}

.track-tile__select {
  position: absolute;
  right: 9px;
  bottom: 9px;
  z-index: 3;
  width: 32px;
  height: 32px;
  margin: 0;
  border-radius: 50%;
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(8, 8, 10, 0.7);
  backdrop-filter: blur(6px);
}

/* ============ drag reorder ============ */

.track-tile.is-dragging { opacity: 0.45; }

.track-tile.drop-before::after,
.track-tile.drop-after::after {
  content: '';
  position: absolute;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 3px;
  background: var(--accent, #b8f45c);
  z-index: 4;
  pointer-events: none;
}

.track-tile.drop-before::after { left: 3px; }
.track-tile.drop-after::after { right: 3px; }

/* ============ bulk selection ============ */

.bulk-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: -4px 0 14px;
}

.bulk-bar.is-active {
  padding: 8px 10px;
  border: 1px solid var(--border, rgba(255, 255, 255, 0.085));
  border-radius: 10px;
  background: var(--panel-2, #17171b);
}

.bulk-bar__count {
  margin-right: auto;
  color: var(--muted, #8a8a94);
  font-size: 11px;
}

.bulk-bar__count strong { color: var(--text, #f5f5f2); }

.track-select {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  padding: 0;
  margin: 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 5px;
  background: transparent;
  font: inherit;
  color: transparent;
  cursor: pointer;
  transition: background 0.16s, border-color 0.16s, color 0.16s;
}

.track-select svg { width: 12px; height: 12px; }

.track-select:hover { border-color: var(--text-2, #b9b9c2); }

.track-select.is-checked {
  background: var(--accent, #b8f45c);
  border-color: var(--accent, #b8f45c);
  color: var(--accent-ink, #0a0c07);
}

.track-row.is-selected { background: rgba(184, 244, 92, 0.08); }
.track-row.is-selected:hover { background: rgba(184, 244, 92, 0.12); }

/* ============ responsive ============ */

@media (max-width: 420px) {
  .track-tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .track-tile { padding: 8px 8px 0; border-radius: var(--radius, 12px); }
  .track-tile__title { font-size: 12.5px; }
  .track-tile__album { display: none; }
  .track-tile__foot { padding: 6px 2px 8px; }
}

@media (min-width: 1500px) {
  .track-tiles {
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 18px;
  }
}

/* тач / узкие экраны: play всегда виден, тап-таргеты крупнее */
@media (hover: none), (max-width: 720px) {
  .track-tile__play {
    width: 44px;
    height: 44px;
    opacity: 1;
    transform: none;
  }

  .track-tile__like > * { width: 36px; height: 36px; }
}

@media (prefers-reduced-motion: reduce) {
  .track-tile,
  .track-tile:hover,
  .track-tile__play {
    transition: none;
    transform: none;
    animation: none;
  }

  .track-tile__eq i { animation: none; transform: scaleY(1); }
}
