:root {
  --main-bg: #18181b;
  --card-bg: #222226;
  --accent: #ff3437;
  --card-hover: #242428;
  --gray: #aaa;
  --text: #fff;
  --input-bg: #232327;
  --icon: #fff;
}
body.light {
  --main-bg: #fff;
  --card-bg: #f0f0f4;
  --accent: #ff3437;
  --card-hover: #e6e6ed;
  --gray: #545466;
  --text: #16161a;
  --input-bg: #ededf2;
  --icon: #ff3437;
}

body {
  font-family: 'Roboto', Arial, sans-serif;
  margin: 0;
  background: var(--main-bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.2s, color 0.2s;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: #212124;
  padding: 1rem 2rem;
  flex-wrap: wrap;
  transition: background 0.2s;
}
body.light header { background: #f9f9fb; }

.logo {
  font-size: 2rem;
  color: var(--accent);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.4em;
  letter-spacing: 1px;
}
.header-controls {
  flex: 1;
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: flex-end;
}
.theme-toggle {
  background: none;
  border: none;
  position: absolute;
  top: 1.2rem;
  right: 1.2rem;
  z-index: 20;
  margin-left: 1.5rem;
  font-size: 1.25em;
  color: var(--icon);
  cursor: pointer;
  transition: color 0.2s;
}
.theme-toggle:active,
.theme-toggle:focus { color: var(--accent); }
.theme-toggle .fa-moon { color: #fd0; }
body.light .theme-toggle .fa-sun { color: #ffb200; }
body.light .theme-toggle .fa-moon { color: var(--gray); }

.search-group {
  display: flex;
  flex: 1 1 250px;
  max-width: 400px;
  min-width: 0;
}

#search {
  width: 100%;
  padding: 0.75em 1em;
  border: 2px solid var(--accent);
  border-radius: 2em 0 0 2em;
  background: var(--input-bg);
  color: var(--text);
  font-size: 1.1em;
  outline: none;
  transition: background 0.2s, color 0.2s, border 0.16s;
}
#search:focus {
  border: 2px solid #fdba2c;
}
body.light #search {
  border: 2px solid #ff3437;
}
#search-btn {
  background: var(--accent); color: #fff;
  border: none;
  border-radius: 0 2em 2em 0;
  padding: 0 1.2em;
  font-size: 1.2em;
  cursor: pointer;
  transition: background 0.2s;
  outline: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
#search-btn:hover { background: #e33134; }

/* Slider Toggle for Playlists */
.slider-toggle-container {
  display: flex;
  align-items: center;
  margin-left: 1em;
  min-width: 190px;
}
.slider-toggle {
  display: flex;
  align-items: center;
  background: var(--card-bg);
  border-radius: 2em;
  box-shadow: 0 2px 16px #0002;
  overflow: hidden;
  font-size: 1em;
  border: 1.5px solid var(--accent);
  transition: background 0.2s, border 0.2s;
  height: 42px;
}
.slider-option {
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.4em 1.1em;
  cursor: pointer;
  outline: none;
  color: var(--gray);
  background: transparent;
  font-weight: 500;
  font-family: inherit;
  font-size: 1em;
  border: none;
  transition: background 0.18s, color 0.18s;
  height: 42px;
}
.slider-option.active,
.slider-option:focus {
  background: var(--accent);
  color: #fff;
  z-index: 1;
}
body.light .slider-toggle { border: 1.5px solid var(--accent);}
body.light .slider-option.active { color: #fff; background: var(--accent);}
body.light .slider-option { color: var(--gray); }

/* Go To Top Button */
#to-top-btn {
  position: fixed;
  right: 32px;
  bottom: 36px;
  z-index: 500;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 52px;
  height: 52px;
  box-shadow: 0 4px 24px #0004;
  font-size: 1.75em;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.18s, box-shadow 0.18s;
}
#to-top-btn:hover { background: #b0292c; }

main {
  padding: 2.5rem 1.2rem 1.5rem 1.2rem;
  min-height: 80vh;
}

@media (max-width: 700px) {
  header {
    flex-direction: column;
    position: relative;
    align-items: stretch;
    gap: 1.1rem;
    padding: 1.2rem 1rem;
  }

  .header-controls > .search-group { order: 1; }
    .header-controls > .slider-toggle-container { order: 2; }
    .header-controls > .theme-toggle { order: 3; }

  .header-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 0.8rem;
    margin-top: 0.7rem;
  }
  .slider-toggle-container, .search-group {
    width: 100%;
    max-width: 100vw;
    margin-left: 0;
    justify-content: flex-start;
  }
  .search-group {
    display: flex;
    flex-direction: row;
    align-items: stretch;     /* <- Change to STRETCH for vertical match */
    flex-wrap: nowrap;
    height: auto;
    flex: none;
    margin: 0;
    order: 1;
  }
  #search {
    border-radius: 2em 0 0 2em;
    border-right: none;
    font-size: 1em;
    padding-top: 0.65em;
    padding-bottom: 0.65em;
    margin: 0;
    height: auto;    /* <- Let input control its own height */
  }
  #search-btn {
    border-radius: 0 2em 2em 0;
    border-left: none;
    font-size: 1em;
    padding-top: 0.65em;
    padding-bottom: 0.65em;
    margin: 0;
    height: auto;    /* <- Will now exactly match input */
    display: flex;
    align-items: center;
  }
  .slider-toggle-container {
    margin: 0;
    order: 2;
  }
}

  .search-group {
    order: 1;
  }
}

