:root {
  --bg: #0b0f17;
  --card: #141a24;
  --card-border: #263040;
  --text: #f0f6fc;
  --muted: #8b949e;
  --accent: #ff4d67;
  --accent-hover: #ff3352;
  --blue: #2563eb;
  --blue-hover: #1d4ed8;
  --green: #238636;
  --green-hover: #2ea043;
  --yellow: #e3b341;
  --container-max-width: 1540px;
  --container-padding: clamp(16px, 2.5vw, 36px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 50% 0%, rgba(37, 99, 235, 0.08), transparent 45%),
    radial-gradient(circle at 90% 90%, rgba(255, 77, 103, 0.05), transparent 40%);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* Header */
header {
  position: sticky;
  top: 0;
  background: rgba(11, 15, 23, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--card-border);
  padding: 12px clamp(14px, 2vw, 28px);
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.header-inner {
  max-width: var(--container-max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.search-input {
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 12px;
  width: 240px;
  outline: none;
  transition: border-color 0.2s ease;
}

.search-input:focus {
  border-color: var(--blue);
}

#sortSelect {
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  outline: none;
}

.btn {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: white;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: all 0.15s ease;
  box-shadow: 0 2px 6px rgba(255, 77, 103, 0.2);
}

.btn:hover {
  filter: brightness(1.12);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
  filter: brightness(0.95);
}

/* Main Container */
.main-container {
  max-width: var(--container-max-width);
  margin: 0 auto;
  padding: 16px var(--container-padding) 60px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
}

/* Tabs & Status */
.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab {
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--muted);
  padding: 6px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.15s ease;
}

.tab:hover {
  color: var(--text);
  border-color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 2px 8px rgba(255, 77, 103, 0.3);
}

.status-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

#status {
  font-size: 12px;
  color: var(--muted);
}

.error-banner {
  background: rgba(248, 81, 73, 0.12);
  border: 1px solid rgba(248, 81, 73, 0.45);
  color: #ffb4ae;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
}

/* Grid & Cards */
#grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
  padding: 4px 0 20px;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 11px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.2s, box-shadow 0.2s;
  content-visibility: auto;
  contain-intrinsic-size: 190px 290px;
}

.card:hover {
  border-color: #444c56;
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.card.is-watching {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(255, 77, 103, 0.4), 0 10px 26px rgba(255, 77, 103, 0.18);
}

.thumb {
  position: relative;
  aspect-ratio: 1 / 1.08;
  background: #000;
  overflow: hidden;
}

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

.thumb-badges {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 2;
  pointer-events: none;
}

.badge-duet {
  background: #1f6feb;
  border: 1px solid #388bfd;
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 6px;
  border-radius: 4px;
  display: inline-block;
}

.badge-pk {
  background: #8957e5;
  border: 1px solid #a371f7;
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 6px;
  border-radius: 4px;
  display: inline-block;
}

.badge-lock-solo {
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid #e3b341;
  color: #f1e05a;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 6px;
  border-radius: 4px;
  display: inline-block;
}

.badge-lock-pk {
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid #bc8cff;
  color: #d2a8ff;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 6px;
  border-radius: 4px;
  display: inline-block;
}

.badge-lock-duet {
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid #58a6ff;
  color: #79c0ff;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 6px;
  border-radius: 4px;
  display: inline-block;
}

.watching {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.68);
  backdrop-filter: blur(4px);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 12px;
}

.slug-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.68);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #c9d1d9;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.slug-badge:hover {
  border-color: var(--blue);
  color: #ffffff;
}

/* Card Info */
.info {
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.user-name-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 3px;
  min-width: 0;
}

