* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: #06060a;
  color: #e8e8ec;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.app {
  position: relative;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Background Blobs */
.bg-blur {
  position: fixed;
  border-radius: 50%;
  filter: blur(140px);
  opacity: 0.04;
  pointer-events: none;
  z-index: 0;
}

.bg-blur--1 {
  width: 50vw;
  height: 50vh;
  top: -15vh;
  left: -10vw;
  background: #6366f1;
}

.bg-blur--2 {
  width: 40vw;
  height: 40vh;
  bottom: -10vh;
  right: -5vw;
  background: #8b5cf6;
}

/* Layout */
.layout {
  position: relative;
  z-index: 10;
  flex: 1;
  display: flex;
  gap: 1.2vw;
  padding: 0 2vw 1vh;
  align-items: center;
  min-height: 0;
}

.layout:has(.right-panel.hidden) {
  justify-content: center;
}

/* Left Block: Video + Source */
.left-block {
  max-width: 85vw;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  gap: 1.4vh;
}

/* Video Card */
.video-card {
  align-items: center;
  width: 100%;
  background: #10101a;
  border-radius: 1vw;
  overflow: hidden;
  border: 1px solid rgba(99, 102, 241, 0.15);
  box-shadow: 0 4px 32px rgba(99, 102, 241, 0.06), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
}

.video-inner {
  aspect-ratio: 16 / 9;
  background: #000;
}

.player-wrapper {
  width: 100%;
  height: 100%;
}

.player-wrapper iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* Right Panel */
.right-panel {
  width: 26vw;
  min-width: 300px;
  max-width: 380px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.8vh;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.right-panel.hidden {
  width: 0;
  min-width: 0;
  max-width: 0;
  opacity: 0;
  gap: 0;
  margin: 0;
  padding: 0;
  pointer-events: none;
}

/* Panel Toggle */
.panel-toggle {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0.6vh 0.4vw;
  cursor: pointer;
  color: #4b5563;
  transition: all 0.2s;
  flex-shrink: 0;
}

.panel-toggle:hover {
  color: #a5b4fc;
  transform: translateX(2px);
}

.panel-toggle svg {
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.right-panel:not(.hidden) .panel-toggle svg {
  transform: rotate(180deg);
}

/* Show Panel FAB */
.show-panel-fab {
  position: fixed;
  top: 1.4vh;
  right: 1.4vw;
  width: 2.4vw;
  height: 2.4vw;
  min-width: 36px;
  min-height: 36px;
  border-radius: 0.6vw;
  background: #10101a;
  border: 1px solid rgba(99, 102, 241, 0.15);
  color: #6366f1;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: all 0.2s;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.show-panel-fab:hover {
  background: #16162a;
  transform: scale(1.05);
}

.show-panel-fab.visible {
  display: flex;
}

/* Select Playlist Bar */
.select-playlist-bar {
  padding: 0.4vh 0.4vw;
  border-bottom: 1px solid rgba(99, 102, 241, 0.06);
}

.select-playlist-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 0.6vh 0.4vw;
  border: 1px solid rgba(99, 102, 241, 0.1);
  border-radius: 0.45vw;
  background: transparent;
  color: #6366f1;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 500;
  font-family: inherit;
  transition: all 0.2s;
}

.select-playlist-btn:hover {
  background: rgba(99, 102, 241, 0.08);
  border-color: rgba(99, 102, 241, 0.2);
}

/* Playlist Stats */
.playlist-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8vw;
  padding: 0.6vh 0.4vw;
  border-bottom: 1px solid rgba(99, 102, 241, 0.06);
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #d4d4d8;
}

.stat-item svg {
  width: 12px;
  height: 12px;
}

.stat-item--total {
  color: #a1a1aa;
}

.stat-item--both {
  color: #a1a1aa;
}

.stat-item--vk svg {
  color: #60a5fa;
}

.stat-item--vk {
  color: #a1a1aa;
}

.stat-item--yt svg {
  color: #f87171;
}

.stat-item--yt {
  color: #a1a1aa;
}

.stat-item--vk-only svg {
  color: #60a5fa;
}

