:root {
  color-scheme: dark;

  --bg: #000000;
  --surface-1: #0f0f11;
  --surface-2: #1a1a1d;
  --surface-3: #242428;
  --surface-sheet: #1c1c1e;
  --surface-toast: #252528;

  --hairline: rgba(255, 255, 255, 0.07);
  --border-focus: rgba(255, 255, 255, 0.16);

  --text: #f5f5f7;
  --text-2: rgba(235, 235, 245, 0.62);
  --text-3: rgba(235, 235, 245, 0.34);

  --accent-yt: #ff0000;
  --accent-sc: #ff5500;
  --accent-blue: #8774e1;
  --success: #30d158;
  --danger: #ff6b6b;

  --r-xs: 8px;
  --r-sm: 12px;
  --r-md: 16px;
  --r-sheet: 20px 20px 0 0;
  --r-pill: 9999px;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-ios: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --gutter: 10px;
  --safe-top: var(--tg-content-safe-area-inset-top, 0px);
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));

  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { overflow: hidden; overscroll-behavior: none; font-size: 15px; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
img { display: block; }
[hidden] { display: none !important; }

.i {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ───────────── Pages ───────────── */
.app-page {
  position: fixed; inset: 0;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  padding-top: var(--safe-top);
  padding-bottom: calc(24px + var(--safe-bottom));
}
.app-page.page-enter { animation: page-in .32s var(--ease-ios) both; }
.app-page.page-leave { animation: page-out .24s var(--ease-ios) both; pointer-events: none; }
@keyframes page-in { from { transform: translateX(28%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes page-out { to { transform: translateX(30%); opacity: 0; } }
.page-hidden { visibility: hidden; }

/* ───────────── Header / brand ───────────── */
.home-top { padding: 18px 14px 6px; transition: opacity .2s, margin .25s var(--ease-out); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 30px; height: 21px; }
.brand-name { font-size: 19px; font-weight: 700; letter-spacing: -0.2px; }
body.searching .home-top { display: none; }

/* ───────────── Search ───────────── */
.search-sticky {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding: 10px var(--gutter) 6px;
}
.field {
  display: flex; align-items: center; gap: 6px;
  height: 46px; padding: 0 6px 0 10px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  transition: border-color .2s;
}
.field:focus-within { border-color: var(--border-focus); }
.search-ico { position: relative; width: 28px; height: 28px; display: grid; place-items: center; color: var(--text-2); }
.search-ico .i { position: absolute; transition: opacity .18s, transform .25s var(--ease-out); }
.search-back { opacity: 0; transform: translateX(6px); color: var(--text); }
body.searching .search-glass { opacity: 0; transform: translateX(-6px); }
body.searching .search-back { opacity: 1; transform: none; }
#q {
  flex: 1; min-width: 0; height: 100%;
  background: transparent; border: 0; outline: 0;
  color: var(--text); font-size: 16px;
  -webkit-appearance: none; appearance: none;
}
#q::placeholder { color: var(--text-3); }
#q::-webkit-search-cancel-button { display: none; }
.search-clear {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(235, 235, 245, 0.3); color: var(--surface-2);
}
.search-clear .i { width: 14px; height: 14px; stroke-width: 2.6; }

/* Suggestions */
.suggest-wrap {
  margin-top: 8px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  overflow: hidden;
  animation: fade-down .18s var(--ease-out);
}
@keyframes fade-down { from { opacity: 0; transform: translateY(-4px); } }
.suggest { list-style: none; margin: 0; padding: 0; }
.suggest-item {
  display: flex; align-items: center; gap: 12px;
  height: 48px; padding: 0 8px 0 14px;
  border-bottom: 1px solid var(--hairline);
  color: var(--text-2); cursor: pointer;
}
.suggest-item:last-child { border-bottom: 0; }
.suggest-item:active { background: var(--surface-3); }
.suggest-glass { width: 18px; height: 18px; color: var(--text-3); }
.suggest-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.suggest-text b { color: var(--text); font-weight: 700; }
.suggest-fill { width: 36px; height: 36px; display: grid; place-items: center; color: var(--text-3); }
.suggest-fill .i { width: 18px; height: 18px; }

/* Chips */
.chips {
  position: relative; display: flex; gap: 8px; padding-top: 10px;
  overflow-x: auto; scrollbar-width: none;
  margin: 0 calc(-1 * var(--gutter)); padding-left: var(--gutter); padding-right: var(--gutter);
}
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; }
.chip {
  height: 34px; padding: 0 14px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border-focus);
  font-size: 14px; font-weight: 600; color: var(--text);
  transition: background .2s, color .2s, transform .15s var(--ease-spring);
}
.chip:active { transform: scale(.96); }
.chip.on { background: var(--text); color: #000; border-color: var(--text); }
.source-chips .chip.on { background: var(--text); color: #000; border-color: var(--text); }

/* ───────────── Sections ───────────── */
.section { padding: 18px 0 4px; }
.section-head { display: flex; align-items: center; justify-content: space-between; padding: 0 var(--gutter) 8px; }
.section-title { margin: 0; font-size: 21px; font-weight: 700; letter-spacing: -0.3px; }
.see-all { display: flex; align-items: center; gap: 2px; color: var(--text-2); font-size: 15px; }
.see-all .i { width: 16px; height: 16px; }

/* Track row */
.track-list { padding: 0; }
.track-row {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 0 8px var(--gutter);
  cursor: pointer; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: background .15s;
}
.track-row:active, .track-row.pressing { background: rgba(255, 255, 255, 0.04); }
.track-num { width: 18px; text-align: center; color: var(--text-2); font-size: 15px; flex: none; }
.track-thumb {
  position: relative; flex: none;
  width: 48px; height: 48px; border-radius: var(--r-xs);
  background: var(--surface-2); overflow: hidden;
}
.track-thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-state {
  position: absolute; inset: 0; display: none; place-items: center;
  background: rgba(0, 0, 0, 0.45); color: #fff;
}
.thumb-state .i { width: 22px; height: 22px; stroke-width: 2.4; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.4px solid rgba(255, 255, 255, 0.25); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.track-row.is-loading .thumb-state, .track-row.is-done .thumb-state { display: grid; }
.track-row.is-loading .thumb-state .i { display: none; }
.track-row.is-done .thumb-state .spinner { display: none; }
.track-row:not(.is-loading):not(.is-done) .thumb-state { display: none; }

.track-info { flex: 1; min-width: 0; }
.track-title { font-size: 15px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-meta {
  display: flex; align-items: center; gap: 5px; margin-top: 3px;
  font-size: 13px; color: var(--text-2);
  white-space: nowrap; overflow: hidden;
}
.track-meta .src { width: 14px; height: 14px; flex: none; }
.track-meta .artist { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.track-meta .dot { flex: none; }
.track-meta .views { display: inline-flex; align-items: center; gap: 3px; flex: none; }
.track-meta .views svg { width: 7px; height: 7px; color: var(--text-3); }
.badge-video {
  flex: none; padding: 1px 4px; border-radius: 3px;
  background: rgba(255, 255, 255, 0.12); color: var(--text-2);
  font-size: 10px; font-weight: 700; letter-spacing: .4px;
}
.track-act {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center; color: var(--text);
  transition: opacity .2s, transform .15s var(--ease-spring);
}
.track-act:active { transform: scale(.9); }
.track-row.is-loading .track-dl { opacity: .3; }
.track-dl .ic-done { display: none; color: var(--text-2); }
.track-row.is-done .track-dl .ic-dl { display: none; }
.track-row.is-done .track-dl .ic-done { display: block; }
.track-more { color: var(--text-2); margin-right: 2px; }

/* Rails (carousels) */
.rail {
  display: flex; gap: 12px;
  overflow-x: auto; overflow-y: hidden;
  padding: 0 var(--gutter) 4px;
  scroll-snap-type: x proximity; scroll-padding: 0 var(--gutter);
  scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }
.card { flex: none; width: 148px; scroll-snap-align: start; cursor: pointer; transition: transform .15s var(--ease-spring); }
.card:active { transform: scale(.97); }
.card-cover {
  position: relative; width: 148px; height: 148px;
  border-radius: var(--r-sm); background: var(--surface-2); overflow: hidden;
}
.card-cover img { width: 100%; height: 100%; object-fit: cover; }
.card-cover .src { position: absolute; top: 7px; left: 7px; width: 16px; height: 16px; opacity: .9; }
.card.is-artist .card-cover { border-radius: 50%; }
.card.is-artist { text-align: center; }
.card-title {
  margin-top: 8px; font-size: 15px; font-weight: 600; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-sub { margin-top: 2px; font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.home-shelves .card, .home-shelves .card-cover { width: 172px; }
.home-shelves .card-cover { height: 172px; }

/* Empty / error */
.empty { padding: 48px 24px; text-align: center; color: var(--text-2); font-size: 15px; line-height: 1.5; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }
.retry-btn { margin-top: 14px; height: 38px; padding: 0 18px; border-radius: var(--r-pill); background: var(--surface-3); font-weight: 600; }

/* Skeletons */
.skel {
  background: linear-gradient(100deg, var(--surface-2) 30%, #26262a 50%, var(--surface-2) 70%);
  background-size: 300% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.skel-list { padding-top: 14px; }
.skel-row { cursor: default; }
.skel-row .track-thumb { border-radius: 10px; width: 52px; height: 52px; }
.skel-line { height: 12px; border-radius: 6px; margin: 4px 0 10px; }
.skel-line.sm { height: 10px; margin-bottom: 4px; }
.skel-row .track-info { padding-right: 60px; }
.skel-card .card-cover { margin-bottom: 8px; }

/* ───────────── Collection (album / playlist) ───────────── */
.album-page { position: fixed; }
.ambient {
  position: absolute; top: -80px; left: 50%; transform: translateX(-50%);
  width: 140%; height: 420px;
  background: radial-gradient(circle at 50% 30%, var(--ambient-color, #4338ca) 0%, rgba(0, 0, 0, 0) 70%);
  opacity: 0.5; filter: blur(60px);
  pointer-events: none; z-index: 0;
}
.album-hero { position: relative; z-index: 1; padding: 44px 16px 14px; text-align: center; }
.album-cover {
  width: 244px; height: 244px; max-width: 64vw; max-height: 64vw;
  margin: 0 auto; border-radius: var(--r-sm); object-fit: cover;
  background: var(--surface-2);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}
.album-title { margin: 22px 0 4px; font-size: 24px; font-weight: 800; letter-spacing: -0.4px; line-height: 1.2; }
.album-sub { font-size: 17px; color: var(--text-2); cursor: default; }
.album-sub.link { cursor: pointer; }
.album-meta { display: inline-flex; align-items: center; gap: 5px; margin-top: 6px; font-size: 13px; color: var(--text-2); }
.album-meta .src { width: 14px; height: 14px; }
.album-page .track-list { position: relative; z-index: 1; padding-top: 4px; }

/* ───────────── Track list page ───────────── */
.list-head { padding: 58px var(--gutter) 8px; }
.list-title { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -0.4px; }

/* ───────────── Artist ───────────── */
.artist-hero { position: relative; height: 45vh; min-height: 300px; max-height: 480px; overflow: hidden; background: var(--surface-1); }
.artist-hero img { width: 100%; height: 100%; object-fit: cover; object-position: center 25%; }
.artist-hero::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0) 45%, rgba(0, 0, 0, .55) 75%, #000 100%);
}
.artist-head { position: absolute; left: 0; right: 0; bottom: 0; z-index: 1; padding: 0 var(--gutter) 14px; }
.artist-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); font-weight: 500; }
.artist-badge .src { width: 14px; height: 14px; }
.artist-name { margin: 2px 0 4px; font-size: 34px; font-weight: 800; letter-spacing: -0.5px; line-height: 1.1; }
.artist-stats { font-size: 13px; color: var(--text-2); }

/* ───────────── Sheets ───────────── */
.sheet-root { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.65);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  opacity: 0; transition: opacity .3s var(--ease-ios);
}
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-width: 640px; margin: 0 auto;
  background: var(--surface-sheet);
  border-radius: var(--r-sheet);
  padding: 8px 8px calc(24px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform .36s var(--ease-ios);
  touch-action: none;
}
.sheet-root.open .sheet-backdrop { opacity: 1; }
.sheet-root.open .sheet { transform: translateY(0); }
.sheet.dragging { transition: none; }
.sheet-handle { width: 36px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.25); margin: 0 auto 12px; }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 0 6px; }
.sheet-cover { width: 56px; height: 56px; border-radius: var(--r-xs); object-fit: cover; background: var(--surface-2); flex: none; }
.sheet-head-meta { flex: 1; min-width: 0; }
.sheet-title { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-artist { margin-top: 3px; font-size: 14px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-x { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); flex: none; }
.sheet-x .i { width: 16px; height: 16px; stroke-width: 2.2; }
.sheet-primary {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; height: 52px;
  background: #ffffff; color: #000000;
  font-size: 16px; font-weight: 600;
  border-radius: var(--r-pill);
  margin: 16px 0 12px;
  transition: transform .15s var(--ease-spring), opacity .2s;
}
.sheet-primary:active { transform: scale(.98); }
.sheet-primary:disabled { opacity: .5; }
.sheet-group { background: var(--surface-2); border-radius: 14px; overflow: hidden; }
.sheet-item {
  display: flex; align-items: center; gap: 14px; width: 100%;
  height: 54px; padding: 0 14px;
  border-bottom: 1px solid var(--hairline);
  font-size: 15px; text-align: left;
}
.sheet-item:last-child { border-bottom: 0; }
.sheet-item:active { background: var(--surface-3); }
.sheet-item span { flex: 1; }
.sheet-item .i { color: var(--text-2); width: 20px; height: 20px; }
.sheet-item .chev { width: 16px; height: 16px; color: var(--text-3); }
.sheet-item:disabled { opacity: .35; }

.sheet-tall { height: 86vh; display: flex; flex-direction: column; padding-left: 0; padding-right: 0; }
.lyrics-head { display: flex; align-items: center; justify-content: space-between; padding: 0 12px 8px 16px; }
.lyrics-title { font-size: 20px; font-weight: 700; }
.lyrics-body {
  flex: 1; overflow-y: auto; padding: 4px 18px 24px;
  font-size: 18px; line-height: 1.6; font-weight: 500; text-align: center; color: #f5f5f7;
  touch-action: pan-y;
}
.lyrics-body p { margin: 0 0 24px; }
.lyrics-source { margin-top: 8px; font-size: 12px; color: var(--text-3); font-weight: 400; }

/* ───────────── Toast ───────────── */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(20px + var(--safe-bottom)); z-index: 99;
  max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 10px 12px 14px;
  background: var(--surface-toast);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  transform: translateY(16px); opacity: 0;
  transition: transform .35s var(--ease-spring), opacity .25s;
}
.toast.show { transform: none; opacity: 1; }
.toast-ic { width: 32px; height: 32px; border-radius: 50%; background: #fff; color: #000; display: grid; place-items: center; flex: none; }
.toast-ic .i { width: 20px; height: 20px; stroke-width: 2.6; }
.toast.error .toast-ic { background: var(--danger); color: #fff; }
.toast-body { flex: 1; min-width: 0; }
.toast-title, .toast-text { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast-title { font-size: 15px; font-weight: 700; }
.toast-text { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.toast.error .toast-text { white-space: normal; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.toast-x { width: 32px; height: 32px; display: grid; place-items: center; color: var(--text-3); flex: none; }
.toast-x .i { width: 16px; height: 16px; }

/* Back button outside Telegram */
.web-back {
  position: fixed; top: calc(10px + var(--safe-top)); left: 10px; z-index: 40;
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(30, 30, 32, 0.7);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}

@media (min-width: 700px) {
  :root { --gutter: 16px; }
  .app-page > * { max-width: 760px; margin-left: auto; margin-right: auto; }
  .app-page > .ambient { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