.header-controls > .search-group { order: 1; }
.header-controls > .slider-toggle-container { order: 2; }
.header-controls > .theme-toggle { order: 3; }

.card {
  background: var(--card-bg);
  border-radius: 8px;
  box-shadow: 0 8px 32px #0003;
  overflow: hidden;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
}
.card:hover { background: var(--card-hover); box-shadow: 0 12px 40px #0005; }
.thumb {
  width: 100%; aspect-ratio: 16/9; background: #222; display: block; border-bottom: 3px solid var(--accent);
}
body.light .thumb { border-bottom: 3px solid var(--accent);}
.card-info {
  padding: 1em 1.1em 0.8em 1.1em;
  flex: 1;
}
.title {
  font-size: 1.19em;
  font-weight: 500;
  margin-bottom: 0.3em;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tags {
  font-size: 0.99em;
  color: var(--gray);
}

.player-layout {
  display: flex;
  gap: 2.2rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}
.player-main {
  flex: 2 1 570px; min-width: 290px; max-width: 1000px;
}
.player-back-btn {
  margin-bottom: 1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  background: var(--card-hover);
  color: var(--text);
  border: none;
  border-radius: 2em;
  padding: 0.55em 1.3em;
  font-size: 1em;
  cursor: pointer;
  font-weight: 500;
  box-shadow: 0 2px 12px #0002;
  transition: background 0.22s;
}
body.light .player-back-btn { background: #ededf2; color: #363647; }
.player-back-btn:hover { background: var(--accent); color: #fff; }

.player-box {
  width: 100%;
  aspect-ratio: 16/9;
  background: #1a1a1d;
  border-radius: 0.7em;
  margin-bottom: 1.7em;
  box-shadow: 0 4px 32px #0003;
  overflow: hidden;
}
body.light .player-box { background: #f4f4fb; }

.player-title {
  font-size: 1.45em;
  font-weight: 700;
  margin-bottom: 0.8em;
  color: var(--text);
}
.player-tags {
  margin-bottom: 1.7em;
  color: var(--gray)
}

.related {
  flex: 1 1 300px; min-width: 240px; max-width: 360px;
  display: flex; flex-direction: column;
}
.related-title {
  font-size: 1.12em; color: var(--text); font-weight: 600;
  margin-bottom: 1em;
}
.related-list {
  display: flex; flex-direction: column; gap: 1em;
}
.related-card {
  display: flex; gap: 1em;
  background: #19191b; border-radius: 8px;
  cursor: pointer;
  overflow: hidden;
  transition: background 0.15s;
}
body.light .related-card { background: #ededf2; }
.related-card:hover { background: var(--card-hover); }
.related-thumb { width: 115px; aspect-ratio: 16/9; object-fit: cover; background: #2a2a2f; }
body.light .related-thumb { background: #f4f4fb; }
.related-info { flex: 1; display: flex; flex-direction: column; justify-content: center; overflow: hidden;}
.related-info .title { font-size: 1em; color: var(--text); font-weight: 600; margin-bottom: 0.23em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.related-info .tags { font-size: 0.96em; color: var(--gray); }
@media (max-width: 1100px) {
  .player-layout { flex-direction: column; gap: 2.5rem;}
  .related { padding: 0; }
}
::-webkit-scrollbar { width: 8px; background: #232327;}
::-webkit-scrollbar-thumb { background: #343436; border-radius: 5px;}
body.light ::-webkit-scrollbar-thumb { background: #d0d0df; }

.thumb-poster-bg {
  background: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 2/3;
  width: 100%;
  position: relative;
  overflow: hidden;
}
.thumb-poster {
  height: 100%;
  width: auto;
  max-width: 100%;
  display: block;
  object-fit: contain;
  background: #111;
}
.thumb-poster-placeholder {
  width: 64px;
  height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #222;
  color: #444;
  font-size: 2.5em;
  border-radius: 8px;
}

.player-controls-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 2em;
  margin-bottom: 1em;
  flex-wrap: wrap;
}
.player-controls-row .dropdowns {
  display: flex;
  align-items: center;
  gap: 0.7em;
}
.player-controls-row select {
  padding-right: 2.2em !important;
  border-radius: 2em;
  border: 1.5px solid var(--accent);
  background: var(--card-bg);
  color: var(--text);
  margin-right: 0.8em;
  font-size: 1em;
}
.player-controls-row label {
  font-weight: 500;
  margin-right: 0.25em;
}
.player-controls-row .prevnext {
  display: flex;
  gap: 0.5em;
}
.player-controls-row .prevnext button {
  padding: 0.5em 1.2em;
  font-size: 1em;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 2em;
  cursor: pointer;
  transition: background 0.18s;
}
.player-controls-row .prevnext button:hover {
  background: #b0292c;
}

.related-list {
  display: flex;
  flex-wrap: wrap;
  gap: 1em;
  margin-top: 0.8em;
}
.related-card {
  display: flex;
  align-items: flex-start;
  background: var(--card-bg);
  border-radius: 8px;
  box-shadow: 0 1px 6px #2222;
  padding: 0.4em 1em;
  min-width: 220px;
}
.related-info .title {
  font-weight: 500;
  margin-bottom: 0.2em;
  font-size: 1em;
}

@media (max-width: 600px) {

  .player-controls-row {
    flex-direction: column;
    align-items: stretch;
    gap: 1em;
  }
  .player-controls-row .dropdowns {
    flex-direction: column;
    align-items: stretch;
    gap: 0.7em;
    width: 100%;
  }
  .player-controls-row label {
    margin-bottom: 0.12em;
    font-size: 1em;
  }
  .player-controls-row select {
    padding-right: 2.6em !important;
    width: 100%;
    min-width: 0;
    border-radius: 2em;
    font-size: 1.08em;
    background: var(--card-bg);
    border: 1.5px solid var(--accent);
    margin-bottom: 0.3em;
  }
  .player-controls-row .prevnext {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    width: 100%;
    gap: 0.5em;
    margin-top: 0.5em;
  }
  .player-controls-row .prevnext button {
    flex: initial;
    min-width: unset;
    width: auto;
    padding: 0.55em 1.3em;
    font-size: 1em;
    border-radius: 2em;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    max-width: 45vw;
    white-space: nowrap;
  }
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-top: 1rem;
}

@media (min-width: 1200px) {
  .grid {
    grid-template-columns: repeat(8, 1fr);
    gap: 1rem;
  }
}

@media (max-width: 1199px) and (min-width: 900px) {
  .grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

@media (max-width: 899px) and (min-width: 600px) {
  .grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 599px) and (min-width: 400px) {
  .grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.8rem;
  }
}

@media (max-width: 399px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.8rem;
  }
}

.details-section {
  margin: 1.6em 0 1.2em 0;
  padding: 1.1em 1.6em;
  background: var(--card-bg);
  border-radius: 8px;
  color: var(--text);
  font-size: 1.07em;
  box-shadow: 0 2px 12px #0001;
}
.details-section > div {
  margin-bottom: 0.5em;
  line-height: 1.7;
}
.details-section b {
  color: var(--accent);
  font-weight: 600;
}

#server-dd, .player-controls-row select {
  padding: 0.55em 2.2em 0.55em 1.1em;
  min-width: 120px;
}
.player-controls-row label {
  margin-right: 0.7em;
  font-weight: 500;
}

/* Watchlist specific styles */
.remove-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(255, 52, 55, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    z-index: 2;
}

.card:hover .remove-btn {
    opacity: 1;
}

.remove-btn:hover {
    background: rgba(255, 52, 55, 1);
    transform: scale(1.1);
}

#watchlist-context-menu:hover {
    background: var(--accent);
    color: white;
}

.loading-spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--gray);
  border-radius: 50%;
  border-top-color: var(--accent);
  animation: spin 1s ease-in-out infinite;
  margin: 0 auto;
}

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

#loading-indicator {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2rem;
  color: var(--gray);
  text-align: center;
}

.loading-text {
  margin-left: 1rem;
  font-weight: 500;
  font-size: 1em;
}

.card.loading {
  background: var(--card-bg);
  animation: pulse 1.5s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { opacity: 0.6; }
  to { opacity: 1; }
}