.stat-item--vk-only {
  color: #a1a1aa;
}

.stat-item--yt-only svg {
  color: #f87171;
}

.stat-item--yt-only {
  color: #a1a1aa;
}

/* Playlist Card */
.playlist-card {
  background: #10101a;
  border: 1px solid rgba(99, 102, 241, 0.12);
  border-radius: 1vw;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 55vh;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.5vw;
  padding: 1.2vh 1vw 1vh;
  border-bottom: 1px solid rgba(99, 102, 241, 0.06);
  flex-shrink: 0;
}

.card-header svg:first-child {
  color: #6366f1;
  flex-shrink: 0;
  width: 1.1vw;
  height: 1.1vw;
  min-width: 14px;
  min-height: 14px;
}

.card-header h3 {
  font-size: 1.2rem;
  font-weight: 600;
  color: #9ca3af;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.playlist-items {
  flex: 1;
  overflow-y: auto;
  padding: 0.5vh 0.4vw;
}

.playlist-items::-webkit-scrollbar {
  width: 3px;
}

.playlist-items::-webkit-scrollbar-track {
  background: transparent;
}

.playlist-items::-webkit-scrollbar-thumb {
  background: rgba(99, 102, 241, 0.15);
  border-radius: 2px;
}

.playlist-item {
  display: flex;
  align-items: center;
  gap: 0.6vw;
  padding: 0.5vh 0.4vw;
  border-radius: 0.5vw;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 0.3vh;
  border: 1px solid transparent;
}

.playlist-item:hover {
  background: rgba(99, 102, 241, 0.05);
  border-color: rgba(99, 102, 241, 0.08);
}

.playlist-item.active {
  background: rgba(99, 102, 241, 0.1);
  border-color: rgba(99, 102, 241, 0.2);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.06);
}

.playlist-item-num {
  width: 1.6vw;
  height: 1.6vw;
  min-width: 20px;
  min-height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.35vw;
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.85rem;
  font-weight: 700;
  color: #4b5563;
  flex-shrink: 0;
}

.playlist-item.active .playlist-item-num {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.playlist-item-thumb {
  width: 5vw;
  height: 3.2vh;
  min-width: 50px;
  min-height: 32px;
  border-radius: 0.35vw;
  overflow: hidden;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.playlist-item-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s;
}

.playlist-item:hover .playlist-item-thumb img {
  transform: scale(1.05);
}

.playlist-item-info {
  flex: 1;
  min-width: 0;
}

.playlist-item-title {
  font-size: 0.8rem;
  font-weight: 500;
  color: #9ca3af;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.35;
}

.playlist-item.active .playlist-item-title {
  color: #a5b4fc;
}

.playlist-item.unavailable {
  opacity: 0.35;
  pointer-events: none;
}

.playlist-item.unavailable .playlist-item-thumb {
  background: #1a1a22;
}

.playlist-item-badges {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.playlist-item-badges .source-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.03);
}

.playlist-item-badges .source-badge svg {
  width: 12px;
  height: 12px;
}

.playlist-item-badges .source-badge--vk svg {
  color: #60a5fa;
}

.playlist-item-badges .source-badge--yt svg {
  color: #f87171;
}

/* Thumbnail iframe wrapper & overlay */
.thumb-iframe-wrap {
  position: relative;
  width: 100%;
  height: 100%;
}

.thumb-iframe-wrap iframe {
  pointer-events: none;
}

.thumb-overlay {
  position: absolute;
  inset: 0;
  background: transparent;
  z-index: 2;
}

