:root {
  --bg-main: #0b0e14;
  --bg-surface: #141923;
  --bg-card: #1c2230;
  --bg-hover: #262e42;
  --border: #283145;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --primary: #8b5cf6;
  --primary-hover: #7c3aed;
  --primary-active: #6d28d9;
  --primary-light: rgba(139, 92, 246, 0.15);
  --success: #10b981;
  --danger: #ef4444;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 8px;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--text-main);
  text-decoration: none;
}

a:hover {
  color: var(--primary-light);
}

/* Header & Navbar */
.site-header {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
}

.brand-badge {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #fff;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.search-form {
  flex: 1;
  max-width: 540px;
  display: flex;
  position: relative;
}

.search-input {
  width: 100%;
  padding: 10px 16px;
  border-radius: 20px;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-size: 0.95rem;
  outline: none;
  transition: all 0.2s ease;
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.search-button {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 14px;
}

.search-button:hover {
  color: var(--primary);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 16px;
}

.nav-item {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.95rem;
  padding: 6px 12px;
  border-radius: var(--radius);
  transition: all 0.2s;
}

.nav-item:hover, .nav-item.active {
  color: #fff;
  background-color: var(--bg-card);
}

/* Main Content Container */
.main-wrapper {
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

/* Homepage Hero / Filter Tabs */
.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  overflow-x: auto;
  padding-bottom: 6px;
}

.filter-tab {
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s;
}

.filter-tab:hover, .filter-tab.active {
  background-color: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Video Grid */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
}

.video-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  display: flex;
  flex-direction: column;
}

.video-card:hover {
  transform: translateY(-4px);
  border-color: var(--primary);
  box-shadow: 0 12px 24px -10px rgba(0, 0, 0, 0.5);
}

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

.card-thumbnail {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
  display: block;
}

.video-card:hover .card-thumbnail {
  transform: scale(1.04);
}

.play-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(139, 92, 246, 0.9);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
}

.video-card:hover .play-badge {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1.1);
}

.card-ratio-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.75);
  color: #e2e8f0;
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
}

