/* Karaoke App Styles */

/* iOS Safari: prevent elastic bounce and ensure proper sizing */
html, body {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none;
}

* {
  scrollbar-width: thin;
  scrollbar-color: #374151 transparent;
}

*::-webkit-scrollbar {
  width: 6px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background-color: #374151;
  border-radius: 3px;
}

/* Video Grid */
.video-grid-layout {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

/* Single participant: full width */
.video-grid-layout.single-tile {
  grid-template-columns: 1fr;
}

.video-tile {
  position: relative;
  background: #111827;
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 16/9;
  border: 2px solid transparent;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.video-tile.speaking {
  border-color: #ec4899;
  box-shadow: 0 0 20px rgba(236, 72, 153, 0.3);
}

.video-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.video-tile .video-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 6px 12px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
  font-size: 13px;
  font-weight: 500;
}

.video-tile .video-muted {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-tile .video-avatar {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  background: #1f2937;
}

/* Camera-off fallback: hidden by default, shown when video has no tracks */
.video-tile .cam-off-fallback {
  display: none;
}

.video-tile .cam-off-avatar {
  width: 50%;
  max-width: 120px;
  border-radius: 50%;
  object-fit: cover;
  aspect-ratio: 1;
}

/* Small avatar in tile name overlay */
.tile-user-avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
  margin-right: 6px;
  vertical-align: middle;
}

/* Controls Bar */
.controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: #111827;
  border-top: 1px solid #1f2937;
  gap: 16px;
  z-index: 30;
  flex-shrink: 0;
}

.controls-left,
.controls-center,
.controls-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.controls-center {
  gap: 8px;
}

/* Control Buttons */
.control-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #374151;
  transition: all 0.2s;
  border: none;
  color: white;
  cursor: pointer;
}

.control-btn:hover {
  background: #4b5563;
}

.control-btn.active {
  background: #374151;
}

.control-btn.muted {
  background: #dc2626;
}

.control-btn-text {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 24px;
  background: #374151;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  border: none;
  color: white;
  cursor: pointer;
}

.control-btn-text:hover {
  background: #4b5563;
}

.control-btn-stop {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 24px;
  background: #dc2626;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  border: none;
  color: white;
  cursor: pointer;
}

.control-btn-stop:hover {
  background: #b91c1c;
}

.control-btn-leave {
  padding: 10px 16px;
  border-radius: 24px;
  background: transparent;
  border: 1px solid #dc2626;
  color: #f87171;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.control-btn-leave:hover {
  background: #dc2626;
  color: white;
}

/* Chat Drawer */
.chat-drawer {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 320px;
  background: #0f172a;
  border-left: 1px solid #1f2937;
  display: flex;
  flex-direction: column;
  z-index: 55;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

.chat-drawer.open {
  transform: translateX(0);
}

.chat-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #1f2937;
}

.chat-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
}

/* Lyrics Overlay — hidden by default, shown by music-mode */
.lyrics-overlay {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 24px 16px;
  background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.85));
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.lyrics-overlay::-webkit-scrollbar {
  display: none;
}

.lyrics-container {
  text-align: center;
  padding-top: 40vh;
  padding-bottom: 40vh;
}

.lyrics-line {
  font-size: 18px;
  line-height: 2;
  color: #6b7280;
  transition: all 0.3s;
  padding: 2px 8px;
  border-radius: 4px;
}

.lyrics-line.active {
  color: #ffffff;
  font-size: 28px;
  font-weight: 600;
  text-shadow: 0 0 20px rgba(236, 72, 153, 0.5), 0 0 40px rgba(236, 72, 153, 0.2);
}

.lyrics-line.past {
  color: #9ca3af;
}

/* Music Mode */
body.music-mode #video-grid {
  max-height: 35vh;
  max-height: 35dvh;
  flex: none;
  overflow: hidden;
  align-content: start;
  grid-auto-rows: 1fr;
}

body.music-mode .video-tile {
  height: 100%;
}

/* Force 2-col in music mode even for single participant */
body.music-mode .video-grid-layout.single-tile {
  grid-template-columns: repeat(2, 1fr);
}

body.music-mode #lyrics-overlay {
  display: block;
}