/* Playlist item stats (in selector) */
.playlist-item-stats {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.playlist-stat {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 0.65rem;
  font-weight: 700;
  color: #a1a1aa;
}

.playlist-stat svg {
  width: 10px;
  height: 10px;
}

.playlist-stat--total {
  color: #9ca3af;
}

.playlist-stat--total svg {
  color: #9ca3af;
}

.playlist-stat--both svg {
  width: 10px;
  height: 10px;
}

.playlist-stat--vk svg {
  color: #60a5fa;
}

.playlist-stat--yt svg {
  color: #f87171;
}

/* Controls Card */
.controls-card {
  width: 12vw;
  background: #10101a;
  border: 1px solid rgba(99, 102, 241, 0.12);
  border-radius: 0.8vw;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6vw;
  padding: 0.8vh 0.8vw;
  align-self: center;
}

.ctrl-btn {
  background: rgba(99, 102, 241, 0.06);
  border: 1px solid rgba(99, 102, 241, 0.1);
  color: #9ca3af;
  cursor: pointer;
  padding: 0.5vh 0.4vw;
  border-radius: 0.45vw;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.ctrl-btn:hover {
  background: rgba(99, 102, 241, 0.14);
  color: #a5b4fc;
  border-color: rgba(99, 102, 241, 0.2);
}

.ctrl-btn:active {
  transform: scale(0.88);
}

.ctrl-btn svg {
  width: 1.1vw;
  height: 1.1vw;
  min-width: 14px;
  min-height: 14px;
}

.counter {
  font-size: 1rem;
  color: #4b5563;
  font-weight: 600;
  min-width: 3.5vw;
  text-align: center;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

/* Source Popup */
.source-popup {
  display: flex;
  justify-content: center;
}

.source-popup-inner {
  background: #10101a;
  border: 1px solid rgba(99, 102, 241, 0.15);
  border-radius: 0.8vw;
  padding: 0.5vh 0.5vw;
  display: flex;
  align-items: center;
  gap: 0.4vw;
  box-shadow: 0 4px 24px rgba(99, 102, 241, 0.08), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
}

.source-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5vw;
  padding: 0.7vh 1vw;
  border: none;
  border-radius: 0.6vw;
  background: transparent;
  color: #4b5563;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 0;
  min-height: 0;
  width: auto;
  height: auto;
  -webkit-tap-highlight-color: transparent;
}

.source-btn svg {
  width: 1.1vw;
  height: 1.1vw;
  min-width: 14px;
  min-height: 14px;
  flex-shrink: 0;
}

.source-btn:hover {
  color: #9ca3af;
}

.source-btn.active {
  background: rgba(99, 102, 241, 0.12);
  color: #c7d2fe;
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.08);
}

.source-btn[data-source="vk"].active {
  color: #60a5fa;
  background: rgba(96, 165, 250, 0.1);
}

.source-btn[data-source="yt"].active {
  color: #f87171;
  background: rgba(248, 113, 113, 0.1);
}

/* ===== RESPONSIVE: TABLET (<=1024px) ===== */
@media (max-width: 1024px) {
  .layout {
    gap: 16px;
    padding: 0 16px 12px;
  }

  .right-panel {
    width: 35vw;
    min-width: 260px;
  }

  .video-card {
    border-radius: 12px;
  }

  .playlist-card {
    border-radius: 12px;
  }

  .controls-card {
    border-radius: 10px;
  }
}

/* ===== RESPONSIVE: MOBILE (<=768px) ===== */
@media (max-width: 768px) {
  .layout {
    flex-direction: column;
    padding: 12px;
    gap: 10px;
    overflow-y: auto;
    height: 100dvh;
  }

  .layout:has(.right-panel.hidden) {
    justify-content: flex-start;
  }

  .left-block {
    max-width: 100%;
    width: 100%;
    gap: 10px;
    flex-shrink: 0;
  }

  .video-card {
    width: 100%;
    border-radius: 12px;
  }

  .video-inner {
    border-radius: 12px;
    overflow: hidden;
  }

  /* Right Panel - slides from bottom on mobile */
  .right-panel {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
    background: #0a0a12;
    border-top: 1px solid rgba(99, 102, 241, 0.12);
    border-radius: 16px 16px 0 0;
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    gap: 10px;
    transform: translateY(0);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 60vh;
    will-change: transform;
  }

  .right-panel.hidden {
    width: 100%;
    max-width: 100%;
    transform: translateY(100%);
    padding: 0;
    border-top: none;
    pointer-events: none;
  }

  /* Override transition during swipe drag */
  .right-panel.dragging {
    transition: none !important;
  }

  /* Panel Toggle - drag handle style on mobile */
  .panel-toggle {
    justify-content: center;
    padding: 4px 0;
  }

  .panel-toggle::before {
    content: '';
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.15);
    display: block;
  }

  .panel-toggle svg {
    display: none;
  }

  .right-panel:not(.hidden) .panel-toggle::before {
    background: rgba(99, 102, 241, 0.3);
  }

  /* Show Panel FAB */
  .show-panel-fab {
    top: auto;
    bottom: max(16px, env(safe-area-inset-bottom));
    right: 16px;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 12px;
  }

  /* Playlist Card */
  .playlist-card {
    height: auto;
    max-height: 35vh;
    border-radius: 12px;
  }

  .card-header {
    padding: 10px 12px 8px;
    gap: 8px;
  }

  .card-header svg:first-child {
    width: 18px;
    height: 18px;
  }

  .card-header h3 {
    font-size: 0.95rem;
  }

  /* Playlist Stats */
  .playlist-stats {
    padding: 8px 12px;
    gap: 12px;
  }

  .stat-item {
    font-size: 0.7rem;
  }

  /* Select Playlist Bar */
  .select-playlist-bar {
    padding: 6px 12px;
  }

  .select-playlist-btn {
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.8rem;
  }

  /* Playlist Items */
  .playlist-items {
    padding: 6px;
  }

  .playlist-item {
    gap: 8px;
    padding: 8px;
    border-radius: 8px;
    margin-bottom: 4px;
    min-height: 44px;
  }

  .playlist-item-num {
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
    font-size: 0.75rem;
    border-radius: 6px;
  }

  .playlist-item-thumb {
    width: 64px;
    height: 40px;
    min-width: 64px;
    min-height: 40px;
    border-radius: 6px;
  }

  .playlist-item-title {
    font-size: 0.75rem;
  }

  /* Controls Card */
  .controls-card {
    width: 100%;
    border-radius: 12px;
    padding: 12px;
    gap: 12px;
  }

  .ctrl-btn {
    padding: 12px 16px;
    border-radius: 10px;
    min-width: 44px;
    min-height: 44px;
  }

  .ctrl-btn svg {
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
  }

  .counter {
    font-size: 0.9rem;
    min-width: auto;
    padding: 0 8px;
  }

  /* Source Popup */
  .source-popup-inner {
    border-radius: 12px;
    padding: 6px;
    gap: 6px;
  }

  .source-btn {
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 0.85rem;
    gap: 8px;
    min-height: 44px;
  }

  .source-btn svg {
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
  }
}

