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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f0f0f;
  color: #e1e1e1;
  min-height: 100vh;
}

body.playlist-open-mobile {
  overflow: hidden;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  color: #fff;
}

header h1 a {
  color: inherit;
  text-decoration: none;
}

.lang-select {
  position: absolute;
  right: 0;
  padding: 0.3rem 0.5rem;
  border: 1px solid #333;
  border-radius: 4px;
  background: #1a1a1a;
  color: #aaa;
  font-size: 0.8rem;
  cursor: pointer;
  outline: none;
  transition: all 0.15s;
}

.lang-select:hover,
.lang-select:focus {
  border-color: #555;
  color: #fff;
}

.title-playlist-btn {
  position: absolute;
  left: 0;
  padding: 0.3rem 0.55rem;
  border: 1px solid #333;
  border-radius: 4px;
  background: #1a1a1a;
  color: #aaa;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}

.title-playlist-btn:hover {
  border-color: #555;
  color: #fff;
}

.subtitle {
  color: #888;
  margin-top: 0.25rem;
}

.search-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

#url-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid #333;
  border-radius: 6px;
  background: #1a1a1a;
  color: #fff;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

#url-input:focus {
  border-color: #555;
}

#load-btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 6px;
  background: #c00;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

#load-btn:hover {
  background: #e00;
}

#load-btn:disabled {
  background: #555;
  cursor: not-allowed;
}

.error {
  background: #3a1111;
  border: 1px solid #611;
  color: #f88;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 2rem;
  color: #888;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #333;
  border-top-color: #c00;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.hidden {
  display: none !important;
}

/* ─── Search results grid ─────────────────────────────────────────────── */

.results-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
}

.video-card {
  cursor: pointer;
  border-radius: 8px;
  overflow: hidden;
  background: #181818;
  transition: transform 0.15s, box-shadow 0.15s;
}

.video-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.card-thumbnail {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #111;
  overflow: hidden;
}

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

.card-duration {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
  line-height: 1.2;
}

.card-body {
  padding: 0.6rem 0.75rem 0.75rem;
}

.card-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: #fff;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 0.3rem;
}

.card-channel {
  font-size: 0.8rem;
  color: #aaa;
  margin-bottom: 0.2rem;
}

.card-meta {
  font-size: 0.75rem;
  color: #777;
}

.card-meta span + span::before {
  content: ' \00b7 ';
}

.card-actions {
  margin-top: 0.55rem;
}

.card-add-playlist-btn {
  width: 100%;
}

/* ─── Back button ─────────────────────────────────────────────────────── */

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid #333;
  border-radius: 6px;
  background: #1a1a1a;
  color: #aaa;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: 1rem;
}

.back-btn:hover {
  border-color: #555;
  color: #fff;
}

/* ─── Player ──────────────────────────────────────────────────────────── */

.video-info {
  margin-bottom: 1rem;
}

.video-info h2 {
  font-size: 1.25rem;
  color: #fff;
  line-height: 1.4;
}

.video-info p {
  color: #888;
  margin-top: 0.25rem;
  font-size: 0.9rem;
}

.player-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.player-main {
  min-width: 0;
}

.playlist-panel {
  background: #151515;
  border: 1px solid #262626;
  border-radius: 10px;
  padding: 0.75rem;
}

.playlist-drawer-overlay {
  display: none;
}

.playlist-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

.playlist-head h3 {
  font-size: 0.95rem;
  color: #ddd;
}

.playlist-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.playlist-empty {
  color: #777;
  font-size: 0.85rem;
  margin-bottom: 0.6rem;
}

.playlist-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 460px;
  overflow-y: auto;
}

.playlist-item {
  display: flex;
  align-items: stretch;
  gap: 0.35rem;
}

.playlist-item-main {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  border: 1px solid #2f2f2f;
  border-radius: 8px;
  background: #1a1a1a;
  color: #ddd;
  padding: 0.4rem;
  cursor: pointer;
  text-align: left;
}

.playlist-item-main:hover {
  border-color: #555;
}

.playlist-item.active .playlist-item-main {
  border-color: #c00;
  background: #2a1212;
}

.playlist-thumb {
  width: 64px;
  height: 36px;
  border-radius: 5px;
  object-fit: cover;
  background: #0f0f0f;
  flex-shrink: 0;
}

.playlist-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.playlist-title {
  color: #fff;
  font-size: 0.8rem;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.playlist-sub {
  color: #8c8c8c;
  font-size: 0.72rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.playlist-tools {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 0 0 auto;
}

.playlist-action-btn {
  width: 28px;
  height: 28px;
  border: 1px solid #333;
  border-radius: 8px;
  background: #1a1a1a;
  color: #8f8f8f;
  cursor: pointer;
}

.playlist-action-btn:hover {
  border-color: #555;
  color: #fff;
}

.playlist-action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.playlist-remove:hover {
  border-color: #a33;
  color: #fff;
}

.video-actions {
  margin-bottom: 0.75rem;
}

.video-wrapper {
  position: relative;
  width: 100%;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
}

#video-player {
  display: block;
  width: 100%;
  max-height: 540px;
  background: #000;
}

.controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.5rem;
  padding: 1rem 0;
  border-top: 1px solid #222;
  margin-top: 0.5rem;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.control-group label {
  color: #888;
  font-size: 0.85rem;
  white-space: nowrap;
}

select {
  padding: 0.4rem 0.6rem;
  border: 1px solid #333;
  border-radius: 4px;
  background: #1a1a1a;
  color: #fff;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

.speed-buttons {
  display: flex;
  gap: 0.25rem;
}

.speed-buttons button {
  padding: 0.35rem 0.5rem;
  border: 1px solid #333;
  border-radius: 4px;
  background: #1a1a1a;
  color: #aaa;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}

.speed-buttons button:hover {
  border-color: #555;
  color: #fff;
}

.speed-buttons button.active {
  background: #c00;
  border-color: #c00;
  color: #fff;
}

.btn {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  border: 1px solid #333;
  border-radius: 4px;
  background: #1a1a1a;
  color: #aaa;
  font-size: 0.85rem;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-small {
  padding: 0.3rem 0.55rem;
  font-size: 0.75rem;
}

.btn:hover {
  border-color: #555;
  color: #fff;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.is-added {
  border-color: #c00;
  background: #2a1212;
  color: #fff;
}

/* ─── Responsive ──────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .results-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .player-layout {
    grid-template-columns: 1fr;
  }

  #player-section {
    position: relative;
  }

  .playlist-panel {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(86vw, 320px);
    z-index: 1001;
    border-radius: 0 10px 10px 0;
    transform: translateX(calc(-100% - 12px));
    transition: transform 0.2s ease;
    overflow-y: auto;
    box-shadow: none;
  }

  #player-section.playlist-open .playlist-panel {
    transform: translateX(0);
    box-shadow: 0 0 0 1px #262626, 18px 0 36px rgba(0, 0, 0, 0.55);
  }

  .playlist-list {
    max-height: calc(100vh - 150px);
  }

  .playlist-drawer-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  #player-section.playlist-open .playlist-drawer-overlay {
    opacity: 1;
    pointer-events: auto;
  }
}

@media (max-width: 640px) {
  .container {
    padding: 1rem 0.75rem;
  }

  header h1 {
    font-size: 1.5rem;
  }

  .results-grid {
    grid-template-columns: 1fr;
  }

  .controls-bar {
    gap: 1rem;
  }

  .playlist-list {
    max-height: calc(100vh - 170px);
  }

  .speed-buttons button {
    padding: 0.3rem 0.4rem;
    font-size: 0.75rem;
  }
}