/* Chat Messages */
.chat-msg {
  display: flex;
  gap: 8px;
  font-size: 14px;
}

.chat-msg .chat-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
  background: #374151;
  object-fit: cover;
}

img.chat-avatar {
  display: block;
}

.chat-msg.host-msg .chat-avatar {
  background: linear-gradient(135deg, #ec4899, #8b5cf6);
}

.chat-msg .chat-name {
  font-weight: 600;
  font-size: 13px;
}

.chat-msg.host-msg .chat-name {
  color: #ec4899;
}

.chat-msg .chat-text {
  color: #d1d5db;
  word-break: break-word;
}

/* Now Playing Animation */
.now-playing-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
}

.now-playing-bars span {
  width: 3px;
  background: #ec4899;
  border-radius: 1px;
  animation: bar-bounce 1s ease-in-out infinite;
}

.now-playing-bars span:nth-child(1) { height: 40%; animation-delay: 0s; }
.now-playing-bars span:nth-child(2) { height: 70%; animation-delay: 0.2s; }
.now-playing-bars span:nth-child(3) { height: 50%; animation-delay: 0.4s; }

@keyframes bar-bounce {
  0%, 100% { transform: scaleY(0.5); }
  50% { transform: scaleY(1); }
}

/* Host Avatar Speaking */
#host-avatar.speaking {
  animation: host-pulse 1s ease-in-out infinite;
}

@keyframes host-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(236, 72, 153, 0.4); transform: scale(1); }
  50% { box-shadow: 0 0 0 8px rgba(236, 72, 153, 0); transform: scale(1.1); }
}

/* Kawaii tile avatar */
.kawaii-avatar {
  width: 50%;
  max-width: 120px;
  border-radius: 50%;
  object-fit: cover;
  aspect-ratio: 1;
  transition: transform 0.3s;
}

/* Kawaii tile speaking — pulsate the avatar image */
#tile-kawaii.speaking .kawaii-avatar {
  animation: kawaii-breathe 0.8s ease-in-out infinite;
}

@keyframes kawaii-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.25); }
}

/* Song List Item */
.song-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: #1f2937;
  border-radius: 8px;
  transition: background 0.2s;
}

.song-item:hover {
  background: #374151;
}

.song-item .song-info {
  min-width: 0;
}

.song-item .song-title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.song-item .song-artist {
  font-size: 12px;
  color: #9ca3af;
}

.song-item .song-queue-btn {
  padding: 6px 14px;
  border-radius: 6px;
  background: #ec4899;
  font-size: 12px;
  font-weight: 600;
  transition: background 0.2s;
  border: none;
  color: white;
  cursor: pointer;
  flex-shrink: 0;
}

.song-item .song-queue-btn:hover {
  background: #db2777;
}

/* Room Card */
.room-card {
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 16px;
  padding: 24px;
  transition: all 0.3s;
  cursor: pointer;
}

.room-card:hover {
  border-color: #374151;
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}

/* Queue item in modal */
.queue-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.queue-item .queue-pos {
  color: #6b7280;
  font-size: 12px;
  width: 20px;
}

/* Hidden utility */
.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 767px) {
  .video-grid-layout {
    grid-template-columns: repeat(2, 1fr);
  }

  .video-grid-layout.single-tile {
    grid-template-columns: 1fr;
  }

  .controls-bar {
    flex-wrap: wrap;
    justify-content: center;
    padding: 8px 12px;
    gap: 8px;
  }

  .controls-left,
  .controls-center,
  .controls-right {
    gap: 8px;
  }

  .controls-left {
    order: 1;
  }

  .controls-center {
    order: 2;
  }

  .controls-right {
    order: 3;
  }

  .control-btn {
    width: 44px;
    height: 44px;
  }

  .control-btn-text,
  .control-btn-stop {
    padding: 8px 14px;
    font-size: 13px;
  }

  .control-btn-leave {
    padding: 8px 12px;
    font-size: 13px;
  }

  .chat-drawer {
    width: 100%;
  }

  .lyrics-line.active {
    font-size: 22px;
  }

  body.music-mode #video-grid {
    max-height: 30vh;
    max-height: 30dvh;
  }
}

@media (min-width: 768px) {
  .chat-backdrop {
    display: none !important;
  }
}