/* ===== RESPONSIVE: SMALL MOBILE (<=480px) ===== */
@media (max-width: 480px) {
  .layout {
    padding: 8px;
    gap: 8px;
  }

  .video-card {
    border-radius: 10px;
  }

  .right-panel {
    padding: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    gap: 8px;
  }

  .playlist-card {
    max-height: 30vh;
    border-radius: 10px;
  }

  .card-header {
    padding: 8px 10px 6px;
  }

  .card-header h3 {
    font-size: 0.85rem;
  }

  .playlist-stats {
    padding: 6px 8px;
    gap: 8px;
  }

  .stat-item {
    font-size: 0.65rem;
  }

  .playlist-items {
    padding: 4px;
  }

  .playlist-item {
    padding: 6px;
    gap: 6px;
    margin-bottom: 3px;
  }

  .playlist-item-num {
    width: 22px;
    height: 22px;
    min-width: 22px;
    min-height: 22px;
    font-size: 0.7rem;
  }

  .playlist-item-thumb {
    width: 56px;
    height: 36px;
    min-width: 56px;
    min-height: 36px;
  }

  .playlist-item-title {
    font-size: 0.7rem;
    -webkit-line-clamp: 1;
  }

  .controls-card {
    padding: 10px;
    gap: 10px;
    border-radius: 10px;
  }

  .ctrl-btn {
    padding: 10px 14px;
    border-radius: 8px;
  }

  .counter {
    font-size: 0.8rem;
  }

  .show-panel-fab {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border-radius: 10px;
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
  }
}