.user-badge {
  background: linear-gradient(135deg, #ff4d67, #ff758c);
  color: white;
  font-size: 8.5px;
  font-weight: 800;
  padding: 1px 4px;
  border-radius: 4px;
  letter-spacing: 0.4px;
  flex-shrink: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 700;
  color: #ffffff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.vj-id-badge {
  font-size: 10px;
  color: var(--muted);
  margin-left: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
  flex-shrink: 0;
  max-width: 85px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.title {
  font-size: 11.5px;
  font-weight: 400;
  color: var(--muted);
  margin: 0 0 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta {
  font-size: 10.5px;
  color: var(--muted);
  display: flex;
  gap: 10px;
  margin-bottom: 5px;
}

.cats {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-bottom: 6px;
}

.cats span {
  font-size: 9.5px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--card-border);
  padding: 1px 5px;
  border-radius: 5px;
  color: var(--muted);
}

.lock-time {
  font-size: 10px;
  color: var(--yellow);
  margin-bottom: 8px;
  padding: 3px 6px;
  border-radius: 5px;
  background: rgba(227, 179, 65, 0.08);
  border: 1px solid rgba(227, 179, 65, 0.25);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Single Watch Action at Bottom */
.card-actions {
  margin-top: auto;
  padding-top: 2px;
}

.watch-btn {
  width: 100%;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 7px;
}

.watch-btn.watching-active {
  background: var(--green);
  border-color: var(--green);
  box-shadow: 0 2px 8px rgba(35, 134, 54, 0.35);
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 14px;
  background: var(--card);
  border: 1px dashed var(--card-border);
  border-radius: 14px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(5px);
  overflow-y: auto;
}

.modal-box {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  width: 100%;
  max-width: 840px;
  max-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8);
  overflow: hidden;
  position: relative;
}

.modal-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--card-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  background: #161b22;
}

.modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.player-badge {
  background: #dc2626;
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

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

.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.15s ease;
}

.modal-close:hover {
  color: white;
  background: rgba(255, 255, 255, 0.1);
}

.modal-body {
  padding: 0;
  background: #000;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  overflow: hidden;
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
}

#webPlayerVideo {
  width: 100%;
  max-height: 80vh;
  background: #000;
  outline: none;
  display: block;
}

@media (max-width: 900px) {
  #grid {
    grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
    gap: 12px;
  }
}

@media (max-width: 600px) {
  header {
    padding: 10px 12px;
  }
  .header-inner {
    gap: 10px;
  }
  .tabs {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .tabs::-webkit-scrollbar {
    display: none;
  }
  .tab {
    flex-shrink: 0;
    padding: 5px 12px;
    font-size: 11.5px;
  }
  .header-controls {
    display: grid;
    grid-template-columns: 1fr auto;
    width: 100%;
    gap: 8px;
  }
  .search-input {
    width: 100%;
    min-width: 0;
  }
  .main-container {
    padding: 12px 10px 44px;
    gap: 10px;
  }
  #grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .card {
    border-radius: 10px;
    contain-intrinsic-size: 165px 250px;
  }
  .thumb-badges {
    top: 6px;
    left: 6px;
  }
  .watching {
    bottom: 6px;
    left: 6px;
    font-size: 10px;
    padding: 2px 6px;
  }
  .slug-badge {
    display: none;
  }
  .info {
    padding: 8px 9px;
  }
  .user-name {
    font-size: 12px;
  }
  .vj-id-badge {
    display: none;
  }
  .title {
    font-size: 11px;
    margin-bottom: 4px;
  }
  .meta {
    font-size: 10px;
    gap: 8px;
    margin-bottom: 4px;
  }
  .cats {
    display: none;
  }
  .lock-time {
    font-size: 9.5px;
    padding: 2px 5px;
    margin-bottom: 6px;
  }
  .watch-btn {
    padding: 6px 8px;
    font-size: 11.5px;
  }
  .modal-overlay {
    padding: 8px;
  }
  .modal-header {
    padding: 10px 14px;
  }
  .modal-title-text {
    font-size: 13px;
  }
}

@media (max-width: 350px) {
  #grid {
    grid-template-columns: 1fr;
  }
}
