:root {
  color-scheme: light dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--tg-theme-bg-color, #0f1116);
  color: var(--tg-theme-text-color, #f4f6f8);
}

* { box-sizing: border-box; }
button, input { font: inherit; }
button { cursor: pointer; }
body { margin: 0; min-height: 100vh; background: var(--tg-theme-bg-color, #0f1116); color: var(--tg-theme-text-color, #f4f6f8); }
main { max-width: 820px; margin: 0 auto; padding: 22px 16px 190px; }
.hidden { display: none !important; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
h1, h2 { margin: 0; }
h1 { margin-top: 4px; font-size: 28px; letter-spacing: -.03em; }
h2 { font-size: 22px; letter-spacing: -.02em; }
.eyebrow { font-size: 10px; letter-spacing: .2em; opacity: .52; }
.icon-button { width: 42px; height: 42px; border: 0; border-radius: 14px; background: var(--tg-theme-secondary-bg-color, #1a1e26); color: inherit; font-size: 21px; }
.danger-text { color: var(--tg-theme-destructive-text-color, #ff5c68); }

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; padding: 5px; margin: 22px 0 18px; border-radius: 15px; background: var(--tg-theme-secondary-bg-color, #191d24); }
.tab { border: 0; border-radius: 11px; padding: 10px; background: transparent; color: var(--tg-theme-hint-color, #8b929e); }
.tab.active { background: var(--tg-theme-button-color, #2d80ff); color: var(--tg-theme-button-text-color, #fff); font-weight: 700; }

.toolbar { margin-bottom: 13px; }
.search, .dialog input { width: 100%; border: 1px solid rgba(127,127,127,.16); outline: 0; border-radius: 14px; padding: 12px 14px; background: var(--tg-theme-secondary-bg-color, #191d24); color: inherit; }
.search:focus, .dialog input:focus { border-color: var(--tg-theme-button-color, #2d80ff); }

.tracks { display: grid; gap: 8px; }
.track { display: grid; grid-template-columns: 58px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 9px; border-radius: 17px; background: var(--tg-theme-secondary-bg-color, #191d24); }
.track-main { min-width: 0; display: contents; cursor: pointer; }
.track-cover, .cover-placeholder { width: 58px; height: 58px; border-radius: 12px; object-fit: cover; background: rgba(127,127,127,.13); }
.cover-placeholder { display: grid; place-items: center; font-size: 23px; opacity: .7; }
.track-meta { min-width: 0; display: grid; gap: 4px; }
.track-meta strong, .track-meta span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.track-meta strong { font-size: 14px; }
.track-meta span { color: var(--tg-theme-hint-color, #9299a5); font-size: 12px; }
.track-status { display: inline-flex; width: max-content; margin-top: 1px; padding: 2px 7px; border-radius: 999px; font-size: 10px !important; background: rgba(127,127,127,.12); }
.track-status.failed { color: var(--tg-theme-destructive-text-color, #ff6670); }
.track-menu { width: 36px; height: 40px; border: 0; border-radius: 12px; background: transparent; color: inherit; font-size: 21px; opacity: .75; }
.track-menu:hover { background: rgba(127,127,127,.12); opacity: 1; }
.empty { padding: 56px 18px; text-align: center; color: var(--tg-theme-hint-color, #9299a5); }

.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 4px 0 16px; }
.section-heading p { margin: 4px 0 0; font-size: 12px; color: var(--tg-theme-hint-color, #9299a5); }
.primary { border: 0; border-radius: 12px; padding: 11px 15px; background: var(--tg-theme-button-color, #2d80ff); color: var(--tg-theme-button-text-color, #fff); font-weight: 700; }
.primary.small { padding: 9px 12px; font-size: 12px; }
.playlist-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.playlist-card { border: 0; border-radius: 18px; padding: 10px; text-align: left; background: var(--tg-theme-secondary-bg-color, #191d24); color: inherit; }
.playlist-cover { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; aspect-ratio: 1; overflow: hidden; border-radius: 13px; background: rgba(127,127,127,.12); }
.playlist-cover img { width: 100%; height: 100%; object-fit: cover; }
.playlist-cover .playlist-placeholder { grid-column: 1 / -1; grid-row: 1 / -1; display: grid; place-items: center; font-size: 38px; opacity: .55; }
.playlist-card strong { display: block; margin: 10px 2px 2px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.playlist-card span { margin-left: 2px; font-size: 11px; color: var(--tg-theme-hint-color, #9299a5); }
.playlist-detail-heading { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; margin: 4px 0 18px; }
.playlist-detail-title { min-width: 0; }
.playlist-detail-title h2 { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.playlist-detail-title span { font-size: 11px; color: var(--tg-theme-hint-color, #9299a5); }

.player { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; padding: 10px 16px max(12px, env(safe-area-inset-bottom)); border-top: 1px solid rgba(127,127,127,.16); background: color-mix(in srgb, var(--tg-theme-bg-color, #0f1116) 92%, transparent); backdrop-filter: blur(22px); }
.player-inner { width: min(820px, 100%); margin: 0 auto; }
.player-meta { display: flex; align-items: center; gap: 10px; }
.player-cover-wrap { position: relative; flex: 0 0 44px; width: 44px; height: 44px; border-radius: 10px; overflow: hidden; background: rgba(127,127,127,.14); }
.player-cover-wrap img { width: 100%; height: 100%; object-fit: cover; }
.player-cover-wrap span { position: absolute; inset: 0; display: grid; place-items: center; }
.player-copy { min-width: 0; display: grid; }
.player-copy strong, .player-copy span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.player-copy strong { font-size: 13px; }
.player-copy span { font-size: 11px; color: var(--tg-theme-hint-color, #9299a5); }
.progress-row { display: grid; grid-template-columns: 34px 1fr 34px; gap: 7px; align-items: center; margin-top: 7px; font-size: 9px; color: var(--tg-theme-hint-color, #9299a5); }
.progress-row input { width: 100%; accent-color: var(--tg-theme-button-color, #2d80ff); }
.player-controls { display: flex; justify-content: center; gap: 14px; margin-top: 4px; }
.player-button { width: 38px; height: 34px; border: 0; border-radius: 12px; background: transparent; color: inherit; font-size: 18px; }
.play-button { background: var(--tg-theme-button-color, #2d80ff); color: var(--tg-theme-button-text-color, #fff); }
#audio { display: none; }

.overlay { position: fixed; z-index: 50; inset: 0; display: flex; align-items: flex-end; justify-content: center; padding: 16px; background: rgba(0,0,0,.48); }
.sheet, .dialog { width: min(520px, 100%); border: 1px solid rgba(127,127,127,.15); border-radius: 22px; padding: 14px; background: var(--tg-theme-bg-color, #11141a); box-shadow: 0 16px 60px rgba(0,0,0,.28); }
.sheet-handle { width: 42px; height: 4px; margin: -4px auto 13px; border-radius: 999px; background: rgba(127,127,127,.35); }
.sheet > strong { display: block; margin: 2px 6px 10px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sheet > button, .picker-list button { width: 100%; border: 0; border-radius: 13px; padding: 12px 10px; text-align: left; background: transparent; color: inherit; }
.sheet > button:hover, .picker-list button:hover { background: rgba(127,127,127,.1); }
.sheet .danger { color: var(--tg-theme-destructive-text-color, #ff6670); }
.muted-button { color: var(--tg-theme-hint-color, #9299a5) !important; text-align: center !important; }
.sheet-title-row { display: flex; align-items: center; justify-content: space-between; margin: 2px 6px 10px; }
.mini-link { border: 0; background: transparent; color: var(--tg-theme-link-color, #5b9cff); }
.picker-list { max-height: 300px; overflow: auto; }
.picker-list button { display: flex; justify-content: space-between; gap: 14px; }
.dialog { align-self: center; padding: 20px; }
.dialog strong { display: block; margin-bottom: 14px; font-size: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.dialog-actions button { width: auto; }
.toast { position: fixed; z-index: 80; left: 50%; bottom: 164px; transform: translateX(-50%); max-width: calc(100% - 32px); padding: 9px 13px; border-radius: 999px; background: #f2f4f7; color: #11141a; font-size: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.25); }

@media (min-width: 680px) {
  .playlist-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .track { grid-template-columns: 64px minmax(0, 1fr) auto; }
  .track-cover, .cover-placeholder { width: 64px; height: 64px; }
}

.playlist-card-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 3px 2px 0; }
.playlist-card-meta > span:first-child { margin-left: 0; }
.source-badge { display: inline-flex; align-items: center; width: max-content; padding: 3px 7px; border-radius: 999px; font-size: 10px !important; font-weight: 700; line-height: 1; }
.source-badge.youtube { background: rgba(255, 58, 58, .14); color: #ff5d5d; }
.youtube-playlist-tools { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: -6px 0 14px; padding: 10px 12px; border-radius: 15px; background: var(--tg-theme-secondary-bg-color, #191d24); }
.youtube-playlist-tools > div { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sync-time { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 10px; color: var(--tg-theme-hint-color, #9299a5); }
#refresh-youtube-playlist:disabled { opacity: .6; cursor: default; }