.card-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.4;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.category-tag {
  background-color: var(--bg-hover);
  color: var(--primary-light);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 64px 20px;
  background-color: var(--bg-surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  grid-column: 1 / -1;
}

.empty-state h3 {
  font-size: 1.25rem;
  color: var(--text-main);
  margin-bottom: 8px;
}

.empty-state p {
  color: var(--text-muted);
}

/* ================================================= */
/* Watch Page Layout */
/* ================================================= */

.watch-layout {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(320px, 3fr);
  gap: 28px;
  align-items: start;
}

.watch-main-column {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Player Container */
.player-container {
  background-color: #000;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.4);
  position: relative;
  width: 100%;
}

.player-container.ratio-16-9 {
  aspect-ratio: 16 / 9;
}

.player-container.ratio-9-16 {
  aspect-ratio: 9 / 16;
  max-height: 80vh;
  margin: 0 auto;
}

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

/* Video Info Box */
.video-details {
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.video-heading {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 10px;
  color: #fff;
}

.video-meta-row {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.video-desc {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* Prev / Next Nav Buttons */
.episode-nav {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius);
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-weight: 500;
  font-size: 0.9rem;
  transition: all 0.2s;
  min-height: 44px;
}

.nav-btn:hover:not(.disabled) {
  background-color: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.nav-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* Playlist Sidebar */
.playlist-sidebar {
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.playlist-header {
  padding: 16px 20px;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.playlist-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
}

.playlist-count {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.playlist-items {
  max-height: 520px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.playlist-item {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  transition: background-color 0.2s;
  align-items: center;
}

.playlist-item:hover {
  background-color: var(--bg-hover);
}

.playlist-item.active {
  background-color: var(--primary-light);
  border-left: 4px solid var(--primary);
}

.playlist-item-thumb {
  width: 96px;
  aspect-ratio: 16 / 9;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
  background: #000;
}

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

.playlist-item-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.playlist-item.active .playlist-item-title {
  color: var(--primary);
  font-weight: 600;
}

/* Comments Section */
.comments-section {
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-top: 10px;
}

.section-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.comment-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.form-input, .form-textarea {
  width: 100%;
  padding: 10px 14px;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-main);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus, .form-textarea:focus {
  border-color: var(--primary);
}

.form-textarea {
  min-height: 90px;
  resize: vertical;
}

.btn-submit {
  align-self: flex-start;
  padding: 10px 24px;
  background-color: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background-color 0.2s;
  min-height: 44px;
}

.btn-submit:hover {
  background-color: var(--primary-hover);
}

.form-status {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  display: none;
}

.form-status.success {
  display: block;
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--success);
  border: 1px solid var(--success);
}

.form-status.error {
  display: block;
  background-color: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.comment-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.comment-card {
  padding: 14px 18px;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.comment-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.comment-author {
  font-weight: 600;
  color: var(--primary-light);
  font-size: 0.95rem;
}

.comment-date {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.comment-body {
  font-size: 0.95rem;
  color: var(--text-main);
  white-space: pre-wrap;
  word-break: break-word;
}

.official-reply {
  margin-top: 12px;
  margin-left: 18px;
  padding: 12px 14px;
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: rgba(124, 58, 237, 0.12);
}

.official-reply-label {
  color: var(--primary-light);
  font-weight: 700;
  font-size: 0.82rem;
  margin-bottom: 5px;
}

.comment-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 18px;
}

.comment-pagination a {
  color: var(--accent);
  font-weight: 700;
}

.continue-watching {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 18px 20px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(120, 74, 194, 0.18), var(--bg-surface));
}

.continue-watching[hidden] { display: none; }
.continue-label { display: block; color: var(--text-dim); font-size: 0.82rem; margin-bottom: 4px; }
.continue-link { color: white; background: var(--accent); padding: 10px 14px; border-radius: 10px; font-weight: 700; white-space: nowrap; }

.copy-link-btn {
  margin-top: 14px;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-main);
  cursor: pointer;
}

.series-directory {
  padding: 14px;
  border-top: 1px solid var(--border);
}

.series-directory-title {
  font-weight: 700;
  margin-bottom: 10px;
}

.series-group summary {
  cursor: pointer;
  padding: 10px 4px;
  color: var(--text-muted);
}

.series-items {
  display: grid;
  gap: 4px;
  padding: 0 0 10px 12px;
}

.series-items a {
  color: var(--text-muted);
  padding: 7px 8px;
  border-radius: 6px;
}

.series-items a:hover {
  color: #fff;
  background: var(--bg-card);
}

/* Footer */
.site-footer {
  margin-top: auto;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 24px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* Global overflow protection */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}

/* Mobile Responsiveness (360px - 768px) */
@media (max-width: 900px) {
  .watch-layout {
    display: flex;
    flex-direction: column;
  }

  .watch-main-column { display: contents; }
  .player-container { order: 1; }
  .video-details { order: 2; }
  .playlist-sidebar {
    order: 3;
  }

  .comments-section {
    order: 4;
  }
}

@media (max-width: 768px) {
  .header-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    gap: 8px;
  }

  .brand-link {
    flex: 0 0 auto;
  }

  .nav-links {
    flex: 0 0 auto;
  }

  .search-form {
    order: 3;
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    margin-top: 4px;
  }

  .search-input {
    width: 100%;
    min-width: 0;
  }

  .main-wrapper {
    padding: 14px 12px 32px;
  }

  .video-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .video-heading {
    font-size: 1.15rem;
  }

  .episode-nav {
    flex-direction: column;
  }

  .nav-btn {
    justify-content: center;
    width: 100%;
    min-height: 44px;
  }

  .btn-submit {
    width: 100%;
    min-height: 44px;
  }

  .filter-bar {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .continue-watching {
    align-items: flex-start;
    flex-direction: column;
  }
}
